Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
invensense2.h File Reference

Driver for the Invensense V2 IMUs ICM20948, ICM20648 and ICM20649. More...

#include "std.h"
#include "mcu_periph/spi.h"
#include "mcu_periph/i2c.h"
+ Include dependency graph for invensense2.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  invensense2_spi_t
 
struct  invensense2_i2c_t
 
struct  invensense2_t
 
union  invensense2_t.__unnamed323__
 

Macros

#define INVENSENSE2_SAMPLE_CNT   22
 
#define INVENSENSE2_SAMPLE_SIZE   14
 
#define INVENSENSE2_BUFFER_SIZE   ((INVENSENSE2_SAMPLE_SIZE*INVENSENSE2_SAMPLE_CNT) + 3)
 

Enumerations

enum  invensense2_bus_t { INVENSENSE2_SPI , INVENSENSE2_I2C }
 
enum  invensense2_status_t { INVENSENSE2_IDLE , INVENSENSE2_CONFIG , INVENSENSE2_RUNNING }
 
enum  invensense2_device_t { INVENSENSE2_UNKOWN , INVENSENSE2_ICM20648 , INVENSENSE2_ICM20649 , INVENSENSE2_ICM20948 }
 
enum  invensense2_gyro_dlpf_t {
  INVENSENSE2_GYRO_DLPF_OFF , INVENSENSE2_GYRO_DLPF_229HZ , INVENSENSE2_GYRO_DLPF_188HZ , INVENSENSE2_GYRO_DLPF_154HZ ,
  INVENSENSE2_GYRO_DLPF_73HZ , INVENSENSE2_GYRO_DLPF_36HZ , INVENSENSE2_GYRO_DLPF_18HZ , INVENSENSE2_GYRO_DLPF_9HZ ,
  INVENSENSE2_GYRO_DLPF_377HZ
}
 
enum  invensense2_gyro_range_t {
  INVENSENSE2_GYRO_RANGE_250DPS , INVENSENSE2_GYRO_RANGE_500DPS , INVENSENSE2_GYRO_RANGE_1000DPS , INVENSENSE2_GYRO_RANGE_2000DPS ,
  INVENSENSE2_GYRO_RANGE_4000DPS
}
 
enum  invensense2_accel_dlpf_t {
  INVENSENSE2_ACCEL_DLPF_OFF , INVENSENSE2_ACCEL_DLPF_265HZ , INVENSENSE2_ACCEL_DLPF_136HZ , INVENSENSE2_ACCEL_DLPF_69HZ ,
  INVENSENSE2_ACCEL_DLPF_34HZ , INVENSENSE2_ACCEL_DLPF_17HZ , INVENSENSE2_ACCEL_DLPF_8HZ , INVENSENSE2_ACCEL_DLPF_499HZ
}
 
enum  invensense2_accel_range_t {
  INVENSENSE2_ACCEL_RANGE_2G , INVENSENSE2_ACCEL_RANGE_4G , INVENSENSE2_ACCEL_RANGE_8G , INVENSENSE2_ACCEL_RANGE_16G ,
  INVENSENSE2_ACCEL_RANGE_30G
}
 

Functions

void invensense2_init (struct invensense2_t *inv)
 Initialize the invensense v2 sensor instance. More...
 
void invensense2_periodic (struct invensense2_t *inv)
 Should be called periodically to request sensor readings. More...
 
void invensense2_event (struct invensense2_t *inv)
 Should be called in the event thread. More...
 

Detailed Description

Driver for the Invensense V2 IMUs ICM20948, ICM20648 and ICM20649.

Definition in file invensense2.h.


Data Structure Documentation

◆ invensense2_spi_t

struct invensense2_spi_t

Definition at line 42 of file invensense2.h.

+ Collaboration diagram for invensense2_spi_t:
Data Fields
struct spi_periph * p Peripheral device for communication.
volatile uint8_t rx_buf[INVENSENSE2_BUFFER_SIZE] Receive buffer.
uint8_t slave_idx Slave index used for Slave Select.
struct spi_transaction trans Transaction used during configuration and measurements.
volatile uint8_t tx_buf[2] Transmit buffer.

