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:
parent
44d101acab
commit
5aebd1276d
2 changed files with 33 additions and 0 deletions
|
@ -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?
|
||||||
*
|
*
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue