I am developnig an application under Zephyr RTOS, that has a few simmilar illuminance sensors. I have added few child nodes to the I2C node like this:
&i2c21 {
status = "okay";
pinctrl-names = "default", "sleep";
opt3001_0: opt3001_0@46 {
compatible = "ti,opt3001";
reg = <0x46>;
status = "okay";
};
opt3001_1: opt3001_1@47 {
compatible = "ti,opt3001";
reg = <0x47>;
status = "okay";
};
};
I can access the sensors in my code using the DEVICE_DT_GET()
and DT_NODELABEL()
macros.
But now I want to do it in a more "high level" way, using aliases. So my code will use illuminance-sensor
alias instead of opt3001_0
and opt3001_1
node labels. So in future I would be able to change the senor (or a number of sensors) without changing the code. I want the alias to do something like this:
/ {
aliases {
illuminance-sensor = &opt3001_0, &opt3001_1;
};
};
But the problem is that devicetree compiler throws the error: "All properties in aliases must be singluar". What is the best way to reference a few nodes through a single alias?
I am expecting to use a single alias to use one or multiple sensors in code without using node lables.
You can do this with the zephyr,user devicetree node : https://docs.zephyrproject.org/latest/build/dts/zephyr-user-node.html#devices