Relocate and use some of the common MPU code from MPU6500 into
[betaflight.git] / src / main / drivers / accgyro_mpu.h
blob6d946c1b4998ed86efbc6b8719e20afb5ec759c6
1 /*
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/>.
18 #pragma once
20 typedef bool (*mpuReadRegisterFunc)(uint8_t reg, uint8_t length, uint8_t* data);
21 typedef bool (*mpuWriteRegisterFunc)(uint8_t reg, uint8_t data);
23 typedef struct mpuConfiguration_s {
24 uint8_t gyroReadXRegister; // Y and Z must registers follow this, 2 words each
25 mpuReadRegisterFunc read;
26 mpuWriteRegisterFunc write;
27 } mpuConfiguration_t;
29 extern mpuConfiguration_t mpuConfiguration;
31 enum lpf_e {
32 INV_FILTER_256HZ_NOLPF2 = 0,
33 INV_FILTER_188HZ,
34 INV_FILTER_98HZ,
35 INV_FILTER_42HZ,
36 INV_FILTER_20HZ,
37 INV_FILTER_10HZ,
38 INV_FILTER_5HZ,
39 INV_FILTER_2100HZ_NOLPF,
40 NUM_FILTER
42 enum gyro_fsr_e {
43 INV_FSR_250DPS = 0,
44 INV_FSR_500DPS,
45 INV_FSR_1000DPS,
46 INV_FSR_2000DPS,
47 NUM_GYRO_FSR
49 enum clock_sel_e {
50 INV_CLK_INTERNAL = 0,
51 INV_CLK_PLL,
52 NUM_CLK
54 enum accel_fsr_e {
55 INV_FSR_2G = 0,
56 INV_FSR_4G,
57 INV_FSR_8G,
58 INV_FSR_16G,
59 NUM_ACCEL_FSR
62 typedef enum {
63 MPU_NONE,
64 MPU_3050,
65 MPU_60x0,
66 MPU_65xx_I2C,
67 MPU_65xx_SPI
68 } detectedMPUSensor_e;
70 typedef enum {
71 MPU_HALF_RESOLUTION,
72 MPU_FULL_RESOLUTION
73 } mpu6050Resolution_e;
75 typedef struct mpuDetectionResult_s {
76 detectedMPUSensor_e sensor;
77 mpu6050Resolution_e resolution;
78 } mpuDetectionResult_t;
80 void configureMPULPF(uint16_t lpf);
81 void configureMPUDataReadyInterruptHandling(void);
82 void mpuIntExtiInit(void);
83 bool mpuAccRead(int16_t *accData);
84 bool mpuGyroRead(int16_t *gyroADC);
85 mpuDetectionResult_t *detectMpu(const extiConfig_t *configToUse);