|
2507 | 2507 | #define DT_FOREACH_PROP_ELEM(node_id, prop, fn) \
|
2508 | 2508 | DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM)(fn)
|
2509 | 2509 |
|
| 2510 | +/** |
| 2511 | + * @brief Invokes @p fn for each element in the value of property @p prop with |
| 2512 | + * separator. |
| 2513 | + * |
| 2514 | + * Example devicetree fragment: |
| 2515 | + * |
| 2516 | + * @code{.dts} |
| 2517 | + * n: node { |
| 2518 | + * my-gpios = <&gpioa 0 GPIO_ACTICE_HIGH>, |
| 2519 | + * <&gpiob 1 GPIO_ACTIVE_HIGH>; |
| 2520 | + * }; |
| 2521 | + * @endcode |
| 2522 | + * |
| 2523 | + * Example usage: |
| 2524 | + * |
| 2525 | + * @code{.c} |
| 2526 | + * struct gpio_dt_spec specs[] = { |
| 2527 | + * DT_FOREACH_PROP_ELEM_SEP(DT_NODELABEL(n), my_gpios, |
| 2528 | + * GPIO_DT_SPEC_BY_IDX, (,)) |
| 2529 | + * }; |
| 2530 | + * @endcode |
| 2531 | + * |
| 2532 | + * This expands as a first step to: |
| 2533 | + * |
| 2534 | + * @code{.c} |
| 2535 | + * struct gpio_dt_spec specs[] = { |
| 2536 | + * struct gpio_dt_spec specs[] = { |
| 2537 | + * GPIO_DT_SPEC_BY_IDX(DT_NODELABEL(n), my_gpios, 0), |
| 2538 | + * GPIO_DT_SPEC_BY_IDX(DT_NODELABEL(n), my_gpios, 1) |
| 2539 | + * }; |
| 2540 | + * @endcode |
| 2541 | + * |
| 2542 | + * The "prop" argument must refer to a property with type string, |
| 2543 | + * array, uint8-array, string-array, phandles, or phandle-array. It is |
| 2544 | + * an error to use this macro with properties of other types. |
| 2545 | + * |
| 2546 | + * @param node_id node identifier |
| 2547 | + * @param prop lowercase-and-underscores property name |
| 2548 | + * @param fn macro to invoke |
| 2549 | + * @param sep Separator (e.g. comma or semicolon). Must be in parentheses; |
| 2550 | + * this is required to enable providing a comma as separator. |
| 2551 | + * |
| 2552 | + * @see DT_FOREACH_PROP_ELEM |
| 2553 | + */ |
| 2554 | +#define DT_FOREACH_PROP_ELEM_SEP(node_id, prop, fn, sep) \ |
| 2555 | + DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM_SEP)(fn, sep) |
| 2556 | + |
2510 | 2557 | /**
|
2511 | 2558 | * @brief Invokes @p fn for each element in the value of property @p prop with
|
2512 | 2559 | * multiple arguments.
|
|
2527 | 2574 | #define DT_FOREACH_PROP_ELEM_VARGS(node_id, prop, fn, ...) \
|
2528 | 2575 | DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM_VARGS)(fn, __VA_ARGS__)
|
2529 | 2576 |
|
| 2577 | +/** |
| 2578 | + * @brief Invokes @p fn for each element in the value of property @p prop with |
| 2579 | + * multiple arguments and a separator. |
| 2580 | + * |
| 2581 | + * @param node_id node identifier |
| 2582 | + * @param prop lowercase-and-underscores property name |
| 2583 | + * @param fn macro to invoke |
| 2584 | + * @param sep Separator (e.g. comma or semicolon). Must be in parentheses; |
| 2585 | + * this is required to enable providing a comma as separator. |
| 2586 | + * @param ... variable number of arguments to pass to fn |
| 2587 | + * |
| 2588 | + * @see DT_FOREACH_PROP_ELEM_VARGS |
| 2589 | + */ |
| 2590 | +#define DT_FOREACH_PROP_ELEM_SEP_VARGS(node_id, prop, fn, sep, ...) \ |
| 2591 | + DT_CAT4(node_id, _P_, prop, _FOREACH_PROP_ELEM_SEP_VARGS)( \ |
| 2592 | + fn, sep, __VA_ARGS__) |
| 2593 | + |
2530 | 2594 | /**
|
2531 | 2595 | * @brief Invokes @p fn for each status `okay` node of a compatible.
|
2532 | 2596 | *
|
|
3592 | 3656 | #define DT_INST_FOREACH_PROP_ELEM(inst, prop, fn) \
|
3593 | 3657 | DT_FOREACH_PROP_ELEM(DT_DRV_INST(inst), prop, fn)
|
3594 | 3658 |
|
| 3659 | +/** |
| 3660 | + * @brief Invokes @p fn for each element of property @p prop for |
| 3661 | + * a `DT_DRV_COMPAT` instance with a separator. |
| 3662 | + * |
| 3663 | + * Equivalent to DT_FOREACH_PROP_ELEM_SEP(DT_DRV_INST(inst), prop, fn, sep). |
| 3664 | + * |
| 3665 | + * @param inst instance number |
| 3666 | + * @param prop lowercase-and-underscores property name |
| 3667 | + * @param fn macro to invoke |
| 3668 | + * @param sep Separator (e.g. comma or semicolon). Must be in parentheses; |
| 3669 | + * this is required to enable providing a comma as separator. |
| 3670 | + */ |
| 3671 | +#define DT_INST_FOREACH_PROP_ELEM_SEP(inst, prop, fn, sep) \ |
| 3672 | + DT_FOREACH_PROP_ELEM_SEP(DT_DRV_INST(inst), prop, fn, sep) |
| 3673 | + |
3595 | 3674 | /**
|
3596 | 3675 | * @brief Invokes @p fn for each element of property @p prop for
|
3597 | 3676 | * a `DT_DRV_COMPAT` instance with multiple arguments.
|
|
3610 | 3689 | DT_FOREACH_PROP_ELEM_VARGS(DT_DRV_INST(inst), prop, fn, __VA_ARGS__)
|
3611 | 3690 |
|
3612 | 3691 | /**
|
3613 |
| - * @brief Does a `DT_DRV_COMPAT` instance have a property? |
| 3692 | + * @brief Invokes @p fn for each element of property @p prop for |
| 3693 | + * a `DT_DRV_COMPAT` instance with multiple arguments and a sepatator. |
| 3694 | + * |
| 3695 | + * Equivalent to |
| 3696 | + * DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_DRV_INST(inst), prop, fn, sep, |
| 3697 | + * __VA_ARGS__) |
| 3698 | + * |
| 3699 | + * @param inst instance number |
| 3700 | + * @param prop lowercase-and-underscores property name |
| 3701 | + * @param fn macro to invoke |
| 3702 | + * @param sep Separator (e.g. comma or semicolon). Must be in parentheses; |
| 3703 | + * this is required to enable providing a comma as separator. |
| 3704 | + * @param ... variable number of arguments to pass to fn |
| 3705 | + * |
| 3706 | + * @see DT_INST_FOREACH_PROP_ELEM |
| 3707 | + */ |
| 3708 | +#define DT_INST_FOREACH_PROP_ELEM_SEP_VARGS(inst, prop, fn, sep, ...) \ |
| 3709 | + DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_DRV_INST(inst), prop, fn, sep, \ |
| 3710 | + __VA_ARGS__) |
| 3711 | + |
| 3712 | +/** |
| 3713 | + * @brief Does a DT_DRV_COMPAT instance have a property? |
3614 | 3714 | * @param inst instance number
|
3615 | 3715 | * @param prop lowercase-and-underscores property name
|
3616 | 3716 | * @return 1 if the instance has the property, 0 otherwise.
|
|
0 commit comments