lis2dw12 sensor configuration.

Hello,

I have a question regarding sensor configuration. I am planning to use the LIS2DW12 sensor. While reviewing the SDK, I found the source code in the path sdk\zephyr\drivers\sensor\lis2dw12. However, I discovered that the lis2dw12_init function is static, so it cannot be called externally.

Could you please explain how to use this function?

Parents
  • Hi

    I would have a look at how we how we use the Zephyrs sensor lib here. The drivers that comes with Zephyr is written with the Zephyr Sensing subsystem in mind, you can the documentation for it here
    Regards

    Runar

  • When using DEVICE_DT_GET, I get the device pointer, but when I use I2C_DT_SPEC_GET as in the example, an error occurs.

    I'm using the 52833 chip, and below is the overlay configuration.

    And in src.c, I accessed it using the device pointer.

    There is no build error, and the device is successfully retrieved.

    Next, I tried using I2C_DT_SPEC_GET as in the example. dts code is the same as before.


    When I execute it, the following error occurs.

    What is the reason for this error and how can it be resolved?
  • Hi

    I suspect that it does not like that your struct lis2dw12_spec is defined and if you change it to

    static const struct i2c_dt_spec lis2dw12_spec = I2C_DT_SPEC_GET(I2C_NODE);
    
    

    it will work.

    Regards

    Runar

  • Hi.

    I have resolved the error.

    However, I have an additional question.

    When declaring static struct i2c_dt_spec i2c_lis2dw12 = I2C_DT_SPEC_GET(LIS2DW12_NODE);, I discovered that the bus->config inside i2c_lis2dw12 is void.
    I tried to configure it, but the bus variable is declared as const, making it unmodifiable.

    ///////
    struct i2c_dt_spec {
    const struct device *bus;
    uint16_t addr;
    };
    ////////

    Is there a way to initialize the config or api inside the bus when declaring the static struct i2c_dt_spec i2c_lis2dw12 variable?

Reply
  • Hi.

    I have resolved the error.

    However, I have an additional question.

    When declaring static struct i2c_dt_spec i2c_lis2dw12 = I2C_DT_SPEC_GET(LIS2DW12_NODE);, I discovered that the bus->config inside i2c_lis2dw12 is void.
    I tried to configure it, but the bus variable is declared as const, making it unmodifiable.

    ///////
    struct i2c_dt_spec {
    const struct device *bus;
    uint16_t addr;
    };
    ////////

    Is there a way to initialize the config or api inside the bus when declaring the static struct i2c_dt_spec i2c_lis2dw12 variable?

Children
Related