Configure lsm6dso using sensor.h and lsm6dso.h API

From zephyr/samples/sensor/lsm6dso, I found the following code using sensor_channel_get(). API from sensor.h.  

 
}
static void fetch_and_display(const struct device *dev)
{
    struct sensor_value x, y, z;
    static int trig_cnt;

    trig_cnt++;

    /* lsm6dso accel */
    sensor_sample_fetch_chan(dev, SENSOR_CHAN_ACCEL_XYZ);
    sensor_channel_get(dev, SENSOR_CHAN_ACCEL_X, &x);
    sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Y, &y);
    sensor_channel_get(dev, SENSOR_CHAN_ACCEL_Z, &z);

    printf("accel x:%f ms/2 y:%f ms/2 z:%f ms/2\n",
           out_ev(&x), out_ev(&y), out_ev(&z));

    /* lsm6dso gyro */
    sensor_sample_fetch_chan(dev, SENSOR_CHAN_GYRO_XYZ);
    sensor_channel_get(dev, SENSOR_CHAN_GYRO_X, &x);
    sensor_channel_get(dev, SENSOR_CHAN_GYRO_Y, &y);
    sensor_channel_get(dev, SENSOR_CHAN_GYRO_Z, &z);

    printf("gyro x:%f dps y:%f dps z:%f dps\n",
           out_ev(&x), out_ev(&y), out_ev(&z));

    printf("trig_cnt:%d\n\n", trig_cnt);
}

However, there are more driver API in zephyr/drivers/sensor/lsm6dso

For example

static int lsm6dso_gyro_config(const struct device *dev,
			       enum sensor_channel chan,
			       enum sensor_attribute attr,
			       const struct sensor_value *val)

I could not find the corresponding sensor_gyro_config() API in sensor.h. 

What is the proper way to use API to configure the lsm6dso chip ??

Thanks,

JC

Parents Reply Children
  • Hello Hakon,

    Thanks again for your quick response.  It will take time for the zephyr folk to support the FIFO mode, so I will need to do by myself.

    There are five function calls in the sensor_driver_api 

    __subsystem struct sensor_driver_api {
    sensor_attr_set_t attr_set;
    sensor_attr_get_t attr_get;
    sensor_trigger_set_t trigger_set;
    sensor_sample_fetch_t sample_fetch;
    sensor_channel_get_t channel_get;
    };
     
    I may add the 6th function
    sensor_fifo_config_set;
    to set the fifo water mark threshold, data compression, .....etc
    or expand more attributes and use the existing sensor_attr_set_t attr_set;
    or just modify the lsm6dso_init() to configure the FIFO without messing around with the sensor API
    Hope this works.
    Do you have better ideas ??
    Thanks,
    JC
  • Hi JC,

     

    jchan12345 said:
    I may add the 6th function
    sensor_fifo_config_set;
    to set the fifo water mark threshold, data compression, .....etc
    or expand more attributes and use the existing sensor_attr_set_t attr_set;
    or just modify the lsm6dso_init() to configure the FIFO without messing around with the sensor API
    Hope this works.
    Do you have better ideas ??

    You'll need to add support in the driver itself, meaning that you'll have to expand the "lsm6dso.c" port file (and possibly the kconfig around the port). I am not familiar with the IC, so I cannot give direct feedback on the FIFO functionality, as it might require more than just setting the register, meaning that the helper functions may also need to be adjusted to support this mode.

     

    Kind regards,

    Håkon

  • Hello Hakon, 

    Thanks for your response.  I will just need to write some code to implement it.  You may close this ticket

    Thanks,

    JC

Related