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"
33 #include "accgyro_mpu.h"
34 #include "accgyro_mpu6500.h"
36 extern uint16_t acc_1G
;
38 bool mpu6500AccDetect(acc_t
*acc
)
40 if (mpuDetectionResult
.sensor
!= MPU_65xx_I2C
) {
44 acc
->init
= mpu6500AccInit
;
45 acc
->read
= mpuAccRead
;
50 bool mpu6500GyroDetect(gyro_t
*gyro
)
52 if (mpuDetectionResult
.sensor
!= MPU_65xx_I2C
) {
56 gyro
->init
= mpu6500GyroInit
;
57 gyro
->read
= mpuGyroRead
;
59 // 16.4 dps/lsb scalefactor
60 gyro
->scale
= 1.0f
/ 16.4f
;
65 void mpu6500AccInit(void)
72 void mpu6500GyroInit(uint16_t lpf
)
77 // FIXME target specific code in driver code.
80 // MPU_INT output on rev5 hardware (PC13). rev4 was on PB13, conflicts with SPI devices
81 if (hse_value
== 12000000) {
83 gpio
.speed
= Speed_2MHz
;
84 gpio
.mode
= Mode_IN_FLOATING
;
85 gpioInit(GPIOC
, &gpio
);
89 uint8_t mpuLowPassFilter
= determineMPULPF(lpf
);
91 mpuConfiguration
.write(MPU_RA_PWR_MGMT_1
, MPU6500_BIT_RESET
);
93 mpuConfiguration
.write(MPU_RA_SIGNAL_PATH_RESET
, 0x07);
95 mpuConfiguration
.write(MPU_RA_PWR_MGMT_1
, 0);
97 mpuConfiguration
.write(MPU_RA_PWR_MGMT_1
, INV_CLK_PLL
);
98 mpuConfiguration
.write(MPU_RA_GYRO_CONFIG
, INV_FSR_2000DPS
<< 3);
99 mpuConfiguration
.write(MPU_RA_ACCEL_CONFIG
, INV_FSR_8G
<< 3);
100 mpuConfiguration
.write(MPU_RA_CONFIG
, mpuLowPassFilter
);
101 mpuConfiguration
.write(MPU_RA_SMPLRT_DIV
, 0); // 1kHz S/R
103 // Data ready interrupt configuration
104 mpuConfiguration
.write(MPU_RA_INT_PIN_CFG
, 0 << 7 | 0 << 6 | 0 << 5 | 1 << 4 | 0 << 3 | 0 << 2 | 1 << 1 | 0 << 0); // INT_ANYRD_2CLEAR, BYPASS_EN
105 #ifdef USE_MPU_DATA_READY_SIGNAL
106 mpuConfiguration
.write(MPU_RA_INT_ENABLE
, 0x01); // RAW_RDY_EN interrupt enable