Alias drive me a bit crazy, I like them but originally understanding their rules and behaviors was difficult. At first I would get agitated trying to get builds to work, but here is the short story of using them.
You may wonder, why use them at all. There are numerous ways to reference devicetree object. I use them because they are simple syntax in source code and they allow me to preserve details about implementation in the actual devicetree.
I consistently create an alias for the devices I use in a project, below is an alias to a WS2812 item LooUQ uses in many internal and customer projects.
/ {
aliases {
rgb-led = &led_strip;
};
};
| Bad pattern | Why it is bad |
| RGB-LED | Violates the regular expression [a-z0-9-]. Capital letters are not permitted, so using caps for acronyms is not allowed. |
| rgb_led | Also violates the regular expression [a-z0-9-]. The only separator allowed is the dash. This is especially maddening since the build system will convert the acceptible dash (-) into an underscore (_) in the generated devicetree_generated.h for your source code to use. The alias name: "rgb-led" is converted by the build system into "rgb_led" (technically it becomes DT_N_ALIAS_rgb_led) |
To see how the devicetree ends up as a project consumable resource look in this path/file.
<build-director>\<project-name>\zephyr\include\generated\zephyr\ devicetree_generated.h
The alias macros generated by the build system may be precise , but that are not exactly human-readable. That is were the DT_ALIAS() macro comes in handy. RGBLED = &led_strip