◆ invensense2_i2c_t

struct invensense2_i2c_t

Definition at line 52 of file invensense2.h.

+ Collaboration diagram for invensense2_i2c_t:
Data Fields
struct i2c_periph * p Peripheral device for communication.
uint8_t slave_addr The I2C slave address on the bus.
struct i2c_transaction trans TRansaction used during configuration and measurements.

◆ invensense2_t

struct invensense2_t

Definition at line 123 of file invensense2.h.

Data Fields
union invensense2_t __unnamed__
uint8_t abi_id The ABI id used to broadcast the device measurements.
enum invensense2_accel_dlpf_t accel_dlpf Accelerometer DLPF configuration.
enum invensense2_accel_range_t accel_range Accelerometer range configuration.
enum invensense2_bus_t bus The communication bus used to connect the device SPI/I2C.
uint8_t config_idx The current configuration index.
enum invensense2_device_t device The device type detected.
enum invensense2_gyro_dlpf_t gyro_dlpf Gyro DLPF configuration.
enum invensense2_gyro_range_t gyro_range Gyro range configuration.
uint8_t register_bank The current register bank communicating with.
enum invensense2_status_t status Status of the invensense V2 device.
float timebase_correction_pll Timebase correction factor for the PLL clock.
uint32_t timer Used to time operations during configuration (samples left during measuring)

◆ invensense2_t.__unnamed323__

union invensense2_t.__unnamed323__

Definition at line 129 of file invensense2.h.

Data Fields
struct invensense2_i2c_t i2c I2C specific configuration.
struct invensense2_spi_t spi SPI specific configuration.

Macro Definition Documentation

◆ INVENSENSE2_BUFFER_SIZE

#define INVENSENSE2_BUFFER_SIZE   ((INVENSENSE2_SAMPLE_SIZE*INVENSENSE2_SAMPLE_CNT) + 3)

Definition at line 39 of file invensense2.h.

◆ INVENSENSE2_SAMPLE_CNT

#define INVENSENSE2_SAMPLE_CNT   22

Definition at line 37 of file invensense2.h.

◆ INVENSENSE2_SAMPLE_SIZE

#define INVENSENSE2_SAMPLE_SIZE   14

Definition at line 38 of file invensense2.h.

Enumeration Type Documentation

◆ invensense2_accel_dlpf_t

Enumerator
INVENSENSE2_ACCEL_DLPF_OFF 
INVENSENSE2_ACCEL_DLPF_265HZ 
INVENSENSE2_ACCEL_DLPF_136HZ 
INVENSENSE2_ACCEL_DLPF_69HZ 
INVENSENSE2_ACCEL_DLPF_34HZ 
INVENSENSE2_ACCEL_DLPF_17HZ 
INVENSENSE2_ACCEL_DLPF_8HZ 
INVENSENSE2_ACCEL_DLPF_499HZ 

Definition at line 102 of file invensense2.h.

◆ invensense2_accel_range_t

Enumerator
INVENSENSE2_ACCEL_RANGE_2G 

Not possible for ICM20649.

INVENSENSE2_ACCEL_RANGE_4G 
INVENSENSE2_ACCEL_RANGE_8G 
INVENSENSE2_ACCEL_RANGE_16G 
INVENSENSE2_ACCEL_RANGE_30G 

Only possible for ICM20649.

Definition at line 114 of file invensense2.h.

◆ invensense2_bus_t

Enumerator
INVENSENSE2_SPI 
INVENSENSE2_I2C 

Definition at line 59 of file invensense2.h.

◆ invensense2_device_t

Enumerator
INVENSENSE2_UNKOWN 
INVENSENSE2_ICM20648 
INVENSENSE2_ICM20649 
INVENSENSE2_ICM20948 

Definition at line 72 of file invensense2.h.

◆ invensense2_gyro_dlpf_t

