Expand Device Tree enums to C-enum names #59256
Labels
area: Devicetree Tooling
PR modifies or adds a Device Tree tooling
Feature Request
A request for a new feature
Needs review
This PR needs attention from Zephyr's maintainers
Is your feature request related to a problem? Please describe.
While creating the device tree bindings and implementing the parsing of the said bindings, we came across some issues.
In the pre-zephyr times, we had the configuration of these devices in code, with an enum, where every enum value was associated with either direct register values or bit masks to work on the registers.
At the moment we are using included defines inside of the device tree in combination with int-enums in the device tree bindings to reflect this. But from our point of view this has some disadvantages:
Instead of using in the dt-bindings an integer enum, we could use a string enum. Then we are able to access the enum value by using the props
..._ENUM_TOKEN
macro.The string enum will be easier to read in the generated device tree. It will also not generate any overhead in the binaries as these are behind macros in
devicetree_generated.h
. But this also has some drawbacks. First and foremost the configuration will have the full code-enum value which (again) makes the device tree harder to read.Example:
Configuration of a multiplier:
Enumeration:
dt-bindings:
Describe the solution you'd like
The addition necessary for this is a macro to prefix (and maybe postfix) the string enum with the actual code-enum value.
Using the example above
dt-bindings
In code, we would have a macro to access it
The macro
DT_INST_ENUM_PREFIX
will expand then toDEVNAME_MULT_38
Describe alternatives you've considered
An alternative solution would have been to add an additional field(s) in the device-tree syntax which would contain the code-enum prefix and postfix. For this, we would also need to adapt the scripts to generate additional macros into
devicetree_generated.h
.The text was updated successfully, but these errors were encountered: