This one compatable with brobot V3. first commit to BroBot
Dependents: BroBot_ESE350_Skeleton
Fork of MPU6050 by
Diff: MPU6050.cpp
- Revision:
- 6:f38dfe62d74c
- Parent:
- 3:25e1a5a10e53
- Child:
- 7:d5845b617139
--- a/MPU6050.cpp Sat Nov 23 16:47:00 2013 +0000 +++ b/MPU6050.cpp Sat Jan 30 17:12:45 2016 +0000 @@ -1,9 +1,3 @@ -//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> @@ -42,18 +36,10 @@ #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 +49,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 +60,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 +83,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 +93,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 +120,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 +129,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 +162,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 +171,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 +202,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 +214,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 +237,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 +249,8 @@ * @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); } // ACCEL_CONFIG register @@ -302,52 +259,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 +317,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 +363,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 +373,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 +394,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 +403,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 +426,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 +435,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,9 +460,8 @@ * @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. @@ -527,9 +469,8 @@ * @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 +490,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 +499,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 +530,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 +539,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 +561,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 +570,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 +582,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 +591,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 +600,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 +609,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 +618,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 +627,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 +636,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 +645,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 +655,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 +664,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 +673,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 +682,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 +691,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 +700,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 +709,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 +718,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 +739,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 +748,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 +762,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 +771,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 +780,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 +789,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 +802,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 +811,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 +843,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) @@ -953,7 +862,7 @@ * operation, and if it is cleared, then it's a write operation. The remaining * bits (6-0) are the 7-bit device address of the slave device. * - * In read mode, the result of the read is placed in the lowest available + * In read mode, the result of the read is placed in the lowest available * EXT_SENS_DATA register. For further information regarding the allocation of * read results, please refer to the EXT_SENS_DATA register description * (Registers 73 - 96). @@ -989,10 +898,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 +909,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 +924,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 +935,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 +946,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 +972,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 +983,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 +997,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 +1008,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 +1023,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 +1034,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 +1045,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 +1056,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 +1072,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 +1081,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 +1091,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 +1100,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 +1109,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 +1118,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 +1127,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 +1139,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 +1148,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 +1160,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 +1169,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 +1187,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 +1196,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 +1205,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 +1221,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 +1233,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 +1244,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 +1255,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 +1266,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 +1277,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 +1288,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 +1299,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 +1312,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 +1322,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 +1331,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 +1341,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 +1350,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 +1360,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 +1369,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 +1379,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 +1388,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 +1398,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 +1407,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 +1417,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 +1431,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 +1446,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 +1458,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 +1471,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 +1484,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 +1496,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 +1505,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 +1515,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 +1524,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 +1534,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 +1543,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 +1553,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 +1562,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 +1572,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 +1582,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 +1592,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 +1602,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 +1612,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 +1625,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 +1636,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 +1647,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 +1658,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 +1669,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 +1681,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 +1692,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 +1715,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 +1731,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 +1776,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 +1787,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 +1796,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 +1805,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 +1816,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 +1855,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 +1866,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 +1875,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 +1884,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 +1965,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 +1974,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 +1983,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 +2012,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 +2021,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 +2030,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 +2039,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 +2048,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 +2057,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 +2072,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 +2087,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 +2097,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 +2118,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 +2130,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 +2142,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 +2151,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 +2160,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 +2180,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 +2190,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 +2219,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 +2229,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 +2255,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 +2265,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 +2279,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 +2289,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 +2303,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 +2313,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 +2329,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 +2338,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 +2353,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 +2364,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 +2378,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 +2388,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 +2399,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 +2409,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 +2423,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 +2437,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 +2447,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 +2481,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 @@ -2727,18 +2510,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 +2528,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 +2538,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 +2547,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 +2557,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 +2566,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 +2576,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 +2585,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 +2595,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 +2604,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 +2614,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 +2623,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 +2633,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 +2646,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 +2678,19 @@ * * @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) { + i2cdev.readBytes(devAddr, MPU6050_RA_FIFO_R_W, length, data); } /** 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 +2702,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 +2715,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,8 +2955,8 @@ 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 +2971,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; uint16_t i; uint8_t j; if (verify) verifyBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE); @@ -3274,7 +2990,7 @@ // make sure this chunk doesn't go past the bank boundary (256 bytes) if (chunkSize > 256 - address) chunkSize = 256 - address; - + if (useProgMem) { // write the chunk of data as specified for (j = 0; j < chunkSize; j++) progBuffer[j] = pgm_read_byte(data + i + j); @@ -3283,13 +2999,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 +3047,11 @@ 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) -{ - uint8_t success, special; - uint8_t *progBuffer = NULL; +bool MPU6050::writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize, bool useProgMem) { + uint8_t *progBuffer, success, special; uint16_t i, j; if (useProgMem) { progBuffer = (uint8_t *)malloc(8); // assume 8-byte blocks, realloc later if necessary @@ -3391,11 +3104,11 @@ Serial.println(" found...");*/ if (special == 0x01) { // enable DMP-related interrupts - + //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 { @@ -3403,7 +3116,7 @@ success = false; } } - + if (!success) { if (useProgMem) free(progBuffer); return false; // uh oh @@ -3412,31 +3125,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); -} \ No newline at end of file +void MPU6050::setDMPConfig2(uint8_t config) { + i2cdev.writeByte(devAddr, MPU6050_RA_DMP_CFG_2, config); +}