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 <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
This commit is contained in:
Yong Cong Sin 2024-09-20 10:34:24 +08:00 committed by Fabio Baltieri
commit 5aebd1276d
2 changed files with 33 additions and 0 deletions

View file

@ -3431,6 +3431,28 @@
#define DT_NODE_HAS_STATUS(node_id, status) \ #define DT_NODE_HAS_STATUS(node_id, status) \
DT_NODE_HAS_STATUS_INTERNAL(node_id, status) DT_NODE_HAS_STATUS_INTERNAL(node_id, status)
/**
* @brief Does a node identifier refer to a node with a status `okay`?
*
* Example uses:
*
* @code{.c}
* DT_NODE_HAS_STATUS_OKAY(DT_PATH(soc, i2c_12340000))
* @endcode
*
* Tests whether a node identifier refers to a node which:
*
* - exists in the devicetree, and
* - has a status property as `okay`
*
* As usual, both a missing status and an `ok` status are treated as
* `okay`.
*
* @param node_id a node identifier
* @return 1 if the node has status as `okay`, 0 otherwise.
*/
#define DT_NODE_HAS_STATUS_OKAY(node_id) DT_NODE_HAS_STATUS(node_id, okay)
/** /**
* @brief Does the devicetree have a status `okay` node with a compatible? * @brief Does the devicetree have a status `okay` node with a compatible?
* *

View file

@ -366,6 +366,17 @@ ZTEST(devicetree_api, test_has_status)
0, ""); 0, "");
} }
ZTEST(devicetree_api, test_has_status_okay)
{
zassert_equal(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(test_gpio_1)), 1);
zassert_equal(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(test_no_status)), 1);
zassert_equal(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(disabled_gpio)), 0);
zassert_equal(DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(reserved_gpio)), 0);
}
ZTEST(devicetree_api, test_bus) ZTEST(devicetree_api, test_bus)
{ {
int pin, flags; int pin, flags;