This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Including specific sensor header files

Hi everyone,

I have a board based on thingy91. I have lis2dh and adxl372 sensors on it. They are both connected via SPI, and I've added this to my overlay file:

&spi0 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	sck-pin = <3>;
	mosi-pin = <4>;
	miso-pin = <5>;
	cs-gpios = <&gpio0 8 GPIO_ACTIVE_LOW>, <&gpio0 7 GPIO_ACTIVE_LOW>;

	lis2dh@0 {
		compatible = "st,lis2dh";
		label = "LIS2DH";
		spi-max-frequency = <8000000>;
		reg = <0>;
		irq-gpios = <&gpio0 9 0>;
	};

	adxl372@1 {
		compatible = "adi,adxl372";
		label = "ADXL372";
		spi-max-frequency = <8000000>;
		reg = <1>;
		int1-gpios = <&gpio0 6 0>;
	};
};

Also I've enabled the sensors in the prj.conf. I am able to initialize and get sensor readings, everything works fine there. The issue comes up when I try to include lis2dh.h and adxl372.h in my project. I do this because I want to have access to the SPI bus, and I want to be able to send custom values to the device registers(I wasn't able to find this as an option through the sensor api provided by Zephyr). I've added adxl372 and lis2dh to my list of include directories in top level CMakeLists.txt, and I am able now to include them in my source code. However when compiling, I get the following error:

error: 'const union lis2dh_bus_cfg' has no member named 'spi_cfg'
  122 |     const struct spi_config *spi_cfg = &cfg->bus_cfg.spi_cfg->spi_conf;
 

That's weird, because it is defined to use spi, and the devices do work. So I suspect that the macro DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) is not working well because these files are included in a weird way(directly from my top level cmakelists.txt, instead of the usual way). 

How can I include these files in my source code and use them properly?

Cheers,

Aleksa

Parents Reply Children
No Data
Related