[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / drivers / accgyro / accgyro.h
blob4a9673311e15fc6073f282b981a8ab64007dd857
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "platform.h"
25 #include "common/axis.h"
26 #include "common/maths.h"
27 #include "common/sensor_alignment.h"
28 #include "common/time.h"
29 #include "drivers/exti.h"
30 #include "drivers/bus.h"
31 #include "drivers/sensor.h"
32 #include "drivers/accgyro/accgyro_mpu.h"
34 #pragma GCC diagnostic push
35 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
36 #include <pthread.h>
37 #endif
39 #define GYRO_SCALE_2000DPS (2000.0f / (1 << 15)) // 16.384 dps/lsb scalefactor for 2000dps sensors
40 #define GYRO_SCALE_4000DPS (4000.0f / (1 << 15)) // 8.192 dps/lsb scalefactor for 4000dps sensors
42 typedef enum {
43 GYRO_NONE = 0,
44 GYRO_DEFAULT,
45 GYRO_MPU6050,
46 GYRO_L3G4200D,
47 GYRO_MPU3050,
48 GYRO_L3GD20,
49 GYRO_MPU6000,
50 GYRO_MPU6500,
51 GYRO_MPU9250,
52 GYRO_ICM20601,
53 GYRO_ICM20602,
54 GYRO_ICM20608G,
55 GYRO_ICM20649,
56 GYRO_ICM20689,
57 GYRO_ICM42605,
58 GYRO_ICM42688P,
59 GYRO_BMI160,
60 GYRO_BMI270,
61 GYRO_LSM6DSO,
62 GYRO_FAKE
63 } gyroHardware_e;
65 typedef enum {
66 GYRO_HARDWARE_LPF_NORMAL,
67 GYRO_HARDWARE_LPF_OPTION_1,
68 GYRO_HARDWARE_LPF_OPTION_2,
69 #ifdef USE_GYRO_DLPF_EXPERIMENTAL
70 GYRO_HARDWARE_LPF_EXPERIMENTAL,
71 #endif
72 GYRO_HARDWARE_LPF_COUNT
73 } gyroHardwareLpf_e;
75 typedef enum {
76 GYRO_RATE_1_kHz,
77 GYRO_RATE_1100_Hz,
78 GYRO_RATE_3200_Hz,
79 GYRO_RATE_6400_Hz,
80 GYRO_RATE_6664_Hz,
81 GYRO_RATE_8_kHz,
82 GYRO_RATE_9_kHz,
83 GYRO_RATE_32_kHz,
84 } gyroRateKHz_e;
86 typedef enum {
87 GYRO_EXTI_INIT = 0,
88 GYRO_EXTI_INT_DMA,
89 GYRO_EXTI_INT,
90 GYRO_EXTI_NO_INT
91 } gyroModeSPI_e;
93 typedef struct gyroDev_s {
94 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
95 pthread_mutex_t lock;
96 #endif
97 sensorGyroInitFuncPtr initFn; // initialize function
98 sensorGyroReadFuncPtr readFn; // read 3 axis data function
99 sensorGyroReadDataFuncPtr temperatureFn; // read temperature if available
100 extiCallbackRec_t exti;
101 extDevice_t dev;
102 float scale; // scalefactor
103 float gyroZero[XYZ_AXIS_COUNT];
104 float gyroADC[XYZ_AXIS_COUNT]; // gyro data after calibration and alignment
105 int32_t gyroADCRawPrevious[XYZ_AXIS_COUNT];
106 int16_t gyroADCRaw[XYZ_AXIS_COUNT]; // raw data from sensor
107 int16_t temperature;
108 mpuDetectionResult_t mpuDetectionResult;
109 sensor_align_e gyroAlign;
110 gyroRateKHz_e gyroRateKHz;
111 gyroModeSPI_e gyroModeSPI;
112 uint32_t detectedEXTI;
113 uint32_t gyroLastEXTI;
114 uint32_t gyroSyncEXTI;
115 int32_t gyroShortPeriod;
116 int32_t gyroDmaMaxDuration;
117 busSegment_t segments[2];
118 volatile bool dataReady;
119 bool gyro_high_fsr;
120 uint8_t hardware_lpf;
121 uint8_t hardware_32khz_lpf;
122 uint8_t mpuDividerDrops;
123 ioTag_t mpuIntExtiTag;
124 uint8_t gyroHasOverflowProtection;
125 gyroHardware_e gyroHardware;
126 fp_rotationMatrix_t rotationMatrix;
127 uint16_t gyroSampleRateHz;
128 uint16_t accSampleRateHz;
129 uint8_t accDataReg;
130 uint8_t gyroDataReg;
131 } gyroDev_t;
133 typedef struct accDev_s {
134 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
135 pthread_mutex_t lock;
136 #endif
137 float acc_1G_rec;
138 sensorAccInitFuncPtr initFn; // initialize function
139 sensorAccReadFuncPtr readFn; // read 3 axis data function
140 uint16_t acc_1G;
141 int16_t ADCRaw[XYZ_AXIS_COUNT];
142 mpuDetectionResult_t mpuDetectionResult;
143 sensor_align_e accAlign;
144 bool dataReady;
145 gyroDev_t *gyro;
146 bool acc_high_fsr;
147 char revisionCode; // a revision code for the sensor, if known
148 uint8_t filler[2];
149 fp_rotationMatrix_t rotationMatrix;
150 } accDev_t;
152 static inline void accDevLock(accDev_t *acc)
154 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
155 pthread_mutex_lock(&acc->lock);
156 #else
157 (void)acc;
158 #endif
161 static inline void accDevUnLock(accDev_t *acc)
163 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
164 pthread_mutex_unlock(&acc->lock);
165 #else
166 (void)acc;
167 #endif
170 static inline void gyroDevLock(gyroDev_t *gyro)
172 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
173 pthread_mutex_lock(&gyro->lock);
174 #else
175 (void)gyro;
176 #endif
179 static inline void gyroDevUnLock(gyroDev_t *gyro)
181 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
182 pthread_mutex_unlock(&gyro->lock);
183 #else
184 (void)gyro;
185 #endif
187 #pragma GCC diagnostic pop