Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Migrating LSM6DSL Custom FIFO and Interrupts Implementation from nRF to Zephyr SDK: Seeking Guidance

Hello Everyone,

I am currently in the process of migrating code for step detection using LSM6DSL, written for an older version of the nRF SDK, to the latest Zephyr SDK.

My primary query revolves around setting up custom interrupts and attributes for the LSM6DSL sensor in the Zephyr environment. I am looking to understand whether I need to directly access the I2C driver and edit LSM6DSL registers there, or if Zephyr's abstraction layer allows for the configuration of custom thresholds and interrupt triggers.

To be more specific, my goal is to create a function that triggers when the FIFO buffer in the LSM6DSL sensor is full. Additionally, I want to be able to set the threshold for the FIFO buffer size, enable the pedometer function in LSM6DSL, among other things, all during the runtime of the program.

In the older nRF SDK, before the Zephyr adaptation, this task was quite straightforward. For instance, I could independently set each register and configure custom trigger values for FIFO.

Here is the snippet of code from the old sdk version. 


uint8_t imu_continious_to_fifo_setup(stmdev_ctx_t *ctx, uint16_t fifo_size)
{
    /*
     *  Enable Block Data Update
     */
    lsm6dsl_block_data_update_set(ctx, PROPERTY_ENABLE);
    lsm6dsl_auto_increment_set(ctx, PROPERTY_ENABLE);

    /* Before changing FIFO settings the device must be in bypass mode */
    lsm6dsl_fifo_mode_set(ctx, LSM6DSL_BYPASS_MODE);

    /* Set power modes for accelerometer and gyroscope */
    lsm6dsl_xl_power_mode_set(ctx, LSM6DSL_XL_NORMAL);
    lsm6dsl_gy_power_mode_set(ctx, LSM6DSL_GY_NORMAL);

    /* Set Output Data Rate and full scale for accelerometer */
    lsm6dsl_xl_data_rate_set(ctx, LSM6DSL_XL_ODR_52Hz);
    lsm6dsl_xl_full_scale_set(ctx, LSM6DSL_2g);

    /* Set Output Data Rate and full scale for gyroscope */
    lsm6dsl_gy_data_rate_set(ctx, LSM6DSL_GY_ODR_OFF); 
    lsm6dsl_gy_full_scale_set(ctx, LSM6DSL_500dps);

    /* Set FIFO trigger - acc data ready signal */
    lsm6dsl_fifo_write_trigger_set(ctx, LSM6DSL_TRG_XL_GY_DRDY);
    /* Set watermark level(size of FIFO) */
    lsm6dsl_fifo_watermark_set(ctx, fifo_size * IMU_NUM_OF_AXIS + 3);
    /* Enable FIFO threshold */
    lsm6dsl_fifo_stop_on_wtm_set(ctx, PROPERTY_ENABLE);

    /* Decimation - data to be stored in FIFO */
    lsm6dsl_fifo_gy_batch_set(ctx, LSM6DSL_FIFO_GY_DISABLE); // SPREMENJENO IZ NEKI
    lsm6dsl_fifo_xl_batch_set(ctx, LSM6DSL_FIFO_XL_NO_DEC);
    lsm6dsl_fifo_dataset_3_batch_set(ctx, LSM6DSL_FIFO_DS3_DISABLE);
    lsm6dsl_fifo_dataset_4_batch_set(ctx, LSM6DSL_FIFO_DS4_DISABLE);

    /* FIFO data rate and mode */
    lsm6dsl_fifo_data_rate_set(ctx, LSM6DSL_FIFO_52Hz);
    lsm6dsl_fifo_mode_set(ctx, LSM6DSL_BYPASS_MODE);
    lsm6dsl_fifo_mode_set(ctx, LSM6DSL_STREAM_TO_FIFO_MODE);

    return EXIT_SUCCESS;
}

Now in the newer sdk (zephyr) I added the lsm6dsl as i2c device and added interrupt pins. The basic lsm6dsl example provided by zephyr works fine.

&i2c1 {
	compatible = "nordic,nrf-twim";
	status = "okay";
	pinctrl-0 = <&i2c1_default>;
	pinctrl-1 = <&i2c1_sleep>;
	pinctrl-names = "default", "sleep";
	clock-frequency = <I2C_BITRATE_STANDARD>;
	lsm6dsl: lsm6dsl@6a {
		compatible = "st,lsm6dsl";
		status = "okay";
		reg = <0x6a>;
		irq-gpios = <&gpio0 22 GPIO_ACTIVE_HIGH>,<&gpio0 25 GPIO_ACTIVE_HIGH>;

	};
};

Now, I want to add FIFO functionality. In the previous version of the SDK, I would typically use I2C to directly write to the registers of LSM6DSL, enabling interrupts and setting the required thresholds. I'm wondering if this same approach is applicable in the context of Zephyr.

Currently, when setting sensor attributes, I am using sensor_attr_get(device, sensor_channel, sensor_attribute, sensor_value). This method works well for simple configurations. Indeed, in sensor.h, I found the definitions for setting properties like sampling frequency, sensor scale ..., also interrupt triggers for double tap or single tap ect.

However, i can't find the option to set FIFO, or to define other specific features or triggers of LSM6DSL like interrupts within the sensor.

So, I would like to revisit my original question: Have I overlooked something in the Zephyr SDK that could assist me in setting up these features, or am I required to manually access the registers of LSM6DSL using I2C, as I used to do with the old SDK?

Thank you for your help.

Parents Reply Children
Related