Skip to content

Commit a9d0a36

Browse files
nordicjmkartben
authored andcommitted
scripts: kconfig: Add dt_nodelabel_int_prop function
Adds a function which can be used to get the integer value of a devicetree property in Kconfig from a nodelabel Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
1 parent bc06d85 commit a9d0a36

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

scripts/kconfig/kconfigfunctions.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,29 @@ def dt_nodelabel_bool_prop(kconf, _, label, prop):
532532

533533
return _dt_node_bool_prop_generic(edt.label2node.get, label, prop)
534534

535+
def dt_nodelabel_int_prop(kconf, _, label, prop):
536+
"""
537+
This function takes a 'label' and looks for an EDT node with that label.
538+
If it finds an EDT node, it will look to see if that node has a int
539+
property by the name of 'prop'. If the 'prop' exists it will return the
540+
value of the property, otherwise it returns "0".
541+
"""
542+
if doc_mode or edt is None:
543+
return "0"
544+
545+
try:
546+
node = edt.label2node.get(label)
547+
except edtlib.EDTError:
548+
return "0"
549+
550+
if not node or node.props[prop].type != "int":
551+
return "0"
552+
553+
if not node.props[prop].val:
554+
return "0"
555+
556+
return str(node.props[prop].val)
557+
535558
def dt_chosen_bool_prop(kconf, _, chosen, prop):
536559
"""
537560
This function takes a /chosen node property named 'chosen', and
@@ -1059,6 +1082,7 @@ def inc_dec(kconf, name, *args):
10591082
"dt_nodelabel_reg_size_hex": (dt_nodelabel_reg, 1, 3),
10601083
"dt_node_bool_prop": (dt_node_bool_prop, 2, 2),
10611084
"dt_nodelabel_bool_prop": (dt_nodelabel_bool_prop, 2, 2),
1085+
"dt_nodelabel_int_prop": (dt_nodelabel_int_prop, 2, 2),
10621086
"dt_chosen_bool_prop": (dt_chosen_bool_prop, 2, 2),
10631087
"dt_node_has_prop": (dt_node_has_prop, 2, 2),
10641088
"dt_nodelabel_has_prop": (dt_nodelabel_has_prop, 2, 2),

0 commit comments

Comments
 (0)