ACwing FC firmware
STM32WB55: attitude IEKF, altitude Kalman filter, flight core, protocol v2
Loading...
Searching...
No Matches
imu_i2c.c File Reference
#include "imu_i2c.h"
Include dependency graph for imu_i2c.c:

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
 

Macro Definition Documentation

◆ I2C_TIMEOUT_MS

#define I2C_TIMEOUT_MS   10u

Definition at line 6 of file imu_i2c.c.

◆ FLAG_DMA_DONE

#define FLAG_DMA_DONE   0x0100u /* bits distinct from the IMU IRQ flag used by the same task */

Definition at line 7 of file imu_i2c.c.

◆ FLAG_DMA_ERR

#define FLAG_DMA_ERR   0x0200u

Definition at line 8 of file imu_i2c.c.

◆ LOCK_TIMEOUT_MS

#define LOCK_TIMEOUT_MS   5u

Definition at line 10 of file imu_i2c.c.

Function Documentation

◆ imu_i2c_bus_init()

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().

Here is the caller graph for this function:

◆ imu_i2c_lock()

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().

Here is the caller graph for this function:

◆ imu_i2c_unlock()

void imu_i2c_unlock ( void  )

Definition at line 34 of file imu_i2c.c.

References s_lock.

Referenced by imu_i2c_read_dma(), rd(), wr(), and xfer().

Here is the caller graph for this function:

◆ imu_i2c_handle()

I2C_HandleTypeDef * imu_i2c_handle ( void  )

Definition at line 39 of file imu_i2c.c.

References s_hi2c.

Referenced by xfer().

Here is the caller graph for this function:

◆ wr()

static int32_t wr ( void *  h,
uint8_t  reg,
const uint8_t *  d,
uint16_t  len 
)
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().

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

◆ rd()

static int32_t rd ( void *  h,
uint8_t  reg,
uint8_t *  d,
uint16_t  len 
)
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().

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

◆ dly()

static void dly ( uint32_t  ms)
static

Definition at line 61 of file imu_i2c.c.

References ms.

Referenced by imu_i2c_make_bus().

Here is the caller graph for this function:

◆ 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().

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

◆ imu_i2c_read_dma()

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().

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

◆ imu_i2c_rx_cplt_isr()

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().

Here is the caller graph for this function:

◆ imu_i2c_error_isr()

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().

Here is the caller graph for this function:

Variable Documentation

◆ s_hi2c

I2C_HandleTypeDef* s_hi2c
static

◆ s_addr8

uint16_t s_addr8
static

Definition at line 13 of file imu_i2c.c.

Referenced by imu_i2c_make_bus(), imu_i2c_read_dma(), rd(), and wr().

◆ s_waiter

osThreadId_t s_waiter
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().

◆ s_lock

osMutexId_t s_lock
static

Definition at line 15 of file imu_i2c.c.

Referenced by imu_i2c_bus_init(), imu_i2c_lock(), and imu_i2c_unlock().