I am developing an application under Zephyr RTOS that has a few similar illuminance sensors. I have added a few child nodes to the I²C 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 the illuminance-sensor
alias instead of opt3001_0
and opt3001_1
node labels. So in the 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 the devicetree compiler throws the error:
"All properties in aliases must be singular".
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 labels.
I am developing an application under Zephyr RTOS that has a few similar illuminance sensors. I have added a few child nodes to the I²C 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 the illuminance-sensor
alias instead of opt3001_0
and opt3001_1
node labels. So in the 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 the devicetree compiler throws the error:
"All properties in aliases must be singular".
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 labels.
Share Improve this question edited Mar 9 at 7:30 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Jan 30 at 16:54 Dmitry SesDmitry Ses 31 bronze badge 2- "What is the best way to reference a few nodes through a single alias?" - There's no "best way" simply because there is no way possible. The alias can refer to only one node. This is an XY problem that has no solution for Y. – sawdust Commented Jan 31 at 0:18
- You are right. Alias was not suitable for my needs. I was experimenting with it and the best I could do was creating an alias to a node, that has a property with phandles. – Dmitry Ses Commented Jan 31 at 15:12
1 Answer
Reset to default 0You can do this with the zephyr,user devicetree node. See:
Devices