35 #include "mcu_periph/gpio_arch.h"
51 { {40147, 40147, 40147},
53 { {40147, 40147, 40147},
54 {18420, 18420, 18420} },
55 { {60534, 60534, 60534},
56 {55463, 55463, 55463} },
57 { {30267, 30267, 30267},
58 {55463, 55463, 55463} },
59 { {30267, 30267, 30267},
60 {110926, 110926, 110926} },
61 { {3292054, 3292054, 3292054},
62 {24144015, 24144015, 24144015} },
63 { {1646027, 1646027, 1646027},
64 {24144015, 24144015, 24144015} },
65 { {1646027, 1646027, 1646027},
66 {48288030, 48288030, 48288030} },
71 { {51024, 51024, 51024},
73 { {25512, 25512, 25512},
75 { {12756, 12756, 12756},
239 inv->spi.trans.slave_idx = inv->spi.slave_idx;
240 inv->spi.trans.output_length = 0;
241 inv->spi.trans.input_length = 0;
242 inv->spi.trans.before_cb = NULL;
243 inv->spi.trans.after_cb = NULL;
244 inv->spi.trans.input_buf = inv->spi.rx_buf;
245 inv->spi.trans.output_buf = inv->spi.tx_buf;
250 inv->
rx_length = &inv->spi.trans.input_length;
254 inv->i2c.trans.slave_addr = inv->i2c.slave_addr;
302 static const uint16_t max_bytes =
sizeof(inv->spi.rx_buf) - 3;
304 read_bytes =
Min(max_bytes, read_bytes);
394 if(fifo_bytes > 4096) {
403 inv->
timer -= nb_packets_read;
467 uint8_t faster_odr = gyro_samplerate;
468 if (accel_samplerate > gyro_samplerate)
469 faster_odr = accel_samplerate;
477 for(
uint8_t sample = 0; sample < samples; sample++) {
479 if ((data[0] & 0xFC) != 0x68) {
483 gyro_samplerate_count = gyro_samplerate * (sample + 1);
484 if(gyro_samplerate_count % faster_odr == 0) {
490 if(gyro_samplerate == faster_odr)
496 accel_samplerate_count = accel_samplerate * (sample + 1);
497 if(accel_samplerate_count % faster_odr == 0) {
502 if(accel_samplerate == faster_odr)
513 float temp_f = ((float)temp / i) / 2.07 + 25.f;
514 if (accel_samplerate == faster_odr)
515 temp_f = ((float)temp / j) / 2.07 + 25.f;
521 AbiSendMsgTEMPERATURE(inv->
abi_id, temp_f);
536 float temp_f = (float)temp / 132.48 + 25.f;
550 AbiSendMsgTEMPERATURE(inv->
abi_id, temp_f);
593 for(i = 0; i < aaf_len; i++) {
594 if(inv->
gyro_aaf <= aaf_table[i][0]) {
600 if(i >= (aaf_len-1)) {
601 inv->
gyro_aaf = aaf_table[aaf_len-1][0];
605 for(i = 0; i < aaf_len; i++) {
612 if(i >= (aaf_len-1)) {
613 inv->
accel_aaf = aaf_table[aaf_len-1][0];
742 inv->spi.trans.output_length = 2;
743 inv->spi.trans.input_length = 0;
748 i2c_transmit(inv->i2c.p, &(inv->i2c.trans), inv->i2c.slave_addr, 2);
776 inv->spi.trans.output_length = 2;
777 inv->spi.trans.input_length = 1 + size;
783 i2c_transceive(inv->i2c.p, &(inv->i2c.trans), inv->i2c.slave_addr, 1, (1 + size));
806 inv->spi.trans.output_length = 2;
807 inv->spi.trans.input_length = 0;
812 i2c_transmit(inv->i2c.p, &(inv->i2c.trans), inv->i2c.slave_addr, 2);
994 return ceilf(freq/PERIODIC_FREQUENCY);
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
#define RMAT_COPY(_o, _i)
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.
#define GYRO_FS_SEL_SHIFT
#define ACCEL_FS_SEL_SHIFT
static const uint16_t invensense3_aaf4x605[][4]
static const struct Int32Vect3 invensense3_accel_scale[5][2]
void invensense3_periodic(struct invensense3_t *inv)
Should be called periodically to request sensor readings.
static void invensense3_parse_fifo_data(struct invensense3_t *inv, uint8_t *data, uint16_t samples)
Parse the FIFO buffer data.
static int samples_from_odr(int odr)
static const uint8_t invensense3_fifo_sample_size[4]
static const uint16_t invensense3_aaf[][4]
static void invensense3_parse_reg_data(struct invensense3_t *inv, uint8_t *data)
Parse data from registers.
static bool invensense3_reset_fifo(struct invensense3_t *inv)
Reset FIFO (can be useful in some situations)
static bool invensense3_select_bank(struct invensense3_t *inv, uint8_t bank)
Select the correct register bank.
void invensense3_event(struct invensense3_t *inv)
Should be called in the event thread.
static bool invensense3_config(struct invensense3_t *inv)
Configure the Invensense 3 device register by register.
static void invensense3_fix_config(struct invensense3_t *inv)
This fixes the configuration errors and sets the correct scalings.
static bool invensense3_register_read(struct invensense3_t *inv, uint16_t bank_reg, uint16_t size)
Read a register based on a combined bank/regsiter value.
static const struct Int32Rates invensense3_gyro_scale[8][2]
static bool invensense3_register_write(struct invensense3_t *inv, uint16_t bank_reg, uint8_t value)
Write a register based on a combined bank/regsiter value.
void invensense3_init(struct invensense3_t *inv)
Initialize the invensense v3 sensor instance.
Driver for the Invensense V3 IMUs ICM40605, ICM40609, ICM42605, IIM42652 and ICM42688.
enum invensense3_gyro_range_t gyro_range
Gyro range configuration.
@ INVENSENSE3_ACCEL_RANGE_16G
@ INVENSENSE3_ACCEL_RANGE_4G
uint8_t register_bank
The current register bank communicating with.
enum invensense3_status_t status
Status of the invensense v3 device.
@ INVENSENSE3_GYRO_ODR_4KHZ
@ INVENSENSE3_GYRO_ODR_25HZ
@ INVENSENSE3_GYRO_ODR_500HZ
@ INVENSENSE3_GYRO_ODR_8KHZ
@ INVENSENSE3_GYRO_ODR_1_5625HZ
@ INVENSENSE3_GYRO_ODR_100HZ
@ INVENSENSE3_GYRO_ODR_2KHZ
@ INVENSENSE3_GYRO_ODR_50HZ
@ INVENSENSE3_GYRO_ODR_1KHZ
@ INVENSENSE3_GYRO_ODR_16KHZ
Not possible for ICM40605 and ICM42605.
@ INVENSENSE3_GYRO_ODR_32KHZ
Not possible for ICM40605 and ICM42605.
@ INVENSENSE3_GYRO_ODR_3_125HZ
@ INVENSENSE3_GYRO_ODR_6_25HZ
@ INVENSENSE3_GYRO_ODR_200HZ
@ INVENSENSE3_GYRO_ODR_12_5HZ
enum invensense3_parser_t parser
Parser of the device.
uint16_t accel_aaf
Accelerometer Anti-alias filter 3dB Bandwidth configuration [Hz].
@ INVENSENSE3_PARSER_FIFO
@ INVENSENSE3_PARSER_REGISTERS
uint32_t timer
Used to time operations during configuration (samples left during measuring)
enum invensense3_accel_odr_t accel_odr
Accelerometer Output Data Rate configuration.
@ INVENSENSE3_ACCEL_ODR_4KHZ
@ INVENSENSE3_ACCEL_ODR_16KHZ
Not possible for ICM40605 and ICM42605.
@ INVENSENSE3_ACCEL_ODR_50HZ
@ INVENSENSE3_ACCEL_ODR_32KHZ
Not possible for ICM40605 and ICM42605.
@ INVENSENSE3_ACCEL_ODR_2KHZ
@ INVENSENSE3_ACCEL_ODR_25HZ
@ INVENSENSE3_ACCEL_ODR_1_5625HZ
@ INVENSENSE3_ACCEL_ODR_8KHZ
@ INVENSENSE3_ACCEL_ODR_6_25HZ
@ INVENSENSE3_ACCEL_ODR_200HZ
@ INVENSENSE3_ACCEL_ODR_100HZ
@ INVENSENSE3_ACCEL_ODR_1KHZ
@ INVENSENSE3_ACCEL_ODR_500HZ
@ INVENSENSE3_ACCEL_ODR_12_5HZ
@ INVENSENSE3_ACCEL_ODR_3_125HZ
enum invensense3_bus_t bus
The communication bus used to connect the device SPI/I2C.
uint8_t config_idx
The current configuration index.
int sample_numbers
expected FIFO packet number, assuming reading at PERIODIC_FREQUENCY
enum invensense3_device_t device
The device type detected.
float gyro_samplerate
Sample rate in Hz from the gyro_odr.
float accel_samplerate
Sample rate in Hz from the accel_odr.
enum invensense3_accel_range_t accel_range
Accelerometer range configuration.
enum invensense3_fifo_packet_t sample_size
FIFO packet size.
@ INVENSENSE3_SAMPLE_SIZE_PK3
uint16_t gyro_aaf_regs[4]
Gyro Anti-alias filter register values.
uint8_t abi_id
The ABI id used to broadcast the device measurements.
uint16_t accel_aaf_regs[4]
Accelerometer Anti-alias filter register values.
uint16_t gyro_aaf
Gyro Anti-alias filter 3dB Bandwidth configuration [Hz].
enum invensense3_gyro_odr_t gyro_odr
Gyro Output Data Rate configuration.
#define INVENSENSE3_FIFO_BUFFER_LEN
Register and address definitions for the Invensense V3 from ardupilot.
#define INV3REG_INTF_CONFIG1
#define FIFO_CONFIG_MODE_SHIFT
#define INV3REG_FIFO_CONFIG
#define FIFO_CONFIG_MODE_STOP_ON_FULL
#define INV3REG_GYRO_CONFIG_STATIC2
#define INV3REG_ACCEL_CONFIG_STATIC2
#define BIT_FIFO_CONFIG1_ACCEL_EN
#define INV3_WHOAMI_ICM42605
#define BIT_FIFO_CONFIG1_GYRO_EN
#define INV3REG_FIFO_CONFIG3
#define ACCEL_AAF_BITSHIFT_SHIFT
#define INV3REG_PWR_MGMT0
#define INV3REG_INT_CONFIG1
#define BIT_SIGNAL_PATH_RESET_FIFO_FLUSH
#define INV3REG_FIFO_CONFIG1
#define BIT_FIFO_FULL_INT_EN
#define ACCEL_AAF_DELT_SHIFT
#define BIT_FIFO_CONFIG1_TEMP_EN
#define INV3REG_INTF_CONFIG0
#define INV3REG_INT_SOURCE0
#define INV3_WHOAMI_ICM42688
#define GYRO_AAF_BITSHIFT_SHIFT
#define INV3REG_TEMP_DATA1
#define INV3_WHOAMI_ICM40605
#define BIT_INT_ASYNC_RESET
#define INV3REG_DEVICE_CONFIG
#define INV3REG_GYRO_CONFIG_STATIC3
#define BIT_FIFO_THS_INT_EN
#define INV3REG_ACCEL_CONFIG_STATIC4
#define INV3REG_GYRO_CONFIG_STATIC5
#define INV3REG_GYRO_CONFIG_STATIC4
#define BIT_UI_DRDY_INT_EN
#define INV3_WHOAMI_IIM42652
#define INV3REG_ACCEL_CONFIG_STATIC3
#define INV3REG_ACCEL_CONFIG0
#define BIT_DEVICE_CONFIG_SOFT_RESET_CONFIG
#define INV3REG_FIFO_CONFIG2
#define INV3REG_FIFO_COUNTH
#define INV3_WHOAMI_ICM40609
#define INV3REG_SIGNAL_PATH_RESET
#define INV3REG_GYRO_CONFIG0
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.