Enumerator
INVENSENSE2_GYRO_DLPF_OFF 
INVENSENSE2_GYRO_DLPF_229HZ 
INVENSENSE2_GYRO_DLPF_188HZ 
INVENSENSE2_GYRO_DLPF_154HZ 
INVENSENSE2_GYRO_DLPF_73HZ 
INVENSENSE2_GYRO_DLPF_36HZ 
INVENSENSE2_GYRO_DLPF_18HZ 
INVENSENSE2_GYRO_DLPF_9HZ 
INVENSENSE2_GYRO_DLPF_377HZ 

Definition at line 80 of file invensense2.h.

◆ invensense2_gyro_range_t

Enumerator
INVENSENSE2_GYRO_RANGE_250DPS 

Not possible for ICM20649.

INVENSENSE2_GYRO_RANGE_500DPS 
INVENSENSE2_GYRO_RANGE_1000DPS 
INVENSENSE2_GYRO_RANGE_2000DPS 
INVENSENSE2_GYRO_RANGE_4000DPS 

Only possible for ICM20649.

Definition at line 93 of file invensense2.h.

◆ invensense2_status_t

Enumerator
INVENSENSE2_IDLE 
INVENSENSE2_CONFIG 
INVENSENSE2_RUNNING 

Definition at line 65 of file invensense2.h.

Function Documentation

◆ invensense2_event()

void invensense2_event ( struct invensense2_t inv)

Should be called in the event thread.

  • Checks the response of the WHO_AM_I reading
  • Configures the sensor and reads the responses
  • Parse and request the sensor data from the FIFO buffers
Parameters
invThe invensense v2 instance

Definition at line 152 of file invensense2.c.

References invensense2_t::bus, invensense2_t::config_idx, invensense2_t::device, I2CTransDone, I2CTransFailed, I2CTransSuccess, INV2_WHOAMI_ICM20648, INV2_WHOAMI_ICM20649, INV2_WHOAMI_ICM20948, INV2REG_BANK_SEL, INV2REG_FIFO_COUNTH, invensense2_config(), INVENSENSE2_CONFIG, invensense2_fix_config(), INVENSENSE2_I2C, INVENSENSE2_ICM20648, INVENSENSE2_ICM20649, INVENSENSE2_ICM20948, INVENSENSE2_IDLE, invensense2_parse_data(), invensense2_register_read(), INVENSENSE2_RUNNING, INVENSENSE2_SAMPLE_SIZE, INVENSENSE2_SPI, invensense2_t::register_bank, SPITransDone, SPITransFailed, SPITransSuccess, invensense2_t::status, and invensense2_t::timer.

Referenced by imu_cube_event(), and imu_pixhawk6x_event().

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

◆ invensense2_init()

void invensense2_init ( struct invensense2_t inv)

Initialize the invensense v2 sensor instance.

Parameters
invThe structure containing the configuration of the invensense v2 instance

Definition at line 79 of file invensense2.c.

References invensense2_t::bus, invensense2_t::config_idx, invensense2_t::device, I2CTransDone, INVENSENSE2_IDLE, INVENSENSE2_SPI, INVENSENSE2_UNKOWN, invensense2_t::register_bank, SPICphaEdge2, SPICpolIdleHigh, SPIDiv16, SPIDss8bit, SPIMSBFirst, SPISelectUnselect, SPITransDone, and invensense2_t::status.

Referenced by imu_cube_init(), and imu_pixhawk6x_init().

+ Here is the caller graph for this function:

◆ invensense2_periodic()

void invensense2_periodic ( struct invensense2_t inv)

Should be called periodically to request sensor readings.

  • First detects the sensor using WHO_AM_I reading
  • Configures the sensor according the users requested configuration
  • Requests a sensor reading by reading the FIFO_COUNT register
Parameters
invThe invensense v2 instance

Definition at line 119 of file invensense2.c.

References invensense2_t::bus, I2CTransDone, INV2REG_FIFO_COUNTH, INV2REG_WHO_AM_I, invensense2_config(), INVENSENSE2_CONFIG, INVENSENSE2_I2C, INVENSENSE2_IDLE, invensense2_register_read(), INVENSENSE2_RUNNING, INVENSENSE2_SPI, SPITransDone, and invensense2_t::status.

Referenced by imu_cube_periodic(), and imu_pixhawk6x_periodic().

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