35 #include "mcu_periph/gpio_arch.h"
48 { {30267, 30267, 30267},
49 {55463, 55463, 55463} },
50 { {60534, 60534, 60534},
51 {55463, 55463, 55463} },
52 { {40147, 40147, 40147},
53 {18420, 18420, 18420} },
54 { {40147, 40147, 40147},
56 { {40147, 40147, 40147},
66 { {12756, 12756, 12756},
68 { {25512, 25512, 25512},
70 { {51024, 51024, 51024},
95 inv->spi.trans.slave_idx = inv->spi.slave_idx;
96 inv->spi.trans.output_length = 0;
97 inv->spi.trans.input_length = 0;
98 inv->spi.trans.before_cb = NULL;
99 inv->spi.trans.after_cb = NULL;
100 inv->spi.trans.input_buf = inv->spi.rx_buf;
101 inv->spi.trans.output_buf = inv->spi.tx_buf;
106 inv->i2c.trans.slave_addr = inv->i2c.slave_addr;
153 volatile uint8_t *rx_buffer, *tx_buffer;
158 rx_buffer = inv->spi.rx_buf;
159 tx_buffer = inv->spi.tx_buf;
160 rx_length = inv->spi.trans.input_length;
163 rx_buffer = inv->i2c.trans.buf;
164 tx_buffer = inv->i2c.trans.buf;
165 rx_length = inv->i2c.trans.len_r;
209 static const uint16_t max_bytes =
sizeof(inv->spi.rx_buf) - 3;
213 if(fifo_bytes > 4096) {
219 if((rx_length - 3) > 0) {
220 uint16_t valid_bytes = ((rx_length - 3) < fifo_bytes)? (rx_length - 3) : fifo_bytes;
222 inv->
timer -= valid_bytes;
225 inv->
timer = fifo_bytes;
287 gyro_samplerate = 1125;
291 accel_samplerate = 1125;
295 uint8_t downsample = gyro_samplerate / accel_samplerate;
297 for(
uint8_t i = 0; i < samples; i++) {
298 if(i % downsample == 0) {
313 float temp_f = ((float)temp / samples) / 333.87f + 21.f;
367 inv->spi.trans.output_length = 2;
368 inv->spi.trans.input_length = 0;
369 inv->spi.tx_buf[0] = reg;
370 inv->spi.tx_buf[1] = value;
375 inv->i2c.trans.buf[0] = reg;
376 inv->i2c.trans.buf[1] = value;
377 i2c_transmit(inv->i2c.p, &(inv->i2c.trans), inv->i2c.slave_addr, 2);
404 inv->spi.trans.output_length = 2;
405 inv->spi.trans.input_length = 1 + size;
407 inv->spi.tx_buf[1] = 0;
413 i2c_transceive(inv->i2c.p, &(inv->i2c.trans), inv->i2c.slave_addr, 1, (1 + size));
434 inv->spi.trans.output_length = 2;
435 inv->spi.trans.input_length = 0;
437 inv->spi.tx_buf[1] = bank << 4;
443 inv->i2c.trans.buf[1] = bank << 4;
444 i2c_transmit(inv->i2c.p, &(inv->i2c.trans), inv->i2c.slave_addr, 2);
Main include for ABI (AirBorneInterface).
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
bool i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
@ I2CTransSuccess
transaction successfully finished by I2C driver
@ I2CTransFailed
transaction failed
@ I2CTransDone
transaction set to done by user level
int32_t p
in rad/s with INT32_RATE_FRAC
int32_t r
in rad/s with INT32_RATE_FRAC
int32_t q
in rad/s with INT32_RATE_FRAC
bool spi_submit(struct spi_periph *p, struct spi_transaction *t)
Submit SPI transaction.
@ SPICpolIdleHigh
CPOL = 1.
@ SPISelectUnselect
slave is selected before transaction and unselected after
void imu_set_defaults_accel(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Vect3 *neutral, const struct Int32Vect3 *scale)
Set the defaults for a accel sensor WARNING: Should be called before sensor is publishing messages to...
void imu_set_defaults_gyro(uint8_t abi_id, const struct Int32RMat *imu_to_sensor, const struct Int32Rates *neutral, const struct Int32Rates *scale)
Set the defaults for a gyro sensor WARNING: Should be called before sensor is publishing messages to ...
Inertial Measurement Unit interface.
static const struct Int32Rates invensense2_gyro_scale[5][2]
static bool invensense2_select_bank(struct invensense2_t *inv, uint8_t bank)
Select the correct register bank.
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.
void invensense2_event(struct invensense2_t *inv)
Should be called in the event thread.
static void invensense2_parse_data(struct invensense2_t *inv, volatile uint8_t *data, uint16_t len)
Parse the FIFO buffer data.
void invensense2_periodic(struct invensense2_t *inv)
Should be called periodically to request sensor readings.
static bool invensense2_config(struct invensense2_t *inv)
Configure the Invensense 2 device register by register.
static void invensense2_fix_config(struct invensense2_t *inv)
This fixes the configuration errors and sets the correct scalings.
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.
void invensense2_init(struct invensense2_t *inv)
Initialize the invensense v2 sensor instance.
static const struct Int32Vect3 invensense2_accel_scale[5][2]
Driver for the Invensense V2 IMUs ICM20948, ICM20648 and ICM20649.
enum invensense2_accel_range_t accel_range
Accelerometer range configuration.
@ INVENSENSE2_GYRO_DLPF_OFF
enum invensense2_device_t device
The device type detected.
@ INVENSENSE2_GYRO_RANGE_4000DPS
Only possible for ICM20649.
@ INVENSENSE2_GYRO_RANGE_500DPS
@ INVENSENSE2_GYRO_RANGE_2000DPS
@ INVENSENSE2_GYRO_RANGE_250DPS
Not possible for ICM20649.
uint8_t config_idx
The current configuration index.
enum invensense2_gyro_dlpf_t gyro_dlpf
Gyro DLPF configuration.
uint8_t register_bank
The current register bank communicating with.
@ INVENSENSE2_ACCEL_RANGE_2G
Not possible for ICM20649.
@ INVENSENSE2_ACCEL_RANGE_16G
@ INVENSENSE2_ACCEL_RANGE_4G
@ INVENSENSE2_ACCEL_RANGE_30G
Only possible for ICM20649.
enum invensense2_status_t status
Status of the invensense V2 device.
@ INVENSENSE2_ACCEL_DLPF_OFF
float timebase_correction_pll
Timebase correction factor for the PLL clock.
enum invensense2_bus_t bus
The communication bus used to connect the device SPI/I2C.
uint32_t timer
Used to time operations during configuration (samples left during measuring)
#define INVENSENSE2_SAMPLE_CNT
#define INVENSENSE2_SAMPLE_SIZE
enum invensense2_accel_dlpf_t accel_dlpf
Accelerometer DLPF configuration.
uint8_t abi_id
The ABI id used to broadcast the device measurements.
enum invensense2_gyro_range_t gyro_range
Gyro range configuration.
Register and address definitions for the Invensense V2 from ardupilot.
#define GYRO_FS_SEL_SHIFT
#define BIT_USER_CTRL_FIFO_EN
#define INV2REG_INT_ENABLE_1
#define INV2REG_FIFO_COUNTH
#define BIT_PWR_MGMT_1_CLK_AUTO
#define INV2_WHOAMI_ICM20948
#define BIT_ACCEL_DLPF_ENABLE
#define INV2_WHOAMI_ICM20648
#define ACCEL_DLPF_CFG_SHIFT
#define INV2REG_ACCEL_CONFIG
#define BIT_USER_CTRL_I2C_IF_DIS
#define INV2REG_PWR_MGMT_1
#define BIT_USER_CTRL_I2C_MST_RESET
#define INV2REG_GYRO_CONFIG_1
#define INV2REG_TIMEBASE_CORRECTIO
#define INV2REG_FIFO_MODE
#define INV2REG_FIFO_EN_2
#define INV2REG_USER_CTRL
#define ACCEL_FS_SEL_SHIFT
#define GYRO_DLPF_CFG_SHIFT
#define BIT_USER_CTRL_SRAM_RESET
#define BIT_ACCEL_FIFO_EN
#define INV2REG_GYRO_SMPLRT_DIV
#define BIT_GYRO_DLPF_ENABLE
#define BIT_PWR_MGMT_1_DEVICE_RESET
#define INV2_WHOAMI_ICM20649
Paparazzi fixed point algebra.
Paparazzi atmospheric pressure conversion utilities.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.