For nucleoF103 change sda,scl to PB_7,PB_6
Dependents: AGV_0411 AGV_SMT_Sevro AGV_SMT
Fork of MPU6050-DMP by
Diff: MPU6050.cpp
- Revision:
- 8:473800bd51ac
- Parent:
- 3:25e1a5a10e53
diff -r 6b1b4bcaf494 -r 473800bd51ac MPU6050.cpp --- a/MPU6050.cpp Thu Apr 12 01:11:08 2018 +0000 +++ b/MPU6050.cpp Thu May 10 08:15:44 2018 +0000 @@ -1,59 +1,9 @@ -//ported from arduino library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 -//written by szymon gaertig (email: szymon@gaertig.com.pl) -// -//Changelog: -//2013-01-08 - first beta release - -// I2Cdev library collection - MPU6050 I2C device class -// Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00) -// 8/24/2011 by Jeff Rowberg <jeff@rowberg.net> -// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib -// -// Changelog: -// ... - ongoing debug release - -// NOTE: THIS IS ONLY A PARIAL RELEASE. THIS DEVICE CLASS IS CURRENTLY UNDERGOING ACTIVE -// DEVELOPMENT AND IS STILL MISSING SOME IMPORTANT FEATURES. PLEASE KEEP THIS IN MIND IF -// YOU DECIDE TO USE THIS PARTICULAR CODE FOR ANYTHING. - -/* ============================================ -I2Cdev device library code is placed under the MIT license -Copyright (c) 2012 Jeff Rowberg - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -=============================================== -*/ - #include "MPU6050.h" -#define useDebugSerial - -//instead of using pgmspace.h -typedef const unsigned char prog_uchar; -#define pgm_read_byte_near(x) (*(prog_uchar*)(x))//<- I modified here -#define pgm_read_byte(x) (*(prog_uchar*)(x))//<- I modified here - /** Default constructor, uses default I2C address. * @see MPU6050_DEFAULT_ADDRESS */ -MPU6050::MPU6050() : debugSerial(USBTX, USBRX) -{ +MPU6050::MPU6050() { devAddr = MPU6050_DEFAULT_ADDRESS; } @@ -63,8 +13,7 @@ * @see MPU6050_ADDRESS_AD0_LOW * @see MPU6050_ADDRESS_AD0_HIGH */ -MPU6050::MPU6050(uint8_t address) : debugSerial(USBTX, USBRX) -{ +MPU6050::MPU6050(uint8_t address) { devAddr = address; } @@ -75,37 +24,19 @@ * the clock source to use the X Gyro for reference, which is slightly better than * the default internal clock source. */ -void MPU6050::initialize() -{ - -#ifdef useDebugSerial - debugSerial.printf("MPU6050::initialize start\n"); -#endif - +void MPU6050::initialize() { setClockSource(MPU6050_CLOCK_PLL_XGYRO); setFullScaleGyroRange(MPU6050_GYRO_FS_250); setFullScaleAccelRange(MPU6050_ACCEL_FS_2); setSleepEnabled(false); // thanks to Jack Elston for pointing this one out! - -#ifdef useDebugSerial - debugSerial.printf("MPU6050::initialize end\n"); -#endif } /** Verify the I2C connection. * Make sure the device is connected and responds as expected. * @return True if connection is valid, false otherwise */ -bool MPU6050::testConnection() -{ -#ifdef useDebugSerial - debugSerial.printf("MPU6050::testConnection start\n"); -#endif - uint8_t deviceId = getDeviceID(); -#ifdef useDebugSerial - debugSerial.printf("DeviceId = %d\n",deviceId); -#endif - return deviceId == 0x34; +bool MPU6050::testConnection() { + return getDeviceID() == 0x34; } // AUX_VDDIO register (InvenSense demo code calls this RA_*G_OFFS_TC) @@ -116,9 +47,8 @@ * the MPU-6000, which does not have a VLOGIC pin. * @return I2C supply voltage level (0=VLOGIC, 1=VDD) */ -uint8_t MPU6050::getAuxVDDIOLevel() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, buffer); +uint8_t MPU6050::getAuxVDDIOLevel() { + I2Cdev::readBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, buffer); return buffer[0]; } /** Set the auxiliary I2C supply voltage level. @@ -127,9 +57,8 @@ * the MPU-6000, which does not have a VLOGIC pin. * @param level I2C supply voltage level (0=VLOGIC, 1=VDD) */ -void MPU6050::setAuxVDDIOLevel(uint8_t level) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, level); +void MPU6050::setAuxVDDIOLevel(uint8_t level) { + I2Cdev::writeBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, level); } // SMPLRT_DIV register @@ -155,9 +84,8 @@ * @return Current sample rate * @see MPU6050_RA_SMPLRT_DIV */ -uint8_t MPU6050::getRate() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_SMPLRT_DIV, buffer); +uint8_t MPU6050::getRate() { + I2Cdev::readByte(devAddr, MPU6050_RA_SMPLRT_DIV, buffer); return buffer[0]; } /** Set gyroscope sample rate divider. @@ -165,9 +93,8 @@ * @see getRate() * @see MPU6050_RA_SMPLRT_DIV */ -void MPU6050::setRate(uint8_t rate) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_SMPLRT_DIV, rate); +void MPU6050::setRate(uint8_t rate) { + I2Cdev::writeByte(devAddr, MPU6050_RA_SMPLRT_DIV, rate); } // CONFIG register @@ -199,9 +126,8 @@ * * @return FSYNC configuration value */ -uint8_t MPU6050::getExternalFrameSync() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, buffer); +uint8_t MPU6050::getExternalFrameSync() { + I2Cdev::readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, buffer); return buffer[0]; } /** Set external FSYNC configuration. @@ -209,9 +135,8 @@ * @see MPU6050_RA_CONFIG * @param sync New FSYNC configuration value */ -void MPU6050::setExternalFrameSync(uint8_t sync) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, sync); +void MPU6050::setExternalFrameSync(uint8_t sync) { + I2Cdev::writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, sync); } /** Get digital low-pass filter configuration. * The DLPF_CFG parameter sets the digital low pass filter configuration. It @@ -241,9 +166,8 @@ * @see MPU6050_CFG_DLPF_CFG_BIT * @see MPU6050_CFG_DLPF_CFG_LENGTH */ -uint8_t MPU6050::getDLPFMode() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, buffer); +uint8_t MPU6050::getDLPFMode() { + I2Cdev::readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, buffer); return buffer[0]; } /** Set digital low-pass filter configuration. @@ -254,9 +178,8 @@ * @see MPU6050_CFG_DLPF_CFG_BIT * @see MPU6050_CFG_DLPF_CFG_LENGTH */ -void MPU6050::setDLPFMode(uint8_t mode) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, mode); +void MPU6050::setDLPFMode(uint8_t mode) { + I2Cdev::writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, mode); } // GYRO_CONFIG register @@ -278,9 +201,8 @@ * @see MPU6050_GCONFIG_FS_SEL_BIT * @see MPU6050_GCONFIG_FS_SEL_LENGTH */ -uint8_t MPU6050::getFullScaleGyroRange() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, buffer); +uint8_t MPU6050::getFullScaleGyroRange() { + I2Cdev::readBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, buffer); return buffer[0]; } /** Set full-scale gyroscope range. @@ -291,9 +213,66 @@ * @see MPU6050_GCONFIG_FS_SEL_BIT * @see MPU6050_GCONFIG_FS_SEL_LENGTH */ -void MPU6050::setFullScaleGyroRange(uint8_t range) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, range); +void MPU6050::setFullScaleGyroRange(uint8_t range) { + I2Cdev::writeBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, range); +} + +// SELF TEST FACTORY TRIM VALUES + +/** Get self-test factory trim value for accelerometer X axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_X + */ +uint8_t MPU6050::getAccelXSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_X, &buffer[0]); + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_A, &buffer[1]); + return (buffer[0]>>3) | ((buffer[1]>>4) & 0x03); +} + +/** Get self-test factory trim value for accelerometer Y axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_Y + */ +uint8_t MPU6050::getAccelYSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_Y, &buffer[0]); + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_A, &buffer[1]); + return (buffer[0]>>3) | ((buffer[1]>>2) & 0x03); +} + +/** Get self-test factory trim value for accelerometer Z axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_Z + */ +uint8_t MPU6050::getAccelZSelfTestFactoryTrim() { + I2Cdev::readBytes(devAddr, MPU6050_RA_SELF_TEST_Z, 2, buffer); + return (buffer[0]>>3) | (buffer[1] & 0x03); +} + +/** Get self-test factory trim value for gyro X axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_X + */ +uint8_t MPU6050::getGyroXSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_X, buffer); + return (buffer[0] & 0x1F); +} + +/** Get self-test factory trim value for gyro Y axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_Y + */ +uint8_t MPU6050::getGyroYSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_Y, buffer); + return (buffer[0] & 0x1F); +} + +/** Get self-test factory trim value for gyro Z axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_Z + */ +uint8_t MPU6050::getGyroZSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_Z, buffer); + return (buffer[0] & 0x1F); } // ACCEL_CONFIG register @@ -302,52 +281,46 @@ * @return Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ -bool MPU6050::getAccelXSelfTest() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, buffer); +bool MPU6050::getAccelXSelfTest() { + I2Cdev::readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, buffer); return buffer[0]; } /** Get self-test enabled setting for accelerometer X axis. * @param enabled Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ -void MPU6050::setAccelXSelfTest(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, enabled); +void MPU6050::setAccelXSelfTest(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, enabled); } /** Get self-test enabled value for accelerometer Y axis. * @return Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ -bool MPU6050::getAccelYSelfTest() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, buffer); +bool MPU6050::getAccelYSelfTest() { + I2Cdev::readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, buffer); return buffer[0]; } /** Get self-test enabled value for accelerometer Y axis. * @param enabled Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ -void MPU6050::setAccelYSelfTest(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, enabled); +void MPU6050::setAccelYSelfTest(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, enabled); } /** Get self-test enabled value for accelerometer Z axis. * @return Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ -bool MPU6050::getAccelZSelfTest() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, buffer); +bool MPU6050::getAccelZSelfTest() { + I2Cdev::readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, buffer); return buffer[0]; } /** Set self-test enabled value for accelerometer Z axis. * @param enabled Self-test enabled value * @see MPU6050_RA_ACCEL_CONFIG */ -void MPU6050::setAccelZSelfTest(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, enabled); +void MPU6050::setAccelZSelfTest(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, enabled); } /** Get full-scale accelerometer range. * The FS_SEL parameter allows setting the full-scale range of the accelerometer @@ -366,18 +339,16 @@ * @see MPU6050_ACONFIG_AFS_SEL_BIT * @see MPU6050_ACONFIG_AFS_SEL_LENGTH */ -uint8_t MPU6050::getFullScaleAccelRange() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, buffer); +uint8_t MPU6050::getFullScaleAccelRange() { + I2Cdev::readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, buffer); return buffer[0]; } /** Set full-scale accelerometer range. * @param range New full-scale accelerometer range setting * @see getFullScaleAccelRange() */ -void MPU6050::setFullScaleAccelRange(uint8_t range) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, range); +void MPU6050::setFullScaleAccelRange(uint8_t range) { + I2Cdev::writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, range); } /** Get the high-pass filter configuration. * The DHPF is a filter module in the path leading to motion detectors (Free @@ -414,9 +385,8 @@ * @see MPU6050_DHPF_RESET * @see MPU6050_RA_ACCEL_CONFIG */ -uint8_t MPU6050::getDHPFMode() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, buffer); +uint8_t MPU6050::getDHPFMode() { + I2Cdev::readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, buffer); return buffer[0]; } /** Set the high-pass filter configuration. @@ -425,9 +395,8 @@ * @see MPU6050_DHPF_RESET * @see MPU6050_RA_ACCEL_CONFIG */ -void MPU6050::setDHPFMode(uint8_t bandwidth) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, bandwidth); +void MPU6050::setDHPFMode(uint8_t bandwidth) { + I2Cdev::writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, bandwidth); } // FF_THR register @@ -447,9 +416,8 @@ * @return Current free-fall acceleration threshold value (LSB = 2mg) * @see MPU6050_RA_FF_THR */ -uint8_t MPU6050::getFreefallDetectionThreshold() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_FF_THR, buffer); +uint8_t MPU6050::getFreefallDetectionThreshold() { + I2Cdev::readByte(devAddr, MPU6050_RA_FF_THR, buffer); return buffer[0]; } /** Get free-fall event acceleration threshold. @@ -457,9 +425,8 @@ * @see getFreefallDetectionThreshold() * @see MPU6050_RA_FF_THR */ -void MPU6050::setFreefallDetectionThreshold(uint8_t threshold) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_FF_THR, threshold); +void MPU6050::setFreefallDetectionThreshold(uint8_t threshold) { + I2Cdev::writeByte(devAddr, MPU6050_RA_FF_THR, threshold); } // FF_DUR register @@ -481,9 +448,8 @@ * @return Current free-fall duration threshold value (LSB = 1ms) * @see MPU6050_RA_FF_DUR */ -uint8_t MPU6050::getFreefallDetectionDuration() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_FF_DUR, buffer); +uint8_t MPU6050::getFreefallDetectionDuration() { + I2Cdev::readByte(devAddr, MPU6050_RA_FF_DUR, buffer); return buffer[0]; } /** Get free-fall event duration threshold. @@ -491,9 +457,8 @@ * @see getFreefallDetectionDuration() * @see MPU6050_RA_FF_DUR */ -void MPU6050::setFreefallDetectionDuration(uint8_t duration) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_FF_DUR, duration); +void MPU6050::setFreefallDetectionDuration(uint8_t duration) { + I2Cdev::writeByte(devAddr, MPU6050_RA_FF_DUR, duration); } // MOT_THR register @@ -517,19 +482,17 @@ * @return Current motion detection acceleration threshold value (LSB = 2mg) * @see MPU6050_RA_MOT_THR */ -uint8_t MPU6050::getMotionDetectionThreshold() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_MOT_THR, buffer); +uint8_t MPU6050::getMotionDetectionThreshold() { + I2Cdev::readByte(devAddr, MPU6050_RA_MOT_THR, buffer); return buffer[0]; } -/** Set free-fall event acceleration threshold. +/** Set motion detection event acceleration threshold. * @param threshold New motion detection acceleration threshold value (LSB = 2mg) * @see getMotionDetectionThreshold() * @see MPU6050_RA_MOT_THR */ -void MPU6050::setMotionDetectionThreshold(uint8_t threshold) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_MOT_THR, threshold); +void MPU6050::setMotionDetectionThreshold(uint8_t threshold) { + I2Cdev::writeByte(devAddr, MPU6050_RA_MOT_THR, threshold); } // MOT_DUR register @@ -549,9 +512,8 @@ * @return Current motion detection duration threshold value (LSB = 1ms) * @see MPU6050_RA_MOT_DUR */ -uint8_t MPU6050::getMotionDetectionDuration() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_MOT_DUR, buffer); +uint8_t MPU6050::getMotionDetectionDuration() { + I2Cdev::readByte(devAddr, MPU6050_RA_MOT_DUR, buffer); return buffer[0]; } /** Set motion detection event duration threshold. @@ -559,9 +521,8 @@ * @see getMotionDetectionDuration() * @see MPU6050_RA_MOT_DUR */ -void MPU6050::setMotionDetectionDuration(uint8_t duration) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_MOT_DUR, duration); +void MPU6050::setMotionDetectionDuration(uint8_t duration) { + I2Cdev::writeByte(devAddr, MPU6050_RA_MOT_DUR, duration); } // ZRMOT_THR register @@ -591,9 +552,8 @@ * @return Current zero motion detection acceleration threshold value (LSB = 2mg) * @see MPU6050_RA_ZRMOT_THR */ -uint8_t MPU6050::getZeroMotionDetectionThreshold() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_ZRMOT_THR, buffer); +uint8_t MPU6050::getZeroMotionDetectionThreshold() { + I2Cdev::readByte(devAddr, MPU6050_RA_ZRMOT_THR, buffer); return buffer[0]; } /** Set zero motion detection event acceleration threshold. @@ -601,9 +561,8 @@ * @see getZeroMotionDetectionThreshold() * @see MPU6050_RA_ZRMOT_THR */ -void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_THR, threshold); +void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold) { + I2Cdev::writeByte(devAddr, MPU6050_RA_ZRMOT_THR, threshold); } // ZRMOT_DUR register @@ -624,9 +583,8 @@ * @return Current zero motion detection duration threshold value (LSB = 64ms) * @see MPU6050_RA_ZRMOT_DUR */ -uint8_t MPU6050::getZeroMotionDetectionDuration() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_ZRMOT_DUR, buffer); +uint8_t MPU6050::getZeroMotionDetectionDuration() { + I2Cdev::readByte(devAddr, MPU6050_RA_ZRMOT_DUR, buffer); return buffer[0]; } /** Set zero motion detection event duration threshold. @@ -634,9 +592,8 @@ * @see getZeroMotionDetectionDuration() * @see MPU6050_RA_ZRMOT_DUR */ -void MPU6050::setZeroMotionDetectionDuration(uint8_t duration) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_DUR, duration); +void MPU6050::setZeroMotionDetectionDuration(uint8_t duration) { + I2Cdev::writeByte(devAddr, MPU6050_RA_ZRMOT_DUR, duration); } // FIFO_EN register @@ -647,9 +604,8 @@ * @return Current temperature FIFO enabled value * @see MPU6050_RA_FIFO_EN */ -bool MPU6050::getTempFIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, buffer); +bool MPU6050::getTempFIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set temperature FIFO enabled value. @@ -657,9 +613,8 @@ * @see getTempFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ -void MPU6050::setTempFIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, enabled); +void MPU6050::setTempFIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, enabled); } /** Get gyroscope X-axis FIFO enabled value. * When set to 1, this bit enables GYRO_XOUT_H and GYRO_XOUT_L (Registers 67 and @@ -667,9 +622,8 @@ * @return Current gyroscope X-axis FIFO enabled value * @see MPU6050_RA_FIFO_EN */ -bool MPU6050::getXGyroFIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, buffer); +bool MPU6050::getXGyroFIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set gyroscope X-axis FIFO enabled value. @@ -677,9 +631,8 @@ * @see getXGyroFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ -void MPU6050::setXGyroFIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, enabled); +void MPU6050::setXGyroFIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, enabled); } /** Get gyroscope Y-axis FIFO enabled value. * When set to 1, this bit enables GYRO_YOUT_H and GYRO_YOUT_L (Registers 69 and @@ -687,9 +640,8 @@ * @return Current gyroscope Y-axis FIFO enabled value * @see MPU6050_RA_FIFO_EN */ -bool MPU6050::getYGyroFIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, buffer); +bool MPU6050::getYGyroFIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set gyroscope Y-axis FIFO enabled value. @@ -697,9 +649,8 @@ * @see getYGyroFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ -void MPU6050::setYGyroFIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, enabled); +void MPU6050::setYGyroFIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, enabled); } /** Get gyroscope Z-axis FIFO enabled value. * When set to 1, this bit enables GYRO_ZOUT_H and GYRO_ZOUT_L (Registers 71 and @@ -707,9 +658,8 @@ * @return Current gyroscope Z-axis FIFO enabled value * @see MPU6050_RA_FIFO_EN */ -bool MPU6050::getZGyroFIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, buffer); +bool MPU6050::getZGyroFIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set gyroscope Z-axis FIFO enabled value. @@ -717,9 +667,8 @@ * @see getZGyroFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ -void MPU6050::setZGyroFIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, enabled); +void MPU6050::setZGyroFIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, enabled); } /** Get accelerometer FIFO enabled value. * When set to 1, this bit enables ACCEL_XOUT_H, ACCEL_XOUT_L, ACCEL_YOUT_H, @@ -728,9 +677,8 @@ * @return Current accelerometer FIFO enabled value * @see MPU6050_RA_FIFO_EN */ -bool MPU6050::getAccelFIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, buffer); +bool MPU6050::getAccelFIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set accelerometer FIFO enabled value. @@ -738,9 +686,8 @@ * @see getAccelFIFOEnabled() * @see MPU6050_RA_FIFO_EN */ -void MPU6050::setAccelFIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, enabled); +void MPU6050::setAccelFIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, enabled); } /** Get Slave 2 FIFO enabled value. * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) @@ -748,9 +695,8 @@ * @return Current Slave 2 FIFO enabled value * @see MPU6050_RA_FIFO_EN */ -bool MPU6050::getSlave2FIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, buffer); +bool MPU6050::getSlave2FIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 2 FIFO enabled value. @@ -758,9 +704,8 @@ * @see getSlave2FIFOEnabled() * @see MPU6050_RA_FIFO_EN */ -void MPU6050::setSlave2FIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, enabled); +void MPU6050::setSlave2FIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, enabled); } /** Get Slave 1 FIFO enabled value. * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) @@ -768,9 +713,8 @@ * @return Current Slave 1 FIFO enabled value * @see MPU6050_RA_FIFO_EN */ -bool MPU6050::getSlave1FIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, buffer); +bool MPU6050::getSlave1FIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 1 FIFO enabled value. @@ -778,9 +722,8 @@ * @see getSlave1FIFOEnabled() * @see MPU6050_RA_FIFO_EN */ -void MPU6050::setSlave1FIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, enabled); +void MPU6050::setSlave1FIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, enabled); } /** Get Slave 0 FIFO enabled value. * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) @@ -788,9 +731,8 @@ * @return Current Slave 0 FIFO enabled value * @see MPU6050_RA_FIFO_EN */ -bool MPU6050::getSlave0FIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, buffer); +bool MPU6050::getSlave0FIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 0 FIFO enabled value. @@ -798,9 +740,8 @@ * @see getSlave0FIFOEnabled() * @see MPU6050_RA_FIFO_EN */ -void MPU6050::setSlave0FIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, enabled); +void MPU6050::setSlave0FIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, enabled); } // I2C_MST_CTRL register @@ -820,9 +761,8 @@ * @return Current multi-master enabled value * @see MPU6050_RA_I2C_MST_CTRL */ -bool MPU6050::getMultiMasterEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, buffer); +bool MPU6050::getMultiMasterEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, buffer); return buffer[0]; } /** Set multi-master enabled value. @@ -830,9 +770,8 @@ * @see getMultiMasterEnabled() * @see MPU6050_RA_I2C_MST_CTRL */ -void MPU6050::setMultiMasterEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, enabled); +void MPU6050::setMultiMasterEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, enabled); } /** Get wait-for-external-sensor-data enabled value. * When the WAIT_FOR_ES bit is set to 1, the Data Ready interrupt will be @@ -845,9 +784,8 @@ * @return Current wait-for-external-sensor-data enabled value * @see MPU6050_RA_I2C_MST_CTRL */ -bool MPU6050::getWaitForExternalSensorEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, buffer); +bool MPU6050::getWaitForExternalSensorEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, buffer); return buffer[0]; } /** Set wait-for-external-sensor-data enabled value. @@ -855,9 +793,8 @@ * @see getWaitForExternalSensorEnabled() * @see MPU6050_RA_I2C_MST_CTRL */ -void MPU6050::setWaitForExternalSensorEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, enabled); +void MPU6050::setWaitForExternalSensorEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, enabled); } /** Get Slave 3 FIFO enabled value. * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96) @@ -865,9 +802,8 @@ * @return Current Slave 3 FIFO enabled value * @see MPU6050_RA_MST_CTRL */ -bool MPU6050::getSlave3FIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, buffer); +bool MPU6050::getSlave3FIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 3 FIFO enabled value. @@ -875,9 +811,8 @@ * @see getSlave3FIFOEnabled() * @see MPU6050_RA_MST_CTRL */ -void MPU6050::setSlave3FIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, enabled); +void MPU6050::setSlave3FIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, enabled); } /** Get slave read/write transition enabled value. * The I2C_MST_P_NSR bit configures the I2C Master's transition from one slave @@ -889,9 +824,8 @@ * @return Current slave read/write transition enabled value * @see MPU6050_RA_I2C_MST_CTRL */ -bool MPU6050::getSlaveReadWriteTransitionEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, buffer); +bool MPU6050::getSlaveReadWriteTransitionEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, buffer); return buffer[0]; } /** Set slave read/write transition enabled value. @@ -899,9 +833,8 @@ * @see getSlaveReadWriteTransitionEnabled() * @see MPU6050_RA_I2C_MST_CTRL */ -void MPU6050::setSlaveReadWriteTransitionEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, enabled); +void MPU6050::setSlaveReadWriteTransitionEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, enabled); } /** Get I2C master clock speed. * I2C_MST_CLK is a 4 bit unsigned value which configures a divider on the @@ -932,18 +865,16 @@ * @return Current I2C master clock speed * @see MPU6050_RA_I2C_MST_CTRL */ -uint8_t MPU6050::getMasterClockSpeed() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, buffer); +uint8_t MPU6050::getMasterClockSpeed() { + I2Cdev::readBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, buffer); return buffer[0]; } /** Set I2C master clock speed. * @reparam speed Current I2C master clock speed * @see MPU6050_RA_I2C_MST_CTRL */ -void MPU6050::setMasterClockSpeed(uint8_t speed) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, speed); +void MPU6050::setMasterClockSpeed(uint8_t speed) { + I2Cdev::writeBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, speed); } // I2C_SLV* registers (Slave 0-3) @@ -989,10 +920,9 @@ * @return Current address for specified slave * @see MPU6050_RA_I2C_SLV0_ADDR */ -uint8_t MPU6050::getSlaveAddress(uint8_t num) -{ +uint8_t MPU6050::getSlaveAddress(uint8_t num) { if (num > 3) return 0; - i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, buffer); return buffer[0]; } /** Set the I2C address of the specified slave (0-3). @@ -1001,10 +931,9 @@ * @see getSlaveAddress() * @see MPU6050_RA_I2C_SLV0_ADDR */ -void MPU6050::setSlaveAddress(uint8_t num, uint8_t address) -{ +void MPU6050::setSlaveAddress(uint8_t num, uint8_t address) { if (num > 3) return; - i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, address); + I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, address); } /** Get the active internal register for the specified slave (0-3). * Read/write operations for this slave will be done to whatever internal @@ -1017,10 +946,9 @@ * @return Current active register for specified slave * @see MPU6050_RA_I2C_SLV0_REG */ -uint8_t MPU6050::getSlaveRegister(uint8_t num) -{ +uint8_t MPU6050::getSlaveRegister(uint8_t num) { if (num > 3) return 0; - i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, buffer); return buffer[0]; } /** Set the active internal register for the specified slave (0-3). @@ -1029,10 +957,9 @@ * @see getSlaveRegister() * @see MPU6050_RA_I2C_SLV0_REG */ -void MPU6050::setSlaveRegister(uint8_t num, uint8_t reg) -{ +void MPU6050::setSlaveRegister(uint8_t num, uint8_t reg) { if (num > 3) return; - i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, reg); + I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, reg); } /** Get the enabled value for the specified slave (0-3). * When set to 1, this bit enables Slave 0 for data transfer operations. When @@ -1041,22 +968,20 @@ * @return Current enabled value for specified slave * @see MPU6050_RA_I2C_SLV0_CTRL */ -bool MPU6050::getSlaveEnabled(uint8_t num) -{ +bool MPU6050::getSlaveEnabled(uint8_t num) { if (num > 3) return 0; - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, buffer); return buffer[0]; } /** Set the enabled value for the specified slave (0-3). * @param num Slave number (0-3) - * @param enabled New enabled value for specified slave + * @param enabled New enabled value for specified slave * @see getSlaveEnabled() * @see MPU6050_RA_I2C_SLV0_CTRL */ -void MPU6050::setSlaveEnabled(uint8_t num, bool enabled) -{ +void MPU6050::setSlaveEnabled(uint8_t num, bool enabled) { if (num > 3) return; - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, enabled); + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_EN_BIT, enabled); } /** Get word pair byte-swapping enabled for the specified slave (0-3). * When set to 1, this bit enables byte swapping. When byte swapping is enabled, @@ -1069,10 +994,9 @@ * @return Current word pair byte-swapping enabled value for specified slave * @see MPU6050_RA_I2C_SLV0_CTRL */ -bool MPU6050::getSlaveWordByteSwap(uint8_t num) -{ +bool MPU6050::getSlaveWordByteSwap(uint8_t num) { if (num > 3) return 0; - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, buffer); return buffer[0]; } /** Set word pair byte-swapping enabled for the specified slave (0-3). @@ -1081,10 +1005,9 @@ * @see getSlaveWordByteSwap() * @see MPU6050_RA_I2C_SLV0_CTRL */ -void MPU6050::setSlaveWordByteSwap(uint8_t num, bool enabled) -{ +void MPU6050::setSlaveWordByteSwap(uint8_t num, bool enabled) { if (num > 3) return; - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, enabled); + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_BYTE_SW_BIT, enabled); } /** Get write mode for the specified slave (0-3). * When set to 1, the transaction will read or write data only. When cleared to @@ -1096,10 +1019,9 @@ * @return Current write mode for specified slave (0 = register address + data, 1 = data only) * @see MPU6050_RA_I2C_SLV0_CTRL */ -bool MPU6050::getSlaveWriteMode(uint8_t num) -{ +bool MPU6050::getSlaveWriteMode(uint8_t num) { if (num > 3) return 0; - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, buffer); return buffer[0]; } /** Set write mode for the specified slave (0-3). @@ -1108,10 +1030,9 @@ * @see getSlaveWriteMode() * @see MPU6050_RA_I2C_SLV0_CTRL */ -void MPU6050::setSlaveWriteMode(uint8_t num, bool mode) -{ +void MPU6050::setSlaveWriteMode(uint8_t num, bool mode) { if (num > 3) return; - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, mode); + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_REG_DIS_BIT, mode); } /** Get word pair grouping order offset for the specified slave (0-3). * This sets specifies the grouping order of word pairs received from registers. @@ -1124,10 +1045,9 @@ * @return Current word pair grouping order offset for specified slave * @see MPU6050_RA_I2C_SLV0_CTRL */ -bool MPU6050::getSlaveWordGroupOffset(uint8_t num) -{ +bool MPU6050::getSlaveWordGroupOffset(uint8_t num) { if (num > 3) return 0; - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, buffer); return buffer[0]; } /** Set word pair grouping order offset for the specified slave (0-3). @@ -1136,10 +1056,9 @@ * @see getSlaveWordGroupOffset() * @see MPU6050_RA_I2C_SLV0_CTRL */ -void MPU6050::setSlaveWordGroupOffset(uint8_t num, bool enabled) -{ +void MPU6050::setSlaveWordGroupOffset(uint8_t num, bool enabled) { if (num > 3) return; - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, enabled); + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_GRP_BIT, enabled); } /** Get number of bytes to read for the specified slave (0-3). * Specifies the number of bytes transferred to and from Slave 0. Clearing this @@ -1148,10 +1067,9 @@ * @return Number of bytes to read for specified slave * @see MPU6050_RA_I2C_SLV0_CTRL */ -uint8_t MPU6050::getSlaveDataLength(uint8_t num) -{ +uint8_t MPU6050::getSlaveDataLength(uint8_t num) { if (num > 3) return 0; - i2Cdev.readBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, buffer); + I2Cdev::readBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, buffer); return buffer[0]; } /** Set number of bytes to read for the specified slave (0-3). @@ -1160,10 +1078,9 @@ * @see getSlaveDataLength() * @see MPU6050_RA_I2C_SLV0_CTRL */ -void MPU6050::setSlaveDataLength(uint8_t num, uint8_t length) -{ +void MPU6050::setSlaveDataLength(uint8_t num, uint8_t length) { if (num > 3) return; - i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, length); + I2Cdev::writeBits(devAddr, MPU6050_RA_I2C_SLV0_CTRL + num*3, MPU6050_I2C_SLV_LEN_BIT, MPU6050_I2C_SLV_LEN_LENGTH, length); } // I2C_SLV* registers (Slave 4) @@ -1177,9 +1094,8 @@ * @see getSlaveAddress() * @see MPU6050_RA_I2C_SLV4_ADDR */ -uint8_t MPU6050::getSlave4Address() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, buffer); +uint8_t MPU6050::getSlave4Address() { + I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, buffer); return buffer[0]; } /** Set the I2C address of Slave 4. @@ -1187,9 +1103,8 @@ * @see getSlave4Address() * @see MPU6050_RA_I2C_SLV4_ADDR */ -void MPU6050::setSlave4Address(uint8_t address) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, address); +void MPU6050::setSlave4Address(uint8_t address) { + I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, address); } /** Get the active internal register for the Slave 4. * Read/write operations for this slave will be done to whatever internal @@ -1198,9 +1113,8 @@ * @return Current active register for Slave 4 * @see MPU6050_RA_I2C_SLV4_REG */ -uint8_t MPU6050::getSlave4Register() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_REG, buffer); +uint8_t MPU6050::getSlave4Register() { + I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_REG, buffer); return buffer[0]; } /** Set the active internal register for Slave 4. @@ -1208,9 +1122,8 @@ * @see getSlave4Register() * @see MPU6050_RA_I2C_SLV4_REG */ -void MPU6050::setSlave4Register(uint8_t reg) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_REG, reg); +void MPU6050::setSlave4Register(uint8_t reg) { + I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV4_REG, reg); } /** Set new byte to write to Slave 4. * This register stores the data to be written into the Slave 4. If I2C_SLV4_RW @@ -1218,9 +1131,8 @@ * @param data New byte to write to Slave 4 * @see MPU6050_RA_I2C_SLV4_DO */ -void MPU6050::setSlave4OutputByte(uint8_t data) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_DO, data); +void MPU6050::setSlave4OutputByte(uint8_t data) { + I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV4_DO, data); } /** Get the enabled value for the Slave 4. * When set to 1, this bit enables Slave 4 for data transfer operations. When @@ -1228,9 +1140,8 @@ * @return Current enabled value for Slave 4 * @see MPU6050_RA_I2C_SLV4_CTRL */ -bool MPU6050::getSlave4Enabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, buffer); +bool MPU6050::getSlave4Enabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, buffer); return buffer[0]; } /** Set the enabled value for Slave 4. @@ -1238,9 +1149,8 @@ * @see getSlave4Enabled() * @see MPU6050_RA_I2C_SLV4_CTRL */ -void MPU6050::setSlave4Enabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, enabled); +void MPU6050::setSlave4Enabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, enabled); } /** Get the enabled value for Slave 4 transaction interrupts. * When set to 1, this bit enables the generation of an interrupt signal upon @@ -1251,9 +1161,8 @@ * @return Current enabled value for Slave 4 transaction interrupts. * @see MPU6050_RA_I2C_SLV4_CTRL */ -bool MPU6050::getSlave4InterruptEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, buffer); +bool MPU6050::getSlave4InterruptEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, buffer); return buffer[0]; } /** Set the enabled value for Slave 4 transaction interrupts. @@ -1261,9 +1170,8 @@ * @see getSlave4InterruptEnabled() * @see MPU6050_RA_I2C_SLV4_CTRL */ -void MPU6050::setSlave4InterruptEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, enabled); +void MPU6050::setSlave4InterruptEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, enabled); } /** Get write mode for Slave 4. * When set to 1, the transaction will read or write data only. When cleared to @@ -1274,9 +1182,8 @@ * @return Current write mode for Slave 4 (0 = register address + data, 1 = data only) * @see MPU6050_RA_I2C_SLV4_CTRL */ -bool MPU6050::getSlave4WriteMode() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, buffer); +bool MPU6050::getSlave4WriteMode() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, buffer); return buffer[0]; } /** Set write mode for the Slave 4. @@ -1284,9 +1191,8 @@ * @see getSlave4WriteMode() * @see MPU6050_RA_I2C_SLV4_CTRL */ -void MPU6050::setSlave4WriteMode(bool mode) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, mode); +void MPU6050::setSlave4WriteMode(bool mode) { + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, mode); } /** Get Slave 4 master delay value. * This configures the reduced access rate of I2C slaves relative to the Sample @@ -1303,9 +1209,8 @@ * @return Current Slave 4 master delay value * @see MPU6050_RA_I2C_SLV4_CTRL */ -uint8_t MPU6050::getSlave4MasterDelay() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, buffer); +uint8_t MPU6050::getSlave4MasterDelay() { + I2Cdev::readBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, buffer); return buffer[0]; } /** Set Slave 4 master delay value. @@ -1313,9 +1218,8 @@ * @see getSlave4MasterDelay() * @see MPU6050_RA_I2C_SLV4_CTRL */ -void MPU6050::setSlave4MasterDelay(uint8_t delay) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, delay); +void MPU6050::setSlave4MasterDelay(uint8_t delay) { + I2Cdev::writeBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, delay); } /** Get last available byte read from Slave 4. * This register stores the data read from Slave 4. This field is populated @@ -1323,9 +1227,8 @@ * @return Last available byte read from to Slave 4 * @see MPU6050_RA_I2C_SLV4_DI */ -uint8_t MPU6050::getSlate4InputByte() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_DI, buffer); +uint8_t MPU6050::getSlate4InputByte() { + I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_DI, buffer); return buffer[0]; } @@ -1340,9 +1243,8 @@ * @return FSYNC interrupt status * @see MPU6050_RA_I2C_MST_STATUS */ -bool MPU6050::getPassthroughStatus() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_PASS_THROUGH_BIT, buffer); +bool MPU6050::getPassthroughStatus() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_PASS_THROUGH_BIT, buffer); return buffer[0]; } /** Get Slave 4 transaction done status. @@ -1353,9 +1255,8 @@ * @return Slave 4 transaction done status * @see MPU6050_RA_I2C_MST_STATUS */ -bool MPU6050::getSlave4IsDone() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_DONE_BIT, buffer); +bool MPU6050::getSlave4IsDone() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_DONE_BIT, buffer); return buffer[0]; } /** Get master arbitration lost status. @@ -1365,9 +1266,8 @@ * @return Master arbitration lost status * @see MPU6050_RA_I2C_MST_STATUS */ -bool MPU6050::getLostArbitration() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_LOST_ARB_BIT, buffer); +bool MPU6050::getLostArbitration() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_LOST_ARB_BIT, buffer); return buffer[0]; } /** Get Slave 4 NACK status. @@ -1377,9 +1277,8 @@ * @return Slave 4 NACK interrupt status * @see MPU6050_RA_I2C_MST_STATUS */ -bool MPU6050::getSlave4Nack() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_NACK_BIT, buffer); +bool MPU6050::getSlave4Nack() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_NACK_BIT, buffer); return buffer[0]; } /** Get Slave 3 NACK status. @@ -1389,9 +1288,8 @@ * @return Slave 3 NACK interrupt status * @see MPU6050_RA_I2C_MST_STATUS */ -bool MPU6050::getSlave3Nack() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV3_NACK_BIT, buffer); +bool MPU6050::getSlave3Nack() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV3_NACK_BIT, buffer); return buffer[0]; } /** Get Slave 2 NACK status. @@ -1401,9 +1299,8 @@ * @return Slave 2 NACK interrupt status * @see MPU6050_RA_I2C_MST_STATUS */ -bool MPU6050::getSlave2Nack() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV2_NACK_BIT, buffer); +bool MPU6050::getSlave2Nack() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV2_NACK_BIT, buffer); return buffer[0]; } /** Get Slave 1 NACK status. @@ -1413,9 +1310,8 @@ * @return Slave 1 NACK interrupt status * @see MPU6050_RA_I2C_MST_STATUS */ -bool MPU6050::getSlave1Nack() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV1_NACK_BIT, buffer); +bool MPU6050::getSlave1Nack() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV1_NACK_BIT, buffer); return buffer[0]; } /** Get Slave 0 NACK status. @@ -1425,9 +1321,8 @@ * @return Slave 0 NACK interrupt status * @see MPU6050_RA_I2C_MST_STATUS */ -bool MPU6050::getSlave0Nack() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV0_NACK_BIT, buffer); +bool MPU6050::getSlave0Nack() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV0_NACK_BIT, buffer); return buffer[0]; } @@ -1439,9 +1334,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_INT_LEVEL_BIT */ -bool MPU6050::getInterruptMode() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, buffer); +bool MPU6050::getInterruptMode() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, buffer); return buffer[0]; } /** Set interrupt logic level mode. @@ -1450,9 +1344,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_INT_LEVEL_BIT */ -void MPU6050::setInterruptMode(bool mode) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, mode); +void MPU6050::setInterruptMode(bool mode) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, mode); } /** Get interrupt drive mode. * Will be set 0 for push-pull, 1 for open-drain. @@ -1460,9 +1353,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_INT_OPEN_BIT */ -bool MPU6050::getInterruptDrive() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, buffer); +bool MPU6050::getInterruptDrive() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, buffer); return buffer[0]; } /** Set interrupt drive mode. @@ -1471,9 +1363,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_INT_OPEN_BIT */ -void MPU6050::setInterruptDrive(bool drive) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, drive); +void MPU6050::setInterruptDrive(bool drive) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, drive); } /** Get interrupt latch mode. * Will be set 0 for 50us-pulse, 1 for latch-until-int-cleared. @@ -1481,9 +1372,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_LATCH_INT_EN_BIT */ -bool MPU6050::getInterruptLatch() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, buffer); +bool MPU6050::getInterruptLatch() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, buffer); return buffer[0]; } /** Set interrupt latch mode. @@ -1492,9 +1382,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_LATCH_INT_EN_BIT */ -void MPU6050::setInterruptLatch(bool latch) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, latch); +void MPU6050::setInterruptLatch(bool latch) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, latch); } /** Get interrupt latch clear mode. * Will be set 0 for status-read-only, 1 for any-register-read. @@ -1502,9 +1391,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT */ -bool MPU6050::getInterruptLatchClear() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, buffer); +bool MPU6050::getInterruptLatchClear() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, buffer); return buffer[0]; } /** Set interrupt latch clear mode. @@ -1513,9 +1401,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT */ -void MPU6050::setInterruptLatchClear(bool clear) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, clear); +void MPU6050::setInterruptLatchClear(bool clear) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, clear); } /** Get FSYNC interrupt logic level mode. * @return Current FSYNC interrupt mode (0=active-high, 1=active-low) @@ -1523,9 +1410,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT */ -bool MPU6050::getFSyncInterruptLevel() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, buffer); +bool MPU6050::getFSyncInterruptLevel() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, buffer); return buffer[0]; } /** Set FSYNC interrupt logic level mode. @@ -1534,9 +1420,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT */ -void MPU6050::setFSyncInterruptLevel(bool level) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, level); +void MPU6050::setFSyncInterruptLevel(bool level) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, level); } /** Get FSYNC pin interrupt enabled setting. * Will be set 0 for disabled, 1 for enabled. @@ -1544,9 +1429,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT */ -bool MPU6050::getFSyncInterruptEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, buffer); +bool MPU6050::getFSyncInterruptEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, buffer); return buffer[0]; } /** Set FSYNC pin interrupt enabled setting. @@ -1555,9 +1439,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT */ -void MPU6050::setFSyncInterruptEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, enabled); +void MPU6050::setFSyncInterruptEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, enabled); } /** Get I2C bypass enabled status. * When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to @@ -1570,9 +1453,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT */ -bool MPU6050::getI2CBypassEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, buffer); +bool MPU6050::getI2CBypassEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, buffer); return buffer[0]; } /** Set I2C bypass enabled status. @@ -1586,9 +1468,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT */ -void MPU6050::setI2CBypassEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, enabled); +void MPU6050::setI2CBypassEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, enabled); } /** Get reference clock output enabled status. * When this bit is equal to 1, a reference clock output is provided at the @@ -1599,9 +1480,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_CLKOUT_EN_BIT */ -bool MPU6050::getClockOutputEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, buffer); +bool MPU6050::getClockOutputEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, buffer); return buffer[0]; } /** Set reference clock output enabled status. @@ -1613,9 +1493,8 @@ * @see MPU6050_RA_INT_PIN_CFG * @see MPU6050_INTCFG_CLKOUT_EN_BIT */ -void MPU6050::setClockOutputEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, enabled); +void MPU6050::setClockOutputEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, enabled); } // INT_ENABLE register @@ -1627,9 +1506,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_FF_BIT **/ -uint8_t MPU6050::getIntEnabled() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_INT_ENABLE, buffer); +uint8_t MPU6050::getIntEnabled() { + I2Cdev::readByte(devAddr, MPU6050_RA_INT_ENABLE, buffer); return buffer[0]; } /** Set full interrupt enabled status. @@ -1640,9 +1518,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_FF_BIT **/ -void MPU6050::setIntEnabled(uint8_t enabled) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_INT_ENABLE, enabled); +void MPU6050::setIntEnabled(uint8_t enabled) { + I2Cdev::writeByte(devAddr, MPU6050_RA_INT_ENABLE, enabled); } /** Get Free Fall interrupt enabled status. * Will be set 0 for disabled, 1 for enabled. @@ -1650,9 +1527,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_FF_BIT **/ -bool MPU6050::getIntFreefallEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, buffer); +bool MPU6050::getIntFreefallEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, buffer); return buffer[0]; } /** Set Free Fall interrupt enabled status. @@ -1661,9 +1537,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_FF_BIT **/ -void MPU6050::setIntFreefallEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, enabled); +void MPU6050::setIntFreefallEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, enabled); } /** Get Motion Detection interrupt enabled status. * Will be set 0 for disabled, 1 for enabled. @@ -1671,9 +1546,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_MOT_BIT **/ -bool MPU6050::getIntMotionEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, buffer); +bool MPU6050::getIntMotionEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, buffer); return buffer[0]; } /** Set Motion Detection interrupt enabled status. @@ -1682,9 +1556,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_MOT_BIT **/ -void MPU6050::setIntMotionEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, enabled); +void MPU6050::setIntMotionEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, enabled); } /** Get Zero Motion Detection interrupt enabled status. * Will be set 0 for disabled, 1 for enabled. @@ -1692,9 +1565,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_ZMOT_BIT **/ -bool MPU6050::getIntZeroMotionEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, buffer); +bool MPU6050::getIntZeroMotionEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, buffer); return buffer[0]; } /** Set Zero Motion Detection interrupt enabled status. @@ -1703,9 +1575,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_ZMOT_BIT **/ -void MPU6050::setIntZeroMotionEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, enabled); +void MPU6050::setIntZeroMotionEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, enabled); } /** Get FIFO Buffer Overflow interrupt enabled status. * Will be set 0 for disabled, 1 for enabled. @@ -1713,9 +1584,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT **/ -bool MPU6050::getIntFIFOBufferOverflowEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer); +bool MPU6050::getIntFIFOBufferOverflowEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer); return buffer[0]; } /** Set FIFO Buffer Overflow interrupt enabled status. @@ -1724,9 +1594,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT **/ -void MPU6050::setIntFIFOBufferOverflowEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, enabled); +void MPU6050::setIntFIFOBufferOverflowEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, enabled); } /** Get I2C Master interrupt enabled status. * This enables any of the I2C Master interrupt sources to generate an @@ -1735,9 +1604,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT **/ -bool MPU6050::getIntI2CMasterEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer); +bool MPU6050::getIntI2CMasterEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer); return buffer[0]; } /** Set I2C Master interrupt enabled status. @@ -1746,9 +1614,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT **/ -void MPU6050::setIntI2CMasterEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, enabled); +void MPU6050::setIntI2CMasterEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, enabled); } /** Get Data Ready interrupt enabled setting. * This event occurs each time a write operation to all of the sensor registers @@ -1757,9 +1624,8 @@ * @see MPU6050_RA_INT_ENABLE * @see MPU6050_INTERRUPT_DATA_RDY_BIT */ -bool MPU6050::getIntDataReadyEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer); +bool MPU6050::getIntDataReadyEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer); return buffer[0]; } /** Set Data Ready interrupt enabled status. @@ -1768,9 +1634,8 @@ * @see MPU6050_RA_INT_CFG * @see MPU6050_INTERRUPT_DATA_RDY_BIT */ -void MPU6050::setIntDataReadyEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, enabled); +void MPU6050::setIntDataReadyEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, enabled); } // INT_STATUS register @@ -1782,9 +1647,8 @@ * @return Current interrupt status * @see MPU6050_RA_INT_STATUS */ -uint8_t MPU6050::getIntStatus() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_INT_STATUS, buffer); +uint8_t MPU6050::getIntStatus() { + I2Cdev::readByte(devAddr, MPU6050_RA_INT_STATUS, buffer); return buffer[0]; } /** Get Free Fall interrupt status. @@ -1794,9 +1658,8 @@ * @see MPU6050_RA_INT_STATUS * @see MPU6050_INTERRUPT_FF_BIT */ -bool MPU6050::getIntFreefallStatus() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FF_BIT, buffer); +bool MPU6050::getIntFreefallStatus() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FF_BIT, buffer); return buffer[0]; } /** Get Motion Detection interrupt status. @@ -1806,9 +1669,8 @@ * @see MPU6050_RA_INT_STATUS * @see MPU6050_INTERRUPT_MOT_BIT */ -bool MPU6050::getIntMotionStatus() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_MOT_BIT, buffer); +bool MPU6050::getIntMotionStatus() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_MOT_BIT, buffer); return buffer[0]; } /** Get Zero Motion Detection interrupt status. @@ -1818,9 +1680,8 @@ * @see MPU6050_RA_INT_STATUS * @see MPU6050_INTERRUPT_ZMOT_BIT */ -bool MPU6050::getIntZeroMotionStatus() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_ZMOT_BIT, buffer); +bool MPU6050::getIntZeroMotionStatus() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_ZMOT_BIT, buffer); return buffer[0]; } /** Get FIFO Buffer Overflow interrupt status. @@ -1830,9 +1691,8 @@ * @see MPU6050_RA_INT_STATUS * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT */ -bool MPU6050::getIntFIFOBufferOverflowStatus() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer); +bool MPU6050::getIntFIFOBufferOverflowStatus() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer); return buffer[0]; } /** Get I2C Master interrupt status. @@ -1843,9 +1703,8 @@ * @see MPU6050_RA_INT_STATUS * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT */ -bool MPU6050::getIntI2CMasterStatus() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer); +bool MPU6050::getIntI2CMasterStatus() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer); return buffer[0]; } /** Get Data Ready interrupt status. @@ -1855,9 +1714,8 @@ * @see MPU6050_RA_INT_STATUS * @see MPU6050_INTERRUPT_DATA_RDY_BIT */ -bool MPU6050::getIntDataReadyStatus() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer); +bool MPU6050::getIntDataReadyStatus() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer); return buffer[0]; } @@ -1879,19 +1737,9 @@ * @see getRotation() * @see MPU6050_RA_ACCEL_XOUT_H */ -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) -{ +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) { getMotion6(ax, ay, az, gx, gy, gz); - - // magnetometer reading - i2Cdev.writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x02); //set i2c bypass enable pin to true to access magnetometer - wait_ms(10); // necessary wait >=6ms - i2Cdev.writeByte(MPU9150_RA_MAG_ADDRESS, 0x0A, 0x01); // enable the magnetometer - wait_ms(10); // necessary wait >=6ms - i2Cdev.readBytes(MPU9150_RA_MAG_ADDRESS, MPU9150_RA_MAG_XOUT_L, 6, buffer); - *mx = (((int16_t)buffer[0]) << 8) | buffer[1]; - *my = (((int16_t)buffer[2]) << 8) | buffer[3]; - *mz = (((int16_t)buffer[4]) << 8) | buffer[5]; + // TODO: magnetometer integration } /** Get raw 6-axis motion sensor readings (accel/gyro). * Retrieves all currently available motion sensor values. @@ -1905,9 +1753,8 @@ * @see getRotation() * @see MPU6050_RA_ACCEL_XOUT_H */ -void MPU6050::getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz) -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 14, buffer); +void MPU6050::getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz) { + I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 14, buffer); *ax = (((int16_t)buffer[0]) << 8) | buffer[1]; *ay = (((int16_t)buffer[2]) << 8) | buffer[3]; *az = (((int16_t)buffer[4]) << 8) | buffer[5]; @@ -1951,9 +1798,8 @@ * @param z 16-bit signed integer container for Z-axis acceleration * @see MPU6050_RA_GYRO_XOUT_H */ -void MPU6050::getAcceleration(int16_t* x, int16_t* y, int16_t* z) -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 6, buffer); +void MPU6050::getAcceleration(int16_t* x, int16_t* y, int16_t* z) { + I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 6, buffer); *x = (((int16_t)buffer[0]) << 8) | buffer[1]; *y = (((int16_t)buffer[2]) << 8) | buffer[3]; *z = (((int16_t)buffer[4]) << 8) | buffer[5]; @@ -1963,9 +1809,8 @@ * @see getMotion6() * @see MPU6050_RA_ACCEL_XOUT_H */ -int16_t MPU6050::getAccelerationX() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 2, buffer); +int16_t MPU6050::getAccelerationX() { + I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } /** Get Y-axis accelerometer reading. @@ -1973,9 +1818,8 @@ * @see getMotion6() * @see MPU6050_RA_ACCEL_YOUT_H */ -int16_t MPU6050::getAccelerationY() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_YOUT_H, 2, buffer); +int16_t MPU6050::getAccelerationY() { + I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_YOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } /** Get Z-axis accelerometer reading. @@ -1983,9 +1827,8 @@ * @see getMotion6() * @see MPU6050_RA_ACCEL_ZOUT_H */ -int16_t MPU6050::getAccelerationZ() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_ACCEL_ZOUT_H, 2, buffer); +int16_t MPU6050::getAccelerationZ() { + I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_ZOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } @@ -1995,9 +1838,8 @@ * @return Temperature reading in 16-bit 2's complement format * @see MPU6050_RA_TEMP_OUT_H */ -int16_t MPU6050::getTemperature() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_TEMP_OUT_H, 2, buffer); +int16_t MPU6050::getTemperature() { + I2Cdev::readBytes(devAddr, MPU6050_RA_TEMP_OUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } @@ -2035,9 +1877,8 @@ * @see getMotion6() * @see MPU6050_RA_GYRO_XOUT_H */ -void MPU6050::getRotation(int16_t* x, int16_t* y, int16_t* z) -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 6, buffer); +void MPU6050::getRotation(int16_t* x, int16_t* y, int16_t* z) { + I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 6, buffer); *x = (((int16_t)buffer[0]) << 8) | buffer[1]; *y = (((int16_t)buffer[2]) << 8) | buffer[3]; *z = (((int16_t)buffer[4]) << 8) | buffer[5]; @@ -2047,9 +1888,8 @@ * @see getMotion6() * @see MPU6050_RA_GYRO_XOUT_H */ -int16_t MPU6050::getRotationX() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 2, buffer); +int16_t MPU6050::getRotationX() { + I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } /** Get Y-axis gyroscope reading. @@ -2057,9 +1897,8 @@ * @see getMotion6() * @see MPU6050_RA_GYRO_YOUT_H */ -int16_t MPU6050::getRotationY() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_YOUT_H, 2, buffer); +int16_t MPU6050::getRotationY() { + I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_YOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } /** Get Z-axis gyroscope reading. @@ -2067,9 +1906,8 @@ * @see getMotion6() * @see MPU6050_RA_GYRO_ZOUT_H */ -int16_t MPU6050::getRotationZ() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_GYRO_ZOUT_H, 2, buffer); +int16_t MPU6050::getRotationZ() { + I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_ZOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } @@ -2149,9 +1987,8 @@ * @param position Starting position (0-23) * @return Byte read from register */ -uint8_t MPU6050::getExternalSensorByte(int position) -{ - i2Cdev.readByte(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, buffer); +uint8_t MPU6050::getExternalSensorByte(int position) { + I2Cdev::readByte(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, buffer); return buffer[0]; } /** Read word (2 bytes) from external sensor data registers. @@ -2159,9 +1996,8 @@ * @return Word read from register * @see getExternalSensorByte() */ -uint16_t MPU6050::getExternalSensorWord(int position) -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 2, buffer); +uint16_t MPU6050::getExternalSensorWord(int position) { + I2Cdev::readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 2, buffer); return (((uint16_t)buffer[0]) << 8) | buffer[1]; } /** Read double word (4 bytes) from external sensor data registers. @@ -2169,22 +2005,28 @@ * @return Double word read from registers * @see getExternalSensorByte() */ -uint32_t MPU6050::getExternalSensorDWord(int position) -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 4, buffer); +uint32_t MPU6050::getExternalSensorDWord(int position) { + I2Cdev::readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 4, buffer); return (((uint32_t)buffer[0]) << 24) | (((uint32_t)buffer[1]) << 16) | (((uint16_t)buffer[2]) << 8) | buffer[3]; } // MOT_DETECT_STATUS register +/** Get full motion detection status register content (all bits). + * @return Motion detection status byte + * @see MPU6050_RA_MOT_DETECT_STATUS + */ +uint8_t MPU6050::getMotionStatus() { + I2Cdev::readByte(devAddr, MPU6050_RA_MOT_DETECT_STATUS, buffer); + return buffer[0]; +} /** Get X-axis negative motion detection interrupt status. * @return Motion detection status * @see MPU6050_RA_MOT_DETECT_STATUS * @see MPU6050_MOTION_MOT_XNEG_BIT */ -bool MPU6050::getXNegMotionDetected() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XNEG_BIT, buffer); +bool MPU6050::getXNegMotionDetected() { + I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XNEG_BIT, buffer); return buffer[0]; } /** Get X-axis positive motion detection interrupt status. @@ -2192,9 +2034,8 @@ * @see MPU6050_RA_MOT_DETECT_STATUS * @see MPU6050_MOTION_MOT_XPOS_BIT */ -bool MPU6050::getXPosMotionDetected() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XPOS_BIT, buffer); +bool MPU6050::getXPosMotionDetected() { + I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XPOS_BIT, buffer); return buffer[0]; } /** Get Y-axis negative motion detection interrupt status. @@ -2202,9 +2043,8 @@ * @see MPU6050_RA_MOT_DETECT_STATUS * @see MPU6050_MOTION_MOT_YNEG_BIT */ -bool MPU6050::getYNegMotionDetected() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YNEG_BIT, buffer); +bool MPU6050::getYNegMotionDetected() { + I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YNEG_BIT, buffer); return buffer[0]; } /** Get Y-axis positive motion detection interrupt status. @@ -2212,9 +2052,8 @@ * @see MPU6050_RA_MOT_DETECT_STATUS * @see MPU6050_MOTION_MOT_YPOS_BIT */ -bool MPU6050::getYPosMotionDetected() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YPOS_BIT, buffer); +bool MPU6050::getYPosMotionDetected() { + I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YPOS_BIT, buffer); return buffer[0]; } /** Get Z-axis negative motion detection interrupt status. @@ -2222,9 +2061,8 @@ * @see MPU6050_RA_MOT_DETECT_STATUS * @see MPU6050_MOTION_MOT_ZNEG_BIT */ -bool MPU6050::getZNegMotionDetected() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZNEG_BIT, buffer); +bool MPU6050::getZNegMotionDetected() { + I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZNEG_BIT, buffer); return buffer[0]; } /** Get Z-axis positive motion detection interrupt status. @@ -2232,9 +2070,8 @@ * @see MPU6050_RA_MOT_DETECT_STATUS * @see MPU6050_MOTION_MOT_ZPOS_BIT */ -bool MPU6050::getZPosMotionDetected() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZPOS_BIT, buffer); +bool MPU6050::getZPosMotionDetected() { + I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZPOS_BIT, buffer); return buffer[0]; } /** Get zero motion detection interrupt status. @@ -2242,9 +2079,8 @@ * @see MPU6050_RA_MOT_DETECT_STATUS * @see MPU6050_MOTION_MOT_ZRMOT_BIT */ -bool MPU6050::getZeroMotionDetected() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZRMOT_BIT, buffer); +bool MPU6050::getZeroMotionDetected() { + I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZRMOT_BIT, buffer); return buffer[0]; } @@ -2258,10 +2094,9 @@ * @param data Byte to write * @see MPU6050_RA_I2C_SLV0_DO */ -void MPU6050::setSlaveOutputByte(uint8_t num, uint8_t data) -{ +void MPU6050::setSlaveOutputByte(uint8_t num, uint8_t data) { if (num > 3) return; - i2Cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV0_DO + num, data); + I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV0_DO + num, data); } // I2C_MST_DELAY_CTRL register @@ -2274,9 +2109,8 @@ * @see MPU6050_RA_I2C_MST_DELAY_CTRL * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT */ -bool MPU6050::getExternalShadowDelayEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, buffer); +bool MPU6050::getExternalShadowDelayEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, buffer); return buffer[0]; } /** Set external data shadow delay enabled status. @@ -2285,9 +2119,8 @@ * @see MPU6050_RA_I2C_MST_DELAY_CTRL * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT */ -void MPU6050::setExternalShadowDelayEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, enabled); +void MPU6050::setExternalShadowDelayEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, enabled); } /** Get slave delay enabled status. * When a particular slave delay is enabled, the rate of access for the that @@ -2307,11 +2140,10 @@ * @see MPU6050_RA_I2C_MST_DELAY_CTRL * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT */ -bool MPU6050::getSlaveDelayEnabled(uint8_t num) -{ +bool MPU6050::getSlaveDelayEnabled(uint8_t num) { // MPU6050_DELAYCTRL_I2C_SLV4_DLY_EN_BIT is 4, SLV3 is 3, etc. if (num > 4) return 0; - i2Cdev.readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, buffer); return buffer[0]; } /** Set slave delay enabled status. @@ -2320,9 +2152,8 @@ * @see MPU6050_RA_I2C_MST_DELAY_CTRL * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT */ -void MPU6050::setSlaveDelayEnabled(uint8_t num, bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, enabled); +void MPU6050::setSlaveDelayEnabled(uint8_t num, bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, enabled); } // SIGNAL_PATH_RESET register @@ -2333,9 +2164,8 @@ * @see MPU6050_RA_SIGNAL_PATH_RESET * @see MPU6050_PATHRESET_GYRO_RESET_BIT */ -void MPU6050::resetGyroscopePath() -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_GYRO_RESET_BIT, true); +void MPU6050::resetGyroscopePath() { + I2Cdev::writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_GYRO_RESET_BIT, true); } /** Reset accelerometer signal path. * The reset will revert the signal path analog to digital converters and @@ -2343,9 +2173,8 @@ * @see MPU6050_RA_SIGNAL_PATH_RESET * @see MPU6050_PATHRESET_ACCEL_RESET_BIT */ -void MPU6050::resetAccelerometerPath() -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_ACCEL_RESET_BIT, true); +void MPU6050::resetAccelerometerPath() { + I2Cdev::writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_ACCEL_RESET_BIT, true); } /** Reset temperature sensor signal path. * The reset will revert the signal path analog to digital converters and @@ -2353,9 +2182,8 @@ * @see MPU6050_RA_SIGNAL_PATH_RESET * @see MPU6050_PATHRESET_TEMP_RESET_BIT */ -void MPU6050::resetTemperaturePath() -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_TEMP_RESET_BIT, true); +void MPU6050::resetTemperaturePath() { + I2Cdev::writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_TEMP_RESET_BIT, true); } // MOT_DETECT_CTRL register @@ -2374,9 +2202,8 @@ * @see MPU6050_RA_MOT_DETECT_CTRL * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT */ -uint8_t MPU6050::getAccelerometerPowerOnDelay() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, buffer); +uint8_t MPU6050::getAccelerometerPowerOnDelay() { + I2Cdev::readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, buffer); return buffer[0]; } /** Set accelerometer power-on delay. @@ -2385,9 +2212,8 @@ * @see MPU6050_RA_MOT_DETECT_CTRL * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT */ -void MPU6050::setAccelerometerPowerOnDelay(uint8_t delay) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, delay); +void MPU6050::setAccelerometerPowerOnDelay(uint8_t delay) { + I2Cdev::writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, delay); } /** Get Free Fall detection counter decrement configuration. * Detection is registered by the Free Fall detection module after accelerometer @@ -2415,9 +2241,8 @@ * @see MPU6050_RA_MOT_DETECT_CTRL * @see MPU6050_DETECT_FF_COUNT_BIT */ -uint8_t MPU6050::getFreefallDetectionCounterDecrement() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, buffer); +uint8_t MPU6050::getFreefallDetectionCounterDecrement() { + I2Cdev::readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, buffer); return buffer[0]; } /** Set Free Fall detection counter decrement configuration. @@ -2426,9 +2251,8 @@ * @see MPU6050_RA_MOT_DETECT_CTRL * @see MPU6050_DETECT_FF_COUNT_BIT */ -void MPU6050::setFreefallDetectionCounterDecrement(uint8_t decrement) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, decrement); +void MPU6050::setFreefallDetectionCounterDecrement(uint8_t decrement) { + I2Cdev::writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, decrement); } /** Get Motion detection counter decrement configuration. * Detection is registered by the Motion detection module after accelerometer @@ -2453,9 +2277,8 @@ * please refer to Registers 29 to 32. * */ -uint8_t MPU6050::getMotionDetectionCounterDecrement() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, buffer); +uint8_t MPU6050::getMotionDetectionCounterDecrement() { + I2Cdev::readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, buffer); return buffer[0]; } /** Set Motion detection counter decrement configuration. @@ -2464,9 +2287,8 @@ * @see MPU6050_RA_MOT_DETECT_CTRL * @see MPU6050_DETECT_MOT_COUNT_BIT */ -void MPU6050::setMotionDetectionCounterDecrement(uint8_t decrement) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, decrement); +void MPU6050::setMotionDetectionCounterDecrement(uint8_t decrement) { + I2Cdev::writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, decrement); } // USER_CTRL register @@ -2479,9 +2301,8 @@ * @see MPU6050_RA_USER_CTRL * @see MPU6050_USERCTRL_FIFO_EN_BIT */ -bool MPU6050::getFIFOEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, buffer); +bool MPU6050::getFIFOEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set FIFO enabled status. @@ -2490,9 +2311,8 @@ * @see MPU6050_RA_USER_CTRL * @see MPU6050_USERCTRL_FIFO_EN_BIT */ -void MPU6050::setFIFOEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, enabled); +void MPU6050::setFIFOEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, enabled); } /** Get I2C Master Mode enabled status. * When this mode is enabled, the MPU-60X0 acts as the I2C Master to the @@ -2505,9 +2325,8 @@ * @see MPU6050_RA_USER_CTRL * @see MPU6050_USERCTRL_I2C_MST_EN_BIT */ -bool MPU6050::getI2CMasterModeEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, buffer); +bool MPU6050::getI2CMasterModeEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, buffer); return buffer[0]; } /** Set I2C Master Mode enabled status. @@ -2516,17 +2335,15 @@ * @see MPU6050_RA_USER_CTRL * @see MPU6050_USERCTRL_I2C_MST_EN_BIT */ -void MPU6050::setI2CMasterModeEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, enabled); +void MPU6050::setI2CMasterModeEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, enabled); } /** Switch from I2C to SPI mode (MPU-6000 only) * If this is set, the primary SPI interface will be enabled in place of the * disabled primary I2C interface. */ -void MPU6050::switchSPIEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_IF_DIS_BIT, enabled); +void MPU6050::switchSPIEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_IF_DIS_BIT, enabled); } /** Reset the FIFO. * This bit resets the FIFO buffer when set to 1 while FIFO_EN equals 0. This @@ -2534,9 +2351,8 @@ * @see MPU6050_RA_USER_CTRL * @see MPU6050_USERCTRL_FIFO_RESET_BIT */ -void MPU6050::resetFIFO() -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_RESET_BIT, true); +void MPU6050::resetFIFO() { + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_RESET_BIT, true); } /** Reset the I2C Master. * This bit resets the I2C Master when set to 1 while I2C_MST_EN equals 0. @@ -2544,9 +2360,8 @@ * @see MPU6050_RA_USER_CTRL * @see MPU6050_USERCTRL_I2C_MST_RESET_BIT */ -void MPU6050::resetI2CMaster() -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_RESET_BIT, true); +void MPU6050::resetI2CMaster() { + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_RESET_BIT, true); } /** Reset all sensor registers and signal paths. * When set to 1, this bit resets the signal paths for all sensors (gyroscopes, @@ -2560,9 +2375,8 @@ * @see MPU6050_RA_USER_CTRL * @see MPU6050_USERCTRL_SIG_COND_RESET_BIT */ -void MPU6050::resetSensors() -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_SIG_COND_RESET_BIT, true); +void MPU6050::resetSensors() { + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_SIG_COND_RESET_BIT, true); } // PWR_MGMT_1 register @@ -2572,9 +2386,8 @@ * @see MPU6050_RA_PWR_MGMT_1 * @see MPU6050_PWR1_DEVICE_RESET_BIT */ -void MPU6050::reset() -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_DEVICE_RESET_BIT, true); +void MPU6050::reset() { + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_DEVICE_RESET_BIT, true); } /** Get sleep mode status. * Setting the SLEEP bit in the register puts the device into very low power @@ -2587,9 +2400,8 @@ * @see MPU6050_RA_PWR_MGMT_1 * @see MPU6050_PWR1_SLEEP_BIT */ -bool MPU6050::getSleepEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, buffer); +bool MPU6050::getSleepEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, buffer); return buffer[0]; } /** Set sleep mode status. @@ -2598,9 +2410,8 @@ * @see MPU6050_RA_PWR_MGMT_1 * @see MPU6050_PWR1_SLEEP_BIT */ -void MPU6050::setSleepEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, enabled); +void MPU6050::setSleepEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, enabled); } /** Get wake cycle enabled status. * When this bit is set to 1 and SLEEP is disabled, the MPU-60X0 will cycle @@ -2610,9 +2421,8 @@ * @see MPU6050_RA_PWR_MGMT_1 * @see MPU6050_PWR1_CYCLE_BIT */ -bool MPU6050::getWakeCycleEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, buffer); +bool MPU6050::getWakeCycleEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, buffer); return buffer[0]; } /** Set wake cycle enabled status. @@ -2621,9 +2431,8 @@ * @see MPU6050_RA_PWR_MGMT_1 * @see MPU6050_PWR1_CYCLE_BIT */ -void MPU6050::setWakeCycleEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, enabled); +void MPU6050::setWakeCycleEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, enabled); } /** Get temperature sensor enabled status. * Control the usage of the internal temperature sensor. @@ -2636,9 +2445,8 @@ * @see MPU6050_RA_PWR_MGMT_1 * @see MPU6050_PWR1_TEMP_DIS_BIT */ -bool MPU6050::getTempSensorEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, buffer); +bool MPU6050::getTempSensorEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, buffer); return buffer[0] == 0; // 1 is actually disabled here } /** Set temperature sensor enabled status. @@ -2651,10 +2459,9 @@ * @see MPU6050_RA_PWR_MGMT_1 * @see MPU6050_PWR1_TEMP_DIS_BIT */ -void MPU6050::setTempSensorEnabled(bool enabled) -{ +void MPU6050::setTempSensorEnabled(bool enabled) { // 1 is actually disabled here - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, !enabled); + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, !enabled); } /** Get clock source setting. * @return Current clock source setting @@ -2662,9 +2469,8 @@ * @see MPU6050_PWR1_CLKSEL_BIT * @see MPU6050_PWR1_CLKSEL_LENGTH */ -uint8_t MPU6050::getClockSource() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, buffer); +uint8_t MPU6050::getClockSource() { + I2Cdev::readBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, buffer); return buffer[0]; } /** Set clock source setting. @@ -2697,9 +2503,8 @@ * @see MPU6050_PWR1_CLKSEL_BIT * @see MPU6050_PWR1_CLKSEL_LENGTH */ -void MPU6050::setClockSource(uint8_t source) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, source); +void MPU6050::setClockSource(uint8_t source) { + I2Cdev::writeBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, source); } // PWR_MGMT_2 register @@ -2719,7 +2524,7 @@ * 1 | 2.5 Hz * 2 | 5 Hz * 3 | 10 Hz - * <pre> + * </pre> * * For further information regarding the MPU-60X0's power modes, please refer to * Register 107. @@ -2727,18 +2532,16 @@ * @return Current wake frequency * @see MPU6050_RA_PWR_MGMT_2 */ -uint8_t MPU6050::getWakeFrequency() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, buffer); +uint8_t MPU6050::getWakeFrequency() { + I2Cdev::readBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, buffer); return buffer[0]; } /** Set wake frequency in Accel-Only Low Power Mode. * @param frequency New wake frequency * @see MPU6050_RA_PWR_MGMT_2 */ -void MPU6050::setWakeFrequency(uint8_t frequency) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, frequency); +void MPU6050::setWakeFrequency(uint8_t frequency) { + I2Cdev::writeBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, frequency); } /** Get X-axis accelerometer standby enabled status. @@ -2747,9 +2550,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_XA_BIT */ -bool MPU6050::getStandbyXAccelEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, buffer); +bool MPU6050::getStandbyXAccelEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, buffer); return buffer[0]; } /** Set X-axis accelerometer standby enabled status. @@ -2758,9 +2560,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_XA_BIT */ -void MPU6050::setStandbyXAccelEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, enabled); +void MPU6050::setStandbyXAccelEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, enabled); } /** Get Y-axis accelerometer standby enabled status. * If enabled, the Y-axis will not gather or report data (or use power). @@ -2768,9 +2569,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_YA_BIT */ -bool MPU6050::getStandbyYAccelEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, buffer); +bool MPU6050::getStandbyYAccelEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, buffer); return buffer[0]; } /** Set Y-axis accelerometer standby enabled status. @@ -2779,9 +2579,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_YA_BIT */ -void MPU6050::setStandbyYAccelEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, enabled); +void MPU6050::setStandbyYAccelEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, enabled); } /** Get Z-axis accelerometer standby enabled status. * If enabled, the Z-axis will not gather or report data (or use power). @@ -2789,9 +2588,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_ZA_BIT */ -bool MPU6050::getStandbyZAccelEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, buffer); +bool MPU6050::getStandbyZAccelEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, buffer); return buffer[0]; } /** Set Z-axis accelerometer standby enabled status. @@ -2800,9 +2598,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_ZA_BIT */ -void MPU6050::setStandbyZAccelEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, enabled); +void MPU6050::setStandbyZAccelEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, enabled); } /** Get X-axis gyroscope standby enabled status. * If enabled, the X-axis will not gather or report data (or use power). @@ -2810,9 +2607,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_XG_BIT */ -bool MPU6050::getStandbyXGyroEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, buffer); +bool MPU6050::getStandbyXGyroEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, buffer); return buffer[0]; } /** Set X-axis gyroscope standby enabled status. @@ -2821,9 +2617,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_XG_BIT */ -void MPU6050::setStandbyXGyroEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, enabled); +void MPU6050::setStandbyXGyroEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, enabled); } /** Get Y-axis gyroscope standby enabled status. * If enabled, the Y-axis will not gather or report data (or use power). @@ -2831,9 +2626,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_YG_BIT */ -bool MPU6050::getStandbyYGyroEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, buffer); +bool MPU6050::getStandbyYGyroEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, buffer); return buffer[0]; } /** Set Y-axis gyroscope standby enabled status. @@ -2842,9 +2636,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_YG_BIT */ -void MPU6050::setStandbyYGyroEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, enabled); +void MPU6050::setStandbyYGyroEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, enabled); } /** Get Z-axis gyroscope standby enabled status. * If enabled, the Z-axis will not gather or report data (or use power). @@ -2852,9 +2645,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_ZG_BIT */ -bool MPU6050::getStandbyZGyroEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, buffer); +bool MPU6050::getStandbyZGyroEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, buffer); return buffer[0]; } /** Set Z-axis gyroscope standby enabled status. @@ -2863,9 +2655,8 @@ * @see MPU6050_RA_PWR_MGMT_2 * @see MPU6050_PWR2_STBY_ZG_BIT */ -void MPU6050::setStandbyZGyroEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, enabled); +void MPU6050::setStandbyZGyroEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, enabled); } // FIFO_COUNT* registers @@ -2877,9 +2668,8 @@ * set of sensor data bound to be stored in the FIFO (register 35 and 36). * @return Current FIFO buffer size */ -uint16_t MPU6050::getFIFOCount() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_FIFO_COUNTH, 2, buffer); +uint16_t MPU6050::getFIFOCount() { + I2Cdev::readBytes(devAddr, MPU6050_RA_FIFO_COUNTH, 2, buffer); return (((uint16_t)buffer[0]) << 8) | buffer[1]; } @@ -2910,22 +2700,23 @@ * * @return Byte from FIFO buffer */ -uint8_t MPU6050::getFIFOByte() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_FIFO_R_W, buffer); +uint8_t MPU6050::getFIFOByte() { + I2Cdev::readByte(devAddr, MPU6050_RA_FIFO_R_W, buffer); return buffer[0]; } -void MPU6050::getFIFOBytes(uint8_t *data, uint8_t length) -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_FIFO_R_W, length, data); +void MPU6050::getFIFOBytes(uint8_t *data, uint8_t length) { + if(length > 0){ + I2Cdev::readBytes(devAddr, MPU6050_RA_FIFO_R_W, length, data); + } else { + *data = 0; + } } /** Write byte to FIFO buffer. * @see getFIFOByte() * @see MPU6050_RA_FIFO_R_W */ -void MPU6050::setFIFOByte(uint8_t data) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_FIFO_R_W, data); +void MPU6050::setFIFOByte(uint8_t data) { + I2Cdev::writeByte(devAddr, MPU6050_RA_FIFO_R_W, data); } // WHO_AM_I register @@ -2937,9 +2728,8 @@ * @see MPU6050_WHO_AM_I_BIT * @see MPU6050_WHO_AM_I_LENGTH */ -uint8_t MPU6050::getDeviceID() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, buffer); +uint8_t MPU6050::getDeviceID() { + I2Cdev::readBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, buffer); return buffer[0]; } /** Set Device ID. @@ -2951,279 +2741,232 @@ * @see MPU6050_WHO_AM_I_BIT * @see MPU6050_WHO_AM_I_LENGTH */ -void MPU6050::setDeviceID(uint8_t id) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, id); +void MPU6050::setDeviceID(uint8_t id) { + I2Cdev::writeBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, id); } // ======== UNDOCUMENTED/DMP REGISTERS/METHODS ======== // XG_OFFS_TC register -uint8_t MPU6050::getOTPBankValid() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, buffer); +uint8_t MPU6050::getOTPBankValid() { + I2Cdev::readBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, buffer); return buffer[0]; } -void MPU6050::setOTPBankValid(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, enabled); +void MPU6050::setOTPBankValid(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, enabled); } -int8_t MPU6050::getXGyroOffset() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); +int8_t MPU6050::getXGyroOffsetTC() { + I2Cdev::readBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); return buffer[0]; } -void MPU6050::setXGyroOffset(int8_t offset) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset); +void MPU6050::setXGyroOffsetTC(int8_t offset) { + I2Cdev::writeBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset); } // YG_OFFS_TC register -int8_t MPU6050::getYGyroOffset() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); +int8_t MPU6050::getYGyroOffsetTC() { + I2Cdev::readBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); return buffer[0]; } -void MPU6050::setYGyroOffset(int8_t offset) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset); +void MPU6050::setYGyroOffsetTC(int8_t offset) { + I2Cdev::writeBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset); } // ZG_OFFS_TC register -int8_t MPU6050::getZGyroOffset() -{ - i2Cdev.readBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); +int8_t MPU6050::getZGyroOffsetTC() { + I2Cdev::readBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); return buffer[0]; } -void MPU6050::setZGyroOffset(int8_t offset) -{ - i2Cdev.writeBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset); +void MPU6050::setZGyroOffsetTC(int8_t offset) { + I2Cdev::writeBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, offset); } // X_FINE_GAIN register -int8_t MPU6050::getXFineGain() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_X_FINE_GAIN, buffer); +int8_t MPU6050::getXFineGain() { + I2Cdev::readByte(devAddr, MPU6050_RA_X_FINE_GAIN, buffer); return buffer[0]; } -void MPU6050::setXFineGain(int8_t gain) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_X_FINE_GAIN, gain); +void MPU6050::setXFineGain(int8_t gain) { + I2Cdev::writeByte(devAddr, MPU6050_RA_X_FINE_GAIN, gain); } // Y_FINE_GAIN register -int8_t MPU6050::getYFineGain() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_Y_FINE_GAIN, buffer); +int8_t MPU6050::getYFineGain() { + I2Cdev::readByte(devAddr, MPU6050_RA_Y_FINE_GAIN, buffer); return buffer[0]; } -void MPU6050::setYFineGain(int8_t gain) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_Y_FINE_GAIN, gain); +void MPU6050::setYFineGain(int8_t gain) { + I2Cdev::writeByte(devAddr, MPU6050_RA_Y_FINE_GAIN, gain); } // Z_FINE_GAIN register -int8_t MPU6050::getZFineGain() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_Z_FINE_GAIN, buffer); +int8_t MPU6050::getZFineGain() { + I2Cdev::readByte(devAddr, MPU6050_RA_Z_FINE_GAIN, buffer); return buffer[0]; } -void MPU6050::setZFineGain(int8_t gain) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_Z_FINE_GAIN, gain); +void MPU6050::setZFineGain(int8_t gain) { + I2Cdev::writeByte(devAddr, MPU6050_RA_Z_FINE_GAIN, gain); } // XA_OFFS_* registers -int16_t MPU6050::getXAccelOffset() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_XA_OFFS_H, 2, buffer); +int16_t MPU6050::getXAccelOffset() { + I2Cdev::readBytes(devAddr, MPU6050_RA_XA_OFFS_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } -void MPU6050::setXAccelOffset(int16_t offset) -{ - i2Cdev.writeWord(devAddr, MPU6050_RA_XA_OFFS_H, offset); +void MPU6050::setXAccelOffset(int16_t offset) { + I2Cdev::writeWord(devAddr, MPU6050_RA_XA_OFFS_H, offset); } // YA_OFFS_* register -int16_t MPU6050::getYAccelOffset() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_YA_OFFS_H, 2, buffer); +int16_t MPU6050::getYAccelOffset() { + I2Cdev::readBytes(devAddr, MPU6050_RA_YA_OFFS_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } -void MPU6050::setYAccelOffset(int16_t offset) -{ - i2Cdev.writeWord(devAddr, MPU6050_RA_YA_OFFS_H, offset); +void MPU6050::setYAccelOffset(int16_t offset) { + I2Cdev::writeWord(devAddr, MPU6050_RA_YA_OFFS_H, offset); } // ZA_OFFS_* register -int16_t MPU6050::getZAccelOffset() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_ZA_OFFS_H, 2, buffer); +int16_t MPU6050::getZAccelOffset() { + I2Cdev::readBytes(devAddr, MPU6050_RA_ZA_OFFS_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } -void MPU6050::setZAccelOffset(int16_t offset) -{ - i2Cdev.writeWord(devAddr, MPU6050_RA_ZA_OFFS_H, offset); +void MPU6050::setZAccelOffset(int16_t offset) { + I2Cdev::writeWord(devAddr, MPU6050_RA_ZA_OFFS_H, offset); } // XG_OFFS_USR* registers -int16_t MPU6050::getXGyroOffsetUser() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_XG_OFFS_USRH, 2, buffer); +int16_t MPU6050::getXGyroOffset() { + I2Cdev::readBytes(devAddr, MPU6050_RA_XG_OFFS_USRH, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } -void MPU6050::setXGyroOffsetUser(int16_t offset) -{ - i2Cdev.writeWord(devAddr, MPU6050_RA_XG_OFFS_USRH, offset); +void MPU6050::setXGyroOffset(int16_t offset) { + I2Cdev::writeWord(devAddr, MPU6050_RA_XG_OFFS_USRH, offset); } // YG_OFFS_USR* register -int16_t MPU6050::getYGyroOffsetUser() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_YG_OFFS_USRH, 2, buffer); +int16_t MPU6050::getYGyroOffset() { + I2Cdev::readBytes(devAddr, MPU6050_RA_YG_OFFS_USRH, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } -void MPU6050::setYGyroOffsetUser(int16_t offset) -{ - i2Cdev.writeWord(devAddr, MPU6050_RA_YG_OFFS_USRH, offset); +void MPU6050::setYGyroOffset(int16_t offset) { + I2Cdev::writeWord(devAddr, MPU6050_RA_YG_OFFS_USRH, offset); } // ZG_OFFS_USR* register -int16_t MPU6050::getZGyroOffsetUser() -{ - i2Cdev.readBytes(devAddr, MPU6050_RA_ZG_OFFS_USRH, 2, buffer); +int16_t MPU6050::getZGyroOffset() { + I2Cdev::readBytes(devAddr, MPU6050_RA_ZG_OFFS_USRH, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } -void MPU6050::setZGyroOffsetUser(int16_t offset) -{ - i2Cdev.writeWord(devAddr, MPU6050_RA_ZG_OFFS_USRH, offset); +void MPU6050::setZGyroOffset(int16_t offset) { + I2Cdev::writeWord(devAddr, MPU6050_RA_ZG_OFFS_USRH, offset); } // INT_ENABLE register (DMP functions) -bool MPU6050::getIntPLLReadyEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer); +bool MPU6050::getIntPLLReadyEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer); return buffer[0]; } -void MPU6050::setIntPLLReadyEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, enabled); +void MPU6050::setIntPLLReadyEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, enabled); } -bool MPU6050::getIntDMPEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, buffer); +bool MPU6050::getIntDMPEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, buffer); return buffer[0]; } -void MPU6050::setIntDMPEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, enabled); +void MPU6050::setIntDMPEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, enabled); } // DMP_INT_STATUS -bool MPU6050::getDMPInt5Status() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_5_BIT, buffer); +bool MPU6050::getDMPInt5Status() { + I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_5_BIT, buffer); return buffer[0]; } -bool MPU6050::getDMPInt4Status() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_4_BIT, buffer); +bool MPU6050::getDMPInt4Status() { + I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_4_BIT, buffer); return buffer[0]; } -bool MPU6050::getDMPInt3Status() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_3_BIT, buffer); +bool MPU6050::getDMPInt3Status() { + I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_3_BIT, buffer); return buffer[0]; } -bool MPU6050::getDMPInt2Status() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_2_BIT, buffer); +bool MPU6050::getDMPInt2Status() { + I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_2_BIT, buffer); return buffer[0]; } -bool MPU6050::getDMPInt1Status() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_1_BIT, buffer); +bool MPU6050::getDMPInt1Status() { + I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_1_BIT, buffer); return buffer[0]; } -bool MPU6050::getDMPInt0Status() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_0_BIT, buffer); +bool MPU6050::getDMPInt0Status() { + I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_0_BIT, buffer); return buffer[0]; } // INT_STATUS register (DMP functions) -bool MPU6050::getIntPLLReadyStatus() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer); +bool MPU6050::getIntPLLReadyStatus() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer); return buffer[0]; } -bool MPU6050::getIntDMPStatus() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DMP_INT_BIT, buffer); +bool MPU6050::getIntDMPStatus() { + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DMP_INT_BIT, buffer); return buffer[0]; } // USER_CTRL register (DMP functions) -bool MPU6050::getDMPEnabled() -{ - i2Cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, buffer); +bool MPU6050::getDMPEnabled() { + I2Cdev::readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, buffer); return buffer[0]; } -void MPU6050::setDMPEnabled(bool enabled) -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, enabled); +void MPU6050::setDMPEnabled(bool enabled) { + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, enabled); } -void MPU6050::resetDMP() -{ - i2Cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_RESET_BIT, true); +void MPU6050::resetDMP() { + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_RESET_BIT, true); } // BANK_SEL register -void MPU6050::setMemoryBank(uint8_t bank, bool prefetchEnabled, bool userBank) -{ +void MPU6050::setMemoryBank(uint8_t bank, bool prefetchEnabled, bool userBank) { bank &= 0x1F; if (userBank) bank |= 0x20; if (prefetchEnabled) bank |= 0x40; - i2Cdev.writeByte(devAddr, MPU6050_RA_BANK_SEL, bank); + I2Cdev::writeByte(devAddr, MPU6050_RA_BANK_SEL, bank); } // MEM_START_ADDR register -void MPU6050::setMemoryStartAddress(uint8_t address) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_MEM_START_ADDR, address); +void MPU6050::setMemoryStartAddress(uint8_t address) { + I2Cdev::writeByte(devAddr, MPU6050_RA_MEM_START_ADDR, address); } // MEM_R_W register -uint8_t MPU6050::readMemoryByte() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_MEM_R_W, buffer); +uint8_t MPU6050::readMemoryByte() { + I2Cdev::readByte(devAddr, MPU6050_RA_MEM_R_W, buffer); return buffer[0]; } -void MPU6050::writeMemoryByte(uint8_t data) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_MEM_R_W, data); +void MPU6050::writeMemoryByte(uint8_t data) { + I2Cdev::writeByte(devAddr, MPU6050_RA_MEM_R_W, data); } -void MPU6050::readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address) -{ +void MPU6050::readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address) { setMemoryBank(bank); setMemoryStartAddress(address); uint8_t chunkSize; @@ -3238,7 +2981,7 @@ if (chunkSize > 256 - address) chunkSize = 256 - address; // read the chunk of data as specified - i2Cdev.readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, data + i); + I2Cdev::readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, data + i); // increase byte index by [chunkSize] i += chunkSize; @@ -3254,13 +2997,12 @@ } } } -bool MPU6050::writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify, bool useProgMem) -{ +bool MPU6050::writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify, bool useProgMem) { setMemoryBank(bank); setMemoryStartAddress(address); uint8_t chunkSize; - uint8_t *verifyBuffer = NULL; - uint8_t *progBuffer = NULL; + uint8_t *verifyBuffer; + uint8_t *progBuffer=0; uint16_t i; uint8_t j; if (verify) verifyBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE); @@ -3283,13 +3025,13 @@ progBuffer = (uint8_t *)data + i; } - i2Cdev.writeBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, progBuffer); + I2Cdev::writeBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, progBuffer); // verify data if needed if (verify && verifyBuffer) { setMemoryBank(bank); setMemoryStartAddress(address); - i2Cdev.readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, verifyBuffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, verifyBuffer); if (memcmp(progBuffer, verifyBuffer, chunkSize) != 0) { /*Serial.print("Block write verification error, bank "); Serial.print(bank, DEC); @@ -3331,14 +3073,12 @@ if (useProgMem) free(progBuffer); return true; } -bool MPU6050::writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify) -{ +bool MPU6050::writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify) { return writeMemoryBlock(data, dataSize, bank, address, verify, true); } -bool MPU6050::writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize, bool useProgMem) -{ +bool MPU6050::writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize, bool useProgMem) { + uint8_t *progBuffer = 0; uint8_t success, special; - uint8_t *progBuffer = NULL; uint16_t i, j; if (useProgMem) { progBuffer = (uint8_t *)malloc(8); // assume 8-byte blocks, realloc later if necessary @@ -3395,7 +3135,7 @@ //setIntZeroMotionEnabled(true); //setIntFIFOBufferOverflowEnabled(true); //setIntDMPEnabled(true); - i2Cdev.writeByte(devAddr, MPU6050_RA_INT_ENABLE, 0x32); // single operation + I2Cdev::writeByte(devAddr, MPU6050_RA_INT_ENABLE, 0x32); // single operation success = true; } else { @@ -3412,31 +3152,26 @@ if (useProgMem) free(progBuffer); return true; } -bool MPU6050::writeProgDMPConfigurationSet(const uint8_t *data, uint16_t dataSize) -{ - return writeDMPConfigurationSet(data, dataSize, false); +bool MPU6050::writeProgDMPConfigurationSet(const uint8_t *data, uint16_t dataSize) { + return writeDMPConfigurationSet(data, dataSize, true); } // DMP_CFG_1 register -uint8_t MPU6050::getDMPConfig1() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_DMP_CFG_1, buffer); +uint8_t MPU6050::getDMPConfig1() { + I2Cdev::readByte(devAddr, MPU6050_RA_DMP_CFG_1, buffer); return buffer[0]; } -void MPU6050::setDMPConfig1(uint8_t config) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_1, config); +void MPU6050::setDMPConfig1(uint8_t config) { + I2Cdev::writeByte(devAddr, MPU6050_RA_DMP_CFG_1, config); } // DMP_CFG_2 register -uint8_t MPU6050::getDMPConfig2() -{ - i2Cdev.readByte(devAddr, MPU6050_RA_DMP_CFG_2, buffer); +uint8_t MPU6050::getDMPConfig2() { + I2Cdev::readByte(devAddr, MPU6050_RA_DMP_CFG_2, buffer); return buffer[0]; } -void MPU6050::setDMPConfig2(uint8_t config) -{ - i2Cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_2, config); +void MPU6050::setDMPConfig2(uint8_t config) { + I2Cdev::writeByte(devAddr, MPU6050_RA_DMP_CFG_2, config); } \ No newline at end of file