scripts: dts: gen_defines: add ENUM_VAL_<val>_EXISTS define

Add a define of the form
`DT_N_<node-id>_P_<prop-id>_ENUM_VAL_<val>_EXISTS` for enumerated
devicetree properties. This enables the devicetree API to check whether
an enum is a given value directly, without resorting to error-prone
checks against the enum index.

Example generated defines (int and string):
	`#define DT_N_S_test_S_enum_4_P_val_ENUM_VAL_5_EXISTS 1`
	`#define DT_N_S_test_S_enum_6_P_val_ENUM_VAL_zero_EXISTS 1`

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
Jordan Yates 2023-04-15 11:24:11 +10:00 committed by Marti Bolivar
parent c03e1900ae
commit 59167e1888

View file

@ -657,12 +657,17 @@ def write_vanilla_props(node):
if spec.enum_tokenizable:
as_token = prop.val_as_token
# DT_N_<node-id>_P_<prop-id>_ENUM_VAL_<val>_EXISTS 1
macro2val[macro + f"_ENUM_VAL_{as_token}_EXISTS"] = 1
# DT_N_<node-id>_P_<prop-id>_ENUM_TOKEN
macro2val[macro + "_ENUM_TOKEN"] = as_token
if spec.enum_upper_tokenizable:
# DT_N_<node-id>_P_<prop-id>_ENUM_UPPER_TOKEN
macro2val[macro + "_ENUM_UPPER_TOKEN"] = as_token.upper()
else:
# DT_N_<node-id>_P_<prop-id>_ENUM_VAL_<val>_EXISTS 1
macro2val[macro + f"_ENUM_VAL_{prop.val}_EXISTS"] = 1
if "phandle" in prop.type:
macro2val.update(phandle_macros(prop, macro))