ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
imu_lsm6dsv16x.c File Reference

The sensor-hub configuration sequence follows the official ST example lsm6dsv16x_sensor_hub.c (STMems_Standard_C_drivers), with explicit timeouts instead of infinite loops. More...

#include "imu_lsm6dsv16x.h"
#include <string.h>
Include dependency graph for imu_lsm6dsv16x.c:

Go to the source code of this file.

Macros

#define LIS2MDL_ADDR_8BIT   0x3Du /* same as LIS2MDL_I2C_ADD in lis2mdl_reg.h */
 
#define LIS2MDL_WHO_AM_I   0x4Fu
 
#define LIS2MDL_ID   0x40u
 
#define LIS2MDL_CFG_A   0x60u
 
#define LIS2MDL_CFG_B   0x61u
 
#define LIS2MDL_CFG_C   0x62u
 
#define LIS2MDL_OUTX_L   0x68u
 
#define LIS2MDL_UT_PER_LSB   0.15f
 
#define LPS22_ADDR_8BIT_H   0xBAu /* SA0 = 1 -> 0x5D */
 
#define LPS22_ADDR_8BIT_L   0xB8u /* SA0 = 0 -> 0x5C */
 
#define LPS22_WHO_AM_I   0x0Fu
 
#define LPS22DF_ID   0xB4u
 
#define LPS22HB_ID   0xB1u
 
#define LPS22_CTRL_REG1   0x10u
 
#define LPS22_CTRL_REG2   0x11u
 
#define LPS22_PRESS_OUT_XL   0x28u /* PRESS XL, L, H, TEMP L, H */
 
#define DEG2RAD_F   0.017453292519943295f
 
#define SH_POLL_MAX   50u /* x 5 ms */
 

Functions

static void dly (imu_t *imu, uint32_t ms)
 
static int32_t sh_run_once (imu_t *imu)
 
static int32_t sh_write (imu_t *imu, uint8_t addr8, uint8_t reg, uint8_t val)
 
static int32_t sh_read (imu_t *imu, uint8_t addr8, uint8_t reg, uint8_t *buf, uint8_t len)
 
static int32_t mag_setup (imu_t *imu, uint8_t fast)
 
static int32_t baro_setup (imu_t *imu)
 
int32_t imu_init (imu_t *imu, const sensor_bus_t *bus, const imu_config_t *cfg)
 
int32_t imu_fifo_level (imu_t *imu, uint16_t *words)
 Number of 7-byte words in the FIFO.
 
int32_t imu_fifo_read_burst (imu_t *imu, uint8_t *raw, uint16_t words)
 Blocking read via sensor_bus (for tests or when DMA is not used)
 
static int16_t le16 (const uint8_t *p)
 
size_t imu_fifo_parse (imu_t *imu, const uint8_t *raw, uint16_t words, imu_event_t *ev, size_t cap, imu_parse_stats_t *st)
 Decodes 'words' words read in a burst from IMU_FIFO_REG.
 

Detailed Description

The sensor-hub configuration sequence follows the official ST example lsm6dsv16x_sensor_hub.c (STMems_Standard_C_drivers), with explicit timeouts instead of infinite loops.

Definition in file imu_lsm6dsv16x.c.

Macro Definition Documentation

◆ LIS2MDL_ADDR_8BIT

#define LIS2MDL_ADDR_8BIT   0x3Du /* same as LIS2MDL_I2C_ADD in lis2mdl_reg.h */

Definition at line 12 of file imu_lsm6dsv16x.c.

◆ LIS2MDL_WHO_AM_I

#define LIS2MDL_WHO_AM_I   0x4Fu

Definition at line 13 of file imu_lsm6dsv16x.c.

◆ LIS2MDL_ID

#define LIS2MDL_ID   0x40u

Definition at line 14 of file imu_lsm6dsv16x.c.

◆ LIS2MDL_CFG_A

#define LIS2MDL_CFG_A   0x60u

Definition at line 15 of file imu_lsm6dsv16x.c.

◆ LIS2MDL_CFG_B

#define LIS2MDL_CFG_B   0x61u

Definition at line 16 of file imu_lsm6dsv16x.c.

