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
I tried to look around but could not find any such guides. However I have provided an answer for this earlier, take a look at it here.
Down below I've provided a short guide how to add a custom sensor to Zephyr
add_subdirectory_ifdef(CONFIG_<name of sensor> <sensor directory>)
source "drivers/sensor/<sensor directory>/Kconfig"
Best regards,
Simon
Thanks for the info. will check and revert.
Hi
Thanks for the info and this is verymuch useful.
I have followed all the steps.
in the sensor c file, i have some like below:
#if defined(DT_VENDOR_CHIPNAME_BUS_SPI) chip_spi_init(dev); #elif defined(DT_VENDOR_CHIPNAME_BUS_I2C) chip_i2c_init(dev); #else #error "BUS MACRO NOT DEFINED IN DTS" #endif
These macros are not getting defined. This is some things to do with zephyr system, but any pointers that would greatly help to proceed.
Could you upload these files:
Best regards,
Simon
Hi
zephyr\dts\bindings\sensor\<compatible string>.yaml -----> Contains tdk,icm20948-i2c.yaml , tdk,icm20948-spi.yaml
tdk,icm20948-spi.yaml
description: | ICM-20948 Nine Axis I2C/SPI MEMS This is a representation of the ICM-20948 Three Axis High-g I2C/SPI accelerometer compatible: "tdk,icm20948" include: spi-device.yaml #inherits: # !include i2c-device.yaml properties: int1-gpios: type: phandle-array required: false description: | The INT1 signal defaults to active high as produced by the sensor. The property value should ensure the flags properly describe the signal that is presented to the driver.
tdk,icm20948-i2c.yaml
description: | ICM-20948 Nine Axis I2C/SPI MEMS This is a representation of the ICM-20948 Three Axis High-g I2C/SPI accelerometer compatible: "tdk,icm20948" include: i2c-device.yaml #inherits: # !include i2c-device.yaml properties: int1-gpios: type: phandle-array required: false description: | The INT1 signal defaults to active high as produced by the sensor. The property value should ensure the flags properly describe the signal that is presented to the driver.
zephyr\samples\sensor\<your sensor>\boards\<board name>.overlay --> I donot have this file. but I have overlay file in my application:nrf9160dk_nrf9160ns.overlay
/* uart0 reserved for debug prints uart1 reserved for modem traces */ /* status = "okay"; disable usart2 to use I2C_2 for ICM20948 */ &uart2 { status = "disabled"; }; &i2c2 { compatible = "nordic,nrf-twim"; status = "okay"; sda-pin = <11>; scl-pin = <12>; clock-frequency = <I2C_BITRATE_STANDARD>; /* The I2C address could be one of two, here 0x68 is assumed */ icm20948@68 { compatible = "tdk,icm20948"; reg = <0x68>; label = "ICM20948"; }; };