Skip to content

Commit 761c285

Browse files
ycsingmarull
authored andcommitted
[nrf fromtree] devicetree: add DT_NODE_HAS_STATUS_OKAY
We already have `DT_HAS_COMPAT_STATUS_OKAY` and `DT_NUM_INST_STATUS_OKAY`, it seems intuitive to assume that `DT_NODE_HAS_STATUS_OKAY` exists, so much so that it was used before it's implemented. This patch implements `DT_NODE_HAS_STATUS_OKAY`, which is equivalent to: `DT_NODE_HAS_STATUS(<node_id>, okay)` Added test for it in `tests/lib/devicetree/api` Signed-off-by: Yong Cong Sin <[email protected]> Signed-off-by: Yong Cong Sin <[email protected]> (cherry picked from commit 5aebd12)
1 parent b226d08 commit 761c285

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

include/zephyr/devicetree.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,6 +3403,28 @@
34033403
#define DT_NODE_HAS_STATUS(node_id, status) \
34043404
DT_NODE_HAS_STATUS_INTERNAL(node_id, status)
34053405

3406+
/**
3407+
* @brief Does a node identifier refer to a node with a status `okay`?
3408+
*
3409+
* Example uses:
3410+
*
3411+
* @code{.c}
3412+
* DT_NODE_HAS_STATUS_OKAY(DT_PATH(soc, i2c_12340000))
3413+
* @endcode
3414+
*
3415+
* Tests whether a node identifier refers to a node which:
3416+
*
3417+
* - exists in the devicetree, and
3418+
* - has a status property as `okay`
3419+
*
3420+
* As usual, both a missing status and an `ok` status are treated as
3421+
* `okay`.
3422+
*
3423+
* @param node_id a node identifier
3424+
* @return 1 if the node has status as `okay`, 0 otherwise.
3425+
*/
3426+
#define DT_NODE_HAS_STATUS_OKAY(node_id) DT_NODE_HAS_STATUS(node_id, okay)
3427+
34063428
/**
34073429
* @brief Does the devicetree have a status `okay` node with a compatible?
34083430
*

tests/lib/devicetree/api/src/main.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@ ZTEST(devicetree_api, test_has_status)
366366
0, "");
367367
}
368368

369+
ZTEST(devicetree_api, test_has_status_okay)
370+
{
371+
zassert_equal(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(test_gpio_1)), 1);
372+
373+
zassert_equal(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(test_no_status)), 1);
374+
375+
zassert_equal(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(disabled_gpio)), 0);
376+
377+
zassert_equal(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(reserved_gpio)), 0);
378+
}
379+
369380
ZTEST(devicetree_api, test_bus)
370381
{
371382
int pin, flags;

0 commit comments

Comments
 (0)