◆ LIS2MDL_CFG_C

#define LIS2MDL_CFG_C   0x62u

Definition at line 17 of file imu_lsm6dsv16x.c.

◆ LIS2MDL_OUTX_L

#define LIS2MDL_OUTX_L   0x68u

Definition at line 18 of file imu_lsm6dsv16x.c.

◆ LIS2MDL_UT_PER_LSB

#define LIS2MDL_UT_PER_LSB   0.15f

Definition at line 19 of file imu_lsm6dsv16x.c.

◆ LPS22_ADDR_8BIT_H

#define LPS22_ADDR_8BIT_H   0xBAu /* SA0 = 1 -> 0x5D */

Definition at line 22 of file imu_lsm6dsv16x.c.

◆ LPS22_ADDR_8BIT_L

#define LPS22_ADDR_8BIT_L   0xB8u /* SA0 = 0 -> 0x5C */

Definition at line 23 of file imu_lsm6dsv16x.c.

◆ LPS22_WHO_AM_I

#define LPS22_WHO_AM_I   0x0Fu

Definition at line 24 of file imu_lsm6dsv16x.c.

◆ LPS22DF_ID

#define LPS22DF_ID   0xB4u

Definition at line 25 of file imu_lsm6dsv16x.c.

◆ LPS22HB_ID

#define LPS22HB_ID   0xB1u

Definition at line 26 of file imu_lsm6dsv16x.c.

◆ LPS22_CTRL_REG1

#define LPS22_CTRL_REG1   0x10u

Definition at line 27 of file imu_lsm6dsv16x.c.

◆ LPS22_CTRL_REG2

#define LPS22_CTRL_REG2   0x11u

Definition at line 28 of file imu_lsm6dsv16x.c.

◆ LPS22_PRESS_OUT_XL

#define LPS22_PRESS_OUT_XL   0x28u /* PRESS XL, L, H, TEMP L, H */

Definition at line 29 of file imu_lsm6dsv16x.c.

◆ DEG2RAD_F

#define DEG2RAD_F   0.017453292519943295f

Definition at line 31 of file imu_lsm6dsv16x.c.

◆ SH_POLL_MAX

#define SH_POLL_MAX   50u /* x 5 ms */

Definition at line 32 of file imu_lsm6dsv16x.c.

Function Documentation

◆ dly()

static void dly ( imu_t *  imu,
uint32_t  ms 
)
static

Definition at line 34 of file imu_lsm6dsv16x.c.

References imu_t::bus, sensor_bus_t::delay_ms, and ms.

Referenced by baro_setup(), imu_init(), mag_setup(), and sh_run_once().

Here is the caller graph for this function:

◆ sh_run_once()

static int32_t sh_run_once ( imu_t *  imu)
static

Definition at line 37 of file imu_lsm6dsv16x.c.

References imu_t::ctx, dly(), IMU_ERR_BUS, IMU_ERR_SH_TIMEOUT, IMU_OK, ms, and SH_POLL_MAX.

Referenced by sh_read(), and sh_write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sh_write()

static int32_t sh_write ( imu_t *  imu,
uint8_t  addr8,
uint8_t  reg,
uint8_t  val 
)
static

Definition at line 62 of file imu_lsm6dsv16x.c.

References imu_t::ctx, IMU_ERR_BUS, and sh_run_once().

Referenced by baro_setup(), and mag_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sh_read()

static int32_t sh_read ( imu_t *  imu,
uint8_t  addr8,
uint8_t  reg,
uint8_t *  buf,
uint8_t  len 
)
static

Definition at line 71 of file imu_lsm6dsv16x.c.

References imu_t::ctx, IMU_ERR_BUS, IMU_OK, sh_run_once(), and st().

Referenced by baro_setup(), and mag_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mag_setup()

static int32_t mag_setup ( imu_t *  imu,
uint8_t  fast 
)
static

Definition at line 82 of file imu_lsm6dsv16x.c.

References dly(), IMU_ERR_MAG_ID, LIS2MDL_ADDR_8BIT, LIS2MDL_CFG_A, LIS2MDL_CFG_B, LIS2MDL_CFG_C, LIS2MDL_ID, LIS2MDL_WHO_AM_I, sh_read(), sh_write(), and st().

