devicetree: implement DT_INST_NODE_HAS_COMPAT
Implement `DT_INST_NODE_HAS_COMPAT` to check if a node has a compatible. This is helpful when a node has more than one compatible, which can be used to enable additional features in the driver. Updated the devicetree test to play with the new API. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
parent
a1916b0121
commit
9b7638f049
|
@ -4357,6 +4357,15 @@
|
|||
#define DT_INST_NODE_HAS_PROP(inst, prop) \
|
||||
DT_NODE_HAS_PROP(DT_DRV_INST(inst), prop)
|
||||
|
||||
/**
|
||||
* @brief Does a DT_DRV_COMPAT instance have the compatible?
|
||||
* @param inst instance number
|
||||
* @param compat lowercase-and-underscores compatible, without quotes
|
||||
* @return 1 if the instance matches the compatible, 0 otherwise.
|
||||
*/
|
||||
#define DT_INST_NODE_HAS_COMPAT(inst, compat) \
|
||||
DT_NODE_HAS_COMPAT(DT_DRV_INST(inst), compat)
|
||||
|
||||
/**
|
||||
* @brief Does a phandle array have a named cell specifier at an index
|
||||
* for a `DT_DRV_COMPAT` instance?
|
||||
|
|
|
@ -319,6 +319,10 @@ ZTEST(devicetree_api, test_has_compat)
|
|||
(TA_HAS_COMPAT(vnd_undefined_compat) << 1) |
|
||||
(TA_HAS_COMPAT(vnd_not_a_test_array_compat) << 2));
|
||||
zassert_equal(compats, 0x3, "");
|
||||
|
||||
#undef DT_DRV_COMPAT
|
||||
#define DT_DRV_COMPAT vnd_model1
|
||||
zassert_true(DT_INST_NODE_HAS_COMPAT(0, zephyr_model2));
|
||||
}
|
||||
|
||||
ZTEST(devicetree_api, test_has_status)
|
||||
|
|
Loading…
Reference in a new issue