Skip to content

Commit 75ab4d5

Browse files
maass-hamburgkartben
authored andcommitted
devicetree: add DT_ALL_INST_HAS_PROP_STATUS_OKAY() macro
add DT_ALL_INST_HAS_PROP_STATUS_OKAY() macro. Signed-off-by: Fin Maaß <[email protected]>
1 parent 416a760 commit 75ab4d5

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

include/zephyr/devicetree.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,6 +4821,53 @@
48214821
UTIL_NOT(IS_EMPTY( \
48224822
DT_INST_FOREACH_STATUS_OKAY_VARGS(DT_ANY_INST_HAS_PROP_STATUS_OKAY_, prop)))
48234823

4824+
/**
4825+
* @brief Check if all `DT_DRV_COMPAT` node with status `okay` has a given
4826+
* property. If all nodes are disabled, this will return 1.
4827+
*
4828+
* @param prop lowercase-and-underscores property name
4829+
*
4830+
* Example devicetree overlay:
4831+
*
4832+
* @code{.dts}
4833+
* &i2c0 {
4834+
* sensor0: sensor@0 {
4835+
* compatible = "vnd,some-sensor";
4836+
* status = "okay";
4837+
* reg = <0>;
4838+
* foo = <1>;
4839+
* bar = <2>;
4840+
* };
4841+
*
4842+
* sensor1: sensor@1 {
4843+
* compatible = "vnd,some-sensor";
4844+
* status = "okay";
4845+
* reg = <1>;
4846+
* foo = <2>;
4847+
* };
4848+
*
4849+
* sensor2: sensor@2 {
4850+
* compatible = "vnd,some-sensor";
4851+
* status = "disabled";
4852+
* reg = <2>;
4853+
* baz = <1>;
4854+
* };
4855+
* };
4856+
* @endcode
4857+
*
4858+
* Example usage:
4859+
*
4860+
* @code{.c}
4861+
* #define DT_DRV_COMPAT vnd_some_sensor
4862+
*
4863+
* DT_ALL_INST_HAS_PROP_STATUS_OKAY(foo) // 1
4864+
* DT_ALL_INST_HAS_PROP_STATUS_OKAY(bar) // 0
4865+
* DT_ALL_INST_HAS_PROP_STATUS_OKAY(baz) // 0
4866+
* @endcode
4867+
*/
4868+
#define DT_ALL_INST_HAS_PROP_STATUS_OKAY(prop) \
4869+
IS_EMPTY(DT_INST_FOREACH_STATUS_OKAY_VARGS(DT_ALL_INST_HAS_PROP_STATUS_OKAY_, prop))
4870+
48244871
/**
48254872
* @brief Check if any device node with status `okay` has a given
48264873
* property.
@@ -5265,6 +5312,20 @@
52655312
#define DT_ANY_INST_HAS_BOOL_STATUS_OKAY_(idx, prop) \
52665313
IF_ENABLED(DT_INST_PROP(idx, prop), (1,))
52675314

5315+
/** @brief Helper for DT_ALL_INST_HAS_PROP_STATUS_OKAY
5316+
*
5317+
* This macro generates token "1," for instance of a device,
5318+
* identified by index @p idx, if instance has no property @p prop.
5319+
*
5320+
* @param idx instance number
5321+
* @param prop property to check for
5322+
*
5323+
* @return Macro evaluates to `1,` if instance has the property,
5324+
* otherwise it evaluates to literal nothing.
5325+
*/
5326+
#define DT_ALL_INST_HAS_PROP_STATUS_OKAY_(idx, prop) \
5327+
IF_DISABLED(DT_INST_NODE_HAS_PROP(idx, prop), (1,))
5328+
52685329
/** @brief Helper for DT_ALL_INST_HAS_BOOL_STATUS_OKAY
52695330
*
52705331
* This macro generates token "1," for instance of a device,

0 commit comments

Comments
 (0)