Akash Vibhute / MPU6050_DMP_Nucleo-I2Cdev

Dependents:   MPU9150_nucleo_i2cdev Orion_newPCB_test_LV Orion_PCB_test_Faulhaber_gr41_wptcmd_V1 MPU9150_nucleo_i2cdev ... more

Fork of MPU6050-DMP-Ian by Ian Hua

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MPU6050.cpp Source File

MPU6050.cpp

00001 //ported from arduino library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050
00002 //written by szymon gaertig (email: szymon@gaertig.com.pl)
00003 //
00004 //Changelog:
00005 //2013-01-08 - first beta release
00006  
00007 // I2Cdev library collection - MPU6050 I2C device class
00008 // Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
00009 // 8/24/2011 by Jeff Rowberg <jeff@rowberg.net>
00010 // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
00011 //
00012 // Changelog:
00013 //     ... - ongoing debug release
00014  
00015 // NOTE: THIS IS ONLY A PARIAL RELEASE. THIS DEVICE CLASS IS CURRENTLY UNDERGOING ACTIVE
00016 // DEVELOPMENT AND IS STILL MISSING SOME IMPORTANT FEATURES. PLEASE KEEP THIS IN MIND IF
00017 // YOU DECIDE TO USE THIS PARTICULAR CODE FOR ANYTHING.
00018  
00019 /* ============================================
00020 I2Cdev device library code is placed under the MIT license
00021 Copyright (c) 2012 Jeff Rowberg
00022  
00023 Permission is hereby granted, free of charge, to any person obtaining a copy
00024 of this software and associated documentation files (the "Software"), to deal
00025 in the Software without restriction, including without limitation the rights
00026 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00027 copies of the Software, and to permit persons to whom the Software is
00028 furnished to do so, subject to the following conditions:
00029  
00030 The above copyright notice and this permission notice shall be included in
00031 all copies or substantial portions of the Software.
00032  
00033 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00034 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00035 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00036 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00037 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00038 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00039 THE SOFTWARE.
00040 ===============================================
00041 */
00042 
00043 #include "MPU6050.h"
00044 
00045 #define useDebugSerial
00046 
00047 //instead of using pgmspace.h
00048 typedef const unsigned char prog_uchar;
00049 #define pgm_read_byte_near(x) (*(prog_uchar*)(x))//<- I modified here
00050 #define pgm_read_byte(x) (*(prog_uchar*)(x))//<- I modified here
00051 
00052 /** Default constructor, uses default I2C address.
00053  * @see MPU6050_DEFAULT_ADDRESS
00054  */
00055 MPU6050::MPU6050() : debugSerial(USBTX, USBRX)
00056 {
00057     devAddr = MPU6050_DEFAULT_ADDRESS;
00058 }
00059 
00060 MPU6050::MPU6050(PinName i2cSDA, PinName i2cSCL) : i2Cdev(i2cSDA, i2cSCL), debugSerial(USBTX, USBRX)
00061 {
00062     devAddr = MPU6050_DEFAULT_ADDRESS;
00063 }
00064 
00065 /** Specific address constructor.
00066  * @param address I2C address
00067  * @see MPU6050_DEFAULT_ADDRESS
00068  * @see MPU6050_ADDRESS_AD0_LOW
00069  * @see MPU6050_ADDRESS_AD0_HIGH
00070  */
00071 MPU6050::MPU6050(uint8_t address) : debugSerial(USBTX, USBRX)
00072 {
00073     devAddr = address;
00074 }
00075 
00076 /** Power on and prepare for general usage.
00077  * This will activate the device and take it out of sleep mode (which must be done
00078  * after start-up). This function also sets both the accelerometer and the gyroscope
00079  * to their most sensitive settings, namely +/- 2g and +/- 250 degrees/sec, and sets
00080  * the clock source to use the X Gyro for reference, which is slightly better than
00081  * the default internal clock source.
00082  */
00083 void MPU6050::initialize()
00084 {
00085 #ifdef useDebugSerial
00086     debugSerial.printf("MPU6050::initialize start\n");
00087 #endif
00088 
00089     //setClockSource(MPU6050_CLOCK_PLL_XGYRO);
00090     //setFullScaleGyroRange(MPU6050_GYRO_FS_250);
00091     //setFullScaleAccelRange(MPU6050_ACCEL_FS_2);
00092     setSleepEnabled(false); // thanks to Jack Elston for pointing this one out!
00093 
00094 #ifdef useDebugSerial
00095     debugSerial.printf("MPU6050::initialize end\n");
00096 #endif
00097 }
00098 
00099 /** Verify the I2C connection.
00100  * Make sure the device is connected and responds as expected.
00101  * @return True if connection is valid, false otherwise
00102  */
00103 bool MPU6050::testConnection()
00104 {
00105 #ifdef useDebugSerial
00106     debugSerial.printf("MPU6050::testConnection start\n");
00107 #endif
00108     uint8_t deviceId = getDeviceID();
00109 #ifdef useDebugSerial
00110     debugSerial.printf("DeviceId = %d\n",deviceId);
00111 #endif
00112     return deviceId == 0x34;
00113 }
00114 
00115 // AUX_VDDIO register (InvenSense demo code calls this RA_*G_OFFS_TC)
00116 
00117 /** Get the auxiliary I2C supply voltage level.
00118  * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to
00119  * 0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to
00120  * the MPU-6000, which does not have a VLOGIC pin.
00121  * @return I2C supply voltage level (0=VLOGIC, 1=VDD)
00122  */
00123 uint8_t MPU6050::getAuxVDDIOLevel()
00124 {
00125     i2Cdev.readBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, buffer);
00126     return buffer[0];
00127 }
00128 /** Set the auxiliary I2C supply voltage level.
00129  * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to
00130  * 0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to
00131  * the MPU-6000, which does not have a VLOGIC pin.
00132  * @param level I2C supply voltage level (0=VLOGIC, 1=VDD)
00133  */
00134 void MPU6050::setAuxVDDIOLevel(uint8_t level)
00135 {
00136     i2Cdev.writeBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, level);
00137 }
00138 
00139 // SMPLRT_DIV register
00140 
00141 /** Get gyroscope output rate divider.
00142  * The sensor register output, FIFO output, DMP sampling, Motion detection, Zero
00143  * Motion detection, and Free Fall detection are all based on the Sample Rate.
00144  * The Sample Rate is generated by dividing the gyroscope output rate by
00145  * SMPLRT_DIV:
00146  *
00147  * Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
00148  *
00149  * where Gyroscope Output Rate = 8kHz when the DLPF is disabled (DLPF_CFG = 0 or
00150  * 7), and 1kHz when the DLPF is enabled (see Register 26).
00151  *
00152  * Note: The accelerometer output rate is 1kHz. This means that for a Sample
00153  * Rate greater than 1kHz, the same accelerometer sample may be output to the
00154  * FIFO, DMP, and sensor registers more than once.
00155  *
00156  * For a diagram of the gyroscope and accelerometer signal paths, see Section 8
00157  * of the MPU-6000/MPU-6050 Product Specification document.
00158  *
00159  * @return Current sample rate
00160  * @see MPU6050_RA_SMPLRT_DIV
00161  */
00162 uint8_t MPU6050::getRate()
00163 {
00164     i2Cdev.readByte(devAddr, MPU6050_RA_SMPLRT_DIV, buffer);
00165     return buffer[0];
00166 }
00167 /** Set gyroscope sample rate divider.
00168  * @param rate New sample rate divider
00169  * @see getRate()
00170  * @see MPU6050_RA_SMPLRT_DIV
00171  */
00172 void MPU6050::setRate(uint8_t rate)
00173 {
00174     i2Cdev.writeByte(devAddr, MPU6050_RA_SMPLRT_DIV, rate);
00175 }
00176 
00177 // CONFIG register
00178 
00179 /** Get external FSYNC configuration.
00180  * Configures the external Frame Synchronization (FSYNC) pin sampling. An
00181  * external signal connected to the FSYNC pin can be sampled by configuring
00182  * EXT_SYNC_SET. Signal changes to the FSYNC pin are latched so that short
00183  * strobes may be captured. The latched FSYNC signal will be sampled at the
00184  * Sampling Rate, as defined in register 25. After sampling, the latch will
00185  * reset to the current FSYNC signal state.
00186  *
00187  * The sampled value will be reported in place of the least significant bit in
00188  * a sensor data register determined by the value of EXT_SYNC_SET according to
00189  * the following table.
00190  *
00191  * <pre>
00192  * EXT_SYNC_SET | FSYNC Bit Location
00193  * -------------+-------------------
00194  * 0            | Input disabled
00195  * 1            | TEMP_OUT_L[0]
00196  * 2            | GYRO_XOUT_L[0]
00197  * 3            | GYRO_YOUT_L[0]
00198  * 4            | GYRO_ZOUT_L[0]
00199  * 5            | ACCEL_XOUT_L[0]
00200  * 6            | ACCEL_YOUT_L[0]
00201  * 7            | ACCEL_ZOUT_L[0]
00202  * </pre>
00203  *
00204  * @return FSYNC configuration value
00205  */
00206 uint8_t MPU6050::getExternalFrameSync()
00207 {
00208     i2Cdev.readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, buffer);
00209     return buffer[0];
00210 }
00211 /** Set external FSYNC configuration.
00212  * @see getExternalFrameSync()
00213  * @see MPU6050_RA_CONFIG
00214  * @param sync New FSYNC configuration value
00215  */
00216 void MPU6050::setExternalFrameSync(uint8_t sync)
00217 {
00218     i2Cdev.writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, sync);
00219 }
00220 /** Get digital low-pass filter configuration.
00221  * The DLPF_CFG parameter sets the digital low pass filter configuration. It
00222  * also determines the internal sampling rate used by the device as shown in
00223  * the table below.
00224  *
00225  * Note: The accelerometer output rate is 1kHz. This means that for a Sample
00226  * Rate greater than 1kHz, the same accelerometer sample may be output to the
00227  * FIFO, DMP, and sensor registers more than once.
00228  *
00229  * <pre>
00230  *          |   ACCELEROMETER    |           GYROSCOPE
00231  * DLPF_CFG | Bandwidth | Delay  | Bandwidth | Delay  | Sample Rate
00232  * ---------+-----------+--------+-----------+--------+-------------
00233  * 0        | 260Hz     | 0ms    | 256Hz     | 0.98ms | 8kHz
00234  * 1        | 184Hz     | 2.0ms  | 188Hz     | 1.9ms  | 1kHz
00235  * 2        | 94Hz      | 3.0ms  | 98Hz      | 2.8ms  | 1kHz
00236  * 3        | 44Hz      | 4.9ms  | 42Hz      | 4.8ms  | 1kHz
00237  * 4        | 21Hz      | 8.5ms  | 20Hz      | 8.3ms  | 1kHz
00238  * 5        | 10Hz      | 13.8ms | 10Hz      | 13.4ms | 1kHz
00239  * 6        | 5Hz       | 19.0ms | 5Hz       | 18.6ms | 1kHz
00240  * 7        |   -- Reserved --   |   -- Reserved --   | Reserved
00241  * </pre>
00242  *
00243  * @return DLFP configuration
00244  * @see MPU6050_RA_CONFIG
00245  * @see MPU6050_CFG_DLPF_CFG_BIT
00246  * @see MPU6050_CFG_DLPF_CFG_LENGTH
00247  */
00248 uint8_t MPU6050::getDLPFMode()
00249 {
00250     i2Cdev.readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, buffer);
00251     return buffer[0];
00252 }
00253 /** Set digital low-pass filter configuration.
00254  * @param mode New DLFP configuration setting
00255  * @see getDLPFBandwidth()
00256  * @see MPU6050_DLPF_BW_256
00257  * @see MPU6050_RA_CONFIG
00258  * @see MPU6050_CFG_DLPF_CFG_BIT
00259  * @see MPU6050_CFG_DLPF_CFG_LENGTH
00260  */
00261 void MPU6050::setDLPFMode(uint8_t mode)
00262 {
00263     i2Cdev.writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, mode);
00264 }
00265 
00266 // GYRO_CONFIG register
00267 
00268 /** Get full-scale gyroscope range.
00269  * The FS_SEL parameter allows setting the full-scale range of the gyro sensors,
00270  * as described in the table below.
00271  *
00272  * <pre>
00273  * 0 = +/- 250 degrees/sec
00274  * 1 = +/- 500 degrees/sec
00275  * 2 = +/- 1000 degrees/sec
00276  * 3 = +/- 2000 degrees/sec
00277  * </pre>
00278  *
00279  * @return Current full-scale gyroscope range setting
00280  * @see MPU6050_GYRO_FS_250
00281  * @see MPU6050_RA_GYRO_CONFIG
00282  * @see MPU6050_GCONFIG_FS_SEL_BIT
00283  * @see MPU6050_GCONFIG_FS_SEL_LENGTH
00284  */
00285 uint8_t MPU6050::getFullScaleGyroRange()
00286 {
00287     i2Cdev.readBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, buffer);
00288     return buffer[0];
00289 }
00290 /** Set full-scale gyroscope range.
00291  * @param range New full-scale gyroscope range value
00292  * @see getFullScaleRange()
00293  * @see MPU6050_GYRO_FS_250
00294  * @see MPU6050_RA_GYRO_CONFIG
00295  * @see MPU6050_GCONFIG_FS_SEL_BIT
00296  * @see MPU6050_GCONFIG_FS_SEL_LENGTH
00297  */
00298 void MPU6050::setFullScaleGyroRange(uint8_t range)
00299 {
00300     i2Cdev.writeBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, range);
00301 }
00302 
00303 // ACCEL_CONFIG register
00304 
00305 /** Get self-test enabled setting for accelerometer X axis.
00306  * @return Self-test enabled value
00307  * @see MPU6050_RA_ACCEL_CONFIG
00308  */
00309 bool MPU6050::getAccelXSelfTest()
00310 {
00311     i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, buffer);
00312     return buffer[0];
00313 }
00314 /** Get self-test enabled setting for accelerometer X axis.
00315  * @param enabled Self-test enabled value
00316  * @see MPU6050_RA_ACCEL_CONFIG
00317  */
00318 void MPU6050::setAccelXSelfTest(bool enabled)
00319 {
00320     i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, enabled);
00321 }
00322 /** Get self-test enabled value for accelerometer Y axis.
00323  * @return Self-test enabled value
00324  * @see MPU6050_RA_ACCEL_CONFIG
00325  */
00326 bool MPU6050::getAccelYSelfTest()
00327 {
00328     i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, buffer);
00329     return buffer[0];
00330 }
00331 /** Get self-test enabled value for accelerometer Y axis.
00332  * @param enabled Self-test enabled value
00333  * @see MPU6050_RA_ACCEL_CONFIG
00334  */
00335 void MPU6050::setAccelYSelfTest(bool enabled)
00336 {
00337     i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, enabled);
00338 }
00339 /** Get self-test enabled value for accelerometer Z axis.
00340  * @return Self-test enabled value
00341  * @see MPU6050_RA_ACCEL_CONFIG
00342  */
00343 bool MPU6050::getAccelZSelfTest()
00344 {
00345     i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, buffer);
00346     return buffer[0];
00347 }
00348 /** Set self-test enabled value for accelerometer Z axis.
00349  * @param enabled Self-test enabled value
00350  * @see MPU6050_RA_ACCEL_CONFIG
00351  */
00352 void MPU6050::setAccelZSelfTest(bool enabled)
00353 {
00354     i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, enabled);
00355 }
00356 /** Get full-scale accelerometer range.
00357  * The FS_SEL parameter allows setting the full-scale range of the accelerometer
00358  * sensors, as described in the table below.
00359  *
00360  * <pre>
00361  * 0 = +/- 2g
00362  * 1 = +/- 4g
00363  * 2 = +/- 8g
00364  * 3 = +/- 16g
00365  * </pre>
00366  *
00367  * @return Current full-scale accelerometer range setting
00368  * @see MPU6050_ACCEL_FS_2
00369  * @see MPU6050_RA_ACCEL_CONFIG
00370  * @see MPU6050_ACONFIG_AFS_SEL_BIT
00371  * @see MPU6050_ACONFIG_AFS_SEL_LENGTH
00372  */
00373 uint8_t MPU6050::getFullScaleAccelRange()
00374 {
00375     i2Cdev.readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, buffer);
00376     return buffer[0];
00377 }
00378 /** Set full-scale accelerometer range.
00379  * @param range New full-scale accelerometer range setting
00380  * @see getFullScaleAccelRange()
00381  */
00382 void MPU6050::setFullScaleAccelRange(uint8_t range)
00383 {
00384     i2Cdev.writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, range);
00385 }
00386 /** Get the high-pass filter configuration.
00387  * The DHPF is a filter module in the path leading to motion detectors (Free
00388  * Fall, Motion threshold, and Zero Motion). The high pass filter output is not
00389  * available to the data registers (see Figure in Section 8 of the MPU-6000/
00390  * MPU-6050 Product Specification document).
00391  *
00392  * The high pass filter has three modes:
00393  *
00394  * <pre>
00395  *    Reset: The filter output settles to zero within one sample. This
00396  *           effectively disables the high pass filter. This mode may be toggled
00397  *           to quickly settle the filter.
00398  *
00399  *    On:    The high pass filter will pass signals above the cut off frequency.
00400  *
00401  *    Hold:  When triggered, the filter holds the present sample. The filter
00402  *           output will be the difference between the input sample and the held
00403  *           sample.
00404  * </pre>
00405  *
00406  * <pre>
00407  * ACCEL_HPF | Filter Mode | Cut-off Frequency
00408  * ----------+-------------+------------------
00409  * 0         | Reset       | None
00410  * 1         | On          | 5Hz
00411  * 2         | On          | 2.5Hz
00412  * 3         | On          | 1.25Hz
00413  * 4         | On          | 0.63Hz
00414  * 7         | Hold        | None
00415  * </pre>
00416  *
00417  * @return Current high-pass filter configuration
00418  * @see MPU6050_DHPF_RESET
00419  * @see MPU6050_RA_ACCEL_CONFIG
00420  */
00421 uint8_t MPU6050::getDHPFMode()
00422 {
00423     i2Cdev.readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, buffer);
00424     return buffer[0];
00425 }
00426 /** Set the high-pass filter configuration.
00427  * @param bandwidth New high-pass filter configuration
00428  * @see setDHPFMode()
00429  * @see MPU6050_DHPF_RESET
00430  * @see MPU6050_RA_ACCEL_CONFIG
00431  */
00432 void MPU6050::setDHPFMode(uint8_t bandwidth)
00433 {
00434     i2Cdev.writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, bandwidth);
00435 }
00436 
00437 // FF_THR register
00438 
00439 /** Get free-fall event acceleration threshold.
00440  * This register configures the detection threshold for Free Fall event
00441  * detection. The unit of FF_THR is 1LSB = 2mg. Free Fall is detected when the
00442  * absolute value of the accelerometer measurements for the three axes are each
00443  * less than the detection threshold. This condition increments the Free Fall
00444  * duration counter (Register 30). The Free Fall interrupt is triggered when the
00445  * Free Fall duration counter reaches the time specified in FF_DUR.
00446  *
00447  * For more details on the Free Fall detection interrupt, see Section 8.2 of the
00448  * MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and
00449  * 58 of this document.
00450  *
00451  * @return Current free-fall acceleration threshold value (LSB = 2mg)
00452  * @see MPU6050_RA_FF_THR
00453  */
00454 uint8_t MPU6050::getFreefallDetectionThreshold()
00455 {
00456     i2Cdev.readByte(devAddr, MPU6050_RA_FF_THR, buffer);
00457     return buffer[0];
00458 }
00459 /** Get free-fall event acceleration threshold.
00460  * @param threshold New free-fall acceleration threshold value (LSB = 2mg)
00461  * @see getFreefallDetectionThreshold()
00462  * @see MPU6050_RA_FF_THR
00463  */
00464 void MPU6050::setFreefallDetectionThreshold(uint8_t threshold)
00465 {
00466     i2Cdev.writeByte(devAddr, MPU6050_RA_FF_THR, threshold);
00467 }
00468 
00469 // FF_DUR register
00470 
00471 /** Get free-fall event duration threshold.
00472  * This register configures the duration counter threshold for Free Fall event
00473  * detection. The duration counter ticks at 1kHz, therefore FF_DUR has a unit
00474  * of 1 LSB = 1 ms.
00475  *
00476  * The Free Fall duration counter increments while the absolute value of the
00477  * accelerometer measurements are each less than the detection threshold
00478  * (Register 29). The Free Fall interrupt is triggered when the Free Fall
00479  * duration counter reaches the time specified in this register.
00480  *
00481  * For more details on the Free Fall detection interrupt, see Section 8.2 of
00482  * the MPU-6000/MPU-6050 Product Specification document as well as Registers 56
00483  * and 58 of this document.
00484  *
00485  * @return Current free-fall duration threshold value (LSB = 1ms)
00486  * @see MPU6050_RA_FF_DUR
00487  */
00488 uint8_t MPU6050::getFreefallDetectionDuration()
00489 {
00490     i2Cdev.readByte(devAddr, MPU6050_RA_FF_DUR, buffer);
00491     return buffer[0];
00492 }
00493 /** Get free-fall event duration threshold.
00494  * @param duration New free-fall duration threshold value (LSB = 1ms)
00495  * @see getFreefallDetectionDuration()
00496  * @see MPU6050_RA_FF_DUR
00497  */
00498 void MPU6050::setFreefallDetectionDuration(uint8_t duration)
00499 {
00500     i2Cdev.writeByte(devAddr, MPU6050_RA_FF_DUR, duration);
00501 }
00502 
00503 // MOT_THR register
00504 
00505 /** Get motion detection event acceleration threshold.
00506  * This register configures the detection threshold for Motion interrupt
00507  * generation. The unit of MOT_THR is 1LSB = 2mg. Motion is detected when the
00508  * absolute value of any of the accelerometer measurements exceeds this Motion
00509  * detection threshold. This condition increments the Motion detection duration
00510  * counter (Register 32). The Motion detection interrupt is triggered when the
00511  * Motion Detection counter reaches the time count specified in MOT_DUR
00512  * (Register 32).
00513  *
00514  * The Motion interrupt will indicate the axis and polarity of detected motion
00515  * in MOT_DETECT_STATUS (Register 97).
00516  *
00517  * For more details on the Motion detection interrupt, see Section 8.3 of the
00518  * MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and
00519  * 58 of this document.
00520  *
00521  * @return Current motion detection acceleration threshold value (LSB = 2mg)
00522  * @see MPU6050_RA_MOT_THR
00523  */
00524 uint8_t MPU6050::getMotionDetectionThreshold()
00525 {
00526     i2Cdev.readByte(devAddr, MPU6050_RA_MOT_THR, buffer);
00527     return buffer[0];
00528 }
00529 /** Set free-fall event acceleration threshold.
00530  * @param threshold New motion detection acceleration threshold value (LSB = 2mg)
00531  * @see getMotionDetectionThreshold()
00532  * @see MPU6050_RA_MOT_THR
00533  */
00534 void MPU6050::setMotionDetectionThreshold(uint8_t threshold)
00535 {
00536     i2Cdev.writeByte(devAddr, MPU6050_RA_MOT_THR, threshold);
00537 }
00538 
00539 // MOT_DUR register
00540 
00541 /** Get motion detection event duration threshold.
00542  * This register configures the duration counter threshold for Motion interrupt
00543  * generation. The duration counter ticks at 1 kHz, therefore MOT_DUR has a unit
00544  * of 1LSB = 1ms. The Motion detection duration counter increments when the
00545  * absolute value of any of the accelerometer measurements exceeds the Motion
00546  * detection threshold (Register 31). The Motion detection interrupt is
00547  * triggered when the Motion detection counter reaches the time count specified
00548  * in this register.
00549  *
00550  * For more details on the Motion detection interrupt, see Section 8.3 of the
00551  * MPU-6000/MPU-6050 Product Specification document.
00552  *
00553  * @return Current motion detection duration threshold value (LSB = 1ms)
00554  * @see MPU6050_RA_MOT_DUR
00555  */
00556 uint8_t MPU6050::getMotionDetectionDuration()
00557 {
00558     i2Cdev.readByte(devAddr, MPU6050_RA_MOT_DUR, buffer);
00559     return buffer[0];
00560 }
00561 /** Set motion detection event duration threshold.
00562  * @param duration New motion detection duration threshold value (LSB = 1ms)
00563  * @see getMotionDetectionDuration()
00564  * @see MPU6050_RA_MOT_DUR
00565  */
00566 void MPU6050::setMotionDetectionDuration(uint8_t duration)
00567 {
00568     i2Cdev.writeByte(devAddr, MPU6050_RA_MOT_DUR, duration);
00569 }
00570 
00571 // ZRMOT_THR register
00572 
00573 /** Get zero motion detection event acceleration threshold.
00574  * This register configures the detection threshold for Zero Motion interrupt
00575  * generation. The unit of ZRMOT_THR is 1LSB = 2mg. Zero Motion is detected when
00576  * the absolute value of the accelerometer measurements for the 3 axes are each
00577  * less than the detection threshold. This condition increments the Zero Motion
00578  * duration counter (Register 34). The Zero Motion interrupt is triggered when
00579  * the Zero Motion duration counter reaches the time count specified in
00580  * ZRMOT_DUR (Register 34).
00581  *
00582  * Unlike Free Fall or Motion detection, Zero Motion detection triggers an
00583  * interrupt both when Zero Motion is first detected and when Zero Motion is no
00584  * longer detected.
00585  *
00586  * When a zero motion event is detected, a Zero Motion Status will be indicated
00587  * in the MOT_DETECT_STATUS register (Register 97). When a motion-to-zero-motion
00588  * condition is detected, the status bit is set to 1. When a zero-motion-to-
00589  * motion condition is detected, the status bit is set to 0.
00590  *
00591  * For more details on the Zero Motion detection interrupt, see Section 8.4 of
00592  * the MPU-6000/MPU-6050 Product Specification document as well as Registers 56
00593  * and 58 of this document.
00594  *
00595  * @return Current zero motion detection acceleration threshold value (LSB = 2mg)
00596  * @see MPU6050_RA_ZRMOT_THR
00597  */
00598 uint8_t MPU6050::getZeroMotionDetectionThreshold()
00599 {
00600     i2Cdev.readByte(devAddr, MPU6050_RA_ZRMOT_THR, buffer);
00601     return buffer[0];
00602 }
00603 /** Set zero motion detection event acceleration threshold.
00604  * @param threshold New zero motion detection acceleration threshold value (LSB = 2mg)
00605  * @see getZeroMotionDetectionThreshold()
00606  * @see MPU6050_RA_ZRMOT_THR
00607  */
00608 void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold)
00609 {
00610     i2Cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_THR, threshold);
00611 }
00612 
00613 // ZRMOT_DUR register
00614 
00615 /** Get zero motion detection event duration threshold.
00616  * This register configures the duration counter threshold for Zero Motion
00617  * interrupt generation. The duration counter ticks at 16 Hz, therefore
00618  * ZRMOT_DUR has a unit of 1 LSB = 64 ms. The Zero Motion duration counter
00619  * increments while the absolute value of the accelerometer measurements are
00620  * each less than the detection threshold (Register 33). The Zero Motion
00621  * interrupt is triggered when the Zero Motion duration counter reaches the time
00622  * count specified in this register.
00623  *
00624  * For more details on the Zero Motion detection interrupt, see Section 8.4 of
00625  * the MPU-6000/MPU-6050 Product Specification document, as well as Registers 56
00626  * and 58 of this document.
00627  *
00628  * @return Current zero motion detection duration threshold value (LSB = 64ms)
00629  * @see MPU6050_RA_ZRMOT_DUR
00630  */
00631 uint8_t MPU6050::getZeroMotionDetectionDuration()
00632 {
00633     i2Cdev.readByte(devAddr, MPU6050_RA_ZRMOT_DUR, buffer);
00634     return buffer[0];
00635 }
00636 /** Set zero motion detection event duration threshold.
00637  * @param duration New zero motion detection duration threshold value (LSB = 1ms)
00638  * @see getZeroMotionDetectionDuration()
00639  * @see MPU6050_RA_ZRMOT_DUR
00640  */
00641 void MPU6050::setZeroMotionDetectionDuration(uint8_t duration)
00642 {
00643     i2Cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_DUR, duration);
00644 }
00645 
00646 // FIFO_EN register
00647 
00648 /** Get temperature FIFO enabled value.
00649  * When set to 1, this bit enables TEMP_OUT_H and TEMP_OUT_L (Registers 65 and
00650  * 66) to be written into the FIFO buffer.
00651  * @return Current temperature FIFO enabled value
00652  * @see MPU6050_RA_FIFO_EN
00653  */
00654 bool MPU6050::getTempFIFOEnabled()
00655 {
00656     i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, buffer);
00657     return buffer[0];
00658 }
00659 /** Set temperature FIFO enabled value.
00660  * @param enabled New temperature FIFO enabled value
00661  * @see getTempFIFOEnabled()
00662  * @see MPU6050_RA_FIFO_EN
00663  */
00664 void MPU6050::setTempFIFOEnabled(bool enabled)
00665 {
00666     i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, enabled);
00667 }
00668 /** Get gyroscope X-axis FIFO enabled value.
00669  * When set to 1, this bit enables GYRO_XOUT_H and GYRO_XOUT_L (Registers 67 and
00670  * 68) to be written into the FIFO buffer.
00671  * @return Current gyroscope X-axis FIFO enabled value
00672  * @see MPU6050_RA_FIFO_EN
00673  */
00674 bool MPU6050::getXGyroFIFOEnabled()
00675 {
00676     i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, buffer);
00677     return buffer[0];
00678 }
00679 /** Set gyroscope X-axis FIFO enabled value.
00680  * @param enabled New gyroscope X-axis FIFO enabled value
00681  * @see getXGyroFIFOEnabled()
00682  * @see MPU6050_RA_FIFO_EN
00683  */
00684 void MPU6050::setXGyroFIFOEnabled(bool enabled)
00685 {
00686     i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, enabled);
00687 }
00688 /** Get gyroscope Y-axis FIFO enabled value.
00689  * When set to 1, this bit enables GYRO_YOUT_H and GYRO_YOUT_L (Registers 69 and
00690  * 70) to be written into the FIFO buffer.
00691  * @return Current gyroscope Y-axis FIFO enabled value
00692  * @see MPU6050_RA_FIFO_EN
00693  */
00694 bool MPU6050::getYGyroFIFOEnabled()
00695 {
00696     i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, buffer);
00697     return buffer[0];
00698 }
00699 /** Set gyroscope Y-axis FIFO enabled value.
00700  * @param enabled New gyroscope Y-axis FIFO enabled value
00701  * @see getYGyroFIFOEnabled()
00702  * @see MPU6050_RA_FIFO_EN
00703  */
00704 void MPU6050::setYGyroFIFOEnabled(bool enabled)
00705 {
00706     i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, enabled);
00707 }
00708 /** Get gyroscope Z-axis FIFO enabled value.
00709  * When set to 1, this bit enables GYRO_ZOUT_H and GYRO_ZOUT_L (Registers 71 and
00710  * 72) to be written into the FIFO buffer.
00711  * @return Current gyroscope Z-axis FIFO enabled value
00712  * @see MPU6050_RA_FIFO_EN
00713  */
00714 bool MPU6050::getZGyroFIFOEnabled()
00715 {
00716     i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, buffer);
00717     return buffer[0];
00718 }
00719 /** Set gyroscope Z-axis FIFO enabled value.
00720  * @param enabled New gyroscope Z-axis FIFO enabled value
00721  * @see getZGyroFIFOEnabled()
00722  * @see MPU6050_RA_FIFO_EN
00723  */
00724 void MPU6050::setZGyroFIFOEnabled(bool enabled)
00725 {
00726     i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, enabled);
00727 }
00728 /** Get accelerometer FIFO enabled value.
00729  * When set to 1, this bit enables ACCEL_XOUT_H, ACCEL_XOUT_L, ACCEL_YOUT_H,
00730  * ACCEL_YOUT_L, ACCEL_ZOUT_H, and ACCEL_ZOUT_L (Registers 59 to 64) to be
00731  * written into the FIFO buffer.
00732  * @return Current accelerometer FIFO enabled value
00733  * @see MPU6050_RA_FIFO_EN
00734  */
00735 bool MPU6050::getAccelFIFOEnabled()
00736 {
00737     i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, buffer);
00738     return buffer[0];
00739 }
00740 /** Set accelerometer FIFO enabled value.
00741  * @param enabled New accelerometer FIFO enabled value
00742  * @see getAccelFIFOEnabled()
00743  * @see MPU6050_RA_FIFO_EN
00744  */
00745 void MPU6050::setAccelFIFOEnabled(bool enabled)
00746 {
00747     i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, enabled);
00748 }
00749 /** Get Slave 2 FIFO enabled value.
00750  * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
00751  * associated with Slave 2 to be written into the FIFO buffer.
00752  * @return Current Slave 2 FIFO enabled value
00753  * @see MPU6050_RA_FIFO_EN
00754  */
00755 bool MPU6050::getSlave2FIFOEnabled()
00756 {
00757     i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, buffer);
00758     return buffer[0];
00759 }
00760 /** Set Slave 2 FIFO enabled value.
00761  * @param enabled New Slave 2 FIFO enabled value
00762  * @see getSlave2FIFOEnabled()
00763  * @see MPU6050_RA_FIFO_EN
00764  */
00765 void MPU6050::setSlave2FIFOEnabled(bool enabled)
00766 {
00767     i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, enabled);
00768 }
00769 /** Get Slave 1 FIFO enabled value.
00770  * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
00771  * associated with Slave 1 to be written into the FIFO buffer.
00772  * @return Current Slave 1 FIFO enabled value
00773  * @see MPU6050_RA_FIFO_EN
00774  */
00775 bool MPU6050::getSlave1FIFOEnabled()
00776 {
00777     i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, buffer);
00778     return buffer[0];
00779 }
00780 /** Set Slave 1 FIFO enabled value.
00781  * @param enabled New Slave 1 FIFO enabled value
00782  * @see getSlave1FIFOEnabled()
00783  * @see MPU6050_RA_FIFO_EN
00784  */
00785 void MPU6050::setSlave1FIFOEnabled(bool enabled)
00786 {
00787     i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, enabled);
00788 }
00789 /** Get Slave 0 FIFO enabled value.
00790  * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
00791  * associated with Slave 0 to be written into the FIFO buffer.
00792  * @return Current Slave 0 FIFO enabled value
00793  * @see MPU6050_RA_FIFO_EN
00794  */
00795 bool MPU6050::getSlave0FIFOEnabled()
00796 {
00797     i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, buffer);
00798     return buffer[0];
00799 }
00800 /** Set Slave 0 FIFO enabled value.
00801  * @param enabled New Slave 0 FIFO enabled value
00802  * @see getSlave0FIFOEnabled()
00803  * @see MPU6050_RA_FIFO_EN
00804  */
00805 void MPU6050::setSlave0FIFOEnabled(bool enabled)
00806 {
00807     i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, enabled);
00808 }
00809 
00810 // I2C_MST_CTRL register
00811 
00812 /** Get multi-master enabled value.
00813  * Multi-master capability allows multiple I2C masters to operate on the same
00814  * bus. In circuits where multi-master capability is required, set MULT_MST_EN
00815  * to 1. This will increase current drawn by approximately 30uA.
00816  *
00817  * In circuits where multi-master capability is required, the state of the I2C
00818  * bus must always be monitored by each separate I2C Master. Before an I2C
00819  * Master can assume arbitration of the bus, it must first confirm that no other
00820  * I2C Master has arbitration of the bus. When MULT_MST_EN is set to 1, the
00821  * MPU-60X0's bus arbitration detection logic is turned on, enabling it to
00822  * detect when the bus is available.
00823  *
00824  * @return Current multi-master enabled value
00825  * @see MPU6050_RA_I2C_MST_CTRL
00826  */
00827 bool MPU6050::getMultiMasterEnabled()
00828 {
00829     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, buffer);
00830     return buffer[0];
00831 }
00832 /** Set multi-master enabled value.
00833  * @param enabled New multi-master enabled value
00834  * @see getMultiMasterEnabled()
00835  * @see MPU6050_RA_I2C_MST_CTRL
00836  */
00837 void MPU6050::setMultiMasterEnabled(bool enabled)
00838 {
00839     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, enabled);
00840 }
00841 /** Get wait-for-external-sensor-data enabled value.
00842  * When the WAIT_FOR_ES bit is set to 1, the Data Ready interrupt will be
00843  * delayed until External Sensor data from the Slave Devices are loaded into the
00844  * EXT_SENS_DATA registers. This is used to ensure that both the internal sensor
00845  * data (i.e. from gyro and accel) and external sensor data have been loaded to
00846  * their respective data registers (i.e. the data is synced) when the Data Ready
00847  * interrupt is triggered.
00848  *
00849  * @return Current wait-for-external-sensor-data enabled value
00850  * @see MPU6050_RA_I2C_MST_CTRL
00851  */
00852 bool MPU6050::getWaitForExternalSensorEnabled()
00853 {
00854     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, buffer);
00855     return buffer[0];
00856 }
00857 /** Set wait-for-external-sensor-data enabled value.
00858  * @param enabled New wait-for-external-sensor-data enabled value
00859  * @see getWaitForExternalSensorEnabled()
00860  * @see MPU6050_RA_I2C_MST_CTRL
00861  */
00862 void MPU6050::setWaitForExternalSensorEnabled(bool enabled)
00863 {
00864     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, enabled);
00865 }
00866 /** Get Slave 3 FIFO enabled value.
00867  * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
00868  * associated with Slave 3 to be written into the FIFO buffer.
00869  * @return Current Slave 3 FIFO enabled value
00870  * @see MPU6050_RA_MST_CTRL
00871  */
00872 bool MPU6050::getSlave3FIFOEnabled()
00873 {
00874     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, buffer);
00875     return buffer[0];
00876 }
00877 /** Set Slave 3 FIFO enabled value.
00878  * @param enabled New Slave 3 FIFO enabled value
00879  * @see getSlave3FIFOEnabled()
00880  * @see MPU6050_RA_MST_CTRL
00881  */
00882 void MPU6050::setSlave3FIFOEnabled(bool enabled)
00883 {
00884     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, enabled);
00885 }
00886 /** Get slave read/write transition enabled value.
00887  * The I2C_MST_P_NSR bit configures the I2C Master's transition from one slave
00888  * read to the next slave read. If the bit equals 0, there will be a restart
00889  * between reads. If the bit equals 1, there will be a stop followed by a start
00890  * of the following read. When a write transaction follows a read transaction,
00891  * the stop followed by a start of the successive write will be always used.
00892  *
00893  * @return Current slave read/write transition enabled value
00894  * @see MPU6050_RA_I2C_MST_CTRL
00895  */
00896 bool MPU6050::getSlaveReadWriteTransitionEnabled()
00897 {
00898     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, buffer);
00899     return buffer[0];
00900 }
00901 /** Set slave read/write transition enabled value.
00902  * @param enabled New slave read/write transition enabled value
00903  * @see getSlaveReadWriteTransitionEnabled()
00904  * @see MPU6050_RA_I2C_MST_CTRL
00905  */
00906 void MPU6050::setSlaveReadWriteTransitionEnabled(bool enabled)
00907 {
00908     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, enabled);
00909 }
00910 /** Get I2C master clock speed.
00911  * I2C_MST_CLK is a 4 bit unsigned value which configures a divider on the
00912  * MPU-60X0 internal 8MHz clock. It sets the I2C master clock speed according to
00913  * the following table:
00914  *
00915  * <pre>
00916  * I2C_MST_CLK | I2C Master Clock Speed | 8MHz Clock Divider
00917  * ------------+------------------------+-------------------
00918  * 0           | 348kHz                 | 23
00919  * 1           | 333kHz                 | 24
00920  * 2           | 320kHz                 | 25
00921  * 3           | 308kHz                 | 26
00922  * 4           | 296kHz                 | 27
00923  * 5           | 286kHz                 | 28
00924  * 6           | 276kHz                 | 29
00925  * 7           | 267kHz                 | 30
00926  * 8           | 258kHz                 | 31
00927  * 9           | 500kHz                 | 16
00928  * 10          | 471kHz                 | 17
00929  * 11          | 444kHz                 | 18
00930  * 12          | 421kHz                 | 19
00931  * 13          | 400kHz                 | 20
00932  * 14          | 381kHz                 | 21
00933  * 15          | 364kHz                 | 22
00934  * </pre>
00935  *
00936  * @return Current I2C master clock speed
00937  * @see MPU6050_RA_I2C_MST_CTRL
00938  */
00939 uint8_t MPU6050::getMasterClockSpeed()
00940 {
00941     i2Cdev.readBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, buffer);
00942     return buffer[0];
00943 }
00944 /** Set I2C master clock speed.
00945  * @reparam speed Current I2C master clock speed
00946  * @see MPU6050_RA_I2C_MST_CTRL
00947  */
00948 void MPU6050::setMasterClockSpeed(uint8_t speed)
00949 {
00950     i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, speed);
00951 }
00952 
00953 // I2C_SLV* registers (Slave 0-3)
00954 
00955 /** Get the I2C address of the specified slave (0-3).
00956  * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read
00957  * operation, and if it is cleared, then it's a write operation. The remaining
00958  * bits (6-0) are the 7-bit device address of the slave device.
00959  *
00960  * In read mode, the result of the read is placed in the lowest available
00961  * EXT_SENS_DATA register. For further information regarding the allocation of
00962  * read results, please refer to the EXT_SENS_DATA register description
00963  * (Registers 73 - 96).
00964  *
00965  * The MPU-6050 supports a total of five slaves, but Slave 4 has unique
00966  * characteristics, and so it has its own functions (getSlave4* and setSlave4*).
00967  *
00968  * I2C data transactions are performed at the Sample Rate, as defined in
00969  * Register 25. The user is responsible for ensuring that I2C data transactions
00970  * to and from each enabled Slave can be completed within a single period of the
00971  * Sample Rate.
00972  *
00973  * The I2C slave access rate can be reduced relative to the Sample Rate. This
00974  * reduced access rate is determined by I2C_MST_DLY (Register 52). Whether a
00975  * slave's access rate is reduced relative to the Sample Rate is determined by
00976  * I2C_MST_DELAY_CTRL (Register 103).
00977  *
00978  * The processing order for the slaves is fixed. The sequence followed for
00979  * processing the slaves is Slave 0, Slave 1, Slave 2, Slave 3 and Slave 4. If a
00980  * particular Slave is disabled it will be skipped.
00981  *
00982  * Each slave can either be accessed at the sample rate or at a reduced sample
00983  * rate. In a case where some slaves are accessed at the Sample Rate and some
00984  * slaves are accessed at the reduced rate, the sequence of accessing the slaves
00985  * (Slave 0 to Slave 4) is still followed. However, the reduced rate slaves will
00986  * be skipped if their access rate dictates that they should not be accessed
00987  * during that particular cycle. For further information regarding the reduced
00988  * access rate, please refer to Register 52. Whether a slave is accessed at the
00989  * Sample Rate or at the reduced rate is determined by the Delay Enable bits in
00990  * Register 103.
00991  *
00992  * @param num Slave number (0-3)
00993  * @return Current address for specified slave
00994  * @see MPU6050_RA_I2C_SLV0_ADDR
00995  */
00996 uint8_t MPU6050::getSlaveAddress(uint8_t num)
00997 {
00998     if (num > 3) return 0;
00999     i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, buffer);
01000     return buffer[0];
01001 }
01002 /** Set the I2C address of the specified slave (0-3).
01003  * @param num Slave number (0-3)
01004  * @param address New address for specified slave
01005  * @see getSlaveAddress()
01006  * @see MPU6050_RA_I2C_SLV0_ADDR
01007  */
01008 void MPU6050::setSlaveAddress(uint8_t num, uint8_t address)
01009 {
01010     if (num > 3) return;
01011     i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, address);
01012 }
01013 /** Get the active internal register for the specified slave (0-3).
01014  * Read/write operations for this slave will be done to whatever internal
01015  * register address is stored in this MPU register.
01016  *
01017  * The MPU-6050 supports a total of five slaves, but Slave 4 has unique
01018  * characteristics, and so it has its own functions.
01019  *
01020  * @param num Slave number (0-3)
01021  * @return Current active register for specified slave
01022  * @see MPU6050_RA_I2C_SLV0_REG
01023  */
01024 uint8_t MPU6050::getSlaveRegister(uint8_t num)
01025 {
01026     if (num > 3) return 0;
01027     i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, buffer);
01028     return buffer[0];
01029 }
01030 /** Set the active internal register for the specified slave (0-3).
01031  * @param num Slave number (0-3)
01032  * @param reg New active register for specified slave
01033  * @see getSlaveRegister()
01034  * @see MPU6050_RA_I2C_SLV0_REG
01035  */
01036 void MPU6050::setSlaveRegister(uint8_t num, uint8_t reg)
01037 {
01038     if (num > 3) return;
01039     i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, reg);
01040 }
01041 /** Get the enabled value for the specified slave (0-3).
01042  * When set to 1, this bit enables Slave 0 for data transfer operations. When
01043  * cleared to 0, this bit disables Slave 0 from data transfer operations.
01044  * @param num Slave number (0-3)
01045  * @return Current enabled value for specified slave
01046  * @see MPU6050_RA_I2C_SLV0_CTRL
01047  */
01048 bool MPU6050::getSlaveEnabled(uint8_t num)
01049 {
01050     if (num > 3) return 0;
01051     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, buffer);
01052     return buffer[0];
01053 }
01054 /** Set the enabled value for the specified slave (0-3).
01055  * @param num Slave number (0-3)
01056  * @param enabled New enabled value for specified slave
01057  * @see getSlaveEnabled()
01058  * @see MPU6050_RA_I2C_SLV0_CTRL
01059  */
01060 void MPU6050::setSlaveEnabled(uint8_t num, bool enabled)
01061 {
01062     if (num > 3) return;
01063     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, enabled);
01064 }
01065 /** Get word pair byte-swapping enabled for the specified slave (0-3).
01066  * When set to 1, this bit enables byte swapping. When byte swapping is enabled,
01067  * the high and low bytes of a word pair are swapped. Please refer to
01068  * I2C_SLV0_GRP for the pairing convention of the word pairs. When cleared to 0,
01069  * bytes transferred to and from Slave 0 will be written to EXT_SENS_DATA
01070  * registers in the order they were transferred.
01071  *
01072  * @param num Slave number (0-3)
01073  * @return Current word pair byte-swapping enabled value for specified slave
01074  * @see MPU6050_RA_I2C_SLV0_CTRL
01075  */
01076 bool MPU6050::getSlaveWordByteSwap(uint8_t num)
01077 {
01078     if (num > 3) return 0;
01079     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, buffer);
01080     return buffer[0];
01081 }
01082 /** Set word pair byte-swapping enabled for the specified slave (0-3).
01083  * @param num Slave number (0-3)
01084  * @param enabled New word pair byte-swapping enabled value for specified slave
01085  * @see getSlaveWordByteSwap()
01086  * @see MPU6050_RA_I2C_SLV0_CTRL
01087  */
01088 void MPU6050::setSlaveWordByteSwap(uint8_t num, bool enabled)
01089 {
01090     if (num > 3) return;
01091     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, enabled);
01092 }
01093 /** Get write mode for the specified slave (0-3).
01094  * When set to 1, the transaction will read or write data only. When cleared to
01095  * 0, the transaction will write a register address prior to reading or writing
01096  * data. This should equal 0 when specifying the register address within the
01097  * Slave device to/from which the ensuing data transaction will take place.
01098  *
01099  * @param num Slave number (0-3)
01100  * @return Current write mode for specified slave (0 = register address + data, 1 = data only)
01101  * @see MPU6050_RA_I2C_SLV0_CTRL
01102  */
01103 bool MPU6050::getSlaveWriteMode(uint8_t num)
01104 {
01105     if (num > 3) return 0;
01106     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, buffer);
01107     return buffer[0];
01108 }
01109 /** Set write mode for the specified slave (0-3).
01110  * @param num Slave number (0-3)
01111  * @param mode New write mode for specified slave (0 = register address + data, 1 = data only)
01112  * @see getSlaveWriteMode()
01113  * @see MPU6050_RA_I2C_SLV0_CTRL
01114  */
01115 void MPU6050::setSlaveWriteMode(uint8_t num, bool mode)
01116 {
01117     if (num > 3) return;
01118     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, mode);
01119 }
01120 /** Get word pair grouping order offset for the specified slave (0-3).
01121  * This sets specifies the grouping order of word pairs received from registers.
01122  * When cleared to 0, bytes from register addresses 0 and 1, 2 and 3, etc (even,
01123  * then odd register addresses) are paired to form a word. When set to 1, bytes
01124  * from register addresses are paired 1 and 2, 3 and 4, etc. (odd, then even
01125  * register addresses) are paired to form a word.
01126  *
01127  * @param num Slave number (0-3)
01128  * @return Current word pair grouping order offset for specified slave
01129  * @see MPU6050_RA_I2C_SLV0_CTRL
01130  */
01131 bool MPU6050::getSlaveWordGroupOffset(uint8_t num)
01132 {
01133     if (num > 3) return 0;
01134     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, buffer);
01135     return buffer[0];
01136 }
01137 /** Set word pair grouping order offset for the specified slave (0-3).
01138  * @param num Slave number (0-3)
01139  * @param enabled New word pair grouping order offset for specified slave
01140  * @see getSlaveWordGroupOffset()
01141  * @see MPU6050_RA_I2C_SLV0_CTRL
01142  */
01143 void MPU6050::setSlaveWordGroupOffset(uint8_t num, bool enabled)
01144 {
01145     if (num > 3) return;
01146     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, enabled);
01147 }
01148 /** Get number of bytes to read for the specified slave (0-3).
01149  * Specifies the number of bytes transferred to and from Slave 0. Clearing this
01150  * bit to 0 is equivalent to disabling the register by writing 0 to I2C_SLV0_EN.
01151  * @param num Slave number (0-3)
01152  * @return Number of bytes to read for specified slave
01153  * @see MPU6050_RA_I2C_SLV0_CTRL
01154  */
01155 uint8_t MPU6050::getSlaveDataLength(uint8_t num)
01156 {
01157     if (num > 3) return 0;
01158     i2Cdev.readBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, buffer);
01159     return buffer[0];
01160 }
01161 /** Set number of bytes to read for the specified slave (0-3).
01162  * @param num Slave number (0-3)
01163  * @param length Number of bytes to read for specified slave
01164  * @see getSlaveDataLength()
01165  * @see MPU6050_RA_I2C_SLV0_CTRL
01166  */
01167 void MPU6050::setSlaveDataLength(uint8_t num, uint8_t length)
01168 {
01169     if (num > 3) return;
01170     i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, length);
01171 }
01172 
01173 // I2C_SLV* registers (Slave 4)
01174 
01175 /** Get the I2C address of Slave 4.
01176  * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read
01177  * operation, and if it is cleared, then it's a write operation. The remaining
01178  * bits (6-0) are the 7-bit device address of the slave device.
01179  *
01180  * @return Current address for Slave 4
01181  * @see getSlaveAddress()
01182  * @see MPU6050_RA_I2C_SLV4_ADDR
01183  */
01184 uint8_t MPU6050::getSlave4Address()
01185 {
01186     i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, buffer);
01187     return buffer[0];
01188 }
01189 /** Set the I2C address of Slave 4.
01190  * @param address New address for Slave 4
01191  * @see getSlave4Address()
01192  * @see MPU6050_RA_I2C_SLV4_ADDR
01193  */
01194 void MPU6050::setSlave4Address(uint8_t address)
01195 {
01196     i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, address);
01197 }
01198 /** Get the active internal register for the Slave 4.
01199  * Read/write operations for this slave will be done to whatever internal
01200  * register address is stored in this MPU register.
01201  *
01202  * @return Current active register for Slave 4
01203  * @see MPU6050_RA_I2C_SLV4_REG
01204  */
01205 uint8_t MPU6050::getSlave4Register()
01206 {
01207     i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_REG, buffer);
01208     return buffer[0];
01209 }
01210 /** Set the active internal register for Slave 4.
01211  * @param reg New active register for Slave 4
01212  * @see getSlave4Register()
01213  * @see MPU6050_RA_I2C_SLV4_REG
01214  */
01215 void MPU6050::setSlave4Register(uint8_t reg)
01216 {
01217     i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_REG, reg);
01218 }
01219 /** Set new byte to write to Slave 4.
01220  * This register stores the data to be written into the Slave 4. If I2C_SLV4_RW
01221  * is set 1 (set to read), this register has no effect.
01222  * @param data New byte to write to Slave 4
01223  * @see MPU6050_RA_I2C_SLV4_DO
01224  */
01225 void MPU6050::setSlave4OutputByte(uint8_t data)
01226 {
01227     i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_DO, data);
01228 }
01229 /** Get the enabled value for the Slave 4.
01230  * When set to 1, this bit enables Slave 4 for data transfer operations. When
01231  * cleared to 0, this bit disables Slave 4 from data transfer operations.
01232  * @return Current enabled value for Slave 4
01233  * @see MPU6050_RA_I2C_SLV4_CTRL
01234  */
01235 bool MPU6050::getSlave4Enabled()
01236 {
01237     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, buffer);
01238     return buffer[0];
01239 }
01240 /** Set the enabled value for Slave 4.
01241  * @param enabled New enabled value for Slave 4
01242  * @see getSlave4Enabled()
01243  * @see MPU6050_RA_I2C_SLV4_CTRL
01244  */
01245 void MPU6050::setSlave4Enabled(bool enabled)
01246 {
01247     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, enabled);
01248 }
01249 /** Get the enabled value for Slave 4 transaction interrupts.
01250  * When set to 1, this bit enables the generation of an interrupt signal upon
01251  * completion of a Slave 4 transaction. When cleared to 0, this bit disables the
01252  * generation of an interrupt signal upon completion of a Slave 4 transaction.
01253  * The interrupt status can be observed in Register 54.
01254  *
01255  * @return Current enabled value for Slave 4 transaction interrupts.
01256  * @see MPU6050_RA_I2C_SLV4_CTRL
01257  */
01258 bool MPU6050::getSlave4InterruptEnabled()
01259 {
01260     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, buffer);
01261     return buffer[0];
01262 }
01263 /** Set the enabled value for Slave 4 transaction interrupts.
01264  * @param enabled New enabled value for Slave 4 transaction interrupts.
01265  * @see getSlave4InterruptEnabled()
01266  * @see MPU6050_RA_I2C_SLV4_CTRL
01267  */
01268 void MPU6050::setSlave4InterruptEnabled(bool enabled)
01269 {
01270     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, enabled);
01271 }
01272 /** Get write mode for Slave 4.
01273  * When set to 1, the transaction will read or write data only. When cleared to
01274  * 0, the transaction will write a register address prior to reading or writing
01275  * data. This should equal 0 when specifying the register address within the
01276  * Slave device to/from which the ensuing data transaction will take place.
01277  *
01278  * @return Current write mode for Slave 4 (0 = register address + data, 1 = data only)
01279  * @see MPU6050_RA_I2C_SLV4_CTRL
01280  */
01281 bool MPU6050::getSlave4WriteMode()
01282 {
01283     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, buffer);
01284     return buffer[0];
01285 }
01286 /** Set write mode for the Slave 4.
01287  * @param mode New write mode for Slave 4 (0 = register address + data, 1 = data only)
01288  * @see getSlave4WriteMode()
01289  * @see MPU6050_RA_I2C_SLV4_CTRL
01290  */
01291 void MPU6050::setSlave4WriteMode(bool mode)
01292 {
01293     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, mode);
01294 }
01295 /** Get Slave 4 master delay value.
01296  * This configures the reduced access rate of I2C slaves relative to the Sample
01297  * Rate. When a slave's access rate is decreased relative to the Sample Rate,
01298  * the slave is accessed every:
01299  *
01300  *     1 / (1 + I2C_MST_DLY) samples
01301  *
01302  * This base Sample Rate in turn is determined by SMPLRT_DIV (register 25) and
01303  * DLPF_CFG (register 26). Whether a slave's access rate is reduced relative to
01304  * the Sample Rate is determined by I2C_MST_DELAY_CTRL (register 103). For
01305  * further information regarding the Sample Rate, please refer to register 25.
01306  *
01307  * @return Current Slave 4 master delay value
01308  * @see MPU6050_RA_I2C_SLV4_CTRL
01309  */
01310 uint8_t MPU6050::getSlave4MasterDelay()
01311 {
01312     i2Cdev.readBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, buffer);
01313     return buffer[0];
01314 }
01315 /** Set Slave 4 master delay value.
01316  * @param delay New Slave 4 master delay value
01317  * @see getSlave4MasterDelay()
01318  * @see MPU6050_RA_I2C_SLV4_CTRL
01319  */
01320 void MPU6050::setSlave4MasterDelay(uint8_t delay)
01321 {
01322     i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, delay);
01323 }
01324 /** Get last available byte read from Slave 4.
01325  * This register stores the data read from Slave 4. This field is populated
01326  * after a read transaction.
01327  * @return Last available byte read from to Slave 4
01328  * @see MPU6050_RA_I2C_SLV4_DI
01329  */
01330 uint8_t MPU6050::getSlate4InputByte()
01331 {
01332     i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_DI, buffer);
01333     return buffer[0];
01334 }
01335 
01336 // I2C_MST_STATUS register
01337 
01338 /** Get FSYNC interrupt status.
01339  * This bit reflects the status of the FSYNC interrupt from an external device
01340  * into the MPU-60X0. This is used as a way to pass an external interrupt
01341  * through the MPU-60X0 to the host application processor. When set to 1, this
01342  * bit will cause an interrupt if FSYNC_INT_EN is asserted in INT_PIN_CFG
01343  * (Register 55).
01344  * @return FSYNC interrupt status
01345  * @see MPU6050_RA_I2C_MST_STATUS
01346  */
01347 bool MPU6050::getPassthroughStatus()
01348 {
01349     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_PASS_THROUGH_BIT, buffer);
01350     return buffer[0];
01351 }
01352 /** Get Slave 4 transaction done status.
01353  * Automatically sets to 1 when a Slave 4 transaction has completed. This
01354  * triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register
01355  * (Register 56) is asserted and if the SLV_4_DONE_INT bit is asserted in the
01356  * I2C_SLV4_CTRL register (Register 52).
01357  * @return Slave 4 transaction done status
01358  * @see MPU6050_RA_I2C_MST_STATUS
01359  */
01360 bool MPU6050::getSlave4IsDone()
01361 {
01362     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_DONE_BIT, buffer);
01363     return buffer[0];
01364 }
01365 /** Get master arbitration lost status.
01366  * This bit automatically sets to 1 when the I2C Master has lost arbitration of
01367  * the auxiliary I2C bus (an error condition). This triggers an interrupt if the
01368  * I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.
01369  * @return Master arbitration lost status
01370  * @see MPU6050_RA_I2C_MST_STATUS
01371  */
01372 bool MPU6050::getLostArbitration()
01373 {
01374     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_LOST_ARB_BIT, buffer);
01375     return buffer[0];
01376 }
01377 /** Get Slave 4 NACK status.
01378  * This bit automatically sets to 1 when the I2C Master receives a NACK in a
01379  * transaction with Slave 4. This triggers an interrupt if the I2C_MST_INT_EN
01380  * bit in the INT_ENABLE register (Register 56) is asserted.
01381  * @return Slave 4 NACK interrupt status
01382  * @see MPU6050_RA_I2C_MST_STATUS
01383  */
01384 bool MPU6050::getSlave4Nack()
01385 {
01386     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_NACK_BIT, buffer);
01387     return buffer[0];
01388 }
01389 /** Get Slave 3 NACK status.
01390  * This bit automatically sets to 1 when the I2C Master receives a NACK in a
01391  * transaction with Slave 3. This triggers an interrupt if the I2C_MST_INT_EN
01392  * bit in the INT_ENABLE register (Register 56) is asserted.
01393  * @return Slave 3 NACK interrupt status
01394  * @see MPU6050_RA_I2C_MST_STATUS
01395  */
01396 bool MPU6050::getSlave3Nack()
01397 {
01398     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV3_NACK_BIT, buffer);
01399     return buffer[0];
01400 }
01401 /** Get Slave 2 NACK status.
01402  * This bit automatically sets to 1 when the I2C Master receives a NACK in a
01403  * transaction with Slave 2. This triggers an interrupt if the I2C_MST_INT_EN
01404  * bit in the INT_ENABLE register (Register 56) is asserted.
01405  * @return Slave 2 NACK interrupt status
01406  * @see MPU6050_RA_I2C_MST_STATUS
01407  */
01408 bool MPU6050::getSlave2Nack()
01409 {
01410     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV2_NACK_BIT, buffer);
01411     return buffer[0];
01412 }
01413 /** Get Slave 1 NACK status.
01414  * This bit automatically sets to 1 when the I2C Master receives a NACK in a
01415  * transaction with Slave 1. This triggers an interrupt if the I2C_MST_INT_EN
01416  * bit in the INT_ENABLE register (Register 56) is asserted.
01417  * @return Slave 1 NACK interrupt status
01418  * @see MPU6050_RA_I2C_MST_STATUS
01419  */
01420 bool MPU6050::getSlave1Nack()
01421 {
01422     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV1_NACK_BIT, buffer);
01423     return buffer[0];
01424 }
01425 /** Get Slave 0 NACK status.
01426  * This bit automatically sets to 1 when the I2C Master receives a NACK in a
01427  * transaction with Slave 0. This triggers an interrupt if the I2C_MST_INT_EN
01428  * bit in the INT_ENABLE register (Register 56) is asserted.
01429  * @return Slave 0 NACK interrupt status
01430  * @see MPU6050_RA_I2C_MST_STATUS
01431  */
01432 bool MPU6050::getSlave0Nack()
01433 {
01434     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV0_NACK_BIT, buffer);
01435     return buffer[0];
01436 }
01437 
01438 // INT_PIN_CFG register
01439 
01440 /** Get interrupt logic level mode.
01441  * Will be set 0 for active-high, 1 for active-low.
01442  * @return Current interrupt mode (0=active-high, 1=active-low)
01443  * @see MPU6050_RA_INT_PIN_CFG
01444  * @see MPU6050_INTCFG_INT_LEVEL_BIT
01445  */
01446 bool MPU6050::getInterruptMode()
01447 {
01448     i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, buffer);
01449     return buffer[0];
01450 }
01451 /** Set interrupt logic level mode.
01452  * @param mode New interrupt mode (0=active-high, 1=active-low)
01453  * @see getInterruptMode()
01454  * @see MPU6050_RA_INT_PIN_CFG
01455  * @see MPU6050_INTCFG_INT_LEVEL_BIT
01456  */
01457 void MPU6050::setInterruptMode(bool mode)
01458 {
01459     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, mode);
01460 }
01461 /** Get interrupt drive mode.
01462  * Will be set 0 for push-pull, 1 for open-drain.
01463  * @return Current interrupt drive mode (0=push-pull, 1=open-drain)
01464  * @see MPU6050_RA_INT_PIN_CFG
01465  * @see MPU6050_INTCFG_INT_OPEN_BIT
01466  */
01467 bool MPU6050::getInterruptDrive()
01468 {
01469     i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, buffer);
01470     return buffer[0];
01471 }
01472 /** Set interrupt drive mode.
01473  * @param drive New interrupt drive mode (0=push-pull, 1=open-drain)
01474  * @see getInterruptDrive()
01475  * @see MPU6050_RA_INT_PIN_CFG
01476  * @see MPU6050_INTCFG_INT_OPEN_BIT
01477  */
01478 void MPU6050::setInterruptDrive(bool drive)
01479 {
01480     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, drive);
01481 }
01482 /** Get interrupt latch mode.
01483  * Will be set 0 for 50us-pulse, 1 for latch-until-int-cleared.
01484  * @return Current latch mode (0=50us-pulse, 1=latch-until-int-cleared)
01485  * @see MPU6050_RA_INT_PIN_CFG
01486  * @see MPU6050_INTCFG_LATCH_INT_EN_BIT
01487  */
01488 bool MPU6050::getInterruptLatch()
01489 {
01490     i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, buffer);
01491     return buffer[0];
01492 }
01493 /** Set interrupt latch mode.
01494  * @param latch New latch mode (0=50us-pulse, 1=latch-until-int-cleared)
01495  * @see getInterruptLatch()
01496  * @see MPU6050_RA_INT_PIN_CFG
01497  * @see MPU6050_INTCFG_LATCH_INT_EN_BIT
01498  */
01499 void MPU6050::setInterruptLatch(bool latch)
01500 {
01501     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, latch);
01502 }
01503 /** Get interrupt latch clear mode.
01504  * Will be set 0 for status-read-only, 1 for any-register-read.
01505  * @return Current latch clear mode (0=status-read-only, 1=any-register-read)
01506  * @see MPU6050_RA_INT_PIN_CFG
01507  * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT
01508  */
01509 bool MPU6050::getInterruptLatchClear()
01510 {
01511     i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, buffer);
01512     return buffer[0];
01513 }
01514 /** Set interrupt latch clear mode.
01515  * @param clear New latch clear mode (0=status-read-only, 1=any-register-read)
01516  * @see getInterruptLatchClear()
01517  * @see MPU6050_RA_INT_PIN_CFG
01518  * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT
01519  */
01520 void MPU6050::setInterruptLatchClear(bool clear)
01521 {
01522     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, clear);
01523 }
01524 /** Get FSYNC interrupt logic level mode.
01525  * @return Current FSYNC interrupt mode (0=active-high, 1=active-low)
01526  * @see getFSyncInterruptMode()
01527  * @see MPU6050_RA_INT_PIN_CFG
01528  * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT
01529  */
01530 bool MPU6050::getFSyncInterruptLevel()
01531 {
01532     i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, buffer);
01533     return buffer[0];
01534 }
01535 /** Set FSYNC interrupt logic level mode.
01536  * @param mode New FSYNC interrupt mode (0=active-high, 1=active-low)
01537  * @see getFSyncInterruptMode()
01538  * @see MPU6050_RA_INT_PIN_CFG
01539  * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT
01540  */
01541 void MPU6050::setFSyncInterruptLevel(bool level)
01542 {
01543     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, level);
01544 }
01545 /** Get FSYNC pin interrupt enabled setting.
01546  * Will be set 0 for disabled, 1 for enabled.
01547  * @return Current interrupt enabled setting
01548  * @see MPU6050_RA_INT_PIN_CFG
01549  * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT
01550  */
01551 bool MPU6050::getFSyncInterruptEnabled()
01552 {
01553     i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, buffer);
01554     return buffer[0];
01555 }
01556 /** Set FSYNC pin interrupt enabled setting.
01557  * @param enabled New FSYNC pin interrupt enabled setting
01558  * @see getFSyncInterruptEnabled()
01559  * @see MPU6050_RA_INT_PIN_CFG
01560  * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT
01561  */
01562 void MPU6050::setFSyncInterruptEnabled(bool enabled)
01563 {
01564     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, enabled);
01565 }
01566 /** Get I2C bypass enabled status.
01567  * When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to
01568  * 0, the host application processor will be able to directly access the
01569  * auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host
01570  * application processor will not be able to directly access the auxiliary I2C
01571  * bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106
01572  * bit[5]).
01573  * @return Current I2C bypass enabled status
01574  * @see MPU6050_RA_INT_PIN_CFG
01575  * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT
01576  */
01577 bool MPU6050::getI2CBypassEnabled()
01578 {
01579     i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, buffer);
01580     return buffer[0];
01581 }
01582 /** Set I2C bypass enabled status.
01583  * When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to
01584  * 0, the host application processor will be able to directly access the
01585  * auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host
01586  * application processor will not be able to directly access the auxiliary I2C
01587  * bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106
01588  * bit[5]).
01589  * @param enabled New I2C bypass enabled status
01590  * @see MPU6050_RA_INT_PIN_CFG
01591  * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT
01592  */
01593 void MPU6050::setI2CBypassEnabled(bool enabled)
01594 {
01595     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, enabled);
01596 }
01597 /** Get reference clock output enabled status.
01598  * When this bit is equal to 1, a reference clock output is provided at the
01599  * CLKOUT pin. When this bit is equal to 0, the clock output is disabled. For
01600  * further information regarding CLKOUT, please refer to the MPU-60X0 Product
01601  * Specification document.
01602  * @return Current reference clock output enabled status
01603  * @see MPU6050_RA_INT_PIN_CFG
01604  * @see MPU6050_INTCFG_CLKOUT_EN_BIT
01605  */
01606 bool MPU6050::getClockOutputEnabled()
01607 {
01608     i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, buffer);
01609     return buffer[0];
01610 }
01611 /** Set reference clock output enabled status.
01612  * When this bit is equal to 1, a reference clock output is provided at the
01613  * CLKOUT pin. When this bit is equal to 0, the clock output is disabled. For
01614  * further information regarding CLKOUT, please refer to the MPU-60X0 Product
01615  * Specification document.
01616  * @param enabled New reference clock output enabled status
01617  * @see MPU6050_RA_INT_PIN_CFG
01618  * @see MPU6050_INTCFG_CLKOUT_EN_BIT
01619  */
01620 void MPU6050::setClockOutputEnabled(bool enabled)
01621 {
01622     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, enabled);
01623 }
01624 
01625 // INT_ENABLE register
01626 
01627 /** Get full interrupt enabled status.
01628  * Full register byte for all interrupts, for quick reading. Each bit will be
01629  * set 0 for disabled, 1 for enabled.
01630  * @return Current interrupt enabled status
01631  * @see MPU6050_RA_INT_ENABLE
01632  * @see MPU6050_INTERRUPT_FF_BIT
01633  **/
01634 uint8_t MPU6050::getIntEnabled()
01635 {
01636     i2Cdev.readByte(devAddr, MPU6050_RA_INT_ENABLE, buffer);
01637     return buffer[0];
01638 }
01639 /** Set full interrupt enabled status.
01640  * Full register byte for all interrupts, for quick reading. Each bit should be
01641  * set 0 for disabled, 1 for enabled.
01642  * @param enabled New interrupt enabled status
01643  * @see getIntFreefallEnabled()
01644  * @see MPU6050_RA_INT_ENABLE
01645  * @see MPU6050_INTERRUPT_FF_BIT
01646  **/
01647 void MPU6050::setIntEnabled(uint8_t enabled)
01648 {
01649     i2Cdev.writeByte(devAddr, MPU6050_RA_INT_ENABLE, enabled);
01650 }
01651 /** Get Free Fall interrupt enabled status.
01652  * Will be set 0 for disabled, 1 for enabled.
01653  * @return Current interrupt enabled status
01654  * @see MPU6050_RA_INT_ENABLE
01655  * @see MPU6050_INTERRUPT_FF_BIT
01656  **/
01657 bool MPU6050::getIntFreefallEnabled()
01658 {
01659     i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, buffer);
01660     return buffer[0];
01661 }
01662 /** Set Free Fall interrupt enabled status.
01663  * @param enabled New interrupt enabled status
01664  * @see getIntFreefallEnabled()
01665  * @see MPU6050_RA_INT_ENABLE
01666  * @see MPU6050_INTERRUPT_FF_BIT
01667  **/
01668 void MPU6050::setIntFreefallEnabled(bool enabled)
01669 {
01670     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, enabled);
01671 }
01672 /** Get Motion Detection interrupt enabled status.
01673  * Will be set 0 for disabled, 1 for enabled.
01674  * @return Current interrupt enabled status
01675  * @see MPU6050_RA_INT_ENABLE
01676  * @see MPU6050_INTERRUPT_MOT_BIT
01677  **/
01678 bool MPU6050::getIntMotionEnabled()
01679 {
01680     i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, buffer);
01681     return buffer[0];
01682 }
01683 /** Set Motion Detection interrupt enabled status.
01684  * @param enabled New interrupt enabled status
01685  * @see getIntMotionEnabled()
01686  * @see MPU6050_RA_INT_ENABLE
01687  * @see MPU6050_INTERRUPT_MOT_BIT
01688  **/
01689 void MPU6050::setIntMotionEnabled(bool enabled)
01690 {
01691     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, enabled);
01692 }
01693 /** Get Zero Motion Detection interrupt enabled status.
01694  * Will be set 0 for disabled, 1 for enabled.
01695  * @return Current interrupt enabled status
01696  * @see MPU6050_RA_INT_ENABLE
01697  * @see MPU6050_INTERRUPT_ZMOT_BIT
01698  **/
01699 bool MPU6050::getIntZeroMotionEnabled()
01700 {
01701     i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, buffer);
01702     return buffer[0];
01703 }
01704 /** Set Zero Motion Detection interrupt enabled status.
01705  * @param enabled New interrupt enabled status
01706  * @see getIntZeroMotionEnabled()
01707  * @see MPU6050_RA_INT_ENABLE
01708  * @see MPU6050_INTERRUPT_ZMOT_BIT
01709  **/
01710 void MPU6050::setIntZeroMotionEnabled(bool enabled)
01711 {
01712     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, enabled);
01713 }
01714 /** Get FIFO Buffer Overflow interrupt enabled status.
01715  * Will be set 0 for disabled, 1 for enabled.
01716  * @return Current interrupt enabled status
01717  * @see MPU6050_RA_INT_ENABLE
01718  * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
01719  **/
01720 bool MPU6050::getIntFIFOBufferOverflowEnabled()
01721 {
01722     i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer);
01723     return buffer[0];
01724 }
01725 /** Set FIFO Buffer Overflow interrupt enabled status.
01726  * @param enabled New interrupt enabled status
01727  * @see getIntFIFOBufferOverflowEnabled()
01728  * @see MPU6050_RA_INT_ENABLE
01729  * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
01730  **/
01731 void MPU6050::setIntFIFOBufferOverflowEnabled(bool enabled)
01732 {
01733     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, enabled);
01734 }
01735 /** Get I2C Master interrupt enabled status.
01736  * This enables any of the I2C Master interrupt sources to generate an
01737  * interrupt. Will be set 0 for disabled, 1 for enabled.
01738  * @return Current interrupt enabled status
01739  * @see MPU6050_RA_INT_ENABLE
01740  * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
01741  **/
01742 bool MPU6050::getIntI2CMasterEnabled()
01743 {
01744     i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer);
01745     return buffer[0];
01746 }
01747 /** Set I2C Master interrupt enabled status.
01748  * @param enabled New interrupt enabled status
01749  * @see getIntI2CMasterEnabled()
01750  * @see MPU6050_RA_INT_ENABLE
01751  * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
01752  **/
01753 void MPU6050::setIntI2CMasterEnabled(bool enabled)
01754 {
01755     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, enabled);
01756 }
01757 /** Get Data Ready interrupt enabled setting.
01758  * This event occurs each time a write operation to all of the sensor registers
01759  * has been completed. Will be set 0 for disabled, 1 for enabled.
01760  * @return Current interrupt enabled status
01761  * @see MPU6050_RA_INT_ENABLE
01762  * @see MPU6050_INTERRUPT_DATA_RDY_BIT
01763  */
01764 bool MPU6050::getIntDataReadyEnabled()
01765 {
01766     i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer);
01767     return buffer[0];
01768 }
01769 /** Set Data Ready interrupt enabled status.
01770  * @param enabled New interrupt enabled status
01771  * @see getIntDataReadyEnabled()
01772  * @see MPU6050_RA_INT_CFG
01773  * @see MPU6050_INTERRUPT_DATA_RDY_BIT
01774  */
01775 void MPU6050::setIntDataReadyEnabled(bool enabled)
01776 {
01777     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, enabled);
01778 }
01779 
01780 // INT_STATUS register
01781 
01782 /** Get full set of interrupt status bits.
01783  * These bits clear to 0 after the register has been read. Very useful
01784  * for getting multiple INT statuses, since each single bit read clears
01785  * all of them because it has to read the whole byte.
01786  * @return Current interrupt status
01787  * @see MPU6050_RA_INT_STATUS
01788  */
01789 uint8_t MPU6050::getIntStatus()
01790 {
01791     i2Cdev.readByte(devAddr, MPU6050_RA_INT_STATUS, buffer);
01792     return buffer[0];
01793 }
01794 /** Get Free Fall interrupt status.
01795  * This bit automatically sets to 1 when a Free Fall interrupt has been
01796  * generated. The bit clears to 0 after the register has been read.
01797  * @return Current interrupt status
01798  * @see MPU6050_RA_INT_STATUS
01799  * @see MPU6050_INTERRUPT_FF_BIT
01800  */
01801 bool MPU6050::getIntFreefallStatus()
01802 {
01803     i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FF_BIT, buffer);
01804     return buffer[0];
01805 }
01806 /** Get Motion Detection interrupt status.
01807  * This bit automatically sets to 1 when a Motion Detection interrupt has been
01808  * generated. The bit clears to 0 after the register has been read.
01809  * @return Current interrupt status
01810  * @see MPU6050_RA_INT_STATUS
01811  * @see MPU6050_INTERRUPT_MOT_BIT
01812  */
01813 bool MPU6050::getIntMotionStatus()
01814 {
01815     i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_MOT_BIT, buffer);
01816     return buffer[0];
01817 }
01818 /** Get Zero Motion Detection interrupt status.
01819  * This bit automatically sets to 1 when a Zero Motion Detection interrupt has
01820  * been generated. The bit clears to 0 after the register has been read.
01821  * @return Current interrupt status
01822  * @see MPU6050_RA_INT_STATUS
01823  * @see MPU6050_INTERRUPT_ZMOT_BIT
01824  */
01825 bool MPU6050::getIntZeroMotionStatus()
01826 {
01827     i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_ZMOT_BIT, buffer);
01828     return buffer[0];
01829 }
01830 /** Get FIFO Buffer Overflow interrupt status.
01831  * This bit automatically sets to 1 when a Free Fall interrupt has been
01832  * generated. The bit clears to 0 after the register has been read.
01833  * @return Current interrupt status
01834  * @see MPU6050_RA_INT_STATUS
01835  * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
01836  */
01837 bool MPU6050::getIntFIFOBufferOverflowStatus()
01838 {
01839     i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer);
01840     return buffer[0];
01841 }
01842 /** Get I2C Master interrupt status.
01843  * This bit automatically sets to 1 when an I2C Master interrupt has been
01844  * generated. For a list of I2C Master interrupts, please refer to Register 54.
01845  * The bit clears to 0 after the register has been read.
01846  * @return Current interrupt status
01847  * @see MPU6050_RA_INT_STATUS
01848  * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
01849  */
01850 bool MPU6050::getIntI2CMasterStatus()
01851 {
01852     i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer);
01853     return buffer[0];
01854 }
01855 /** Get Data Ready interrupt status.
01856  * This bit automatically sets to 1 when a Data Ready interrupt has been
01857  * generated. The bit clears to 0 after the register has been read.
01858  * @return Current interrupt status
01859  * @see MPU6050_RA_INT_STATUS
01860  * @see MPU6050_INTERRUPT_DATA_RDY_BIT
01861  */
01862 bool MPU6050::getIntDataReadyStatus()
01863 {
01864     i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer);
01865     return buffer[0];
01866 }
01867 
01868 // ACCEL_*OUT_* registers
01869 
01870 /** Get raw 9-axis motion sensor readings (accel/gyro/compass).
01871  * FUNCTION NOT FULLY IMPLEMENTED YET.
01872  * @param ax 16-bit signed integer container for accelerometer X-axis value
01873  * @param ay 16-bit signed integer container for accelerometer Y-axis value
01874  * @param az 16-bit signed integer container for accelerometer Z-axis value
01875  * @param gx 16-bit signed integer container for gyroscope X-axis value
01876  * @param gy 16-bit signed integer container for gyroscope Y-axis value
01877  * @param gz 16-bit signed integer container for gyroscope Z-axis value
01878  * @param mx 16-bit signed integer container for magnetometer X-axis value
01879  * @param my 16-bit signed integer container for magnetometer Y-axis value
01880  * @param mz 16-bit signed integer container for magnetometer Z-axis value
01881  * @see getMotion6()
01882  * @see getAcceleration()
01883  * @see getRotation()
01884  * @see MPU6050_RA_ACCEL_XOUT_H
01885  */
01886 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)
01887 {
01888     getMotion6(ax, ay, az, gx, gy, gz);
01889 
01890     // magnetometer reading
01891     i2Cdev.writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer
01892     wait_ms(10); // necessary wait >=6ms
01893     i2Cdev.writeByte(MPU9150_RA_MAG_ADDRESS, 0x0A, 0x01); // enable the magnetometer
01894     wait_ms(10); // necessary wait >=6ms
01895     i2Cdev.readBytes(MPU9150_RA_MAG_ADDRESS, MPU9150_RA_MAG_XOUT_L, 6, buffer);
01896     *mx = (((int16_t)buffer[0]) << 8) | buffer[1];
01897     *my = (((int16_t)buffer[2]) << 8) | buffer[3];
01898     *mz = (((int16_t)buffer[4]) << 8) | buffer[5];
01899 }
01900 
01901 void MPU6050::getMag(int16_t* mx, int16_t* my, int16_t* mz)
01902 {
01903     // magnetometer reading
01904     i2Cdev.writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer
01905     wait_ms(10); // necessary wait >=6ms
01906     i2Cdev.writeByte(MPU9150_RA_MAG_ADDRESS, 0x0A, 0x01); // enable the magnetometer
01907     wait_ms(10); // necessary wait >=6ms
01908     i2Cdev.readBytes(MPU9150_RA_MAG_ADDRESS, MPU9150_RA_MAG_XOUT_L, 6, buffer);
01909     *mx = (((int16_t)buffer[0]) << 8) | buffer[1];
01910     *my = (((int16_t)buffer[2]) << 8) | buffer[3];
01911     *mz = (((int16_t)buffer[4]) << 8) | buffer[5];
01912 }
01913 
01914 /** Get raw 6-axis motion sensor readings (accel/gyro).
01915  * Retrieves all currently available motion sensor values.
01916  * @param ax 16-bit signed integer container for accelerometer X-axis value
01917  * @param ay 16-bit signed integer container for accelerometer Y-axis value
01918  * @param az 16-bit signed integer container for accelerometer Z-axis value
01919  * @param gx 16-bit signed integer container for gyroscope X-axis value
01920  * @param gy 16-bit signed integer container for gyroscope Y-axis value
01921  * @param gz 16-bit signed integer container for gyroscope Z-axis value
01922  * @see getAcceleration()
01923  * @see getRotation()
01924  * @see MPU6050_RA_ACCEL_XOUT_H
01925  */
01926 void MPU6050::getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz)
01927 {
01928     i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 14, buffer);
01929     *ax = (((int16_t)buffer[0]) << 8) | buffer[1];
01930     *ay = (((int16_t)buffer[2]) << 8) | buffer[3];
01931     *az = (((int16_t)buffer[4]) << 8) | buffer[5];
01932     *gx = (((int16_t)buffer[8]) << 8) | buffer[9];
01933     *gy = (((int16_t)buffer[10]) << 8) | buffer[11];
01934     *gz = (((int16_t)buffer[12]) << 8) | buffer[13];
01935 }
01936 /** Get 3-axis accelerometer readings.
01937  * These registers store the most recent accelerometer measurements.
01938  * Accelerometer measurements are written to these registers at the Sample Rate
01939  * as defined in Register 25.
01940  *
01941  * The accelerometer measurement registers, along with the temperature
01942  * measurement registers, gyroscope measurement registers, and external sensor
01943  * data registers, are composed of two sets of registers: an internal register
01944  * set and a user-facing read register set.
01945  *
01946  * The data within the accelerometer sensors' internal register set is always
01947  * updated at the Sample Rate. Meanwhile, the user-facing read register set
01948  * duplicates the internal register set's data values whenever the serial
01949  * interface is idle. This guarantees that a burst read of sensor registers will
01950  * read measurements from the same sampling instant. Note that if burst reads
01951  * are not used, the user is responsible for ensuring a set of single byte reads
01952  * correspond to a single sampling instant by checking the Data Ready interrupt.
01953  *
01954  * Each 16-bit accelerometer measurement has a full scale defined in ACCEL_FS
01955  * (Register 28). For each full scale setting, the accelerometers' sensitivity
01956  * per LSB in ACCEL_xOUT is shown in the table below:
01957  *
01958  * <pre>
01959  * AFS_SEL | Full Scale Range | LSB Sensitivity
01960  * --------+------------------+----------------
01961  * 0       | +/- 2g           | 8192 LSB/mg
01962  * 1       | +/- 4g           | 4096 LSB/mg
01963  * 2       | +/- 8g           | 2048 LSB/mg
01964  * 3       | +/- 16g          | 1024 LSB/mg
01965  * </pre>
01966  *
01967  * @param x 16-bit signed integer container for X-axis acceleration
01968  * @param y 16-bit signed integer container for Y-axis acceleration
01969  * @param z 16-bit signed integer container for Z-axis acceleration
01970  * @see MPU6050_RA_GYRO_XOUT_H
01971  */
01972 void MPU6050::getAcceleration(int16_t* x, int16_t* y, int16_t* z)
01973 {
01974     i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 6, buffer);
01975     *x = (((int16_t)buffer[0]) << 8) | buffer[1];
01976     *y = (((int16_t)buffer[2]) << 8) | buffer[3];
01977     *z = (((int16_t)buffer[4]) << 8) | buffer[5];
01978 }
01979 /** Get X-axis accelerometer reading.
01980  * @return X-axis acceleration measurement in 16-bit 2's complement format
01981  * @see getMotion6()
01982  * @see MPU6050_RA_ACCEL_XOUT_H
01983  */
01984 int16_t MPU6050::getAccelerationX()
01985 {
01986     i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 2, buffer);
01987     return (((int16_t)buffer[0]) << 8) | buffer[1];
01988 }
01989 /** Get Y-axis accelerometer reading.
01990  * @return Y-axis acceleration measurement in 16-bit 2's complement format
01991  * @see getMotion6()
01992  * @see MPU6050_RA_ACCEL_YOUT_H
01993  */
01994 int16_t MPU6050::getAccelerationY()
01995 {
01996     i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_YOUT_H, 2, buffer);
01997     return (((int16_t)buffer[0]) << 8) | buffer[1];
01998 }
01999 /** Get Z-axis accelerometer reading.
02000  * @return Z-axis acceleration measurement in 16-bit 2's complement format
02001  * @see getMotion6()
02002  * @see MPU6050_RA_ACCEL_ZOUT_H
02003  */
02004 int16_t MPU6050::getAccelerationZ()
02005 {
02006     i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_ZOUT_H, 2, buffer);
02007     return (((int16_t)buffer[0]) << 8) | buffer[1];
02008 }
02009 
02010 // TEMP_OUT_* registers
02011 
02012 /** Get current internal temperature.
02013  * @return Temperature reading in 16-bit 2's complement format
02014  * @see MPU6050_RA_TEMP_OUT_H
02015  */
02016 int16_t MPU6050::getTemperature()
02017 {
02018     i2Cdev.readBytes(devAddr, MPU6050_RA_TEMP_OUT_H, 2, buffer);
02019     return (((int16_t)buffer[0]) << 8) | buffer[1];
02020 }
02021 
02022 // GYRO_*OUT_* registers
02023 
02024 /** Get 3-axis gyroscope readings.
02025  * These gyroscope measurement registers, along with the accelerometer
02026  * measurement registers, temperature measurement registers, and external sensor
02027  * data registers, are composed of two sets of registers: an internal register
02028  * set and a user-facing read register set.
02029  * The data within the gyroscope sensors' internal register set is always
02030  * updated at the Sample Rate. Meanwhile, the user-facing read register set
02031  * duplicates the internal register set's data values whenever the serial
02032  * interface is idle. This guarantees that a burst read of sensor registers will
02033  * read measurements from the same sampling instant. Note that if burst reads
02034  * are not used, the user is responsible for ensuring a set of single byte reads
02035  * correspond to a single sampling instant by checking the Data Ready interrupt.
02036  *
02037  * Each 16-bit gyroscope measurement has a full scale defined in FS_SEL
02038  * (Register 27). For each full scale setting, the gyroscopes' sensitivity per
02039  * LSB in GYRO_xOUT is shown in the table below:
02040  *
02041  * <pre>
02042  * FS_SEL | Full Scale Range   | LSB Sensitivity
02043  * -------+--------------------+----------------
02044  * 0      | +/- 250 degrees/s  | 131 LSB/deg/s
02045  * 1      | +/- 500 degrees/s  | 65.5 LSB/deg/s
02046  * 2      | +/- 1000 degrees/s | 32.8 LSB/deg/s
02047  * 3      | +/- 2000 degrees/s | 16.4 LSB/deg/s
02048  * </pre>
02049  *
02050  * @param x 16-bit signed integer container for X-axis rotation
02051  * @param y 16-bit signed integer container for Y-axis rotation
02052  * @param z 16-bit signed integer container for Z-axis rotation
02053  * @see getMotion6()
02054  * @see MPU6050_RA_GYRO_XOUT_H
02055  */
02056 void MPU6050::getRotation(int16_t* x, int16_t* y, int16_t* z)
02057 {
02058     i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 6, buffer);
02059     *x = (((int16_t)buffer[0]) << 8) | buffer[1];
02060     *y = (((int16_t)buffer[2]) << 8) | buffer[3];
02061     *z = (((int16_t)buffer[4]) << 8) | buffer[5];
02062 }
02063 /** Get X-axis gyroscope reading.
02064  * @return X-axis rotation measurement in 16-bit 2's complement format
02065  * @see getMotion6()
02066  * @see MPU6050_RA_GYRO_XOUT_H
02067  */
02068 int16_t MPU6050::getRotationX()
02069 {
02070     i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 2, buffer);
02071     return (((int16_t)buffer[0]) << 8) | buffer[1];
02072 }
02073 /** Get Y-axis gyroscope reading.
02074  * @return Y-axis rotation measurement in 16-bit 2's complement format
02075  * @see getMotion6()
02076  * @see MPU6050_RA_GYRO_YOUT_H
02077  */
02078 int16_t MPU6050::getRotationY()
02079 {
02080     i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_YOUT_H, 2, buffer);
02081     return (((int16_t)buffer[0]) << 8) | buffer[1];
02082 }
02083 /** Get Z-axis gyroscope reading.
02084  * @return Z-axis rotation measurement in 16-bit 2's complement format
02085  * @see getMotion6()
02086  * @see MPU6050_RA_GYRO_ZOUT_H
02087  */
02088 int16_t MPU6050::getRotationZ()
02089 {
02090     i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_ZOUT_H, 2, buffer);
02091     return (((int16_t)buffer[0]) << 8) | buffer[1];
02092 }
02093 
02094 // EXT_SENS_DATA_* registers
02095 
02096 /** Read single byte from external sensor data register.
02097  * These registers store data read from external sensors by the Slave 0, 1, 2,
02098  * and 3 on the auxiliary I2C interface. Data read by Slave 4 is stored in
02099  * I2C_SLV4_DI (Register 53).
02100  *
02101  * External sensor data is written to these registers at the Sample Rate as
02102  * defined in Register 25. This access rate can be reduced by using the Slave
02103  * Delay Enable registers (Register 103).
02104  *
02105  * External sensor data registers, along with the gyroscope measurement
02106  * registers, accelerometer measurement registers, and temperature measurement
02107  * registers, are composed of two sets of registers: an internal register set
02108  * and a user-facing read register set.
02109  *
02110  * The data within the external sensors' internal register set is always updated
02111  * at the Sample Rate (or the reduced access rate) whenever the serial interface
02112  * is idle. This guarantees that a burst read of sensor registers will read
02113  * measurements from the same sampling instant. Note that if burst reads are not
02114  * used, the user is responsible for ensuring a set of single byte reads
02115  * correspond to a single sampling instant by checking the Data Ready interrupt.
02116  *
02117  * Data is placed in these external sensor data registers according to
02118  * I2C_SLV0_CTRL, I2C_SLV1_CTRL, I2C_SLV2_CTRL, and I2C_SLV3_CTRL (Registers 39,
02119  * 42, 45, and 48). When more than zero bytes are read (I2C_SLVx_LEN > 0) from
02120  * an enabled slave (I2C_SLVx_EN = 1), the slave is read at the Sample Rate (as
02121  * defined in Register 25) or delayed rate (if specified in Register 52 and
02122  * 103). During each Sample cycle, slave reads are performed in order of Slave
02123  * number. If all slaves are enabled with more than zero bytes to be read, the
02124  * order will be Slave 0, followed by Slave 1, Slave 2, and Slave 3.
02125  *
02126  * Each enabled slave will have EXT_SENS_DATA registers associated with it by
02127  * number of bytes read (I2C_SLVx_LEN) in order of slave number, starting from
02128  * EXT_SENS_DATA_00. Note that this means enabling or disabling a slave may
02129  * change the higher numbered slaves' associated registers. Furthermore, if
02130  * fewer total bytes are being read from the external sensors as a result of
02131  * such a change, then the data remaining in the registers which no longer have
02132  * an associated slave device (i.e. high numbered registers) will remain in
02133  * these previously allocated registers unless reset.
02134  *
02135  * If the sum of the read lengths of all SLVx transactions exceed the number of
02136  * available EXT_SENS_DATA registers, the excess bytes will be dropped. There
02137  * are 24 EXT_SENS_DATA registers and hence the total read lengths between all
02138  * the slaves cannot be greater than 24 or some bytes will be lost.
02139  *
02140  * Note: Slave 4's behavior is distinct from that of Slaves 0-3. For further
02141  * information regarding the characteristics of Slave 4, please refer to
02142  * Registers 49 to 53.
02143  *
02144  * EXAMPLE:
02145  * Suppose that Slave 0 is enabled with 4 bytes to be read (I2C_SLV0_EN = 1 and
02146  * I2C_SLV0_LEN = 4) while Slave 1 is enabled with 2 bytes to be read so that
02147  * I2C_SLV1_EN = 1 and I2C_SLV1_LEN = 2. In such a situation, EXT_SENS_DATA _00
02148  * through _03 will be associated with Slave 0, while EXT_SENS_DATA _04 and 05
02149  * will be associated with Slave 1. If Slave 2 is enabled as well, registers
02150  * starting from EXT_SENS_DATA_06 will be allocated to Slave 2.
02151  *
02152  * If Slave 2 is disabled while Slave 3 is enabled in this same situation, then
02153  * registers starting from EXT_SENS_DATA_06 will be allocated to Slave 3
02154  * instead.
02155  *
02156  * REGISTER ALLOCATION FOR DYNAMIC DISABLE VS. NORMAL DISABLE:
02157  * If a slave is disabled at any time, the space initially allocated to the
02158  * slave in the EXT_SENS_DATA register, will remain associated with that slave.
02159  * This is to avoid dynamic adjustment of the register allocation.
02160  *
02161  * The allocation of the EXT_SENS_DATA registers is recomputed only when (1) all
02162  * slaves are disabled, or (2) the I2C_MST_RST bit is set (Register 106).
02163  *
02164  * This above is also true if one of the slaves gets NACKed and stops
02165  * functioning.
02166  *
02167  * @param position Starting position (0-23)
02168  * @return Byte read from register
02169  */
02170 uint8_t MPU6050::getExternalSensorByte(int position)
02171 {
02172     i2Cdev.readByte(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, buffer);
02173     return buffer[0];
02174 }
02175 /** Read word (2 bytes) from external sensor data registers.
02176  * @param position Starting position (0-21)
02177  * @return Word read from register
02178  * @see getExternalSensorByte()
02179  */
02180 uint16_t MPU6050::getExternalSensorWord(int position)
02181 {
02182     i2Cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 2, buffer);
02183     return (((uint16_t)buffer[0]) << 8) | buffer[1];
02184 }
02185 /** Read double word (4 bytes) from external sensor data registers.
02186  * @param position Starting position (0-20)
02187  * @return Double word read from registers
02188  * @see getExternalSensorByte()
02189  */
02190 uint32_t MPU6050::getExternalSensorDWord(int position)
02191 {
02192     i2Cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 4, buffer);
02193     return (((uint32_t)buffer[0]) << 24) | (((uint32_t)buffer[1]) << 16) | (((uint16_t)buffer[2]) << 8) | buffer[3];
02194 }
02195 
02196 // MOT_DETECT_STATUS register
02197 
02198 /** Get X-axis negative motion detection interrupt status.
02199  * @return Motion detection status
02200  * @see MPU6050_RA_MOT_DETECT_STATUS
02201  * @see MPU6050_MOTION_MOT_XNEG_BIT
02202  */
02203 bool MPU6050::getXNegMotionDetected()
02204 {
02205     i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XNEG_BIT, buffer);
02206     return buffer[0];
02207 }
02208 /** Get X-axis positive motion detection interrupt status.
02209  * @return Motion detection status
02210  * @see MPU6050_RA_MOT_DETECT_STATUS
02211  * @see MPU6050_MOTION_MOT_XPOS_BIT
02212  */
02213 bool MPU6050::getXPosMotionDetected()
02214 {
02215     i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XPOS_BIT, buffer);
02216     return buffer[0];
02217 }
02218 /** Get Y-axis negative motion detection interrupt status.
02219  * @return Motion detection status
02220  * @see MPU6050_RA_MOT_DETECT_STATUS
02221  * @see MPU6050_MOTION_MOT_YNEG_BIT
02222  */
02223 bool MPU6050::getYNegMotionDetected()
02224 {
02225     i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YNEG_BIT, buffer);
02226     return buffer[0];
02227 }
02228 /** Get Y-axis positive motion detection interrupt status.
02229  * @return Motion detection status
02230  * @see MPU6050_RA_MOT_DETECT_STATUS
02231  * @see MPU6050_MOTION_MOT_YPOS_BIT
02232  */
02233 bool MPU6050::getYPosMotionDetected()
02234 {
02235     i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YPOS_BIT, buffer);
02236     return buffer[0];
02237 }
02238 /** Get Z-axis negative motion detection interrupt status.
02239  * @return Motion detection status
02240  * @see MPU6050_RA_MOT_DETECT_STATUS
02241  * @see MPU6050_MOTION_MOT_ZNEG_BIT
02242  */
02243 bool MPU6050::getZNegMotionDetected()
02244 {
02245     i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZNEG_BIT, buffer);
02246     return buffer[0];
02247 }
02248 /** Get Z-axis positive motion detection interrupt status.
02249  * @return Motion detection status
02250  * @see MPU6050_RA_MOT_DETECT_STATUS
02251  * @see MPU6050_MOTION_MOT_ZPOS_BIT
02252  */
02253 bool MPU6050::getZPosMotionDetected()
02254 {
02255     i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZPOS_BIT, buffer);
02256     return buffer[0];
02257 }
02258 /** Get zero motion detection interrupt status.
02259  * @return Motion detection status
02260  * @see MPU6050_RA_MOT_DETECT_STATUS
02261  * @see MPU6050_MOTION_MOT_ZRMOT_BIT
02262  */
02263 bool MPU6050::getZeroMotionDetected()
02264 {
02265     i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZRMOT_BIT, buffer);
02266     return buffer[0];
02267 }
02268 
02269 // I2C_SLV*_DO register
02270 
02271 /** Write byte to Data Output container for specified slave.
02272  * This register holds the output data written into Slave when Slave is set to
02273  * write mode. For further information regarding Slave control, please
02274  * refer to Registers 37 to 39 and immediately following.
02275  * @param num Slave number (0-3)
02276  * @param data Byte to write
02277  * @see MPU6050_RA_I2C_SLV0_DO
02278  */
02279 void MPU6050::setSlaveOutputByte(uint8_t num, uint8_t data)
02280 {
02281     if (num > 3) return;
02282     i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_DO + num, data);
02283 }
02284 
02285 // I2C_MST_DELAY_CTRL register
02286 
02287 /** Get external data shadow delay enabled status.
02288  * This register is used to specify the timing of external sensor data
02289  * shadowing. When DELAY_ES_SHADOW is set to 1, shadowing of external
02290  * sensor data is delayed until all data has been received.
02291  * @return Current external data shadow delay enabled status.
02292  * @see MPU6050_RA_I2C_MST_DELAY_CTRL
02293  * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT
02294  */
02295 bool MPU6050::getExternalShadowDelayEnabled()
02296 {
02297     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, buffer);
02298     return buffer[0];
02299 }
02300 /** Set external data shadow delay enabled status.
02301  * @param enabled New external data shadow delay enabled status.
02302  * @see getExternalShadowDelayEnabled()
02303  * @see MPU6050_RA_I2C_MST_DELAY_CTRL
02304  * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT
02305  */
02306 void MPU6050::setExternalShadowDelayEnabled(bool enabled)
02307 {
02308     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, enabled);
02309 }
02310 /** Get slave delay enabled status.
02311  * When a particular slave delay is enabled, the rate of access for the that
02312  * slave device is reduced. When a slave's access rate is decreased relative to
02313  * the Sample Rate, the slave is accessed every:
02314  *
02315  *     1 / (1 + I2C_MST_DLY) Samples
02316  *
02317  * This base Sample Rate in turn is determined by SMPLRT_DIV (register  * 25)
02318  * and DLPF_CFG (register 26).
02319  *
02320  * For further information regarding I2C_MST_DLY, please refer to register 52.
02321  * For further information regarding the Sample Rate, please refer to register 25.
02322  *
02323  * @param num Slave number (0-4)
02324  * @return Current slave delay enabled status.
02325  * @see MPU6050_RA_I2C_MST_DELAY_CTRL
02326  * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT
02327  */
02328 bool MPU6050::getSlaveDelayEnabled(uint8_t num)
02329 {
02330     // MPU6050_DELAYCTRL_I2C_SLV4_DLY_EN_BIT is 4, SLV3 is 3, etc.
02331     if (num > 4) return 0;
02332     i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, buffer);
02333     return buffer[0];
02334 }
02335 /** Set slave delay enabled status.
02336  * @param num Slave number (0-4)
02337  * @param enabled New slave delay enabled status.
02338  * @see MPU6050_RA_I2C_MST_DELAY_CTRL
02339  * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT
02340  */
02341 void MPU6050::setSlaveDelayEnabled(uint8_t num, bool enabled)
02342 {
02343     i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, enabled);
02344 }
02345 
02346 // SIGNAL_PATH_RESET register
02347 
02348 /** Reset gyroscope signal path.
02349  * The reset will revert the signal path analog to digital converters and
02350  * filters to their power up configurations.
02351  * @see MPU6050_RA_SIGNAL_PATH_RESET
02352  * @see MPU6050_PATHRESET_GYRO_RESET_BIT
02353  */
02354 void MPU6050::resetGyroscopePath()
02355 {
02356     i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_GYRO_RESET_BIT, true);
02357 }
02358 /** Reset accelerometer signal path.
02359  * The reset will revert the signal path analog to digital converters and
02360  * filters to their power up configurations.
02361  * @see MPU6050_RA_SIGNAL_PATH_RESET
02362  * @see MPU6050_PATHRESET_ACCEL_RESET_BIT
02363  */
02364 void MPU6050::resetAccelerometerPath()
02365 {
02366     i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_ACCEL_RESET_BIT, true);
02367 }
02368 /** Reset temperature sensor signal path.
02369  * The reset will revert the signal path analog to digital converters and
02370  * filters to their power up configurations.
02371  * @see MPU6050_RA_SIGNAL_PATH_RESET
02372  * @see MPU6050_PATHRESET_TEMP_RESET_BIT
02373  */
02374 void MPU6050::resetTemperaturePath()
02375 {
02376     i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_TEMP_RESET_BIT, true);
02377 }
02378 
02379 // MOT_DETECT_CTRL register
02380 
02381 /** Get accelerometer power-on delay.
02382  * The accelerometer data path provides samples to the sensor registers, Motion
02383  * detection, Zero Motion detection, and Free Fall detection modules. The
02384  * signal path contains filters which must be flushed on wake-up with new
02385  * samples before the detection modules begin operations. The default wake-up
02386  * delay, of 4ms can be lengthened by up to 3ms. This additional delay is
02387  * specified in ACCEL_ON_DELAY in units of 1 LSB = 1 ms. The user may select
02388  * any value above zero unless instructed otherwise by InvenSense. Please refer
02389  * to Section 8 of the MPU-6000/MPU-6050 Product Specification document for
02390  * further information regarding the detection modules.
02391  * @return Current accelerometer power-on delay
02392  * @see MPU6050_RA_MOT_DETECT_CTRL
02393  * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT
02394  */
02395 uint8_t MPU6050::getAccelerometerPowerOnDelay()
02396 {
02397     i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, buffer);
02398     return buffer[0];
02399 }
02400 /** Set accelerometer power-on delay.
02401  * @param delay New accelerometer power-on delay (0-3)
02402  * @see getAccelerometerPowerOnDelay()
02403  * @see MPU6050_RA_MOT_DETECT_CTRL
02404  * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT
02405  */
02406 void MPU6050::setAccelerometerPowerOnDelay(uint8_t delay)
02407 {
02408     i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, delay);
02409 }
02410 /** Get Free Fall detection counter decrement configuration.
02411  * Detection is registered by the Free Fall detection module after accelerometer
02412  * measurements meet their respective threshold conditions over a specified
02413  * number of samples. When the threshold conditions are met, the corresponding
02414  * detection counter increments by 1. The user may control the rate at which the
02415  * detection counter decrements when the threshold condition is not met by
02416  * configuring FF_COUNT. The decrement rate can be set according to the
02417  * following table:
02418  *
02419  * <pre>
02420  * FF_COUNT | Counter Decrement
02421  * ---------+------------------
02422  * 0        | Reset
02423  * 1        | 1
02424  * 2        | 2
02425  * 3        | 4
02426  * </pre>
02427  *
02428  * When FF_COUNT is configured to 0 (reset), any non-qualifying sample will
02429  * reset the counter to 0. For further information on Free Fall detection,
02430  * please refer to Registers 29 to 32.
02431  *
02432  * @return Current decrement configuration
02433  * @see MPU6050_RA_MOT_DETECT_CTRL
02434  * @see MPU6050_DETECT_FF_COUNT_BIT
02435  */
02436 uint8_t MPU6050::getFreefallDetectionCounterDecrement()
02437 {
02438     i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, buffer);
02439     return buffer[0];
02440 }
02441 /** Set Free Fall detection counter decrement configuration.
02442  * @param decrement New decrement configuration value
02443  * @see getFreefallDetectionCounterDecrement()
02444  * @see MPU6050_RA_MOT_DETECT_CTRL
02445  * @see MPU6050_DETECT_FF_COUNT_BIT
02446  */
02447 void MPU6050::setFreefallDetectionCounterDecrement(uint8_t decrement)
02448 {
02449     i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, decrement);
02450 }
02451 /** Get Motion detection counter decrement configuration.
02452  * Detection is registered by the Motion detection module after accelerometer
02453  * measurements meet their respective threshold conditions over a specified
02454  * number of samples. When the threshold conditions are met, the corresponding
02455  * detection counter increments by 1. The user may control the rate at which the
02456  * detection counter decrements when the threshold condition is not met by
02457  * configuring MOT_COUNT. The decrement rate can be set according to the
02458  * following table:
02459  *
02460  * <pre>
02461  * MOT_COUNT | Counter Decrement
02462  * ----------+------------------
02463  * 0         | Reset
02464  * 1         | 1
02465  * 2         | 2
02466  * 3         | 4
02467  * </pre>
02468  *
02469  * When MOT_COUNT is configured to 0 (reset), any non-qualifying sample will
02470  * reset the counter to 0. For further information on Motion detection,
02471  * please refer to Registers 29 to 32.
02472  *
02473  */
02474 uint8_t MPU6050::getMotionDetectionCounterDecrement()
02475 {
02476     i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, buffer);
02477     return buffer[0];
02478 }
02479 /** Set Motion detection counter decrement configuration.
02480  * @param decrement New decrement configuration value
02481  * @see getMotionDetectionCounterDecrement()
02482  * @see MPU6050_RA_MOT_DETECT_CTRL
02483  * @see MPU6050_DETECT_MOT_COUNT_BIT
02484  */
02485 void MPU6050::setMotionDetectionCounterDecrement(uint8_t decrement)
02486 {
02487     i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, decrement);
02488 }
02489 
02490 // USER_CTRL register
02491 
02492 /** Get FIFO enabled status.
02493  * When this bit is set to 0, the FIFO buffer is disabled. The FIFO buffer
02494  * cannot be written to or read from while disabled. The FIFO buffer's state
02495  * does not change unless the MPU-60X0 is power cycled.
02496  * @return Current FIFO enabled status
02497  * @see MPU6050_RA_USER_CTRL
02498  * @see MPU6050_USERCTRL_FIFO_EN_BIT
02499  */
02500 bool MPU6050::getFIFOEnabled()
02501 {
02502     i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, buffer);
02503     return buffer[0];
02504 }
02505 /** Set FIFO enabled status.
02506  * @param enabled New FIFO enabled status
02507  * @see getFIFOEnabled()
02508  * @see MPU6050_RA_USER_CTRL
02509  * @see MPU6050_USERCTRL_FIFO_EN_BIT
02510  */
02511 void MPU6050::setFIFOEnabled(bool enabled)
02512 {
02513     i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, enabled);
02514 }
02515 /** Get I2C Master Mode enabled status.
02516  * When this mode is enabled, the MPU-60X0 acts as the I2C Master to the
02517  * external sensor slave devices on the auxiliary I2C bus. When this bit is
02518  * cleared to 0, the auxiliary I2C bus lines (AUX_DA and AUX_CL) are logically
02519  * driven by the primary I2C bus (SDA and SCL). This is a precondition to
02520  * enabling Bypass Mode. For further information regarding Bypass Mode, please
02521  * refer to Register 55.
02522  * @return Current I2C Master Mode enabled status
02523  * @see MPU6050_RA_USER_CTRL
02524  * @see MPU6050_USERCTRL_I2C_MST_EN_BIT
02525  */
02526 bool MPU6050::getI2CMasterModeEnabled()
02527 {
02528     i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, buffer);
02529     return buffer[0];
02530 }
02531 /** Set I2C Master Mode enabled status.
02532  * @param enabled New I2C Master Mode enabled status
02533  * @see getI2CMasterModeEnabled()
02534  * @see MPU6050_RA_USER_CTRL
02535  * @see MPU6050_USERCTRL_I2C_MST_EN_BIT
02536  */
02537 void MPU6050::setI2CMasterModeEnabled(bool enabled)
02538 {
02539     i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, enabled);
02540 }
02541 /** Switch from I2C to SPI mode (MPU-6000 only)
02542  * If this is set, the primary SPI interface will be enabled in place of the
02543  * disabled primary I2C interface.
02544  */
02545 void MPU6050::switchSPIEnabled(bool enabled)
02546 {
02547     i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_IF_DIS_BIT, enabled);
02548 }
02549 /** Reset the FIFO.
02550  * This bit resets the FIFO buffer when set to 1 while FIFO_EN equals 0. This
02551  * bit automatically clears to 0 after the reset has been triggered.
02552  * @see MPU6050_RA_USER_CTRL
02553  * @see MPU6050_USERCTRL_FIFO_RESET_BIT
02554  */
02555 void MPU6050::resetFIFO()
02556 {
02557     i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_RESET_BIT, true);
02558 }
02559 /** Reset the I2C Master.
02560  * This bit resets the I2C Master when set to 1 while I2C_MST_EN equals 0.
02561  * This bit automatically clears to 0 after the reset has been triggered.
02562  * @see MPU6050_RA_USER_CTRL
02563  * @see MPU6050_USERCTRL_I2C_MST_RESET_BIT
02564  */
02565 void MPU6050::resetI2CMaster()
02566 {
02567     i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_RESET_BIT, true);
02568 }
02569 /** Reset all sensor registers and signal paths.
02570  * When set to 1, this bit resets the signal paths for all sensors (gyroscopes,
02571  * accelerometers, and temperature sensor). This operation will also clear the
02572  * sensor registers. This bit automatically clears to 0 after the reset has been
02573  * triggered.
02574  *
02575  * When resetting only the signal path (and not the sensor registers), please
02576  * use Register 104, SIGNAL_PATH_RESET.
02577  *
02578  * @see MPU6050_RA_USER_CTRL
02579  * @see MPU6050_USERCTRL_SIG_COND_RESET_BIT
02580  */
02581 void MPU6050::resetSensors()
02582 {
02583     i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_SIG_COND_RESET_BIT, true);
02584 }
02585 
02586 // PWR_MGMT_1 register
02587 
02588 /** Trigger a full device reset.
02589  * A small delay of ~50ms may be desirable after triggering a reset.
02590  * @see MPU6050_RA_PWR_MGMT_1
02591  * @see MPU6050_PWR1_DEVICE_RESET_BIT
02592  */
02593 void MPU6050::reset()
02594 {
02595     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_DEVICE_RESET_BIT, true);
02596 }
02597 /** Get sleep mode status.
02598  * Setting the SLEEP bit in the register puts the device into very low power
02599  * sleep mode. In this mode, only the serial interface and internal registers
02600  * remain active, allowing for a very low standby current. Clearing this bit
02601  * puts the device back into normal mode. To save power, the individual standby
02602  * selections for each of the gyros should be used if any gyro axis is not used
02603  * by the application.
02604  * @return Current sleep mode enabled status
02605  * @see MPU6050_RA_PWR_MGMT_1
02606  * @see MPU6050_PWR1_SLEEP_BIT
02607  */
02608 bool MPU6050::getSleepEnabled()
02609 {
02610     i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, buffer);
02611     return buffer[0];
02612 }
02613 /** Set sleep mode status.
02614  * @param enabled New sleep mode enabled status
02615  * @see getSleepEnabled()
02616  * @see MPU6050_RA_PWR_MGMT_1
02617  * @see MPU6050_PWR1_SLEEP_BIT
02618  */
02619 void MPU6050::setSleepEnabled(bool enabled)
02620 {
02621     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, enabled);
02622 }
02623 /** Get wake cycle enabled status.
02624  * When this bit is set to 1 and SLEEP is disabled, the MPU-60X0 will cycle
02625  * between sleep mode and waking up to take a single sample of data from active
02626  * sensors at a rate determined by LP_WAKE_CTRL (register 108).
02627  * @return Current sleep mode enabled status
02628  * @see MPU6050_RA_PWR_MGMT_1
02629  * @see MPU6050_PWR1_CYCLE_BIT
02630  */
02631 bool MPU6050::getWakeCycleEnabled()
02632 {
02633     i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, buffer);
02634     return buffer[0];
02635 }
02636 /** Set wake cycle enabled status.
02637  * @param enabled New sleep mode enabled status
02638  * @see getWakeCycleEnabled()
02639  * @see MPU6050_RA_PWR_MGMT_1
02640  * @see MPU6050_PWR1_CYCLE_BIT
02641  */
02642 void MPU6050::setWakeCycleEnabled(bool enabled)
02643 {
02644     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, enabled);
02645 }
02646 /** Get temperature sensor enabled status.
02647  * Control the usage of the internal temperature sensor.
02648  *
02649  * Note: this register stores the *disabled* value, but for consistency with the
02650  * rest of the code, the function is named and used with standard true/false
02651  * values to indicate whether the sensor is enabled or disabled, respectively.
02652  *
02653  * @return Current temperature sensor enabled status
02654  * @see MPU6050_RA_PWR_MGMT_1
02655  * @see MPU6050_PWR1_TEMP_DIS_BIT
02656  */
02657 bool MPU6050::getTempSensorEnabled()
02658 {
02659     i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, buffer);
02660     return buffer[0] == 0; // 1 is actually disabled here
02661 }
02662 /** Set temperature sensor enabled status.
02663  * Note: this register stores the *disabled* value, but for consistency with the
02664  * rest of the code, the function is named and used with standard true/false
02665  * values to indicate whether the sensor is enabled or disabled, respectively.
02666  *
02667  * @param enabled New temperature sensor enabled status
02668  * @see getTempSensorEnabled()
02669  * @see MPU6050_RA_PWR_MGMT_1
02670  * @see MPU6050_PWR1_TEMP_DIS_BIT
02671  */
02672 void MPU6050::setTempSensorEnabled(bool enabled)
02673 {
02674     // 1 is actually disabled here
02675     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, !enabled);
02676 }
02677 /** Get clock source setting.
02678  * @return Current clock source setting
02679  * @see MPU6050_RA_PWR_MGMT_1
02680  * @see MPU6050_PWR1_CLKSEL_BIT
02681  * @see MPU6050_PWR1_CLKSEL_LENGTH
02682  */
02683 uint8_t MPU6050::getClockSource()
02684 {
02685     i2Cdev.readBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, buffer);
02686     return buffer[0];
02687 }
02688 /** Set clock source setting.
02689  * An internal 8MHz oscillator, gyroscope based clock, or external sources can
02690  * be selected as the MPU-60X0 clock source. When the internal 8 MHz oscillator
02691  * or an external source is chosen as the clock source, the MPU-60X0 can operate
02692  * in low power modes with the gyroscopes disabled.
02693  *
02694  * Upon power up, the MPU-60X0 clock source defaults to the internal oscillator.
02695  * However, it is highly recommended that the device be configured to use one of
02696  * the gyroscopes (or an external clock source) as the clock reference for
02697  * improved stability. The clock source can be selected according to the following table:
02698  *
02699  * <pre>
02700  * CLK_SEL | Clock Source
02701  * --------+--------------------------------------
02702  * 0       | Internal oscillator
02703  * 1       | PLL with X Gyro reference
02704  * 2       | PLL with Y Gyro reference
02705  * 3       | PLL with Z Gyro reference
02706  * 4       | PLL with external 32.768kHz reference
02707  * 5       | PLL with external 19.2MHz reference
02708  * 6       | Reserved
02709  * 7       | Stops the clock and keeps the timing generator in reset
02710  * </pre>
02711  *
02712  * @param source New clock source setting
02713  * @see getClockSource()
02714  * @see MPU6050_RA_PWR_MGMT_1
02715  * @see MPU6050_PWR1_CLKSEL_BIT
02716  * @see MPU6050_PWR1_CLKSEL_LENGTH
02717  */
02718 void MPU6050::setClockSource(uint8_t source)
02719 {
02720     i2Cdev.writeBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, source);
02721 }
02722 
02723 // PWR_MGMT_2 register
02724 
02725 /** Get wake frequency in Accel-Only Low Power Mode.
02726  * The MPU-60X0 can be put into Accerlerometer Only Low Power Mode by setting
02727  * PWRSEL to 1 in the Power Management 1 register (Register 107). In this mode,
02728  * the device will power off all devices except for the primary I2C interface,
02729  * waking only the accelerometer at fixed intervals to take a single
02730  * measurement. The frequency of wake-ups can be configured with LP_WAKE_CTRL
02731  * as shown below:
02732  *
02733  * <pre>
02734  * LP_WAKE_CTRL | Wake-up Frequency
02735  * -------------+------------------
02736  * 0            | 1.25 Hz
02737  * 1            | 2.5 Hz
02738  * 2            | 5 Hz
02739  * 3            | 10 Hz
02740  * <pre>
02741  *
02742  * For further information regarding the MPU-60X0's power modes, please refer to
02743  * Register 107.
02744  *
02745  * @return Current wake frequency
02746  * @see MPU6050_RA_PWR_MGMT_2
02747  */
02748 uint8_t MPU6050::getWakeFrequency()
02749 {
02750     i2Cdev.readBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, buffer);
02751     return buffer[0];
02752 }
02753 /** Set wake frequency in Accel-Only Low Power Mode.
02754  * @param frequency New wake frequency
02755  * @see MPU6050_RA_PWR_MGMT_2
02756  */
02757 void MPU6050::setWakeFrequency(uint8_t frequency)
02758 {
02759     i2Cdev.writeBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, frequency);
02760 }
02761 
02762 /** Get X-axis accelerometer standby enabled status.
02763  * If enabled, the X-axis will not gather or report data (or use power).
02764  * @return Current X-axis standby enabled status
02765  * @see MPU6050_RA_PWR_MGMT_2
02766  * @see MPU6050_PWR2_STBY_XA_BIT
02767  */
02768 bool MPU6050::getStandbyXAccelEnabled()
02769 {
02770     i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, buffer);
02771     return buffer[0];
02772 }
02773 /** Set X-axis accelerometer standby enabled status.
02774  * @param New X-axis standby enabled status
02775  * @see getStandbyXAccelEnabled()
02776  * @see MPU6050_RA_PWR_MGMT_2
02777  * @see MPU6050_PWR2_STBY_XA_BIT
02778  */
02779 void MPU6050::setStandbyXAccelEnabled(bool enabled)
02780 {
02781     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, enabled);
02782 }
02783 /** Get Y-axis accelerometer standby enabled status.
02784  * If enabled, the Y-axis will not gather or report data (or use power).
02785  * @return Current Y-axis standby enabled status
02786  * @see MPU6050_RA_PWR_MGMT_2
02787  * @see MPU6050_PWR2_STBY_YA_BIT
02788  */
02789 bool MPU6050::getStandbyYAccelEnabled()
02790 {
02791     i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, buffer);
02792     return buffer[0];
02793 }
02794 /** Set Y-axis accelerometer standby enabled status.
02795  * @param New Y-axis standby enabled status
02796  * @see getStandbyYAccelEnabled()
02797  * @see MPU6050_RA_PWR_MGMT_2
02798  * @see MPU6050_PWR2_STBY_YA_BIT
02799  */
02800 void MPU6050::setStandbyYAccelEnabled(bool enabled)
02801 {
02802     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, enabled);
02803 }
02804 /** Get Z-axis accelerometer standby enabled status.
02805  * If enabled, the Z-axis will not gather or report data (or use power).
02806  * @return Current Z-axis standby enabled status
02807  * @see MPU6050_RA_PWR_MGMT_2
02808  * @see MPU6050_PWR2_STBY_ZA_BIT
02809  */
02810 bool MPU6050::getStandbyZAccelEnabled()
02811 {
02812     i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, buffer);
02813     return buffer[0];
02814 }
02815 /** Set Z-axis accelerometer standby enabled status.
02816  * @param New Z-axis standby enabled status
02817  * @see getStandbyZAccelEnabled()
02818  * @see MPU6050_RA_PWR_MGMT_2
02819  * @see MPU6050_PWR2_STBY_ZA_BIT
02820  */
02821 void MPU6050::setStandbyZAccelEnabled(bool enabled)
02822 {
02823     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, enabled);
02824 }
02825 /** Get X-axis gyroscope standby enabled status.
02826  * If enabled, the X-axis will not gather or report data (or use power).
02827  * @return Current X-axis standby enabled status
02828  * @see MPU6050_RA_PWR_MGMT_2
02829  * @see MPU6050_PWR2_STBY_XG_BIT
02830  */
02831 bool MPU6050::getStandbyXGyroEnabled()
02832 {
02833     i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, buffer);
02834     return buffer[0];
02835 }
02836 /** Set X-axis gyroscope standby enabled status.
02837  * @param New X-axis standby enabled status
02838  * @see getStandbyXGyroEnabled()
02839  * @see MPU6050_RA_PWR_MGMT_2
02840  * @see MPU6050_PWR2_STBY_XG_BIT
02841  */
02842 void MPU6050::setStandbyXGyroEnabled(bool enabled)
02843 {
02844     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, enabled);
02845 }
02846 /** Get Y-axis gyroscope standby enabled status.
02847  * If enabled, the Y-axis will not gather or report data (or use power).
02848  * @return Current Y-axis standby enabled status
02849  * @see MPU6050_RA_PWR_MGMT_2
02850  * @see MPU6050_PWR2_STBY_YG_BIT
02851  */
02852 bool MPU6050::getStandbyYGyroEnabled()
02853 {
02854     i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, buffer);
02855     return buffer[0];
02856 }
02857 /** Set Y-axis gyroscope standby enabled status.
02858  * @param New Y-axis standby enabled status
02859  * @see getStandbyYGyroEnabled()
02860  * @see MPU6050_RA_PWR_MGMT_2
02861  * @see MPU6050_PWR2_STBY_YG_BIT
02862  */
02863 void MPU6050::setStandbyYGyroEnabled(bool enabled)
02864 {
02865     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, enabled);
02866 }
02867 /** Get Z-axis gyroscope standby enabled status.
02868  * If enabled, the Z-axis will not gather or report data (or use power).
02869  * @return Current Z-axis standby enabled status
02870  * @see MPU6050_RA_PWR_MGMT_2
02871  * @see MPU6050_PWR2_STBY_ZG_BIT
02872  */
02873 bool MPU6050::getStandbyZGyroEnabled()
02874 {
02875     i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, buffer);
02876     return buffer[0];
02877 }
02878 /** Set Z-axis gyroscope standby enabled status.
02879  * @param New Z-axis standby enabled status
02880  * @see getStandbyZGyroEnabled()
02881  * @see MPU6050_RA_PWR_MGMT_2
02882  * @see MPU6050_PWR2_STBY_ZG_BIT
02883  */
02884 void MPU6050::setStandbyZGyroEnabled(bool enabled)
02885 {
02886     i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, enabled);
02887 }
02888 
02889 // FIFO_COUNT* registers
02890 
02891 /** Get current FIFO buffer size.
02892  * This value indicates the number of bytes stored in the FIFO buffer. This
02893  * number is in turn the number of bytes that can be read from the FIFO buffer
02894  * and it is directly proportional to the number of samples available given the
02895  * set of sensor data bound to be stored in the FIFO (register 35 and 36).
02896  * @return Current FIFO buffer size
02897  */
02898 uint16_t MPU6050::getFIFOCount()
02899 {
02900     i2Cdev.readBytes(devAddr, MPU6050_RA_FIFO_COUNTH, 2, buffer);
02901     return (((uint16_t)buffer[0]) << 8) | buffer[1];
02902 }
02903 
02904 // FIFO_R_W register
02905 
02906 /** Get byte from FIFO buffer.
02907  * This register is used to read and write data from the FIFO buffer. Data is
02908  * written to the FIFO in order of register number (from lowest to highest). If
02909  * all the FIFO enable flags (see below) are enabled and all External Sensor
02910  * Data registers (Registers 73 to 96) are associated with a Slave device, the
02911  * contents of registers 59 through 96 will be written in order at the Sample
02912  * Rate.
02913  *
02914  * The contents of the sensor data registers (Registers 59 to 96) are written
02915  * into the FIFO buffer when their corresponding FIFO enable flags are set to 1
02916  * in FIFO_EN (Register 35). An additional flag for the sensor data registers
02917  * associated with I2C Slave 3 can be found in I2C_MST_CTRL (Register 36).
02918  *
02919  * If the FIFO buffer has overflowed, the status bit FIFO_OFLOW_INT is
02920  * automatically set to 1. This bit is located in INT_STATUS (Register 58).
02921  * When the FIFO buffer has overflowed, the oldest data will be lost and new
02922  * data will be written to the FIFO.
02923  *
02924  * If the FIFO buffer is empty, reading this register will return the last byte
02925  * that was previously read from the FIFO until new data is available. The user
02926  * should check FIFO_COUNT to ensure that the FIFO buffer is not read when
02927  * empty.
02928  *
02929  * @return Byte from FIFO buffer
02930  */
02931 uint8_t MPU6050::getFIFOByte()
02932 {
02933     i2Cdev.readByte(devAddr, MPU6050_RA_FIFO_R_W, buffer);
02934     return buffer[0];
02935 }
02936 void MPU6050::getFIFOBytes(uint8_t *data, uint8_t length)
02937 {
02938     i2Cdev.readBytes(devAddr, MPU6050_RA_FIFO_R_W, length, data);
02939 }
02940 /** Write byte to FIFO buffer.
02941  * @see getFIFOByte()
02942  * @see MPU6050_RA_FIFO_R_W
02943  */
02944 void MPU6050::setFIFOByte(uint8_t data)
02945 {
02946     i2Cdev.writeByte(devAddr, MPU6050_RA_FIFO_R_W, data);
02947 }
02948 
02949 // WHO_AM_I register
02950 
02951 /** Get Device ID.
02952  * This register is used to verify the identity of the device (0b110100, 0x34).
02953  * @return Device ID (6 bits only! should be 0x34)
02954  * @see MPU6050_RA_WHO_AM_I
02955  * @see MPU6050_WHO_AM_I_BIT
02956  * @see MPU6050_WHO_AM_I_LENGTH
02957  */
02958 uint8_t MPU6050::getDeviceID()
02959 {
02960     i2Cdev.readBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, buffer);
02961     return buffer[0];
02962 }
02963 /** Set Device ID.
02964  * Write a new ID into the WHO_AM_I register (no idea why this should ever be
02965  * necessary though).
02966  * @param id New device ID to set.
02967  * @see getDeviceID()
02968  * @see MPU6050_RA_WHO_AM_I
02969  * @see MPU6050_WHO_AM_I_BIT
02970  * @see MPU6050_WHO_AM_I_LENGTH
02971  */
02972 void MPU6050::setDeviceID(uint8_t id)
02973 {
02974     i2Cdev.writeBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, id);
02975 }
02976 
02977 // ======== UNDOCUMENTED/DMP REGISTERS/METHODS ========
02978 
02979 // XG_OFFS_TC register
02980 
02981 uint8_t MPU6050::getOTPBankValid()
02982 {
02983     i2Cdev.readBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, buffer);
02984     return buffer[0];
02985 }
02986 void MPU6050::setOTPBankValid(bool enabled)
02987 {
02988     i2Cdev.writeBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, enabled);
02989 }
02990 int8_t MPU6050::getXGyroOffset()
02991 {
02992     i2Cdev.readBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer);
02993     return buffer[0];
02994 }
02995 void MPU6050::setXGyroOffset(int8_t offset)
02996 {
02997     i2Cdev.writeBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset);
02998 }
02999 
03000 // YG_OFFS_TC register
03001 
03002 int8_t MPU6050::getYGyroOffset()
03003 {
03004     i2Cdev.readBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer);
03005     return buffer[0];
03006 }
03007 void MPU6050::setYGyroOffset(int8_t offset)
03008 {
03009     i2Cdev.writeBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset);
03010 }
03011 
03012 // ZG_OFFS_TC register
03013 
03014 int8_t MPU6050::getZGyroOffset()
03015 {
03016     i2Cdev.readBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer);
03017     return buffer[0];
03018 }
03019 void MPU6050::setZGyroOffset(int8_t offset)
03020 {
03021     i2Cdev.writeBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset);
03022 }
03023 
03024 // X_FINE_GAIN register
03025 
03026 int8_t MPU6050::getXFineGain()
03027 {
03028     i2Cdev.readByte(devAddr, MPU6050_RA_X_FINE_GAIN, buffer);
03029     return buffer[0];
03030 }
03031 void MPU6050::setXFineGain(int8_t gain)
03032 {
03033     i2Cdev.writeByte(devAddr, MPU6050_RA_X_FINE_GAIN, gain);
03034 }
03035 
03036 // Y_FINE_GAIN register
03037 
03038 int8_t MPU6050::getYFineGain()
03039 {
03040     i2Cdev.readByte(devAddr, MPU6050_RA_Y_FINE_GAIN, buffer);
03041     return buffer[0];
03042 }
03043 void MPU6050::setYFineGain(int8_t gain)
03044 {
03045     i2Cdev.writeByte(devAddr, MPU6050_RA_Y_FINE_GAIN, gain);
03046 }
03047 
03048 // Z_FINE_GAIN register
03049 
03050 int8_t MPU6050::getZFineGain()
03051 {
03052     i2Cdev.readByte(devAddr, MPU6050_RA_Z_FINE_GAIN, buffer);
03053     return buffer[0];
03054 }
03055 void MPU6050::setZFineGain(int8_t gain)
03056 {
03057     i2Cdev.writeByte(devAddr, MPU6050_RA_Z_FINE_GAIN, gain);
03058 }
03059 
03060 // XA_OFFS_* registers
03061 
03062 int16_t MPU6050::getXAccelOffset()
03063 {
03064     i2Cdev.readBytes(devAddr, MPU6050_RA_XA_OFFS_H, 2, buffer);
03065     return (((int16_t)buffer[0]) << 8) | buffer[1];
03066 }
03067 void MPU6050::setXAccelOffset(int16_t offset)
03068 {
03069     i2Cdev.writeWord(devAddr, MPU6050_RA_XA_OFFS_H, offset);
03070 }
03071 
03072 // YA_OFFS_* register
03073 
03074 int16_t MPU6050::getYAccelOffset()
03075 {
03076     i2Cdev.readBytes(devAddr, MPU6050_RA_YA_OFFS_H, 2, buffer);
03077     return (((int16_t)buffer[0]) << 8) | buffer[1];
03078 }
03079 void MPU6050::setYAccelOffset(int16_t offset)
03080 {
03081     i2Cdev.writeWord(devAddr, MPU6050_RA_YA_OFFS_H, offset);
03082 }
03083 
03084 // ZA_OFFS_* register
03085 
03086 int16_t MPU6050::getZAccelOffset()
03087 {
03088     i2Cdev.readBytes(devAddr, MPU6050_RA_ZA_OFFS_H, 2, buffer);
03089     return (((int16_t)buffer[0]) << 8) | buffer[1];
03090 }
03091 void MPU6050::setZAccelOffset(int16_t offset)
03092 {
03093     i2Cdev.writeWord(devAddr, MPU6050_RA_ZA_OFFS_H, offset);
03094 }
03095 
03096 // XG_OFFS_USR* registers
03097 
03098 int16_t MPU6050::getXGyroOffsetUser()
03099 {
03100     i2Cdev.readBytes(devAddr, MPU6050_RA_XG_OFFS_USRH, 2, buffer);
03101     return (((int16_t)buffer[0]) << 8) | buffer[1];
03102 }
03103 void MPU6050::setXGyroOffsetUser(int16_t offset)
03104 {
03105     i2Cdev.writeWord(devAddr, MPU6050_RA_XG_OFFS_USRH, offset);
03106 }
03107 
03108 // YG_OFFS_USR* register
03109 
03110 int16_t MPU6050::getYGyroOffsetUser()
03111 {
03112     i2Cdev.readBytes(devAddr, MPU6050_RA_YG_OFFS_USRH, 2, buffer);
03113     return (((int16_t)buffer[0]) << 8) | buffer[1];
03114 }
03115 void MPU6050::setYGyroOffsetUser(int16_t offset)
03116 {
03117     i2Cdev.writeWord(devAddr, MPU6050_RA_YG_OFFS_USRH, offset);
03118 }
03119 
03120 // ZG_OFFS_USR* register
03121 
03122 int16_t MPU6050::getZGyroOffsetUser()
03123 {
03124     i2Cdev.readBytes(devAddr, MPU6050_RA_ZG_OFFS_USRH, 2, buffer);
03125     return (((int16_t)buffer[0]) << 8) | buffer[1];
03126 }
03127 void MPU6050::setZGyroOffsetUser(int16_t offset)
03128 {
03129     i2Cdev.writeWord(devAddr, MPU6050_RA_ZG_OFFS_USRH, offset);
03130 }
03131 
03132 // INT_ENABLE register (DMP functions)
03133 
03134 bool MPU6050::getIntPLLReadyEnabled()
03135 {
03136     i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer);
03137     return buffer[0];
03138 }
03139 void MPU6050::setIntPLLReadyEnabled(bool enabled)
03140 {
03141     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, enabled);
03142 }
03143 bool MPU6050::getIntDMPEnabled()
03144 {
03145     i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, buffer);
03146     return buffer[0];
03147 }
03148 void MPU6050::setIntDMPEnabled(bool enabled)
03149 {
03150     i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, enabled);
03151 }
03152 
03153 // DMP_INT_STATUS
03154 
03155 bool MPU6050::getDMPInt5Status()
03156 {
03157     i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_5_BIT, buffer);
03158     return buffer[0];
03159 }
03160 bool MPU6050::getDMPInt4Status()
03161 {
03162     i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_4_BIT, buffer);
03163     return buffer[0];
03164 }
03165 bool MPU6050::getDMPInt3Status()
03166 {
03167     i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_3_BIT, buffer);
03168     return buffer[0];
03169 }
03170 bool MPU6050::getDMPInt2Status()
03171 {
03172     i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_2_BIT, buffer);
03173     return buffer[0];
03174 }
03175 bool MPU6050::getDMPInt1Status()
03176 {
03177     i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_1_BIT, buffer);
03178     return buffer[0];
03179 }
03180 bool MPU6050::getDMPInt0Status()
03181 {
03182     i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_0_BIT, buffer);
03183     return buffer[0];
03184 }
03185 
03186 // INT_STATUS register (DMP functions)
03187 
03188 bool MPU6050::getIntPLLReadyStatus()
03189 {
03190     i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer);
03191     return buffer[0];
03192 }
03193 bool MPU6050::getIntDMPStatus()
03194 {
03195     i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DMP_INT_BIT, buffer);
03196     return buffer[0];
03197 }
03198 
03199 // USER_CTRL register (DMP functions)
03200 
03201 bool MPU6050::getDMPEnabled()
03202 {
03203     i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, buffer);
03204     return buffer[0];
03205 }
03206 void MPU6050::setDMPEnabled(bool enabled)
03207 {
03208     i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, enabled);
03209 }
03210 void MPU6050::resetDMP()
03211 {
03212     i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_RESET_BIT, true);
03213 }
03214 
03215 // BANK_SEL register
03216 
03217 void MPU6050::setMemoryBank(uint8_t bank, bool prefetchEnabled, bool userBank)
03218 {
03219     bank &= 0x1F;
03220     if (userBank) bank |= 0x20;
03221     if (prefetchEnabled) bank |= 0x40;
03222     i2Cdev.writeByte(devAddr, MPU6050_RA_BANK_SEL, bank);
03223 }
03224 
03225 // MEM_START_ADDR register
03226 
03227 void MPU6050::setMemoryStartAddress(uint8_t address)
03228 {
03229     i2Cdev.writeByte(devAddr, MPU6050_RA_MEM_START_ADDR, address);
03230 }
03231 
03232 // MEM_R_W register
03233 
03234 uint8_t MPU6050::readMemoryByte()
03235 {
03236     i2Cdev.readByte(devAddr, MPU6050_RA_MEM_R_W, buffer);
03237     return buffer[0];
03238 }
03239 void MPU6050::writeMemoryByte(uint8_t data)
03240 {
03241     i2Cdev.writeByte(devAddr, MPU6050_RA_MEM_R_W, data);
03242 }
03243 void MPU6050::readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address)
03244 {
03245     setMemoryBank(bank);
03246     setMemoryStartAddress(address);
03247     uint8_t chunkSize;
03248     for (uint16_t i = 0; i < dataSize;) {
03249         // determine correct chunk size according to bank position and data size
03250         chunkSize = MPU6050_DMP_MEMORY_CHUNK_SIZE;
03251 
03252         // make sure we don't go past the data size
03253         if (i + chunkSize > dataSize) chunkSize = dataSize - i;
03254 
03255         // make sure this chunk doesn't go past the bank boundary (256 bytes)
03256         if (chunkSize > 256 - address) chunkSize = 256 - address;
03257 
03258         // read the chunk of data as specified
03259         i2Cdev.readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, data + i);
03260 
03261         // increase byte index by [chunkSize]
03262         i += chunkSize;
03263 
03264         // uint8_t automatically wraps to 0 at 256
03265         address += chunkSize;
03266 
03267         // if we aren't done, update bank (if necessary) and address
03268         if (i < dataSize) {
03269             if (address == 0) bank++;
03270             setMemoryBank(bank);
03271             setMemoryStartAddress(address);
03272         }
03273     }
03274 }
03275 bool MPU6050::writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify, bool useProgMem)
03276 {
03277     setMemoryBank(bank);
03278     setMemoryStartAddress(address);
03279     uint8_t chunkSize;
03280     uint8_t *verifyBuffer = NULL;
03281     uint8_t *progBuffer = NULL;
03282     uint16_t i;
03283     uint8_t j;
03284     if (verify) verifyBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE);
03285     if (useProgMem) progBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE);
03286     for (i = 0; i < dataSize;) {
03287         // determine correct chunk size according to bank position and data size
03288         chunkSize = MPU6050_DMP_MEMORY_CHUNK_SIZE;
03289 
03290         // make sure we don't go past the data size
03291         if (i + chunkSize > dataSize) chunkSize = dataSize - i;
03292 
03293         // make sure this chunk doesn't go past the bank boundary (256 bytes)
03294         if (chunkSize > 256 - address) chunkSize = 256 - address;
03295 
03296         if (useProgMem) {
03297             // write the chunk of data as specified
03298             for (j = 0; j < chunkSize; j++) progBuffer[j] = pgm_read_byte(data + i + j);
03299         } else {
03300             // write the chunk of data as specified
03301             progBuffer = (uint8_t *)data + i;
03302         }
03303 
03304         i2Cdev.writeBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, progBuffer);
03305 
03306         // verify data if needed
03307         if (verify && verifyBuffer) {
03308             setMemoryBank(bank);
03309             setMemoryStartAddress(address);
03310             i2Cdev.readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, verifyBuffer);
03311             if (memcmp(progBuffer, verifyBuffer, chunkSize) != 0) {
03312                 /*Serial.print("Block write verification error, bank ");
03313                 Serial.print(bank, DEC);
03314                 Serial.print(", address ");
03315                 Serial.print(address, DEC);
03316                 Serial.print("!\nExpected:");
03317                 for (j = 0; j < chunkSize; j++) {
03318                     Serial.print(" 0x");
03319                     if (progBuffer[j] < 16) Serial.print("0");
03320                     Serial.print(progBuffer[j], HEX);
03321                 }
03322                 Serial.print("\nReceived:");
03323                 for (uint8_t j = 0; j < chunkSize; j++) {
03324                     Serial.print(" 0x");
03325                     if (verifyBuffer[i + j] < 16) Serial.print("0");
03326                     Serial.print(verifyBuffer[i + j], HEX);
03327                 }
03328                 Serial.print("\n");*/
03329                 free(verifyBuffer);
03330                 if (useProgMem) free(progBuffer);
03331                 return false; // uh oh.
03332             }
03333         }
03334 
03335         // increase byte index by [chunkSize]
03336         i += chunkSize;
03337 
03338         // uint8_t automatically wraps to 0 at 256
03339         address += chunkSize;
03340 
03341         // if we aren't done, update bank (if necessary) and address
03342         if (i < dataSize) {
03343             if (address == 0) bank++;
03344             setMemoryBank(bank);
03345             setMemoryStartAddress(address);
03346         }
03347     }
03348     if (verify) free(verifyBuffer);
03349     if (useProgMem) free(progBuffer);
03350     return true;
03351 }
03352 bool MPU6050::writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify)
03353 {
03354     return writeMemoryBlock(data, dataSize, bank, address, verify, true);
03355 }
03356 bool MPU6050::writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize, bool useProgMem)
03357 {
03358     uint8_t success, special;
03359     uint8_t *progBuffer = NULL;
03360     uint16_t i, j;
03361     if (useProgMem) {
03362         progBuffer = (uint8_t *)malloc(8); // assume 8-byte blocks, realloc later if necessary
03363     }
03364 
03365     // config set data is a long string of blocks with the following structure:
03366     // [bank] [offset] [length] [byte[0], byte[1], ..., byte[length]]
03367     uint8_t bank, offset, length;
03368     for (i = 0; i < dataSize;) {
03369         if (useProgMem) {
03370             bank = pgm_read_byte(data + i++);
03371             offset = pgm_read_byte(data + i++);
03372             length = pgm_read_byte(data + i++);
03373         } else {
03374             bank = data[i++];
03375             offset = data[i++];
03376             length = data[i++];
03377         }
03378 
03379         // write data or perform special action
03380         if (length > 0) {
03381             // regular block of data to write
03382             /*Serial.print("Writing config block to bank ");
03383             Serial.print(bank);
03384             Serial.print(", offset ");
03385             Serial.print(offset);
03386             Serial.print(", length=");
03387             Serial.println(length);*/
03388             if (useProgMem) {
03389                 if (sizeof(progBuffer) < length) progBuffer = (uint8_t *)realloc(progBuffer, length);
03390                 for (j = 0; j < length; j++) progBuffer[j] = pgm_read_byte(data + i + j);
03391             } else {
03392                 progBuffer = (uint8_t *)data + i;
03393             }
03394             success = writeMemoryBlock(progBuffer, length, bank, offset, true);
03395             i += length;
03396         } else {
03397             // special instruction
03398             // NOTE: this kind of behavior (what and when to do certain things)
03399             // is totally undocumented. This code is in here based on observed
03400             // behavior only, and exactly why (or even whether) it has to be here
03401             // is anybody's guess for now.
03402             if (useProgMem) {
03403                 special = pgm_read_byte(data + i++);
03404             } else {
03405                 special = data[i++];
03406             }
03407             /*Serial.print("Special command code ");
03408             Serial.print(special, HEX);
03409             Serial.println(" found...");*/
03410             if (special == 0x01) {
03411                 // enable DMP-related interrupts
03412 
03413                 //setIntZeroMotionEnabled(true);
03414                 //setIntFIFOBufferOverflowEnabled(true);
03415                 //setIntDMPEnabled(true);
03416                 i2Cdev.writeByte(devAddr, MPU6050_RA_INT_ENABLE, 0x32);  // single operation
03417 
03418                 success = true;
03419             } else {
03420                 // unknown special command
03421                 success = false;
03422             }
03423         }
03424 
03425         if (!success) {
03426             if (useProgMem) free(progBuffer);
03427             return false; // uh oh
03428         }
03429     }
03430     if (useProgMem) free(progBuffer);
03431     return true;
03432 }
03433 bool MPU6050::writeProgDMPConfigurationSet(const uint8_t *data, uint16_t dataSize)
03434 {
03435     return writeDMPConfigurationSet(data, dataSize, false);
03436 }
03437 
03438 // DMP_CFG_1 register
03439 
03440 uint8_t MPU6050::getDMPConfig1()
03441 {
03442     i2Cdev.readByte(devAddr, MPU6050_RA_DMP_CFG_1, buffer);
03443     return buffer[0];
03444 }
03445 void MPU6050::setDMPConfig1(uint8_t config)
03446 {
03447     i2Cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_1, config);
03448 }
03449 
03450 // DMP_CFG_2 register
03451 
03452 uint8_t MPU6050::getDMPConfig2()
03453 {
03454     i2Cdev.readByte(devAddr, MPU6050_RA_DMP_CFG_2, buffer);
03455     return buffer[0];
03456 }
03457 void MPU6050::setDMPConfig2(uint8_t config)
03458 {
03459     i2Cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_2, config);
03460 }