Referenced by imu_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ baro_setup()

static int32_t baro_setup ( imu_t *  imu)
static

Definition at line 100 of file imu_lsm6dsv16x.c.

References addr(), imu_t::baro_addr8, imu_t::baro_model, dly(), IMU_BARO_LPS22DF, IMU_BARO_LPS22HB, IMU_OK, LPS22_ADDR_8BIT_H, LPS22_ADDR_8BIT_L, LPS22_CTRL_REG1, LPS22_CTRL_REG2, LPS22_WHO_AM_I, LPS22DF_ID, LPS22HB_ID, sh_read(), and sh_write().

Referenced by imu_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imu_init()

int32_t imu_init ( imu_t *  imu,
const sensor_bus_t *  bus,
const imu_config_t *  cfg 
)

Definition at line 128 of file imu_lsm6dsv16x.c.

References imu_t::baro_addr8, imu_config_t::baro_enable, imu_t::baro_enabled, baro_setup(), imu_t::baro_slot, imu_t::bus, imu_t::ctx, sensor_bus_t::delay_ms, dly(), imu_config_t::gy_lpf1_bw, sensor_bus_t::handle, IMU_ERR_ARG, IMU_ERR_BUS, IMU_ERR_ID, IMU_ODR_1920HZ, IMU_OK, LIS2MDL_ADDR_8BIT, LIS2MDL_OUTX_L, LPS22_PRESS_OUT_XL, imu_config_t::mag_enable, imu_t::mag_enabled, imu_config_t::mag_fast, mag_setup(), imu_config_t::odr, imu_t::odr_hz, sensor_bus_t::read, st(), imu_config_t::watermark_words, sensor_bus_t::write, imu_config_t::xl_lpf2_bw, and imu_config_t::xl_lpf2_enable.

Referenced by ImuTask().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ imu_fifo_level()

int32_t imu_fifo_level ( imu_t *  imu,
uint16_t *  words 
)

Number of 7-byte words in the FIFO.

Definition at line 216 of file imu_lsm6dsv16x.c.

References imu_t::ctx, IMU_ERR_BUS, IMU_OK, and s.

Referenced by ImuTask().

Here is the caller graph for this function:

◆ imu_fifo_read_burst()

int32_t imu_fifo_read_burst ( imu_t *  imu,
uint8_t *  raw,
uint16_t  words 
)

Blocking read via sensor_bus (for tests or when DMA is not used)

Definition at line 224 of file imu_lsm6dsv16x.c.

References imu_t::bus, sensor_bus_t::handle, IMU_ERR_BUS, IMU_FIFO_MAX_WORDS, IMU_FIFO_REG, IMU_FIFO_WORD_BYTES, IMU_OK, and sensor_bus_t::read.

◆ le16()

static int16_t le16 ( const uint8_t *  p)
static

Definition at line 231 of file imu_lsm6dsv16x.c.

Referenced by imu_fifo_parse().

Here is the caller graph for this function:

◆ imu_fifo_parse()

size_t imu_fifo_parse ( imu_t *  imu,
const uint8_t *  raw,
uint16_t  words,
imu_event_t *  ev,
size_t  cap,
imu_parse_stats_t *  st 
)

Decodes 'words' words read in a burst from IMU_FIFO_REG.

Returns the number of events written to ev (<= cap). Pure function of the data; the only state is the magnetometer duplicate filter.

Definition at line 233 of file imu_lsm6dsv16x.c.

References imu_t::baro_enabled, imu_t::baro_slot, cap, DEG2RAD_F, imu_t::have_baro, imu_t::have_mag, IMU_EV_ACC, IMU_EV_BARO, IMU_EV_GYRO, IMU_EV_MAG, IMU_FIFO_WORD_BYTES, imu_t::last_baro_raw, imu_t::last_mag_raw, le16(), LIS2MDL_UT_PER_LSB, imu_t::mag_enabled, n, slot(), st(), imu_event_t::type, and imu_event_t::v.

Referenced by ImuTask().

Here is the call graph for this function:
Here is the caller graph for this function: