devicetree: Add _VARGS variants to _FOREACH_ marcos `_FOREACH_` macros do not allow the caller to pass additional arguments to the `fn`. A series of `_VARGS` variants have been added that allow the caller to pass arbitrary number of arguments to the `fn`: ``` DT_FOREACH_CHILD_VARGS DT_FOREACH_CHILD_STATUS_OKAY_VARGS DT_FOREACH_PROP_ELEM_VARGS DT_INST_FOREACH_CHILD_VARGS DT_INST_FOREACH_STATUS_OKAY_VARGS DT_INST_FOREACH_PROP_ELEM_VARGS ``` Signed-off-by: Arvin Farahmand <arvinf@ip-logix.com>
diff --git a/scripts/dts/gen_defines.py b/scripts/dts/gen_defines.py index 5ce8417..435e8fe 100755 --- a/scripts/dts/gen_defines.py +++ b/scripts/dts/gen_defines.py
@@ -479,17 +479,25 @@ " ".join(f"fn(DT_{child.z_path_id})" for child in node.children.values())) + out_dt_define(f"{node.z_path_id}_FOREACH_CHILD_VARGS(fn, ...)", + " ".join(f"fn(DT_{child.z_path_id}, __VA_ARGS__)" for child in + node.children.values())) def write_child_functions_status_okay(node): # Writes macro that are helpers that will call a macro/function # for each child node with status "okay". functions = '' + functions_args = '' for child in node.children.values(): if child.status == "okay": functions = functions + f"fn(DT_{child.z_path_id}) " + functions_args = functions_args + f"fn(DT_{child.z_path_id}, " \ + "__VA_ARGS__) " out_dt_define(f"{node.z_path_id}_FOREACH_CHILD_STATUS_OKAY(fn)", functions) + out_dt_define(f"{node.z_path_id}_FOREACH_CHILD_STATUS_OKAY_VARGS(fn, ...)", + functions_args) def write_status(node): @@ -549,6 +557,11 @@ ' \\\n\t'.join(f'fn(DT_{node.z_path_id}, {prop_id}, {i})' for i in range(len(prop.val))) + macro2val[f"{macro}_FOREACH_PROP_ELEM_VARGS(fn, ...)"] = \ + ' \\\n\t'.join(f'fn(DT_{node.z_path_id}, {prop_id}, {i},' + ' __VA_ARGS__)' + for i in range(len(prop.val))) + plen = prop_len(prop) if plen is not None: # DT_N_<node-id>_P_<prop-id>_LEN @@ -749,6 +762,10 @@ " ".join(f"fn({edt.compat2nodes[compat].index(node)})" for node in okay_nodes) + for_each_macros[f"DT_FOREACH_OKAY_INST_VARGS_{ident}(fn, ...)"] = \ + " ".join(f"fn({edt.compat2nodes[compat].index(node)}, __VA_ARGS__)" + for node in okay_nodes) + for compat, nodes in edt.compat2nodes.items(): for node in nodes: if compat == "fixed-partitions":