Hi
Apologies in advance if my terminology is all wrong for the following question.
I am trying to write some i2c functions that will compile / work for any of I2C peripherals specified in the device tree.
My starting point is the Peripheral UART project for the nRF5340 DK.
In this case, I have added a definition for I2C2 in an overlay file.
So. in my code, I can reference “i2c1” and “i2c2”.
For example:
i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c1));
If I reference i2c0, the build fails.
For example:
i2c_dev = DEVICE_DT_GET(DT_NODELABEL(i2c0));
Build fails:
undefined reference to `__device_dts_ord_85'
Question: Is there any way to check at run time whether, say, i2c0 peripheral has been defined in the device tree, so that the code builds etc.?
I tried this:
if (DT_NODE_EXISTS(i2c0)) {
// do something
}
But that returns false for all the i2c peripherals.
I know this is probably because I am mixing up nodes, and node labels, or something like that.
Thanks.
Garrett