ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
imu_lsm6dsv16x.h
Go to the documentation of this file.
1
17#ifndef IMU_LSM6DSV16X_H
18#define IMU_LSM6DSV16X_H
19
20#include <stdint.h>
21#include <stddef.h>
22#include "sensor_bus.h"
23#include "lsm6dsv16x_reg.h"
24
25#define IMU_I2C_ADDR_7BIT 0x6Bu
26#define IMU_FIFO_REG LSM6DSV16X_FIFO_DATA_OUT_TAG
27#define IMU_FIFO_WORD_BYTES 7u
28#define IMU_FIFO_MAX_WORDS 48u
29typedef enum { IMU_ODR_960HZ = 0, IMU_ODR_1920HZ = 1 } imu_odr_t;
30
31typedef struct {
34 uint8_t gy_lpf1_bw;
36 uint8_t xl_lpf2_bw;
37 uint8_t mag_enable;
38 uint8_t mag_fast;
39 uint8_t baro_enable; /* LPS22DF/LPS22HB via sensor hub, optional: a missing
40 part leaves baro_enabled = 0 and is not an error */
42
44
45/* Sensor-hub re-read rate, used to compute the age of the mag sample */
46#define IMU_SH_HZ(fast) ((fast) ? 120.0f : 60.0f)
47
52
53typedef enum { IMU_EV_GYRO = 1, IMU_EV_ACC = 2, IMU_EV_MAG = 3, IMU_EV_BARO = 4 } imu_ev_type_t;
54
55typedef struct {
56 uint8_t type;
57 float v[3]; /* gyro rad/s, acc g, mag uT (sensor frame);
58 baro: v[0] Pa, v[1] degC */
60
61typedef struct {
62 uint32_t words, gyro, acc, mag, mag_dup, sh_nack, empty, unknown;
63 uint32_t baro, baro_dup;
65
66typedef struct {
67 stmdev_ctx_t ctx;
69 float odr_hz;
70 uint8_t mag_enabled;
71 uint8_t last_mag_raw[6];
72 uint8_t have_mag;
73 uint8_t baro_enabled, baro_model, baro_addr8, baro_slot;
74 uint8_t last_baro_raw[5];
75 uint8_t have_baro;
76} imu_t;
77
78int32_t imu_init(imu_t *imu, const sensor_bus_t *bus, const imu_config_t *cfg);
79
81int32_t imu_fifo_level(imu_t *imu, uint16_t *words);
82
84int32_t imu_fifo_read_burst(imu_t *imu, uint8_t *raw, uint16_t words);
85
89size_t imu_fifo_parse(imu_t *imu, const uint8_t *raw, uint16_t words,
90 imu_event_t *ev, size_t cap, imu_parse_stats_t *st);
91
92#endif /* IMU_LSM6DSV16X_H */
float cap[6][3]
Definition calib_mgr.c:36
imu_status_t
@ IMU_OK
@ IMU_ERR_ARG
@ IMU_ERR_BUS
@ IMU_ERR_MAG_ID
@ IMU_ERR_ID
@ IMU_ERR_SH_TIMEOUT
imu_baro_t
@ IMU_BARO_LPS22DF
@ IMU_BARO_LPS22HB
@ IMU_BARO_NONE
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.
int32_t imu_init(imu_t *imu, const sensor_bus_t *bus, const imu_config_t *cfg)
imu_ev_type_t
@ IMU_EV_BARO
@ IMU_EV_ACC
@ IMU_EV_GYRO
@ IMU_EV_MAG
int32_t imu_fifo_level(imu_t *imu, uint16_t *words)
Number of 7-byte words in the FIFO.
imu_odr_t
@ IMU_ODR_960HZ
@ IMU_ODR_1920HZ
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)
Platform-independent bus interface.
uint8_t mag_fast
0: LIS2MDL 50 Hz / hub 60 Hz; 1: 100 Hz / 120 Hz
uint8_t xl_lpf2_bw
lsm6dsv16x_filt_xl_lp2_bandwidth_t
uint8_t watermark_words
4 = 2 gyro + 2 acc -> one interrupt every 2 samples
uint8_t baro_enable
uint8_t mag_enable
LIS2MDL via sensor hub (requires IKS4A1 Mode 3)
uint8_t gy_lpf1_bw
lsm6dsv16x_filt_gy_lp1_bandwidth_t
imu_odr_t odr
same ODR for gyro and acc
uint8_t xl_lpf2_enable
uint8_t type
imu_ev_type_t
uint8_t baro_addr8
stmdev_ctx_t ctx
float odr_hz
uint8_t have_mag
uint8_t have_baro
uint8_t mag_enabled
sensor_bus_t bus
static USBD_StatusTypeDef st(HAL_StatusTypeDef h)
Definition usbd_conf.c:86