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/>.
27 #include "common/axis.h"
28 #include "common/maths.h"
30 #include "drivers/exti.h"
31 #include "drivers/sensor.h"
32 #include "drivers/time.h"
35 #include "accgyro_mpu.h"
36 #include "accgyro_mpu6500.h"
38 void mpu6500AccInit(accDev_t
*acc
)
40 acc
->acc_1G
= 512 * 4;
43 bool mpu6500AccDetect(accDev_t
*acc
)
45 if (acc
->mpuDetectionResult
.sensor
!= MPU_65xx_I2C
) {
49 acc
->initFn
= mpu6500AccInit
;
50 acc
->readFn
= mpuAccRead
;
55 void mpu6500GyroInit(gyroDev_t
*gyro
)
59 int gyro_range
= INV_FSR_2000DPS
;
60 int accel_range
= INV_FSR_16G
;
62 if (gyro
->mpuDetectionResult
.sensor
== ICM_20601_SPI
) {
63 gyro_range
= gyro
->gyro_high_fsr
? ICM_HIGH_RANGE_FSR_4000DPS
: ICM_HIGH_RANGE_FSR_2000DPS
;
64 accel_range
= ICM_HIGH_RANGE_FSR_16G
;
67 busWriteRegister(&gyro
->dev
, MPU_RA_PWR_MGMT_1
, MPU6500_BIT_RESET
);
69 busWriteRegister(&gyro
->dev
, MPU_RA_SIGNAL_PATH_RESET
, 0x07);
71 busWriteRegister(&gyro
->dev
, MPU_RA_PWR_MGMT_1
, 0);
73 busWriteRegister(&gyro
->dev
, MPU_RA_PWR_MGMT_1
, INV_CLK_PLL
);
75 busWriteRegister(&gyro
->dev
, MPU_RA_GYRO_CONFIG
, gyro_range
<< 3);
77 busWriteRegister(&gyro
->dev
, MPU_RA_ACCEL_CONFIG
, accel_range
<< 3);
79 busWriteRegister(&gyro
->dev
, MPU_RA_CONFIG
, mpuGyroDLPF(gyro
));
81 busWriteRegister(&gyro
->dev
, MPU_RA_SMPLRT_DIV
, gyro
->mpuDividerDrops
); // Get Divider Drops
84 // Data ready interrupt configuration
85 #ifdef USE_MPU9250_MAG
86 busWriteRegister(&gyro
->dev
, MPU_RA_INT_PIN_CFG
, MPU6500_BIT_INT_ANYRD_2CLEAR
| MPU6500_BIT_BYPASS_EN
); // INT_ANYRD_2CLEAR, BYPASS_EN
88 busWriteRegister(&gyro
->dev
, MPU_RA_INT_PIN_CFG
, MPU6500_BIT_INT_ANYRD_2CLEAR
); // INT_ANYRD_2CLEAR
92 #ifdef USE_MPU_DATA_READY_SIGNAL
93 busWriteRegister(&gyro
->dev
, MPU_RA_INT_ENABLE
, MPU6500_BIT_RAW_RDY_EN
); // RAW_RDY_EN interrupt enable
98 bool mpu6500GyroDetect(gyroDev_t
*gyro
)
100 if (gyro
->mpuDetectionResult
.sensor
!= MPU_65xx_I2C
) {
104 gyro
->initFn
= mpu6500GyroInit
;
105 gyro
->readFn
= mpuGyroRead
;
107 gyro
->scale
= GYRO_SCALE_2000DPS
;