Skip to content

Commit 35a8e37

Browse files
maass-hamburgkartben
authored andcommitted
devicetree: add DT_ALL_INST_HAS_BOOL_STATUS_OKAY() macro
add DT_ALL_INST_HAS_BOOL_STATUS_OKAY() macro. Signed-off-by: Fin Maaß <[email protected]>
1 parent ca6645d commit 35a8e37

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

include/zephyr/devicetree.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4919,6 +4919,54 @@
49194919
UTIL_NOT(IS_EMPTY( \
49204920
DT_INST_FOREACH_STATUS_OKAY_VARGS(DT_ANY_INST_HAS_BOOL_STATUS_OKAY_, prop)))
49214921

4922+
/**
4923+
* @brief Check if all `DT_DRV_COMPAT` node with status `okay` has a given
4924+
* boolean property that exists. If all nodes are disabled, this
4925+
* will return 1.
4926+
* *
4927+
* @param prop lowercase-and-underscores property name
4928+
*
4929+
* Example devicetree overlay:
4930+
*
4931+
* @code{.dts}
4932+
* &i2c0 {
4933+
* sensor0: sensor@0 {
4934+
* compatible = "vnd,some-sensor";
4935+
* status = "okay";
4936+
* reg = <0>;
4937+
* foo;
4938+
* bar;
4939+
* };
4940+
*
4941+
* sensor1: sensor@1 {
4942+
* compatible = "vnd,some-sensor";
4943+
* status = "okay";
4944+
* reg = <1>;
4945+
* foo;
4946+
* };
4947+
*
4948+
* sensor2: sensor@2 {
4949+
* compatible = "vnd,some-sensor";
4950+
* status = "disabled";
4951+
* reg = <2>;
4952+
* baz;
4953+
* };
4954+
* };
4955+
* @endcode
4956+
*
4957+
* Example usage:
4958+
*
4959+
* @code{.c}
4960+
* #define DT_DRV_COMPAT vnd_some_sensor
4961+
*
4962+
* DT_ALL_INST_HAS_BOOL_STATUS_OKAY(foo) // 1
4963+
* DT_ALL_INST_HAS_BOOL_STATUS_OKAY(bar) // 0
4964+
* DT_ALL_INST_HAS_BOOL_STATUS_OKAY(baz) // 0
4965+
* @endcode
4966+
*/
4967+
#define DT_ALL_INST_HAS_BOOL_STATUS_OKAY(prop) \
4968+
IS_EMPTY(DT_INST_FOREACH_STATUS_OKAY_VARGS(DT_ALL_INST_HAS_BOOL_STATUS_OKAY_, prop))
4969+
49224970
/**
49234971
* @brief Call @p fn on all nodes with compatible `DT_DRV_COMPAT`
49244972
* and status `okay`
@@ -5217,6 +5265,21 @@
52175265
#define DT_ANY_INST_HAS_BOOL_STATUS_OKAY_(idx, prop) \
52185266
IF_ENABLED(DT_INST_PROP(idx, prop), (1,))
52195267

5268+
/** @brief Helper for DT_ALL_INST_HAS_BOOL_STATUS_OKAY
5269+
*
5270+
* This macro generates token "1," for instance of a device,
5271+
* identified by index @p idx, if instance has no boolean property
5272+
* @p prop with value 1.
5273+
*
5274+
* @param idx instance number
5275+
* @param prop property to check for
5276+
*
5277+
* @return Macro evaluates to `1,` if instance property value is 0,
5278+
* otherwise it evaluates to literal nothing.
5279+
*/
5280+
#define DT_ALL_INST_HAS_BOOL_STATUS_OKAY_(idx, prop) \
5281+
IF_DISABLED(DT_INST_PROP(idx, prop), (1,))
5282+
52205283
#define DT_PATH_INTERNAL(...) \
52215284
UTIL_CAT(DT_ROOT, MACRO_MAP_CAT(DT_S_PREFIX, __VA_ARGS__))
52225285
/** @brief DT_PATH_INTERNAL() helper: prepends _S_ to a node name

0 commit comments

Comments
 (0)