Commit 5aebd127 authored by Yong Cong Sin's avatar Yong Cong Sin Committed by Fabio Baltieri
Browse files

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: default avatarYong Cong Sin <ycsin@meta.com>
Signed-off-by: default avatarYong Cong Sin <yongcong.sin@gmail.com>
parent 44d101ac
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -3431,6 +3431,28 @@
#define DT_NODE_HAS_STATUS(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?
 *
+11 −0
Original line number Diff line number Diff line
@@ -366,6 +366,17 @@ ZTEST(devicetree_api, test_has_status)
		      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)
{
	int pin, flags;