How to add new i2c based sensor device to ncs\v1.3.0\zephyr\drivers\sensor.
Can you suggest any tutorial to do so as i want to use sensor subsystem which in turn uses i2c driver.
Thanks
Chandra
How to add new i2c based sensor device to ncs\v1.3.0\zephyr\drivers\sensor.
Can you suggest any tutorial to do so as i want to use sensor subsystem which in turn uses i2c driver.
Thanks
Chandra
Try to do this:
// You need this in order for DT_ANY_INST_ON_BUS_STATUS_OKAY to work #define DT_DRV_COMPAT tdk_icm20948 // code // code // code #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) //Do stuff #elif DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) //Do stuff #else #error "BUS MACRO NOT DEFINED IN DTS" #endif
Take a look at the zephyr/include/devicetree.h for more information about the macro DT_ANY_INST_ON_BUS_STATUS_OKAY.
Best regards,
Simon
This part i got it. it works for me early this week.
but i have following code in driver.
#if defined(DT_TDK_ICM20948_BUS_SPI)
icm20948_spi_init(dev);
#elif defined(DT_TDK_ICM20948_BUS_I2C)
icm20948_i2c_init(dev);
#else
#error "BUS MACRO NOT DEFINED IN DTS"
#endif
DT_TDK_ICM20948_BUS_SPI, DT_TDK_ICM20948_BUS_I2C: what are these?
I just repalced these with DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) and DT_ANY_INST_ON_BUS_STATUS_OKAY(I2C).
How to enable these macros : DT_TDK_ICM20948_BUS_SPI ,DT_TDK_ICM20948_BUS_I2C? we can just ignore.
I'm not sure where you get those DTS defines from, and why you think those should be generated. Could you give me some pointers?
I think you should be fine using DT_ANY_INST_ON_BUS_STATUS_OKAY and DT_ANY_INST_ON_BUS_STATUS_OKAY, that is what all the other sensor drives in NCS v1.3.0 are using:
https://github.com/nrfconnect/sdk-zephyr/blob/v2.3.0-rc1-ncs1/drivers/sensor/stts751/stts751.c#L207
https://github.com/nrfconnect/sdk-zephyr/blob/v2.3.0-rc1-ncs1/drivers/sensor/lsm6dso/lsm6dso.c#L755
Best regards,
Simon
OK thanks for all the clarifications. Thank you very much.
I could succeed with DT_ANY_INST_ON_BUS_STATUS_OKAY , could communicate with sensor.
Need to improve sensor driver.
for now I am going to close this ticket.
Thanks
Chandra