amiro-lld / drivers / MPU6050 / v1 / alld_MPU6050.h @ c9774bf5
History | View | Annotate | Download (8.183 KB)
1 | 5d4d14a3 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU Lesser General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU Lesser General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU Lesser General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | /**
|
||
20 | 9466e34d | Thomas Schöpping | * @file alld_MPU6050.h
|
21 | 5d4d14a3 | Thomas Schöpping | * @brief Gyro & Accelerometer macros and structures.
|
22 | *
|
||
23 | * @addtogroup lld_mems
|
||
24 | * @{
|
||
25 | */
|
||
26 | |||
27 | 9466e34d | Thomas Schöpping | #ifndef AMIROLLD_MPU6050_H
|
28 | #define AMIROLLD_MPU6050_H
|
||
29 | 5d4d14a3 | Thomas Schöpping | |
30 | #include <amiro-lld.h> |
||
31 | |||
32 | /******************************************************************************/
|
||
33 | /* CONSTANTS */
|
||
34 | /******************************************************************************/
|
||
35 | |||
36 | /**
|
||
37 | * @brief Maximum I2C frequency.
|
||
38 | */
|
||
39 | #define MPU6050_LLD_I2C_MAXFREQUENCY 400000 |
||
40 | |||
41 | b6364b51 | Thomas Schöpping | /* Default I2C address */
|
42 | #define MPU6050_LLD_I2C_ADDR_FIXED 0x68 |
||
43 | #define MPU6050_LLD_I2C_ADDR_AD0 0x01 |
||
44 | |||
45 | /* MPU6050 registers */
|
||
46 | #define MPU6050_LLD_AUX_VDDIO 0x01 |
||
47 | #define MPU6050_LLD_SMPLRT_DIV 0x19 |
||
48 | #define MPU6050_LLD_CONFIG 0x1A |
||
49 | #define MPU6050_LLD_GYRO_CONFIG 0x1B |
||
50 | #define MPU6050_LLD_ACCEL_CONFIG 0x1C |
||
51 | #define MPU6050_LLD_MOTION_THRESH 0x1F |
||
52 | #define MPU6050_LLD_INT_PIN_CFG 0x37 |
||
53 | #define MPU6050_LLD_INT_ENABLE 0x38 |
||
54 | #define MPU6050_LLD_INT_STATUS 0x3A |
||
55 | #define MPU6050_LLD_ACCEL_XOUT_H 0x3B |
||
56 | #define MPU6050_LLD_ACCEL_XOUT_L 0x3C |
||
57 | #define MPU6050_LLD_ACCEL_YOUT_H 0x3D |
||
58 | #define MPU6050_LLD_ACCEL_YOUT_L 0x3E |
||
59 | #define MPU6050_LLD_ACCEL_ZOUT_H 0x3F |
||
60 | #define MPU6050_LLD_ACCEL_ZOUT_L 0x40 |
||
61 | #define MPU6050_LLD_TEMP_OUT_H 0x41 |
||
62 | #define MPU6050_LLD_TEMP_OUT_L 0x42 |
||
63 | #define MPU6050_LLD_GYRO_XOUT_H 0x43 |
||
64 | #define MPU6050_LLD_GYRO_XOUT_L 0x44 |
||
65 | #define MPU6050_LLD_GYRO_YOUT_H 0x45 |
||
66 | #define MPU6050_LLD_GYRO_YOUT_L 0x46 |
||
67 | #define MPU6050_LLD_GYRO_ZOUT_H 0x47 |
||
68 | #define MPU6050_LLD_GYRO_ZOUT_L 0x48 |
||
69 | #define MPU6050_LLD_MOT_DETECT_STATUS 0x61 |
||
70 | #define MPU6050_LLD_SIGNAL_PATH_RESET 0x68 |
||
71 | #define MPU6050_LLD_MOT_DETECT_CTRL 0x69 |
||
72 | #define MPU6050_LLD_USER_CTRL 0x6A |
||
73 | #define MPU6050_LLD_PWR_MGMT_1 0x6B |
||
74 | #define MPU6050_LLD_PWR_MGMT_2 0x6C |
||
75 | #define MPU6050_LLD_FIFO_COUNTH 0x72 |
||
76 | #define MPU6050_LLD_FIFO_COUNTL 0x73 |
||
77 | #define MPU6050_LLD_FIFO_R_W 0x74 |
||
78 | #define MPU6050_LLD_WHO_AM_I 0x75 |
||
79 | |||
80 | #define MPU6050_LLD_DataRate_8KHz 0 /**< Sample rate set to 8 kHz */ |
||
81 | #define MPU6050_LLD_DataRate_4KHz 1 /**< Sample rate set to 4 kHz */ |
||
82 | #define MPU6050_LLD_DataRate_2KHz 3 /**< Sample rate set to 2 kHz */ |
||
83 | #define MPU6050_LLD_DataRate_1KHz 7 /**< Sample rate set to 1 kHz */ |
||
84 | #define MPU6050_LLD_DataRate_500Hz 15 /**< Sample rate set to 500 Hz */ |
||
85 | #define MPU6050_LLD_DataRate_250Hz 31 /**< Sample rate set to 250 Hz */ |
||
86 | #define MPU6050_LLD_DataRate_125Hz 63 /**< Sample rate set to 125 Hz */ |
||
87 | #define MPU6050_LLD_DataRate_100Hz 79 /**< Sample rate set to 100 Hz */ |
||
88 | |||
89 | /* Who I am register value */
|
||
90 | #define MPU6050_I_AM MPU6050_LLD_I2C_ADDR_FIXED
|
||
91 | |||
92 | /* Gyro sensitivities in degrees/s */
|
||
93 | #define MPU6050_LLD_GYRO_SENS_250 ((float) 131) |
||
94 | #define MPU6050_LLD_GYRO_SENS_500 ((float) 65.5) |
||
95 | #define MPU6050_LLD_GYRO_SENS_1000 ((float) 32.8) |
||
96 | #define MPU6050_LLD_GYRO_SENS_2000 ((float) 16.4) |
||
97 | |||
98 | /* Acce sensitivities in g/s */
|
||
99 | #define MPU6050_LLD_ACCE_SENS_2 ((float) 16384) |
||
100 | #define MPU6050_LLD_ACCE_SENS_4 ((float) 8192) |
||
101 | #define MPU6050_LLD_ACCE_SENS_8 ((float) 4096) |
||
102 | #define MPU6050_LLD_ACCE_SENS_16 ((float) 2048) |
||
103 | 5d4d14a3 | Thomas Schöpping | |
104 | /******************************************************************************/
|
||
105 | /* SETTINGS */
|
||
106 | /******************************************************************************/
|
||
107 | |||
108 | /******************************************************************************/
|
||
109 | /* CHECKS */
|
||
110 | /******************************************************************************/
|
||
111 | |||
112 | /******************************************************************************/
|
||
113 | /* DATA STRUCTURES AND TYPES */
|
||
114 | /******************************************************************************/
|
||
115 | |||
116 | /**
|
||
117 | * @brief MPU6050 can have 2 different slave addresses, depends on it's input AD0 pin
|
||
118 | * This feature allows you to use 2 different sensors with this library at the same time
|
||
119 | */
|
||
120 | typedef enum { |
||
121 | SD_MPU6050_Device_0 = 0x00, /*!< AD0 pin is set to low */ |
||
122 | SD_MPU6050_Device_1 = 0x02 /*!< AD0 pin is set to high */ |
||
123 | } SD_MPU6050_Device; |
||
124 | |||
125 | /**
|
||
126 | * @brief MPU6050 result enumeration
|
||
127 | */
|
||
128 | typedef enum { |
||
129 | SD_MPU6050_Result_Ok = 0x00, /*!< Everything OK */ |
||
130 | SD_MPU6050_Result_Error, /*!< Unknown error */
|
||
131 | SD_MPU6050_Result_DeviceNotConnected, /*!< There is no device with valid slave address */
|
||
132 | SD_MPU6050_Result_DeviceInvalid /*!< Connected device with address is not MPU6050 */
|
||
133 | } SD_MPU6050_Result; |
||
134 | |||
135 | /**
|
||
136 | * @brief Parameters for accelerometer range
|
||
137 | */
|
||
138 | typedef enum { |
||
139 | SD_MPU6050_Accelerometer_2G = 0x00, /*!< Range is +- 2G */ |
||
140 | SD_MPU6050_Accelerometer_4G = 0x01, /*!< Range is +- 4G */ |
||
141 | SD_MPU6050_Accelerometer_8G = 0x02, /*!< Range is +- 8G */ |
||
142 | SD_MPU6050_Accelerometer_16G = 0x03 /*!< Range is +- 16G */ |
||
143 | } SD_MPU6050_Accelerometer; |
||
144 | |||
145 | /**
|
||
146 | * @brief Parameters for gyroscope range
|
||
147 | */
|
||
148 | typedef enum { |
||
149 | SD_MPU6050_Gyroscope_250s = 0x00, /*!< Range is +- 250 degrees/s */ |
||
150 | SD_MPU6050_Gyroscope_500s = 0x01, /*!< Range is +- 500 degrees/s */ |
||
151 | SD_MPU6050_Gyroscope_1000s = 0x02, /*!< Range is +- 1000 degrees/s */ |
||
152 | SD_MPU6050_Gyroscope_2000s = 0x03 /*!< Range is +- 2000 degrees/s */ |
||
153 | } SD_MPU6050_Gyroscope; |
||
154 | |||
155 | |||
156 | /**
|
||
157 | * @brief Interrupts union and structure
|
||
158 | */
|
||
159 | typedef union { |
||
160 | struct {
|
||
161 | uint8_t DataReady:1; /*!< Data ready interrupt */ |
||
162 | uint8_t reserved2:2; /*!< Reserved bits */ |
||
163 | uint8_t Master:1; /*!< Master interrupt. Not enabled with library */ |
||
164 | uint8_t FifoOverflow:1; /*!< FIFO overflow interrupt. Not enabled with library */ |
||
165 | uint8_t reserved1:1; /*!< Reserved bit */ |
||
166 | uint8_t MotionDetection:1; /*!< Motion detected interrupt */ |
||
167 | uint8_t reserved0:1; /*!< Reserved bit */ |
||
168 | } F; |
||
169 | uint8_t Status; |
||
170 | } SD_MPU6050_Interrupt; |
||
171 | |||
172 | /**
|
||
173 | * @brief Config register.
|
||
174 | */
|
||
175 | typedef union { |
||
176 | uint16_t data; |
||
177 | struct {
|
||
178 | /**
|
||
179 | ina219_lld_mode_t mode : 3;
|
||
180 | ina219_lld_adc_t sadc : 4;
|
||
181 | ina219_lld_adc_t badc : 4;
|
||
182 | ina219_lld_gain_t gain : 2;
|
||
183 | ina219_lld_brng_t brng : 1;
|
||
184 | */
|
||
185 | uint8_t zero : 1;
|
||
186 | uint8_t reset : 1;
|
||
187 | } options; |
||
188 | } mpu6050_lld_cfg_t; |
||
189 | |||
190 | |||
191 | /**
|
||
192 | * @brief The MPU6050 struct.
|
||
193 | */
|
||
194 | typedef struct { |
||
195 | apalI2CDriver_t* i2cd; |
||
196 | apalI2Caddr_t addr; /**<The address of the module for I2C communication */
|
||
197 | } MPU6050Driver; |
||
198 | |||
199 | /******************************************************************************/
|
||
200 | /* MACROS */
|
||
201 | /******************************************************************************/
|
||
202 | |||
203 | /******************************************************************************/
|
||
204 | /* EXTERN DECLARATIONS */
|
||
205 | /******************************************************************************/
|
||
206 | |||
207 | #ifdef __cplusplus
|
||
208 | extern "C" { |
||
209 | #endif
|
||
210 | b6364b51 | Thomas Schöpping | apalExitStatus_t mpu6050_lld_read_register(const MPU6050Driver* const mpu6050, const uint8_t addr, uint8_t* const data, const uint8_t num, const apalTime_t timeout); |
211 | apalExitStatus_t mpu6050_lld_write_register(const MPU6050Driver* const mpu6050, const uint8_t addr, const uint8_t* const data, const uint8_t num, const apalTime_t timeout); |
||
212 | 5d4d14a3 | Thomas Schöpping | #ifdef __cplusplus
|
213 | } |
||
214 | #endif
|
||
215 | |||
216 | /******************************************************************************/
|
||
217 | /* INLINE FUNCTIONS */
|
||
218 | /******************************************************************************/
|
||
219 | |||
220 | 9466e34d | Thomas Schöpping | #endif /* AMIROLLD_MPU6050_H */ |
221 | |||
222 | 5d4d14a3 | Thomas Schöpping | |
223 | 9466e34d | Thomas Schöpping | /** @} */
|