2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
24 #include "common/axis.h"
25 #include "common/maths.h"
30 #include "gyro_sync.h"
34 #include "accgyro_mpu.h"
35 #include "accgyro_mpu6500.h"
37 bool mpu6500AccDetect(acc_t
*acc
)
39 if (mpuDetectionResult
.sensor
!= MPU_65xx_I2C
) {
43 acc
->init
= mpu6500AccInit
;
44 acc
->read
= mpuAccRead
;
49 bool mpu6500GyroDetect(gyro_t
*gyro
)
51 if (mpuDetectionResult
.sensor
!= MPU_65xx_I2C
) {
55 gyro
->init
= mpu6500GyroInit
;
56 gyro
->read
= mpuGyroRead
;
57 gyro
->intStatus
= checkMPUDataReady
;
59 // 16.4 dps/lsb scalefactor
60 gyro
->scale
= 1.0f
/ 16.4f
;
65 void mpu6500AccInit(acc_t
*acc
)
69 acc
->acc_1G
= 512 * 4;
72 void mpu6500GyroInit(uint8_t lpf
)
76 mpuConfiguration
.write(MPU_RA_PWR_MGMT_1
, MPU6500_BIT_RESET
);
78 mpuConfiguration
.write(MPU_RA_SIGNAL_PATH_RESET
, 0x07);
80 mpuConfiguration
.write(MPU_RA_PWR_MGMT_1
, 0);
82 mpuConfiguration
.write(MPU_RA_PWR_MGMT_1
, INV_CLK_PLL
);
84 mpuConfiguration
.write(MPU_RA_GYRO_CONFIG
, INV_FSR_2000DPS
<< 3);
86 mpuConfiguration
.write(MPU_RA_ACCEL_CONFIG
, INV_FSR_16G
<< 3);
88 mpuConfiguration
.write(MPU_RA_CONFIG
, lpf
);
90 mpuConfiguration
.write(MPU_RA_SMPLRT_DIV
, gyroMPU6xxxGetDividerDrops()); // Get Divider Drops
93 // Data ready interrupt configuration
94 #ifdef USE_MPU9250_MAG
95 mpuConfiguration
.write(MPU_RA_INT_PIN_CFG
, MPU6500_BIT_INT_ANYRD_2CLEAR
| MPU6500_BIT_BYPASS_EN
); // INT_ANYRD_2CLEAR, BYPASS_EN
97 mpuConfiguration
.write(MPU_RA_INT_PIN_CFG
, MPU6500_BIT_INT_ANYRD_2CLEAR
); // INT_ANYRD_2CLEAR
101 #ifdef USE_MPU_DATA_READY_SIGNAL
102 mpuConfiguration
.write(MPU_RA_INT_ENABLE
, MPU6500_BIT_RAW_RDY_EN
); // RAW_RDY_EN interrupt enable