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

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

#include "peripherals/invensense2.h"
#include "peripherals/invensense2_regs.h"
#include "math/pprz_isa.h"
#include "math/pprz_algebra_int.h"
#include "modules/imu/imu.h"
#include "modules/core/abi.h"
#include "mcu_periph/gpio_arch.h"
+ Include dependency graph for invensense2.c:

Go to the source code of this file.

Functions

static void invensense2_parse_data (struct invensense2_t *inv, volatile uint8_t *data, uint16_t len)
 Parse the FIFO buffer data. More...
 
static void invensense2_fix_config (struct invensense2_t *inv)
 This fixes the configuration errors and sets the correct scalings. More...
 
static bool invensense2_register_write (struct invensense2_t *inv, uint16_t bank_reg, uint8_t value)
 Write a register based on a combined bank/regsiter value. More...
 
static bool invensense2_register_read (struct invensense2_t *inv, uint16_t bank_reg, uint16_t size)
 Read a register based on a combined bank/regsiter value. More...
 
static bool invensense2_select_bank (struct invensense2_t *inv, uint8_t bank)
 Select the correct register bank. More...
 
static bool invensense2_config (struct invensense2_t *inv)
 Configure the Invensense 2 device register by register. More...
 
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...
 

Variables

static const struct Int32Rates invensense2_gyro_scale [5][2]
 
static const struct Int32Vect3 invensense2_accel_scale [5][2]
 

Detailed Description

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

Definition in file invensense2.c.

Function Documentation

◆ invensense2_config()

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

static void invensense2_fix_config ( struct invensense2_t inv)
static

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

static void invensense2_parse_data ( struct invensense2_t inv,
volatile uint8_t data,
uint16_t  len 
)
static

Parse the FIFO buffer data.

Parameters
invThe invensense v2 instance
dataThe FIFO buffer data to parse
lenThe length of the FIFO buffer

Definition at line 277 of file invensense2.c.

References invensense2_t::abi_id, invensense2_t::accel_dlpf, get_sys_time_usec(), invensense2_t::gyro_dlpf, INVENSENSE2_ACCEL_DLPF_OFF, INVENSENSE2_GYRO_DLPF_OFF, INVENSENSE2_SAMPLE_CNT, INVENSENSE2_SAMPLE_SIZE, Int32Rates::p, Int32Rates::q, Int32Rates::r, invensense2_t::timebase_correction_pll, Int32Vect3::x, Int32Vect3::y, and Int32Vect3::z.

Referenced by invensense2_event().

+ Here is the call graph for this function:
+ 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:

◆ invensense2_register_read()

static bool invensense2_register_read ( struct invensense2_t inv,
uint16_t  bank_reg,
uint16_t  size 
)
static

Read a register based on a combined bank/regsiter value.

Parameters
invThe invensense v2 instance
bank_regThe bank is shifted 8 bits left, adn register is &0xFF
sizeThe size to read (already 1 is added for the transmission of the register to read)
Returns
true If we initiated the register read succesfully
false First we are busy switching the register bank

Definition at line 392 of file invensense2.c.

References invensense2_t::bus, i2c_transceive(), INV2_READ_FLAG, invensense2_select_bank(), INVENSENSE2_SPI, and spi_submit().

Referenced by invensense2_config(), invensense2_event(), and invensense2_periodic().

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

◆ invensense2_register_write()

static bool invensense2_register_write ( struct invensense2_t inv,
uint16_t  bank_reg,
uint8_t  value 
)
static

Write a register based on a combined bank/regsiter value.

Parameters
invThe invensense v2 instance
bank_regThe bank is shifted 8 bits left, adn register is &0xFF
valueThe value to write to the register
Returns
true Whenever the register write was started
false First we are busy switching the register bank

Definition at line 355 of file invensense2.c.

References invensense2_t::bus, i2c_transmit(), invensense2_select_bank(), INVENSENSE2_SPI, and spi_submit().

Referenced by invensense2_config().

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

◆ invensense2_select_bank()

static bool invensense2_select_bank ( struct invensense2_t inv,
uint8_t  bank 
)
static

Select the correct register bank.

Parameters
invThe invensense v2 instance
bankThe bank ID to select
Returns
true The bank change has been requested
false The register bank is already correct

Definition at line 427 of file invensense2.c.

References invensense2_t::bus, i2c_transmit(), INV2REG_BANK_SEL, INVENSENSE2_SPI, invensense2_t::register_bank, and spi_submit().

Referenced by invensense2_register_read(), and invensense2_register_write().

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

Variable Documentation

◆ invensense2_accel_scale

const struct Int32Vect3 invensense2_accel_scale[5][2]
static
Initial value:
= {
{ {3189, 3189, 3189},
{5203, 5203, 5203} },
{ {6378, 6378, 6378},
{5203, 5203, 5203} },
{ {12756, 12756, 12756},
{5203, 5203, 5203} },
{ {25512, 25512, 25512},
{5203, 5203, 5203} },
{ {51024, 51024, 51024},
{5203, 5203, 5203} }
}

Definition at line 44 of file invensense2.c.

Referenced by invensense2_fix_config().

◆ invensense2_gyro_scale

const struct Int32Rates invensense2_gyro_scale[5][2]
static
Initial value:
= {
{ {30267, 30267, 30267},
{55463, 55463, 55463} },
{ {60534, 60534, 60534},
{55463, 55463, 55463} },
{ {40147, 40147, 40147},
{18420, 18420, 18420} },
{ {40147, 40147, 40147},
{9210, 9210, 9210} },
{ {40147, 40147, 40147},
{4605, 4605, 4605} }
}

Definition at line 44 of file invensense2.c.

Referenced by invensense2_fix_config().