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 Håkon,

    Thanks for your quick response.  I have a follow up question. 

    The initialization code inzephyr/drivers/sensor/lsm6dso sets the lsm6dso to LSM6DSO_BYPASS_MODE

    I would like to set it to LSM6DSO_FIFO_MODE

    Should I change the zephyr source code or there is another way to change in device tree setting without changing the zephyr source code?   I could not find API in sensor.h to let me change the FIFO setting.  Just want to do it the proper way.

    Thanks,

    JC

     

    static int lsm6dso_init_chip(const struct device *dev)
    {
        .
        .
        .
    
        /* Set FIFO bypass mode */
    	if (lsm6dso_fifo_mode_set(ctx, LSM6DSO_BYPASS_MODE) < 0) {
    		LOG_DBG("failed to set FIFO mode");
    		return -EIO;
    	}
    	
    	.
    	.
    	.
    	
    

    Hope there is a way to change it in DT or using sensor.h API to set the FIFO control registers.

    Something like  sensor_reg_set(uint16_t reg_address, uint8_t reg_value)

    or 

    sensor_reg_set(const struct device *dev, uint16_t reg_address, uint8_t reg_value)

     

  • Hi,

     

    FIFO mode does not seem to be supported in the lsm6dso port file. I would recommend that you open a issue in the zephyr project github page:

    https://github.com/zephyrproject-rtos/zephyr/issues

     

    Looks like this is similar to this issue:

    https://github.com/zephyrproject-rtos/zephyr/issues/26830

     

    Kind regards,

    Håkon

  • 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