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