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
  • 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)

     

Children
Related