Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
invensense2.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 INVENSENSE2_H
30 #define INVENSENSE2_H
31 
32 #include "std.h"
33 #include "mcu_periph/spi.h"
34 #include "mcu_periph/i2c.h"
35 
36 // Hold 22 measurements and 3 for the register address and length
37 #define INVENSENSE2_SAMPLE_CNT 22
38 #define INVENSENSE2_SAMPLE_SIZE 14
39 #define INVENSENSE2_BUFFER_SIZE ((INVENSENSE2_SAMPLE_SIZE*INVENSENSE2_SAMPLE_CNT) + 3)
40 
41 /* Invensense v2 SPI peripheral */
43  struct spi_periph *p;
45  struct spi_transaction trans;
46 
47  volatile uint8_t tx_buf[2];
49 };
50 
51 /* Invensense v2 I2C peripheral */
53  struct i2c_periph *p;
55  struct i2c_transaction trans;
56 };
57 
58 /* Possible communication busses for the invense V2 driver */
62 };
63 
64 /* Different states the invensense driver can be in */
69 };
70 
71 /* Different device types compatible with the invensense V2 driver */
77 };
78 
79 /* The gyro digital low pass filter bandwidth configuration */
90 };
91 
92 /* The gyro range in degrees per second(dps) */
99 };
100 
101 /* The accelerometer digital low pass filter bandwidth configuration */
111 };
112 
113 /* The accelerometer range in G */
120 };
121 
122 /* Main invensense V2 device structure */
127 
128  enum invensense2_bus_t bus;
129  union {
130  struct invensense2_spi_t spi;
131  struct invensense2_i2c_t i2c;
132  };
133 
137 
143 };
144 
145 /* External functions */
146 void invensense2_init(struct invensense2_t *inv);
147 void invensense2_periodic(struct invensense2_t *inv);
148 void invensense2_event(struct invensense2_t *inv);
149 
150 #endif // INVENSENSE2_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 invensense2_accel_range_t accel_range
Accelerometer range configuration.
Definition: invensense2.h:141
uint8_t slave_addr
The I2C slave address on the bus.
Definition: invensense2.h:54
invensense2_gyro_dlpf_t
Definition: invensense2.h:80
@ INVENSENSE2_GYRO_DLPF_73HZ
Definition: invensense2.h:85
@ INVENSENSE2_GYRO_DLPF_229HZ
Definition: invensense2.h:82
@ INVENSENSE2_GYRO_DLPF_188HZ
Definition: invensense2.h:83
@ INVENSENSE2_GYRO_DLPF_377HZ
Definition: invensense2.h:89
@ INVENSENSE2_GYRO_DLPF_36HZ
Definition: invensense2.h:86
@ INVENSENSE2_GYRO_DLPF_18HZ
Definition: invensense2.h:87
@ INVENSENSE2_GYRO_DLPF_154HZ
Definition: invensense2.h:84
@ INVENSENSE2_GYRO_DLPF_OFF
Definition: invensense2.h:81
@ INVENSENSE2_GYRO_DLPF_9HZ
Definition: invensense2.h:88
invensense2_status_t
Definition: invensense2.h:65
@ INVENSENSE2_RUNNING
Definition: invensense2.h:68
@ INVENSENSE2_IDLE
Definition: invensense2.h:66
@ INVENSENSE2_CONFIG
Definition: invensense2.h:67
enum invensense2_device_t device
The device type detected.
Definition: invensense2.h:126
struct spi_periph * p
Peripheral device for communication.
Definition: invensense2.h:43
invensense2_gyro_range_t
Definition: invensense2.h:93
@ INVENSENSE2_GYRO_RANGE_4000DPS
Only possible for ICM20649.
Definition: invensense2.h:98
@ INVENSENSE2_GYRO_RANGE_500DPS
Definition: invensense2.h:95
@ INVENSENSE2_GYRO_RANGE_2000DPS
Definition: invensense2.h:97
@ INVENSENSE2_GYRO_RANGE_1000DPS
Definition: invensense2.h:96
@ INVENSENSE2_GYRO_RANGE_250DPS
Not possible for ICM20649.
Definition: invensense2.h:94
void invensense2_event(struct invensense2_t *inv)
Should be called in the event thread.
Definition: invensense2.c:152
struct i2c_periph * p
Peripheral device for communication.
Definition: invensense2.h:53
uint8_t config_idx
The current configuration index.
Definition: invensense2.h:135
struct spi_transaction trans
Transaction used during configuration and measurements.
Definition: invensense2.h:45
enum invensense2_gyro_dlpf_t gyro_dlpf
Gyro DLPF configuration.
Definition: invensense2.h:138
uint8_t register_bank
The current register bank communicating with.
Definition: invensense2.h:134
invensense2_accel_range_t
Definition: invensense2.h:114
@ INVENSENSE2_ACCEL_RANGE_2G
Not possible for ICM20649.
Definition: invensense2.h:115
@ INVENSENSE2_ACCEL_RANGE_8G
Definition: invensense2.h:117
@ INVENSENSE2_ACCEL_RANGE_16G
Definition: invensense2.h:118
@ INVENSENSE2_ACCEL_RANGE_4G
Definition: invensense2.h:116
@ INVENSENSE2_ACCEL_RANGE_30G
Only possible for ICM20649.
Definition: invensense2.h:119
enum invensense2_status_t status
Status of the invensense V2 device.
Definition: invensense2.h:125
invensense2_accel_dlpf_t
Definition: invensense2.h:102
@ INVENSENSE2_ACCEL_DLPF_499HZ
Definition: invensense2.h:110
@ INVENSENSE2_ACCEL_DLPF_17HZ
Definition: invensense2.h:108
@ INVENSENSE2_ACCEL_DLPF_136HZ
Definition: invensense2.h:105
@ INVENSENSE2_ACCEL_DLPF_8HZ
Definition: invensense2.h:109
@ INVENSENSE2_ACCEL_DLPF_34HZ
Definition: invensense2.h:107
@ INVENSENSE2_ACCEL_DLPF_265HZ
Definition: invensense2.h:104
@ INVENSENSE2_ACCEL_DLPF_69HZ
Definition: invensense2.h:106
@ INVENSENSE2_ACCEL_DLPF_OFF
Definition: invensense2.h:103
struct i2c_transaction trans
TRansaction used during configuration and measurements.
Definition: invensense2.h:55
volatile uint8_t tx_buf[2]
Transmit buffer.
Definition: invensense2.h:47
float timebase_correction_pll
Timebase correction factor for the PLL clock.
Definition: invensense2.h:142
uint8_t slave_idx
Slave index used for Slave Select.
Definition: invensense2.h:44
void invensense2_periodic(struct invensense2_t *inv)
Should be called periodically to request sensor readings.
Definition: invensense2.c:119
invensense2_device_t
Definition: invensense2.h:72
@ INVENSENSE2_ICM20648
Definition: invensense2.h:74
@ INVENSENSE2_ICM20649
Definition: invensense2.h:75
@ INVENSENSE2_UNKOWN
Definition: invensense2.h:73
@ INVENSENSE2_ICM20948
Definition: invensense2.h:76
enum invensense2_bus_t bus
The communication bus used to connect the device SPI/I2C.
Definition: invensense2.h:128
volatile uint8_t rx_buf[INVENSENSE2_BUFFER_SIZE]
Receive buffer.
Definition: invensense2.h:48
uint32_t timer
Used to time operations during configuration (samples left during measuring)
Definition: invensense2.h:136
#define INVENSENSE2_BUFFER_SIZE
Definition: invensense2.h:39
enum invensense2_accel_dlpf_t accel_dlpf
Accelerometer DLPF configuration.
Definition: invensense2.h:140
uint8_t abi_id
The ABI id used to broadcast the device measurements.
Definition: invensense2.h:124
void invensense2_init(struct invensense2_t *inv)
Initialize the invensense v2 sensor instance.
Definition: invensense2.c:79
invensense2_bus_t
Definition: invensense2.h:59
@ INVENSENSE2_I2C
Definition: invensense2.h:61
@ INVENSENSE2_SPI
Definition: invensense2.h:60
enum invensense2_gyro_range_t gyro_range
Gyro range configuration.
Definition: invensense2.h:139
Architecture independent SPI (Serial Peripheral Interface) API.
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