Description
Is your enhancement proposal related to a problem? Please describe.
Various samples use DT_INST(0, compat) to get the node identifier for a particular compatible. Using instance numbers in samples does more harm than good: explaining the semantics is quite complicated.
(Don't believe me? Have a look at the awful amount of text describing them in the DT_INST documentation.)
Putting the DT_INST macro in front of users just for the sake of getting a device should be considered an antipattern. It also has the problem that it forces users to understand devicetree node identifiers etc., which is a whole additional pile of complexity that 99.9% of people who just want to get a working const struct device*
and move on within a simple sample application don't and should not care about.
Describe the solution you'd like
- Add a new macro,
DEVICE_DT_GET_ANY(compat)
. This takes a devicetree compatible (in lowercase-and-underscore form) and gives you a straight upconst struct device*
created for that devicetree compatible. - Use this in samples that just want to get a device by any means necessary for the purposes of showing off an API or a particular driver's implementation of it
Describe alternatives you've considered
In #30536, I originally tried adding sample specific aliases, but this got shot down for good reasons.