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)
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/>.
25 #include "common/axis.h"
26 #include "common/maths.h"
27 #include "common/sensor_alignment.h"
28 #include "drivers/exti.h"
29 #include "drivers/bus.h"
30 #include "drivers/sensor.h"
31 #include "drivers/accgyro/accgyro_mpu.h"
33 #pragma GCC diagnostic push
34 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
38 #define GYRO_SCALE_2000DPS (2000.0f / (1 << 15)) // 16.384 dps/lsb scalefactor for 2000dps sensors
39 #define GYRO_SCALE_4000DPS (4000.0f / (1 << 15)) // 8.192 dps/lsb scalefactor for 4000dps sensors
64 GYRO_HARDWARE_LPF_NORMAL
,
65 #ifdef USE_GYRO_DLPF_EXPERIMENTAL
66 GYRO_HARDWARE_LPF_EXPERIMENTAL
81 typedef struct gyroDev_s
{
82 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
85 sensorGyroInitFuncPtr initFn
; // initialize function
86 sensorGyroReadFuncPtr readFn
; // read 3 axis data function
87 sensorGyroReadDataFuncPtr temperatureFn
; // read temperature if available
88 extiCallbackRec_t exti
;
90 float scale
; // scalefactor
91 float gyroZero
[XYZ_AXIS_COUNT
];
92 float gyroADC
[XYZ_AXIS_COUNT
]; // gyro data after calibration and alignment
93 int32_t gyroADCRawPrevious
[XYZ_AXIS_COUNT
];
94 int16_t gyroADCRaw
[XYZ_AXIS_COUNT
]; // raw data from sensor
96 mpuDetectionResult_t mpuDetectionResult
;
97 sensor_align_e gyroAlign
;
98 gyroRateKHz_e gyroRateKHz
;
101 uint8_t hardware_lpf
;
102 uint8_t hardware_32khz_lpf
;
103 uint8_t mpuDividerDrops
;
104 ioTag_t mpuIntExtiTag
;
105 uint8_t gyroHasOverflowProtection
;
106 gyroHardware_e gyroHardware
;
107 fp_rotationMatrix_t rotationMatrix
;
108 uint16_t gyroSampleRateHz
;
109 uint16_t accSampleRateHz
;
112 typedef struct accDev_s
{
113 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
114 pthread_mutex_t lock
;
117 sensorAccInitFuncPtr initFn
; // initialize function
118 sensorAccReadFuncPtr readFn
; // read 3 axis data function
120 int16_t ADCRaw
[XYZ_AXIS_COUNT
];
121 mpuDetectionResult_t mpuDetectionResult
;
122 sensor_align_e accAlign
;
126 char revisionCode
; // a revision code for the sensor, if known
128 fp_rotationMatrix_t rotationMatrix
;
131 static inline void accDevLock(accDev_t
*acc
)
133 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
134 pthread_mutex_lock(&acc
->lock
);
140 static inline void accDevUnLock(accDev_t
*acc
)
142 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
143 pthread_mutex_unlock(&acc
->lock
);
149 static inline void gyroDevLock(gyroDev_t
*gyro
)
151 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
152 pthread_mutex_lock(&gyro
->lock
);
158 static inline void gyroDevUnLock(gyroDev_t
*gyro
)
160 #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_MULTITHREAD)
161 pthread_mutex_unlock(&gyro
->lock
);
166 #pragma GCC diagnostic pop