Crispin Mukalay / MPU6050

Dependents:   MPU_6050_Hello_World PJ12_glove MPU_6050_Hello_World

Committer:
213468891
Date:
Thu Oct 18 16:53:29 2018 +0000
Revision:
0:f4905c7ef2ce
Read 3-axis gyroscope and 3-axis accelerometer readings.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
213468891 0:f4905c7ef2ce 1 /**
213468891 0:f4905c7ef2ce 2 * @author Crispin Mukalay
213468891 0:f4905c7ef2ce 3 *
213468891 0:f4905c7ef2ce 4 * @section LICENSE
213468891 0:f4905c7ef2ce 5 *
213468891 0:f4905c7ef2ce 6 * Copyright (c) 2010 ARM Limited
213468891 0:f4905c7ef2ce 7 *
213468891 0:f4905c7ef2ce 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
213468891 0:f4905c7ef2ce 9 * of this software and associated documentation files (the "Software"), to deal
213468891 0:f4905c7ef2ce 10 * in the Software without restriction, including without limitation the rights
213468891 0:f4905c7ef2ce 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
213468891 0:f4905c7ef2ce 12 * copies of the Software, and to permit persons to whom the Software is
213468891 0:f4905c7ef2ce 13 * furnished to do so, subject to the following conditions:
213468891 0:f4905c7ef2ce 14 *
213468891 0:f4905c7ef2ce 15 * The above copyright notice and this permission notice shall be included in
213468891 0:f4905c7ef2ce 16 * all copies or substantial portions of the Software.
213468891 0:f4905c7ef2ce 17 *
213468891 0:f4905c7ef2ce 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
213468891 0:f4905c7ef2ce 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
213468891 0:f4905c7ef2ce 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
213468891 0:f4905c7ef2ce 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
213468891 0:f4905c7ef2ce 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
213468891 0:f4905c7ef2ce 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
213468891 0:f4905c7ef2ce 24 * THE SOFTWARE.
213468891 0:f4905c7ef2ce 25 *
213468891 0:f4905c7ef2ce 26 * @section DESCRIPTION
213468891 0:f4905c7ef2ce 27 *
213468891 0:f4905c7ef2ce 28 * MPU-6050 triple-axis MEMS gyroscope and triple-axis MEMS accelerometer.
213468891 0:f4905c7ef2ce 29 *
213468891 0:f4905c7ef2ce 30 * Datasheet:
213468891 0:f4905c7ef2ce 31 *
213468891 0:f4905c7ef2ce 32 * https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf
213468891 0:f4905c7ef2ce 33 */
213468891 0:f4905c7ef2ce 34
213468891 0:f4905c7ef2ce 35 #ifndef MPU6050_H
213468891 0:f4905c7ef2ce 36 #define MPU6050_H
213468891 0:f4905c7ef2ce 37
213468891 0:f4905c7ef2ce 38 /**
213468891 0:f4905c7ef2ce 39 * Includes
213468891 0:f4905c7ef2ce 40 */
213468891 0:f4905c7ef2ce 41 #include "mbed.h"
213468891 0:f4905c7ef2ce 42
213468891 0:f4905c7ef2ce 43 /**
213468891 0:f4905c7ef2ce 44 * Defines
213468891 0:f4905c7ef2ce 45 */
213468891 0:f4905c7ef2ce 46 #define MPU6050_I2C_ADDRESS 0x68 //7-bit address of slave device (MPU6050).
213468891 0:f4905c7ef2ce 47
213468891 0:f4905c7ef2ce 48 //-----------
213468891 0:f4905c7ef2ce 49 // Registers
213468891 0:f4905c7ef2ce 50 //-----------
213468891 0:f4905c7ef2ce 51 #define SELF_TEST_X_REG 0x0D
213468891 0:f4905c7ef2ce 52 #define SELF_TEST_Y_REG 0x0E
213468891 0:f4905c7ef2ce 53 #define SELF_TEST_Z_REG 0x0F
213468891 0:f4905c7ef2ce 54 #define SELF_TEST_A_REG 0x10
213468891 0:f4905c7ef2ce 55 #define SMPLRT_DIV_REG 0x19
213468891 0:f4905c7ef2ce 56 #define CONFIG_REG 0x1A
213468891 0:f4905c7ef2ce 57 #define GYRO_CONFIG_REG 0x1B
213468891 0:f4905c7ef2ce 58 #define ACCEL_CONFIG_REG 0x1C
213468891 0:f4905c7ef2ce 59 #define FIFO_EN_REG 0x23
213468891 0:f4905c7ef2ce 60 #define I2C_MST_CTRL_REG 0x24
213468891 0:f4905c7ef2ce 61 #define I2C_SLV0_ADDR_REG 0x25
213468891 0:f4905c7ef2ce 62 #define I2C_SLV0_REG 0x26
213468891 0:f4905c7ef2ce 63 #define I2C_SLV0_CTRL_REG 0x27
213468891 0:f4905c7ef2ce 64 #define I2C_SLV1_ADDR_REG 0x28
213468891 0:f4905c7ef2ce 65 #define I2C_SLV1_REG 0x29
213468891 0:f4905c7ef2ce 66 #define I2C_SLV1_CTRL_REG 0x2A
213468891 0:f4905c7ef2ce 67 #define I2C_SLV2_ADDR_REG 0x2B
213468891 0:f4905c7ef2ce 68 #define I2C_SLV2_REG 0x2C
213468891 0:f4905c7ef2ce 69 #define I2C_SLV2_CTRL_REG 0x2D
213468891 0:f4905c7ef2ce 70 #define I2C_SLV3_ADDR_REG 0x2E
213468891 0:f4905c7ef2ce 71 #define I2C_SLV3_REG 0x2F
213468891 0:f4905c7ef2ce 72 #define I2C_SLV3_CTRL_REG 0x30
213468891 0:f4905c7ef2ce 73 #define I2C_SLV4_ADDR_REG 0x31
213468891 0:f4905c7ef2ce 74 #define I2C_SLV4_REG 0x32
213468891 0:f4905c7ef2ce 75 #define I2C_SLV4_DO_REG 0x33
213468891 0:f4905c7ef2ce 76 #define I2C_SLV4_CTRL_REG 0x34
213468891 0:f4905c7ef2ce 77 #define I2C_SLV4_DI_REG 0x35
213468891 0:f4905c7ef2ce 78 #define I2C_MST_STATUS_REG 0x36
213468891 0:f4905c7ef2ce 79 #define INT_PIN_CFG_REG 0x37
213468891 0:f4905c7ef2ce 80 #define INT_ENABLE_REG 0x38
213468891 0:f4905c7ef2ce 81 #define INT_STATUS_REG 0x3A
213468891 0:f4905c7ef2ce 82 #define ACCEL_XOUT_H_REG 0x3B
213468891 0:f4905c7ef2ce 83 #define ACCEL_XOUT_L_REG 0x3C
213468891 0:f4905c7ef2ce 84 #define ACCEL_YOUT_H_REG 0x3D
213468891 0:f4905c7ef2ce 85 #define ACCEL_YOUT_L_REG 0x3E
213468891 0:f4905c7ef2ce 86 #define ACCEL_ZOUT_H_REG 0x3F
213468891 0:f4905c7ef2ce 87 #define ACCEL_ZOUT_L_REG 0x40
213468891 0:f4905c7ef2ce 88 #define TEMP_OUT_H_REG 0x41
213468891 0:f4905c7ef2ce 89 #define TEMP_OUT_L_REG 0x42
213468891 0:f4905c7ef2ce 90 #define GYRO_XOUT_H_REG 0x43
213468891 0:f4905c7ef2ce 91 #define GYRO_XOUT_L_REG 0x44
213468891 0:f4905c7ef2ce 92 #define GYRO_YOUT_H_REG 0x45
213468891 0:f4905c7ef2ce 93 #define GYRO_YOUT_L_REG 0x46
213468891 0:f4905c7ef2ce 94 #define GYRO_ZOUT_H_REG 0x47
213468891 0:f4905c7ef2ce 95 #define GYRO_ZOUT_L_REG 0x48
213468891 0:f4905c7ef2ce 96 #define EXT_SENS_DATA_00_REG 0x49
213468891 0:f4905c7ef2ce 97 #define EXT_SENS_DATA_01_REG 0x4A
213468891 0:f4905c7ef2ce 98 #define EXT_SENS_DATA_02_REG 0x4B
213468891 0:f4905c7ef2ce 99 #define EXT_SENS_DATA_03_REG 0x4C
213468891 0:f4905c7ef2ce 100 #define EXT_SENS_DATA_04_REG 0x4D
213468891 0:f4905c7ef2ce 101 #define EXT_SENS_DATA_05_REG 0x4E
213468891 0:f4905c7ef2ce 102 #define EXT_SENS_DATA_06_REG 0x4F
213468891 0:f4905c7ef2ce 103 #define EXT_SENS_DATA_07_REG 0x50
213468891 0:f4905c7ef2ce 104 #define EXT_SENS_DATA_08_REG 0x51
213468891 0:f4905c7ef2ce 105 #define EXT_SENS_DATA_09_REG 0x52
213468891 0:f4905c7ef2ce 106 #define EXT_SENS_DATA_10_REG 0x53
213468891 0:f4905c7ef2ce 107 #define EXT_SENS_DATA_11_REG 0x54
213468891 0:f4905c7ef2ce 108 #define EXT_SENS_DATA_12_REG 0x55
213468891 0:f4905c7ef2ce 109 #define EXT_SENS_DATA_13_REG 0x56
213468891 0:f4905c7ef2ce 110 #define EXT_SENS_DATA_14_REG 0x57
213468891 0:f4905c7ef2ce 111 #define EXT_SENS_DATA_15_REG 0x58
213468891 0:f4905c7ef2ce 112 #define EXT_SENS_DATA_16_REG 0x59
213468891 0:f4905c7ef2ce 113 #define EXT_SENS_DATA_17_REG 0x5A
213468891 0:f4905c7ef2ce 114 #define EXT_SENS_DATA_18_REG 0x5B
213468891 0:f4905c7ef2ce 115 #define EXT_SENS_DATA_19_REG 0x5C
213468891 0:f4905c7ef2ce 116 #define EXT_SENS_DATA_20_REG 0x5D
213468891 0:f4905c7ef2ce 117 #define EXT_SENS_DATA_21_REG 0x5E
213468891 0:f4905c7ef2ce 118 #define EXT_SENS_DATA_22_REG 0x5F
213468891 0:f4905c7ef2ce 119 #define EXT_SENS_DATA_23_REG 0x60
213468891 0:f4905c7ef2ce 120 #define I2C_SLV0_DO_REG 0x63
213468891 0:f4905c7ef2ce 121 #define I2C_SLV1_DO_REG 0x64
213468891 0:f4905c7ef2ce 122 #define I2C_SLV2_DO_REG 0x65
213468891 0:f4905c7ef2ce 123 #define I2C_SLV3_DO_REG 0x66
213468891 0:f4905c7ef2ce 124 #define I2C_MST_DELAY_CTRL_REG 0x67
213468891 0:f4905c7ef2ce 125 #define SIGNAL_PATH_RESET_REG 0x68
213468891 0:f4905c7ef2ce 126 #define USER_CTRL_REG 0x6A
213468891 0:f4905c7ef2ce 127 #define PWR_MGMT_1_REG 0x6B
213468891 0:f4905c7ef2ce 128 #define PWR_MGMT_2_REG 0x6C
213468891 0:f4905c7ef2ce 129 #define FIFO_COUNTH_REG 0x72
213468891 0:f4905c7ef2ce 130 #define FIFO_COUNTL_REG 0x73
213468891 0:f4905c7ef2ce 131 #define FIFO_R_W_REG 0x74
213468891 0:f4905c7ef2ce 132 #define WHO_AM_I_REG 0x75
213468891 0:f4905c7ef2ce 133
213468891 0:f4905c7ef2ce 134 //----------------------------------------------
213468891 0:f4905c7ef2ce 135 // External Frame Synchronization Configuration
213468891 0:f4905c7ef2ce 136 //----------------------------------------------
213468891 0:f4905c7ef2ce 137 #define FSYNC_DISABLE 0x00
213468891 0:f4905c7ef2ce 138 #define FSYNC_TEMP_OUT_L 0x01
213468891 0:f4905c7ef2ce 139 #define FSYNC_GYRO_XOUT_L 0x02
213468891 0:f4905c7ef2ce 140 #define FSYNC_GYRO_YOUT_L 0x03
213468891 0:f4905c7ef2ce 141 #define FSYNC_GYRO_ZOUT_L 0x04
213468891 0:f4905c7ef2ce 142 #define FSYNC_ACCEL_XOUT_L 0x05
213468891 0:f4905c7ef2ce 143 #define FSYNC_ACCEL_YOUT_L 0x06
213468891 0:f4905c7ef2ce 144 #define FSYNC_ACCEL_ZOUT_L 0x07
213468891 0:f4905c7ef2ce 145
213468891 0:f4905c7ef2ce 146 //---------------------------------------
213468891 0:f4905c7ef2ce 147 // Digital Low Pass Filter Configuration
213468891 0:f4905c7ef2ce 148 //---------------------------------------
213468891 0:f4905c7ef2ce 149 #define DLPF_260_256 0x00
213468891 0:f4905c7ef2ce 150 #define DLPF_184_188 0x01
213468891 0:f4905c7ef2ce 151 #define DLPF_94_98 0x02
213468891 0:f4905c7ef2ce 152 #define DLPF_44_42 0x03
213468891 0:f4905c7ef2ce 153 #define DLPF_21_20 0x04
213468891 0:f4905c7ef2ce 154 #define DLPF_10_10 0x05
213468891 0:f4905c7ef2ce 155 #define DLPF_5_5 0x06
213468891 0:f4905c7ef2ce 156
213468891 0:f4905c7ef2ce 157 //------------------------------------
213468891 0:f4905c7ef2ce 158 // Gyroscope Selft-Test Configuration
213468891 0:f4905c7ef2ce 159 //------------------------------------
213468891 0:f4905c7ef2ce 160 #define GFS_DISABLE 0x00
213468891 0:f4905c7ef2ce 161 #define GFS_250dps 0x00
213468891 0:f4905c7ef2ce 162 #define GFS_500dps 0x08
213468891 0:f4905c7ef2ce 163 #define GFS_1000dps 0x10
213468891 0:f4905c7ef2ce 164 #define GFS_2000dps 0x18
213468891 0:f4905c7ef2ce 165 #define GYRO_ST_ON 0xE0
213468891 0:f4905c7ef2ce 166 #define GYRO_ST_OFF 0x00
213468891 0:f4905c7ef2ce 167
213468891 0:f4905c7ef2ce 168
213468891 0:f4905c7ef2ce 169 //----------------------------------------
213468891 0:f4905c7ef2ce 170 // Accelerometer Selft-Test Configuration
213468891 0:f4905c7ef2ce 171 //----------------------------------------
213468891 0:f4905c7ef2ce 172 #define AFS_DSIABLE 0x00
213468891 0:f4905c7ef2ce 173 #define AFS_2g 0x00
213468891 0:f4905c7ef2ce 174 #define AFS_4g 0x08
213468891 0:f4905c7ef2ce 175 #define AFS_8g 0x10
213468891 0:f4905c7ef2ce 176 #define AFS_16g 0x18
213468891 0:f4905c7ef2ce 177 #define ACC_ST_ON 0xE0
213468891 0:f4905c7ef2ce 178 #define ACC_ST_OFF 0x00
213468891 0:f4905c7ef2ce 179
213468891 0:f4905c7ef2ce 180 //----------------------------------------------
213468891 0:f4905c7ef2ce 181 // Sensor Measurements To Load In FIFO Register
213468891 0:f4905c7ef2ce 182 //----------------------------------------------
213468891 0:f4905c7ef2ce 183 #define TEMP_FIFO_EN 0x80
213468891 0:f4905c7ef2ce 184 #define GYRO_FIFO_EN 0x70
213468891 0:f4905c7ef2ce 185 #define ACCEL_FIFO_EN 0x08
213468891 0:f4905c7ef2ce 186 #define SLV2_FIFO_EN 0x04
213468891 0:f4905c7ef2ce 187 #define SLV1_FIFO_EN 0x02
213468891 0:f4905c7ef2ce 188 #define SLV0_FIFO_EN 0x01
213468891 0:f4905c7ef2ce 189 #define SLVZ_FIFO_EN 0x07
213468891 0:f4905c7ef2ce 190 #define TEMPGYROACCEL_FIFO_EN 0xF8
213468891 0:f4905c7ef2ce 191 #define GYROACCEL_FIFO_EN 0x78
213468891 0:f4905c7ef2ce 192 #define TEMPGYROACCELSLVZ_FIFO_EN 0xFF
213468891 0:f4905c7ef2ce 193
213468891 0:f4905c7ef2ce 194 //---------------------------
213468891 0:f4905c7ef2ce 195 // Signal Path Reset Values
213468891 0:f4905c7ef2ce 196 //---------------------------
213468891 0:f4905c7ef2ce 197 #define GYRRO_RESET 0x04
213468891 0:f4905c7ef2ce 198 #define ACCEL_RESET 0x02
213468891 0:f4905c7ef2ce 199 #define TEMP_RESET 0x01
213468891 0:f4905c7ef2ce 200 #define ALL_RESET 0x07
213468891 0:f4905c7ef2ce 201
213468891 0:f4905c7ef2ce 202 //-------------------------------
213468891 0:f4905c7ef2ce 203 // User Control settings
213468891 0:f4905c7ef2ce 204 //-------------------------------
213468891 0:f4905c7ef2ce 205 #define FIFO_EN 0x40
213468891 0:f4905c7ef2ce 206 #define FIFO_DIS 0x00
213468891 0:f4905c7ef2ce 207 #define I2C_MST_EN 0x60
213468891 0:f4905c7ef2ce 208 #define I2C_MST_DIS 0x00
213468891 0:f4905c7ef2ce 209 #define FIFO_RESET 0x04
213468891 0:f4905c7ef2ce 210 #define I2C_MST_RESET 0x02
213468891 0:f4905c7ef2ce 211 #define SIG_COND_RESET 0x41
213468891 0:f4905c7ef2ce 212
213468891 0:f4905c7ef2ce 213 //---------------------------------
213468891 0:f4905c7ef2ce 214 // Power Management Setings One
213468891 0:f4905c7ef2ce 215 //---------------------------------
213468891 0:f4905c7ef2ce 216 #define DEVICE_RESET 0x80
213468891 0:f4905c7ef2ce 217 #define SEEP 0x40
213468891 0:f4905c7ef2ce 218 #define CYCLE 0x20
213468891 0:f4905c7ef2ce 219 #define TEMP_DIS 0x08
213468891 0:f4905c7ef2ce 220 #define INT_8MHz_OSC 0x00
213468891 0:f4905c7ef2ce 221 #define PLL_GYROX_REF 0x01
213468891 0:f4905c7ef2ce 222 #define PLL_GYROY_REF 0x02
213468891 0:f4905c7ef2ce 223 #define PLL_GYROZ_REF 0x03
213468891 0:f4905c7ef2ce 224 #define PLL_EXT_32KHz_REF 0x04
213468891 0:f4905c7ef2ce 225 #define PLL_EXT_19KHz_REF 0x05
213468891 0:f4905c7ef2ce 226
213468891 0:f4905c7ef2ce 227 //---------------------------------
213468891 0:f4905c7ef2ce 228 // Power Management Settings Two
213468891 0:f4905c7ef2ce 229 //---------------------------------
213468891 0:f4905c7ef2ce 230 #define LP_WAKE_CTRL_1Hz 0x00
213468891 0:f4905c7ef2ce 231 #define LP_WAKE_CTRL_5Hz 0x40
213468891 0:f4905c7ef2ce 232 #define LP_WAKE_CTRL_20Hz 0x80
213468891 0:f4905c7ef2ce 233 #define LP_WAKE_CTRL_40Hz 0xC0
213468891 0:f4905c7ef2ce 234
213468891 0:f4905c7ef2ce 235
213468891 0:f4905c7ef2ce 236 /**
213468891 0:f4905c7ef2ce 237 * MPU6050 triple axis digital gyroscope and triple axis digital accelerometer.
213468891 0:f4905c7ef2ce 238 */
213468891 0:f4905c7ef2ce 239 class MPU6050 {
213468891 0:f4905c7ef2ce 240
213468891 0:f4905c7ef2ce 241 public:
213468891 0:f4905c7ef2ce 242
213468891 0:f4905c7ef2ce 243 MPU6050(I2C &i2c);
213468891 0:f4905c7ef2ce 244
213468891 0:f4905c7ef2ce 245 /**
213468891 0:f4905c7ef2ce 246 *
213468891 0:f4905c7ef2ce 247 * @param sda - mbed pin to use for the SDA I2C line.
213468891 0:f4905c7ef2ce 248 * @param scl - mbed pin to use for the SCL I2C line.
213468891 0:f4905c7ef2ce 249 */
213468891 0:f4905c7ef2ce 250 MPU6050(PinName sda, PinName scl);
213468891 0:f4905c7ef2ce 251
213468891 0:f4905c7ef2ce 252 /**
213468891 0:f4905c7ef2ce 253 * Self-test permits users to test the mechanical and electrical portions of the MPU6050.
213468891 0:f4905c7ef2ce 254 *
213468891 0:f4905c7ef2ce 255 * @return Contents of the self-test registers.
213468891 0:f4905c7ef2ce 256 * Array of XA_TEST, YA_TEST, ZA_TEST, XG_TEST, YG_TEST and ZG_TEST.
213468891 0:f4905c7ef2ce 257 */
213468891 0:f4905c7ef2ce 258 void selfTest(uint8_t* TestReadings);
213468891 0:f4905c7ef2ce 259
213468891 0:f4905c7ef2ce 260 /**
213468891 0:f4905c7ef2ce 261 * Set Sample Rate for the MPU-6050 senor output, FIFO, and DMP registers.
213468891 0:f4905c7ef2ce 262 *
213468891 0:f4905c7ef2ce 263 * @param Divider - The sample rate divider as a number from 0x00 - 0xFF.
213468891 0:f4905c7ef2ce 264 *
213468891 0:f4905c7ef2ce 265 */
213468891 0:f4905c7ef2ce 266 void setSampleRate(uint8_t Divider);
213468891 0:f4905c7ef2ce 267
213468891 0:f4905c7ef2ce 268 /**
213468891 0:f4905c7ef2ce 269 * Get Sample Rate for the MPU-6050 senor output, FIFO, and DMP registers.
213468891 0:f4905c7ef2ce 270 *
213468891 0:f4905c7ef2ce 271 * @return Sample rate.
213468891 0:f4905c7ef2ce 272 *
213468891 0:f4905c7ef2ce 273 */
213468891 0:f4905c7ef2ce 274 uint8_t getSampleRate(void);
213468891 0:f4905c7ef2ce 275
213468891 0:f4905c7ef2ce 276 /**
213468891 0:f4905c7ef2ce 277 * Set the external Frame Synchronization (FSYNC) pin sampling.
213468891 0:f4905c7ef2ce 278 *
213468891 0:f4905c7ef2ce 279 * @param Conf - The configuration setting as a number from 0x00 - 0xFF.
213468891 0:f4905c7ef2ce 280 *
213468891 0:f4905c7ef2ce 281 */
213468891 0:f4905c7ef2ce 282 void setFSYNCConfig(uint8_t Conf);
213468891 0:f4905c7ef2ce 283
213468891 0:f4905c7ef2ce 284 /**
213468891 0:f4905c7ef2ce 285 * Get the Frame Synchronization (FSYNC) configuration.
213468891 0:f4905c7ef2ce 286 *
213468891 0:f4905c7ef2ce 287 * @return Current Frame Synchronization (FSYNC) configuration.
213468891 0:f4905c7ef2ce 288 *
213468891 0:f4905c7ef2ce 289 */
213468891 0:f4905c7ef2ce 290 uint8_t getFSYNCConfig(void);
213468891 0:f4905c7ef2ce 291
213468891 0:f4905c7ef2ce 292 /**
213468891 0:f4905c7ef2ce 293 * Set the Digital Low Pass Filter (DLPF) setting for both gyro and accelemometer.
213468891 0:f4905c7ef2ce 294 *
213468891 0:f4905c7ef2ce 295 * @param Conf - The configuration setting as a number from 0-7.
213468891 0:f4905c7ef2ce 296 *
213468891 0:f4905c7ef2ce 297 */
213468891 0:f4905c7ef2ce 298 void setDLPFConfig(uint8_t Conf);
213468891 0:f4905c7ef2ce 299
213468891 0:f4905c7ef2ce 300 /**
213468891 0:f4905c7ef2ce 301 * Get the Digital Low Pass Filter (DLPF) setting for both gyro and accelemometer.
213468891 0:f4905c7ef2ce 302 *
213468891 0:f4905c7ef2ce 303 * @return Current Digital Low Pass Filter (DLPF) setting.
213468891 0:f4905c7ef2ce 304 *
213468891 0:f4905c7ef2ce 305 */
213468891 0:f4905c7ef2ce 306 uint8_t getDLPFConfig(void);
213468891 0:f4905c7ef2ce 307
213468891 0:f4905c7ef2ce 308 /**
213468891 0:f4905c7ef2ce 309 * Set the gyroscope self-test trigger and scale range configuration.
213468891 0:f4905c7ef2ce 310 *
213468891 0:f4905c7ef2ce 311 * @param GyroST - Trigger Gyroscope self-test setting. GYRO_ST_ON or GYRO_ST_OFF.
213468891 0:f4905c7ef2ce 312 * @param Scale - The full scale range setting for the gyroscope GFS_DISABLE, GFS_250dps, GFS_500dps, GFS_1000dps, GFS_2000dps.
213468891 0:f4905c7ef2ce 313 *
213468891 0:f4905c7ef2ce 314 */
213468891 0:f4905c7ef2ce 315 void setGyroConfig(uint8_t GyroST, uint8_t Scale);
213468891 0:f4905c7ef2ce 316
213468891 0:f4905c7ef2ce 317 /**
213468891 0:f4905c7ef2ce 318 * Get the gyroscope self-test trigger and scale range configuration.
213468891 0:f4905c7ef2ce 319 *
213468891 0:f4905c7ef2ce 320 * @return Current gyroscope self-test configuration.
213468891 0:f4905c7ef2ce 321 *
213468891 0:f4905c7ef2ce 322 */
213468891 0:f4905c7ef2ce 323 uint8_t getGyroConfig(void);
213468891 0:f4905c7ef2ce 324
213468891 0:f4905c7ef2ce 325 /**
213468891 0:f4905c7ef2ce 326 * Set the gyroscope self-test trigger and scale range configuration.
213468891 0:f4905c7ef2ce 327 *
213468891 0:f4905c7ef2ce 328 * @param AccST - Trigger Accelerometer self-test setting. ACC_ST_ON or ACC_ST_OFF.
213468891 0:f4905c7ef2ce 329 * @param Scale - The full scale range setting for the accelemometer AFS_DSIABLE, AFS_2g, AFS_4g, AFS_8g, AFS_16g.
213468891 0:f4905c7ef2ce 330 *
213468891 0:f4905c7ef2ce 331 */
213468891 0:f4905c7ef2ce 332 void setAccelConfig(uint8_t AccST, uint8_t Scale);
213468891 0:f4905c7ef2ce 333
213468891 0:f4905c7ef2ce 334 /**
213468891 0:f4905c7ef2ce 335 * Get the accelerometer self-test trigger and scale range configuration.
213468891 0:f4905c7ef2ce 336 *
213468891 0:f4905c7ef2ce 337 * @return Current accelerometer self-test configuration.
213468891 0:f4905c7ef2ce 338 *
213468891 0:f4905c7ef2ce 339 */
213468891 0:f4905c7ef2ce 340 uint8_t getAccelConfig(void);
213468891 0:f4905c7ef2ce 341
213468891 0:f4905c7ef2ce 342 /**
213468891 0:f4905c7ef2ce 343 * Set the setting for sensor measurements to be loaded to the FIFO register
213468891 0:f4905c7ef2ce 344 *
213468891 0:f4905c7ef2ce 345 * @param Setting - The configuration settings which determines the sensor measurements loaded into the FIFO register.
213468891 0:f4905c7ef2ce 346 * TEMP_FIFO_EN, GYRO_FIFO_EN, ACCEL_FIFO_EN, SLV2_FIFO_EN, SLV1_FIFO_EN, SLV0_FIFO_EN, SLVZ_FIFO_EN,
213468891 0:f4905c7ef2ce 347 * TEMPGYROACCEL_FIFO_EN, GYROACCEL_FIFO_EN, TEMPGYROACCELSLVZ_FIFO_EN.
213468891 0:f4905c7ef2ce 348 */
213468891 0:f4905c7ef2ce 349 void setFIFO_Enable(uint8_t Setting);
213468891 0:f4905c7ef2ce 350
213468891 0:f4905c7ef2ce 351 /**
213468891 0:f4905c7ef2ce 352 * Get the setting for sensor measurements to be loaded to the FIFO register.
213468891 0:f4905c7ef2ce 353 *
213468891 0:f4905c7ef2ce 354 * @return Current setting which determines the sensor measurements loaded into the FIFO register.
213468891 0:f4905c7ef2ce 355 *
213468891 0:f4905c7ef2ce 356 */
213468891 0:f4905c7ef2ce 357 uint8_t getFIFO_Enable(void);
213468891 0:f4905c7ef2ce 358
213468891 0:f4905c7ef2ce 359 /**
213468891 0:f4905c7ef2ce 360 * The most recent accelemometer measurements.
213468891 0:f4905c7ef2ce 361 *
213468891 0:f4905c7ef2ce 362 * @return Contents of Accelerometer measurement registers.
213468891 0:f4905c7ef2ce 363 * Array of ACCEL_XOUT, ACCEL_YOUT, ACCEL_ZOUT as 16-bit 2's complement values.
213468891 0:f4905c7ef2ce 364 */
213468891 0:f4905c7ef2ce 365 void readAccel(uint16_t* AccReadings);
213468891 0:f4905c7ef2ce 366
213468891 0:f4905c7ef2ce 367 /**
213468891 0:f4905c7ef2ce 368 * The most recent temperature measurements.
213468891 0:f4905c7ef2ce 369 *
213468891 0:f4905c7ef2ce 370 * @return TempReadings - Contents Temperature measurement registers.
213468891 0:f4905c7ef2ce 371 * TEMP_OUT as 16-bit 2's complement value.
213468891 0:f4905c7ef2ce 372 */
213468891 0:f4905c7ef2ce 373 void readTemp(uint16_t* TempReadings);
213468891 0:f4905c7ef2ce 374
213468891 0:f4905c7ef2ce 375 /**
213468891 0:f4905c7ef2ce 376 * The most recent gyroscope measurements.
213468891 0:f4905c7ef2ce 377 *
213468891 0:f4905c7ef2ce 378 * @return Contents of Gyroscope measurement registers.
213468891 0:f4905c7ef2ce 379 * Array of GYRO_XOUT, GYRO_YOUT, GYRO_ZOUT as 16-bit 2's complement values.
213468891 0:f4905c7ef2ce 380 */
213468891 0:f4905c7ef2ce 381 void readGyro(uint16_t* GyroReadings);
213468891 0:f4905c7ef2ce 382
213468891 0:f4905c7ef2ce 383 /**
213468891 0:f4905c7ef2ce 384 * Resets the analog and digital paths of the gyroscope, accelemometer and temperature sensors.
213468891 0:f4905c7ef2ce 385 *
213468891 0:f4905c7ef2ce 386 * @param ResVal - The reset settings GYRO_RESET, ACCEL_RESET, TEMP_RESET, ALL_RESET.
213468891 0:f4905c7ef2ce 387 *
213468891 0:f4905c7ef2ce 388 */
213468891 0:f4905c7ef2ce 389 void sigPathReset(uint8_t ResVal);
213468891 0:f4905c7ef2ce 390
213468891 0:f4905c7ef2ce 391 /**
213468891 0:f4905c7ef2ce 392 * Enable or disable FIFO buffer, I2C Master Mode, and primary I2C interface.
213468891 0:f4905c7ef2ce 393 *
213468891 0:f4905c7ef2ce 394 * @param Settings - The configuration settings for user control register.
213468891 0:f4905c7ef2ce 395 * FIFO_EN, FIFO_DIS, I2C_MST_EN, I2C_MST_DIS, FIFO_RESET, I2C_MST_RESET, SIG_COND_RESET.
213468891 0:f4905c7ef2ce 396 *
213468891 0:f4905c7ef2ce 397 */
213468891 0:f4905c7ef2ce 398 void setUserCtl(uint8_t Settings);
213468891 0:f4905c7ef2ce 399
213468891 0:f4905c7ef2ce 400 /**
213468891 0:f4905c7ef2ce 401 * Get the user setting for FIFO buffer, I2C Master Mode, and primary I2C interface.
213468891 0:f4905c7ef2ce 402 *
213468891 0:f4905c7ef2ce 403 * @return Current user settings for FIFO buffer, I2C Master Mode, and primary I2C interface.
213468891 0:f4905c7ef2ce 404 *
213468891 0:f4905c7ef2ce 405 */
213468891 0:f4905c7ef2ce 406 uint8_t getUserCtl(void);
213468891 0:f4905c7ef2ce 407
213468891 0:f4905c7ef2ce 408 /**
213468891 0:f4905c7ef2ce 409 * Set the power mode control settings.
213468891 0:f4905c7ef2ce 410 *
213468891 0:f4905c7ef2ce 411 * @param DevRes - Resets all internal resgisters to their default values. DEVICE_RESET or 0x00.
213468891 0:f4905c7ef2ce 412 * @param Sleep - Puts the MPU6050 into sleep mode. SEEP or 0x00.
213468891 0:f4905c7ef2ce 413 * @param Cycle - Cycles MPU6050 between sleep mode and waking up to take a single sample of data from active sensors
213468891 0:f4905c7ef2ce 414 * at a rate determined by LP_WAKE_CTRL register. CYCLE or 0x00.
213468891 0:f4905c7ef2ce 415 * @param Temp - Disables the temperature sensor. TEMP_DIS or 0x00.
213468891 0:f4905c7ef2ce 416 * @param Clock - Specifies the clock source of the device.
213468891 0:f4905c7ef2ce 417 * Settings INT_8MHz_OSC, PLL_GYROX_REF, PLL_GYROY_REF, PLL_GYROZ_REF, PLL_EXT_32KHz_REF, PLL_EXT_19KHz_REF.
213468891 0:f4905c7ef2ce 418 *
213468891 0:f4905c7ef2ce 419 */
213468891 0:f4905c7ef2ce 420 void setPowerCtl_1(uint8_t DevRes, uint8_t Sleep, uint8_t Cycle, uint8_t Temp, uint8_t Clock);
213468891 0:f4905c7ef2ce 421
213468891 0:f4905c7ef2ce 422 /**
213468891 0:f4905c7ef2ce 423 * Get the power mode and clock source.
213468891 0:f4905c7ef2ce 424 *
213468891 0:f4905c7ef2ce 425 * @return Current power mode control settings.
213468891 0:f4905c7ef2ce 426 *
213468891 0:f4905c7ef2ce 427 */
213468891 0:f4905c7ef2ce 428 uint8_t getPowerCtl_1(void);
213468891 0:f4905c7ef2ce 429
213468891 0:f4905c7ef2ce 430 /**
213468891 0:f4905c7ef2ce 431 * Set frequency of wake-ups in Accelerometer Only Low Power Mode, as well as individual gyroscope and accelemometer axes standby configuration.
213468891 0:f4905c7ef2ce 432 *
213468891 0:f4905c7ef2ce 433 * @param Conf - Wake-up and axes standby configuration.
213468891 0:f4905c7ef2ce 434 * Configurations LP_WAKE_CTRL_1Hz, LP_WAKE_CTRL_5Hz, LP_WAKE_CTRL_20Hz, LP_WAKE_CTRL_40Hz.
213468891 0:f4905c7ef2ce 435 *
213468891 0:f4905c7ef2ce 436 */
213468891 0:f4905c7ef2ce 437 void setPowerCtl_2(uint8_t Conf);
213468891 0:f4905c7ef2ce 438
213468891 0:f4905c7ef2ce 439 /**
213468891 0:f4905c7ef2ce 440 * Get frequency of wake-ups in Accelerometer Only Low Power Mode, as well as individual gyroscope and accelemometer axes standby status.
213468891 0:f4905c7ef2ce 441 *
213468891 0:f4905c7ef2ce 442 * @return Current wake-up and individual axes standby status.
213468891 0:f4905c7ef2ce 443 *
213468891 0:f4905c7ef2ce 444 */
213468891 0:f4905c7ef2ce 445 uint8_t getPowerCtl_2(void);
213468891 0:f4905c7ef2ce 446
213468891 0:f4905c7ef2ce 447 /**
213468891 0:f4905c7ef2ce 448 * Read the number of samples currenly in the FIFO buffer.
213468891 0:f4905c7ef2ce 449 *
213468891 0:f4905c7ef2ce 450 * @return Current number of samples in the FIFO buffer.
213468891 0:f4905c7ef2ce 451 *
213468891 0:f4905c7ef2ce 452 */
213468891 0:f4905c7ef2ce 453 uint16_t getFIFOCount(void);
213468891 0:f4905c7ef2ce 454
213468891 0:f4905c7ef2ce 455 /**
213468891 0:f4905c7ef2ce 456 * This register is used to write data to the FIFO buffer.
213468891 0:f4905c7ef2ce 457 *
213468891 0:f4905c7ef2ce 458 * @param Data - Data to write to the FIFO buffer. Value from 0x00 - 0xFF.
213468891 0:f4905c7ef2ce 459 *
213468891 0:f4905c7ef2ce 460 */
213468891 0:f4905c7ef2ce 461 void FIFODataWrite(uint8_t Data);
213468891 0:f4905c7ef2ce 462
213468891 0:f4905c7ef2ce 463 /**
213468891 0:f4905c7ef2ce 464 * This register is used to read data from the FIFO buffer.
213468891 0:f4905c7ef2ce 465 *
213468891 0:f4905c7ef2ce 466 * @return Data located in the FIFO buffer.
213468891 0:f4905c7ef2ce 467 *
213468891 0:f4905c7ef2ce 468 */
213468891 0:f4905c7ef2ce 469 uint8_t FIFODataRead(void);
213468891 0:f4905c7ef2ce 470
213468891 0:f4905c7ef2ce 471 /**
213468891 0:f4905c7ef2ce 472 * Get the identity of the device.
213468891 0:f4905c7ef2ce 473 *
213468891 0:f4905c7ef2ce 474 * @return
213468891 0:f4905c7ef2ce 475 *
213468891 0:f4905c7ef2ce 476 */
213468891 0:f4905c7ef2ce 477 uint8_t getWhoAmI(void);
213468891 0:f4905c7ef2ce 478
213468891 0:f4905c7ef2ce 479 private:
213468891 0:f4905c7ef2ce 480
213468891 0:f4905c7ef2ce 481 I2C i2c_;
213468891 0:f4905c7ef2ce 482
213468891 0:f4905c7ef2ce 483 /**
213468891 0:f4905c7ef2ce 484 * Read one byte from a register on the device.
213468891 0:f4905c7ef2ce 485 *
213468891 0:f4905c7ef2ce 486 * @param: - the address to be read from
213468891 0:f4905c7ef2ce 487 *
213468891 0:f4905c7ef2ce 488 * @return: the value of the data read
213468891 0:f4905c7ef2ce 489 */
213468891 0:f4905c7ef2ce 490 char SingleByteRead(char address);
213468891 0:f4905c7ef2ce 491
213468891 0:f4905c7ef2ce 492 /**
213468891 0:f4905c7ef2ce 493 * Write one byte to a register on the device.
213468891 0:f4905c7ef2ce 494 *
213468891 0:f4905c7ef2ce 495 * @param:
213468891 0:f4905c7ef2ce 496 - address of the register to write to.
213468891 0:f4905c7ef2ce 497 - the value of the data to store
213468891 0:f4905c7ef2ce 498 */
213468891 0:f4905c7ef2ce 499 uint8_t SingleByteWrite(char address, char data);
213468891 0:f4905c7ef2ce 500
213468891 0:f4905c7ef2ce 501 /**
213468891 0:f4905c7ef2ce 502 * Read several consecutive bytes on the device and store them in a given location.
213468891 0:f4905c7ef2ce 503 *
213468891 0:f4905c7ef2ce 504 * @param startAddress: The address of the first register to read from.
213468891 0:f4905c7ef2ce 505 * @param ptr_output: a pointer to the location to store the data being read
213468891 0:f4905c7ef2ce 506 * @param size: The number of bytes to read.
213468891 0:f4905c7ef2ce 507 */
213468891 0:f4905c7ef2ce 508 void multiByteRead(char startAddress, char* ptr_output, int size);
213468891 0:f4905c7ef2ce 509
213468891 0:f4905c7ef2ce 510 /**
213468891 0:f4905c7ef2ce 511 * Write several consecutive bytes on the device.
213468891 0:f4905c7ef2ce 512 *
213468891 0:f4905c7ef2ce 513 * @param startAddress: The address of the first register to write to.
213468891 0:f4905c7ef2ce 514 * @param ptr_data: Pointer to a location which contains the data to write.
213468891 0:f4905c7ef2ce 515 * @param size: The number of bytes to write.
213468891 0:f4905c7ef2ce 516 */
213468891 0:f4905c7ef2ce 517 uint8_t multiByteWrite(char startAddress, char* ptr_data, int size);
213468891 0:f4905c7ef2ce 518 };
213468891 0:f4905c7ef2ce 519
213468891 0:f4905c7ef2ce 520 #endif /* MPU6050_H */