Update cloud build defines (#14080)
[betaflight.git] / src / main / drivers / accgyro / gyro_sync.c
blob48ca30039cfffe0db3908da696b0af4ac4f4e905
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"
37 bool gyroSyncCheckUpdate(gyroDev_t *gyro)
39 bool ret;
40 if (gyro->dataReady) {
41 ret = true;
42 gyro->dataReady= false;
43 } else {
44 ret = false;
46 return ret;
49 uint16_t gyroSetSampleRate(gyroDev_t *gyro)
51 uint16_t gyroSampleRateHz;
52 uint16_t accSampleRateHz;
54 switch (gyro->mpuDetectionResult.sensor) {
55 case BMI_160_SPI:
56 gyro->gyroRateKHz = GYRO_RATE_3200_Hz;
57 gyroSampleRateHz = 3200;
58 accSampleRateHz = 800;
59 break;
60 case BMI_270_SPI:
61 #ifdef USE_GYRO_DLPF_EXPERIMENTAL
62 if (gyro->hardware_lpf == GYRO_HARDWARE_LPF_EXPERIMENTAL) {
63 // 6.4KHz sampling, but data is unfiltered (no hardware DLPF)
64 gyro->gyroRateKHz = GYRO_RATE_6400_Hz;
65 gyroSampleRateHz = 6400;
66 } else
67 #endif
69 gyro->gyroRateKHz = GYRO_RATE_3200_Hz;
70 gyroSampleRateHz = 3200;
72 accSampleRateHz = 800;
73 break;
74 case ICM_20649_SPI:
75 gyro->gyroRateKHz = GYRO_RATE_9_kHz;
76 gyroSampleRateHz = 9000;
77 accSampleRateHz = 1125;
78 break;
79 #ifdef USE_ACCGYRO_LSM6DSO
80 case LSM6DSO_SPI:
81 gyro->gyroRateKHz = GYRO_RATE_6664_Hz;
82 gyroSampleRateHz = 6664; // Yes, this is correct per the datasheet. Will effectively round to 150us and 6.67KHz.
83 accSampleRateHz = 833;
84 break;
85 #endif
86 default:
87 gyro->gyroRateKHz = GYRO_RATE_8_kHz;
88 gyroSampleRateHz = 8000;
89 accSampleRateHz = 1000;
90 break;
93 gyro->mpuDividerDrops = 0; // we no longer use the gyro's sample divider
94 gyro->accSampleRateHz = accSampleRateHz;
95 return gyroSampleRateHz;