diff --git a/doc/guides/kconfig/preprocessor-functions.rst b/doc/guides/kconfig/preprocessor-functions.rst index 164bccd197029..f73ce3624845d 100644 --- a/doc/guides/kconfig/preprocessor-functions.rst +++ b/doc/guides/kconfig/preprocessor-functions.rst @@ -39,6 +39,7 @@ while the ``*_hex`` version returns a hexadecimal value starting with ``0x``. $(dt_compat_enabled,) $(dt_chosen_enabled,) $(dt_node_has_bool_prop,,) + $(dt_node_has_prop,,) Example Usage diff --git a/scripts/kconfig/kconfigfunctions.py b/scripts/kconfig/kconfigfunctions.py index 17ba32dc5e79a..e4d5739cb2f07 100644 --- a/scripts/kconfig/kconfigfunctions.py +++ b/scripts/kconfig/kconfigfunctions.py @@ -324,6 +324,29 @@ def dt_node_has_bool_prop(kconf, _, path, prop): return "n" +def dt_node_has_prop(kconf, _, label, prop): + """ + This function takes a 'label' and looks for an EDT node for that label. If + it finds an EDT node, it will look to see if that node has a property + by the name of 'prop'. If the 'prop' exists it will return "y" otherwise + we return "n". + """ + + if doc_mode or edt is None: + return "n" + + try: + node = edt.label2node.get(label) + except edtlib.EDTError: + return "n" + + if node is None: + return "n" + + if prop in node.props: + return "y" + + return "n" def dt_node_int_prop(kconf, name, path, prop): """ @@ -445,6 +468,7 @@ def shields_list_contains(kconf, _, shield): "dt_node_reg_size_int": (dt_node_reg, 1, 3), "dt_node_reg_size_hex": (dt_node_reg, 1, 3), "dt_node_has_bool_prop": (dt_node_has_bool_prop, 2, 2), + "dt_node_has_prop": (dt_node_has_prop, 2, 2), "dt_node_int_prop_int": (dt_node_int_prop, 2, 2), "dt_node_int_prop_hex": (dt_node_int_prop, 2, 2), "dt_nodelabel_has_compat": (dt_nodelabel_has_compat, 2, 2),