USSRII Mathieu DUCROCQ

Dependencies:   mbed BSP_DISCO_F746NG

Committer:
mducrocq
Date:
Tue Jun 15 10:10:18 2021 +0000
Revision:
0:11a51c9ebb09
USRRII Mathieu Ducrocq

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mducrocq 0:11a51c9ebb09 1 //ported from arduino library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050
mducrocq 0:11a51c9ebb09 2 //written by szymon gaertig (email: szymon@gaertig.com.pl)
mducrocq 0:11a51c9ebb09 3 //
mducrocq 0:11a51c9ebb09 4 //Changelog:
mducrocq 0:11a51c9ebb09 5 //2013-01-08 - first beta release
mducrocq 0:11a51c9ebb09 6
mducrocq 0:11a51c9ebb09 7 // I2Cdev library collection - MPU6050 I2C device class
mducrocq 0:11a51c9ebb09 8 // Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
mducrocq 0:11a51c9ebb09 9 // 8/24/2011 by Jeff Rowberg <jeff@rowberg.net>
mducrocq 0:11a51c9ebb09 10 // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
mducrocq 0:11a51c9ebb09 11 //
mducrocq 0:11a51c9ebb09 12 // Changelog:
mducrocq 0:11a51c9ebb09 13 // ... - ongoing debug release
mducrocq 0:11a51c9ebb09 14
mducrocq 0:11a51c9ebb09 15 // NOTE: THIS IS ONLY A PARIAL RELEASE. THIS DEVICE CLASS IS CURRENTLY UNDERGOING ACTIVE
mducrocq 0:11a51c9ebb09 16 // DEVELOPMENT AND IS STILL MISSING SOME IMPORTANT FEATURES. PLEASE KEEP THIS IN MIND IF
mducrocq 0:11a51c9ebb09 17 // YOU DECIDE TO USE THIS PARTICULAR CODE FOR ANYTHING.
mducrocq 0:11a51c9ebb09 18
mducrocq 0:11a51c9ebb09 19 /* ============================================
mducrocq 0:11a51c9ebb09 20 I2Cdev device library code is placed under the MIT license
mducrocq 0:11a51c9ebb09 21 Copyright (c) 2012 Jeff Rowberg
mducrocq 0:11a51c9ebb09 22
mducrocq 0:11a51c9ebb09 23 Permission is hereby granted, free of charge, to any person obtaining a copy
mducrocq 0:11a51c9ebb09 24 of this software and associated documentation files (the "Software"), to deal
mducrocq 0:11a51c9ebb09 25 in the Software without restriction, including without limitation the rights
mducrocq 0:11a51c9ebb09 26 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mducrocq 0:11a51c9ebb09 27 copies of the Software, and to permit persons to whom the Software is
mducrocq 0:11a51c9ebb09 28 furnished to do so, subject to the following conditions:
mducrocq 0:11a51c9ebb09 29
mducrocq 0:11a51c9ebb09 30 The above copyright notice and this permission notice shall be included in
mducrocq 0:11a51c9ebb09 31 all copies or substantial portions of the Software.
mducrocq 0:11a51c9ebb09 32
mducrocq 0:11a51c9ebb09 33 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mducrocq 0:11a51c9ebb09 34 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mducrocq 0:11a51c9ebb09 35 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mducrocq 0:11a51c9ebb09 36 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mducrocq 0:11a51c9ebb09 37 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mducrocq 0:11a51c9ebb09 38 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mducrocq 0:11a51c9ebb09 39 THE SOFTWARE.
mducrocq 0:11a51c9ebb09 40 ===============================================
mducrocq 0:11a51c9ebb09 41 */
mducrocq 0:11a51c9ebb09 42
mducrocq 0:11a51c9ebb09 43 #include "MPU6050.h"
mducrocq 0:11a51c9ebb09 44
mducrocq 0:11a51c9ebb09 45 #define LOG(args...) // printf(args)
mducrocq 0:11a51c9ebb09 46
mducrocq 0:11a51c9ebb09 47 //instead of using pgmspace.h
mducrocq 0:11a51c9ebb09 48 typedef const unsigned char prog_uchar;
mducrocq 0:11a51c9ebb09 49 #define pgm_read_byte_near(x) (*(prog_uchar*)x)
mducrocq 0:11a51c9ebb09 50 #define pgm_read_byte(x) (*(prog_uchar*)x)
mducrocq 0:11a51c9ebb09 51
mducrocq 0:11a51c9ebb09 52 /** Specific address constructor.
mducrocq 0:11a51c9ebb09 53 * @param address I2C address
mducrocq 0:11a51c9ebb09 54 * @see MPU6050_DEFAULT_ADDRESS
mducrocq 0:11a51c9ebb09 55 * @see MPU6050_ADDRESS_AD0_LOW
mducrocq 0:11a51c9ebb09 56 * @see MPU6050_ADDRESS_AD0_HIGH
mducrocq 0:11a51c9ebb09 57 */
mducrocq 0:11a51c9ebb09 58 MPU6050::MPU6050(I2C &i2c, uint8_t address) : i2Cdev(i2c)
mducrocq 0:11a51c9ebb09 59 {
mducrocq 0:11a51c9ebb09 60 devAddr = address;
mducrocq 0:11a51c9ebb09 61 }
mducrocq 0:11a51c9ebb09 62
mducrocq 0:11a51c9ebb09 63 /** Power on and prepare for general usage.
mducrocq 0:11a51c9ebb09 64 * This will activate the device and take it out of sleep mode (which must be done
mducrocq 0:11a51c9ebb09 65 * after start-up). This function also sets both the accelerometer and the gyroscope
mducrocq 0:11a51c9ebb09 66 * to their most sensitive settings, namely +/- 2g and +/- 250 degrees/sec, and sets
mducrocq 0:11a51c9ebb09 67 * the clock source to use the X Gyro for reference, which is slightly better than
mducrocq 0:11a51c9ebb09 68 * the default internal clock source.
mducrocq 0:11a51c9ebb09 69 */
mducrocq 0:11a51c9ebb09 70 void MPU6050::initialize()
mducrocq 0:11a51c9ebb09 71 {
mducrocq 0:11a51c9ebb09 72 LOG("MPU6050::initialize start\n");
mducrocq 0:11a51c9ebb09 73
mducrocq 0:11a51c9ebb09 74 setClockSource(MPU6050_CLOCK_PLL_XGYRO);
mducrocq 0:11a51c9ebb09 75 setFullScaleGyroRange(MPU6050_GYRO_FS_250);
mducrocq 0:11a51c9ebb09 76 setFullScaleAccelRange(MPU6050_ACCEL_FS_2);
mducrocq 0:11a51c9ebb09 77 setSleepEnabled(false); // thanks to Jack Elston for pointing this one out!
mducrocq 0:11a51c9ebb09 78
mducrocq 0:11a51c9ebb09 79 LOG("MPU6050::initialize end\n");
mducrocq 0:11a51c9ebb09 80 }
mducrocq 0:11a51c9ebb09 81
mducrocq 0:11a51c9ebb09 82 /** Verify the I2C connection.
mducrocq 0:11a51c9ebb09 83 * Make sure the device is connected and responds as expected.
mducrocq 0:11a51c9ebb09 84 * @return True if connection is valid, false otherwise
mducrocq 0:11a51c9ebb09 85 */
mducrocq 0:11a51c9ebb09 86 bool MPU6050::testConnection()
mducrocq 0:11a51c9ebb09 87 {
mducrocq 0:11a51c9ebb09 88 LOG("MPU6050::testConnection start\n");
mducrocq 0:11a51c9ebb09 89
mducrocq 0:11a51c9ebb09 90 uint8_t deviceId = getDeviceID();
mducrocq 0:11a51c9ebb09 91
mducrocq 0:11a51c9ebb09 92 LOG("DeviceId = %d\n",deviceId);
mducrocq 0:11a51c9ebb09 93
mducrocq 0:11a51c9ebb09 94 return deviceId == 0x34;
mducrocq 0:11a51c9ebb09 95 }
mducrocq 0:11a51c9ebb09 96
mducrocq 0:11a51c9ebb09 97 // AUX_VDDIO register (InvenSense demo code calls this RA_*G_OFFS_TC)
mducrocq 0:11a51c9ebb09 98
mducrocq 0:11a51c9ebb09 99 /** Get the auxiliary I2C supply voltage level.
mducrocq 0:11a51c9ebb09 100 * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to
mducrocq 0:11a51c9ebb09 101 * 0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to
mducrocq 0:11a51c9ebb09 102 * the MPU-6000, which does not have a VLOGIC pin.
mducrocq 0:11a51c9ebb09 103 * @return I2C supply voltage level (0=VLOGIC, 1=VDD)
mducrocq 0:11a51c9ebb09 104 */
mducrocq 0:11a51c9ebb09 105 uint8_t MPU6050::getAuxVDDIOLevel()
mducrocq 0:11a51c9ebb09 106 {
mducrocq 0:11a51c9ebb09 107 i2Cdev.readBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, buffer);
mducrocq 0:11a51c9ebb09 108 return buffer[0];
mducrocq 0:11a51c9ebb09 109 }
mducrocq 0:11a51c9ebb09 110 /** Set the auxiliary I2C supply voltage level.
mducrocq 0:11a51c9ebb09 111 * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to
mducrocq 0:11a51c9ebb09 112 * 0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to
mducrocq 0:11a51c9ebb09 113 * the MPU-6000, which does not have a VLOGIC pin.
mducrocq 0:11a51c9ebb09 114 * @param level I2C supply voltage level (0=VLOGIC, 1=VDD)
mducrocq 0:11a51c9ebb09 115 */
mducrocq 0:11a51c9ebb09 116 void MPU6050::setAuxVDDIOLevel(uint8_t level)
mducrocq 0:11a51c9ebb09 117 {
mducrocq 0:11a51c9ebb09 118 i2Cdev.writeBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, level);
mducrocq 0:11a51c9ebb09 119 }
mducrocq 0:11a51c9ebb09 120
mducrocq 0:11a51c9ebb09 121 // SMPLRT_DIV register
mducrocq 0:11a51c9ebb09 122
mducrocq 0:11a51c9ebb09 123 /** Get gyroscope output rate divider.
mducrocq 0:11a51c9ebb09 124 * The sensor register output, FIFO output, DMP sampling, Motion detection, Zero
mducrocq 0:11a51c9ebb09 125 * Motion detection, and Free Fall detection are all based on the Sample Rate.
mducrocq 0:11a51c9ebb09 126 * The Sample Rate is generated by dividing the gyroscope output rate by
mducrocq 0:11a51c9ebb09 127 * SMPLRT_DIV:
mducrocq 0:11a51c9ebb09 128 *
mducrocq 0:11a51c9ebb09 129 * Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
mducrocq 0:11a51c9ebb09 130 *
mducrocq 0:11a51c9ebb09 131 * where Gyroscope Output Rate = 8kHz when the DLPF is disabled (DLPF_CFG = 0 or
mducrocq 0:11a51c9ebb09 132 * 7), and 1kHz when the DLPF is enabled (see Register 26).
mducrocq 0:11a51c9ebb09 133 *
mducrocq 0:11a51c9ebb09 134 * Note: The accelerometer output rate is 1kHz. This means that for a Sample
mducrocq 0:11a51c9ebb09 135 * Rate greater than 1kHz, the same accelerometer sample may be output to the
mducrocq 0:11a51c9ebb09 136 * FIFO, DMP, and sensor registers more than once.
mducrocq 0:11a51c9ebb09 137 *
mducrocq 0:11a51c9ebb09 138 * For a diagram of the gyroscope and accelerometer signal paths, see Section 8
mducrocq 0:11a51c9ebb09 139 * of the MPU-6000/MPU-6050 Product Specification document.
mducrocq 0:11a51c9ebb09 140 *
mducrocq 0:11a51c9ebb09 141 * @return Current sample rate
mducrocq 0:11a51c9ebb09 142 * @see MPU6050_RA_SMPLRT_DIV
mducrocq 0:11a51c9ebb09 143 */
mducrocq 0:11a51c9ebb09 144 uint8_t MPU6050::getRate()
mducrocq 0:11a51c9ebb09 145 {
mducrocq 0:11a51c9ebb09 146 i2Cdev.readByte(devAddr, MPU6050_RA_SMPLRT_DIV, buffer);
mducrocq 0:11a51c9ebb09 147 return buffer[0];
mducrocq 0:11a51c9ebb09 148 }
mducrocq 0:11a51c9ebb09 149 /** Set gyroscope sample rate divider.
mducrocq 0:11a51c9ebb09 150 * @param rate New sample rate divider
mducrocq 0:11a51c9ebb09 151 * @see getRate()
mducrocq 0:11a51c9ebb09 152 * @see MPU6050_RA_SMPLRT_DIV
mducrocq 0:11a51c9ebb09 153 */
mducrocq 0:11a51c9ebb09 154 void MPU6050::setRate(uint8_t rate)
mducrocq 0:11a51c9ebb09 155 {
mducrocq 0:11a51c9ebb09 156 i2Cdev.writeByte(devAddr, MPU6050_RA_SMPLRT_DIV, rate);
mducrocq 0:11a51c9ebb09 157 }
mducrocq 0:11a51c9ebb09 158
mducrocq 0:11a51c9ebb09 159 // CONFIG register
mducrocq 0:11a51c9ebb09 160
mducrocq 0:11a51c9ebb09 161 /** Get external FSYNC configuration.
mducrocq 0:11a51c9ebb09 162 * Configures the external Frame Synchronization (FSYNC) pin sampling. An
mducrocq 0:11a51c9ebb09 163 * external signal connected to the FSYNC pin can be sampled by configuring
mducrocq 0:11a51c9ebb09 164 * EXT_SYNC_SET. Signal changes to the FSYNC pin are latched so that short
mducrocq 0:11a51c9ebb09 165 * strobes may be captured. The latched FSYNC signal will be sampled at the
mducrocq 0:11a51c9ebb09 166 * Sampling Rate, as defined in register 25. After sampling, the latch will
mducrocq 0:11a51c9ebb09 167 * reset to the current FSYNC signal state.
mducrocq 0:11a51c9ebb09 168 *
mducrocq 0:11a51c9ebb09 169 * The sampled value will be reported in place of the least significant bit in
mducrocq 0:11a51c9ebb09 170 * a sensor data register determined by the value of EXT_SYNC_SET according to
mducrocq 0:11a51c9ebb09 171 * the following table.
mducrocq 0:11a51c9ebb09 172 *
mducrocq 0:11a51c9ebb09 173 * <pre>
mducrocq 0:11a51c9ebb09 174 * EXT_SYNC_SET | FSYNC Bit Location
mducrocq 0:11a51c9ebb09 175 * -------------+-------------------
mducrocq 0:11a51c9ebb09 176 * 0 | Input disabled
mducrocq 0:11a51c9ebb09 177 * 1 | TEMP_OUT_L[0]
mducrocq 0:11a51c9ebb09 178 * 2 | GYRO_XOUT_L[0]
mducrocq 0:11a51c9ebb09 179 * 3 | GYRO_YOUT_L[0]
mducrocq 0:11a51c9ebb09 180 * 4 | GYRO_ZOUT_L[0]
mducrocq 0:11a51c9ebb09 181 * 5 | ACCEL_XOUT_L[0]
mducrocq 0:11a51c9ebb09 182 * 6 | ACCEL_YOUT_L[0]
mducrocq 0:11a51c9ebb09 183 * 7 | ACCEL_ZOUT_L[0]
mducrocq 0:11a51c9ebb09 184 * </pre>
mducrocq 0:11a51c9ebb09 185 *
mducrocq 0:11a51c9ebb09 186 * @return FSYNC configuration value
mducrocq 0:11a51c9ebb09 187 */
mducrocq 0:11a51c9ebb09 188 uint8_t MPU6050::getExternalFrameSync()
mducrocq 0:11a51c9ebb09 189 {
mducrocq 0:11a51c9ebb09 190 i2Cdev.readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 191 return buffer[0];
mducrocq 0:11a51c9ebb09 192 }
mducrocq 0:11a51c9ebb09 193 /** Set external FSYNC configuration.
mducrocq 0:11a51c9ebb09 194 * @see getExternalFrameSync()
mducrocq 0:11a51c9ebb09 195 * @see MPU6050_RA_CONFIG
mducrocq 0:11a51c9ebb09 196 * @param sync New FSYNC configuration value
mducrocq 0:11a51c9ebb09 197 */
mducrocq 0:11a51c9ebb09 198 void MPU6050::setExternalFrameSync(uint8_t sync)
mducrocq 0:11a51c9ebb09 199 {
mducrocq 0:11a51c9ebb09 200 i2Cdev.writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, sync);
mducrocq 0:11a51c9ebb09 201 }
mducrocq 0:11a51c9ebb09 202 /** Get digital low-pass filter configuration.
mducrocq 0:11a51c9ebb09 203 * The DLPF_CFG parameter sets the digital low pass filter configuration. It
mducrocq 0:11a51c9ebb09 204 * also determines the internal sampling rate used by the device as shown in
mducrocq 0:11a51c9ebb09 205 * the table below.
mducrocq 0:11a51c9ebb09 206 *
mducrocq 0:11a51c9ebb09 207 * Note: The accelerometer output rate is 1kHz. This means that for a Sample
mducrocq 0:11a51c9ebb09 208 * Rate greater than 1kHz, the same accelerometer sample may be output to the
mducrocq 0:11a51c9ebb09 209 * FIFO, DMP, and sensor registers more than once.
mducrocq 0:11a51c9ebb09 210 *
mducrocq 0:11a51c9ebb09 211 * <pre>
mducrocq 0:11a51c9ebb09 212 * | ACCELEROMETER | GYROSCOPE
mducrocq 0:11a51c9ebb09 213 * DLPF_CFG | Bandwidth | Delay | Bandwidth | Delay | Sample Rate
mducrocq 0:11a51c9ebb09 214 * ---------+-----------+--------+-----------+--------+-------------
mducrocq 0:11a51c9ebb09 215 * 0 | 260Hz | 0ms | 256Hz | 0.98ms | 8kHz
mducrocq 0:11a51c9ebb09 216 * 1 | 184Hz | 2.0ms | 188Hz | 1.9ms | 1kHz
mducrocq 0:11a51c9ebb09 217 * 2 | 94Hz | 3.0ms | 98Hz | 2.8ms | 1kHz
mducrocq 0:11a51c9ebb09 218 * 3 | 44Hz | 4.9ms | 42Hz | 4.8ms | 1kHz
mducrocq 0:11a51c9ebb09 219 * 4 | 21Hz | 8.5ms | 20Hz | 8.3ms | 1kHz
mducrocq 0:11a51c9ebb09 220 * 5 | 10Hz | 13.8ms | 10Hz | 13.4ms | 1kHz
mducrocq 0:11a51c9ebb09 221 * 6 | 5Hz | 19.0ms | 5Hz | 18.6ms | 1kHz
mducrocq 0:11a51c9ebb09 222 * 7 | -- Reserved -- | -- Reserved -- | Reserved
mducrocq 0:11a51c9ebb09 223 * </pre>
mducrocq 0:11a51c9ebb09 224 *
mducrocq 0:11a51c9ebb09 225 * @return DLFP configuration
mducrocq 0:11a51c9ebb09 226 * @see MPU6050_RA_CONFIG
mducrocq 0:11a51c9ebb09 227 * @see MPU6050_CFG_DLPF_CFG_BIT
mducrocq 0:11a51c9ebb09 228 * @see MPU6050_CFG_DLPF_CFG_LENGTH
mducrocq 0:11a51c9ebb09 229 */
mducrocq 0:11a51c9ebb09 230 uint8_t MPU6050::getDLPFMode()
mducrocq 0:11a51c9ebb09 231 {
mducrocq 0:11a51c9ebb09 232 i2Cdev.readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 233 return buffer[0];
mducrocq 0:11a51c9ebb09 234 }
mducrocq 0:11a51c9ebb09 235 /** Set digital low-pass filter configuration.
mducrocq 0:11a51c9ebb09 236 * @param mode New DLFP configuration setting
mducrocq 0:11a51c9ebb09 237 * @see getDLPFBandwidth()
mducrocq 0:11a51c9ebb09 238 * @see MPU6050_DLPF_BW_256
mducrocq 0:11a51c9ebb09 239 * @see MPU6050_RA_CONFIG
mducrocq 0:11a51c9ebb09 240 * @see MPU6050_CFG_DLPF_CFG_BIT
mducrocq 0:11a51c9ebb09 241 * @see MPU6050_CFG_DLPF_CFG_LENGTH
mducrocq 0:11a51c9ebb09 242 */
mducrocq 0:11a51c9ebb09 243 void MPU6050::setDLPFMode(uint8_t mode)
mducrocq 0:11a51c9ebb09 244 {
mducrocq 0:11a51c9ebb09 245 i2Cdev.writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, mode);
mducrocq 0:11a51c9ebb09 246 }
mducrocq 0:11a51c9ebb09 247
mducrocq 0:11a51c9ebb09 248 // GYRO_CONFIG register
mducrocq 0:11a51c9ebb09 249
mducrocq 0:11a51c9ebb09 250 /** Get full-scale gyroscope range.
mducrocq 0:11a51c9ebb09 251 * The FS_SEL parameter allows setting the full-scale range of the gyro sensors,
mducrocq 0:11a51c9ebb09 252 * as described in the table below.
mducrocq 0:11a51c9ebb09 253 *
mducrocq 0:11a51c9ebb09 254 * <pre>
mducrocq 0:11a51c9ebb09 255 * 0 = +/- 250 degrees/sec
mducrocq 0:11a51c9ebb09 256 * 1 = +/- 500 degrees/sec
mducrocq 0:11a51c9ebb09 257 * 2 = +/- 1000 degrees/sec
mducrocq 0:11a51c9ebb09 258 * 3 = +/- 2000 degrees/sec
mducrocq 0:11a51c9ebb09 259 * </pre>
mducrocq 0:11a51c9ebb09 260 *
mducrocq 0:11a51c9ebb09 261 * @return Current full-scale gyroscope range setting
mducrocq 0:11a51c9ebb09 262 * @see MPU6050_GYRO_FS_250
mducrocq 0:11a51c9ebb09 263 * @see MPU6050_RA_GYRO_CONFIG
mducrocq 0:11a51c9ebb09 264 * @see MPU6050_GCONFIG_FS_SEL_BIT
mducrocq 0:11a51c9ebb09 265 * @see MPU6050_GCONFIG_FS_SEL_LENGTH
mducrocq 0:11a51c9ebb09 266 */
mducrocq 0:11a51c9ebb09 267 uint8_t MPU6050::getFullScaleGyroRange()
mducrocq 0:11a51c9ebb09 268 {
mducrocq 0:11a51c9ebb09 269 i2Cdev.readBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 270 return buffer[0];
mducrocq 0:11a51c9ebb09 271 }
mducrocq 0:11a51c9ebb09 272 /** Set full-scale gyroscope range.
mducrocq 0:11a51c9ebb09 273 * @param range New full-scale gyroscope range value
mducrocq 0:11a51c9ebb09 274 * @see getFullScaleRange()
mducrocq 0:11a51c9ebb09 275 * @see MPU6050_GYRO_FS_250
mducrocq 0:11a51c9ebb09 276 * @see MPU6050_RA_GYRO_CONFIG
mducrocq 0:11a51c9ebb09 277 * @see MPU6050_GCONFIG_FS_SEL_BIT
mducrocq 0:11a51c9ebb09 278 * @see MPU6050_GCONFIG_FS_SEL_LENGTH
mducrocq 0:11a51c9ebb09 279 */
mducrocq 0:11a51c9ebb09 280 void MPU6050::setFullScaleGyroRange(uint8_t range)
mducrocq 0:11a51c9ebb09 281 {
mducrocq 0:11a51c9ebb09 282 i2Cdev.writeBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, range);
mducrocq 0:11a51c9ebb09 283 }
mducrocq 0:11a51c9ebb09 284
mducrocq 0:11a51c9ebb09 285 // ACCEL_CONFIG register
mducrocq 0:11a51c9ebb09 286
mducrocq 0:11a51c9ebb09 287 /** Get self-test enabled setting for accelerometer X axis.
mducrocq 0:11a51c9ebb09 288 * @return Self-test enabled value
mducrocq 0:11a51c9ebb09 289 * @see MPU6050_RA_ACCEL_CONFIG
mducrocq 0:11a51c9ebb09 290 */
mducrocq 0:11a51c9ebb09 291 bool MPU6050::getAccelXSelfTest()
mducrocq 0:11a51c9ebb09 292 {
mducrocq 0:11a51c9ebb09 293 i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, buffer);
mducrocq 0:11a51c9ebb09 294 return buffer[0];
mducrocq 0:11a51c9ebb09 295 }
mducrocq 0:11a51c9ebb09 296 /** Get self-test enabled setting for accelerometer X axis.
mducrocq 0:11a51c9ebb09 297 * @param enabled Self-test enabled value
mducrocq 0:11a51c9ebb09 298 * @see MPU6050_RA_ACCEL_CONFIG
mducrocq 0:11a51c9ebb09 299 */
mducrocq 0:11a51c9ebb09 300 void MPU6050::setAccelXSelfTest(bool enabled)
mducrocq 0:11a51c9ebb09 301 {
mducrocq 0:11a51c9ebb09 302 i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, enabled);
mducrocq 0:11a51c9ebb09 303 }
mducrocq 0:11a51c9ebb09 304 /** Get self-test enabled value for accelerometer Y axis.
mducrocq 0:11a51c9ebb09 305 * @return Self-test enabled value
mducrocq 0:11a51c9ebb09 306 * @see MPU6050_RA_ACCEL_CONFIG
mducrocq 0:11a51c9ebb09 307 */
mducrocq 0:11a51c9ebb09 308 bool MPU6050::getAccelYSelfTest()
mducrocq 0:11a51c9ebb09 309 {
mducrocq 0:11a51c9ebb09 310 i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, buffer);
mducrocq 0:11a51c9ebb09 311 return buffer[0];
mducrocq 0:11a51c9ebb09 312 }
mducrocq 0:11a51c9ebb09 313 /** Get self-test enabled value for accelerometer Y axis.
mducrocq 0:11a51c9ebb09 314 * @param enabled Self-test enabled value
mducrocq 0:11a51c9ebb09 315 * @see MPU6050_RA_ACCEL_CONFIG
mducrocq 0:11a51c9ebb09 316 */
mducrocq 0:11a51c9ebb09 317 void MPU6050::setAccelYSelfTest(bool enabled)
mducrocq 0:11a51c9ebb09 318 {
mducrocq 0:11a51c9ebb09 319 i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, enabled);
mducrocq 0:11a51c9ebb09 320 }
mducrocq 0:11a51c9ebb09 321 /** Get self-test enabled value for accelerometer Z axis.
mducrocq 0:11a51c9ebb09 322 * @return Self-test enabled value
mducrocq 0:11a51c9ebb09 323 * @see MPU6050_RA_ACCEL_CONFIG
mducrocq 0:11a51c9ebb09 324 */
mducrocq 0:11a51c9ebb09 325 bool MPU6050::getAccelZSelfTest()
mducrocq 0:11a51c9ebb09 326 {
mducrocq 0:11a51c9ebb09 327 i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, buffer);
mducrocq 0:11a51c9ebb09 328 return buffer[0];
mducrocq 0:11a51c9ebb09 329 }
mducrocq 0:11a51c9ebb09 330 /** Set self-test enabled value for accelerometer Z axis.
mducrocq 0:11a51c9ebb09 331 * @param enabled Self-test enabled value
mducrocq 0:11a51c9ebb09 332 * @see MPU6050_RA_ACCEL_CONFIG
mducrocq 0:11a51c9ebb09 333 */
mducrocq 0:11a51c9ebb09 334 void MPU6050::setAccelZSelfTest(bool enabled)
mducrocq 0:11a51c9ebb09 335 {
mducrocq 0:11a51c9ebb09 336 i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, enabled);
mducrocq 0:11a51c9ebb09 337 }
mducrocq 0:11a51c9ebb09 338 /** Get full-scale accelerometer range.
mducrocq 0:11a51c9ebb09 339 * The FS_SEL parameter allows setting the full-scale range of the accelerometer
mducrocq 0:11a51c9ebb09 340 * sensors, as described in the table below.
mducrocq 0:11a51c9ebb09 341 *
mducrocq 0:11a51c9ebb09 342 * <pre>
mducrocq 0:11a51c9ebb09 343 * 0 = +/- 2g
mducrocq 0:11a51c9ebb09 344 * 1 = +/- 4g
mducrocq 0:11a51c9ebb09 345 * 2 = +/- 8g
mducrocq 0:11a51c9ebb09 346 * 3 = +/- 16g
mducrocq 0:11a51c9ebb09 347 * </pre>
mducrocq 0:11a51c9ebb09 348 *
mducrocq 0:11a51c9ebb09 349 * @return Current full-scale accelerometer range setting
mducrocq 0:11a51c9ebb09 350 * @see MPU6050_ACCEL_FS_2
mducrocq 0:11a51c9ebb09 351 * @see MPU6050_RA_ACCEL_CONFIG
mducrocq 0:11a51c9ebb09 352 * @see MPU6050_ACONFIG_AFS_SEL_BIT
mducrocq 0:11a51c9ebb09 353 * @see MPU6050_ACONFIG_AFS_SEL_LENGTH
mducrocq 0:11a51c9ebb09 354 */
mducrocq 0:11a51c9ebb09 355 uint8_t MPU6050::getFullScaleAccelRange()
mducrocq 0:11a51c9ebb09 356 {
mducrocq 0:11a51c9ebb09 357 i2Cdev.readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 358 return buffer[0];
mducrocq 0:11a51c9ebb09 359 }
mducrocq 0:11a51c9ebb09 360 /** Set full-scale accelerometer range.
mducrocq 0:11a51c9ebb09 361 * @param range New full-scale accelerometer range setting
mducrocq 0:11a51c9ebb09 362 * @see getFullScaleAccelRange()
mducrocq 0:11a51c9ebb09 363 */
mducrocq 0:11a51c9ebb09 364 void MPU6050::setFullScaleAccelRange(uint8_t range)
mducrocq 0:11a51c9ebb09 365 {
mducrocq 0:11a51c9ebb09 366 i2Cdev.writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, range);
mducrocq 0:11a51c9ebb09 367 }
mducrocq 0:11a51c9ebb09 368 /** Get the high-pass filter configuration.
mducrocq 0:11a51c9ebb09 369 * The DHPF is a filter module in the path leading to motion detectors (Free
mducrocq 0:11a51c9ebb09 370 * Fall, Motion threshold, and Zero Motion). The high pass filter output is not
mducrocq 0:11a51c9ebb09 371 * available to the data registers (see Figure in Section 8 of the MPU-6000/
mducrocq 0:11a51c9ebb09 372 * MPU-6050 Product Specification document).
mducrocq 0:11a51c9ebb09 373 *
mducrocq 0:11a51c9ebb09 374 * The high pass filter has three modes:
mducrocq 0:11a51c9ebb09 375 *
mducrocq 0:11a51c9ebb09 376 * <pre>
mducrocq 0:11a51c9ebb09 377 * Reset: The filter output settles to zero within one sample. This
mducrocq 0:11a51c9ebb09 378 * effectively disables the high pass filter. This mode may be toggled
mducrocq 0:11a51c9ebb09 379 * to quickly settle the filter.
mducrocq 0:11a51c9ebb09 380 *
mducrocq 0:11a51c9ebb09 381 * On: The high pass filter will pass signals above the cut off frequency.
mducrocq 0:11a51c9ebb09 382 *
mducrocq 0:11a51c9ebb09 383 * Hold: When triggered, the filter holds the present sample. The filter
mducrocq 0:11a51c9ebb09 384 * output will be the difference between the input sample and the held
mducrocq 0:11a51c9ebb09 385 * sample.
mducrocq 0:11a51c9ebb09 386 * </pre>
mducrocq 0:11a51c9ebb09 387 *
mducrocq 0:11a51c9ebb09 388 * <pre>
mducrocq 0:11a51c9ebb09 389 * ACCEL_HPF | Filter Mode | Cut-off Frequency
mducrocq 0:11a51c9ebb09 390 * ----------+-------------+------------------
mducrocq 0:11a51c9ebb09 391 * 0 | Reset | None
mducrocq 0:11a51c9ebb09 392 * 1 | On | 5Hz
mducrocq 0:11a51c9ebb09 393 * 2 | On | 2.5Hz
mducrocq 0:11a51c9ebb09 394 * 3 | On | 1.25Hz
mducrocq 0:11a51c9ebb09 395 * 4 | On | 0.63Hz
mducrocq 0:11a51c9ebb09 396 * 7 | Hold | None
mducrocq 0:11a51c9ebb09 397 * </pre>
mducrocq 0:11a51c9ebb09 398 *
mducrocq 0:11a51c9ebb09 399 * @return Current high-pass filter configuration
mducrocq 0:11a51c9ebb09 400 * @see MPU6050_DHPF_RESET
mducrocq 0:11a51c9ebb09 401 * @see MPU6050_RA_ACCEL_CONFIG
mducrocq 0:11a51c9ebb09 402 */
mducrocq 0:11a51c9ebb09 403 uint8_t MPU6050::getDHPFMode()
mducrocq 0:11a51c9ebb09 404 {
mducrocq 0:11a51c9ebb09 405 i2Cdev.readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 406 return buffer[0];
mducrocq 0:11a51c9ebb09 407 }
mducrocq 0:11a51c9ebb09 408 /** Set the high-pass filter configuration.
mducrocq 0:11a51c9ebb09 409 * @param bandwidth New high-pass filter configuration
mducrocq 0:11a51c9ebb09 410 * @see setDHPFMode()
mducrocq 0:11a51c9ebb09 411 * @see MPU6050_DHPF_RESET
mducrocq 0:11a51c9ebb09 412 * @see MPU6050_RA_ACCEL_CONFIG
mducrocq 0:11a51c9ebb09 413 */
mducrocq 0:11a51c9ebb09 414 void MPU6050::setDHPFMode(uint8_t bandwidth)
mducrocq 0:11a51c9ebb09 415 {
mducrocq 0:11a51c9ebb09 416 i2Cdev.writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, bandwidth);
mducrocq 0:11a51c9ebb09 417 }
mducrocq 0:11a51c9ebb09 418
mducrocq 0:11a51c9ebb09 419 // FF_THR register
mducrocq 0:11a51c9ebb09 420
mducrocq 0:11a51c9ebb09 421 /** Get free-fall event acceleration threshold.
mducrocq 0:11a51c9ebb09 422 * This register configures the detection threshold for Free Fall event
mducrocq 0:11a51c9ebb09 423 * detection. The unit of FF_THR is 1LSB = 2mg. Free Fall is detected when the
mducrocq 0:11a51c9ebb09 424 * absolute value of the accelerometer measurements for the three axes are each
mducrocq 0:11a51c9ebb09 425 * less than the detection threshold. This condition increments the Free Fall
mducrocq 0:11a51c9ebb09 426 * duration counter (Register 30). The Free Fall interrupt is triggered when the
mducrocq 0:11a51c9ebb09 427 * Free Fall duration counter reaches the time specified in FF_DUR.
mducrocq 0:11a51c9ebb09 428 *
mducrocq 0:11a51c9ebb09 429 * For more details on the Free Fall detection interrupt, see Section 8.2 of the
mducrocq 0:11a51c9ebb09 430 * MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and
mducrocq 0:11a51c9ebb09 431 * 58 of this document.
mducrocq 0:11a51c9ebb09 432 *
mducrocq 0:11a51c9ebb09 433 * @return Current free-fall acceleration threshold value (LSB = 2mg)
mducrocq 0:11a51c9ebb09 434 * @see MPU6050_RA_FF_THR
mducrocq 0:11a51c9ebb09 435 */
mducrocq 0:11a51c9ebb09 436 uint8_t MPU6050::getFreefallDetectionThreshold()
mducrocq 0:11a51c9ebb09 437 {
mducrocq 0:11a51c9ebb09 438 i2Cdev.readByte(devAddr, MPU6050_RA_FF_THR, buffer);
mducrocq 0:11a51c9ebb09 439 return buffer[0];
mducrocq 0:11a51c9ebb09 440 }
mducrocq 0:11a51c9ebb09 441 /** Get free-fall event acceleration threshold.
mducrocq 0:11a51c9ebb09 442 * @param threshold New free-fall acceleration threshold value (LSB = 2mg)
mducrocq 0:11a51c9ebb09 443 * @see getFreefallDetectionThreshold()
mducrocq 0:11a51c9ebb09 444 * @see MPU6050_RA_FF_THR
mducrocq 0:11a51c9ebb09 445 */
mducrocq 0:11a51c9ebb09 446 void MPU6050::setFreefallDetectionThreshold(uint8_t threshold)
mducrocq 0:11a51c9ebb09 447 {
mducrocq 0:11a51c9ebb09 448 i2Cdev.writeByte(devAddr, MPU6050_RA_FF_THR, threshold);
mducrocq 0:11a51c9ebb09 449 }
mducrocq 0:11a51c9ebb09 450
mducrocq 0:11a51c9ebb09 451 // FF_DUR register
mducrocq 0:11a51c9ebb09 452
mducrocq 0:11a51c9ebb09 453 /** Get free-fall event duration threshold.
mducrocq 0:11a51c9ebb09 454 * This register configures the duration counter threshold for Free Fall event
mducrocq 0:11a51c9ebb09 455 * detection. The duration counter ticks at 1kHz, therefore FF_DUR has a unit
mducrocq 0:11a51c9ebb09 456 * of 1 LSB = 1 ms.
mducrocq 0:11a51c9ebb09 457 *
mducrocq 0:11a51c9ebb09 458 * The Free Fall duration counter increments while the absolute value of the
mducrocq 0:11a51c9ebb09 459 * accelerometer measurements are each less than the detection threshold
mducrocq 0:11a51c9ebb09 460 * (Register 29). The Free Fall interrupt is triggered when the Free Fall
mducrocq 0:11a51c9ebb09 461 * duration counter reaches the time specified in this register.
mducrocq 0:11a51c9ebb09 462 *
mducrocq 0:11a51c9ebb09 463 * For more details on the Free Fall detection interrupt, see Section 8.2 of
mducrocq 0:11a51c9ebb09 464 * the MPU-6000/MPU-6050 Product Specification document as well as Registers 56
mducrocq 0:11a51c9ebb09 465 * and 58 of this document.
mducrocq 0:11a51c9ebb09 466 *
mducrocq 0:11a51c9ebb09 467 * @return Current free-fall duration threshold value (LSB = 1ms)
mducrocq 0:11a51c9ebb09 468 * @see MPU6050_RA_FF_DUR
mducrocq 0:11a51c9ebb09 469 */
mducrocq 0:11a51c9ebb09 470 uint8_t MPU6050::getFreefallDetectionDuration()
mducrocq 0:11a51c9ebb09 471 {
mducrocq 0:11a51c9ebb09 472 i2Cdev.readByte(devAddr, MPU6050_RA_FF_DUR, buffer);
mducrocq 0:11a51c9ebb09 473 return buffer[0];
mducrocq 0:11a51c9ebb09 474 }
mducrocq 0:11a51c9ebb09 475 /** Get free-fall event duration threshold.
mducrocq 0:11a51c9ebb09 476 * @param duration New free-fall duration threshold value (LSB = 1ms)
mducrocq 0:11a51c9ebb09 477 * @see getFreefallDetectionDuration()
mducrocq 0:11a51c9ebb09 478 * @see MPU6050_RA_FF_DUR
mducrocq 0:11a51c9ebb09 479 */
mducrocq 0:11a51c9ebb09 480 void MPU6050::setFreefallDetectionDuration(uint8_t duration)
mducrocq 0:11a51c9ebb09 481 {
mducrocq 0:11a51c9ebb09 482 i2Cdev.writeByte(devAddr, MPU6050_RA_FF_DUR, duration);
mducrocq 0:11a51c9ebb09 483 }
mducrocq 0:11a51c9ebb09 484
mducrocq 0:11a51c9ebb09 485 // MOT_THR register
mducrocq 0:11a51c9ebb09 486
mducrocq 0:11a51c9ebb09 487 /** Get motion detection event acceleration threshold.
mducrocq 0:11a51c9ebb09 488 * This register configures the detection threshold for Motion interrupt
mducrocq 0:11a51c9ebb09 489 * generation. The unit of MOT_THR is 1LSB = 2mg. Motion is detected when the
mducrocq 0:11a51c9ebb09 490 * absolute value of any of the accelerometer measurements exceeds this Motion
mducrocq 0:11a51c9ebb09 491 * detection threshold. This condition increments the Motion detection duration
mducrocq 0:11a51c9ebb09 492 * counter (Register 32). The Motion detection interrupt is triggered when the
mducrocq 0:11a51c9ebb09 493 * Motion Detection counter reaches the time count specified in MOT_DUR
mducrocq 0:11a51c9ebb09 494 * (Register 32).
mducrocq 0:11a51c9ebb09 495 *
mducrocq 0:11a51c9ebb09 496 * The Motion interrupt will indicate the axis and polarity of detected motion
mducrocq 0:11a51c9ebb09 497 * in MOT_DETECT_STATUS (Register 97).
mducrocq 0:11a51c9ebb09 498 *
mducrocq 0:11a51c9ebb09 499 * For more details on the Motion detection interrupt, see Section 8.3 of the
mducrocq 0:11a51c9ebb09 500 * MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and
mducrocq 0:11a51c9ebb09 501 * 58 of this document.
mducrocq 0:11a51c9ebb09 502 *
mducrocq 0:11a51c9ebb09 503 * @return Current motion detection acceleration threshold value (LSB = 2mg)
mducrocq 0:11a51c9ebb09 504 * @see MPU6050_RA_MOT_THR
mducrocq 0:11a51c9ebb09 505 */
mducrocq 0:11a51c9ebb09 506 uint8_t MPU6050::getMotionDetectionThreshold()
mducrocq 0:11a51c9ebb09 507 {
mducrocq 0:11a51c9ebb09 508 i2Cdev.readByte(devAddr, MPU6050_RA_MOT_THR, buffer);
mducrocq 0:11a51c9ebb09 509 return buffer[0];
mducrocq 0:11a51c9ebb09 510 }
mducrocq 0:11a51c9ebb09 511 /** Set free-fall event acceleration threshold.
mducrocq 0:11a51c9ebb09 512 * @param threshold New motion detection acceleration threshold value (LSB = 2mg)
mducrocq 0:11a51c9ebb09 513 * @see getMotionDetectionThreshold()
mducrocq 0:11a51c9ebb09 514 * @see MPU6050_RA_MOT_THR
mducrocq 0:11a51c9ebb09 515 */
mducrocq 0:11a51c9ebb09 516 void MPU6050::setMotionDetectionThreshold(uint8_t threshold)
mducrocq 0:11a51c9ebb09 517 {
mducrocq 0:11a51c9ebb09 518 i2Cdev.writeByte(devAddr, MPU6050_RA_MOT_THR, threshold);
mducrocq 0:11a51c9ebb09 519 }
mducrocq 0:11a51c9ebb09 520
mducrocq 0:11a51c9ebb09 521 // MOT_DUR register
mducrocq 0:11a51c9ebb09 522
mducrocq 0:11a51c9ebb09 523 /** Get motion detection event duration threshold.
mducrocq 0:11a51c9ebb09 524 * This register configures the duration counter threshold for Motion interrupt
mducrocq 0:11a51c9ebb09 525 * generation. The duration counter ticks at 1 kHz, therefore MOT_DUR has a unit
mducrocq 0:11a51c9ebb09 526 * of 1LSB = 1ms. The Motion detection duration counter increments when the
mducrocq 0:11a51c9ebb09 527 * absolute value of any of the accelerometer measurements exceeds the Motion
mducrocq 0:11a51c9ebb09 528 * detection threshold (Register 31). The Motion detection interrupt is
mducrocq 0:11a51c9ebb09 529 * triggered when the Motion detection counter reaches the time count specified
mducrocq 0:11a51c9ebb09 530 * in this register.
mducrocq 0:11a51c9ebb09 531 *
mducrocq 0:11a51c9ebb09 532 * For more details on the Motion detection interrupt, see Section 8.3 of the
mducrocq 0:11a51c9ebb09 533 * MPU-6000/MPU-6050 Product Specification document.
mducrocq 0:11a51c9ebb09 534 *
mducrocq 0:11a51c9ebb09 535 * @return Current motion detection duration threshold value (LSB = 1ms)
mducrocq 0:11a51c9ebb09 536 * @see MPU6050_RA_MOT_DUR
mducrocq 0:11a51c9ebb09 537 */
mducrocq 0:11a51c9ebb09 538 uint8_t MPU6050::getMotionDetectionDuration()
mducrocq 0:11a51c9ebb09 539 {
mducrocq 0:11a51c9ebb09 540 i2Cdev.readByte(devAddr, MPU6050_RA_MOT_DUR, buffer);
mducrocq 0:11a51c9ebb09 541 return buffer[0];
mducrocq 0:11a51c9ebb09 542 }
mducrocq 0:11a51c9ebb09 543 /** Set motion detection event duration threshold.
mducrocq 0:11a51c9ebb09 544 * @param duration New motion detection duration threshold value (LSB = 1ms)
mducrocq 0:11a51c9ebb09 545 * @see getMotionDetectionDuration()
mducrocq 0:11a51c9ebb09 546 * @see MPU6050_RA_MOT_DUR
mducrocq 0:11a51c9ebb09 547 */
mducrocq 0:11a51c9ebb09 548 void MPU6050::setMotionDetectionDuration(uint8_t duration)
mducrocq 0:11a51c9ebb09 549 {
mducrocq 0:11a51c9ebb09 550 i2Cdev.writeByte(devAddr, MPU6050_RA_MOT_DUR, duration);
mducrocq 0:11a51c9ebb09 551 }
mducrocq 0:11a51c9ebb09 552
mducrocq 0:11a51c9ebb09 553 // ZRMOT_THR register
mducrocq 0:11a51c9ebb09 554
mducrocq 0:11a51c9ebb09 555 /** Get zero motion detection event acceleration threshold.
mducrocq 0:11a51c9ebb09 556 * This register configures the detection threshold for Zero Motion interrupt
mducrocq 0:11a51c9ebb09 557 * generation. The unit of ZRMOT_THR is 1LSB = 2mg. Zero Motion is detected when
mducrocq 0:11a51c9ebb09 558 * the absolute value of the accelerometer measurements for the 3 axes are each
mducrocq 0:11a51c9ebb09 559 * less than the detection threshold. This condition increments the Zero Motion
mducrocq 0:11a51c9ebb09 560 * duration counter (Register 34). The Zero Motion interrupt is triggered when
mducrocq 0:11a51c9ebb09 561 * the Zero Motion duration counter reaches the time count specified in
mducrocq 0:11a51c9ebb09 562 * ZRMOT_DUR (Register 34).
mducrocq 0:11a51c9ebb09 563 *
mducrocq 0:11a51c9ebb09 564 * Unlike Free Fall or Motion detection, Zero Motion detection triggers an
mducrocq 0:11a51c9ebb09 565 * interrupt both when Zero Motion is first detected and when Zero Motion is no
mducrocq 0:11a51c9ebb09 566 * longer detected.
mducrocq 0:11a51c9ebb09 567 *
mducrocq 0:11a51c9ebb09 568 * When a zero motion event is detected, a Zero Motion Status will be indicated
mducrocq 0:11a51c9ebb09 569 * in the MOT_DETECT_STATUS register (Register 97). When a motion-to-zero-motion
mducrocq 0:11a51c9ebb09 570 * condition is detected, the status bit is set to 1. When a zero-motion-to-
mducrocq 0:11a51c9ebb09 571 * motion condition is detected, the status bit is set to 0.
mducrocq 0:11a51c9ebb09 572 *
mducrocq 0:11a51c9ebb09 573 * For more details on the Zero Motion detection interrupt, see Section 8.4 of
mducrocq 0:11a51c9ebb09 574 * the MPU-6000/MPU-6050 Product Specification document as well as Registers 56
mducrocq 0:11a51c9ebb09 575 * and 58 of this document.
mducrocq 0:11a51c9ebb09 576 *
mducrocq 0:11a51c9ebb09 577 * @return Current zero motion detection acceleration threshold value (LSB = 2mg)
mducrocq 0:11a51c9ebb09 578 * @see MPU6050_RA_ZRMOT_THR
mducrocq 0:11a51c9ebb09 579 */
mducrocq 0:11a51c9ebb09 580 uint8_t MPU6050::getZeroMotionDetectionThreshold()
mducrocq 0:11a51c9ebb09 581 {
mducrocq 0:11a51c9ebb09 582 i2Cdev.readByte(devAddr, MPU6050_RA_ZRMOT_THR, buffer);
mducrocq 0:11a51c9ebb09 583 return buffer[0];
mducrocq 0:11a51c9ebb09 584 }
mducrocq 0:11a51c9ebb09 585 /** Set zero motion detection event acceleration threshold.
mducrocq 0:11a51c9ebb09 586 * @param threshold New zero motion detection acceleration threshold value (LSB = 2mg)
mducrocq 0:11a51c9ebb09 587 * @see getZeroMotionDetectionThreshold()
mducrocq 0:11a51c9ebb09 588 * @see MPU6050_RA_ZRMOT_THR
mducrocq 0:11a51c9ebb09 589 */
mducrocq 0:11a51c9ebb09 590 void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold)
mducrocq 0:11a51c9ebb09 591 {
mducrocq 0:11a51c9ebb09 592 i2Cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_THR, threshold);
mducrocq 0:11a51c9ebb09 593 }
mducrocq 0:11a51c9ebb09 594
mducrocq 0:11a51c9ebb09 595 // ZRMOT_DUR register
mducrocq 0:11a51c9ebb09 596
mducrocq 0:11a51c9ebb09 597 /** Get zero motion detection event duration threshold.
mducrocq 0:11a51c9ebb09 598 * This register configures the duration counter threshold for Zero Motion
mducrocq 0:11a51c9ebb09 599 * interrupt generation. The duration counter ticks at 16 Hz, therefore
mducrocq 0:11a51c9ebb09 600 * ZRMOT_DUR has a unit of 1 LSB = 64 ms. The Zero Motion duration counter
mducrocq 0:11a51c9ebb09 601 * increments while the absolute value of the accelerometer measurements are
mducrocq 0:11a51c9ebb09 602 * each less than the detection threshold (Register 33). The Zero Motion
mducrocq 0:11a51c9ebb09 603 * interrupt is triggered when the Zero Motion duration counter reaches the time
mducrocq 0:11a51c9ebb09 604 * count specified in this register.
mducrocq 0:11a51c9ebb09 605 *
mducrocq 0:11a51c9ebb09 606 * For more details on the Zero Motion detection interrupt, see Section 8.4 of
mducrocq 0:11a51c9ebb09 607 * the MPU-6000/MPU-6050 Product Specification document, as well as Registers 56
mducrocq 0:11a51c9ebb09 608 * and 58 of this document.
mducrocq 0:11a51c9ebb09 609 *
mducrocq 0:11a51c9ebb09 610 * @return Current zero motion detection duration threshold value (LSB = 64ms)
mducrocq 0:11a51c9ebb09 611 * @see MPU6050_RA_ZRMOT_DUR
mducrocq 0:11a51c9ebb09 612 */
mducrocq 0:11a51c9ebb09 613 uint8_t MPU6050::getZeroMotionDetectionDuration()
mducrocq 0:11a51c9ebb09 614 {
mducrocq 0:11a51c9ebb09 615 i2Cdev.readByte(devAddr, MPU6050_RA_ZRMOT_DUR, buffer);
mducrocq 0:11a51c9ebb09 616 return buffer[0];
mducrocq 0:11a51c9ebb09 617 }
mducrocq 0:11a51c9ebb09 618 /** Set zero motion detection event duration threshold.
mducrocq 0:11a51c9ebb09 619 * @param duration New zero motion detection duration threshold value (LSB = 1ms)
mducrocq 0:11a51c9ebb09 620 * @see getZeroMotionDetectionDuration()
mducrocq 0:11a51c9ebb09 621 * @see MPU6050_RA_ZRMOT_DUR
mducrocq 0:11a51c9ebb09 622 */
mducrocq 0:11a51c9ebb09 623 void MPU6050::setZeroMotionDetectionDuration(uint8_t duration)
mducrocq 0:11a51c9ebb09 624 {
mducrocq 0:11a51c9ebb09 625 i2Cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_DUR, duration);
mducrocq 0:11a51c9ebb09 626 }
mducrocq 0:11a51c9ebb09 627
mducrocq 0:11a51c9ebb09 628 // FIFO_EN register
mducrocq 0:11a51c9ebb09 629
mducrocq 0:11a51c9ebb09 630 /** Get temperature FIFO enabled value.
mducrocq 0:11a51c9ebb09 631 * When set to 1, this bit enables TEMP_OUT_H and TEMP_OUT_L (Registers 65 and
mducrocq 0:11a51c9ebb09 632 * 66) to be written into the FIFO buffer.
mducrocq 0:11a51c9ebb09 633 * @return Current temperature FIFO enabled value
mducrocq 0:11a51c9ebb09 634 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 635 */
mducrocq 0:11a51c9ebb09 636 bool MPU6050::getTempFIFOEnabled()
mducrocq 0:11a51c9ebb09 637 {
mducrocq 0:11a51c9ebb09 638 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 639 return buffer[0];
mducrocq 0:11a51c9ebb09 640 }
mducrocq 0:11a51c9ebb09 641 /** Set temperature FIFO enabled value.
mducrocq 0:11a51c9ebb09 642 * @param enabled New temperature FIFO enabled value
mducrocq 0:11a51c9ebb09 643 * @see getTempFIFOEnabled()
mducrocq 0:11a51c9ebb09 644 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 645 */
mducrocq 0:11a51c9ebb09 646 void MPU6050::setTempFIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 647 {
mducrocq 0:11a51c9ebb09 648 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 649 }
mducrocq 0:11a51c9ebb09 650 /** Get gyroscope X-axis FIFO enabled value.
mducrocq 0:11a51c9ebb09 651 * When set to 1, this bit enables GYRO_XOUT_H and GYRO_XOUT_L (Registers 67 and
mducrocq 0:11a51c9ebb09 652 * 68) to be written into the FIFO buffer.
mducrocq 0:11a51c9ebb09 653 * @return Current gyroscope X-axis FIFO enabled value
mducrocq 0:11a51c9ebb09 654 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 655 */
mducrocq 0:11a51c9ebb09 656 bool MPU6050::getXGyroFIFOEnabled()
mducrocq 0:11a51c9ebb09 657 {
mducrocq 0:11a51c9ebb09 658 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 659 return buffer[0];
mducrocq 0:11a51c9ebb09 660 }
mducrocq 0:11a51c9ebb09 661 /** Set gyroscope X-axis FIFO enabled value.
mducrocq 0:11a51c9ebb09 662 * @param enabled New gyroscope X-axis FIFO enabled value
mducrocq 0:11a51c9ebb09 663 * @see getXGyroFIFOEnabled()
mducrocq 0:11a51c9ebb09 664 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 665 */
mducrocq 0:11a51c9ebb09 666 void MPU6050::setXGyroFIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 667 {
mducrocq 0:11a51c9ebb09 668 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 669 }
mducrocq 0:11a51c9ebb09 670 /** Get gyroscope Y-axis FIFO enabled value.
mducrocq 0:11a51c9ebb09 671 * When set to 1, this bit enables GYRO_YOUT_H and GYRO_YOUT_L (Registers 69 and
mducrocq 0:11a51c9ebb09 672 * 70) to be written into the FIFO buffer.
mducrocq 0:11a51c9ebb09 673 * @return Current gyroscope Y-axis FIFO enabled value
mducrocq 0:11a51c9ebb09 674 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 675 */
mducrocq 0:11a51c9ebb09 676 bool MPU6050::getYGyroFIFOEnabled()
mducrocq 0:11a51c9ebb09 677 {
mducrocq 0:11a51c9ebb09 678 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 679 return buffer[0];
mducrocq 0:11a51c9ebb09 680 }
mducrocq 0:11a51c9ebb09 681 /** Set gyroscope Y-axis FIFO enabled value.
mducrocq 0:11a51c9ebb09 682 * @param enabled New gyroscope Y-axis FIFO enabled value
mducrocq 0:11a51c9ebb09 683 * @see getYGyroFIFOEnabled()
mducrocq 0:11a51c9ebb09 684 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 685 */
mducrocq 0:11a51c9ebb09 686 void MPU6050::setYGyroFIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 687 {
mducrocq 0:11a51c9ebb09 688 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 689 }
mducrocq 0:11a51c9ebb09 690 /** Get gyroscope Z-axis FIFO enabled value.
mducrocq 0:11a51c9ebb09 691 * When set to 1, this bit enables GYRO_ZOUT_H and GYRO_ZOUT_L (Registers 71 and
mducrocq 0:11a51c9ebb09 692 * 72) to be written into the FIFO buffer.
mducrocq 0:11a51c9ebb09 693 * @return Current gyroscope Z-axis FIFO enabled value
mducrocq 0:11a51c9ebb09 694 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 695 */
mducrocq 0:11a51c9ebb09 696 bool MPU6050::getZGyroFIFOEnabled()
mducrocq 0:11a51c9ebb09 697 {
mducrocq 0:11a51c9ebb09 698 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 699 return buffer[0];
mducrocq 0:11a51c9ebb09 700 }
mducrocq 0:11a51c9ebb09 701 /** Set gyroscope Z-axis FIFO enabled value.
mducrocq 0:11a51c9ebb09 702 * @param enabled New gyroscope Z-axis FIFO enabled value
mducrocq 0:11a51c9ebb09 703 * @see getZGyroFIFOEnabled()
mducrocq 0:11a51c9ebb09 704 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 705 */
mducrocq 0:11a51c9ebb09 706 void MPU6050::setZGyroFIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 707 {
mducrocq 0:11a51c9ebb09 708 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 709 }
mducrocq 0:11a51c9ebb09 710 /** Get accelerometer FIFO enabled value.
mducrocq 0:11a51c9ebb09 711 * When set to 1, this bit enables ACCEL_XOUT_H, ACCEL_XOUT_L, ACCEL_YOUT_H,
mducrocq 0:11a51c9ebb09 712 * ACCEL_YOUT_L, ACCEL_ZOUT_H, and ACCEL_ZOUT_L (Registers 59 to 64) to be
mducrocq 0:11a51c9ebb09 713 * written into the FIFO buffer.
mducrocq 0:11a51c9ebb09 714 * @return Current accelerometer FIFO enabled value
mducrocq 0:11a51c9ebb09 715 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 716 */
mducrocq 0:11a51c9ebb09 717 bool MPU6050::getAccelFIFOEnabled()
mducrocq 0:11a51c9ebb09 718 {
mducrocq 0:11a51c9ebb09 719 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 720 return buffer[0];
mducrocq 0:11a51c9ebb09 721 }
mducrocq 0:11a51c9ebb09 722 /** Set accelerometer FIFO enabled value.
mducrocq 0:11a51c9ebb09 723 * @param enabled New accelerometer FIFO enabled value
mducrocq 0:11a51c9ebb09 724 * @see getAccelFIFOEnabled()
mducrocq 0:11a51c9ebb09 725 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 726 */
mducrocq 0:11a51c9ebb09 727 void MPU6050::setAccelFIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 728 {
mducrocq 0:11a51c9ebb09 729 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 730 }
mducrocq 0:11a51c9ebb09 731 /** Get Slave 2 FIFO enabled value.
mducrocq 0:11a51c9ebb09 732 * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
mducrocq 0:11a51c9ebb09 733 * associated with Slave 2 to be written into the FIFO buffer.
mducrocq 0:11a51c9ebb09 734 * @return Current Slave 2 FIFO enabled value
mducrocq 0:11a51c9ebb09 735 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 736 */
mducrocq 0:11a51c9ebb09 737 bool MPU6050::getSlave2FIFOEnabled()
mducrocq 0:11a51c9ebb09 738 {
mducrocq 0:11a51c9ebb09 739 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 740 return buffer[0];
mducrocq 0:11a51c9ebb09 741 }
mducrocq 0:11a51c9ebb09 742 /** Set Slave 2 FIFO enabled value.
mducrocq 0:11a51c9ebb09 743 * @param enabled New Slave 2 FIFO enabled value
mducrocq 0:11a51c9ebb09 744 * @see getSlave2FIFOEnabled()
mducrocq 0:11a51c9ebb09 745 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 746 */
mducrocq 0:11a51c9ebb09 747 void MPU6050::setSlave2FIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 748 {
mducrocq 0:11a51c9ebb09 749 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 750 }
mducrocq 0:11a51c9ebb09 751 /** Get Slave 1 FIFO enabled value.
mducrocq 0:11a51c9ebb09 752 * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
mducrocq 0:11a51c9ebb09 753 * associated with Slave 1 to be written into the FIFO buffer.
mducrocq 0:11a51c9ebb09 754 * @return Current Slave 1 FIFO enabled value
mducrocq 0:11a51c9ebb09 755 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 756 */
mducrocq 0:11a51c9ebb09 757 bool MPU6050::getSlave1FIFOEnabled()
mducrocq 0:11a51c9ebb09 758 {
mducrocq 0:11a51c9ebb09 759 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 760 return buffer[0];
mducrocq 0:11a51c9ebb09 761 }
mducrocq 0:11a51c9ebb09 762 /** Set Slave 1 FIFO enabled value.
mducrocq 0:11a51c9ebb09 763 * @param enabled New Slave 1 FIFO enabled value
mducrocq 0:11a51c9ebb09 764 * @see getSlave1FIFOEnabled()
mducrocq 0:11a51c9ebb09 765 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 766 */
mducrocq 0:11a51c9ebb09 767 void MPU6050::setSlave1FIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 768 {
mducrocq 0:11a51c9ebb09 769 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 770 }
mducrocq 0:11a51c9ebb09 771 /** Get Slave 0 FIFO enabled value.
mducrocq 0:11a51c9ebb09 772 * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
mducrocq 0:11a51c9ebb09 773 * associated with Slave 0 to be written into the FIFO buffer.
mducrocq 0:11a51c9ebb09 774 * @return Current Slave 0 FIFO enabled value
mducrocq 0:11a51c9ebb09 775 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 776 */
mducrocq 0:11a51c9ebb09 777 bool MPU6050::getSlave0FIFOEnabled()
mducrocq 0:11a51c9ebb09 778 {
mducrocq 0:11a51c9ebb09 779 i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 780 return buffer[0];
mducrocq 0:11a51c9ebb09 781 }
mducrocq 0:11a51c9ebb09 782 /** Set Slave 0 FIFO enabled value.
mducrocq 0:11a51c9ebb09 783 * @param enabled New Slave 0 FIFO enabled value
mducrocq 0:11a51c9ebb09 784 * @see getSlave0FIFOEnabled()
mducrocq 0:11a51c9ebb09 785 * @see MPU6050_RA_FIFO_EN
mducrocq 0:11a51c9ebb09 786 */
mducrocq 0:11a51c9ebb09 787 void MPU6050::setSlave0FIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 788 {
mducrocq 0:11a51c9ebb09 789 i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 790 }
mducrocq 0:11a51c9ebb09 791
mducrocq 0:11a51c9ebb09 792 // I2C_MST_CTRL register
mducrocq 0:11a51c9ebb09 793
mducrocq 0:11a51c9ebb09 794 /** Get multi-master enabled value.
mducrocq 0:11a51c9ebb09 795 * Multi-master capability allows multiple I2C masters to operate on the same
mducrocq 0:11a51c9ebb09 796 * bus. In circuits where multi-master capability is required, set MULT_MST_EN
mducrocq 0:11a51c9ebb09 797 * to 1. This will increase current drawn by approximately 30uA.
mducrocq 0:11a51c9ebb09 798 *
mducrocq 0:11a51c9ebb09 799 * In circuits where multi-master capability is required, the state of the I2C
mducrocq 0:11a51c9ebb09 800 * bus must always be monitored by each separate I2C Master. Before an I2C
mducrocq 0:11a51c9ebb09 801 * Master can assume arbitration of the bus, it must first confirm that no other
mducrocq 0:11a51c9ebb09 802 * I2C Master has arbitration of the bus. When MULT_MST_EN is set to 1, the
mducrocq 0:11a51c9ebb09 803 * MPU-60X0's bus arbitration detection logic is turned on, enabling it to
mducrocq 0:11a51c9ebb09 804 * detect when the bus is available.
mducrocq 0:11a51c9ebb09 805 *
mducrocq 0:11a51c9ebb09 806 * @return Current multi-master enabled value
mducrocq 0:11a51c9ebb09 807 * @see MPU6050_RA_I2C_MST_CTRL
mducrocq 0:11a51c9ebb09 808 */
mducrocq 0:11a51c9ebb09 809 bool MPU6050::getMultiMasterEnabled()
mducrocq 0:11a51c9ebb09 810 {
mducrocq 0:11a51c9ebb09 811 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 812 return buffer[0];
mducrocq 0:11a51c9ebb09 813 }
mducrocq 0:11a51c9ebb09 814 /** Set multi-master enabled value.
mducrocq 0:11a51c9ebb09 815 * @param enabled New multi-master enabled value
mducrocq 0:11a51c9ebb09 816 * @see getMultiMasterEnabled()
mducrocq 0:11a51c9ebb09 817 * @see MPU6050_RA_I2C_MST_CTRL
mducrocq 0:11a51c9ebb09 818 */
mducrocq 0:11a51c9ebb09 819 void MPU6050::setMultiMasterEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 820 {
mducrocq 0:11a51c9ebb09 821 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 822 }
mducrocq 0:11a51c9ebb09 823 /** Get wait-for-external-sensor-data enabled value.
mducrocq 0:11a51c9ebb09 824 * When the WAIT_FOR_ES bit is set to 1, the Data Ready interrupt will be
mducrocq 0:11a51c9ebb09 825 * delayed until External Sensor data from the Slave Devices are loaded into the
mducrocq 0:11a51c9ebb09 826 * EXT_SENS_DATA registers. This is used to ensure that both the internal sensor
mducrocq 0:11a51c9ebb09 827 * data (i.e. from gyro and accel) and external sensor data have been loaded to
mducrocq 0:11a51c9ebb09 828 * their respective data registers (i.e. the data is synced) when the Data Ready
mducrocq 0:11a51c9ebb09 829 * interrupt is triggered.
mducrocq 0:11a51c9ebb09 830 *
mducrocq 0:11a51c9ebb09 831 * @return Current wait-for-external-sensor-data enabled value
mducrocq 0:11a51c9ebb09 832 * @see MPU6050_RA_I2C_MST_CTRL
mducrocq 0:11a51c9ebb09 833 */
mducrocq 0:11a51c9ebb09 834 bool MPU6050::getWaitForExternalSensorEnabled()
mducrocq 0:11a51c9ebb09 835 {
mducrocq 0:11a51c9ebb09 836 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, buffer);
mducrocq 0:11a51c9ebb09 837 return buffer[0];
mducrocq 0:11a51c9ebb09 838 }
mducrocq 0:11a51c9ebb09 839 /** Set wait-for-external-sensor-data enabled value.
mducrocq 0:11a51c9ebb09 840 * @param enabled New wait-for-external-sensor-data enabled value
mducrocq 0:11a51c9ebb09 841 * @see getWaitForExternalSensorEnabled()
mducrocq 0:11a51c9ebb09 842 * @see MPU6050_RA_I2C_MST_CTRL
mducrocq 0:11a51c9ebb09 843 */
mducrocq 0:11a51c9ebb09 844 void MPU6050::setWaitForExternalSensorEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 845 {
mducrocq 0:11a51c9ebb09 846 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, enabled);
mducrocq 0:11a51c9ebb09 847 }
mducrocq 0:11a51c9ebb09 848 /** Get Slave 3 FIFO enabled value.
mducrocq 0:11a51c9ebb09 849 * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
mducrocq 0:11a51c9ebb09 850 * associated with Slave 3 to be written into the FIFO buffer.
mducrocq 0:11a51c9ebb09 851 * @return Current Slave 3 FIFO enabled value
mducrocq 0:11a51c9ebb09 852 * @see MPU6050_RA_MST_CTRL
mducrocq 0:11a51c9ebb09 853 */
mducrocq 0:11a51c9ebb09 854 bool MPU6050::getSlave3FIFOEnabled()
mducrocq 0:11a51c9ebb09 855 {
mducrocq 0:11a51c9ebb09 856 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 857 return buffer[0];
mducrocq 0:11a51c9ebb09 858 }
mducrocq 0:11a51c9ebb09 859 /** Set Slave 3 FIFO enabled value.
mducrocq 0:11a51c9ebb09 860 * @param enabled New Slave 3 FIFO enabled value
mducrocq 0:11a51c9ebb09 861 * @see getSlave3FIFOEnabled()
mducrocq 0:11a51c9ebb09 862 * @see MPU6050_RA_MST_CTRL
mducrocq 0:11a51c9ebb09 863 */
mducrocq 0:11a51c9ebb09 864 void MPU6050::setSlave3FIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 865 {
mducrocq 0:11a51c9ebb09 866 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 867 }
mducrocq 0:11a51c9ebb09 868 /** Get slave read/write transition enabled value.
mducrocq 0:11a51c9ebb09 869 * The I2C_MST_P_NSR bit configures the I2C Master's transition from one slave
mducrocq 0:11a51c9ebb09 870 * read to the next slave read. If the bit equals 0, there will be a restart
mducrocq 0:11a51c9ebb09 871 * between reads. If the bit equals 1, there will be a stop followed by a start
mducrocq 0:11a51c9ebb09 872 * of the following read. When a write transaction follows a read transaction,
mducrocq 0:11a51c9ebb09 873 * the stop followed by a start of the successive write will be always used.
mducrocq 0:11a51c9ebb09 874 *
mducrocq 0:11a51c9ebb09 875 * @return Current slave read/write transition enabled value
mducrocq 0:11a51c9ebb09 876 * @see MPU6050_RA_I2C_MST_CTRL
mducrocq 0:11a51c9ebb09 877 */
mducrocq 0:11a51c9ebb09 878 bool MPU6050::getSlaveReadWriteTransitionEnabled()
mducrocq 0:11a51c9ebb09 879 {
mducrocq 0:11a51c9ebb09 880 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, buffer);
mducrocq 0:11a51c9ebb09 881 return buffer[0];
mducrocq 0:11a51c9ebb09 882 }
mducrocq 0:11a51c9ebb09 883 /** Set slave read/write transition enabled value.
mducrocq 0:11a51c9ebb09 884 * @param enabled New slave read/write transition enabled value
mducrocq 0:11a51c9ebb09 885 * @see getSlaveReadWriteTransitionEnabled()
mducrocq 0:11a51c9ebb09 886 * @see MPU6050_RA_I2C_MST_CTRL
mducrocq 0:11a51c9ebb09 887 */
mducrocq 0:11a51c9ebb09 888 void MPU6050::setSlaveReadWriteTransitionEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 889 {
mducrocq 0:11a51c9ebb09 890 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, enabled);
mducrocq 0:11a51c9ebb09 891 }
mducrocq 0:11a51c9ebb09 892 /** Get I2C master clock speed.
mducrocq 0:11a51c9ebb09 893 * I2C_MST_CLK is a 4 bit unsigned value which configures a divider on the
mducrocq 0:11a51c9ebb09 894 * MPU-60X0 internal 8MHz clock. It sets the I2C master clock speed according to
mducrocq 0:11a51c9ebb09 895 * the following table:
mducrocq 0:11a51c9ebb09 896 *
mducrocq 0:11a51c9ebb09 897 * <pre>
mducrocq 0:11a51c9ebb09 898 * I2C_MST_CLK | I2C Master Clock Speed | 8MHz Clock Divider
mducrocq 0:11a51c9ebb09 899 * ------------+------------------------+-------------------
mducrocq 0:11a51c9ebb09 900 * 0 | 348kHz | 23
mducrocq 0:11a51c9ebb09 901 * 1 | 333kHz | 24
mducrocq 0:11a51c9ebb09 902 * 2 | 320kHz | 25
mducrocq 0:11a51c9ebb09 903 * 3 | 308kHz | 26
mducrocq 0:11a51c9ebb09 904 * 4 | 296kHz | 27
mducrocq 0:11a51c9ebb09 905 * 5 | 286kHz | 28
mducrocq 0:11a51c9ebb09 906 * 6 | 276kHz | 29
mducrocq 0:11a51c9ebb09 907 * 7 | 267kHz | 30
mducrocq 0:11a51c9ebb09 908 * 8 | 258kHz | 31
mducrocq 0:11a51c9ebb09 909 * 9 | 500kHz | 16
mducrocq 0:11a51c9ebb09 910 * 10 | 471kHz | 17
mducrocq 0:11a51c9ebb09 911 * 11 | 444kHz | 18
mducrocq 0:11a51c9ebb09 912 * 12 | 421kHz | 19
mducrocq 0:11a51c9ebb09 913 * 13 | 400kHz | 20
mducrocq 0:11a51c9ebb09 914 * 14 | 381kHz | 21
mducrocq 0:11a51c9ebb09 915 * 15 | 364kHz | 22
mducrocq 0:11a51c9ebb09 916 * </pre>
mducrocq 0:11a51c9ebb09 917 *
mducrocq 0:11a51c9ebb09 918 * @return Current I2C master clock speed
mducrocq 0:11a51c9ebb09 919 * @see MPU6050_RA_I2C_MST_CTRL
mducrocq 0:11a51c9ebb09 920 */
mducrocq 0:11a51c9ebb09 921 uint8_t MPU6050::getMasterClockSpeed()
mducrocq 0:11a51c9ebb09 922 {
mducrocq 0:11a51c9ebb09 923 i2Cdev.readBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 924 return buffer[0];
mducrocq 0:11a51c9ebb09 925 }
mducrocq 0:11a51c9ebb09 926 /** Set I2C master clock speed.
mducrocq 0:11a51c9ebb09 927 * @reparam speed Current I2C master clock speed
mducrocq 0:11a51c9ebb09 928 * @see MPU6050_RA_I2C_MST_CTRL
mducrocq 0:11a51c9ebb09 929 */
mducrocq 0:11a51c9ebb09 930 void MPU6050::setMasterClockSpeed(uint8_t speed)
mducrocq 0:11a51c9ebb09 931 {
mducrocq 0:11a51c9ebb09 932 i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, speed);
mducrocq 0:11a51c9ebb09 933 }
mducrocq 0:11a51c9ebb09 934
mducrocq 0:11a51c9ebb09 935 // I2C_SLV* registers (Slave 0-3)
mducrocq 0:11a51c9ebb09 936
mducrocq 0:11a51c9ebb09 937 /** Get the I2C address of the specified slave (0-3).
mducrocq 0:11a51c9ebb09 938 * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read
mducrocq 0:11a51c9ebb09 939 * operation, and if it is cleared, then it's a write operation. The remaining
mducrocq 0:11a51c9ebb09 940 * bits (6-0) are the 7-bit device address of the slave device.
mducrocq 0:11a51c9ebb09 941 *
mducrocq 0:11a51c9ebb09 942 * In read mode, the result of the read is placed in the lowest available
mducrocq 0:11a51c9ebb09 943 * EXT_SENS_DATA register. For further information regarding the allocation of
mducrocq 0:11a51c9ebb09 944 * read results, please refer to the EXT_SENS_DATA register description
mducrocq 0:11a51c9ebb09 945 * (Registers 73 - 96).
mducrocq 0:11a51c9ebb09 946 *
mducrocq 0:11a51c9ebb09 947 * The MPU-6050 supports a total of five slaves, but Slave 4 has unique
mducrocq 0:11a51c9ebb09 948 * characteristics, and so it has its own functions (getSlave4* and setSlave4*).
mducrocq 0:11a51c9ebb09 949 *
mducrocq 0:11a51c9ebb09 950 * I2C data transactions are performed at the Sample Rate, as defined in
mducrocq 0:11a51c9ebb09 951 * Register 25. The user is responsible for ensuring that I2C data transactions
mducrocq 0:11a51c9ebb09 952 * to and from each enabled Slave can be completed within a single period of the
mducrocq 0:11a51c9ebb09 953 * Sample Rate.
mducrocq 0:11a51c9ebb09 954 *
mducrocq 0:11a51c9ebb09 955 * The I2C slave access rate can be reduced relative to the Sample Rate. This
mducrocq 0:11a51c9ebb09 956 * reduced access rate is determined by I2C_MST_DLY (Register 52). Whether a
mducrocq 0:11a51c9ebb09 957 * slave's access rate is reduced relative to the Sample Rate is determined by
mducrocq 0:11a51c9ebb09 958 * I2C_MST_DELAY_CTRL (Register 103).
mducrocq 0:11a51c9ebb09 959 *
mducrocq 0:11a51c9ebb09 960 * The processing order for the slaves is fixed. The sequence followed for
mducrocq 0:11a51c9ebb09 961 * processing the slaves is Slave 0, Slave 1, Slave 2, Slave 3 and Slave 4. If a
mducrocq 0:11a51c9ebb09 962 * particular Slave is disabled it will be skipped.
mducrocq 0:11a51c9ebb09 963 *
mducrocq 0:11a51c9ebb09 964 * Each slave can either be accessed at the sample rate or at a reduced sample
mducrocq 0:11a51c9ebb09 965 * rate. In a case where some slaves are accessed at the Sample Rate and some
mducrocq 0:11a51c9ebb09 966 * slaves are accessed at the reduced rate, the sequence of accessing the slaves
mducrocq 0:11a51c9ebb09 967 * (Slave 0 to Slave 4) is still followed. However, the reduced rate slaves will
mducrocq 0:11a51c9ebb09 968 * be skipped if their access rate dictates that they should not be accessed
mducrocq 0:11a51c9ebb09 969 * during that particular cycle. For further information regarding the reduced
mducrocq 0:11a51c9ebb09 970 * access rate, please refer to Register 52. Whether a slave is accessed at the
mducrocq 0:11a51c9ebb09 971 * Sample Rate or at the reduced rate is determined by the Delay Enable bits in
mducrocq 0:11a51c9ebb09 972 * Register 103.
mducrocq 0:11a51c9ebb09 973 *
mducrocq 0:11a51c9ebb09 974 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 975 * @return Current address for specified slave
mducrocq 0:11a51c9ebb09 976 * @see MPU6050_RA_I2C_SLV0_ADDR
mducrocq 0:11a51c9ebb09 977 */
mducrocq 0:11a51c9ebb09 978 uint8_t MPU6050::getSlaveAddress(uint8_t num)
mducrocq 0:11a51c9ebb09 979 {
mducrocq 0:11a51c9ebb09 980 if (num > 3) return 0;
mducrocq 0:11a51c9ebb09 981 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, buffer);
mducrocq 0:11a51c9ebb09 982 return buffer[0];
mducrocq 0:11a51c9ebb09 983 }
mducrocq 0:11a51c9ebb09 984 /** Set the I2C address of the specified slave (0-3).
mducrocq 0:11a51c9ebb09 985 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 986 * @param address New address for specified slave
mducrocq 0:11a51c9ebb09 987 * @see getSlaveAddress()
mducrocq 0:11a51c9ebb09 988 * @see MPU6050_RA_I2C_SLV0_ADDR
mducrocq 0:11a51c9ebb09 989 */
mducrocq 0:11a51c9ebb09 990 void MPU6050::setSlaveAddress(uint8_t num, uint8_t address)
mducrocq 0:11a51c9ebb09 991 {
mducrocq 0:11a51c9ebb09 992 if (num > 3) return;
mducrocq 0:11a51c9ebb09 993 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, address);
mducrocq 0:11a51c9ebb09 994 }
mducrocq 0:11a51c9ebb09 995 /** Get the active internal register for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 996 * Read/write operations for this slave will be done to whatever internal
mducrocq 0:11a51c9ebb09 997 * register address is stored in this MPU register.
mducrocq 0:11a51c9ebb09 998 *
mducrocq 0:11a51c9ebb09 999 * The MPU-6050 supports a total of five slaves, but Slave 4 has unique
mducrocq 0:11a51c9ebb09 1000 * characteristics, and so it has its own functions.
mducrocq 0:11a51c9ebb09 1001 *
mducrocq 0:11a51c9ebb09 1002 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1003 * @return Current active register for specified slave
mducrocq 0:11a51c9ebb09 1004 * @see MPU6050_RA_I2C_SLV0_REG
mducrocq 0:11a51c9ebb09 1005 */
mducrocq 0:11a51c9ebb09 1006 uint8_t MPU6050::getSlaveRegister(uint8_t num)
mducrocq 0:11a51c9ebb09 1007 {
mducrocq 0:11a51c9ebb09 1008 if (num > 3) return 0;
mducrocq 0:11a51c9ebb09 1009 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, buffer);
mducrocq 0:11a51c9ebb09 1010 return buffer[0];
mducrocq 0:11a51c9ebb09 1011 }
mducrocq 0:11a51c9ebb09 1012 /** Set the active internal register for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1013 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1014 * @param reg New active register for specified slave
mducrocq 0:11a51c9ebb09 1015 * @see getSlaveRegister()
mducrocq 0:11a51c9ebb09 1016 * @see MPU6050_RA_I2C_SLV0_REG
mducrocq 0:11a51c9ebb09 1017 */
mducrocq 0:11a51c9ebb09 1018 void MPU6050::setSlaveRegister(uint8_t num, uint8_t reg)
mducrocq 0:11a51c9ebb09 1019 {
mducrocq 0:11a51c9ebb09 1020 if (num > 3) return;
mducrocq 0:11a51c9ebb09 1021 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, reg);
mducrocq 0:11a51c9ebb09 1022 }
mducrocq 0:11a51c9ebb09 1023 /** Get the enabled value for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1024 * When set to 1, this bit enables Slave 0 for data transfer operations. When
mducrocq 0:11a51c9ebb09 1025 * cleared to 0, this bit disables Slave 0 from data transfer operations.
mducrocq 0:11a51c9ebb09 1026 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1027 * @return Current enabled value for specified slave
mducrocq 0:11a51c9ebb09 1028 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1029 */
mducrocq 0:11a51c9ebb09 1030 bool MPU6050::getSlaveEnabled(uint8_t num)
mducrocq 0:11a51c9ebb09 1031 {
mducrocq 0:11a51c9ebb09 1032 if (num > 3) return 0;
mducrocq 0:11a51c9ebb09 1033 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 1034 return buffer[0];
mducrocq 0:11a51c9ebb09 1035 }
mducrocq 0:11a51c9ebb09 1036 /** Set the enabled value for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1037 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1038 * @param enabled New enabled value for specified slave
mducrocq 0:11a51c9ebb09 1039 * @see getSlaveEnabled()
mducrocq 0:11a51c9ebb09 1040 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1041 */
mducrocq 0:11a51c9ebb09 1042 void MPU6050::setSlaveEnabled(uint8_t num, bool enabled)
mducrocq 0:11a51c9ebb09 1043 {
mducrocq 0:11a51c9ebb09 1044 if (num > 3) return;
mducrocq 0:11a51c9ebb09 1045 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 1046 }
mducrocq 0:11a51c9ebb09 1047 /** Get word pair byte-swapping enabled for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1048 * When set to 1, this bit enables byte swapping. When byte swapping is enabled,
mducrocq 0:11a51c9ebb09 1049 * the high and low bytes of a word pair are swapped. Please refer to
mducrocq 0:11a51c9ebb09 1050 * I2C_SLV0_GRP for the pairing convention of the word pairs. When cleared to 0,
mducrocq 0:11a51c9ebb09 1051 * bytes transferred to and from Slave 0 will be written to EXT_SENS_DATA
mducrocq 0:11a51c9ebb09 1052 * registers in the order they were transferred.
mducrocq 0:11a51c9ebb09 1053 *
mducrocq 0:11a51c9ebb09 1054 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1055 * @return Current word pair byte-swapping enabled value for specified slave
mducrocq 0:11a51c9ebb09 1056 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1057 */
mducrocq 0:11a51c9ebb09 1058 bool MPU6050::getSlaveWordByteSwap(uint8_t num)
mducrocq 0:11a51c9ebb09 1059 {
mducrocq 0:11a51c9ebb09 1060 if (num > 3) return 0;
mducrocq 0:11a51c9ebb09 1061 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, buffer);
mducrocq 0:11a51c9ebb09 1062 return buffer[0];
mducrocq 0:11a51c9ebb09 1063 }
mducrocq 0:11a51c9ebb09 1064 /** Set word pair byte-swapping enabled for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1065 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1066 * @param enabled New word pair byte-swapping enabled value for specified slave
mducrocq 0:11a51c9ebb09 1067 * @see getSlaveWordByteSwap()
mducrocq 0:11a51c9ebb09 1068 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1069 */
mducrocq 0:11a51c9ebb09 1070 void MPU6050::setSlaveWordByteSwap(uint8_t num, bool enabled)
mducrocq 0:11a51c9ebb09 1071 {
mducrocq 0:11a51c9ebb09 1072 if (num > 3) return;
mducrocq 0:11a51c9ebb09 1073 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, enabled);
mducrocq 0:11a51c9ebb09 1074 }
mducrocq 0:11a51c9ebb09 1075 /** Get write mode for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1076 * When set to 1, the transaction will read or write data only. When cleared to
mducrocq 0:11a51c9ebb09 1077 * 0, the transaction will write a register address prior to reading or writing
mducrocq 0:11a51c9ebb09 1078 * data. This should equal 0 when specifying the register address within the
mducrocq 0:11a51c9ebb09 1079 * Slave device to/from which the ensuing data transaction will take place.
mducrocq 0:11a51c9ebb09 1080 *
mducrocq 0:11a51c9ebb09 1081 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1082 * @return Current write mode for specified slave (0 = register address + data, 1 = data only)
mducrocq 0:11a51c9ebb09 1083 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1084 */
mducrocq 0:11a51c9ebb09 1085 bool MPU6050::getSlaveWriteMode(uint8_t num)
mducrocq 0:11a51c9ebb09 1086 {
mducrocq 0:11a51c9ebb09 1087 if (num > 3) return 0;
mducrocq 0:11a51c9ebb09 1088 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, buffer);
mducrocq 0:11a51c9ebb09 1089 return buffer[0];
mducrocq 0:11a51c9ebb09 1090 }
mducrocq 0:11a51c9ebb09 1091 /** Set write mode for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1092 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1093 * @param mode New write mode for specified slave (0 = register address + data, 1 = data only)
mducrocq 0:11a51c9ebb09 1094 * @see getSlaveWriteMode()
mducrocq 0:11a51c9ebb09 1095 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1096 */
mducrocq 0:11a51c9ebb09 1097 void MPU6050::setSlaveWriteMode(uint8_t num, bool mode)
mducrocq 0:11a51c9ebb09 1098 {
mducrocq 0:11a51c9ebb09 1099 if (num > 3) return;
mducrocq 0:11a51c9ebb09 1100 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, mode);
mducrocq 0:11a51c9ebb09 1101 }
mducrocq 0:11a51c9ebb09 1102 /** Get word pair grouping order offset for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1103 * This sets specifies the grouping order of word pairs received from registers.
mducrocq 0:11a51c9ebb09 1104 * When cleared to 0, bytes from register addresses 0 and 1, 2 and 3, etc (even,
mducrocq 0:11a51c9ebb09 1105 * then odd register addresses) are paired to form a word. When set to 1, bytes
mducrocq 0:11a51c9ebb09 1106 * from register addresses are paired 1 and 2, 3 and 4, etc. (odd, then even
mducrocq 0:11a51c9ebb09 1107 * register addresses) are paired to form a word.
mducrocq 0:11a51c9ebb09 1108 *
mducrocq 0:11a51c9ebb09 1109 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1110 * @return Current word pair grouping order offset for specified slave
mducrocq 0:11a51c9ebb09 1111 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1112 */
mducrocq 0:11a51c9ebb09 1113 bool MPU6050::getSlaveWordGroupOffset(uint8_t num)
mducrocq 0:11a51c9ebb09 1114 {
mducrocq 0:11a51c9ebb09 1115 if (num > 3) return 0;
mducrocq 0:11a51c9ebb09 1116 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, buffer);
mducrocq 0:11a51c9ebb09 1117 return buffer[0];
mducrocq 0:11a51c9ebb09 1118 }
mducrocq 0:11a51c9ebb09 1119 /** Set word pair grouping order offset for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1120 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1121 * @param enabled New word pair grouping order offset for specified slave
mducrocq 0:11a51c9ebb09 1122 * @see getSlaveWordGroupOffset()
mducrocq 0:11a51c9ebb09 1123 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1124 */
mducrocq 0:11a51c9ebb09 1125 void MPU6050::setSlaveWordGroupOffset(uint8_t num, bool enabled)
mducrocq 0:11a51c9ebb09 1126 {
mducrocq 0:11a51c9ebb09 1127 if (num > 3) return;
mducrocq 0:11a51c9ebb09 1128 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, enabled);
mducrocq 0:11a51c9ebb09 1129 }
mducrocq 0:11a51c9ebb09 1130 /** Get number of bytes to read for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1131 * Specifies the number of bytes transferred to and from Slave 0. Clearing this
mducrocq 0:11a51c9ebb09 1132 * bit to 0 is equivalent to disabling the register by writing 0 to I2C_SLV0_EN.
mducrocq 0:11a51c9ebb09 1133 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1134 * @return Number of bytes to read for specified slave
mducrocq 0:11a51c9ebb09 1135 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1136 */
mducrocq 0:11a51c9ebb09 1137 uint8_t MPU6050::getSlaveDataLength(uint8_t num)
mducrocq 0:11a51c9ebb09 1138 {
mducrocq 0:11a51c9ebb09 1139 if (num > 3) return 0;
mducrocq 0:11a51c9ebb09 1140 i2Cdev.readBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 1141 return buffer[0];
mducrocq 0:11a51c9ebb09 1142 }
mducrocq 0:11a51c9ebb09 1143 /** Set number of bytes to read for the specified slave (0-3).
mducrocq 0:11a51c9ebb09 1144 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 1145 * @param length Number of bytes to read for specified slave
mducrocq 0:11a51c9ebb09 1146 * @see getSlaveDataLength()
mducrocq 0:11a51c9ebb09 1147 * @see MPU6050_RA_I2C_SLV0_CTRL
mducrocq 0:11a51c9ebb09 1148 */
mducrocq 0:11a51c9ebb09 1149 void MPU6050::setSlaveDataLength(uint8_t num, uint8_t length)
mducrocq 0:11a51c9ebb09 1150 {
mducrocq 0:11a51c9ebb09 1151 if (num > 3) return;
mducrocq 0:11a51c9ebb09 1152 i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, length);
mducrocq 0:11a51c9ebb09 1153 }
mducrocq 0:11a51c9ebb09 1154
mducrocq 0:11a51c9ebb09 1155 // I2C_SLV* registers (Slave 4)
mducrocq 0:11a51c9ebb09 1156
mducrocq 0:11a51c9ebb09 1157 /** Get the I2C address of Slave 4.
mducrocq 0:11a51c9ebb09 1158 * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read
mducrocq 0:11a51c9ebb09 1159 * operation, and if it is cleared, then it's a write operation. The remaining
mducrocq 0:11a51c9ebb09 1160 * bits (6-0) are the 7-bit device address of the slave device.
mducrocq 0:11a51c9ebb09 1161 *
mducrocq 0:11a51c9ebb09 1162 * @return Current address for Slave 4
mducrocq 0:11a51c9ebb09 1163 * @see getSlaveAddress()
mducrocq 0:11a51c9ebb09 1164 * @see MPU6050_RA_I2C_SLV4_ADDR
mducrocq 0:11a51c9ebb09 1165 */
mducrocq 0:11a51c9ebb09 1166 uint8_t MPU6050::getSlave4Address()
mducrocq 0:11a51c9ebb09 1167 {
mducrocq 0:11a51c9ebb09 1168 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, buffer);
mducrocq 0:11a51c9ebb09 1169 return buffer[0];
mducrocq 0:11a51c9ebb09 1170 }
mducrocq 0:11a51c9ebb09 1171 /** Set the I2C address of Slave 4.
mducrocq 0:11a51c9ebb09 1172 * @param address New address for Slave 4
mducrocq 0:11a51c9ebb09 1173 * @see getSlave4Address()
mducrocq 0:11a51c9ebb09 1174 * @see MPU6050_RA_I2C_SLV4_ADDR
mducrocq 0:11a51c9ebb09 1175 */
mducrocq 0:11a51c9ebb09 1176 void MPU6050::setSlave4Address(uint8_t address)
mducrocq 0:11a51c9ebb09 1177 {
mducrocq 0:11a51c9ebb09 1178 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, address);
mducrocq 0:11a51c9ebb09 1179 }
mducrocq 0:11a51c9ebb09 1180 /** Get the active internal register for the Slave 4.
mducrocq 0:11a51c9ebb09 1181 * Read/write operations for this slave will be done to whatever internal
mducrocq 0:11a51c9ebb09 1182 * register address is stored in this MPU register.
mducrocq 0:11a51c9ebb09 1183 *
mducrocq 0:11a51c9ebb09 1184 * @return Current active register for Slave 4
mducrocq 0:11a51c9ebb09 1185 * @see MPU6050_RA_I2C_SLV4_REG
mducrocq 0:11a51c9ebb09 1186 */
mducrocq 0:11a51c9ebb09 1187 uint8_t MPU6050::getSlave4Register()
mducrocq 0:11a51c9ebb09 1188 {
mducrocq 0:11a51c9ebb09 1189 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_REG, buffer);
mducrocq 0:11a51c9ebb09 1190 return buffer[0];
mducrocq 0:11a51c9ebb09 1191 }
mducrocq 0:11a51c9ebb09 1192 /** Set the active internal register for Slave 4.
mducrocq 0:11a51c9ebb09 1193 * @param reg New active register for Slave 4
mducrocq 0:11a51c9ebb09 1194 * @see getSlave4Register()
mducrocq 0:11a51c9ebb09 1195 * @see MPU6050_RA_I2C_SLV4_REG
mducrocq 0:11a51c9ebb09 1196 */
mducrocq 0:11a51c9ebb09 1197 void MPU6050::setSlave4Register(uint8_t reg)
mducrocq 0:11a51c9ebb09 1198 {
mducrocq 0:11a51c9ebb09 1199 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_REG, reg);
mducrocq 0:11a51c9ebb09 1200 }
mducrocq 0:11a51c9ebb09 1201 /** Set new byte to write to Slave 4.
mducrocq 0:11a51c9ebb09 1202 * This register stores the data to be written into the Slave 4. If I2C_SLV4_RW
mducrocq 0:11a51c9ebb09 1203 * is set 1 (set to read), this register has no effect.
mducrocq 0:11a51c9ebb09 1204 * @param data New byte to write to Slave 4
mducrocq 0:11a51c9ebb09 1205 * @see MPU6050_RA_I2C_SLV4_DO
mducrocq 0:11a51c9ebb09 1206 */
mducrocq 0:11a51c9ebb09 1207 void MPU6050::setSlave4OutputByte(uint8_t data)
mducrocq 0:11a51c9ebb09 1208 {
mducrocq 0:11a51c9ebb09 1209 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_DO, data);
mducrocq 0:11a51c9ebb09 1210 }
mducrocq 0:11a51c9ebb09 1211 /** Get the enabled value for the Slave 4.
mducrocq 0:11a51c9ebb09 1212 * When set to 1, this bit enables Slave 4 for data transfer operations. When
mducrocq 0:11a51c9ebb09 1213 * cleared to 0, this bit disables Slave 4 from data transfer operations.
mducrocq 0:11a51c9ebb09 1214 * @return Current enabled value for Slave 4
mducrocq 0:11a51c9ebb09 1215 * @see MPU6050_RA_I2C_SLV4_CTRL
mducrocq 0:11a51c9ebb09 1216 */
mducrocq 0:11a51c9ebb09 1217 bool MPU6050::getSlave4Enabled()
mducrocq 0:11a51c9ebb09 1218 {
mducrocq 0:11a51c9ebb09 1219 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 1220 return buffer[0];
mducrocq 0:11a51c9ebb09 1221 }
mducrocq 0:11a51c9ebb09 1222 /** Set the enabled value for Slave 4.
mducrocq 0:11a51c9ebb09 1223 * @param enabled New enabled value for Slave 4
mducrocq 0:11a51c9ebb09 1224 * @see getSlave4Enabled()
mducrocq 0:11a51c9ebb09 1225 * @see MPU6050_RA_I2C_SLV4_CTRL
mducrocq 0:11a51c9ebb09 1226 */
mducrocq 0:11a51c9ebb09 1227 void MPU6050::setSlave4Enabled(bool enabled)
mducrocq 0:11a51c9ebb09 1228 {
mducrocq 0:11a51c9ebb09 1229 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 1230 }
mducrocq 0:11a51c9ebb09 1231 /** Get the enabled value for Slave 4 transaction interrupts.
mducrocq 0:11a51c9ebb09 1232 * When set to 1, this bit enables the generation of an interrupt signal upon
mducrocq 0:11a51c9ebb09 1233 * completion of a Slave 4 transaction. When cleared to 0, this bit disables the
mducrocq 0:11a51c9ebb09 1234 * generation of an interrupt signal upon completion of a Slave 4 transaction.
mducrocq 0:11a51c9ebb09 1235 * The interrupt status can be observed in Register 54.
mducrocq 0:11a51c9ebb09 1236 *
mducrocq 0:11a51c9ebb09 1237 * @return Current enabled value for Slave 4 transaction interrupts.
mducrocq 0:11a51c9ebb09 1238 * @see MPU6050_RA_I2C_SLV4_CTRL
mducrocq 0:11a51c9ebb09 1239 */
mducrocq 0:11a51c9ebb09 1240 bool MPU6050::getSlave4InterruptEnabled()
mducrocq 0:11a51c9ebb09 1241 {
mducrocq 0:11a51c9ebb09 1242 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 1243 return buffer[0];
mducrocq 0:11a51c9ebb09 1244 }
mducrocq 0:11a51c9ebb09 1245 /** Set the enabled value for Slave 4 transaction interrupts.
mducrocq 0:11a51c9ebb09 1246 * @param enabled New enabled value for Slave 4 transaction interrupts.
mducrocq 0:11a51c9ebb09 1247 * @see getSlave4InterruptEnabled()
mducrocq 0:11a51c9ebb09 1248 * @see MPU6050_RA_I2C_SLV4_CTRL
mducrocq 0:11a51c9ebb09 1249 */
mducrocq 0:11a51c9ebb09 1250 void MPU6050::setSlave4InterruptEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1251 {
mducrocq 0:11a51c9ebb09 1252 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 1253 }
mducrocq 0:11a51c9ebb09 1254 /** Get write mode for Slave 4.
mducrocq 0:11a51c9ebb09 1255 * When set to 1, the transaction will read or write data only. When cleared to
mducrocq 0:11a51c9ebb09 1256 * 0, the transaction will write a register address prior to reading or writing
mducrocq 0:11a51c9ebb09 1257 * data. This should equal 0 when specifying the register address within the
mducrocq 0:11a51c9ebb09 1258 * Slave device to/from which the ensuing data transaction will take place.
mducrocq 0:11a51c9ebb09 1259 *
mducrocq 0:11a51c9ebb09 1260 * @return Current write mode for Slave 4 (0 = register address + data, 1 = data only)
mducrocq 0:11a51c9ebb09 1261 * @see MPU6050_RA_I2C_SLV4_CTRL
mducrocq 0:11a51c9ebb09 1262 */
mducrocq 0:11a51c9ebb09 1263 bool MPU6050::getSlave4WriteMode()
mducrocq 0:11a51c9ebb09 1264 {
mducrocq 0:11a51c9ebb09 1265 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, buffer);
mducrocq 0:11a51c9ebb09 1266 return buffer[0];
mducrocq 0:11a51c9ebb09 1267 }
mducrocq 0:11a51c9ebb09 1268 /** Set write mode for the Slave 4.
mducrocq 0:11a51c9ebb09 1269 * @param mode New write mode for Slave 4 (0 = register address + data, 1 = data only)
mducrocq 0:11a51c9ebb09 1270 * @see getSlave4WriteMode()
mducrocq 0:11a51c9ebb09 1271 * @see MPU6050_RA_I2C_SLV4_CTRL
mducrocq 0:11a51c9ebb09 1272 */
mducrocq 0:11a51c9ebb09 1273 void MPU6050::setSlave4WriteMode(bool mode)
mducrocq 0:11a51c9ebb09 1274 {
mducrocq 0:11a51c9ebb09 1275 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, mode);
mducrocq 0:11a51c9ebb09 1276 }
mducrocq 0:11a51c9ebb09 1277 /** Get Slave 4 master delay value.
mducrocq 0:11a51c9ebb09 1278 * This configures the reduced access rate of I2C slaves relative to the Sample
mducrocq 0:11a51c9ebb09 1279 * Rate. When a slave's access rate is decreased relative to the Sample Rate,
mducrocq 0:11a51c9ebb09 1280 * the slave is accessed every:
mducrocq 0:11a51c9ebb09 1281 *
mducrocq 0:11a51c9ebb09 1282 * 1 / (1 + I2C_MST_DLY) samples
mducrocq 0:11a51c9ebb09 1283 *
mducrocq 0:11a51c9ebb09 1284 * This base Sample Rate in turn is determined by SMPLRT_DIV (register 25) and
mducrocq 0:11a51c9ebb09 1285 * DLPF_CFG (register 26). Whether a slave's access rate is reduced relative to
mducrocq 0:11a51c9ebb09 1286 * the Sample Rate is determined by I2C_MST_DELAY_CTRL (register 103). For
mducrocq 0:11a51c9ebb09 1287 * further information regarding the Sample Rate, please refer to register 25.
mducrocq 0:11a51c9ebb09 1288 *
mducrocq 0:11a51c9ebb09 1289 * @return Current Slave 4 master delay value
mducrocq 0:11a51c9ebb09 1290 * @see MPU6050_RA_I2C_SLV4_CTRL
mducrocq 0:11a51c9ebb09 1291 */
mducrocq 0:11a51c9ebb09 1292 uint8_t MPU6050::getSlave4MasterDelay()
mducrocq 0:11a51c9ebb09 1293 {
mducrocq 0:11a51c9ebb09 1294 i2Cdev.readBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 1295 return buffer[0];
mducrocq 0:11a51c9ebb09 1296 }
mducrocq 0:11a51c9ebb09 1297 /** Set Slave 4 master delay value.
mducrocq 0:11a51c9ebb09 1298 * @param delay New Slave 4 master delay value
mducrocq 0:11a51c9ebb09 1299 * @see getSlave4MasterDelay()
mducrocq 0:11a51c9ebb09 1300 * @see MPU6050_RA_I2C_SLV4_CTRL
mducrocq 0:11a51c9ebb09 1301 */
mducrocq 0:11a51c9ebb09 1302 void MPU6050::setSlave4MasterDelay(uint8_t delay)
mducrocq 0:11a51c9ebb09 1303 {
mducrocq 0:11a51c9ebb09 1304 i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, delay);
mducrocq 0:11a51c9ebb09 1305 }
mducrocq 0:11a51c9ebb09 1306 /** Get last available byte read from Slave 4.
mducrocq 0:11a51c9ebb09 1307 * This register stores the data read from Slave 4. This field is populated
mducrocq 0:11a51c9ebb09 1308 * after a read transaction.
mducrocq 0:11a51c9ebb09 1309 * @return Last available byte read from to Slave 4
mducrocq 0:11a51c9ebb09 1310 * @see MPU6050_RA_I2C_SLV4_DI
mducrocq 0:11a51c9ebb09 1311 */
mducrocq 0:11a51c9ebb09 1312 uint8_t MPU6050::getSlate4InputByte()
mducrocq 0:11a51c9ebb09 1313 {
mducrocq 0:11a51c9ebb09 1314 i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_DI, buffer);
mducrocq 0:11a51c9ebb09 1315 return buffer[0];
mducrocq 0:11a51c9ebb09 1316 }
mducrocq 0:11a51c9ebb09 1317
mducrocq 0:11a51c9ebb09 1318 // I2C_MST_STATUS register
mducrocq 0:11a51c9ebb09 1319
mducrocq 0:11a51c9ebb09 1320 /** Get FSYNC interrupt status.
mducrocq 0:11a51c9ebb09 1321 * This bit reflects the status of the FSYNC interrupt from an external device
mducrocq 0:11a51c9ebb09 1322 * into the MPU-60X0. This is used as a way to pass an external interrupt
mducrocq 0:11a51c9ebb09 1323 * through the MPU-60X0 to the host application processor. When set to 1, this
mducrocq 0:11a51c9ebb09 1324 * bit will cause an interrupt if FSYNC_INT_EN is asserted in INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1325 * (Register 55).
mducrocq 0:11a51c9ebb09 1326 * @return FSYNC interrupt status
mducrocq 0:11a51c9ebb09 1327 * @see MPU6050_RA_I2C_MST_STATUS
mducrocq 0:11a51c9ebb09 1328 */
mducrocq 0:11a51c9ebb09 1329 bool MPU6050::getPassthroughStatus()
mducrocq 0:11a51c9ebb09 1330 {
mducrocq 0:11a51c9ebb09 1331 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_PASS_THROUGH_BIT, buffer);
mducrocq 0:11a51c9ebb09 1332 return buffer[0];
mducrocq 0:11a51c9ebb09 1333 }
mducrocq 0:11a51c9ebb09 1334 /** Get Slave 4 transaction done status.
mducrocq 0:11a51c9ebb09 1335 * Automatically sets to 1 when a Slave 4 transaction has completed. This
mducrocq 0:11a51c9ebb09 1336 * triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register
mducrocq 0:11a51c9ebb09 1337 * (Register 56) is asserted and if the SLV_4_DONE_INT bit is asserted in the
mducrocq 0:11a51c9ebb09 1338 * I2C_SLV4_CTRL register (Register 52).
mducrocq 0:11a51c9ebb09 1339 * @return Slave 4 transaction done status
mducrocq 0:11a51c9ebb09 1340 * @see MPU6050_RA_I2C_MST_STATUS
mducrocq 0:11a51c9ebb09 1341 */
mducrocq 0:11a51c9ebb09 1342 bool MPU6050::getSlave4IsDone()
mducrocq 0:11a51c9ebb09 1343 {
mducrocq 0:11a51c9ebb09 1344 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_DONE_BIT, buffer);
mducrocq 0:11a51c9ebb09 1345 return buffer[0];
mducrocq 0:11a51c9ebb09 1346 }
mducrocq 0:11a51c9ebb09 1347 /** Get master arbitration lost status.
mducrocq 0:11a51c9ebb09 1348 * This bit automatically sets to 1 when the I2C Master has lost arbitration of
mducrocq 0:11a51c9ebb09 1349 * the auxiliary I2C bus (an error condition). This triggers an interrupt if the
mducrocq 0:11a51c9ebb09 1350 * I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.
mducrocq 0:11a51c9ebb09 1351 * @return Master arbitration lost status
mducrocq 0:11a51c9ebb09 1352 * @see MPU6050_RA_I2C_MST_STATUS
mducrocq 0:11a51c9ebb09 1353 */
mducrocq 0:11a51c9ebb09 1354 bool MPU6050::getLostArbitration()
mducrocq 0:11a51c9ebb09 1355 {
mducrocq 0:11a51c9ebb09 1356 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_LOST_ARB_BIT, buffer);
mducrocq 0:11a51c9ebb09 1357 return buffer[0];
mducrocq 0:11a51c9ebb09 1358 }
mducrocq 0:11a51c9ebb09 1359 /** Get Slave 4 NACK status.
mducrocq 0:11a51c9ebb09 1360 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
mducrocq 0:11a51c9ebb09 1361 * transaction with Slave 4. This triggers an interrupt if the I2C_MST_INT_EN
mducrocq 0:11a51c9ebb09 1362 * bit in the INT_ENABLE register (Register 56) is asserted.
mducrocq 0:11a51c9ebb09 1363 * @return Slave 4 NACK interrupt status
mducrocq 0:11a51c9ebb09 1364 * @see MPU6050_RA_I2C_MST_STATUS
mducrocq 0:11a51c9ebb09 1365 */
mducrocq 0:11a51c9ebb09 1366 bool MPU6050::getSlave4Nack()
mducrocq 0:11a51c9ebb09 1367 {
mducrocq 0:11a51c9ebb09 1368 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_NACK_BIT, buffer);
mducrocq 0:11a51c9ebb09 1369 return buffer[0];
mducrocq 0:11a51c9ebb09 1370 }
mducrocq 0:11a51c9ebb09 1371 /** Get Slave 3 NACK status.
mducrocq 0:11a51c9ebb09 1372 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
mducrocq 0:11a51c9ebb09 1373 * transaction with Slave 3. This triggers an interrupt if the I2C_MST_INT_EN
mducrocq 0:11a51c9ebb09 1374 * bit in the INT_ENABLE register (Register 56) is asserted.
mducrocq 0:11a51c9ebb09 1375 * @return Slave 3 NACK interrupt status
mducrocq 0:11a51c9ebb09 1376 * @see MPU6050_RA_I2C_MST_STATUS
mducrocq 0:11a51c9ebb09 1377 */
mducrocq 0:11a51c9ebb09 1378 bool MPU6050::getSlave3Nack()
mducrocq 0:11a51c9ebb09 1379 {
mducrocq 0:11a51c9ebb09 1380 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV3_NACK_BIT, buffer);
mducrocq 0:11a51c9ebb09 1381 return buffer[0];
mducrocq 0:11a51c9ebb09 1382 }
mducrocq 0:11a51c9ebb09 1383 /** Get Slave 2 NACK status.
mducrocq 0:11a51c9ebb09 1384 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
mducrocq 0:11a51c9ebb09 1385 * transaction with Slave 2. This triggers an interrupt if the I2C_MST_INT_EN
mducrocq 0:11a51c9ebb09 1386 * bit in the INT_ENABLE register (Register 56) is asserted.
mducrocq 0:11a51c9ebb09 1387 * @return Slave 2 NACK interrupt status
mducrocq 0:11a51c9ebb09 1388 * @see MPU6050_RA_I2C_MST_STATUS
mducrocq 0:11a51c9ebb09 1389 */
mducrocq 0:11a51c9ebb09 1390 bool MPU6050::getSlave2Nack()
mducrocq 0:11a51c9ebb09 1391 {
mducrocq 0:11a51c9ebb09 1392 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV2_NACK_BIT, buffer);
mducrocq 0:11a51c9ebb09 1393 return buffer[0];
mducrocq 0:11a51c9ebb09 1394 }
mducrocq 0:11a51c9ebb09 1395 /** Get Slave 1 NACK status.
mducrocq 0:11a51c9ebb09 1396 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
mducrocq 0:11a51c9ebb09 1397 * transaction with Slave 1. This triggers an interrupt if the I2C_MST_INT_EN
mducrocq 0:11a51c9ebb09 1398 * bit in the INT_ENABLE register (Register 56) is asserted.
mducrocq 0:11a51c9ebb09 1399 * @return Slave 1 NACK interrupt status
mducrocq 0:11a51c9ebb09 1400 * @see MPU6050_RA_I2C_MST_STATUS
mducrocq 0:11a51c9ebb09 1401 */
mducrocq 0:11a51c9ebb09 1402 bool MPU6050::getSlave1Nack()
mducrocq 0:11a51c9ebb09 1403 {
mducrocq 0:11a51c9ebb09 1404 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV1_NACK_BIT, buffer);
mducrocq 0:11a51c9ebb09 1405 return buffer[0];
mducrocq 0:11a51c9ebb09 1406 }
mducrocq 0:11a51c9ebb09 1407 /** Get Slave 0 NACK status.
mducrocq 0:11a51c9ebb09 1408 * This bit automatically sets to 1 when the I2C Master receives a NACK in a
mducrocq 0:11a51c9ebb09 1409 * transaction with Slave 0. This triggers an interrupt if the I2C_MST_INT_EN
mducrocq 0:11a51c9ebb09 1410 * bit in the INT_ENABLE register (Register 56) is asserted.
mducrocq 0:11a51c9ebb09 1411 * @return Slave 0 NACK interrupt status
mducrocq 0:11a51c9ebb09 1412 * @see MPU6050_RA_I2C_MST_STATUS
mducrocq 0:11a51c9ebb09 1413 */
mducrocq 0:11a51c9ebb09 1414 bool MPU6050::getSlave0Nack()
mducrocq 0:11a51c9ebb09 1415 {
mducrocq 0:11a51c9ebb09 1416 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV0_NACK_BIT, buffer);
mducrocq 0:11a51c9ebb09 1417 return buffer[0];
mducrocq 0:11a51c9ebb09 1418 }
mducrocq 0:11a51c9ebb09 1419
mducrocq 0:11a51c9ebb09 1420 // INT_PIN_CFG register
mducrocq 0:11a51c9ebb09 1421
mducrocq 0:11a51c9ebb09 1422 /** Get interrupt logic level mode.
mducrocq 0:11a51c9ebb09 1423 * Will be set 0 for active-high, 1 for active-low.
mducrocq 0:11a51c9ebb09 1424 * @return Current interrupt mode (0=active-high, 1=active-low)
mducrocq 0:11a51c9ebb09 1425 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1426 * @see MPU6050_INTCFG_INT_LEVEL_BIT
mducrocq 0:11a51c9ebb09 1427 */
mducrocq 0:11a51c9ebb09 1428 bool MPU6050::getInterruptMode()
mducrocq 0:11a51c9ebb09 1429 {
mducrocq 0:11a51c9ebb09 1430 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, buffer);
mducrocq 0:11a51c9ebb09 1431 return buffer[0];
mducrocq 0:11a51c9ebb09 1432 }
mducrocq 0:11a51c9ebb09 1433 /** Set interrupt logic level mode.
mducrocq 0:11a51c9ebb09 1434 * @param mode New interrupt mode (0=active-high, 1=active-low)
mducrocq 0:11a51c9ebb09 1435 * @see getInterruptMode()
mducrocq 0:11a51c9ebb09 1436 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1437 * @see MPU6050_INTCFG_INT_LEVEL_BIT
mducrocq 0:11a51c9ebb09 1438 */
mducrocq 0:11a51c9ebb09 1439 void MPU6050::setInterruptMode(bool mode)
mducrocq 0:11a51c9ebb09 1440 {
mducrocq 0:11a51c9ebb09 1441 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, mode);
mducrocq 0:11a51c9ebb09 1442 }
mducrocq 0:11a51c9ebb09 1443 /** Get interrupt drive mode.
mducrocq 0:11a51c9ebb09 1444 * Will be set 0 for push-pull, 1 for open-drain.
mducrocq 0:11a51c9ebb09 1445 * @return Current interrupt drive mode (0=push-pull, 1=open-drain)
mducrocq 0:11a51c9ebb09 1446 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1447 * @see MPU6050_INTCFG_INT_OPEN_BIT
mducrocq 0:11a51c9ebb09 1448 */
mducrocq 0:11a51c9ebb09 1449 bool MPU6050::getInterruptDrive()
mducrocq 0:11a51c9ebb09 1450 {
mducrocq 0:11a51c9ebb09 1451 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, buffer);
mducrocq 0:11a51c9ebb09 1452 return buffer[0];
mducrocq 0:11a51c9ebb09 1453 }
mducrocq 0:11a51c9ebb09 1454 /** Set interrupt drive mode.
mducrocq 0:11a51c9ebb09 1455 * @param drive New interrupt drive mode (0=push-pull, 1=open-drain)
mducrocq 0:11a51c9ebb09 1456 * @see getInterruptDrive()
mducrocq 0:11a51c9ebb09 1457 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1458 * @see MPU6050_INTCFG_INT_OPEN_BIT
mducrocq 0:11a51c9ebb09 1459 */
mducrocq 0:11a51c9ebb09 1460 void MPU6050::setInterruptDrive(bool drive)
mducrocq 0:11a51c9ebb09 1461 {
mducrocq 0:11a51c9ebb09 1462 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, drive);
mducrocq 0:11a51c9ebb09 1463 }
mducrocq 0:11a51c9ebb09 1464 /** Get interrupt latch mode.
mducrocq 0:11a51c9ebb09 1465 * Will be set 0 for 50us-pulse, 1 for latch-until-int-cleared.
mducrocq 0:11a51c9ebb09 1466 * @return Current latch mode (0=50us-pulse, 1=latch-until-int-cleared)
mducrocq 0:11a51c9ebb09 1467 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1468 * @see MPU6050_INTCFG_LATCH_INT_EN_BIT
mducrocq 0:11a51c9ebb09 1469 */
mducrocq 0:11a51c9ebb09 1470 bool MPU6050::getInterruptLatch()
mducrocq 0:11a51c9ebb09 1471 {
mducrocq 0:11a51c9ebb09 1472 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 1473 return buffer[0];
mducrocq 0:11a51c9ebb09 1474 }
mducrocq 0:11a51c9ebb09 1475 /** Set interrupt latch mode.
mducrocq 0:11a51c9ebb09 1476 * @param latch New latch mode (0=50us-pulse, 1=latch-until-int-cleared)
mducrocq 0:11a51c9ebb09 1477 * @see getInterruptLatch()
mducrocq 0:11a51c9ebb09 1478 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1479 * @see MPU6050_INTCFG_LATCH_INT_EN_BIT
mducrocq 0:11a51c9ebb09 1480 */
mducrocq 0:11a51c9ebb09 1481 void MPU6050::setInterruptLatch(bool latch)
mducrocq 0:11a51c9ebb09 1482 {
mducrocq 0:11a51c9ebb09 1483 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, latch);
mducrocq 0:11a51c9ebb09 1484 }
mducrocq 0:11a51c9ebb09 1485 /** Get interrupt latch clear mode.
mducrocq 0:11a51c9ebb09 1486 * Will be set 0 for status-read-only, 1 for any-register-read.
mducrocq 0:11a51c9ebb09 1487 * @return Current latch clear mode (0=status-read-only, 1=any-register-read)
mducrocq 0:11a51c9ebb09 1488 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1489 * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT
mducrocq 0:11a51c9ebb09 1490 */
mducrocq 0:11a51c9ebb09 1491 bool MPU6050::getInterruptLatchClear()
mducrocq 0:11a51c9ebb09 1492 {
mducrocq 0:11a51c9ebb09 1493 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, buffer);
mducrocq 0:11a51c9ebb09 1494 return buffer[0];
mducrocq 0:11a51c9ebb09 1495 }
mducrocq 0:11a51c9ebb09 1496 /** Set interrupt latch clear mode.
mducrocq 0:11a51c9ebb09 1497 * @param clear New latch clear mode (0=status-read-only, 1=any-register-read)
mducrocq 0:11a51c9ebb09 1498 * @see getInterruptLatchClear()
mducrocq 0:11a51c9ebb09 1499 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1500 * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT
mducrocq 0:11a51c9ebb09 1501 */
mducrocq 0:11a51c9ebb09 1502 void MPU6050::setInterruptLatchClear(bool clear)
mducrocq 0:11a51c9ebb09 1503 {
mducrocq 0:11a51c9ebb09 1504 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, clear);
mducrocq 0:11a51c9ebb09 1505 }
mducrocq 0:11a51c9ebb09 1506 /** Get FSYNC interrupt logic level mode.
mducrocq 0:11a51c9ebb09 1507 * @return Current FSYNC interrupt mode (0=active-high, 1=active-low)
mducrocq 0:11a51c9ebb09 1508 * @see getFSyncInterruptMode()
mducrocq 0:11a51c9ebb09 1509 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1510 * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT
mducrocq 0:11a51c9ebb09 1511 */
mducrocq 0:11a51c9ebb09 1512 bool MPU6050::getFSyncInterruptLevel()
mducrocq 0:11a51c9ebb09 1513 {
mducrocq 0:11a51c9ebb09 1514 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, buffer);
mducrocq 0:11a51c9ebb09 1515 return buffer[0];
mducrocq 0:11a51c9ebb09 1516 }
mducrocq 0:11a51c9ebb09 1517 /** Set FSYNC interrupt logic level mode.
mducrocq 0:11a51c9ebb09 1518 * @param mode New FSYNC interrupt mode (0=active-high, 1=active-low)
mducrocq 0:11a51c9ebb09 1519 * @see getFSyncInterruptMode()
mducrocq 0:11a51c9ebb09 1520 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1521 * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT
mducrocq 0:11a51c9ebb09 1522 */
mducrocq 0:11a51c9ebb09 1523 void MPU6050::setFSyncInterruptLevel(bool level)
mducrocq 0:11a51c9ebb09 1524 {
mducrocq 0:11a51c9ebb09 1525 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, level);
mducrocq 0:11a51c9ebb09 1526 }
mducrocq 0:11a51c9ebb09 1527 /** Get FSYNC pin interrupt enabled setting.
mducrocq 0:11a51c9ebb09 1528 * Will be set 0 for disabled, 1 for enabled.
mducrocq 0:11a51c9ebb09 1529 * @return Current interrupt enabled setting
mducrocq 0:11a51c9ebb09 1530 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1531 * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT
mducrocq 0:11a51c9ebb09 1532 */
mducrocq 0:11a51c9ebb09 1533 bool MPU6050::getFSyncInterruptEnabled()
mducrocq 0:11a51c9ebb09 1534 {
mducrocq 0:11a51c9ebb09 1535 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 1536 return buffer[0];
mducrocq 0:11a51c9ebb09 1537 }
mducrocq 0:11a51c9ebb09 1538 /** Set FSYNC pin interrupt enabled setting.
mducrocq 0:11a51c9ebb09 1539 * @param enabled New FSYNC pin interrupt enabled setting
mducrocq 0:11a51c9ebb09 1540 * @see getFSyncInterruptEnabled()
mducrocq 0:11a51c9ebb09 1541 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1542 * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT
mducrocq 0:11a51c9ebb09 1543 */
mducrocq 0:11a51c9ebb09 1544 void MPU6050::setFSyncInterruptEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1545 {
mducrocq 0:11a51c9ebb09 1546 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 1547 }
mducrocq 0:11a51c9ebb09 1548 /** Get I2C bypass enabled status.
mducrocq 0:11a51c9ebb09 1549 * When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to
mducrocq 0:11a51c9ebb09 1550 * 0, the host application processor will be able to directly access the
mducrocq 0:11a51c9ebb09 1551 * auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host
mducrocq 0:11a51c9ebb09 1552 * application processor will not be able to directly access the auxiliary I2C
mducrocq 0:11a51c9ebb09 1553 * bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106
mducrocq 0:11a51c9ebb09 1554 * bit[5]).
mducrocq 0:11a51c9ebb09 1555 * @return Current I2C bypass enabled status
mducrocq 0:11a51c9ebb09 1556 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1557 * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT
mducrocq 0:11a51c9ebb09 1558 */
mducrocq 0:11a51c9ebb09 1559 bool MPU6050::getI2CBypassEnabled()
mducrocq 0:11a51c9ebb09 1560 {
mducrocq 0:11a51c9ebb09 1561 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 1562 return buffer[0];
mducrocq 0:11a51c9ebb09 1563 }
mducrocq 0:11a51c9ebb09 1564 /** Set I2C bypass enabled status.
mducrocq 0:11a51c9ebb09 1565 * When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to
mducrocq 0:11a51c9ebb09 1566 * 0, the host application processor will be able to directly access the
mducrocq 0:11a51c9ebb09 1567 * auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host
mducrocq 0:11a51c9ebb09 1568 * application processor will not be able to directly access the auxiliary I2C
mducrocq 0:11a51c9ebb09 1569 * bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106
mducrocq 0:11a51c9ebb09 1570 * bit[5]).
mducrocq 0:11a51c9ebb09 1571 * @param enabled New I2C bypass enabled status
mducrocq 0:11a51c9ebb09 1572 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1573 * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT
mducrocq 0:11a51c9ebb09 1574 */
mducrocq 0:11a51c9ebb09 1575 void MPU6050::setI2CBypassEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1576 {
mducrocq 0:11a51c9ebb09 1577 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 1578 }
mducrocq 0:11a51c9ebb09 1579 /** Get reference clock output enabled status.
mducrocq 0:11a51c9ebb09 1580 * When this bit is equal to 1, a reference clock output is provided at the
mducrocq 0:11a51c9ebb09 1581 * CLKOUT pin. When this bit is equal to 0, the clock output is disabled. For
mducrocq 0:11a51c9ebb09 1582 * further information regarding CLKOUT, please refer to the MPU-60X0 Product
mducrocq 0:11a51c9ebb09 1583 * Specification document.
mducrocq 0:11a51c9ebb09 1584 * @return Current reference clock output enabled status
mducrocq 0:11a51c9ebb09 1585 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1586 * @see MPU6050_INTCFG_CLKOUT_EN_BIT
mducrocq 0:11a51c9ebb09 1587 */
mducrocq 0:11a51c9ebb09 1588 bool MPU6050::getClockOutputEnabled()
mducrocq 0:11a51c9ebb09 1589 {
mducrocq 0:11a51c9ebb09 1590 i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 1591 return buffer[0];
mducrocq 0:11a51c9ebb09 1592 }
mducrocq 0:11a51c9ebb09 1593 /** Set reference clock output enabled status.
mducrocq 0:11a51c9ebb09 1594 * When this bit is equal to 1, a reference clock output is provided at the
mducrocq 0:11a51c9ebb09 1595 * CLKOUT pin. When this bit is equal to 0, the clock output is disabled. For
mducrocq 0:11a51c9ebb09 1596 * further information regarding CLKOUT, please refer to the MPU-60X0 Product
mducrocq 0:11a51c9ebb09 1597 * Specification document.
mducrocq 0:11a51c9ebb09 1598 * @param enabled New reference clock output enabled status
mducrocq 0:11a51c9ebb09 1599 * @see MPU6050_RA_INT_PIN_CFG
mducrocq 0:11a51c9ebb09 1600 * @see MPU6050_INTCFG_CLKOUT_EN_BIT
mducrocq 0:11a51c9ebb09 1601 */
mducrocq 0:11a51c9ebb09 1602 void MPU6050::setClockOutputEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1603 {
mducrocq 0:11a51c9ebb09 1604 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 1605 }
mducrocq 0:11a51c9ebb09 1606
mducrocq 0:11a51c9ebb09 1607 // INT_ENABLE register
mducrocq 0:11a51c9ebb09 1608
mducrocq 0:11a51c9ebb09 1609 /** Get full interrupt enabled status.
mducrocq 0:11a51c9ebb09 1610 * Full register byte for all interrupts, for quick reading. Each bit will be
mducrocq 0:11a51c9ebb09 1611 * set 0 for disabled, 1 for enabled.
mducrocq 0:11a51c9ebb09 1612 * @return Current interrupt enabled status
mducrocq 0:11a51c9ebb09 1613 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1614 * @see MPU6050_INTERRUPT_FF_BIT
mducrocq 0:11a51c9ebb09 1615 **/
mducrocq 0:11a51c9ebb09 1616 uint8_t MPU6050::getIntEnabled()
mducrocq 0:11a51c9ebb09 1617 {
mducrocq 0:11a51c9ebb09 1618 i2Cdev.readByte(devAddr, MPU6050_RA_INT_ENABLE, buffer);
mducrocq 0:11a51c9ebb09 1619 return buffer[0];
mducrocq 0:11a51c9ebb09 1620 }
mducrocq 0:11a51c9ebb09 1621 /** Set full interrupt enabled status.
mducrocq 0:11a51c9ebb09 1622 * Full register byte for all interrupts, for quick reading. Each bit should be
mducrocq 0:11a51c9ebb09 1623 * set 0 for disabled, 1 for enabled.
mducrocq 0:11a51c9ebb09 1624 * @param enabled New interrupt enabled status
mducrocq 0:11a51c9ebb09 1625 * @see getIntFreefallEnabled()
mducrocq 0:11a51c9ebb09 1626 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1627 * @see MPU6050_INTERRUPT_FF_BIT
mducrocq 0:11a51c9ebb09 1628 **/
mducrocq 0:11a51c9ebb09 1629 void MPU6050::setIntEnabled(uint8_t enabled)
mducrocq 0:11a51c9ebb09 1630 {
mducrocq 0:11a51c9ebb09 1631 i2Cdev.writeByte(devAddr, MPU6050_RA_INT_ENABLE, enabled);
mducrocq 0:11a51c9ebb09 1632 }
mducrocq 0:11a51c9ebb09 1633 /** Get Free Fall interrupt enabled status.
mducrocq 0:11a51c9ebb09 1634 * Will be set 0 for disabled, 1 for enabled.
mducrocq 0:11a51c9ebb09 1635 * @return Current interrupt enabled status
mducrocq 0:11a51c9ebb09 1636 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1637 * @see MPU6050_INTERRUPT_FF_BIT
mducrocq 0:11a51c9ebb09 1638 **/
mducrocq 0:11a51c9ebb09 1639 bool MPU6050::getIntFreefallEnabled()
mducrocq 0:11a51c9ebb09 1640 {
mducrocq 0:11a51c9ebb09 1641 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, buffer);
mducrocq 0:11a51c9ebb09 1642 return buffer[0];
mducrocq 0:11a51c9ebb09 1643 }
mducrocq 0:11a51c9ebb09 1644 /** Set Free Fall interrupt enabled status.
mducrocq 0:11a51c9ebb09 1645 * @param enabled New interrupt enabled status
mducrocq 0:11a51c9ebb09 1646 * @see getIntFreefallEnabled()
mducrocq 0:11a51c9ebb09 1647 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1648 * @see MPU6050_INTERRUPT_FF_BIT
mducrocq 0:11a51c9ebb09 1649 **/
mducrocq 0:11a51c9ebb09 1650 void MPU6050::setIntFreefallEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1651 {
mducrocq 0:11a51c9ebb09 1652 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, enabled);
mducrocq 0:11a51c9ebb09 1653 }
mducrocq 0:11a51c9ebb09 1654 /** Get Motion Detection interrupt enabled status.
mducrocq 0:11a51c9ebb09 1655 * Will be set 0 for disabled, 1 for enabled.
mducrocq 0:11a51c9ebb09 1656 * @return Current interrupt enabled status
mducrocq 0:11a51c9ebb09 1657 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1658 * @see MPU6050_INTERRUPT_MOT_BIT
mducrocq 0:11a51c9ebb09 1659 **/
mducrocq 0:11a51c9ebb09 1660 bool MPU6050::getIntMotionEnabled()
mducrocq 0:11a51c9ebb09 1661 {
mducrocq 0:11a51c9ebb09 1662 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, buffer);
mducrocq 0:11a51c9ebb09 1663 return buffer[0];
mducrocq 0:11a51c9ebb09 1664 }
mducrocq 0:11a51c9ebb09 1665 /** Set Motion Detection interrupt enabled status.
mducrocq 0:11a51c9ebb09 1666 * @param enabled New interrupt enabled status
mducrocq 0:11a51c9ebb09 1667 * @see getIntMotionEnabled()
mducrocq 0:11a51c9ebb09 1668 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1669 * @see MPU6050_INTERRUPT_MOT_BIT
mducrocq 0:11a51c9ebb09 1670 **/
mducrocq 0:11a51c9ebb09 1671 void MPU6050::setIntMotionEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1672 {
mducrocq 0:11a51c9ebb09 1673 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, enabled);
mducrocq 0:11a51c9ebb09 1674 }
mducrocq 0:11a51c9ebb09 1675 /** Get Zero Motion Detection interrupt enabled status.
mducrocq 0:11a51c9ebb09 1676 * Will be set 0 for disabled, 1 for enabled.
mducrocq 0:11a51c9ebb09 1677 * @return Current interrupt enabled status
mducrocq 0:11a51c9ebb09 1678 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1679 * @see MPU6050_INTERRUPT_ZMOT_BIT
mducrocq 0:11a51c9ebb09 1680 **/
mducrocq 0:11a51c9ebb09 1681 bool MPU6050::getIntZeroMotionEnabled()
mducrocq 0:11a51c9ebb09 1682 {
mducrocq 0:11a51c9ebb09 1683 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, buffer);
mducrocq 0:11a51c9ebb09 1684 return buffer[0];
mducrocq 0:11a51c9ebb09 1685 }
mducrocq 0:11a51c9ebb09 1686 /** Set Zero Motion Detection interrupt enabled status.
mducrocq 0:11a51c9ebb09 1687 * @param enabled New interrupt enabled status
mducrocq 0:11a51c9ebb09 1688 * @see getIntZeroMotionEnabled()
mducrocq 0:11a51c9ebb09 1689 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1690 * @see MPU6050_INTERRUPT_ZMOT_BIT
mducrocq 0:11a51c9ebb09 1691 **/
mducrocq 0:11a51c9ebb09 1692 void MPU6050::setIntZeroMotionEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1693 {
mducrocq 0:11a51c9ebb09 1694 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, enabled);
mducrocq 0:11a51c9ebb09 1695 }
mducrocq 0:11a51c9ebb09 1696 /** Get FIFO Buffer Overflow interrupt enabled status.
mducrocq 0:11a51c9ebb09 1697 * Will be set 0 for disabled, 1 for enabled.
mducrocq 0:11a51c9ebb09 1698 * @return Current interrupt enabled status
mducrocq 0:11a51c9ebb09 1699 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1700 * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
mducrocq 0:11a51c9ebb09 1701 **/
mducrocq 0:11a51c9ebb09 1702 bool MPU6050::getIntFIFOBufferOverflowEnabled()
mducrocq 0:11a51c9ebb09 1703 {
mducrocq 0:11a51c9ebb09 1704 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer);
mducrocq 0:11a51c9ebb09 1705 return buffer[0];
mducrocq 0:11a51c9ebb09 1706 }
mducrocq 0:11a51c9ebb09 1707 /** Set FIFO Buffer Overflow interrupt enabled status.
mducrocq 0:11a51c9ebb09 1708 * @param enabled New interrupt enabled status
mducrocq 0:11a51c9ebb09 1709 * @see getIntFIFOBufferOverflowEnabled()
mducrocq 0:11a51c9ebb09 1710 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1711 * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
mducrocq 0:11a51c9ebb09 1712 **/
mducrocq 0:11a51c9ebb09 1713 void MPU6050::setIntFIFOBufferOverflowEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1714 {
mducrocq 0:11a51c9ebb09 1715 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, enabled);
mducrocq 0:11a51c9ebb09 1716 }
mducrocq 0:11a51c9ebb09 1717 /** Get I2C Master interrupt enabled status.
mducrocq 0:11a51c9ebb09 1718 * This enables any of the I2C Master interrupt sources to generate an
mducrocq 0:11a51c9ebb09 1719 * interrupt. Will be set 0 for disabled, 1 for enabled.
mducrocq 0:11a51c9ebb09 1720 * @return Current interrupt enabled status
mducrocq 0:11a51c9ebb09 1721 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1722 * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
mducrocq 0:11a51c9ebb09 1723 **/
mducrocq 0:11a51c9ebb09 1724 bool MPU6050::getIntI2CMasterEnabled()
mducrocq 0:11a51c9ebb09 1725 {
mducrocq 0:11a51c9ebb09 1726 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer);
mducrocq 0:11a51c9ebb09 1727 return buffer[0];
mducrocq 0:11a51c9ebb09 1728 }
mducrocq 0:11a51c9ebb09 1729 /** Set I2C Master interrupt enabled status.
mducrocq 0:11a51c9ebb09 1730 * @param enabled New interrupt enabled status
mducrocq 0:11a51c9ebb09 1731 * @see getIntI2CMasterEnabled()
mducrocq 0:11a51c9ebb09 1732 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1733 * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
mducrocq 0:11a51c9ebb09 1734 **/
mducrocq 0:11a51c9ebb09 1735 void MPU6050::setIntI2CMasterEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1736 {
mducrocq 0:11a51c9ebb09 1737 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, enabled);
mducrocq 0:11a51c9ebb09 1738 }
mducrocq 0:11a51c9ebb09 1739 /** Get Data Ready interrupt enabled setting.
mducrocq 0:11a51c9ebb09 1740 * This event occurs each time a write operation to all of the sensor registers
mducrocq 0:11a51c9ebb09 1741 * has been completed. Will be set 0 for disabled, 1 for enabled.
mducrocq 0:11a51c9ebb09 1742 * @return Current interrupt enabled status
mducrocq 0:11a51c9ebb09 1743 * @see MPU6050_RA_INT_ENABLE
mducrocq 0:11a51c9ebb09 1744 * @see MPU6050_INTERRUPT_DATA_RDY_BIT
mducrocq 0:11a51c9ebb09 1745 */
mducrocq 0:11a51c9ebb09 1746 bool MPU6050::getIntDataReadyEnabled()
mducrocq 0:11a51c9ebb09 1747 {
mducrocq 0:11a51c9ebb09 1748 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer);
mducrocq 0:11a51c9ebb09 1749 return buffer[0];
mducrocq 0:11a51c9ebb09 1750 }
mducrocq 0:11a51c9ebb09 1751 /** Set Data Ready interrupt enabled status.
mducrocq 0:11a51c9ebb09 1752 * @param enabled New interrupt enabled status
mducrocq 0:11a51c9ebb09 1753 * @see getIntDataReadyEnabled()
mducrocq 0:11a51c9ebb09 1754 * @see MPU6050_RA_INT_CFG
mducrocq 0:11a51c9ebb09 1755 * @see MPU6050_INTERRUPT_DATA_RDY_BIT
mducrocq 0:11a51c9ebb09 1756 */
mducrocq 0:11a51c9ebb09 1757 void MPU6050::setIntDataReadyEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 1758 {
mducrocq 0:11a51c9ebb09 1759 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, enabled);
mducrocq 0:11a51c9ebb09 1760 }
mducrocq 0:11a51c9ebb09 1761
mducrocq 0:11a51c9ebb09 1762 // INT_STATUS register
mducrocq 0:11a51c9ebb09 1763
mducrocq 0:11a51c9ebb09 1764 /** Get full set of interrupt status bits.
mducrocq 0:11a51c9ebb09 1765 * These bits clear to 0 after the register has been read. Very useful
mducrocq 0:11a51c9ebb09 1766 * for getting multiple INT statuses, since each single bit read clears
mducrocq 0:11a51c9ebb09 1767 * all of them because it has to read the whole byte.
mducrocq 0:11a51c9ebb09 1768 * @return Current interrupt status
mducrocq 0:11a51c9ebb09 1769 * @see MPU6050_RA_INT_STATUS
mducrocq 0:11a51c9ebb09 1770 */
mducrocq 0:11a51c9ebb09 1771 uint8_t MPU6050::getIntStatus()
mducrocq 0:11a51c9ebb09 1772 {
mducrocq 0:11a51c9ebb09 1773 i2Cdev.readByte(devAddr, MPU6050_RA_INT_STATUS, buffer);
mducrocq 0:11a51c9ebb09 1774 return buffer[0];
mducrocq 0:11a51c9ebb09 1775 }
mducrocq 0:11a51c9ebb09 1776 /** Get Free Fall interrupt status.
mducrocq 0:11a51c9ebb09 1777 * This bit automatically sets to 1 when a Free Fall interrupt has been
mducrocq 0:11a51c9ebb09 1778 * generated. The bit clears to 0 after the register has been read.
mducrocq 0:11a51c9ebb09 1779 * @return Current interrupt status
mducrocq 0:11a51c9ebb09 1780 * @see MPU6050_RA_INT_STATUS
mducrocq 0:11a51c9ebb09 1781 * @see MPU6050_INTERRUPT_FF_BIT
mducrocq 0:11a51c9ebb09 1782 */
mducrocq 0:11a51c9ebb09 1783 bool MPU6050::getIntFreefallStatus()
mducrocq 0:11a51c9ebb09 1784 {
mducrocq 0:11a51c9ebb09 1785 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FF_BIT, buffer);
mducrocq 0:11a51c9ebb09 1786 return buffer[0];
mducrocq 0:11a51c9ebb09 1787 }
mducrocq 0:11a51c9ebb09 1788 /** Get Motion Detection interrupt status.
mducrocq 0:11a51c9ebb09 1789 * This bit automatically sets to 1 when a Motion Detection interrupt has been
mducrocq 0:11a51c9ebb09 1790 * generated. The bit clears to 0 after the register has been read.
mducrocq 0:11a51c9ebb09 1791 * @return Current interrupt status
mducrocq 0:11a51c9ebb09 1792 * @see MPU6050_RA_INT_STATUS
mducrocq 0:11a51c9ebb09 1793 * @see MPU6050_INTERRUPT_MOT_BIT
mducrocq 0:11a51c9ebb09 1794 */
mducrocq 0:11a51c9ebb09 1795 bool MPU6050::getIntMotionStatus()
mducrocq 0:11a51c9ebb09 1796 {
mducrocq 0:11a51c9ebb09 1797 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_MOT_BIT, buffer);
mducrocq 0:11a51c9ebb09 1798 return buffer[0];
mducrocq 0:11a51c9ebb09 1799 }
mducrocq 0:11a51c9ebb09 1800 /** Get Zero Motion Detection interrupt status.
mducrocq 0:11a51c9ebb09 1801 * This bit automatically sets to 1 when a Zero Motion Detection interrupt has
mducrocq 0:11a51c9ebb09 1802 * been generated. The bit clears to 0 after the register has been read.
mducrocq 0:11a51c9ebb09 1803 * @return Current interrupt status
mducrocq 0:11a51c9ebb09 1804 * @see MPU6050_RA_INT_STATUS
mducrocq 0:11a51c9ebb09 1805 * @see MPU6050_INTERRUPT_ZMOT_BIT
mducrocq 0:11a51c9ebb09 1806 */
mducrocq 0:11a51c9ebb09 1807 bool MPU6050::getIntZeroMotionStatus()
mducrocq 0:11a51c9ebb09 1808 {
mducrocq 0:11a51c9ebb09 1809 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_ZMOT_BIT, buffer);
mducrocq 0:11a51c9ebb09 1810 return buffer[0];
mducrocq 0:11a51c9ebb09 1811 }
mducrocq 0:11a51c9ebb09 1812 /** Get FIFO Buffer Overflow interrupt status.
mducrocq 0:11a51c9ebb09 1813 * This bit automatically sets to 1 when a Free Fall interrupt has been
mducrocq 0:11a51c9ebb09 1814 * generated. The bit clears to 0 after the register has been read.
mducrocq 0:11a51c9ebb09 1815 * @return Current interrupt status
mducrocq 0:11a51c9ebb09 1816 * @see MPU6050_RA_INT_STATUS
mducrocq 0:11a51c9ebb09 1817 * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
mducrocq 0:11a51c9ebb09 1818 */
mducrocq 0:11a51c9ebb09 1819 bool MPU6050::getIntFIFOBufferOverflowStatus()
mducrocq 0:11a51c9ebb09 1820 {
mducrocq 0:11a51c9ebb09 1821 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer);
mducrocq 0:11a51c9ebb09 1822 return buffer[0];
mducrocq 0:11a51c9ebb09 1823 }
mducrocq 0:11a51c9ebb09 1824 /** Get I2C Master interrupt status.
mducrocq 0:11a51c9ebb09 1825 * This bit automatically sets to 1 when an I2C Master interrupt has been
mducrocq 0:11a51c9ebb09 1826 * generated. For a list of I2C Master interrupts, please refer to Register 54.
mducrocq 0:11a51c9ebb09 1827 * The bit clears to 0 after the register has been read.
mducrocq 0:11a51c9ebb09 1828 * @return Current interrupt status
mducrocq 0:11a51c9ebb09 1829 * @see MPU6050_RA_INT_STATUS
mducrocq 0:11a51c9ebb09 1830 * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
mducrocq 0:11a51c9ebb09 1831 */
mducrocq 0:11a51c9ebb09 1832 bool MPU6050::getIntI2CMasterStatus()
mducrocq 0:11a51c9ebb09 1833 {
mducrocq 0:11a51c9ebb09 1834 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer);
mducrocq 0:11a51c9ebb09 1835 return buffer[0];
mducrocq 0:11a51c9ebb09 1836 }
mducrocq 0:11a51c9ebb09 1837 /** Get Data Ready interrupt status.
mducrocq 0:11a51c9ebb09 1838 * This bit automatically sets to 1 when a Data Ready interrupt has been
mducrocq 0:11a51c9ebb09 1839 * generated. The bit clears to 0 after the register has been read.
mducrocq 0:11a51c9ebb09 1840 * @return Current interrupt status
mducrocq 0:11a51c9ebb09 1841 * @see MPU6050_RA_INT_STATUS
mducrocq 0:11a51c9ebb09 1842 * @see MPU6050_INTERRUPT_DATA_RDY_BIT
mducrocq 0:11a51c9ebb09 1843 */
mducrocq 0:11a51c9ebb09 1844 bool MPU6050::getIntDataReadyStatus()
mducrocq 0:11a51c9ebb09 1845 {
mducrocq 0:11a51c9ebb09 1846 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer);
mducrocq 0:11a51c9ebb09 1847 return buffer[0];
mducrocq 0:11a51c9ebb09 1848 }
mducrocq 0:11a51c9ebb09 1849
mducrocq 0:11a51c9ebb09 1850 // ACCEL_*OUT_* registers
mducrocq 0:11a51c9ebb09 1851
mducrocq 0:11a51c9ebb09 1852 /** Get raw 9-axis motion sensor readings (accel/gyro/compass).
mducrocq 0:11a51c9ebb09 1853 * FUNCTION NOT FULLY IMPLEMENTED YET.
mducrocq 0:11a51c9ebb09 1854 * @param ax 16-bit signed integer container for accelerometer X-axis value
mducrocq 0:11a51c9ebb09 1855 * @param ay 16-bit signed integer container for accelerometer Y-axis value
mducrocq 0:11a51c9ebb09 1856 * @param az 16-bit signed integer container for accelerometer Z-axis value
mducrocq 0:11a51c9ebb09 1857 * @param gx 16-bit signed integer container for gyroscope X-axis value
mducrocq 0:11a51c9ebb09 1858 * @param gy 16-bit signed integer container for gyroscope Y-axis value
mducrocq 0:11a51c9ebb09 1859 * @param gz 16-bit signed integer container for gyroscope Z-axis value
mducrocq 0:11a51c9ebb09 1860 * @param mx 16-bit signed integer container for magnetometer X-axis value
mducrocq 0:11a51c9ebb09 1861 * @param my 16-bit signed integer container for magnetometer Y-axis value
mducrocq 0:11a51c9ebb09 1862 * @param mz 16-bit signed integer container for magnetometer Z-axis value
mducrocq 0:11a51c9ebb09 1863 * @see getMotion6()
mducrocq 0:11a51c9ebb09 1864 * @see getAcceleration()
mducrocq 0:11a51c9ebb09 1865 * @see getRotation()
mducrocq 0:11a51c9ebb09 1866 * @see MPU6050_RA_ACCEL_XOUT_H
mducrocq 0:11a51c9ebb09 1867 */
mducrocq 0:11a51c9ebb09 1868 void MPU6050::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz)
mducrocq 0:11a51c9ebb09 1869 {
mducrocq 0:11a51c9ebb09 1870 getMotion6(ax, ay, az, gx, gy, gz);
mducrocq 0:11a51c9ebb09 1871 // TODO: magnetometer integration
mducrocq 0:11a51c9ebb09 1872 }
mducrocq 0:11a51c9ebb09 1873 /** Get raw 6-axis motion sensor readings (accel/gyro).
mducrocq 0:11a51c9ebb09 1874 * Retrieves all currently available motion sensor values.
mducrocq 0:11a51c9ebb09 1875 * @param ax 16-bit signed integer container for accelerometer X-axis value
mducrocq 0:11a51c9ebb09 1876 * @param ay 16-bit signed integer container for accelerometer Y-axis value
mducrocq 0:11a51c9ebb09 1877 * @param az 16-bit signed integer container for accelerometer Z-axis value
mducrocq 0:11a51c9ebb09 1878 * @param gx 16-bit signed integer container for gyroscope X-axis value
mducrocq 0:11a51c9ebb09 1879 * @param gy 16-bit signed integer container for gyroscope Y-axis value
mducrocq 0:11a51c9ebb09 1880 * @param gz 16-bit signed integer container for gyroscope Z-axis value
mducrocq 0:11a51c9ebb09 1881 * @see getAcceleration()
mducrocq 0:11a51c9ebb09 1882 * @see getRotation()
mducrocq 0:11a51c9ebb09 1883 * @see MPU6050_RA_ACCEL_XOUT_H
mducrocq 0:11a51c9ebb09 1884 */
mducrocq 0:11a51c9ebb09 1885 void MPU6050::getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz)
mducrocq 0:11a51c9ebb09 1886 {
mducrocq 0:11a51c9ebb09 1887 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 14, buffer);
mducrocq 0:11a51c9ebb09 1888 *ax = (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 1889 *ay = (((int16_t)buffer[2]) << 8) | buffer[3];
mducrocq 0:11a51c9ebb09 1890 *az = (((int16_t)buffer[4]) << 8) | buffer[5];
mducrocq 0:11a51c9ebb09 1891 *gx = (((int16_t)buffer[8]) << 8) | buffer[9];
mducrocq 0:11a51c9ebb09 1892 *gy = (((int16_t)buffer[10]) << 8) | buffer[11];
mducrocq 0:11a51c9ebb09 1893 *gz = (((int16_t)buffer[12]) << 8) | buffer[13];
mducrocq 0:11a51c9ebb09 1894 }
mducrocq 0:11a51c9ebb09 1895 /** Get 3-axis accelerometer readings.
mducrocq 0:11a51c9ebb09 1896 * These registers store the most recent accelerometer measurements.
mducrocq 0:11a51c9ebb09 1897 * Accelerometer measurements are written to these registers at the Sample Rate
mducrocq 0:11a51c9ebb09 1898 * as defined in Register 25.
mducrocq 0:11a51c9ebb09 1899 *
mducrocq 0:11a51c9ebb09 1900 * The accelerometer measurement registers, along with the temperature
mducrocq 0:11a51c9ebb09 1901 * measurement registers, gyroscope measurement registers, and external sensor
mducrocq 0:11a51c9ebb09 1902 * data registers, are composed of two sets of registers: an internal register
mducrocq 0:11a51c9ebb09 1903 * set and a user-facing read register set.
mducrocq 0:11a51c9ebb09 1904 *
mducrocq 0:11a51c9ebb09 1905 * The data within the accelerometer sensors' internal register set is always
mducrocq 0:11a51c9ebb09 1906 * updated at the Sample Rate. Meanwhile, the user-facing read register set
mducrocq 0:11a51c9ebb09 1907 * duplicates the internal register set's data values whenever the serial
mducrocq 0:11a51c9ebb09 1908 * interface is idle. This guarantees that a burst read of sensor registers will
mducrocq 0:11a51c9ebb09 1909 * read measurements from the same sampling instant. Note that if burst reads
mducrocq 0:11a51c9ebb09 1910 * are not used, the user is responsible for ensuring a set of single byte reads
mducrocq 0:11a51c9ebb09 1911 * correspond to a single sampling instant by checking the Data Ready interrupt.
mducrocq 0:11a51c9ebb09 1912 *
mducrocq 0:11a51c9ebb09 1913 * Each 16-bit accelerometer measurement has a full scale defined in ACCEL_FS
mducrocq 0:11a51c9ebb09 1914 * (Register 28). For each full scale setting, the accelerometers' sensitivity
mducrocq 0:11a51c9ebb09 1915 * per LSB in ACCEL_xOUT is shown in the table below:
mducrocq 0:11a51c9ebb09 1916 *
mducrocq 0:11a51c9ebb09 1917 * <pre>
mducrocq 0:11a51c9ebb09 1918 * AFS_SEL | Full Scale Range | LSB Sensitivity
mducrocq 0:11a51c9ebb09 1919 * --------+------------------+----------------
mducrocq 0:11a51c9ebb09 1920 * 0 | +/- 2g | 8192 LSB/mg
mducrocq 0:11a51c9ebb09 1921 * 1 | +/- 4g | 4096 LSB/mg
mducrocq 0:11a51c9ebb09 1922 * 2 | +/- 8g | 2048 LSB/mg
mducrocq 0:11a51c9ebb09 1923 * 3 | +/- 16g | 1024 LSB/mg
mducrocq 0:11a51c9ebb09 1924 * </pre>
mducrocq 0:11a51c9ebb09 1925 *
mducrocq 0:11a51c9ebb09 1926 * @param x 16-bit signed integer container for X-axis acceleration
mducrocq 0:11a51c9ebb09 1927 * @param y 16-bit signed integer container for Y-axis acceleration
mducrocq 0:11a51c9ebb09 1928 * @param z 16-bit signed integer container for Z-axis acceleration
mducrocq 0:11a51c9ebb09 1929 * @see MPU6050_RA_GYRO_XOUT_H
mducrocq 0:11a51c9ebb09 1930 */
mducrocq 0:11a51c9ebb09 1931 void MPU6050::getAcceleration(int16_t* x, int16_t* y, int16_t* z)
mducrocq 0:11a51c9ebb09 1932 {
mducrocq 0:11a51c9ebb09 1933 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 6, buffer);
mducrocq 0:11a51c9ebb09 1934 *x = (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 1935 *y = (((int16_t)buffer[2]) << 8) | buffer[3];
mducrocq 0:11a51c9ebb09 1936 *z = (((int16_t)buffer[4]) << 8) | buffer[5];
mducrocq 0:11a51c9ebb09 1937 }
mducrocq 0:11a51c9ebb09 1938 /** Get X-axis accelerometer reading.
mducrocq 0:11a51c9ebb09 1939 * @return X-axis acceleration measurement in 16-bit 2's complement format
mducrocq 0:11a51c9ebb09 1940 * @see getMotion6()
mducrocq 0:11a51c9ebb09 1941 * @see MPU6050_RA_ACCEL_XOUT_H
mducrocq 0:11a51c9ebb09 1942 */
mducrocq 0:11a51c9ebb09 1943 int16_t MPU6050::getAccelerationX()
mducrocq 0:11a51c9ebb09 1944 {
mducrocq 0:11a51c9ebb09 1945 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 2, buffer);
mducrocq 0:11a51c9ebb09 1946 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 1947 }
mducrocq 0:11a51c9ebb09 1948 /** Get Y-axis accelerometer reading.
mducrocq 0:11a51c9ebb09 1949 * @return Y-axis acceleration measurement in 16-bit 2's complement format
mducrocq 0:11a51c9ebb09 1950 * @see getMotion6()
mducrocq 0:11a51c9ebb09 1951 * @see MPU6050_RA_ACCEL_YOUT_H
mducrocq 0:11a51c9ebb09 1952 */
mducrocq 0:11a51c9ebb09 1953 int16_t MPU6050::getAccelerationY()
mducrocq 0:11a51c9ebb09 1954 {
mducrocq 0:11a51c9ebb09 1955 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_YOUT_H, 2, buffer);
mducrocq 0:11a51c9ebb09 1956 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 1957 }
mducrocq 0:11a51c9ebb09 1958 /** Get Z-axis accelerometer reading.
mducrocq 0:11a51c9ebb09 1959 * @return Z-axis acceleration measurement in 16-bit 2's complement format
mducrocq 0:11a51c9ebb09 1960 * @see getMotion6()
mducrocq 0:11a51c9ebb09 1961 * @see MPU6050_RA_ACCEL_ZOUT_H
mducrocq 0:11a51c9ebb09 1962 */
mducrocq 0:11a51c9ebb09 1963 int16_t MPU6050::getAccelerationZ()
mducrocq 0:11a51c9ebb09 1964 {
mducrocq 0:11a51c9ebb09 1965 i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_ZOUT_H, 2, buffer);
mducrocq 0:11a51c9ebb09 1966 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 1967 }
mducrocq 0:11a51c9ebb09 1968
mducrocq 0:11a51c9ebb09 1969 // TEMP_OUT_* registers
mducrocq 0:11a51c9ebb09 1970
mducrocq 0:11a51c9ebb09 1971 /** Get current internal temperature.
mducrocq 0:11a51c9ebb09 1972 * @return Temperature reading in 16-bit 2's complement format
mducrocq 0:11a51c9ebb09 1973 * @see MPU6050_RA_TEMP_OUT_H
mducrocq 0:11a51c9ebb09 1974 */
mducrocq 0:11a51c9ebb09 1975 int16_t MPU6050::getTemperature()
mducrocq 0:11a51c9ebb09 1976 {
mducrocq 0:11a51c9ebb09 1977 i2Cdev.readBytes(devAddr, MPU6050_RA_TEMP_OUT_H, 2, buffer);
mducrocq 0:11a51c9ebb09 1978 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 1979 }
mducrocq 0:11a51c9ebb09 1980
mducrocq 0:11a51c9ebb09 1981 // GYRO_*OUT_* registers
mducrocq 0:11a51c9ebb09 1982
mducrocq 0:11a51c9ebb09 1983 /** Get 3-axis gyroscope readings.
mducrocq 0:11a51c9ebb09 1984 * These gyroscope measurement registers, along with the accelerometer
mducrocq 0:11a51c9ebb09 1985 * measurement registers, temperature measurement registers, and external sensor
mducrocq 0:11a51c9ebb09 1986 * data registers, are composed of two sets of registers: an internal register
mducrocq 0:11a51c9ebb09 1987 * set and a user-facing read register set.
mducrocq 0:11a51c9ebb09 1988 * The data within the gyroscope sensors' internal register set is always
mducrocq 0:11a51c9ebb09 1989 * updated at the Sample Rate. Meanwhile, the user-facing read register set
mducrocq 0:11a51c9ebb09 1990 * duplicates the internal register set's data values whenever the serial
mducrocq 0:11a51c9ebb09 1991 * interface is idle. This guarantees that a burst read of sensor registers will
mducrocq 0:11a51c9ebb09 1992 * read measurements from the same sampling instant. Note that if burst reads
mducrocq 0:11a51c9ebb09 1993 * are not used, the user is responsible for ensuring a set of single byte reads
mducrocq 0:11a51c9ebb09 1994 * correspond to a single sampling instant by checking the Data Ready interrupt.
mducrocq 0:11a51c9ebb09 1995 *
mducrocq 0:11a51c9ebb09 1996 * Each 16-bit gyroscope measurement has a full scale defined in FS_SEL
mducrocq 0:11a51c9ebb09 1997 * (Register 27). For each full scale setting, the gyroscopes' sensitivity per
mducrocq 0:11a51c9ebb09 1998 * LSB in GYRO_xOUT is shown in the table below:
mducrocq 0:11a51c9ebb09 1999 *
mducrocq 0:11a51c9ebb09 2000 * <pre>
mducrocq 0:11a51c9ebb09 2001 * FS_SEL | Full Scale Range | LSB Sensitivity
mducrocq 0:11a51c9ebb09 2002 * -------+--------------------+----------------
mducrocq 0:11a51c9ebb09 2003 * 0 | +/- 250 degrees/s | 131 LSB/deg/s
mducrocq 0:11a51c9ebb09 2004 * 1 | +/- 500 degrees/s | 65.5 LSB/deg/s
mducrocq 0:11a51c9ebb09 2005 * 2 | +/- 1000 degrees/s | 32.8 LSB/deg/s
mducrocq 0:11a51c9ebb09 2006 * 3 | +/- 2000 degrees/s | 16.4 LSB/deg/s
mducrocq 0:11a51c9ebb09 2007 * </pre>
mducrocq 0:11a51c9ebb09 2008 *
mducrocq 0:11a51c9ebb09 2009 * @param x 16-bit signed integer container for X-axis rotation
mducrocq 0:11a51c9ebb09 2010 * @param y 16-bit signed integer container for Y-axis rotation
mducrocq 0:11a51c9ebb09 2011 * @param z 16-bit signed integer container for Z-axis rotation
mducrocq 0:11a51c9ebb09 2012 * @see getMotion6()
mducrocq 0:11a51c9ebb09 2013 * @see MPU6050_RA_GYRO_XOUT_H
mducrocq 0:11a51c9ebb09 2014 */
mducrocq 0:11a51c9ebb09 2015 void MPU6050::getRotation(int16_t* x, int16_t* y, int16_t* z)
mducrocq 0:11a51c9ebb09 2016 {
mducrocq 0:11a51c9ebb09 2017 i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 6, buffer);
mducrocq 0:11a51c9ebb09 2018 *x = (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 2019 *y = (((int16_t)buffer[2]) << 8) | buffer[3];
mducrocq 0:11a51c9ebb09 2020 *z = (((int16_t)buffer[4]) << 8) | buffer[5];
mducrocq 0:11a51c9ebb09 2021 }
mducrocq 0:11a51c9ebb09 2022 /** Get X-axis gyroscope reading.
mducrocq 0:11a51c9ebb09 2023 * @return X-axis rotation measurement in 16-bit 2's complement format
mducrocq 0:11a51c9ebb09 2024 * @see getMotion6()
mducrocq 0:11a51c9ebb09 2025 * @see MPU6050_RA_GYRO_XOUT_H
mducrocq 0:11a51c9ebb09 2026 */
mducrocq 0:11a51c9ebb09 2027 int16_t MPU6050::getRotationX()
mducrocq 0:11a51c9ebb09 2028 {
mducrocq 0:11a51c9ebb09 2029 i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 2, buffer);
mducrocq 0:11a51c9ebb09 2030 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 2031 }
mducrocq 0:11a51c9ebb09 2032 /** Get Y-axis gyroscope reading.
mducrocq 0:11a51c9ebb09 2033 * @return Y-axis rotation measurement in 16-bit 2's complement format
mducrocq 0:11a51c9ebb09 2034 * @see getMotion6()
mducrocq 0:11a51c9ebb09 2035 * @see MPU6050_RA_GYRO_YOUT_H
mducrocq 0:11a51c9ebb09 2036 */
mducrocq 0:11a51c9ebb09 2037 int16_t MPU6050::getRotationY()
mducrocq 0:11a51c9ebb09 2038 {
mducrocq 0:11a51c9ebb09 2039 i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_YOUT_H, 2, buffer);
mducrocq 0:11a51c9ebb09 2040 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 2041 }
mducrocq 0:11a51c9ebb09 2042 /** Get Z-axis gyroscope reading.
mducrocq 0:11a51c9ebb09 2043 * @return Z-axis rotation measurement in 16-bit 2's complement format
mducrocq 0:11a51c9ebb09 2044 * @see getMotion6()
mducrocq 0:11a51c9ebb09 2045 * @see MPU6050_RA_GYRO_ZOUT_H
mducrocq 0:11a51c9ebb09 2046 */
mducrocq 0:11a51c9ebb09 2047 int16_t MPU6050::getRotationZ()
mducrocq 0:11a51c9ebb09 2048 {
mducrocq 0:11a51c9ebb09 2049 i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_ZOUT_H, 2, buffer);
mducrocq 0:11a51c9ebb09 2050 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 2051 }
mducrocq 0:11a51c9ebb09 2052
mducrocq 0:11a51c9ebb09 2053 // EXT_SENS_DATA_* registers
mducrocq 0:11a51c9ebb09 2054
mducrocq 0:11a51c9ebb09 2055 /** Read single byte from external sensor data register.
mducrocq 0:11a51c9ebb09 2056 * These registers store data read from external sensors by the Slave 0, 1, 2,
mducrocq 0:11a51c9ebb09 2057 * and 3 on the auxiliary I2C interface. Data read by Slave 4 is stored in
mducrocq 0:11a51c9ebb09 2058 * I2C_SLV4_DI (Register 53).
mducrocq 0:11a51c9ebb09 2059 *
mducrocq 0:11a51c9ebb09 2060 * External sensor data is written to these registers at the Sample Rate as
mducrocq 0:11a51c9ebb09 2061 * defined in Register 25. This access rate can be reduced by using the Slave
mducrocq 0:11a51c9ebb09 2062 * Delay Enable registers (Register 103).
mducrocq 0:11a51c9ebb09 2063 *
mducrocq 0:11a51c9ebb09 2064 * External sensor data registers, along with the gyroscope measurement
mducrocq 0:11a51c9ebb09 2065 * registers, accelerometer measurement registers, and temperature measurement
mducrocq 0:11a51c9ebb09 2066 * registers, are composed of two sets of registers: an internal register set
mducrocq 0:11a51c9ebb09 2067 * and a user-facing read register set.
mducrocq 0:11a51c9ebb09 2068 *
mducrocq 0:11a51c9ebb09 2069 * The data within the external sensors' internal register set is always updated
mducrocq 0:11a51c9ebb09 2070 * at the Sample Rate (or the reduced access rate) whenever the serial interface
mducrocq 0:11a51c9ebb09 2071 * is idle. This guarantees that a burst read of sensor registers will read
mducrocq 0:11a51c9ebb09 2072 * measurements from the same sampling instant. Note that if burst reads are not
mducrocq 0:11a51c9ebb09 2073 * used, the user is responsible for ensuring a set of single byte reads
mducrocq 0:11a51c9ebb09 2074 * correspond to a single sampling instant by checking the Data Ready interrupt.
mducrocq 0:11a51c9ebb09 2075 *
mducrocq 0:11a51c9ebb09 2076 * Data is placed in these external sensor data registers according to
mducrocq 0:11a51c9ebb09 2077 * I2C_SLV0_CTRL, I2C_SLV1_CTRL, I2C_SLV2_CTRL, and I2C_SLV3_CTRL (Registers 39,
mducrocq 0:11a51c9ebb09 2078 * 42, 45, and 48). When more than zero bytes are read (I2C_SLVx_LEN > 0) from
mducrocq 0:11a51c9ebb09 2079 * an enabled slave (I2C_SLVx_EN = 1), the slave is read at the Sample Rate (as
mducrocq 0:11a51c9ebb09 2080 * defined in Register 25) or delayed rate (if specified in Register 52 and
mducrocq 0:11a51c9ebb09 2081 * 103). During each Sample cycle, slave reads are performed in order of Slave
mducrocq 0:11a51c9ebb09 2082 * number. If all slaves are enabled with more than zero bytes to be read, the
mducrocq 0:11a51c9ebb09 2083 * order will be Slave 0, followed by Slave 1, Slave 2, and Slave 3.
mducrocq 0:11a51c9ebb09 2084 *
mducrocq 0:11a51c9ebb09 2085 * Each enabled slave will have EXT_SENS_DATA registers associated with it by
mducrocq 0:11a51c9ebb09 2086 * number of bytes read (I2C_SLVx_LEN) in order of slave number, starting from
mducrocq 0:11a51c9ebb09 2087 * EXT_SENS_DATA_00. Note that this means enabling or disabling a slave may
mducrocq 0:11a51c9ebb09 2088 * change the higher numbered slaves' associated registers. Furthermore, if
mducrocq 0:11a51c9ebb09 2089 * fewer total bytes are being read from the external sensors as a result of
mducrocq 0:11a51c9ebb09 2090 * such a change, then the data remaining in the registers which no longer have
mducrocq 0:11a51c9ebb09 2091 * an associated slave device (i.e. high numbered registers) will remain in
mducrocq 0:11a51c9ebb09 2092 * these previously allocated registers unless reset.
mducrocq 0:11a51c9ebb09 2093 *
mducrocq 0:11a51c9ebb09 2094 * If the sum of the read lengths of all SLVx transactions exceed the number of
mducrocq 0:11a51c9ebb09 2095 * available EXT_SENS_DATA registers, the excess bytes will be dropped. There
mducrocq 0:11a51c9ebb09 2096 * are 24 EXT_SENS_DATA registers and hence the total read lengths between all
mducrocq 0:11a51c9ebb09 2097 * the slaves cannot be greater than 24 or some bytes will be lost.
mducrocq 0:11a51c9ebb09 2098 *
mducrocq 0:11a51c9ebb09 2099 * Note: Slave 4's behavior is distinct from that of Slaves 0-3. For further
mducrocq 0:11a51c9ebb09 2100 * information regarding the characteristics of Slave 4, please refer to
mducrocq 0:11a51c9ebb09 2101 * Registers 49 to 53.
mducrocq 0:11a51c9ebb09 2102 *
mducrocq 0:11a51c9ebb09 2103 * EXAMPLE:
mducrocq 0:11a51c9ebb09 2104 * Suppose that Slave 0 is enabled with 4 bytes to be read (I2C_SLV0_EN = 1 and
mducrocq 0:11a51c9ebb09 2105 * I2C_SLV0_LEN = 4) while Slave 1 is enabled with 2 bytes to be read so that
mducrocq 0:11a51c9ebb09 2106 * I2C_SLV1_EN = 1 and I2C_SLV1_LEN = 2. In such a situation, EXT_SENS_DATA _00
mducrocq 0:11a51c9ebb09 2107 * through _03 will be associated with Slave 0, while EXT_SENS_DATA _04 and 05
mducrocq 0:11a51c9ebb09 2108 * will be associated with Slave 1. If Slave 2 is enabled as well, registers
mducrocq 0:11a51c9ebb09 2109 * starting from EXT_SENS_DATA_06 will be allocated to Slave 2.
mducrocq 0:11a51c9ebb09 2110 *
mducrocq 0:11a51c9ebb09 2111 * If Slave 2 is disabled while Slave 3 is enabled in this same situation, then
mducrocq 0:11a51c9ebb09 2112 * registers starting from EXT_SENS_DATA_06 will be allocated to Slave 3
mducrocq 0:11a51c9ebb09 2113 * instead.
mducrocq 0:11a51c9ebb09 2114 *
mducrocq 0:11a51c9ebb09 2115 * REGISTER ALLOCATION FOR DYNAMIC DISABLE VS. NORMAL DISABLE:
mducrocq 0:11a51c9ebb09 2116 * If a slave is disabled at any time, the space initially allocated to the
mducrocq 0:11a51c9ebb09 2117 * slave in the EXT_SENS_DATA register, will remain associated with that slave.
mducrocq 0:11a51c9ebb09 2118 * This is to avoid dynamic adjustment of the register allocation.
mducrocq 0:11a51c9ebb09 2119 *
mducrocq 0:11a51c9ebb09 2120 * The allocation of the EXT_SENS_DATA registers is recomputed only when (1) all
mducrocq 0:11a51c9ebb09 2121 * slaves are disabled, or (2) the I2C_MST_RST bit is set (Register 106).
mducrocq 0:11a51c9ebb09 2122 *
mducrocq 0:11a51c9ebb09 2123 * This above is also true if one of the slaves gets NACKed and stops
mducrocq 0:11a51c9ebb09 2124 * functioning.
mducrocq 0:11a51c9ebb09 2125 *
mducrocq 0:11a51c9ebb09 2126 * @param position Starting position (0-23)
mducrocq 0:11a51c9ebb09 2127 * @return Byte read from register
mducrocq 0:11a51c9ebb09 2128 */
mducrocq 0:11a51c9ebb09 2129 uint8_t MPU6050::getExternalSensorByte(int position)
mducrocq 0:11a51c9ebb09 2130 {
mducrocq 0:11a51c9ebb09 2131 i2Cdev.readByte(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, buffer);
mducrocq 0:11a51c9ebb09 2132 return buffer[0];
mducrocq 0:11a51c9ebb09 2133 }
mducrocq 0:11a51c9ebb09 2134 /** Read word (2 bytes) from external sensor data registers.
mducrocq 0:11a51c9ebb09 2135 * @param position Starting position (0-21)
mducrocq 0:11a51c9ebb09 2136 * @return Word read from register
mducrocq 0:11a51c9ebb09 2137 * @see getExternalSensorByte()
mducrocq 0:11a51c9ebb09 2138 */
mducrocq 0:11a51c9ebb09 2139 uint16_t MPU6050::getExternalSensorWord(int position)
mducrocq 0:11a51c9ebb09 2140 {
mducrocq 0:11a51c9ebb09 2141 i2Cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 2, buffer);
mducrocq 0:11a51c9ebb09 2142 return (((uint16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 2143 }
mducrocq 0:11a51c9ebb09 2144 /** Read double word (4 bytes) from external sensor data registers.
mducrocq 0:11a51c9ebb09 2145 * @param position Starting position (0-20)
mducrocq 0:11a51c9ebb09 2146 * @return Double word read from registers
mducrocq 0:11a51c9ebb09 2147 * @see getExternalSensorByte()
mducrocq 0:11a51c9ebb09 2148 */
mducrocq 0:11a51c9ebb09 2149 uint32_t MPU6050::getExternalSensorDWord(int position)
mducrocq 0:11a51c9ebb09 2150 {
mducrocq 0:11a51c9ebb09 2151 i2Cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 4, buffer);
mducrocq 0:11a51c9ebb09 2152 return (((uint32_t)buffer[0]) << 24) | (((uint32_t)buffer[1]) << 16) | (((uint16_t)buffer[2]) << 8) | buffer[3];
mducrocq 0:11a51c9ebb09 2153 }
mducrocq 0:11a51c9ebb09 2154
mducrocq 0:11a51c9ebb09 2155 // MOT_DETECT_STATUS register
mducrocq 0:11a51c9ebb09 2156
mducrocq 0:11a51c9ebb09 2157 /** Get X-axis negative motion detection interrupt status.
mducrocq 0:11a51c9ebb09 2158 * @return Motion detection status
mducrocq 0:11a51c9ebb09 2159 * @see MPU6050_RA_MOT_DETECT_STATUS
mducrocq 0:11a51c9ebb09 2160 * @see MPU6050_MOTION_MOT_XNEG_BIT
mducrocq 0:11a51c9ebb09 2161 */
mducrocq 0:11a51c9ebb09 2162 bool MPU6050::getXNegMotionDetected()
mducrocq 0:11a51c9ebb09 2163 {
mducrocq 0:11a51c9ebb09 2164 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XNEG_BIT, buffer);
mducrocq 0:11a51c9ebb09 2165 return buffer[0];
mducrocq 0:11a51c9ebb09 2166 }
mducrocq 0:11a51c9ebb09 2167 /** Get X-axis positive motion detection interrupt status.
mducrocq 0:11a51c9ebb09 2168 * @return Motion detection status
mducrocq 0:11a51c9ebb09 2169 * @see MPU6050_RA_MOT_DETECT_STATUS
mducrocq 0:11a51c9ebb09 2170 * @see MPU6050_MOTION_MOT_XPOS_BIT
mducrocq 0:11a51c9ebb09 2171 */
mducrocq 0:11a51c9ebb09 2172 bool MPU6050::getXPosMotionDetected()
mducrocq 0:11a51c9ebb09 2173 {
mducrocq 0:11a51c9ebb09 2174 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XPOS_BIT, buffer);
mducrocq 0:11a51c9ebb09 2175 return buffer[0];
mducrocq 0:11a51c9ebb09 2176 }
mducrocq 0:11a51c9ebb09 2177 /** Get Y-axis negative motion detection interrupt status.
mducrocq 0:11a51c9ebb09 2178 * @return Motion detection status
mducrocq 0:11a51c9ebb09 2179 * @see MPU6050_RA_MOT_DETECT_STATUS
mducrocq 0:11a51c9ebb09 2180 * @see MPU6050_MOTION_MOT_YNEG_BIT
mducrocq 0:11a51c9ebb09 2181 */
mducrocq 0:11a51c9ebb09 2182 bool MPU6050::getYNegMotionDetected()
mducrocq 0:11a51c9ebb09 2183 {
mducrocq 0:11a51c9ebb09 2184 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YNEG_BIT, buffer);
mducrocq 0:11a51c9ebb09 2185 return buffer[0];
mducrocq 0:11a51c9ebb09 2186 }
mducrocq 0:11a51c9ebb09 2187 /** Get Y-axis positive motion detection interrupt status.
mducrocq 0:11a51c9ebb09 2188 * @return Motion detection status
mducrocq 0:11a51c9ebb09 2189 * @see MPU6050_RA_MOT_DETECT_STATUS
mducrocq 0:11a51c9ebb09 2190 * @see MPU6050_MOTION_MOT_YPOS_BIT
mducrocq 0:11a51c9ebb09 2191 */
mducrocq 0:11a51c9ebb09 2192 bool MPU6050::getYPosMotionDetected()
mducrocq 0:11a51c9ebb09 2193 {
mducrocq 0:11a51c9ebb09 2194 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YPOS_BIT, buffer);
mducrocq 0:11a51c9ebb09 2195 return buffer[0];
mducrocq 0:11a51c9ebb09 2196 }
mducrocq 0:11a51c9ebb09 2197 /** Get Z-axis negative motion detection interrupt status.
mducrocq 0:11a51c9ebb09 2198 * @return Motion detection status
mducrocq 0:11a51c9ebb09 2199 * @see MPU6050_RA_MOT_DETECT_STATUS
mducrocq 0:11a51c9ebb09 2200 * @see MPU6050_MOTION_MOT_ZNEG_BIT
mducrocq 0:11a51c9ebb09 2201 */
mducrocq 0:11a51c9ebb09 2202 bool MPU6050::getZNegMotionDetected()
mducrocq 0:11a51c9ebb09 2203 {
mducrocq 0:11a51c9ebb09 2204 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZNEG_BIT, buffer);
mducrocq 0:11a51c9ebb09 2205 return buffer[0];
mducrocq 0:11a51c9ebb09 2206 }
mducrocq 0:11a51c9ebb09 2207 /** Get Z-axis positive motion detection interrupt status.
mducrocq 0:11a51c9ebb09 2208 * @return Motion detection status
mducrocq 0:11a51c9ebb09 2209 * @see MPU6050_RA_MOT_DETECT_STATUS
mducrocq 0:11a51c9ebb09 2210 * @see MPU6050_MOTION_MOT_ZPOS_BIT
mducrocq 0:11a51c9ebb09 2211 */
mducrocq 0:11a51c9ebb09 2212 bool MPU6050::getZPosMotionDetected()
mducrocq 0:11a51c9ebb09 2213 {
mducrocq 0:11a51c9ebb09 2214 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZPOS_BIT, buffer);
mducrocq 0:11a51c9ebb09 2215 return buffer[0];
mducrocq 0:11a51c9ebb09 2216 }
mducrocq 0:11a51c9ebb09 2217 /** Get zero motion detection interrupt status.
mducrocq 0:11a51c9ebb09 2218 * @return Motion detection status
mducrocq 0:11a51c9ebb09 2219 * @see MPU6050_RA_MOT_DETECT_STATUS
mducrocq 0:11a51c9ebb09 2220 * @see MPU6050_MOTION_MOT_ZRMOT_BIT
mducrocq 0:11a51c9ebb09 2221 */
mducrocq 0:11a51c9ebb09 2222 bool MPU6050::getZeroMotionDetected()
mducrocq 0:11a51c9ebb09 2223 {
mducrocq 0:11a51c9ebb09 2224 i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZRMOT_BIT, buffer);
mducrocq 0:11a51c9ebb09 2225 return buffer[0];
mducrocq 0:11a51c9ebb09 2226 }
mducrocq 0:11a51c9ebb09 2227
mducrocq 0:11a51c9ebb09 2228 // I2C_SLV*_DO register
mducrocq 0:11a51c9ebb09 2229
mducrocq 0:11a51c9ebb09 2230 /** Write byte to Data Output container for specified slave.
mducrocq 0:11a51c9ebb09 2231 * This register holds the output data written into Slave when Slave is set to
mducrocq 0:11a51c9ebb09 2232 * write mode. For further information regarding Slave control, please
mducrocq 0:11a51c9ebb09 2233 * refer to Registers 37 to 39 and immediately following.
mducrocq 0:11a51c9ebb09 2234 * @param num Slave number (0-3)
mducrocq 0:11a51c9ebb09 2235 * @param data Byte to write
mducrocq 0:11a51c9ebb09 2236 * @see MPU6050_RA_I2C_SLV0_DO
mducrocq 0:11a51c9ebb09 2237 */
mducrocq 0:11a51c9ebb09 2238 void MPU6050::setSlaveOutputByte(uint8_t num, uint8_t data)
mducrocq 0:11a51c9ebb09 2239 {
mducrocq 0:11a51c9ebb09 2240 if (num > 3) return;
mducrocq 0:11a51c9ebb09 2241 i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_DO + num, data);
mducrocq 0:11a51c9ebb09 2242 }
mducrocq 0:11a51c9ebb09 2243
mducrocq 0:11a51c9ebb09 2244 // I2C_MST_DELAY_CTRL register
mducrocq 0:11a51c9ebb09 2245
mducrocq 0:11a51c9ebb09 2246 /** Get external data shadow delay enabled status.
mducrocq 0:11a51c9ebb09 2247 * This register is used to specify the timing of external sensor data
mducrocq 0:11a51c9ebb09 2248 * shadowing. When DELAY_ES_SHADOW is set to 1, shadowing of external
mducrocq 0:11a51c9ebb09 2249 * sensor data is delayed until all data has been received.
mducrocq 0:11a51c9ebb09 2250 * @return Current external data shadow delay enabled status.
mducrocq 0:11a51c9ebb09 2251 * @see MPU6050_RA_I2C_MST_DELAY_CTRL
mducrocq 0:11a51c9ebb09 2252 * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT
mducrocq 0:11a51c9ebb09 2253 */
mducrocq 0:11a51c9ebb09 2254 bool MPU6050::getExternalShadowDelayEnabled()
mducrocq 0:11a51c9ebb09 2255 {
mducrocq 0:11a51c9ebb09 2256 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, buffer);
mducrocq 0:11a51c9ebb09 2257 return buffer[0];
mducrocq 0:11a51c9ebb09 2258 }
mducrocq 0:11a51c9ebb09 2259 /** Set external data shadow delay enabled status.
mducrocq 0:11a51c9ebb09 2260 * @param enabled New external data shadow delay enabled status.
mducrocq 0:11a51c9ebb09 2261 * @see getExternalShadowDelayEnabled()
mducrocq 0:11a51c9ebb09 2262 * @see MPU6050_RA_I2C_MST_DELAY_CTRL
mducrocq 0:11a51c9ebb09 2263 * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT
mducrocq 0:11a51c9ebb09 2264 */
mducrocq 0:11a51c9ebb09 2265 void MPU6050::setExternalShadowDelayEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2266 {
mducrocq 0:11a51c9ebb09 2267 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, enabled);
mducrocq 0:11a51c9ebb09 2268 }
mducrocq 0:11a51c9ebb09 2269 /** Get slave delay enabled status.
mducrocq 0:11a51c9ebb09 2270 * When a particular slave delay is enabled, the rate of access for the that
mducrocq 0:11a51c9ebb09 2271 * slave device is reduced. When a slave's access rate is decreased relative to
mducrocq 0:11a51c9ebb09 2272 * the Sample Rate, the slave is accessed every:
mducrocq 0:11a51c9ebb09 2273 *
mducrocq 0:11a51c9ebb09 2274 * 1 / (1 + I2C_MST_DLY) Samples
mducrocq 0:11a51c9ebb09 2275 *
mducrocq 0:11a51c9ebb09 2276 * This base Sample Rate in turn is determined by SMPLRT_DIV (register * 25)
mducrocq 0:11a51c9ebb09 2277 * and DLPF_CFG (register 26).
mducrocq 0:11a51c9ebb09 2278 *
mducrocq 0:11a51c9ebb09 2279 * For further information regarding I2C_MST_DLY, please refer to register 52.
mducrocq 0:11a51c9ebb09 2280 * For further information regarding the Sample Rate, please refer to register 25.
mducrocq 0:11a51c9ebb09 2281 *
mducrocq 0:11a51c9ebb09 2282 * @param num Slave number (0-4)
mducrocq 0:11a51c9ebb09 2283 * @return Current slave delay enabled status.
mducrocq 0:11a51c9ebb09 2284 * @see MPU6050_RA_I2C_MST_DELAY_CTRL
mducrocq 0:11a51c9ebb09 2285 * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT
mducrocq 0:11a51c9ebb09 2286 */
mducrocq 0:11a51c9ebb09 2287 bool MPU6050::getSlaveDelayEnabled(uint8_t num)
mducrocq 0:11a51c9ebb09 2288 {
mducrocq 0:11a51c9ebb09 2289 // MPU6050_DELAYCTRL_I2C_SLV4_DLY_EN_BIT is 4, SLV3 is 3, etc.
mducrocq 0:11a51c9ebb09 2290 if (num > 4) return 0;
mducrocq 0:11a51c9ebb09 2291 i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, buffer);
mducrocq 0:11a51c9ebb09 2292 return buffer[0];
mducrocq 0:11a51c9ebb09 2293 }
mducrocq 0:11a51c9ebb09 2294 /** Set slave delay enabled status.
mducrocq 0:11a51c9ebb09 2295 * @param num Slave number (0-4)
mducrocq 0:11a51c9ebb09 2296 * @param enabled New slave delay enabled status.
mducrocq 0:11a51c9ebb09 2297 * @see MPU6050_RA_I2C_MST_DELAY_CTRL
mducrocq 0:11a51c9ebb09 2298 * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT
mducrocq 0:11a51c9ebb09 2299 */
mducrocq 0:11a51c9ebb09 2300 void MPU6050::setSlaveDelayEnabled(uint8_t num, bool enabled)
mducrocq 0:11a51c9ebb09 2301 {
mducrocq 0:11a51c9ebb09 2302 i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, enabled);
mducrocq 0:11a51c9ebb09 2303 }
mducrocq 0:11a51c9ebb09 2304
mducrocq 0:11a51c9ebb09 2305 // SIGNAL_PATH_RESET register
mducrocq 0:11a51c9ebb09 2306
mducrocq 0:11a51c9ebb09 2307 /** Reset gyroscope signal path.
mducrocq 0:11a51c9ebb09 2308 * The reset will revert the signal path analog to digital converters and
mducrocq 0:11a51c9ebb09 2309 * filters to their power up configurations.
mducrocq 0:11a51c9ebb09 2310 * @see MPU6050_RA_SIGNAL_PATH_RESET
mducrocq 0:11a51c9ebb09 2311 * @see MPU6050_PATHRESET_GYRO_RESET_BIT
mducrocq 0:11a51c9ebb09 2312 */
mducrocq 0:11a51c9ebb09 2313 void MPU6050::resetGyroscopePath()
mducrocq 0:11a51c9ebb09 2314 {
mducrocq 0:11a51c9ebb09 2315 i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_GYRO_RESET_BIT, true);
mducrocq 0:11a51c9ebb09 2316 }
mducrocq 0:11a51c9ebb09 2317 /** Reset accelerometer signal path.
mducrocq 0:11a51c9ebb09 2318 * The reset will revert the signal path analog to digital converters and
mducrocq 0:11a51c9ebb09 2319 * filters to their power up configurations.
mducrocq 0:11a51c9ebb09 2320 * @see MPU6050_RA_SIGNAL_PATH_RESET
mducrocq 0:11a51c9ebb09 2321 * @see MPU6050_PATHRESET_ACCEL_RESET_BIT
mducrocq 0:11a51c9ebb09 2322 */
mducrocq 0:11a51c9ebb09 2323 void MPU6050::resetAccelerometerPath()
mducrocq 0:11a51c9ebb09 2324 {
mducrocq 0:11a51c9ebb09 2325 i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_ACCEL_RESET_BIT, true);
mducrocq 0:11a51c9ebb09 2326 }
mducrocq 0:11a51c9ebb09 2327 /** Reset temperature sensor signal path.
mducrocq 0:11a51c9ebb09 2328 * The reset will revert the signal path analog to digital converters and
mducrocq 0:11a51c9ebb09 2329 * filters to their power up configurations.
mducrocq 0:11a51c9ebb09 2330 * @see MPU6050_RA_SIGNAL_PATH_RESET
mducrocq 0:11a51c9ebb09 2331 * @see MPU6050_PATHRESET_TEMP_RESET_BIT
mducrocq 0:11a51c9ebb09 2332 */
mducrocq 0:11a51c9ebb09 2333 void MPU6050::resetTemperaturePath()
mducrocq 0:11a51c9ebb09 2334 {
mducrocq 0:11a51c9ebb09 2335 i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_TEMP_RESET_BIT, true);
mducrocq 0:11a51c9ebb09 2336 }
mducrocq 0:11a51c9ebb09 2337
mducrocq 0:11a51c9ebb09 2338 // MOT_DETECT_CTRL register
mducrocq 0:11a51c9ebb09 2339
mducrocq 0:11a51c9ebb09 2340 /** Get accelerometer power-on delay.
mducrocq 0:11a51c9ebb09 2341 * The accelerometer data path provides samples to the sensor registers, Motion
mducrocq 0:11a51c9ebb09 2342 * detection, Zero Motion detection, and Free Fall detection modules. The
mducrocq 0:11a51c9ebb09 2343 * signal path contains filters which must be flushed on wake-up with new
mducrocq 0:11a51c9ebb09 2344 * samples before the detection modules begin operations. The default wake-up
mducrocq 0:11a51c9ebb09 2345 * delay, of 4ms can be lengthened by up to 3ms. This additional delay is
mducrocq 0:11a51c9ebb09 2346 * specified in ACCEL_ON_DELAY in units of 1 LSB = 1 ms. The user may select
mducrocq 0:11a51c9ebb09 2347 * any value above zero unless instructed otherwise by InvenSense. Please refer
mducrocq 0:11a51c9ebb09 2348 * to Section 8 of the MPU-6000/MPU-6050 Product Specification document for
mducrocq 0:11a51c9ebb09 2349 * further information regarding the detection modules.
mducrocq 0:11a51c9ebb09 2350 * @return Current accelerometer power-on delay
mducrocq 0:11a51c9ebb09 2351 * @see MPU6050_RA_MOT_DETECT_CTRL
mducrocq 0:11a51c9ebb09 2352 * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT
mducrocq 0:11a51c9ebb09 2353 */
mducrocq 0:11a51c9ebb09 2354 uint8_t MPU6050::getAccelerometerPowerOnDelay()
mducrocq 0:11a51c9ebb09 2355 {
mducrocq 0:11a51c9ebb09 2356 i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 2357 return buffer[0];
mducrocq 0:11a51c9ebb09 2358 }
mducrocq 0:11a51c9ebb09 2359 /** Set accelerometer power-on delay.
mducrocq 0:11a51c9ebb09 2360 * @param delay New accelerometer power-on delay (0-3)
mducrocq 0:11a51c9ebb09 2361 * @see getAccelerometerPowerOnDelay()
mducrocq 0:11a51c9ebb09 2362 * @see MPU6050_RA_MOT_DETECT_CTRL
mducrocq 0:11a51c9ebb09 2363 * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT
mducrocq 0:11a51c9ebb09 2364 */
mducrocq 0:11a51c9ebb09 2365 void MPU6050::setAccelerometerPowerOnDelay(uint8_t delay)
mducrocq 0:11a51c9ebb09 2366 {
mducrocq 0:11a51c9ebb09 2367 i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, delay);
mducrocq 0:11a51c9ebb09 2368 }
mducrocq 0:11a51c9ebb09 2369 /** Get Free Fall detection counter decrement configuration.
mducrocq 0:11a51c9ebb09 2370 * Detection is registered by the Free Fall detection module after accelerometer
mducrocq 0:11a51c9ebb09 2371 * measurements meet their respective threshold conditions over a specified
mducrocq 0:11a51c9ebb09 2372 * number of samples. When the threshold conditions are met, the corresponding
mducrocq 0:11a51c9ebb09 2373 * detection counter increments by 1. The user may control the rate at which the
mducrocq 0:11a51c9ebb09 2374 * detection counter decrements when the threshold condition is not met by
mducrocq 0:11a51c9ebb09 2375 * configuring FF_COUNT. The decrement rate can be set according to the
mducrocq 0:11a51c9ebb09 2376 * following table:
mducrocq 0:11a51c9ebb09 2377 *
mducrocq 0:11a51c9ebb09 2378 * <pre>
mducrocq 0:11a51c9ebb09 2379 * FF_COUNT | Counter Decrement
mducrocq 0:11a51c9ebb09 2380 * ---------+------------------
mducrocq 0:11a51c9ebb09 2381 * 0 | Reset
mducrocq 0:11a51c9ebb09 2382 * 1 | 1
mducrocq 0:11a51c9ebb09 2383 * 2 | 2
mducrocq 0:11a51c9ebb09 2384 * 3 | 4
mducrocq 0:11a51c9ebb09 2385 * </pre>
mducrocq 0:11a51c9ebb09 2386 *
mducrocq 0:11a51c9ebb09 2387 * When FF_COUNT is configured to 0 (reset), any non-qualifying sample will
mducrocq 0:11a51c9ebb09 2388 * reset the counter to 0. For further information on Free Fall detection,
mducrocq 0:11a51c9ebb09 2389 * please refer to Registers 29 to 32.
mducrocq 0:11a51c9ebb09 2390 *
mducrocq 0:11a51c9ebb09 2391 * @return Current decrement configuration
mducrocq 0:11a51c9ebb09 2392 * @see MPU6050_RA_MOT_DETECT_CTRL
mducrocq 0:11a51c9ebb09 2393 * @see MPU6050_DETECT_FF_COUNT_BIT
mducrocq 0:11a51c9ebb09 2394 */
mducrocq 0:11a51c9ebb09 2395 uint8_t MPU6050::getFreefallDetectionCounterDecrement()
mducrocq 0:11a51c9ebb09 2396 {
mducrocq 0:11a51c9ebb09 2397 i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 2398 return buffer[0];
mducrocq 0:11a51c9ebb09 2399 }
mducrocq 0:11a51c9ebb09 2400 /** Set Free Fall detection counter decrement configuration.
mducrocq 0:11a51c9ebb09 2401 * @param decrement New decrement configuration value
mducrocq 0:11a51c9ebb09 2402 * @see getFreefallDetectionCounterDecrement()
mducrocq 0:11a51c9ebb09 2403 * @see MPU6050_RA_MOT_DETECT_CTRL
mducrocq 0:11a51c9ebb09 2404 * @see MPU6050_DETECT_FF_COUNT_BIT
mducrocq 0:11a51c9ebb09 2405 */
mducrocq 0:11a51c9ebb09 2406 void MPU6050::setFreefallDetectionCounterDecrement(uint8_t decrement)
mducrocq 0:11a51c9ebb09 2407 {
mducrocq 0:11a51c9ebb09 2408 i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, decrement);
mducrocq 0:11a51c9ebb09 2409 }
mducrocq 0:11a51c9ebb09 2410 /** Get Motion detection counter decrement configuration.
mducrocq 0:11a51c9ebb09 2411 * Detection is registered by the Motion detection module after accelerometer
mducrocq 0:11a51c9ebb09 2412 * measurements meet their respective threshold conditions over a specified
mducrocq 0:11a51c9ebb09 2413 * number of samples. When the threshold conditions are met, the corresponding
mducrocq 0:11a51c9ebb09 2414 * detection counter increments by 1. The user may control the rate at which the
mducrocq 0:11a51c9ebb09 2415 * detection counter decrements when the threshold condition is not met by
mducrocq 0:11a51c9ebb09 2416 * configuring MOT_COUNT. The decrement rate can be set according to the
mducrocq 0:11a51c9ebb09 2417 * following table:
mducrocq 0:11a51c9ebb09 2418 *
mducrocq 0:11a51c9ebb09 2419 * <pre>
mducrocq 0:11a51c9ebb09 2420 * MOT_COUNT | Counter Decrement
mducrocq 0:11a51c9ebb09 2421 * ----------+------------------
mducrocq 0:11a51c9ebb09 2422 * 0 | Reset
mducrocq 0:11a51c9ebb09 2423 * 1 | 1
mducrocq 0:11a51c9ebb09 2424 * 2 | 2
mducrocq 0:11a51c9ebb09 2425 * 3 | 4
mducrocq 0:11a51c9ebb09 2426 * </pre>
mducrocq 0:11a51c9ebb09 2427 *
mducrocq 0:11a51c9ebb09 2428 * When MOT_COUNT is configured to 0 (reset), any non-qualifying sample will
mducrocq 0:11a51c9ebb09 2429 * reset the counter to 0. For further information on Motion detection,
mducrocq 0:11a51c9ebb09 2430 * please refer to Registers 29 to 32.
mducrocq 0:11a51c9ebb09 2431 *
mducrocq 0:11a51c9ebb09 2432 */
mducrocq 0:11a51c9ebb09 2433 uint8_t MPU6050::getMotionDetectionCounterDecrement()
mducrocq 0:11a51c9ebb09 2434 {
mducrocq 0:11a51c9ebb09 2435 i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 2436 return buffer[0];
mducrocq 0:11a51c9ebb09 2437 }
mducrocq 0:11a51c9ebb09 2438 /** Set Motion detection counter decrement configuration.
mducrocq 0:11a51c9ebb09 2439 * @param decrement New decrement configuration value
mducrocq 0:11a51c9ebb09 2440 * @see getMotionDetectionCounterDecrement()
mducrocq 0:11a51c9ebb09 2441 * @see MPU6050_RA_MOT_DETECT_CTRL
mducrocq 0:11a51c9ebb09 2442 * @see MPU6050_DETECT_MOT_COUNT_BIT
mducrocq 0:11a51c9ebb09 2443 */
mducrocq 0:11a51c9ebb09 2444 void MPU6050::setMotionDetectionCounterDecrement(uint8_t decrement)
mducrocq 0:11a51c9ebb09 2445 {
mducrocq 0:11a51c9ebb09 2446 i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, decrement);
mducrocq 0:11a51c9ebb09 2447 }
mducrocq 0:11a51c9ebb09 2448
mducrocq 0:11a51c9ebb09 2449 // USER_CTRL register
mducrocq 0:11a51c9ebb09 2450
mducrocq 0:11a51c9ebb09 2451 /** Get FIFO enabled status.
mducrocq 0:11a51c9ebb09 2452 * When this bit is set to 0, the FIFO buffer is disabled. The FIFO buffer
mducrocq 0:11a51c9ebb09 2453 * cannot be written to or read from while disabled. The FIFO buffer's state
mducrocq 0:11a51c9ebb09 2454 * does not change unless the MPU-60X0 is power cycled.
mducrocq 0:11a51c9ebb09 2455 * @return Current FIFO enabled status
mducrocq 0:11a51c9ebb09 2456 * @see MPU6050_RA_USER_CTRL
mducrocq 0:11a51c9ebb09 2457 * @see MPU6050_USERCTRL_FIFO_EN_BIT
mducrocq 0:11a51c9ebb09 2458 */
mducrocq 0:11a51c9ebb09 2459 bool MPU6050::getFIFOEnabled()
mducrocq 0:11a51c9ebb09 2460 {
mducrocq 0:11a51c9ebb09 2461 i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 2462 return buffer[0];
mducrocq 0:11a51c9ebb09 2463 }
mducrocq 0:11a51c9ebb09 2464 /** Set FIFO enabled status.
mducrocq 0:11a51c9ebb09 2465 * @param enabled New FIFO enabled status
mducrocq 0:11a51c9ebb09 2466 * @see getFIFOEnabled()
mducrocq 0:11a51c9ebb09 2467 * @see MPU6050_RA_USER_CTRL
mducrocq 0:11a51c9ebb09 2468 * @see MPU6050_USERCTRL_FIFO_EN_BIT
mducrocq 0:11a51c9ebb09 2469 */
mducrocq 0:11a51c9ebb09 2470 void MPU6050::setFIFOEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2471 {
mducrocq 0:11a51c9ebb09 2472 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 2473 }
mducrocq 0:11a51c9ebb09 2474 /** Get I2C Master Mode enabled status.
mducrocq 0:11a51c9ebb09 2475 * When this mode is enabled, the MPU-60X0 acts as the I2C Master to the
mducrocq 0:11a51c9ebb09 2476 * external sensor slave devices on the auxiliary I2C bus. When this bit is
mducrocq 0:11a51c9ebb09 2477 * cleared to 0, the auxiliary I2C bus lines (AUX_DA and AUX_CL) are logically
mducrocq 0:11a51c9ebb09 2478 * driven by the primary I2C bus (SDA and SCL). This is a precondition to
mducrocq 0:11a51c9ebb09 2479 * enabling Bypass Mode. For further information regarding Bypass Mode, please
mducrocq 0:11a51c9ebb09 2480 * refer to Register 55.
mducrocq 0:11a51c9ebb09 2481 * @return Current I2C Master Mode enabled status
mducrocq 0:11a51c9ebb09 2482 * @see MPU6050_RA_USER_CTRL
mducrocq 0:11a51c9ebb09 2483 * @see MPU6050_USERCTRL_I2C_MST_EN_BIT
mducrocq 0:11a51c9ebb09 2484 */
mducrocq 0:11a51c9ebb09 2485 bool MPU6050::getI2CMasterModeEnabled()
mducrocq 0:11a51c9ebb09 2486 {
mducrocq 0:11a51c9ebb09 2487 i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 2488 return buffer[0];
mducrocq 0:11a51c9ebb09 2489 }
mducrocq 0:11a51c9ebb09 2490 /** Set I2C Master Mode enabled status.
mducrocq 0:11a51c9ebb09 2491 * @param enabled New I2C Master Mode enabled status
mducrocq 0:11a51c9ebb09 2492 * @see getI2CMasterModeEnabled()
mducrocq 0:11a51c9ebb09 2493 * @see MPU6050_RA_USER_CTRL
mducrocq 0:11a51c9ebb09 2494 * @see MPU6050_USERCTRL_I2C_MST_EN_BIT
mducrocq 0:11a51c9ebb09 2495 */
mducrocq 0:11a51c9ebb09 2496 void MPU6050::setI2CMasterModeEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2497 {
mducrocq 0:11a51c9ebb09 2498 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 2499 }
mducrocq 0:11a51c9ebb09 2500 /** Switch from I2C to SPI mode (MPU-6000 only)
mducrocq 0:11a51c9ebb09 2501 * If this is set, the primary SPI interface will be enabled in place of the
mducrocq 0:11a51c9ebb09 2502 * disabled primary I2C interface.
mducrocq 0:11a51c9ebb09 2503 */
mducrocq 0:11a51c9ebb09 2504 void MPU6050::switchSPIEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2505 {
mducrocq 0:11a51c9ebb09 2506 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_IF_DIS_BIT, enabled);
mducrocq 0:11a51c9ebb09 2507 }
mducrocq 0:11a51c9ebb09 2508 /** Reset the FIFO.
mducrocq 0:11a51c9ebb09 2509 * This bit resets the FIFO buffer when set to 1 while FIFO_EN equals 0. This
mducrocq 0:11a51c9ebb09 2510 * bit automatically clears to 0 after the reset has been triggered.
mducrocq 0:11a51c9ebb09 2511 * @see MPU6050_RA_USER_CTRL
mducrocq 0:11a51c9ebb09 2512 * @see MPU6050_USERCTRL_FIFO_RESET_BIT
mducrocq 0:11a51c9ebb09 2513 */
mducrocq 0:11a51c9ebb09 2514 void MPU6050::resetFIFO()
mducrocq 0:11a51c9ebb09 2515 {
mducrocq 0:11a51c9ebb09 2516 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_RESET_BIT, true);
mducrocq 0:11a51c9ebb09 2517 }
mducrocq 0:11a51c9ebb09 2518 /** Reset the I2C Master.
mducrocq 0:11a51c9ebb09 2519 * This bit resets the I2C Master when set to 1 while I2C_MST_EN equals 0.
mducrocq 0:11a51c9ebb09 2520 * This bit automatically clears to 0 after the reset has been triggered.
mducrocq 0:11a51c9ebb09 2521 * @see MPU6050_RA_USER_CTRL
mducrocq 0:11a51c9ebb09 2522 * @see MPU6050_USERCTRL_I2C_MST_RESET_BIT
mducrocq 0:11a51c9ebb09 2523 */
mducrocq 0:11a51c9ebb09 2524 void MPU6050::resetI2CMaster()
mducrocq 0:11a51c9ebb09 2525 {
mducrocq 0:11a51c9ebb09 2526 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_RESET_BIT, true);
mducrocq 0:11a51c9ebb09 2527 }
mducrocq 0:11a51c9ebb09 2528 /** Reset all sensor registers and signal paths.
mducrocq 0:11a51c9ebb09 2529 * When set to 1, this bit resets the signal paths for all sensors (gyroscopes,
mducrocq 0:11a51c9ebb09 2530 * accelerometers, and temperature sensor). This operation will also clear the
mducrocq 0:11a51c9ebb09 2531 * sensor registers. This bit automatically clears to 0 after the reset has been
mducrocq 0:11a51c9ebb09 2532 * triggered.
mducrocq 0:11a51c9ebb09 2533 *
mducrocq 0:11a51c9ebb09 2534 * When resetting only the signal path (and not the sensor registers), please
mducrocq 0:11a51c9ebb09 2535 * use Register 104, SIGNAL_PATH_RESET.
mducrocq 0:11a51c9ebb09 2536 *
mducrocq 0:11a51c9ebb09 2537 * @see MPU6050_RA_USER_CTRL
mducrocq 0:11a51c9ebb09 2538 * @see MPU6050_USERCTRL_SIG_COND_RESET_BIT
mducrocq 0:11a51c9ebb09 2539 */
mducrocq 0:11a51c9ebb09 2540 void MPU6050::resetSensors()
mducrocq 0:11a51c9ebb09 2541 {
mducrocq 0:11a51c9ebb09 2542 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_SIG_COND_RESET_BIT, true);
mducrocq 0:11a51c9ebb09 2543 }
mducrocq 0:11a51c9ebb09 2544
mducrocq 0:11a51c9ebb09 2545 // PWR_MGMT_1 register
mducrocq 0:11a51c9ebb09 2546
mducrocq 0:11a51c9ebb09 2547 /** Trigger a full device reset.
mducrocq 0:11a51c9ebb09 2548 * A small delay of ~50ms may be desirable after triggering a reset.
mducrocq 0:11a51c9ebb09 2549 * @see MPU6050_RA_PWR_MGMT_1
mducrocq 0:11a51c9ebb09 2550 * @see MPU6050_PWR1_DEVICE_RESET_BIT
mducrocq 0:11a51c9ebb09 2551 */
mducrocq 0:11a51c9ebb09 2552 void MPU6050::reset()
mducrocq 0:11a51c9ebb09 2553 {
mducrocq 0:11a51c9ebb09 2554 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_DEVICE_RESET_BIT, true);
mducrocq 0:11a51c9ebb09 2555 }
mducrocq 0:11a51c9ebb09 2556 /** Get sleep mode status.
mducrocq 0:11a51c9ebb09 2557 * Setting the SLEEP bit in the register puts the device into very low power
mducrocq 0:11a51c9ebb09 2558 * sleep mode. In this mode, only the serial interface and internal registers
mducrocq 0:11a51c9ebb09 2559 * remain active, allowing for a very low standby current. Clearing this bit
mducrocq 0:11a51c9ebb09 2560 * puts the device back into normal mode. To save power, the individual standby
mducrocq 0:11a51c9ebb09 2561 * selections for each of the gyros should be used if any gyro axis is not used
mducrocq 0:11a51c9ebb09 2562 * by the application.
mducrocq 0:11a51c9ebb09 2563 * @return Current sleep mode enabled status
mducrocq 0:11a51c9ebb09 2564 * @see MPU6050_RA_PWR_MGMT_1
mducrocq 0:11a51c9ebb09 2565 * @see MPU6050_PWR1_SLEEP_BIT
mducrocq 0:11a51c9ebb09 2566 */
mducrocq 0:11a51c9ebb09 2567 bool MPU6050::getSleepEnabled()
mducrocq 0:11a51c9ebb09 2568 {
mducrocq 0:11a51c9ebb09 2569 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, buffer);
mducrocq 0:11a51c9ebb09 2570 return buffer[0];
mducrocq 0:11a51c9ebb09 2571 }
mducrocq 0:11a51c9ebb09 2572 /** Set sleep mode status.
mducrocq 0:11a51c9ebb09 2573 * @param enabled New sleep mode enabled status
mducrocq 0:11a51c9ebb09 2574 * @see getSleepEnabled()
mducrocq 0:11a51c9ebb09 2575 * @see MPU6050_RA_PWR_MGMT_1
mducrocq 0:11a51c9ebb09 2576 * @see MPU6050_PWR1_SLEEP_BIT
mducrocq 0:11a51c9ebb09 2577 */
mducrocq 0:11a51c9ebb09 2578 void MPU6050::setSleepEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2579 {
mducrocq 0:11a51c9ebb09 2580 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, enabled);
mducrocq 0:11a51c9ebb09 2581 }
mducrocq 0:11a51c9ebb09 2582 /** Get wake cycle enabled status.
mducrocq 0:11a51c9ebb09 2583 * When this bit is set to 1 and SLEEP is disabled, the MPU-60X0 will cycle
mducrocq 0:11a51c9ebb09 2584 * between sleep mode and waking up to take a single sample of data from active
mducrocq 0:11a51c9ebb09 2585 * sensors at a rate determined by LP_WAKE_CTRL (register 108).
mducrocq 0:11a51c9ebb09 2586 * @return Current sleep mode enabled status
mducrocq 0:11a51c9ebb09 2587 * @see MPU6050_RA_PWR_MGMT_1
mducrocq 0:11a51c9ebb09 2588 * @see MPU6050_PWR1_CYCLE_BIT
mducrocq 0:11a51c9ebb09 2589 */
mducrocq 0:11a51c9ebb09 2590 bool MPU6050::getWakeCycleEnabled()
mducrocq 0:11a51c9ebb09 2591 {
mducrocq 0:11a51c9ebb09 2592 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, buffer);
mducrocq 0:11a51c9ebb09 2593 return buffer[0];
mducrocq 0:11a51c9ebb09 2594 }
mducrocq 0:11a51c9ebb09 2595 /** Set wake cycle enabled status.
mducrocq 0:11a51c9ebb09 2596 * @param enabled New sleep mode enabled status
mducrocq 0:11a51c9ebb09 2597 * @see getWakeCycleEnabled()
mducrocq 0:11a51c9ebb09 2598 * @see MPU6050_RA_PWR_MGMT_1
mducrocq 0:11a51c9ebb09 2599 * @see MPU6050_PWR1_CYCLE_BIT
mducrocq 0:11a51c9ebb09 2600 */
mducrocq 0:11a51c9ebb09 2601 void MPU6050::setWakeCycleEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2602 {
mducrocq 0:11a51c9ebb09 2603 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, enabled);
mducrocq 0:11a51c9ebb09 2604 }
mducrocq 0:11a51c9ebb09 2605 /** Get temperature sensor enabled status.
mducrocq 0:11a51c9ebb09 2606 * Control the usage of the internal temperature sensor.
mducrocq 0:11a51c9ebb09 2607 *
mducrocq 0:11a51c9ebb09 2608 * Note: this register stores the *disabled* value, but for consistency with the
mducrocq 0:11a51c9ebb09 2609 * rest of the code, the function is named and used with standard true/false
mducrocq 0:11a51c9ebb09 2610 * values to indicate whether the sensor is enabled or disabled, respectively.
mducrocq 0:11a51c9ebb09 2611 *
mducrocq 0:11a51c9ebb09 2612 * @return Current temperature sensor enabled status
mducrocq 0:11a51c9ebb09 2613 * @see MPU6050_RA_PWR_MGMT_1
mducrocq 0:11a51c9ebb09 2614 * @see MPU6050_PWR1_TEMP_DIS_BIT
mducrocq 0:11a51c9ebb09 2615 */
mducrocq 0:11a51c9ebb09 2616 bool MPU6050::getTempSensorEnabled()
mducrocq 0:11a51c9ebb09 2617 {
mducrocq 0:11a51c9ebb09 2618 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, buffer);
mducrocq 0:11a51c9ebb09 2619 return buffer[0] == 0; // 1 is actually disabled here
mducrocq 0:11a51c9ebb09 2620 }
mducrocq 0:11a51c9ebb09 2621 /** Set temperature sensor enabled status.
mducrocq 0:11a51c9ebb09 2622 * Note: this register stores the *disabled* value, but for consistency with the
mducrocq 0:11a51c9ebb09 2623 * rest of the code, the function is named and used with standard true/false
mducrocq 0:11a51c9ebb09 2624 * values to indicate whether the sensor is enabled or disabled, respectively.
mducrocq 0:11a51c9ebb09 2625 *
mducrocq 0:11a51c9ebb09 2626 * @param enabled New temperature sensor enabled status
mducrocq 0:11a51c9ebb09 2627 * @see getTempSensorEnabled()
mducrocq 0:11a51c9ebb09 2628 * @see MPU6050_RA_PWR_MGMT_1
mducrocq 0:11a51c9ebb09 2629 * @see MPU6050_PWR1_TEMP_DIS_BIT
mducrocq 0:11a51c9ebb09 2630 */
mducrocq 0:11a51c9ebb09 2631 void MPU6050::setTempSensorEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2632 {
mducrocq 0:11a51c9ebb09 2633 // 1 is actually disabled here
mducrocq 0:11a51c9ebb09 2634 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, !enabled);
mducrocq 0:11a51c9ebb09 2635 }
mducrocq 0:11a51c9ebb09 2636 /** Get clock source setting.
mducrocq 0:11a51c9ebb09 2637 * @return Current clock source setting
mducrocq 0:11a51c9ebb09 2638 * @see MPU6050_RA_PWR_MGMT_1
mducrocq 0:11a51c9ebb09 2639 * @see MPU6050_PWR1_CLKSEL_BIT
mducrocq 0:11a51c9ebb09 2640 * @see MPU6050_PWR1_CLKSEL_LENGTH
mducrocq 0:11a51c9ebb09 2641 */
mducrocq 0:11a51c9ebb09 2642 uint8_t MPU6050::getClockSource()
mducrocq 0:11a51c9ebb09 2643 {
mducrocq 0:11a51c9ebb09 2644 i2Cdev.readBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 2645 return buffer[0];
mducrocq 0:11a51c9ebb09 2646 }
mducrocq 0:11a51c9ebb09 2647 /** Set clock source setting.
mducrocq 0:11a51c9ebb09 2648 * An internal 8MHz oscillator, gyroscope based clock, or external sources can
mducrocq 0:11a51c9ebb09 2649 * be selected as the MPU-60X0 clock source. When the internal 8 MHz oscillator
mducrocq 0:11a51c9ebb09 2650 * or an external source is chosen as the clock source, the MPU-60X0 can operate
mducrocq 0:11a51c9ebb09 2651 * in low power modes with the gyroscopes disabled.
mducrocq 0:11a51c9ebb09 2652 *
mducrocq 0:11a51c9ebb09 2653 * Upon power up, the MPU-60X0 clock source defaults to the internal oscillator.
mducrocq 0:11a51c9ebb09 2654 * However, it is highly recommended that the device be configured to use one of
mducrocq 0:11a51c9ebb09 2655 * the gyroscopes (or an external clock source) as the clock reference for
mducrocq 0:11a51c9ebb09 2656 * improved stability. The clock source can be selected according to the following table:
mducrocq 0:11a51c9ebb09 2657 *
mducrocq 0:11a51c9ebb09 2658 * <pre>
mducrocq 0:11a51c9ebb09 2659 * CLK_SEL | Clock Source
mducrocq 0:11a51c9ebb09 2660 * --------+--------------------------------------
mducrocq 0:11a51c9ebb09 2661 * 0 | Internal oscillator
mducrocq 0:11a51c9ebb09 2662 * 1 | PLL with X Gyro reference
mducrocq 0:11a51c9ebb09 2663 * 2 | PLL with Y Gyro reference
mducrocq 0:11a51c9ebb09 2664 * 3 | PLL with Z Gyro reference
mducrocq 0:11a51c9ebb09 2665 * 4 | PLL with external 32.768kHz reference
mducrocq 0:11a51c9ebb09 2666 * 5 | PLL with external 19.2MHz reference
mducrocq 0:11a51c9ebb09 2667 * 6 | Reserved
mducrocq 0:11a51c9ebb09 2668 * 7 | Stops the clock and keeps the timing generator in reset
mducrocq 0:11a51c9ebb09 2669 * </pre>
mducrocq 0:11a51c9ebb09 2670 *
mducrocq 0:11a51c9ebb09 2671 * @param source New clock source setting
mducrocq 0:11a51c9ebb09 2672 * @see getClockSource()
mducrocq 0:11a51c9ebb09 2673 * @see MPU6050_RA_PWR_MGMT_1
mducrocq 0:11a51c9ebb09 2674 * @see MPU6050_PWR1_CLKSEL_BIT
mducrocq 0:11a51c9ebb09 2675 * @see MPU6050_PWR1_CLKSEL_LENGTH
mducrocq 0:11a51c9ebb09 2676 */
mducrocq 0:11a51c9ebb09 2677 void MPU6050::setClockSource(uint8_t source)
mducrocq 0:11a51c9ebb09 2678 {
mducrocq 0:11a51c9ebb09 2679 i2Cdev.writeBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, source);
mducrocq 0:11a51c9ebb09 2680 }
mducrocq 0:11a51c9ebb09 2681
mducrocq 0:11a51c9ebb09 2682 // PWR_MGMT_2 register
mducrocq 0:11a51c9ebb09 2683
mducrocq 0:11a51c9ebb09 2684 /** Get wake frequency in Accel-Only Low Power Mode.
mducrocq 0:11a51c9ebb09 2685 * The MPU-60X0 can be put into Accerlerometer Only Low Power Mode by setting
mducrocq 0:11a51c9ebb09 2686 * PWRSEL to 1 in the Power Management 1 register (Register 107). In this mode,
mducrocq 0:11a51c9ebb09 2687 * the device will power off all devices except for the primary I2C interface,
mducrocq 0:11a51c9ebb09 2688 * waking only the accelerometer at fixed intervals to take a single
mducrocq 0:11a51c9ebb09 2689 * measurement. The frequency of wake-ups can be configured with LP_WAKE_CTRL
mducrocq 0:11a51c9ebb09 2690 * as shown below:
mducrocq 0:11a51c9ebb09 2691 *
mducrocq 0:11a51c9ebb09 2692 * <pre>
mducrocq 0:11a51c9ebb09 2693 * LP_WAKE_CTRL | Wake-up Frequency
mducrocq 0:11a51c9ebb09 2694 * -------------+------------------
mducrocq 0:11a51c9ebb09 2695 * 0 | 1.25 Hz
mducrocq 0:11a51c9ebb09 2696 * 1 | 2.5 Hz
mducrocq 0:11a51c9ebb09 2697 * 2 | 5 Hz
mducrocq 0:11a51c9ebb09 2698 * 3 | 10 Hz
mducrocq 0:11a51c9ebb09 2699 * <pre>
mducrocq 0:11a51c9ebb09 2700 *
mducrocq 0:11a51c9ebb09 2701 * For further information regarding the MPU-60X0's power modes, please refer to
mducrocq 0:11a51c9ebb09 2702 * Register 107.
mducrocq 0:11a51c9ebb09 2703 *
mducrocq 0:11a51c9ebb09 2704 * @return Current wake frequency
mducrocq 0:11a51c9ebb09 2705 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2706 */
mducrocq 0:11a51c9ebb09 2707 uint8_t MPU6050::getWakeFrequency()
mducrocq 0:11a51c9ebb09 2708 {
mducrocq 0:11a51c9ebb09 2709 i2Cdev.readBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 2710 return buffer[0];
mducrocq 0:11a51c9ebb09 2711 }
mducrocq 0:11a51c9ebb09 2712 /** Set wake frequency in Accel-Only Low Power Mode.
mducrocq 0:11a51c9ebb09 2713 * @param frequency New wake frequency
mducrocq 0:11a51c9ebb09 2714 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2715 */
mducrocq 0:11a51c9ebb09 2716 void MPU6050::setWakeFrequency(uint8_t frequency)
mducrocq 0:11a51c9ebb09 2717 {
mducrocq 0:11a51c9ebb09 2718 i2Cdev.writeBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, frequency);
mducrocq 0:11a51c9ebb09 2719 }
mducrocq 0:11a51c9ebb09 2720
mducrocq 0:11a51c9ebb09 2721 /** Get X-axis accelerometer standby enabled status.
mducrocq 0:11a51c9ebb09 2722 * If enabled, the X-axis will not gather or report data (or use power).
mducrocq 0:11a51c9ebb09 2723 * @return Current X-axis standby enabled status
mducrocq 0:11a51c9ebb09 2724 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2725 * @see MPU6050_PWR2_STBY_XA_BIT
mducrocq 0:11a51c9ebb09 2726 */
mducrocq 0:11a51c9ebb09 2727 bool MPU6050::getStandbyXAccelEnabled()
mducrocq 0:11a51c9ebb09 2728 {
mducrocq 0:11a51c9ebb09 2729 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, buffer);
mducrocq 0:11a51c9ebb09 2730 return buffer[0];
mducrocq 0:11a51c9ebb09 2731 }
mducrocq 0:11a51c9ebb09 2732 /** Set X-axis accelerometer standby enabled status.
mducrocq 0:11a51c9ebb09 2733 * @param New X-axis standby enabled status
mducrocq 0:11a51c9ebb09 2734 * @see getStandbyXAccelEnabled()
mducrocq 0:11a51c9ebb09 2735 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2736 * @see MPU6050_PWR2_STBY_XA_BIT
mducrocq 0:11a51c9ebb09 2737 */
mducrocq 0:11a51c9ebb09 2738 void MPU6050::setStandbyXAccelEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2739 {
mducrocq 0:11a51c9ebb09 2740 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, enabled);
mducrocq 0:11a51c9ebb09 2741 }
mducrocq 0:11a51c9ebb09 2742 /** Get Y-axis accelerometer standby enabled status.
mducrocq 0:11a51c9ebb09 2743 * If enabled, the Y-axis will not gather or report data (or use power).
mducrocq 0:11a51c9ebb09 2744 * @return Current Y-axis standby enabled status
mducrocq 0:11a51c9ebb09 2745 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2746 * @see MPU6050_PWR2_STBY_YA_BIT
mducrocq 0:11a51c9ebb09 2747 */
mducrocq 0:11a51c9ebb09 2748 bool MPU6050::getStandbyYAccelEnabled()
mducrocq 0:11a51c9ebb09 2749 {
mducrocq 0:11a51c9ebb09 2750 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, buffer);
mducrocq 0:11a51c9ebb09 2751 return buffer[0];
mducrocq 0:11a51c9ebb09 2752 }
mducrocq 0:11a51c9ebb09 2753 /** Set Y-axis accelerometer standby enabled status.
mducrocq 0:11a51c9ebb09 2754 * @param New Y-axis standby enabled status
mducrocq 0:11a51c9ebb09 2755 * @see getStandbyYAccelEnabled()
mducrocq 0:11a51c9ebb09 2756 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2757 * @see MPU6050_PWR2_STBY_YA_BIT
mducrocq 0:11a51c9ebb09 2758 */
mducrocq 0:11a51c9ebb09 2759 void MPU6050::setStandbyYAccelEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2760 {
mducrocq 0:11a51c9ebb09 2761 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, enabled);
mducrocq 0:11a51c9ebb09 2762 }
mducrocq 0:11a51c9ebb09 2763 /** Get Z-axis accelerometer standby enabled status.
mducrocq 0:11a51c9ebb09 2764 * If enabled, the Z-axis will not gather or report data (or use power).
mducrocq 0:11a51c9ebb09 2765 * @return Current Z-axis standby enabled status
mducrocq 0:11a51c9ebb09 2766 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2767 * @see MPU6050_PWR2_STBY_ZA_BIT
mducrocq 0:11a51c9ebb09 2768 */
mducrocq 0:11a51c9ebb09 2769 bool MPU6050::getStandbyZAccelEnabled()
mducrocq 0:11a51c9ebb09 2770 {
mducrocq 0:11a51c9ebb09 2771 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, buffer);
mducrocq 0:11a51c9ebb09 2772 return buffer[0];
mducrocq 0:11a51c9ebb09 2773 }
mducrocq 0:11a51c9ebb09 2774 /** Set Z-axis accelerometer standby enabled status.
mducrocq 0:11a51c9ebb09 2775 * @param New Z-axis standby enabled status
mducrocq 0:11a51c9ebb09 2776 * @see getStandbyZAccelEnabled()
mducrocq 0:11a51c9ebb09 2777 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2778 * @see MPU6050_PWR2_STBY_ZA_BIT
mducrocq 0:11a51c9ebb09 2779 */
mducrocq 0:11a51c9ebb09 2780 void MPU6050::setStandbyZAccelEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2781 {
mducrocq 0:11a51c9ebb09 2782 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, enabled);
mducrocq 0:11a51c9ebb09 2783 }
mducrocq 0:11a51c9ebb09 2784 /** Get X-axis gyroscope standby enabled status.
mducrocq 0:11a51c9ebb09 2785 * If enabled, the X-axis will not gather or report data (or use power).
mducrocq 0:11a51c9ebb09 2786 * @return Current X-axis standby enabled status
mducrocq 0:11a51c9ebb09 2787 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2788 * @see MPU6050_PWR2_STBY_XG_BIT
mducrocq 0:11a51c9ebb09 2789 */
mducrocq 0:11a51c9ebb09 2790 bool MPU6050::getStandbyXGyroEnabled()
mducrocq 0:11a51c9ebb09 2791 {
mducrocq 0:11a51c9ebb09 2792 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, buffer);
mducrocq 0:11a51c9ebb09 2793 return buffer[0];
mducrocq 0:11a51c9ebb09 2794 }
mducrocq 0:11a51c9ebb09 2795 /** Set X-axis gyroscope standby enabled status.
mducrocq 0:11a51c9ebb09 2796 * @param New X-axis standby enabled status
mducrocq 0:11a51c9ebb09 2797 * @see getStandbyXGyroEnabled()
mducrocq 0:11a51c9ebb09 2798 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2799 * @see MPU6050_PWR2_STBY_XG_BIT
mducrocq 0:11a51c9ebb09 2800 */
mducrocq 0:11a51c9ebb09 2801 void MPU6050::setStandbyXGyroEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2802 {
mducrocq 0:11a51c9ebb09 2803 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, enabled);
mducrocq 0:11a51c9ebb09 2804 }
mducrocq 0:11a51c9ebb09 2805 /** Get Y-axis gyroscope standby enabled status.
mducrocq 0:11a51c9ebb09 2806 * If enabled, the Y-axis will not gather or report data (or use power).
mducrocq 0:11a51c9ebb09 2807 * @return Current Y-axis standby enabled status
mducrocq 0:11a51c9ebb09 2808 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2809 * @see MPU6050_PWR2_STBY_YG_BIT
mducrocq 0:11a51c9ebb09 2810 */
mducrocq 0:11a51c9ebb09 2811 bool MPU6050::getStandbyYGyroEnabled()
mducrocq 0:11a51c9ebb09 2812 {
mducrocq 0:11a51c9ebb09 2813 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, buffer);
mducrocq 0:11a51c9ebb09 2814 return buffer[0];
mducrocq 0:11a51c9ebb09 2815 }
mducrocq 0:11a51c9ebb09 2816 /** Set Y-axis gyroscope standby enabled status.
mducrocq 0:11a51c9ebb09 2817 * @param New Y-axis standby enabled status
mducrocq 0:11a51c9ebb09 2818 * @see getStandbyYGyroEnabled()
mducrocq 0:11a51c9ebb09 2819 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2820 * @see MPU6050_PWR2_STBY_YG_BIT
mducrocq 0:11a51c9ebb09 2821 */
mducrocq 0:11a51c9ebb09 2822 void MPU6050::setStandbyYGyroEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2823 {
mducrocq 0:11a51c9ebb09 2824 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, enabled);
mducrocq 0:11a51c9ebb09 2825 }
mducrocq 0:11a51c9ebb09 2826 /** Get Z-axis gyroscope standby enabled status.
mducrocq 0:11a51c9ebb09 2827 * If enabled, the Z-axis will not gather or report data (or use power).
mducrocq 0:11a51c9ebb09 2828 * @return Current Z-axis standby enabled status
mducrocq 0:11a51c9ebb09 2829 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2830 * @see MPU6050_PWR2_STBY_ZG_BIT
mducrocq 0:11a51c9ebb09 2831 */
mducrocq 0:11a51c9ebb09 2832 bool MPU6050::getStandbyZGyroEnabled()
mducrocq 0:11a51c9ebb09 2833 {
mducrocq 0:11a51c9ebb09 2834 i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, buffer);
mducrocq 0:11a51c9ebb09 2835 return buffer[0];
mducrocq 0:11a51c9ebb09 2836 }
mducrocq 0:11a51c9ebb09 2837 /** Set Z-axis gyroscope standby enabled status.
mducrocq 0:11a51c9ebb09 2838 * @param New Z-axis standby enabled status
mducrocq 0:11a51c9ebb09 2839 * @see getStandbyZGyroEnabled()
mducrocq 0:11a51c9ebb09 2840 * @see MPU6050_RA_PWR_MGMT_2
mducrocq 0:11a51c9ebb09 2841 * @see MPU6050_PWR2_STBY_ZG_BIT
mducrocq 0:11a51c9ebb09 2842 */
mducrocq 0:11a51c9ebb09 2843 void MPU6050::setStandbyZGyroEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 2844 {
mducrocq 0:11a51c9ebb09 2845 i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, enabled);
mducrocq 0:11a51c9ebb09 2846 }
mducrocq 0:11a51c9ebb09 2847
mducrocq 0:11a51c9ebb09 2848 // FIFO_COUNT* registers
mducrocq 0:11a51c9ebb09 2849
mducrocq 0:11a51c9ebb09 2850 /** Get current FIFO buffer size.
mducrocq 0:11a51c9ebb09 2851 * This value indicates the number of bytes stored in the FIFO buffer. This
mducrocq 0:11a51c9ebb09 2852 * number is in turn the number of bytes that can be read from the FIFO buffer
mducrocq 0:11a51c9ebb09 2853 * and it is directly proportional to the number of samples available given the
mducrocq 0:11a51c9ebb09 2854 * set of sensor data bound to be stored in the FIFO (register 35 and 36).
mducrocq 0:11a51c9ebb09 2855 * @return Current FIFO buffer size
mducrocq 0:11a51c9ebb09 2856 */
mducrocq 0:11a51c9ebb09 2857 uint16_t MPU6050::getFIFOCount()
mducrocq 0:11a51c9ebb09 2858 {
mducrocq 0:11a51c9ebb09 2859 i2Cdev.readBytes(devAddr, MPU6050_RA_FIFO_COUNTH, 2, buffer);
mducrocq 0:11a51c9ebb09 2860 return (((uint16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 2861 }
mducrocq 0:11a51c9ebb09 2862
mducrocq 0:11a51c9ebb09 2863 // FIFO_R_W register
mducrocq 0:11a51c9ebb09 2864
mducrocq 0:11a51c9ebb09 2865 /** Get byte from FIFO buffer.
mducrocq 0:11a51c9ebb09 2866 * This register is used to read and write data from the FIFO buffer. Data is
mducrocq 0:11a51c9ebb09 2867 * written to the FIFO in order of register number (from lowest to highest). If
mducrocq 0:11a51c9ebb09 2868 * all the FIFO enable flags (see below) are enabled and all External Sensor
mducrocq 0:11a51c9ebb09 2869 * Data registers (Registers 73 to 96) are associated with a Slave device, the
mducrocq 0:11a51c9ebb09 2870 * contents of registers 59 through 96 will be written in order at the Sample
mducrocq 0:11a51c9ebb09 2871 * Rate.
mducrocq 0:11a51c9ebb09 2872 *
mducrocq 0:11a51c9ebb09 2873 * The contents of the sensor data registers (Registers 59 to 96) are written
mducrocq 0:11a51c9ebb09 2874 * into the FIFO buffer when their corresponding FIFO enable flags are set to 1
mducrocq 0:11a51c9ebb09 2875 * in FIFO_EN (Register 35). An additional flag for the sensor data registers
mducrocq 0:11a51c9ebb09 2876 * associated with I2C Slave 3 can be found in I2C_MST_CTRL (Register 36).
mducrocq 0:11a51c9ebb09 2877 *
mducrocq 0:11a51c9ebb09 2878 * If the FIFO buffer has overflowed, the status bit FIFO_OFLOW_INT is
mducrocq 0:11a51c9ebb09 2879 * automatically set to 1. This bit is located in INT_STATUS (Register 58).
mducrocq 0:11a51c9ebb09 2880 * When the FIFO buffer has overflowed, the oldest data will be lost and new
mducrocq 0:11a51c9ebb09 2881 * data will be written to the FIFO.
mducrocq 0:11a51c9ebb09 2882 *
mducrocq 0:11a51c9ebb09 2883 * If the FIFO buffer is empty, reading this register will return the last byte
mducrocq 0:11a51c9ebb09 2884 * that was previously read from the FIFO until new data is available. The user
mducrocq 0:11a51c9ebb09 2885 * should check FIFO_COUNT to ensure that the FIFO buffer is not read when
mducrocq 0:11a51c9ebb09 2886 * empty.
mducrocq 0:11a51c9ebb09 2887 *
mducrocq 0:11a51c9ebb09 2888 * @return Byte from FIFO buffer
mducrocq 0:11a51c9ebb09 2889 */
mducrocq 0:11a51c9ebb09 2890 uint8_t MPU6050::getFIFOByte()
mducrocq 0:11a51c9ebb09 2891 {
mducrocq 0:11a51c9ebb09 2892 i2Cdev.readByte(devAddr, MPU6050_RA_FIFO_R_W, buffer);
mducrocq 0:11a51c9ebb09 2893 return buffer[0];
mducrocq 0:11a51c9ebb09 2894 }
mducrocq 0:11a51c9ebb09 2895 void MPU6050::getFIFOBytes(uint8_t *data, uint8_t length)
mducrocq 0:11a51c9ebb09 2896 {
mducrocq 0:11a51c9ebb09 2897 i2Cdev.readBytes(devAddr, MPU6050_RA_FIFO_R_W, length, data);
mducrocq 0:11a51c9ebb09 2898 }
mducrocq 0:11a51c9ebb09 2899 /** Write byte to FIFO buffer.
mducrocq 0:11a51c9ebb09 2900 * @see getFIFOByte()
mducrocq 0:11a51c9ebb09 2901 * @see MPU6050_RA_FIFO_R_W
mducrocq 0:11a51c9ebb09 2902 */
mducrocq 0:11a51c9ebb09 2903 void MPU6050::setFIFOByte(uint8_t data)
mducrocq 0:11a51c9ebb09 2904 {
mducrocq 0:11a51c9ebb09 2905 i2Cdev.writeByte(devAddr, MPU6050_RA_FIFO_R_W, data);
mducrocq 0:11a51c9ebb09 2906 }
mducrocq 0:11a51c9ebb09 2907
mducrocq 0:11a51c9ebb09 2908 // WHO_AM_I register
mducrocq 0:11a51c9ebb09 2909
mducrocq 0:11a51c9ebb09 2910 /** Get Device ID.
mducrocq 0:11a51c9ebb09 2911 * This register is used to verify the identity of the device (0b110100, 0x34).
mducrocq 0:11a51c9ebb09 2912 * @return Device ID (6 bits only! should be 0x34)
mducrocq 0:11a51c9ebb09 2913 * @see MPU6050_RA_WHO_AM_I
mducrocq 0:11a51c9ebb09 2914 * @see MPU6050_WHO_AM_I_BIT
mducrocq 0:11a51c9ebb09 2915 * @see MPU6050_WHO_AM_I_LENGTH
mducrocq 0:11a51c9ebb09 2916 */
mducrocq 0:11a51c9ebb09 2917 uint8_t MPU6050::getDeviceID()
mducrocq 0:11a51c9ebb09 2918 {
mducrocq 0:11a51c9ebb09 2919 i2Cdev.readBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 2920 return buffer[0];
mducrocq 0:11a51c9ebb09 2921 }
mducrocq 0:11a51c9ebb09 2922 /** Set Device ID.
mducrocq 0:11a51c9ebb09 2923 * Write a new ID into the WHO_AM_I register (no idea why this should ever be
mducrocq 0:11a51c9ebb09 2924 * necessary though).
mducrocq 0:11a51c9ebb09 2925 * @param id New device ID to set.
mducrocq 0:11a51c9ebb09 2926 * @see getDeviceID()
mducrocq 0:11a51c9ebb09 2927 * @see MPU6050_RA_WHO_AM_I
mducrocq 0:11a51c9ebb09 2928 * @see MPU6050_WHO_AM_I_BIT
mducrocq 0:11a51c9ebb09 2929 * @see MPU6050_WHO_AM_I_LENGTH
mducrocq 0:11a51c9ebb09 2930 */
mducrocq 0:11a51c9ebb09 2931 void MPU6050::setDeviceID(uint8_t id)
mducrocq 0:11a51c9ebb09 2932 {
mducrocq 0:11a51c9ebb09 2933 i2Cdev.writeBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, id);
mducrocq 0:11a51c9ebb09 2934 }
mducrocq 0:11a51c9ebb09 2935
mducrocq 0:11a51c9ebb09 2936 // ======== UNDOCUMENTED/DMP REGISTERS/METHODS ========
mducrocq 0:11a51c9ebb09 2937
mducrocq 0:11a51c9ebb09 2938 // XG_OFFS_TC register
mducrocq 0:11a51c9ebb09 2939
mducrocq 0:11a51c9ebb09 2940 uint8_t MPU6050::getOTPBankValid()
mducrocq 0:11a51c9ebb09 2941 {
mducrocq 0:11a51c9ebb09 2942 i2Cdev.readBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, buffer);
mducrocq 0:11a51c9ebb09 2943 return buffer[0];
mducrocq 0:11a51c9ebb09 2944 }
mducrocq 0:11a51c9ebb09 2945 void MPU6050::setOTPBankValid(bool enabled)
mducrocq 0:11a51c9ebb09 2946 {
mducrocq 0:11a51c9ebb09 2947 i2Cdev.writeBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, enabled);
mducrocq 0:11a51c9ebb09 2948 }
mducrocq 0:11a51c9ebb09 2949 int8_t MPU6050::getXGyroOffset()
mducrocq 0:11a51c9ebb09 2950 {
mducrocq 0:11a51c9ebb09 2951 i2Cdev.readBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 2952 return buffer[0];
mducrocq 0:11a51c9ebb09 2953 }
mducrocq 0:11a51c9ebb09 2954 void MPU6050::setXGyroOffset(int8_t offset)
mducrocq 0:11a51c9ebb09 2955 {
mducrocq 0:11a51c9ebb09 2956 i2Cdev.writeBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset);
mducrocq 0:11a51c9ebb09 2957 }
mducrocq 0:11a51c9ebb09 2958
mducrocq 0:11a51c9ebb09 2959 // YG_OFFS_TC register
mducrocq 0:11a51c9ebb09 2960
mducrocq 0:11a51c9ebb09 2961 int8_t MPU6050::getYGyroOffset()
mducrocq 0:11a51c9ebb09 2962 {
mducrocq 0:11a51c9ebb09 2963 i2Cdev.readBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 2964 return buffer[0];
mducrocq 0:11a51c9ebb09 2965 }
mducrocq 0:11a51c9ebb09 2966 void MPU6050::setYGyroOffset(int8_t offset)
mducrocq 0:11a51c9ebb09 2967 {
mducrocq 0:11a51c9ebb09 2968 i2Cdev.writeBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset);
mducrocq 0:11a51c9ebb09 2969 }
mducrocq 0:11a51c9ebb09 2970
mducrocq 0:11a51c9ebb09 2971 // ZG_OFFS_TC register
mducrocq 0:11a51c9ebb09 2972
mducrocq 0:11a51c9ebb09 2973 int8_t MPU6050::getZGyroOffset()
mducrocq 0:11a51c9ebb09 2974 {
mducrocq 0:11a51c9ebb09 2975 i2Cdev.readBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer);
mducrocq 0:11a51c9ebb09 2976 return buffer[0];
mducrocq 0:11a51c9ebb09 2977 }
mducrocq 0:11a51c9ebb09 2978 void MPU6050::setZGyroOffset(int8_t offset)
mducrocq 0:11a51c9ebb09 2979 {
mducrocq 0:11a51c9ebb09 2980 i2Cdev.writeBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset);
mducrocq 0:11a51c9ebb09 2981 }
mducrocq 0:11a51c9ebb09 2982
mducrocq 0:11a51c9ebb09 2983 // X_FINE_GAIN register
mducrocq 0:11a51c9ebb09 2984
mducrocq 0:11a51c9ebb09 2985 int8_t MPU6050::getXFineGain()
mducrocq 0:11a51c9ebb09 2986 {
mducrocq 0:11a51c9ebb09 2987 i2Cdev.readByte(devAddr, MPU6050_RA_X_FINE_GAIN, buffer);
mducrocq 0:11a51c9ebb09 2988 return buffer[0];
mducrocq 0:11a51c9ebb09 2989 }
mducrocq 0:11a51c9ebb09 2990 void MPU6050::setXFineGain(int8_t gain)
mducrocq 0:11a51c9ebb09 2991 {
mducrocq 0:11a51c9ebb09 2992 i2Cdev.writeByte(devAddr, MPU6050_RA_X_FINE_GAIN, gain);
mducrocq 0:11a51c9ebb09 2993 }
mducrocq 0:11a51c9ebb09 2994
mducrocq 0:11a51c9ebb09 2995 // Y_FINE_GAIN register
mducrocq 0:11a51c9ebb09 2996
mducrocq 0:11a51c9ebb09 2997 int8_t MPU6050::getYFineGain()
mducrocq 0:11a51c9ebb09 2998 {
mducrocq 0:11a51c9ebb09 2999 i2Cdev.readByte(devAddr, MPU6050_RA_Y_FINE_GAIN, buffer);
mducrocq 0:11a51c9ebb09 3000 return buffer[0];
mducrocq 0:11a51c9ebb09 3001 }
mducrocq 0:11a51c9ebb09 3002 void MPU6050::setYFineGain(int8_t gain)
mducrocq 0:11a51c9ebb09 3003 {
mducrocq 0:11a51c9ebb09 3004 i2Cdev.writeByte(devAddr, MPU6050_RA_Y_FINE_GAIN, gain);
mducrocq 0:11a51c9ebb09 3005 }
mducrocq 0:11a51c9ebb09 3006
mducrocq 0:11a51c9ebb09 3007 // Z_FINE_GAIN register
mducrocq 0:11a51c9ebb09 3008
mducrocq 0:11a51c9ebb09 3009 int8_t MPU6050::getZFineGain()
mducrocq 0:11a51c9ebb09 3010 {
mducrocq 0:11a51c9ebb09 3011 i2Cdev.readByte(devAddr, MPU6050_RA_Z_FINE_GAIN, buffer);
mducrocq 0:11a51c9ebb09 3012 return buffer[0];
mducrocq 0:11a51c9ebb09 3013 }
mducrocq 0:11a51c9ebb09 3014 void MPU6050::setZFineGain(int8_t gain)
mducrocq 0:11a51c9ebb09 3015 {
mducrocq 0:11a51c9ebb09 3016 i2Cdev.writeByte(devAddr, MPU6050_RA_Z_FINE_GAIN, gain);
mducrocq 0:11a51c9ebb09 3017 }
mducrocq 0:11a51c9ebb09 3018
mducrocq 0:11a51c9ebb09 3019 // XA_OFFS_* registers
mducrocq 0:11a51c9ebb09 3020
mducrocq 0:11a51c9ebb09 3021 int16_t MPU6050::getXAccelOffset()
mducrocq 0:11a51c9ebb09 3022 {
mducrocq 0:11a51c9ebb09 3023 i2Cdev.readBytes(devAddr, MPU6050_RA_XA_OFFS_H, 2, buffer);
mducrocq 0:11a51c9ebb09 3024 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 3025 }
mducrocq 0:11a51c9ebb09 3026 void MPU6050::setXAccelOffset(int16_t offset)
mducrocq 0:11a51c9ebb09 3027 {
mducrocq 0:11a51c9ebb09 3028 i2Cdev.writeWord(devAddr, MPU6050_RA_XA_OFFS_H, offset);
mducrocq 0:11a51c9ebb09 3029 }
mducrocq 0:11a51c9ebb09 3030
mducrocq 0:11a51c9ebb09 3031 // YA_OFFS_* register
mducrocq 0:11a51c9ebb09 3032
mducrocq 0:11a51c9ebb09 3033 int16_t MPU6050::getYAccelOffset()
mducrocq 0:11a51c9ebb09 3034 {
mducrocq 0:11a51c9ebb09 3035 i2Cdev.readBytes(devAddr, MPU6050_RA_YA_OFFS_H, 2, buffer);
mducrocq 0:11a51c9ebb09 3036 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 3037 }
mducrocq 0:11a51c9ebb09 3038 void MPU6050::setYAccelOffset(int16_t offset)
mducrocq 0:11a51c9ebb09 3039 {
mducrocq 0:11a51c9ebb09 3040 i2Cdev.writeWord(devAddr, MPU6050_RA_YA_OFFS_H, offset);
mducrocq 0:11a51c9ebb09 3041 }
mducrocq 0:11a51c9ebb09 3042
mducrocq 0:11a51c9ebb09 3043 // ZA_OFFS_* register
mducrocq 0:11a51c9ebb09 3044
mducrocq 0:11a51c9ebb09 3045 int16_t MPU6050::getZAccelOffset()
mducrocq 0:11a51c9ebb09 3046 {
mducrocq 0:11a51c9ebb09 3047 i2Cdev.readBytes(devAddr, MPU6050_RA_ZA_OFFS_H, 2, buffer);
mducrocq 0:11a51c9ebb09 3048 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 3049 }
mducrocq 0:11a51c9ebb09 3050 void MPU6050::setZAccelOffset(int16_t offset)
mducrocq 0:11a51c9ebb09 3051 {
mducrocq 0:11a51c9ebb09 3052 i2Cdev.writeWord(devAddr, MPU6050_RA_ZA_OFFS_H, offset);
mducrocq 0:11a51c9ebb09 3053 }
mducrocq 0:11a51c9ebb09 3054
mducrocq 0:11a51c9ebb09 3055 // XG_OFFS_USR* registers
mducrocq 0:11a51c9ebb09 3056
mducrocq 0:11a51c9ebb09 3057 int16_t MPU6050::getXGyroOffsetUser()
mducrocq 0:11a51c9ebb09 3058 {
mducrocq 0:11a51c9ebb09 3059 i2Cdev.readBytes(devAddr, MPU6050_RA_XG_OFFS_USRH, 2, buffer);
mducrocq 0:11a51c9ebb09 3060 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 3061 }
mducrocq 0:11a51c9ebb09 3062 void MPU6050::setXGyroOffsetUser(int16_t offset)
mducrocq 0:11a51c9ebb09 3063 {
mducrocq 0:11a51c9ebb09 3064 i2Cdev.writeWord(devAddr, MPU6050_RA_XG_OFFS_USRH, offset);
mducrocq 0:11a51c9ebb09 3065 }
mducrocq 0:11a51c9ebb09 3066
mducrocq 0:11a51c9ebb09 3067 // YG_OFFS_USR* register
mducrocq 0:11a51c9ebb09 3068
mducrocq 0:11a51c9ebb09 3069 int16_t MPU6050::getYGyroOffsetUser()
mducrocq 0:11a51c9ebb09 3070 {
mducrocq 0:11a51c9ebb09 3071 i2Cdev.readBytes(devAddr, MPU6050_RA_YG_OFFS_USRH, 2, buffer);
mducrocq 0:11a51c9ebb09 3072 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 3073 }
mducrocq 0:11a51c9ebb09 3074 void MPU6050::setYGyroOffsetUser(int16_t offset)
mducrocq 0:11a51c9ebb09 3075 {
mducrocq 0:11a51c9ebb09 3076 i2Cdev.writeWord(devAddr, MPU6050_RA_YG_OFFS_USRH, offset);
mducrocq 0:11a51c9ebb09 3077 }
mducrocq 0:11a51c9ebb09 3078
mducrocq 0:11a51c9ebb09 3079 // ZG_OFFS_USR* register
mducrocq 0:11a51c9ebb09 3080
mducrocq 0:11a51c9ebb09 3081 int16_t MPU6050::getZGyroOffsetUser()
mducrocq 0:11a51c9ebb09 3082 {
mducrocq 0:11a51c9ebb09 3083 i2Cdev.readBytes(devAddr, MPU6050_RA_ZG_OFFS_USRH, 2, buffer);
mducrocq 0:11a51c9ebb09 3084 return (((int16_t)buffer[0]) << 8) | buffer[1];
mducrocq 0:11a51c9ebb09 3085 }
mducrocq 0:11a51c9ebb09 3086 void MPU6050::setZGyroOffsetUser(int16_t offset)
mducrocq 0:11a51c9ebb09 3087 {
mducrocq 0:11a51c9ebb09 3088 i2Cdev.writeWord(devAddr, MPU6050_RA_ZG_OFFS_USRH, offset);
mducrocq 0:11a51c9ebb09 3089 }
mducrocq 0:11a51c9ebb09 3090
mducrocq 0:11a51c9ebb09 3091 // INT_ENABLE register (DMP functions)
mducrocq 0:11a51c9ebb09 3092
mducrocq 0:11a51c9ebb09 3093 bool MPU6050::getIntPLLReadyEnabled()
mducrocq 0:11a51c9ebb09 3094 {
mducrocq 0:11a51c9ebb09 3095 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer);
mducrocq 0:11a51c9ebb09 3096 return buffer[0];
mducrocq 0:11a51c9ebb09 3097 }
mducrocq 0:11a51c9ebb09 3098 void MPU6050::setIntPLLReadyEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 3099 {
mducrocq 0:11a51c9ebb09 3100 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, enabled);
mducrocq 0:11a51c9ebb09 3101 }
mducrocq 0:11a51c9ebb09 3102 bool MPU6050::getIntDMPEnabled()
mducrocq 0:11a51c9ebb09 3103 {
mducrocq 0:11a51c9ebb09 3104 i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, buffer);
mducrocq 0:11a51c9ebb09 3105 return buffer[0];
mducrocq 0:11a51c9ebb09 3106 }
mducrocq 0:11a51c9ebb09 3107 void MPU6050::setIntDMPEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 3108 {
mducrocq 0:11a51c9ebb09 3109 i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, enabled);
mducrocq 0:11a51c9ebb09 3110 }
mducrocq 0:11a51c9ebb09 3111
mducrocq 0:11a51c9ebb09 3112 // DMP_INT_STATUS
mducrocq 0:11a51c9ebb09 3113
mducrocq 0:11a51c9ebb09 3114 bool MPU6050::getDMPInt5Status()
mducrocq 0:11a51c9ebb09 3115 {
mducrocq 0:11a51c9ebb09 3116 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_5_BIT, buffer);
mducrocq 0:11a51c9ebb09 3117 return buffer[0];
mducrocq 0:11a51c9ebb09 3118 }
mducrocq 0:11a51c9ebb09 3119 bool MPU6050::getDMPInt4Status()
mducrocq 0:11a51c9ebb09 3120 {
mducrocq 0:11a51c9ebb09 3121 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_4_BIT, buffer);
mducrocq 0:11a51c9ebb09 3122 return buffer[0];
mducrocq 0:11a51c9ebb09 3123 }
mducrocq 0:11a51c9ebb09 3124 bool MPU6050::getDMPInt3Status()
mducrocq 0:11a51c9ebb09 3125 {
mducrocq 0:11a51c9ebb09 3126 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_3_BIT, buffer);
mducrocq 0:11a51c9ebb09 3127 return buffer[0];
mducrocq 0:11a51c9ebb09 3128 }
mducrocq 0:11a51c9ebb09 3129 bool MPU6050::getDMPInt2Status()
mducrocq 0:11a51c9ebb09 3130 {
mducrocq 0:11a51c9ebb09 3131 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_2_BIT, buffer);
mducrocq 0:11a51c9ebb09 3132 return buffer[0];
mducrocq 0:11a51c9ebb09 3133 }
mducrocq 0:11a51c9ebb09 3134 bool MPU6050::getDMPInt1Status()
mducrocq 0:11a51c9ebb09 3135 {
mducrocq 0:11a51c9ebb09 3136 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_1_BIT, buffer);
mducrocq 0:11a51c9ebb09 3137 return buffer[0];
mducrocq 0:11a51c9ebb09 3138 }
mducrocq 0:11a51c9ebb09 3139 bool MPU6050::getDMPInt0Status()
mducrocq 0:11a51c9ebb09 3140 {
mducrocq 0:11a51c9ebb09 3141 i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_0_BIT, buffer);
mducrocq 0:11a51c9ebb09 3142 return buffer[0];
mducrocq 0:11a51c9ebb09 3143 }
mducrocq 0:11a51c9ebb09 3144
mducrocq 0:11a51c9ebb09 3145 // INT_STATUS register (DMP functions)
mducrocq 0:11a51c9ebb09 3146
mducrocq 0:11a51c9ebb09 3147 bool MPU6050::getIntPLLReadyStatus()
mducrocq 0:11a51c9ebb09 3148 {
mducrocq 0:11a51c9ebb09 3149 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer);
mducrocq 0:11a51c9ebb09 3150 return buffer[0];
mducrocq 0:11a51c9ebb09 3151 }
mducrocq 0:11a51c9ebb09 3152 bool MPU6050::getIntDMPStatus()
mducrocq 0:11a51c9ebb09 3153 {
mducrocq 0:11a51c9ebb09 3154 i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DMP_INT_BIT, buffer);
mducrocq 0:11a51c9ebb09 3155 return buffer[0];
mducrocq 0:11a51c9ebb09 3156 }
mducrocq 0:11a51c9ebb09 3157
mducrocq 0:11a51c9ebb09 3158 // USER_CTRL register (DMP functions)
mducrocq 0:11a51c9ebb09 3159
mducrocq 0:11a51c9ebb09 3160 bool MPU6050::getDMPEnabled()
mducrocq 0:11a51c9ebb09 3161 {
mducrocq 0:11a51c9ebb09 3162 i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, buffer);
mducrocq 0:11a51c9ebb09 3163 return buffer[0];
mducrocq 0:11a51c9ebb09 3164 }
mducrocq 0:11a51c9ebb09 3165 void MPU6050::setDMPEnabled(bool enabled)
mducrocq 0:11a51c9ebb09 3166 {
mducrocq 0:11a51c9ebb09 3167 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, enabled);
mducrocq 0:11a51c9ebb09 3168 }
mducrocq 0:11a51c9ebb09 3169 void MPU6050::resetDMP()
mducrocq 0:11a51c9ebb09 3170 {
mducrocq 0:11a51c9ebb09 3171 i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_RESET_BIT, true);
mducrocq 0:11a51c9ebb09 3172 }
mducrocq 0:11a51c9ebb09 3173
mducrocq 0:11a51c9ebb09 3174 // BANK_SEL register
mducrocq 0:11a51c9ebb09 3175
mducrocq 0:11a51c9ebb09 3176 void MPU6050::setMemoryBank(uint8_t bank, bool prefetchEnabled, bool userBank)
mducrocq 0:11a51c9ebb09 3177 {
mducrocq 0:11a51c9ebb09 3178 bank &= 0x1F;
mducrocq 0:11a51c9ebb09 3179 if (userBank) bank |= 0x20;
mducrocq 0:11a51c9ebb09 3180 if (prefetchEnabled) bank |= 0x40;
mducrocq 0:11a51c9ebb09 3181 i2Cdev.writeByte(devAddr, MPU6050_RA_BANK_SEL, bank);
mducrocq 0:11a51c9ebb09 3182 }
mducrocq 0:11a51c9ebb09 3183
mducrocq 0:11a51c9ebb09 3184 // MEM_START_ADDR register
mducrocq 0:11a51c9ebb09 3185
mducrocq 0:11a51c9ebb09 3186 void MPU6050::setMemoryStartAddress(uint8_t address)
mducrocq 0:11a51c9ebb09 3187 {
mducrocq 0:11a51c9ebb09 3188 i2Cdev.writeByte(devAddr, MPU6050_RA_MEM_START_ADDR, address);
mducrocq 0:11a51c9ebb09 3189 }
mducrocq 0:11a51c9ebb09 3190
mducrocq 0:11a51c9ebb09 3191 // MEM_R_W register
mducrocq 0:11a51c9ebb09 3192
mducrocq 0:11a51c9ebb09 3193 uint8_t MPU6050::readMemoryByte()
mducrocq 0:11a51c9ebb09 3194 {
mducrocq 0:11a51c9ebb09 3195 i2Cdev.readByte(devAddr, MPU6050_RA_MEM_R_W, buffer);
mducrocq 0:11a51c9ebb09 3196 return buffer[0];
mducrocq 0:11a51c9ebb09 3197 }
mducrocq 0:11a51c9ebb09 3198 void MPU6050::writeMemoryByte(uint8_t data)
mducrocq 0:11a51c9ebb09 3199 {
mducrocq 0:11a51c9ebb09 3200 i2Cdev.writeByte(devAddr, MPU6050_RA_MEM_R_W, data);
mducrocq 0:11a51c9ebb09 3201 }
mducrocq 0:11a51c9ebb09 3202 void MPU6050::readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address)
mducrocq 0:11a51c9ebb09 3203 {
mducrocq 0:11a51c9ebb09 3204 setMemoryBank(bank);
mducrocq 0:11a51c9ebb09 3205 setMemoryStartAddress(address);
mducrocq 0:11a51c9ebb09 3206 uint8_t chunkSize;
mducrocq 0:11a51c9ebb09 3207 for (uint16_t i = 0; i < dataSize;) {
mducrocq 0:11a51c9ebb09 3208 // determine correct chunk size according to bank position and data size
mducrocq 0:11a51c9ebb09 3209 chunkSize = MPU6050_DMP_MEMORY_CHUNK_SIZE;
mducrocq 0:11a51c9ebb09 3210
mducrocq 0:11a51c9ebb09 3211 // make sure we don't go past the data size
mducrocq 0:11a51c9ebb09 3212 if (i + chunkSize > dataSize) chunkSize = dataSize - i;
mducrocq 0:11a51c9ebb09 3213
mducrocq 0:11a51c9ebb09 3214 // make sure this chunk doesn't go past the bank boundary (256 bytes)
mducrocq 0:11a51c9ebb09 3215 if (chunkSize > 256 - address) chunkSize = 256 - address;
mducrocq 0:11a51c9ebb09 3216
mducrocq 0:11a51c9ebb09 3217 // read the chunk of data as specified
mducrocq 0:11a51c9ebb09 3218 i2Cdev.readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, data + i);
mducrocq 0:11a51c9ebb09 3219
mducrocq 0:11a51c9ebb09 3220 // increase byte index by [chunkSize]
mducrocq 0:11a51c9ebb09 3221 i += chunkSize;
mducrocq 0:11a51c9ebb09 3222
mducrocq 0:11a51c9ebb09 3223 // uint8_t automatically wraps to 0 at 256
mducrocq 0:11a51c9ebb09 3224 address += chunkSize;
mducrocq 0:11a51c9ebb09 3225
mducrocq 0:11a51c9ebb09 3226 // if we aren't done, update bank (if necessary) and address
mducrocq 0:11a51c9ebb09 3227 if (i < dataSize) {
mducrocq 0:11a51c9ebb09 3228 if (address == 0) bank++;
mducrocq 0:11a51c9ebb09 3229 setMemoryBank(bank);
mducrocq 0:11a51c9ebb09 3230 setMemoryStartAddress(address);
mducrocq 0:11a51c9ebb09 3231 }
mducrocq 0:11a51c9ebb09 3232 }
mducrocq 0:11a51c9ebb09 3233 }
mducrocq 0:11a51c9ebb09 3234 bool MPU6050::writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify, bool useProgMem)
mducrocq 0:11a51c9ebb09 3235 {
mducrocq 0:11a51c9ebb09 3236 setMemoryBank(bank);
mducrocq 0:11a51c9ebb09 3237 setMemoryStartAddress(address);
mducrocq 0:11a51c9ebb09 3238 uint8_t chunkSize;
mducrocq 0:11a51c9ebb09 3239 uint8_t *verifyBuffer;
mducrocq 0:11a51c9ebb09 3240 uint8_t *progBuffer;
mducrocq 0:11a51c9ebb09 3241 uint16_t i;
mducrocq 0:11a51c9ebb09 3242 uint8_t j;
mducrocq 0:11a51c9ebb09 3243 if (verify) verifyBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE);
mducrocq 0:11a51c9ebb09 3244 if (useProgMem) progBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE);
mducrocq 0:11a51c9ebb09 3245 for (i = 0; i < dataSize;) {
mducrocq 0:11a51c9ebb09 3246 // determine correct chunk size according to bank position and data size
mducrocq 0:11a51c9ebb09 3247 chunkSize = MPU6050_DMP_MEMORY_CHUNK_SIZE;
mducrocq 0:11a51c9ebb09 3248
mducrocq 0:11a51c9ebb09 3249 // make sure we don't go past the data size
mducrocq 0:11a51c9ebb09 3250 if (i + chunkSize > dataSize) chunkSize = dataSize - i;
mducrocq 0:11a51c9ebb09 3251
mducrocq 0:11a51c9ebb09 3252 // make sure this chunk doesn't go past the bank boundary (256 bytes)
mducrocq 0:11a51c9ebb09 3253 if (chunkSize > 256 - address) chunkSize = 256 - address;
mducrocq 0:11a51c9ebb09 3254
mducrocq 0:11a51c9ebb09 3255 if (useProgMem) {
mducrocq 0:11a51c9ebb09 3256 // write the chunk of data as specified
mducrocq 0:11a51c9ebb09 3257 for (j = 0; j < chunkSize; j++) progBuffer[j] = pgm_read_byte(data + i + j);
mducrocq 0:11a51c9ebb09 3258 } else {
mducrocq 0:11a51c9ebb09 3259 // write the chunk of data as specified
mducrocq 0:11a51c9ebb09 3260 progBuffer = (uint8_t *)data + i;
mducrocq 0:11a51c9ebb09 3261 }
mducrocq 0:11a51c9ebb09 3262
mducrocq 0:11a51c9ebb09 3263 i2Cdev.writeBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, progBuffer);
mducrocq 0:11a51c9ebb09 3264
mducrocq 0:11a51c9ebb09 3265 // verify data if needed
mducrocq 0:11a51c9ebb09 3266 if (verify && verifyBuffer) {
mducrocq 0:11a51c9ebb09 3267 setMemoryBank(bank);
mducrocq 0:11a51c9ebb09 3268 setMemoryStartAddress(address);
mducrocq 0:11a51c9ebb09 3269 i2Cdev.readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, verifyBuffer);
mducrocq 0:11a51c9ebb09 3270 if (memcmp(progBuffer, verifyBuffer, chunkSize) != 0) {
mducrocq 0:11a51c9ebb09 3271 /*Serial.print("Block write verification error, bank ");
mducrocq 0:11a51c9ebb09 3272 Serial.print(bank, DEC);
mducrocq 0:11a51c9ebb09 3273 Serial.print(", address ");
mducrocq 0:11a51c9ebb09 3274 Serial.print(address, DEC);
mducrocq 0:11a51c9ebb09 3275 Serial.print("!\nExpected:");
mducrocq 0:11a51c9ebb09 3276 for (j = 0; j < chunkSize; j++) {
mducrocq 0:11a51c9ebb09 3277 Serial.print(" 0x");
mducrocq 0:11a51c9ebb09 3278 if (progBuffer[j] < 16) Serial.print("0");
mducrocq 0:11a51c9ebb09 3279 Serial.print(progBuffer[j], HEX);
mducrocq 0:11a51c9ebb09 3280 }
mducrocq 0:11a51c9ebb09 3281 Serial.print("\nReceived:");
mducrocq 0:11a51c9ebb09 3282 for (uint8_t j = 0; j < chunkSize; j++) {
mducrocq 0:11a51c9ebb09 3283 Serial.print(" 0x");
mducrocq 0:11a51c9ebb09 3284 if (verifyBuffer[i + j] < 16) Serial.print("0");
mducrocq 0:11a51c9ebb09 3285 Serial.print(verifyBuffer[i + j], HEX);
mducrocq 0:11a51c9ebb09 3286 }
mducrocq 0:11a51c9ebb09 3287 Serial.print("\n");*/
mducrocq 0:11a51c9ebb09 3288 free(verifyBuffer);
mducrocq 0:11a51c9ebb09 3289 if (useProgMem) free(progBuffer);
mducrocq 0:11a51c9ebb09 3290 return false; // uh oh.
mducrocq 0:11a51c9ebb09 3291 }
mducrocq 0:11a51c9ebb09 3292 }
mducrocq 0:11a51c9ebb09 3293
mducrocq 0:11a51c9ebb09 3294 // increase byte index by [chunkSize]
mducrocq 0:11a51c9ebb09 3295 i += chunkSize;
mducrocq 0:11a51c9ebb09 3296
mducrocq 0:11a51c9ebb09 3297 // uint8_t automatically wraps to 0 at 256
mducrocq 0:11a51c9ebb09 3298 address += chunkSize;
mducrocq 0:11a51c9ebb09 3299
mducrocq 0:11a51c9ebb09 3300 // if we aren't done, update bank (if necessary) and address
mducrocq 0:11a51c9ebb09 3301 if (i < dataSize) {
mducrocq 0:11a51c9ebb09 3302 if (address == 0) bank++;
mducrocq 0:11a51c9ebb09 3303 setMemoryBank(bank);
mducrocq 0:11a51c9ebb09 3304 setMemoryStartAddress(address);
mducrocq 0:11a51c9ebb09 3305 }
mducrocq 0:11a51c9ebb09 3306 }
mducrocq 0:11a51c9ebb09 3307 if (verify) free(verifyBuffer);
mducrocq 0:11a51c9ebb09 3308 if (useProgMem) free(progBuffer);
mducrocq 0:11a51c9ebb09 3309 return true;
mducrocq 0:11a51c9ebb09 3310 }
mducrocq 0:11a51c9ebb09 3311 bool MPU6050::writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify)
mducrocq 0:11a51c9ebb09 3312 {
mducrocq 0:11a51c9ebb09 3313 return writeMemoryBlock(data, dataSize, bank, address, verify, true);
mducrocq 0:11a51c9ebb09 3314 }
mducrocq 0:11a51c9ebb09 3315 bool MPU6050::writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize, bool useProgMem)
mducrocq 0:11a51c9ebb09 3316 {
mducrocq 0:11a51c9ebb09 3317 uint8_t *progBuffer, success, special;
mducrocq 0:11a51c9ebb09 3318 uint16_t i, j;
mducrocq 0:11a51c9ebb09 3319 if (useProgMem) {
mducrocq 0:11a51c9ebb09 3320 progBuffer = (uint8_t *)malloc(8); // assume 8-byte blocks, realloc later if necessary
mducrocq 0:11a51c9ebb09 3321 }
mducrocq 0:11a51c9ebb09 3322
mducrocq 0:11a51c9ebb09 3323 // config set data is a long string of blocks with the following structure:
mducrocq 0:11a51c9ebb09 3324 // [bank] [offset] [length] [byte[0], byte[1], ..., byte[length]]
mducrocq 0:11a51c9ebb09 3325 uint8_t bank, offset, length;
mducrocq 0:11a51c9ebb09 3326 for (i = 0; i < dataSize;) {
mducrocq 0:11a51c9ebb09 3327 if (useProgMem) {
mducrocq 0:11a51c9ebb09 3328 bank = pgm_read_byte(data + i++);
mducrocq 0:11a51c9ebb09 3329 offset = pgm_read_byte(data + i++);
mducrocq 0:11a51c9ebb09 3330 length = pgm_read_byte(data + i++);
mducrocq 0:11a51c9ebb09 3331 } else {
mducrocq 0:11a51c9ebb09 3332 bank = data[i++];
mducrocq 0:11a51c9ebb09 3333 offset = data[i++];
mducrocq 0:11a51c9ebb09 3334 length = data[i++];
mducrocq 0:11a51c9ebb09 3335 }
mducrocq 0:11a51c9ebb09 3336
mducrocq 0:11a51c9ebb09 3337 // write data or perform special action
mducrocq 0:11a51c9ebb09 3338 if (length > 0) {
mducrocq 0:11a51c9ebb09 3339 // regular block of data to write
mducrocq 0:11a51c9ebb09 3340 /*Serial.print("Writing config block to bank ");
mducrocq 0:11a51c9ebb09 3341 Serial.print(bank);
mducrocq 0:11a51c9ebb09 3342 Serial.print(", offset ");
mducrocq 0:11a51c9ebb09 3343 Serial.print(offset);
mducrocq 0:11a51c9ebb09 3344 Serial.print(", length=");
mducrocq 0:11a51c9ebb09 3345 Serial.println(length);*/
mducrocq 0:11a51c9ebb09 3346 if (useProgMem) {
mducrocq 0:11a51c9ebb09 3347 if (sizeof(progBuffer) < length) progBuffer = (uint8_t *)realloc(progBuffer, length);
mducrocq 0:11a51c9ebb09 3348 for (j = 0; j < length; j++) progBuffer[j] = pgm_read_byte(data + i + j);
mducrocq 0:11a51c9ebb09 3349 } else {
mducrocq 0:11a51c9ebb09 3350 progBuffer = (uint8_t *)data + i;
mducrocq 0:11a51c9ebb09 3351 }
mducrocq 0:11a51c9ebb09 3352 success = writeMemoryBlock(progBuffer, length, bank, offset, true);
mducrocq 0:11a51c9ebb09 3353 i += length;
mducrocq 0:11a51c9ebb09 3354 } else {
mducrocq 0:11a51c9ebb09 3355 // special instruction
mducrocq 0:11a51c9ebb09 3356 // NOTE: this kind of behavior (what and when to do certain things)
mducrocq 0:11a51c9ebb09 3357 // is totally undocumented. This code is in here based on observed
mducrocq 0:11a51c9ebb09 3358 // behavior only, and exactly why (or even whether) it has to be here
mducrocq 0:11a51c9ebb09 3359 // is anybody's guess for now.
mducrocq 0:11a51c9ebb09 3360 if (useProgMem) {
mducrocq 0:11a51c9ebb09 3361 special = pgm_read_byte(data + i++);
mducrocq 0:11a51c9ebb09 3362 } else {
mducrocq 0:11a51c9ebb09 3363 special = data[i++];
mducrocq 0:11a51c9ebb09 3364 }
mducrocq 0:11a51c9ebb09 3365 /*Serial.print("Special command code ");
mducrocq 0:11a51c9ebb09 3366 Serial.print(special, HEX);
mducrocq 0:11a51c9ebb09 3367 Serial.println(" found...");*/
mducrocq 0:11a51c9ebb09 3368 if (special == 0x01) {
mducrocq 0:11a51c9ebb09 3369 // enable DMP-related interrupts
mducrocq 0:11a51c9ebb09 3370
mducrocq 0:11a51c9ebb09 3371 //setIntZeroMotionEnabled(true);
mducrocq 0:11a51c9ebb09 3372 //setIntFIFOBufferOverflowEnabled(true);
mducrocq 0:11a51c9ebb09 3373 //setIntDMPEnabled(true);
mducrocq 0:11a51c9ebb09 3374 i2Cdev.writeByte(devAddr, MPU6050_RA_INT_ENABLE, 0x32); // single operation
mducrocq 0:11a51c9ebb09 3375
mducrocq 0:11a51c9ebb09 3376 success = true;
mducrocq 0:11a51c9ebb09 3377 } else {
mducrocq 0:11a51c9ebb09 3378 // unknown special command
mducrocq 0:11a51c9ebb09 3379 success = false;
mducrocq 0:11a51c9ebb09 3380 }
mducrocq 0:11a51c9ebb09 3381 }
mducrocq 0:11a51c9ebb09 3382
mducrocq 0:11a51c9ebb09 3383 if (!success) {
mducrocq 0:11a51c9ebb09 3384 if (useProgMem) free(progBuffer);
mducrocq 0:11a51c9ebb09 3385 return false; // uh oh
mducrocq 0:11a51c9ebb09 3386 }
mducrocq 0:11a51c9ebb09 3387 }
mducrocq 0:11a51c9ebb09 3388 if (useProgMem) free(progBuffer);
mducrocq 0:11a51c9ebb09 3389 return true;
mducrocq 0:11a51c9ebb09 3390 }
mducrocq 0:11a51c9ebb09 3391 bool MPU6050::writeProgDMPConfigurationSet(const uint8_t *data, uint16_t dataSize)
mducrocq 0:11a51c9ebb09 3392 {
mducrocq 0:11a51c9ebb09 3393 return writeDMPConfigurationSet(data, dataSize, false);
mducrocq 0:11a51c9ebb09 3394 }
mducrocq 0:11a51c9ebb09 3395
mducrocq 0:11a51c9ebb09 3396 // DMP_CFG_1 register
mducrocq 0:11a51c9ebb09 3397
mducrocq 0:11a51c9ebb09 3398 uint8_t MPU6050::getDMPConfig1()
mducrocq 0:11a51c9ebb09 3399 {
mducrocq 0:11a51c9ebb09 3400 i2Cdev.readByte(devAddr, MPU6050_RA_DMP_CFG_1, buffer);
mducrocq 0:11a51c9ebb09 3401 return buffer[0];
mducrocq 0:11a51c9ebb09 3402 }
mducrocq 0:11a51c9ebb09 3403 void MPU6050::setDMPConfig1(uint8_t config)
mducrocq 0:11a51c9ebb09 3404 {
mducrocq 0:11a51c9ebb09 3405 i2Cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_1, config);
mducrocq 0:11a51c9ebb09 3406 }
mducrocq 0:11a51c9ebb09 3407
mducrocq 0:11a51c9ebb09 3408 // DMP_CFG_2 register
mducrocq 0:11a51c9ebb09 3409
mducrocq 0:11a51c9ebb09 3410 uint8_t MPU6050::getDMPConfig2()
mducrocq 0:11a51c9ebb09 3411 {
mducrocq 0:11a51c9ebb09 3412 i2Cdev.readByte(devAddr, MPU6050_RA_DMP_CFG_2, buffer);
mducrocq 0:11a51c9ebb09 3413 return buffer[0];
mducrocq 0:11a51c9ebb09 3414 }
mducrocq 0:11a51c9ebb09 3415 void MPU6050::setDMPConfig2(uint8_t config)
mducrocq 0:11a51c9ebb09 3416 {
mducrocq 0:11a51c9ebb09 3417 i2Cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_2, config);
mducrocq 0:11a51c9ebb09 3418 }