Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
invensense3.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 Freek van Tienen <freek.v.tienen@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
29 #ifndef INVENSENSE3_H
30 #define INVENSENSE3_H
31 
32 #include "std.h"
33 #include "mcu_periph/spi.h"
34 #include "mcu_periph/i2c.h"
35 
36 /* This sensor has an option to request little-endian data */
37 // Hold 22 measurements + 3 for the register address and length
38 #define INVENSENSE3_FIFO_BUFFER_LEN 22
39 #define INVENSENSE3_BUFFER_SIZE INVENSENSE3_FIFO_BUFFER_LEN * 20 + 3 // 20 bytes is the maximum sample size
40 
41 /* Invensense v3 SPI peripheral */
43  struct spi_periph *p;
45  struct spi_transaction trans;
46 
49 };
50 
51 /* Invensense v3 I2C peripheral */
53  struct i2c_periph *p;
55  struct i2c_transaction trans;
56 };
57 
58 /* Possible communication busses for the invense V3 driver */
62 };
63 
64 /* Different states the invensense v3 driver can be in */
69 };
70 
71 /* Different parsers of the invensense v3 driver */
75 };
76 
82 };
83 
84 /* Different device types compatible with the invensense v3 driver */
92 };
93 
94 /* The gyro output data rate configuration */
111 };
112 
113 /* The gyro range in degrees per second(dps) */
123 };
124 
125 /* The accelerometer output data rate configuration */
142 };
143 
144 /* The accelerometer range in G */
151 };
152 
153 /* Main invensense v3 device structure */
159 
160  enum invensense3_bus_t bus;
161  union {
162  struct invensense3_spi_t spi;
163  struct invensense3_i2c_t i2c;
164  };
168 
172 
185 };
186 
187 /* External functions */
188 void invensense3_init(struct invensense3_t *inv);
189 void invensense3_periodic(struct invensense3_t *inv);
190 void invensense3_event(struct invensense3_t *inv);
191 
192 #endif // INVENSENSE3_H
I2C transaction structure.
Definition: i2c.h:93
SPI peripheral structure.
Definition: spi.h:174
SPI transaction structure.
Definition: spi.h:148
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
enum invensense3_gyro_range_t gyro_range
Gyro range configuration.
Definition: invensense3.h:174
invensense3_accel_range_t
Definition: invensense3.h:145
@ INVENSENSE3_ACCEL_RANGE_16G
Definition: invensense3.h:147
@ INVENSENSE3_ACCEL_RANGE_4G
Definition: invensense3.h:149
@ INVENSENSE3_ACCEL_RANGE_32G
Only possible for ICM40609.
Definition: invensense3.h:146
@ INVENSENSE3_ACCEL_RANGE_2G
Definition: invensense3.h:150
@ INVENSENSE3_ACCEL_RANGE_8G
Definition: invensense3.h:148
void invensense3_periodic(struct invensense3_t *inv)
Should be called periodically to request sensor readings.
Definition: invensense3.c:275
uint8_t register_bank
The current register bank communicating with.
Definition: invensense3.h:169
enum invensense3_status_t status
Status of the invensense v3 device.
Definition: invensense3.h:156
uint16_t * rx_length
Definition: invensense3.h:167
invensense3_gyro_odr_t
Definition: invensense3.h:95
@ INVENSENSE3_GYRO_ODR_4KHZ
Definition: invensense3.h:99
@ INVENSENSE3_GYRO_ODR_25HZ
Definition: invensense3.h:105
@ INVENSENSE3_GYRO_ODR_500HZ
Definition: invensense3.h:110
@ INVENSENSE3_GYRO_ODR_8KHZ
Definition: invensense3.h:98
@ INVENSENSE3_GYRO_ODR_1_5625HZ
Definition: invensense3.h:109
@ INVENSENSE3_GYRO_ODR_100HZ
Definition: invensense3.h:103
@ INVENSENSE3_GYRO_ODR_2KHZ
Definition: invensense3.h:100
@ INVENSENSE3_GYRO_ODR_50HZ
Definition: invensense3.h:104
@ INVENSENSE3_GYRO_ODR_1KHZ
Definition: invensense3.h:101
@ INVENSENSE3_GYRO_ODR_16KHZ
Not possible for ICM40605 and ICM42605.
Definition: invensense3.h:97
@ INVENSENSE3_GYRO_ODR_32KHZ
Not possible for ICM40605 and ICM42605.
Definition: invensense3.h:96
@ INVENSENSE3_GYRO_ODR_3_125HZ
Definition: invensense3.h:108
@ INVENSENSE3_GYRO_ODR_6_25HZ
Definition: invensense3.h:107
@ INVENSENSE3_GYRO_ODR_200HZ
Definition: invensense3.h:102
@ INVENSENSE3_GYRO_ODR_12_5HZ
Definition: invensense3.h:106
struct i2c_periph * p
Peripheral device for communication.
Definition: invensense3.h:53
invensense3_device_t
Definition: invensense3.h:85
@ INVENSENSE3_UNKOWN
Definition: invensense3.h:86
@ INVENSENSE3_ICM42688
Definition: invensense3.h:91
@ INVENSENSE3_ICM40605
Definition: invensense3.h:87
@ INVENSENSE3_IIM42652
Definition: invensense3.h:90
@ INVENSENSE3_ICM40609
Definition: invensense3.h:88
@ INVENSENSE3_ICM42605
Definition: invensense3.h:89
uint8_t tx_buf[2]
Transmit buffer.
Definition: invensense3.h:47
enum invensense3_parser_t parser
Parser of the device.
Definition: invensense3.h:158
void invensense3_event(struct invensense3_t *inv)
Should be called in the event thread.
Definition: invensense3.c:327
uint16_t accel_aaf
Accelerometer Anti-alias filter 3dB Bandwidth configuration [Hz].
Definition: invensense3.h:179
uint8_t slave_idx
Slave index used for Slave Select.
Definition: invensense3.h:44
struct spi_transaction trans
Transaction used during configuration and measurements.
Definition: invensense3.h:45
invensense3_parser_t
Definition: invensense3.h:72
@ INVENSENSE3_PARSER_FIFO
Definition: invensense3.h:74
@ INVENSENSE3_PARSER_REGISTERS
Definition: invensense3.h:73
uint32_t timer
Used to time operations during configuration (samples left during measuring)
Definition: invensense3.h:171
enum invensense3_accel_odr_t accel_odr
Accelerometer Output Data Rate configuration.
Definition: invensense3.h:177
struct spi_periph * p
Peripheral device for communication.
Definition: invensense3.h:43
invensense3_accel_odr_t
Definition: invensense3.h:126
@ INVENSENSE3_ACCEL_ODR_4KHZ
Definition: invensense3.h:130
@ INVENSENSE3_ACCEL_ODR_16KHZ
Not possible for ICM40605 and ICM42605.
Definition: invensense3.h:128
@ INVENSENSE3_ACCEL_ODR_50HZ
Definition: invensense3.h:135
@ INVENSENSE3_ACCEL_ODR_32KHZ
Not possible for ICM40605 and ICM42605.
Definition: invensense3.h:127
@ INVENSENSE3_ACCEL_ODR_2KHZ
Definition: invensense3.h:131
@ INVENSENSE3_ACCEL_ODR_25HZ
Definition: invensense3.h:136
@ INVENSENSE3_ACCEL_ODR_1_5625HZ
Definition: invensense3.h:140
@ INVENSENSE3_ACCEL_ODR_8KHZ
Definition: invensense3.h:129
@ INVENSENSE3_ACCEL_ODR_6_25HZ
Definition: invensense3.h:138
@ INVENSENSE3_ACCEL_ODR_200HZ
Definition: invensense3.h:133
@ INVENSENSE3_ACCEL_ODR_100HZ
Definition: invensense3.h:134
@ INVENSENSE3_ACCEL_ODR_1KHZ
Definition: invensense3.h:132
@ INVENSENSE3_ACCEL_ODR_500HZ
Definition: invensense3.h:141
@ INVENSENSE3_ACCEL_ODR_12_5HZ
Definition: invensense3.h:137
@ INVENSENSE3_ACCEL_ODR_3_125HZ
Definition: invensense3.h:139
enum invensense3_bus_t bus
The communication bus used to connect the device SPI/I2C.
Definition: invensense3.h:160
uint8_t config_idx
The current configuration index.
Definition: invensense3.h:170
uint8_t * rx_buffer
Definition: invensense3.h:165
struct i2c_transaction trans
TRansaction used during configuration and measurements.
Definition: invensense3.h:55
#define INVENSENSE3_BUFFER_SIZE
Definition: invensense3.h:39
invensense3_gyro_range_t
Definition: invensense3.h:114
@ INVENSENSE3_GYRO_RANGE_62_5DPS
Definition: invensense3.h:120
@ INVENSENSE3_GYRO_RANGE_31_25DPS
Definition: invensense3.h:121
@ INVENSENSE3_GYRO_RANGE_15_625DPS
Definition: invensense3.h:122
@ INVENSENSE3_GYRO_RANGE_500DPS
Definition: invensense3.h:117
@ INVENSENSE3_GYRO_RANGE_250DPS
Definition: invensense3.h:118
@ INVENSENSE3_GYRO_RANGE_1000DPS
Definition: invensense3.h:116
@ INVENSENSE3_GYRO_RANGE_125DPS
Definition: invensense3.h:119
@ INVENSENSE3_GYRO_RANGE_2000DPS
Definition: invensense3.h:115
int sample_numbers
expected FIFO packet number, assuming reading at PERIODIC_FREQUENCY
Definition: invensense3.h:182
enum invensense3_device_t device
The device type detected.
Definition: invensense3.h:157
float gyro_samplerate
Sample rate in Hz from the gyro_odr.
Definition: invensense3.h:183
invensense3_bus_t
Definition: invensense3.h:59
@ INVENSENSE3_I2C
Definition: invensense3.h:61
@ INVENSENSE3_SPI
Definition: invensense3.h:60
uint8_t * tx_buffer
Definition: invensense3.h:166
float accel_samplerate
Sample rate in Hz from the accel_odr.
Definition: invensense3.h:184
enum invensense3_accel_range_t accel_range
Accelerometer range configuration.
Definition: invensense3.h:178
enum invensense3_fifo_packet_t sample_size
FIFO packet size.
Definition: invensense3.h:181
invensense3_fifo_packet_t
Definition: invensense3.h:77
@ INVENSENSE3_SAMPLE_SIZE_PK3
Definition: invensense3.h:80
@ INVENSENSE3_SAMPLE_SIZE_PK1
Definition: invensense3.h:78
@ INVENSENSE3_SAMPLE_SIZE_PK4
Definition: invensense3.h:81
@ INVENSENSE3_SAMPLE_SIZE_PK2
Definition: invensense3.h:79
uint8_t slave_addr
The I2C slave address on the bus.
Definition: invensense3.h:54
uint16_t gyro_aaf_regs[4]
Gyro Anti-alias filter register values.
Definition: invensense3.h:176
uint8_t abi_id
The ABI id used to broadcast the device measurements.
Definition: invensense3.h:155
uint16_t accel_aaf_regs[4]
Accelerometer Anti-alias filter register values.
Definition: invensense3.h:180
uint8_t rx_buf[INVENSENSE3_BUFFER_SIZE]
Receive buffer.
Definition: invensense3.h:48
uint16_t gyro_aaf
Gyro Anti-alias filter 3dB Bandwidth configuration [Hz].
Definition: invensense3.h:175
enum invensense3_gyro_odr_t gyro_odr
Gyro Output Data Rate configuration.
Definition: invensense3.h:173
invensense3_status_t
Definition: invensense3.h:65
@ INVENSENSE3_CONFIG
Definition: invensense3.h:67
@ INVENSENSE3_IDLE
Definition: invensense3.h:66
@ INVENSENSE3_RUNNING
Definition: invensense3.h:68
void invensense3_init(struct invensense3_t *inv)
Initialize the invensense v3 sensor instance.
Definition: invensense3.c:223
Architecture independent SPI (Serial Peripheral Interface) API.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98