![]() |
ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
|
#include "imu_i2c.h"Go to the source code of this file.
Macros | |
| #define | I2C_TIMEOUT_MS 10u |
| #define | FLAG_DMA_DONE 0x0100u /* bits distinct from the IMU IRQ flag used by the same task */ |
| #define | FLAG_DMA_ERR 0x0200u |
| #define | LOCK_TIMEOUT_MS 5u |
Functions | |
| void | imu_i2c_bus_init (I2C_HandleTypeDef *hi2c) |
| Creates the bus lock: call once before starting the tasks that use the bus. | |
| int | imu_i2c_lock (void) |
| 0 = taken (or no kernel yet), -1 = timeout | |
| void | imu_i2c_unlock (void) |
| I2C_HandleTypeDef * | imu_i2c_handle (void) |
| static int32_t | wr (void *h, uint8_t reg, const uint8_t *d, uint16_t len) |
| static int32_t | rd (void *h, uint8_t reg, uint8_t *d, uint16_t len) |
| static void | dly (uint32_t ms) |
| void | imu_i2c_make_bus (sensor_bus_t *bus, I2C_HandleTypeDef *hi2c, uint8_t addr7) |
| int32_t | imu_i2c_read_dma (uint8_t reg, uint8_t *buf, uint16_t len, uint32_t timeout_ms) |
| Starts the DMA read and blocks the calling task until completion. | |
| void | imu_i2c_rx_cplt_isr (I2C_HandleTypeDef *hi2c) |
| To be called from HAL_I2C_MemRxCpltCallback / HAL_I2C_ErrorCallback. | |
| void | imu_i2c_error_isr (I2C_HandleTypeDef *hi2c) |
Variables | |
| static I2C_HandleTypeDef * | s_hi2c |
| static uint16_t | s_addr8 |
| static osThreadId_t | s_waiter |
| static osMutexId_t | s_lock |
| #define FLAG_DMA_DONE 0x0100u /* bits distinct from the IMU IRQ flag used by the same task */ |
| void imu_i2c_bus_init | ( | I2C_HandleTypeDef * | hi2c | ) |
Creates the bus lock: call once before starting the tasks that use the bus.
Definition at line 21 of file imu_i2c.c.
References s_hi2c, and s_lock.
Referenced by app_start().
| int imu_i2c_lock | ( | void | ) |
0 = taken (or no kernel yet), -1 = timeout
Definition at line 28 of file imu_i2c.c.
References LOCK_TIMEOUT_MS, and s_lock.
Referenced by imu_i2c_read_dma(), rd(), wr(), and xfer().
| void imu_i2c_unlock | ( | void | ) |
| I2C_HandleTypeDef * imu_i2c_handle | ( | void | ) |
|
static |
Definition at line 41 of file imu_i2c.c.
References I2C_TIMEOUT_MS, imu_i2c_lock(), imu_i2c_unlock(), s_addr8, and s_hi2c.
Referenced by imu_i2c_make_bus().
|
static |
Definition at line 51 of file imu_i2c.c.
References I2C_TIMEOUT_MS, imu_i2c_lock(), imu_i2c_unlock(), s_addr8, and s_hi2c.
Referenced by imu_i2c_make_bus().
|
static |
Definition at line 61 of file imu_i2c.c.
References ms.
Referenced by imu_i2c_make_bus().
| void imu_i2c_make_bus | ( | sensor_bus_t * | bus, |
| I2C_HandleTypeDef * | hi2c, | ||
| uint8_t | addr7 | ||
| ) |
Definition at line 66 of file imu_i2c.c.
References sensor_bus_t::delay_ms, dly(), sensor_bus_t::handle, rd(), sensor_bus_t::read, s_addr8, s_hi2c, wr(), and sensor_bus_t::write.
Referenced by ImuTask().
| int32_t imu_i2c_read_dma | ( | uint8_t | reg, |
| uint8_t * | buf, | ||
| uint16_t | len, | ||
| uint32_t | timeout_ms | ||
| ) |
Starts the DMA read and blocks the calling task until completion.
0 = OK, -1 error/timeout.
Definition at line 76 of file imu_i2c.c.
References FLAG_DMA_DONE, FLAG_DMA_ERR, imu_i2c_lock(), imu_i2c_unlock(), s_addr8, s_hi2c, and s_waiter.
Referenced by ImuTask().
| void imu_i2c_rx_cplt_isr | ( | I2C_HandleTypeDef * | hi2c | ) |
To be called from HAL_I2C_MemRxCpltCallback / HAL_I2C_ErrorCallback.
Definition at line 91 of file imu_i2c.c.
References FLAG_DMA_DONE, s_hi2c, and s_waiter.
Referenced by app_i2c_rx_cplt().
| void imu_i2c_error_isr | ( | I2C_HandleTypeDef * | hi2c | ) |
Definition at line 96 of file imu_i2c.c.
References FLAG_DMA_ERR, s_hi2c, and s_waiter.
Referenced by app_i2c_error().
|
static |
Definition at line 12 of file imu_i2c.c.
Referenced by imu_i2c_bus_init(), imu_i2c_error_isr(), imu_i2c_handle(), imu_i2c_make_bus(), imu_i2c_read_dma(), imu_i2c_rx_cplt_isr(), rd(), and wr().
|
static |
Definition at line 13 of file imu_i2c.c.
Referenced by imu_i2c_make_bus(), imu_i2c_read_dma(), rd(), and wr().
|
static |
Definition at line 14 of file imu_i2c.c.
Referenced by imu_i2c_error_isr(), imu_i2c_read_dma(), and imu_i2c_rx_cplt_isr().
|
static |
Definition at line 15 of file imu_i2c.c.
Referenced by imu_i2c_bus_init(), imu_i2c_lock(), and imu_i2c_unlock().