NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
accgyro_mpu.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight 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.
8  *
9  * Ninjaflight 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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
20 // MPU6050
21 #define MPU_RA_WHO_AM_I 0x75
22 #define MPU_RA_WHO_AM_I_LEGACY 0x00
23 
24 // RA = Register Address
25 
26 #define MPU_RA_XG_OFFS_TC 0x00 //[7] PWR_MODE, [6:1] XG_OFFS_TC, [0] OTP_BNK_VLD
27 #define MPU_RA_YG_OFFS_TC 0x01 //[7] PWR_MODE, [6:1] YG_OFFS_TC, [0] OTP_BNK_VLD
28 #define MPU_RA_ZG_OFFS_TC 0x02 //[7] PWR_MODE, [6:1] ZG_OFFS_TC, [0] OTP_BNK_VLD
29 #define MPU_RA_X_FINE_GAIN 0x03 //[7:0] X_FINE_GAIN
30 #define MPU_RA_Y_FINE_GAIN 0x04 //[7:0] Y_FINE_GAIN
31 #define MPU_RA_Z_FINE_GAIN 0x05 //[7:0] Z_FINE_GAIN
32 #define MPU_RA_XA_OFFS_H 0x06 //[15:0] XA_OFFS
33 #define MPU_RA_XA_OFFS_L_TC 0x07
34 #define MPU_RA_YA_OFFS_H 0x08 //[15:0] YA_OFFS
35 #define MPU_RA_YA_OFFS_L_TC 0x09
36 #define MPU_RA_ZA_OFFS_H 0x0A //[15:0] ZA_OFFS
37 #define MPU_RA_ZA_OFFS_L_TC 0x0B
38 #define MPU_RA_PRODUCT_ID 0x0C // Product ID Register
39 #define MPU_RA_XG_OFFS_USRH 0x13 //[15:0] XG_OFFS_USR
40 #define MPU_RA_XG_OFFS_USRL 0x14
41 #define MPU_RA_YG_OFFS_USRH 0x15 //[15:0] YG_OFFS_USR
42 #define MPU_RA_YG_OFFS_USRL 0x16
43 #define MPU_RA_ZG_OFFS_USRH 0x17 //[15:0] ZG_OFFS_USR
44 #define MPU_RA_ZG_OFFS_USRL 0x18
45 #define MPU_RA_SMPLRT_DIV 0x19
46 #define MPU_RA_CONFIG 0x1A
47 #define MPU_RA_GYRO_CONFIG 0x1B
48 #define MPU_RA_ACCEL_CONFIG 0x1C
49 #define MPU_RA_FF_THR 0x1D
50 #define MPU_RA_FF_DUR 0x1E
51 #define MPU_RA_MOT_THR 0x1F
52 #define MPU_RA_MOT_DUR 0x20
53 #define MPU_RA_ZRMOT_THR 0x21
54 #define MPU_RA_ZRMOT_DUR 0x22
55 #define MPU_RA_FIFO_EN 0x23
56 #define MPU_RA_I2C_MST_CTRL 0x24
57 #define MPU_RA_I2C_SLV0_ADDR 0x25
58 #define MPU_RA_I2C_SLV0_REG 0x26
59 #define MPU_RA_I2C_SLV0_CTRL 0x27
60 #define MPU_RA_I2C_SLV1_ADDR 0x28
61 #define MPU_RA_I2C_SLV1_REG 0x29
62 #define MPU_RA_I2C_SLV1_CTRL 0x2A
63 #define MPU_RA_I2C_SLV2_ADDR 0x2B
64 #define MPU_RA_I2C_SLV2_REG 0x2C
65 #define MPU_RA_I2C_SLV2_CTRL 0x2D
66 #define MPU_RA_I2C_SLV3_ADDR 0x2E
67 #define MPU_RA_I2C_SLV3_REG 0x2F
68 #define MPU_RA_I2C_SLV3_CTRL 0x30
69 #define MPU_RA_I2C_SLV4_ADDR 0x31
70 #define MPU_RA_I2C_SLV4_REG 0x32
71 #define MPU_RA_I2C_SLV4_DO 0x33
72 #define MPU_RA_I2C_SLV4_CTRL 0x34
73 #define MPU_RA_I2C_SLV4_DI 0x35
74 #define MPU_RA_I2C_MST_STATUS 0x36
75 #define MPU_RA_INT_PIN_CFG 0x37
76 #define MPU_RA_INT_ENABLE 0x38
77 #define MPU_RA_DMP_INT_STATUS 0x39
78 #define MPU_RA_INT_STATUS 0x3A
79 #define MPU_RA_ACCEL_XOUT_H 0x3B
80 #define MPU_RA_ACCEL_XOUT_L 0x3C
81 #define MPU_RA_ACCEL_YOUT_H 0x3D
82 #define MPU_RA_ACCEL_YOUT_L 0x3E
83 #define MPU_RA_ACCEL_ZOUT_H 0x3F
84 #define MPU_RA_ACCEL_ZOUT_L 0x40
85 #define MPU_RA_TEMP_OUT_H 0x41
86 #define MPU_RA_TEMP_OUT_L 0x42
87 #define MPU_RA_GYRO_XOUT_H 0x43
88 #define MPU_RA_GYRO_XOUT_L 0x44
89 #define MPU_RA_GYRO_YOUT_H 0x45
90 #define MPU_RA_GYRO_YOUT_L 0x46
91 #define MPU_RA_GYRO_ZOUT_H 0x47
92 #define MPU_RA_GYRO_ZOUT_L 0x48
93 #define MPU_RA_EXT_SENS_DATA_00 0x49
94 #define MPU_RA_MOT_DETECT_STATUS 0x61
95 #define MPU_RA_I2C_SLV0_DO 0x63
96 #define MPU_RA_I2C_SLV1_DO 0x64
97 #define MPU_RA_I2C_SLV2_DO 0x65
98 #define MPU_RA_I2C_SLV3_DO 0x66
99 #define MPU_RA_I2C_MST_DELAY_CTRL 0x67
100 #define MPU_RA_SIGNAL_PATH_RESET 0x68
101 #define MPU_RA_MOT_DETECT_CTRL 0x69
102 #define MPU_RA_USER_CTRL 0x6A
103 #define MPU_RA_PWR_MGMT_1 0x6B
104 #define MPU_RA_PWR_MGMT_2 0x6C
105 #define MPU_RA_BANK_SEL 0x6D
106 #define MPU_RA_MEM_START_ADDR 0x6E
107 #define MPU_RA_MEM_R_W 0x6F
108 #define MPU_RA_DMP_CFG_1 0x70
109 #define MPU_RA_DMP_CFG_2 0x71
110 #define MPU_RA_FIFO_COUNTH 0x72
111 #define MPU_RA_FIFO_COUNTL 0x73
112 #define MPU_RA_FIFO_R_W 0x74
113 #define MPU_RA_WHO_AM_I 0x75
114 
115 #define MPU_INQUIRY_MASK 0x7E
116 
117 // WHO_AM_I register contents for MPU3050, 6050 and 6500
118 #define MPU6500_WHO_AM_I_CONST (0x70)
119 #define MPUx0x0_WHO_AM_I_CONST (0x68)
120 
121 // RF = Register Flag
122 #define MPU_RF_DATA_RDY_EN (1 << 0)
123 
124 typedef bool (*mpuReadRegisterFunc)(uint8_t reg, uint8_t length, uint8_t* data);
125 typedef bool (*mpuWriteRegisterFunc)(uint8_t reg, uint8_t data);
126 
127 typedef struct mpuConfiguration_s {
128  uint8_t gyroReadXRegister; // Y and Z must registers follow this, 2 words each
132 
134 
135 enum lpf_e {
145 };
152 };
157 };
164 };
165 
166 typedef enum {
174 
175 typedef enum {
179 
180 typedef struct mpuDetectionResult_s {
184 
186 
188 void mpuIntExtiInit(void);
189 bool mpuAccRead(int16_t *accData);
190 bool mpuGyroRead(int16_t *gyroADC);
191 mpuDetectionResult_t *detectMpu(const extiConfig_t *configToUse);
192 bool mpuIsDataReady(void);
gyro_fsr_e
Definition: accgyro_mpu.h:146
Definition: accgyro_mpu.h:180
Definition: accgyro_mpu.h:147
mpu6050Resolution_e resolution
Definition: accgyro_mpu.h:182
Definition: accgyro_mpu.h:171
Definition: accgyro_mpu.h:150
Definition: accgyro_mpu.h:142
Definition: accgyro_mpu.h:176
Definition: accgyro_mpu.h:151
bool mpuAccRead(int16_t *accData)
Definition: accgyro_mpu.c:302
mpuReadRegisterFunc read
Definition: accgyro_mpu.h:129
Definition: accgyro_mpu.h:168
lpf_e
Definition: accgyro_mpu.h:135
Definition: accgyro_mpu.h:141
Definition: accgyro_mpu.h:140
Definition: exti.h:21
struct mpuConfiguration_s mpuConfiguration_t
void mpuIntExtiInit(void)
Definition: accgyro_mpu.c:259
void configureMPUDataReadyInterruptHandling(void)
Definition: accgyro_mpu.c:209
Definition: accgyro_mpu.h:139
Definition: accgyro_mpu.h:172
accel_fsr_e
Definition: accgyro_mpu.h:158
Definition: accgyro_mpu.h:136
Definition: accgyro_mpu.h:137
Definition: accgyro_mpu.h:154
Definition: accgyro_mpu.h:156
bool mpuIsDataReady(void)
Definition: accgyro_mpu.c:334
uint8_t gyroReadXRegister
Definition: accgyro_mpu.h:128
mpuWriteRegisterFunc write
Definition: accgyro_mpu.h:130
clock_sel_e
Definition: accgyro_mpu.h:153
mpuDetectionResult_t * detectMpu(const extiConfig_t *configToUse)
Definition: accgyro_mpu.c:66
struct mpuDetectionResult_s mpuDetectionResult_t
detectedMPUSensor_e
Definition: accgyro_mpu.h:166
mpu6050Resolution_e
Definition: accgyro_mpu.h:175
Definition: accgyro_mpu.h:169
bool(* mpuWriteRegisterFunc)(uint8_t reg, uint8_t data)
Definition: accgyro_mpu.h:125
Definition: accgyro_mpu.h:149
mpuConfiguration_t mpuConfiguration
Definition: accgyro_mpu.c:61
Definition: accgyro_mpu.h:167
bool(* mpuReadRegisterFunc)(uint8_t reg, uint8_t length, uint8_t *data)
Definition: accgyro_mpu.h:124
Definition: accgyro_mpu.h:143
Definition: accgyro_mpu.h:138
Definition: accgyro_mpu.h:148
Definition: accgyro_mpu.h:163
Definition: accgyro_mpu.h:162
Definition: accgyro_mpu.h:144
Definition: accgyro_mpu.h:160
Definition: accgyro_mpu.h:127
Definition: accgyro_mpu.h:177
Definition: accgyro_mpu.h:170
Definition: accgyro_mpu.h:161
Definition: accgyro_mpu.h:155
bool mpuGyroRead(int16_t *gyroADC)
Definition: accgyro_mpu.c:318
detectedMPUSensor_e sensor
Definition: accgyro_mpu.h:181
Definition: accgyro_mpu.h:159
uint16_t data
Definition: config.c:91
mpuDetectionResult_t mpuDetectionResult
Definition: accgyro_mpu.c:59