diff --git a/include/zephyr/devicetree.h b/include/zephyr/devicetree.h index b6a8756c9c..7255d7981f 100644 --- a/include/zephyr/devicetree.h +++ b/include/zephyr/devicetree.h @@ -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? diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c index 5c0937dbc2..340ff1edbf 100644 --- a/tests/lib/devicetree/api/src/main.c +++ b/tests/lib/devicetree/api/src/main.c @@ -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)