[4.4.2] Remove 15 m/s limit on estimated vario (#12788)
[betaflight.git] / src / main / drivers / accgyro / gyro_sync.c
bloba514e2cb874d706b2efe0647e431280d4acc6081
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/>.
22 * gyro_sync.c
24 * Created on: 3 aug. 2015
25 * Author: borisb
28 #include <stdbool.h>
29 #include <stdint.h>
31 #include "platform.h"
33 #include "drivers/sensor.h"
34 #include "drivers/accgyro/accgyro.h"
35 #include "drivers/accgyro/gyro_sync.h"
38 bool gyroSyncCheckUpdate(gyroDev_t *gyro)
40 bool ret;
41 if (gyro->dataReady) {
42 ret = true;
43 gyro->dataReady= false;
44 } else {
45 ret = false;
47 return ret;
50 uint16_t gyroSetSampleRate(gyroDev_t *gyro)
52 uint16_t gyroSampleRateHz;
53 uint16_t accSampleRateHz;
55 switch (gyro->mpuDetectionResult.sensor) {
56 case BMI_160_SPI:
57 gyro->gyroRateKHz = GYRO_RATE_3200_Hz;
58 gyroSampleRateHz = 3200;
59 accSampleRateHz = 800;
60 break;
61 case BMI_270_SPI:
62 #ifdef USE_GYRO_DLPF_EXPERIMENTAL
63 if (gyro->hardware_lpf == GYRO_HARDWARE_LPF_EXPERIMENTAL) {
64 // 6.4KHz sampling, but data is unfiltered (no hardware DLPF)
65 gyro->gyroRateKHz = GYRO_RATE_6400_Hz;
66 gyroSampleRateHz = 6400;
67 } else
68 #endif
70 gyro->gyroRateKHz = GYRO_RATE_3200_Hz;
71 gyroSampleRateHz = 3200;
73 accSampleRateHz = 800;
74 break;
75 case ICM_20649_SPI:
76 gyro->gyroRateKHz = GYRO_RATE_9_kHz;
77 gyroSampleRateHz = 9000;
78 accSampleRateHz = 1125;
79 break;
80 #ifdef USE_ACCGYRO_LSM6DSO
81 case LSM6DSO_SPI:
82 gyro->gyroRateKHz = GYRO_RATE_6664_Hz;
83 gyroSampleRateHz = 6664; // Yes, this is correct per the datasheet. Will effectively round to 150us and 6.67KHz.
84 accSampleRateHz = 833;
85 break;
86 #endif
87 default:
88 gyro->gyroRateKHz = GYRO_RATE_8_kHz;
89 gyroSampleRateHz = 8000;
90 accSampleRateHz = 1000;
91 break;
94 gyro->mpuDividerDrops = 0; // we no longer use the gyro's sample divider
95 gyro->accSampleRateHz = accSampleRateHz;
96 return gyroSampleRateHz;