使いやすいように。
Dependencies: ArduinoSerial I2Cdev
Fork of MPU6050 by
Revision 7:d5845b617139, committed 2016-01-31
- Comitter:
- syundo0730
- Date:
- Sun Jan 31 09:12:19 2016 +0000
- Parent:
- 6:f38dfe62d74c
- Child:
- 8:4ee054567b6c
- Commit message:
- trace changes in arduino project
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ArduinoSerial.lib Sun Jan 31 09:12:19 2016 +0000 @@ -0,0 +1,1 @@ +ArduinoSerial#35db472ea9e6
--- a/I2Cdev.cpp Sat Jan 30 17:12:45 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,267 +0,0 @@ -// ported from arduino library: https://github.com/jrowberg/i2cdevlib -// written by szymon gaertig (email: szymon@gaertig.com.pl, website: szymongaertig.pl) -// Changelog: -// 2013-01-08 - first release - -#include "I2Cdev.h" - -I2Cdev::I2Cdev(): i2c(I2C_SDA,I2C_SCL) {} - -I2Cdev::I2Cdev(PinName i2cSda, PinName i2cScl): i2c(i2cSda,i2cScl) {} - -/** Read a single bit from an 8-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to read from - * @param bitNum Bit position to read (0-7) - * @param data Container for single bit value - * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) - * @return Status of read operation (true = success) - */ -int8_t I2Cdev::readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout) { - uint8_t b; - uint8_t count = readByte(devAddr, regAddr, &b, timeout); - *data = b & (1 << bitNum); - return count; -} - -/** Read a single bit from a 16-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to read from - * @param bitNum Bit position to read (0-15) - * @param data Container for single bit value - * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) - * @return Status of read operation (true = success) - */ -int8_t I2Cdev::readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout) { - uint16_t b; - uint8_t count = readWord(devAddr, regAddr, &b, timeout); - *data = b & (1 << bitNum); - return count; -} - -/** Read multiple bits from an 8-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to read from - * @param bitStart First bit position to read (0-7) - * @param length Number of bits to read (not more than 8) - * @param data Container for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05) - * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) - * @return Status of read operation (true = success) - */ -int8_t I2Cdev::readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout) { - // 01101001 read byte - // 76543210 bit numbers - // xxx args: bitStart=4, length=3 - // 010 masked - // -> 010 shifted - uint8_t count, b; - if ((count = readByte(devAddr, regAddr, &b, timeout)) != 0) { - uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1); - b &= mask; - b >>= (bitStart - length + 1); - *data = b; - } - return count; -} - -/** Read multiple bits from a 16-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to read from - * @param bitStart First bit position to read (0-15) - * @param length Number of bits to read (not more than 16) - * @param data Container for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05) - * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) - * @return Status of read operation (1 = success, 0 = failure, -1 = timeout) - */ -int8_t I2Cdev::readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout) { - // 1101011001101001 read byte - // fedcba9876543210 bit numbers - // xxx args: bitStart=12, length=3 - // 010 masked - // -> 010 shifted - uint8_t count; - uint16_t w; - if ((count = readWord(devAddr, regAddr, &w, timeout)) != 0) { - uint16_t mask = ((1 << length) - 1) << (bitStart - length + 1); - w &= mask; - w >>= (bitStart - length + 1); - *data = w; - } - return count; -} -/** Read single byte from an 8-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to read from - * @param data Container for byte value read from device - * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) - * @return Status of read operation (true = success) - */ -int8_t I2Cdev::readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout) { - return readBytes(devAddr, regAddr, 1, data, timeout); -} - -/** Read single word from a 16-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to read from - * @param data Container for word value read from device - * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) - * @return Status of read operation (true = success) - */ -int8_t I2Cdev::readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout) { - return readWords(devAddr, regAddr, 1, data, timeout); -} - -/** Read multiple bytes from an 8-bit device register. - * @param devAddr I2C slave device address - * @param regAddr First register regAddr to read from - * @param length Number of bytes to read - * @param data Buffer to store read data in - * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) - * @return Number of bytes read (-1 indicates failure) - */ -int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout) -{ - char command[1]; - command[0] = regAddr; - char *redData = (char*)malloc(length); - i2c.write(devAddr<<1, command, 1, true); - i2c.read(devAddr<<1, redData, length); - for(int i =0; i < length; i++) { - data[i] = redData[i]; - } - free (redData); - return length; -} - -int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout) -{ - return 0; -} - -/** write a single bit in an 8-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to write to - * @param bitNum Bit position to write (0-7) - * @param value New bit value to write - * @return Status of operation (true = success) - */ -bool I2Cdev::writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data) { - uint8_t b; - readByte(devAddr, regAddr, &b); - b = (data != 0) ? (b | (1 << bitNum)) : (b & ~(1 << bitNum)); - return writeByte(devAddr, regAddr, b); -} - -/** write a single bit in a 16-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to write to - * @param bitNum Bit position to write (0-15) - * @param value New bit value to write - * @return Status of operation (true = success) - */ -bool I2Cdev::writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data) { - uint16_t w; - readWord(devAddr, regAddr, &w); - w = (data != 0) ? (w | (1 << bitNum)) : (w & ~(1 << bitNum)); - return writeWord(devAddr, regAddr, w); -} - -/** Write multiple bits in an 8-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to write to - * @param bitStart First bit position to write (0-7) - * @param length Number of bits to write (not more than 8) - * @param data Right-aligned value to write - * @return Status of operation (true = success) - */ -bool I2Cdev::writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data) { - // 010 value to write - // 76543210 bit numbers - // xxx args: bitStart=4, length=3 - // 00011100 mask byte - // 10101111 original value (sample) - // 10100011 original & ~mask - // 10101011 masked | value - uint8_t b; - if (readByte(devAddr, regAddr, &b) != 0) { - uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1); - data <<= (bitStart - length + 1); // shift data into correct position - data &= mask; // zero all non-important bits in data - b &= ~(mask); // zero all important bits in existing byte - b |= data; // combine data with existing byte - return writeByte(devAddr, regAddr, b); - } else { - return false; - } -} - -/** Write multiple bits in a 16-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register regAddr to write to - * @param bitStart First bit position to write (0-15) - * @param length Number of bits to write (not more than 16) - * @param data Right-aligned value to write - * @return Status of operation (true = success) - */ -bool I2Cdev::writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data) { - // 010 value to write - // fedcba9876543210 bit numbers - // xxx args: bitStart=12, length=3 - // 0001110000000000 mask byte - // 1010111110010110 original value (sample) - // 1010001110010110 original & ~mask - // 1010101110010110 masked | value - uint16_t w; - if (readWord(devAddr, regAddr, &w) != 0) { - uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1); - data <<= (bitStart - length + 1); // shift data into correct position - data &= mask; // zero all non-important bits in data - w &= ~(mask); // zero all important bits in existing word - w |= data; // combine data with existing word - return writeWord(devAddr, regAddr, w); - } else { - return false; - } -} - -/** Write single byte to an 8-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register address to write to - * @param data New byte value to write - * @return Status of operation (true = success) - */ -bool I2Cdev::writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data) { - return writeBytes(devAddr, regAddr, 1, &data); -} - -/** Write single word to a 16-bit device register. - * @param devAddr I2C slave device address - * @param regAddr Register address to write to - * @param data New word value to write - * @return Status of operation (true = success) - */ -bool I2Cdev::writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data) { - return writeWords(devAddr, regAddr, 1, &data); -} - -bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data) -{ - i2c.start(); - i2c.write(devAddr<<1); - i2c.write(regAddr); - for(int i = 0; i < length; i++) { - i2c.write(data[i]); - } - i2c.stop(); - return true; -} - -bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data) -{ - return true; -} - -uint16_t I2Cdev::readTimeout(void) -{ - return 0; -} \ No newline at end of file
--- a/I2Cdev.h Sat Jan 30 17:12:45 2016 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -//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 - -#ifndef I2Cdev_h -#define I2Cdev_h - -#include "mbed.h" - -#define I2C_SDA p28 -#define I2C_SCL p27 - -class I2Cdev { - private: - I2C i2c; - public: - I2Cdev(); - I2Cdev(PinName i2cSda, PinName i2cScl); - - int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); - int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); - int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); - int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); - int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); - int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); - int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); - int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); - - bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data); - bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data); - bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data); - bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data); - bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data); - bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data); - bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data); - bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data); - - static uint16_t readTimeout(void); -}; - -#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/I2Cdev/I2Cdev.cpp Sun Jan 31 09:12:19 2016 +0000 @@ -0,0 +1,273 @@ +// ported from arduino library: https://github.com/jrowberg/i2cdevlib +// written by szymon gaertig (email: szymon@gaertig.com.pl, website: szymongaertig.pl) +// modified by shundo kishi +// +// Changelog: +// 2013-01-08 - first release +// 2016-01-31 - changed all functions and variables static to make porting from arduino easier(by shundo kishi) + +#include "I2Cdev.h" + +I2C I2Cdev::i2c(I2C_SDA,I2C_SCL); + +/** Default constructor. + */ +I2Cdev::I2Cdev() { +} + +/** Read a single bit from an 8-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to read from + * @param bitNum Bit position to read (0-7) + * @param data Container for single bit value + * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) + * @return Status of read operation (true = success) + */ +int8_t I2Cdev::readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout) { + uint8_t b; + uint8_t count = readByte(devAddr, regAddr, &b, timeout); + *data = b & (1 << bitNum); + return count; +} + +/** Read a single bit from a 16-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to read from + * @param bitNum Bit position to read (0-15) + * @param data Container for single bit value + * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) + * @return Status of read operation (true = success) + */ +int8_t I2Cdev::readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout) { + uint16_t b; + uint8_t count = readWord(devAddr, regAddr, &b, timeout); + *data = b & (1 << bitNum); + return count; +} + +/** Read multiple bits from an 8-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to read from + * @param bitStart First bit position to read (0-7) + * @param length Number of bits to read (not more than 8) + * @param data Container for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05) + * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) + * @return Status of read operation (true = success) + */ +int8_t I2Cdev::readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout) { + // 01101001 read byte + // 76543210 bit numbers + // xxx args: bitStart=4, length=3 + // 010 masked + // -> 010 shifted + uint8_t count, b; + if ((count = readByte(devAddr, regAddr, &b, timeout)) != 0) { + uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1); + b &= mask; + b >>= (bitStart - length + 1); + *data = b; + } + return count; +} + +/** Read multiple bits from a 16-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to read from + * @param bitStart First bit position to read (0-15) + * @param length Number of bits to read (not more than 16) + * @param data Container for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05) + * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) + * @return Status of read operation (1 = success, 0 = failure, -1 = timeout) + */ +int8_t I2Cdev::readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout) { + // 1101011001101001 read byte + // fedcba9876543210 bit numbers + // xxx args: bitStart=12, length=3 + // 010 masked + // -> 010 shifted + uint8_t count; + uint16_t w; + if ((count = readWord(devAddr, regAddr, &w, timeout)) != 0) { + uint16_t mask = ((1 << length) - 1) << (bitStart - length + 1); + w &= mask; + w >>= (bitStart - length + 1); + *data = w; + } + return count; +} +/** Read single byte from an 8-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to read from + * @param data Container for byte value read from device + * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) + * @return Status of read operation (true = success) + */ +int8_t I2Cdev::readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout) { + return readBytes(devAddr, regAddr, 1, data, timeout); +} + +/** Read single word from a 16-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to read from + * @param data Container for word value read from device + * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) + * @return Status of read operation (true = success) + */ +int8_t I2Cdev::readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout) { + return readWords(devAddr, regAddr, 1, data, timeout); +} + +/** Read multiple bytes from an 8-bit device register. + * @param devAddr I2C slave device address + * @param regAddr First register regAddr to read from + * @param length Number of bytes to read + * @param data Buffer to store read data in + * @param timeout Optional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout) + * @return Number of bytes read (-1 indicates failure) + */ +int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout) +{ + char command[1]; + command[0] = regAddr; + char *redData = (char*)malloc(length); + i2c.write(devAddr<<1, command, 1, true); + i2c.read(devAddr<<1, redData, length); + for(int i =0; i < length; i++) { + data[i] = redData[i]; + } + free (redData); + return length; +} + +int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout) +{ + return 0; +} + +/** write a single bit in an 8-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to write to + * @param bitNum Bit position to write (0-7) + * @param value New bit value to write + * @return Status of operation (true = success) + */ +bool I2Cdev::writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data) { + uint8_t b; + readByte(devAddr, regAddr, &b); + b = (data != 0) ? (b | (1 << bitNum)) : (b & ~(1 << bitNum)); + return writeByte(devAddr, regAddr, b); +} + +/** write a single bit in a 16-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to write to + * @param bitNum Bit position to write (0-15) + * @param value New bit value to write + * @return Status of operation (true = success) + */ +bool I2Cdev::writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data) { + uint16_t w; + readWord(devAddr, regAddr, &w); + w = (data != 0) ? (w | (1 << bitNum)) : (w & ~(1 << bitNum)); + return writeWord(devAddr, regAddr, w); +} + +/** Write multiple bits in an 8-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to write to + * @param bitStart First bit position to write (0-7) + * @param length Number of bits to write (not more than 8) + * @param data Right-aligned value to write + * @return Status of operation (true = success) + */ +bool I2Cdev::writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data) { + // 010 value to write + // 76543210 bit numbers + // xxx args: bitStart=4, length=3 + // 00011100 mask byte + // 10101111 original value (sample) + // 10100011 original & ~mask + // 10101011 masked | value + uint8_t b; + if (readByte(devAddr, regAddr, &b) != 0) { + uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1); + data <<= (bitStart - length + 1); // shift data into correct position + data &= mask; // zero all non-important bits in data + b &= ~(mask); // zero all important bits in existing byte + b |= data; // combine data with existing byte + return writeByte(devAddr, regAddr, b); + } else { + return false; + } +} + +/** Write multiple bits in a 16-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register regAddr to write to + * @param bitStart First bit position to write (0-15) + * @param length Number of bits to write (not more than 16) + * @param data Right-aligned value to write + * @return Status of operation (true = success) + */ +bool I2Cdev::writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data) { + // 010 value to write + // fedcba9876543210 bit numbers + // xxx args: bitStart=12, length=3 + // 0001110000000000 mask byte + // 1010111110010110 original value (sample) + // 1010001110010110 original & ~mask + // 1010101110010110 masked | value + uint16_t w; + if (readWord(devAddr, regAddr, &w) != 0) { + uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1); + data <<= (bitStart - length + 1); // shift data into correct position + data &= mask; // zero all non-important bits in data + w &= ~(mask); // zero all important bits in existing word + w |= data; // combine data with existing word + return writeWord(devAddr, regAddr, w); + } else { + return false; + } +} + +/** Write single byte to an 8-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register address to write to + * @param data New byte value to write + * @return Status of operation (true = success) + */ +bool I2Cdev::writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data) { + return writeBytes(devAddr, regAddr, 1, &data); +} + +/** Write single word to a 16-bit device register. + * @param devAddr I2C slave device address + * @param regAddr Register address to write to + * @param data New word value to write + * @return Status of operation (true = success) + */ +bool I2Cdev::writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data) { + return writeWords(devAddr, regAddr, 1, &data); +} + +bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data) +{ + i2c.start(); + i2c.write(devAddr<<1); + i2c.write(regAddr); + for(int i = 0; i < length; i++) { + i2c.write(data[i]); + } + i2c.stop(); + return true; +} + +bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data) +{ + return true; +} + +uint16_t I2Cdev::readTimeout(void) +{ + return 0; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/I2Cdev/I2Cdev.h Sun Jan 31 09:12:19 2016 +0000 @@ -0,0 +1,44 @@ +//ported from arduino library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 +//written by szymon gaertig (email: szymon@gaertig.com.pl) +// modified by shundo kishi +// +// Changelog: +// 2013-01-08 - first release +// 2016-01-31 - changed all functions and variables static to make porting from arduino easier(by shundo kishi) + +#ifndef I2Cdev_h +#define I2Cdev_h + +#include "mbed.h" + +#define I2C_SDA p28 +#define I2C_SCL p27 + +class I2Cdev { + private: + static I2C i2c; + public: + I2Cdev(); + + static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); + static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); + static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); + static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); + static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); + static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); + static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); + static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); + + static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data); + static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data); + static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data); + static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data); + static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data); + static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data); + static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data); + static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data); + + static uint16_t readTimeout(void); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE.md Sun Jan 31 09:12:19 2016 +0000 @@ -0,0 +1,23 @@ +/* ============================================ +I2Cdev device library code is placed under the MIT license +Copyright (c) 2012 Jeff Rowberg + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +=============================================== +*/ \ No newline at end of file
--- a/MPU6050.cpp Sat Jan 30 17:12:45 2016 +0000 +++ b/MPU6050.cpp Sun Jan 31 09:12:19 2016 +0000 @@ -1,39 +1,3 @@ -// I2Cdev library collection - MPU6050 I2C device class -// Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00) -// 8/24/2011 by Jeff Rowberg <jeff@rowberg.net> -// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib -// -// Changelog: -// ... - ongoing debug release - -// NOTE: THIS IS ONLY A PARIAL RELEASE. THIS DEVICE CLASS IS CURRENTLY UNDERGOING ACTIVE -// DEVELOPMENT AND IS STILL MISSING SOME IMPORTANT FEATURES. PLEASE KEEP THIS IN MIND IF -// YOU DECIDE TO USE THIS PARTICULAR CODE FOR ANYTHING. - -/* ============================================ -I2Cdev device library code is placed under the MIT license -Copyright (c) 2012 Jeff Rowberg - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -=============================================== -*/ - #include "MPU6050.h" /** Default constructor, uses default I2C address. @@ -84,7 +48,7 @@ * @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); + I2Cdev::readBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, buffer); return buffer[0]; } /** Set the auxiliary I2C supply voltage level. @@ -94,7 +58,7 @@ * @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); + I2Cdev::writeBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, level); } // SMPLRT_DIV register @@ -121,7 +85,7 @@ * @see MPU6050_RA_SMPLRT_DIV */ uint8_t MPU6050::getRate() { - i2cdev.readByte(devAddr, MPU6050_RA_SMPLRT_DIV, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_SMPLRT_DIV, buffer); return buffer[0]; } /** Set gyroscope sample rate divider. @@ -130,7 +94,7 @@ * @see MPU6050_RA_SMPLRT_DIV */ void MPU6050::setRate(uint8_t rate) { - i2cdev.writeByte(devAddr, MPU6050_RA_SMPLRT_DIV, rate); + I2Cdev::writeByte(devAddr, MPU6050_RA_SMPLRT_DIV, rate); } // CONFIG register @@ -163,7 +127,7 @@ * @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); + 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. @@ -172,7 +136,7 @@ * @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); + 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 @@ -203,7 +167,7 @@ * @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); + 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. @@ -215,7 +179,7 @@ * @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); + I2Cdev::writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, mode); } // GYRO_CONFIG register @@ -238,7 +202,7 @@ * @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); + 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. @@ -250,7 +214,65 @@ * @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); + I2Cdev::writeBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, range); +} + +// SELF TEST FACTORY TRIM VALUES + +/** Get self-test factory trim value for accelerometer X axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_X + */ +uint8_t MPU6050::getAccelXSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_X, &buffer[0]); + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_A, &buffer[1]); + return (buffer[0]>>3) | ((buffer[1]>>4) & 0x03); +} + +/** Get self-test factory trim value for accelerometer Y axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_Y + */ +uint8_t MPU6050::getAccelYSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_Y, &buffer[0]); + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_A, &buffer[1]); + return (buffer[0]>>3) | ((buffer[1]>>2) & 0x03); +} + +/** Get self-test factory trim value for accelerometer Z axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_Z + */ +uint8_t MPU6050::getAccelZSelfTestFactoryTrim() { + I2Cdev::readBytes(devAddr, MPU6050_RA_SELF_TEST_Z, 2, buffer); + return (buffer[0]>>3) | (buffer[1] & 0x03); +} + +/** Get self-test factory trim value for gyro X axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_X + */ +uint8_t MPU6050::getGyroXSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_X, buffer); + return (buffer[0] & 0x1F); +} + +/** Get self-test factory trim value for gyro Y axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_Y + */ +uint8_t MPU6050::getGyroYSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_Y, buffer); + return (buffer[0] & 0x1F); +} + +/** Get self-test factory trim value for gyro Z axis. + * @return factory trim value + * @see MPU6050_RA_SELF_TEST_Z + */ +uint8_t MPU6050::getGyroZSelfTestFactoryTrim() { + I2Cdev::readByte(devAddr, MPU6050_RA_SELF_TEST_Z, buffer); + return (buffer[0] & 0x1F); } // ACCEL_CONFIG register @@ -260,7 +282,7 @@ * @see MPU6050_RA_ACCEL_CONFIG */ bool MPU6050::getAccelXSelfTest() { - i2cdev.readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, buffer); + 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. @@ -268,14 +290,14 @@ * @see MPU6050_RA_ACCEL_CONFIG */ void MPU6050::setAccelXSelfTest(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, 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); + 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. @@ -283,14 +305,14 @@ * @see MPU6050_RA_ACCEL_CONFIG */ void MPU6050::setAccelYSelfTest(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, 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); + 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. @@ -298,7 +320,7 @@ * @see MPU6050_RA_ACCEL_CONFIG */ void MPU6050::setAccelZSelfTest(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, 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 @@ -318,7 +340,7 @@ * @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); + 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. @@ -326,7 +348,7 @@ * @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); + 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 @@ -364,7 +386,7 @@ * @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); + 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. @@ -374,7 +396,7 @@ * @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); + I2Cdev::writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, bandwidth); } // FF_THR register @@ -395,7 +417,7 @@ * @see MPU6050_RA_FF_THR */ uint8_t MPU6050::getFreefallDetectionThreshold() { - i2cdev.readByte(devAddr, MPU6050_RA_FF_THR, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_FF_THR, buffer); return buffer[0]; } /** Get free-fall event acceleration threshold. @@ -404,7 +426,7 @@ * @see MPU6050_RA_FF_THR */ void MPU6050::setFreefallDetectionThreshold(uint8_t threshold) { - i2cdev.writeByte(devAddr, MPU6050_RA_FF_THR, threshold); + I2Cdev::writeByte(devAddr, MPU6050_RA_FF_THR, threshold); } // FF_DUR register @@ -427,7 +449,7 @@ * @see MPU6050_RA_FF_DUR */ uint8_t MPU6050::getFreefallDetectionDuration() { - i2cdev.readByte(devAddr, MPU6050_RA_FF_DUR, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_FF_DUR, buffer); return buffer[0]; } /** Get free-fall event duration threshold. @@ -436,7 +458,7 @@ * @see MPU6050_RA_FF_DUR */ void MPU6050::setFreefallDetectionDuration(uint8_t duration) { - i2cdev.writeByte(devAddr, MPU6050_RA_FF_DUR, duration); + I2Cdev::writeByte(devAddr, MPU6050_RA_FF_DUR, duration); } // MOT_THR register @@ -461,16 +483,16 @@ * @see MPU6050_RA_MOT_THR */ uint8_t MPU6050::getMotionDetectionThreshold() { - i2cdev.readByte(devAddr, MPU6050_RA_MOT_THR, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_MOT_THR, buffer); return buffer[0]; } -/** Set free-fall event acceleration threshold. +/** Set motion detection event acceleration threshold. * @param threshold New motion detection acceleration threshold value (LSB = 2mg) * @see getMotionDetectionThreshold() * @see MPU6050_RA_MOT_THR */ void MPU6050::setMotionDetectionThreshold(uint8_t threshold) { - i2cdev.writeByte(devAddr, MPU6050_RA_MOT_THR, threshold); + I2Cdev::writeByte(devAddr, MPU6050_RA_MOT_THR, threshold); } // MOT_DUR register @@ -491,7 +513,7 @@ * @see MPU6050_RA_MOT_DUR */ uint8_t MPU6050::getMotionDetectionDuration() { - i2cdev.readByte(devAddr, MPU6050_RA_MOT_DUR, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_MOT_DUR, buffer); return buffer[0]; } /** Set motion detection event duration threshold. @@ -500,7 +522,7 @@ * @see MPU6050_RA_MOT_DUR */ void MPU6050::setMotionDetectionDuration(uint8_t duration) { - i2cdev.writeByte(devAddr, MPU6050_RA_MOT_DUR, duration); + I2Cdev::writeByte(devAddr, MPU6050_RA_MOT_DUR, duration); } // ZRMOT_THR register @@ -531,7 +553,7 @@ * @see MPU6050_RA_ZRMOT_THR */ uint8_t MPU6050::getZeroMotionDetectionThreshold() { - i2cdev.readByte(devAddr, MPU6050_RA_ZRMOT_THR, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_ZRMOT_THR, buffer); return buffer[0]; } /** Set zero motion detection event acceleration threshold. @@ -540,7 +562,7 @@ * @see MPU6050_RA_ZRMOT_THR */ void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold) { - i2cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_THR, threshold); + I2Cdev::writeByte(devAddr, MPU6050_RA_ZRMOT_THR, threshold); } // ZRMOT_DUR register @@ -562,7 +584,7 @@ * @see MPU6050_RA_ZRMOT_DUR */ uint8_t MPU6050::getZeroMotionDetectionDuration() { - i2cdev.readByte(devAddr, MPU6050_RA_ZRMOT_DUR, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_ZRMOT_DUR, buffer); return buffer[0]; } /** Set zero motion detection event duration threshold. @@ -571,7 +593,7 @@ * @see MPU6050_RA_ZRMOT_DUR */ void MPU6050::setZeroMotionDetectionDuration(uint8_t duration) { - i2cdev.writeByte(devAddr, MPU6050_RA_ZRMOT_DUR, duration); + I2Cdev::writeByte(devAddr, MPU6050_RA_ZRMOT_DUR, duration); } // FIFO_EN register @@ -583,7 +605,7 @@ * @see MPU6050_RA_FIFO_EN */ bool MPU6050::getTempFIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set temperature FIFO enabled value. @@ -592,7 +614,7 @@ * @see MPU6050_RA_FIFO_EN */ void MPU6050::setTempFIFOEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, 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 @@ -601,7 +623,7 @@ * @see MPU6050_RA_FIFO_EN */ bool MPU6050::getXGyroFIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set gyroscope X-axis FIFO enabled value. @@ -610,7 +632,7 @@ * @see MPU6050_RA_FIFO_EN */ void MPU6050::setXGyroFIFOEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, 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 @@ -619,7 +641,7 @@ * @see MPU6050_RA_FIFO_EN */ bool MPU6050::getYGyroFIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set gyroscope Y-axis FIFO enabled value. @@ -628,7 +650,7 @@ * @see MPU6050_RA_FIFO_EN */ void MPU6050::setYGyroFIFOEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, 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 @@ -637,7 +659,7 @@ * @see MPU6050_RA_FIFO_EN */ bool MPU6050::getZGyroFIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set gyroscope Z-axis FIFO enabled value. @@ -646,7 +668,7 @@ * @see MPU6050_RA_FIFO_EN */ void MPU6050::setZGyroFIFOEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, 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, @@ -656,7 +678,7 @@ * @see MPU6050_RA_FIFO_EN */ bool MPU6050::getAccelFIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set accelerometer FIFO enabled value. @@ -665,7 +687,7 @@ * @see MPU6050_RA_FIFO_EN */ void MPU6050::setAccelFIFOEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, 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) @@ -674,7 +696,7 @@ * @see MPU6050_RA_FIFO_EN */ bool MPU6050::getSlave2FIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 2 FIFO enabled value. @@ -683,7 +705,7 @@ * @see MPU6050_RA_FIFO_EN */ void MPU6050::setSlave2FIFOEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, 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) @@ -692,7 +714,7 @@ * @see MPU6050_RA_FIFO_EN */ bool MPU6050::getSlave1FIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 1 FIFO enabled value. @@ -701,7 +723,7 @@ * @see MPU6050_RA_FIFO_EN */ void MPU6050::setSlave1FIFOEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, 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) @@ -710,7 +732,7 @@ * @see MPU6050_RA_FIFO_EN */ bool MPU6050::getSlave0FIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 0 FIFO enabled value. @@ -719,7 +741,7 @@ * @see MPU6050_RA_FIFO_EN */ void MPU6050::setSlave0FIFOEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, enabled); + I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, enabled); } // I2C_MST_CTRL register @@ -740,7 +762,7 @@ * @see MPU6050_RA_I2C_MST_CTRL */ bool MPU6050::getMultiMasterEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, buffer); return buffer[0]; } /** Set multi-master enabled value. @@ -749,7 +771,7 @@ * @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); + 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 @@ -763,7 +785,7 @@ * @see MPU6050_RA_I2C_MST_CTRL */ bool MPU6050::getWaitForExternalSensorEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, buffer); + 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. @@ -772,7 +794,7 @@ * @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); + 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) @@ -781,7 +803,7 @@ * @see MPU6050_RA_MST_CTRL */ bool MPU6050::getSlave3FIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set Slave 3 FIFO enabled value. @@ -790,7 +812,7 @@ * @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); + 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 @@ -803,7 +825,7 @@ * @see MPU6050_RA_I2C_MST_CTRL */ bool MPU6050::getSlaveReadWriteTransitionEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, buffer); + 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. @@ -812,7 +834,7 @@ * @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); + 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 @@ -844,7 +866,7 @@ * @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); + 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. @@ -852,7 +874,7 @@ * @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); + 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) @@ -862,7 +884,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). @@ -900,7 +922,7 @@ */ 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). @@ -911,7 +933,7 @@ */ 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 @@ -926,7 +948,7 @@ */ 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). @@ -937,7 +959,7 @@ */ 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 @@ -948,7 +970,7 @@ */ 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). @@ -959,7 +981,7 @@ */ 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, @@ -974,7 +996,7 @@ */ 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). @@ -985,7 +1007,7 @@ */ 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 @@ -999,7 +1021,7 @@ */ 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). @@ -1010,7 +1032,7 @@ */ 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. @@ -1025,7 +1047,7 @@ */ 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). @@ -1036,7 +1058,7 @@ */ 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 @@ -1047,7 +1069,7 @@ */ 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). @@ -1058,7 +1080,7 @@ */ 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) @@ -1073,7 +1095,7 @@ * @see MPU6050_RA_I2C_SLV4_ADDR */ uint8_t MPU6050::getSlave4Address() { - i2cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, buffer); return buffer[0]; } /** Set the I2C address of Slave 4. @@ -1082,7 +1104,7 @@ * @see MPU6050_RA_I2C_SLV4_ADDR */ void MPU6050::setSlave4Address(uint8_t address) { - i2cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, 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 @@ -1092,7 +1114,7 @@ * @see MPU6050_RA_I2C_SLV4_REG */ uint8_t MPU6050::getSlave4Register() { - i2cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_REG, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_REG, buffer); return buffer[0]; } /** Set the active internal register for Slave 4. @@ -1101,7 +1123,7 @@ * @see MPU6050_RA_I2C_SLV4_REG */ void MPU6050::setSlave4Register(uint8_t reg) { - i2cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_REG, 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 @@ -1110,7 +1132,7 @@ * @see MPU6050_RA_I2C_SLV4_DO */ void MPU6050::setSlave4OutputByte(uint8_t data) { - i2cdev.writeByte(devAddr, MPU6050_RA_I2C_SLV4_DO, 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 @@ -1119,7 +1141,7 @@ * @see MPU6050_RA_I2C_SLV4_CTRL */ bool MPU6050::getSlave4Enabled() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, buffer); return buffer[0]; } /** Set the enabled value for Slave 4. @@ -1128,7 +1150,7 @@ * @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); + 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 @@ -1140,7 +1162,7 @@ * @see MPU6050_RA_I2C_SLV4_CTRL */ bool MPU6050::getSlave4InterruptEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, buffer); + 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. @@ -1149,7 +1171,7 @@ * @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); + 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 @@ -1161,7 +1183,7 @@ * @see MPU6050_RA_I2C_SLV4_CTRL */ bool MPU6050::getSlave4WriteMode() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, buffer); + 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. @@ -1170,7 +1192,7 @@ * @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); + 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 @@ -1188,7 +1210,7 @@ * @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); + 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. @@ -1197,7 +1219,7 @@ * @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); + 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 @@ -1206,7 +1228,7 @@ * @see MPU6050_RA_I2C_SLV4_DI */ uint8_t MPU6050::getSlate4InputByte() { - i2cdev.readByte(devAddr, MPU6050_RA_I2C_SLV4_DI, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_DI, buffer); return buffer[0]; } @@ -1222,7 +1244,7 @@ * @see MPU6050_RA_I2C_MST_STATUS */ bool MPU6050::getPassthroughStatus() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_PASS_THROUGH_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_PASS_THROUGH_BIT, buffer); return buffer[0]; } /** Get Slave 4 transaction done status. @@ -1234,7 +1256,7 @@ * @see MPU6050_RA_I2C_MST_STATUS */ bool MPU6050::getSlave4IsDone() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_DONE_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_DONE_BIT, buffer); return buffer[0]; } /** Get master arbitration lost status. @@ -1245,7 +1267,7 @@ * @see MPU6050_RA_I2C_MST_STATUS */ bool MPU6050::getLostArbitration() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_LOST_ARB_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_LOST_ARB_BIT, buffer); return buffer[0]; } /** Get Slave 4 NACK status. @@ -1256,7 +1278,7 @@ * @see MPU6050_RA_I2C_MST_STATUS */ bool MPU6050::getSlave4Nack() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_NACK_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_NACK_BIT, buffer); return buffer[0]; } /** Get Slave 3 NACK status. @@ -1267,7 +1289,7 @@ * @see MPU6050_RA_I2C_MST_STATUS */ bool MPU6050::getSlave3Nack() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV3_NACK_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV3_NACK_BIT, buffer); return buffer[0]; } /** Get Slave 2 NACK status. @@ -1278,7 +1300,7 @@ * @see MPU6050_RA_I2C_MST_STATUS */ bool MPU6050::getSlave2Nack() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV2_NACK_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV2_NACK_BIT, buffer); return buffer[0]; } /** Get Slave 1 NACK status. @@ -1289,7 +1311,7 @@ * @see MPU6050_RA_I2C_MST_STATUS */ bool MPU6050::getSlave1Nack() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV1_NACK_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV1_NACK_BIT, buffer); return buffer[0]; } /** Get Slave 0 NACK status. @@ -1300,7 +1322,7 @@ * @see MPU6050_RA_I2C_MST_STATUS */ bool MPU6050::getSlave0Nack() { - i2cdev.readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV0_NACK_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV0_NACK_BIT, buffer); return buffer[0]; } @@ -1313,7 +1335,7 @@ * @see MPU6050_INTCFG_INT_LEVEL_BIT */ bool MPU6050::getInterruptMode() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, buffer); return buffer[0]; } /** Set interrupt logic level mode. @@ -1323,7 +1345,7 @@ * @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); + 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. @@ -1332,7 +1354,7 @@ * @see MPU6050_INTCFG_INT_OPEN_BIT */ bool MPU6050::getInterruptDrive() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, buffer); return buffer[0]; } /** Set interrupt drive mode. @@ -1342,7 +1364,7 @@ * @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); + 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. @@ -1351,7 +1373,7 @@ * @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); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, buffer); return buffer[0]; } /** Set interrupt latch mode. @@ -1361,7 +1383,7 @@ * @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); + 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. @@ -1370,7 +1392,7 @@ * @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); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, buffer); return buffer[0]; } /** Set interrupt latch clear mode. @@ -1380,7 +1402,7 @@ * @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); + 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) @@ -1389,7 +1411,7 @@ * @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); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, buffer); return buffer[0]; } /** Set FSYNC interrupt logic level mode. @@ -1399,7 +1421,7 @@ * @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); + 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. @@ -1408,7 +1430,7 @@ * @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); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, buffer); return buffer[0]; } /** Set FSYNC pin interrupt enabled setting. @@ -1418,7 +1440,7 @@ * @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); + 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 @@ -1432,7 +1454,7 @@ * @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); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, buffer); return buffer[0]; } /** Set I2C bypass enabled status. @@ -1447,7 +1469,7 @@ * @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); + 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 @@ -1459,7 +1481,7 @@ * @see MPU6050_INTCFG_CLKOUT_EN_BIT */ bool MPU6050::getClockOutputEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, buffer); return buffer[0]; } /** Set reference clock output enabled status. @@ -1472,7 +1494,7 @@ * @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); + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, enabled); } // INT_ENABLE register @@ -1485,7 +1507,7 @@ * @see MPU6050_INTERRUPT_FF_BIT **/ uint8_t MPU6050::getIntEnabled() { - i2cdev.readByte(devAddr, MPU6050_RA_INT_ENABLE, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_INT_ENABLE, buffer); return buffer[0]; } /** Set full interrupt enabled status. @@ -1497,7 +1519,7 @@ * @see MPU6050_INTERRUPT_FF_BIT **/ void MPU6050::setIntEnabled(uint8_t enabled) { - i2cdev.writeByte(devAddr, MPU6050_RA_INT_ENABLE, enabled); + I2Cdev::writeByte(devAddr, MPU6050_RA_INT_ENABLE, enabled); } /** Get Free Fall interrupt enabled status. * Will be set 0 for disabled, 1 for enabled. @@ -1506,7 +1528,7 @@ * @see MPU6050_INTERRUPT_FF_BIT **/ bool MPU6050::getIntFreefallEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, buffer); return buffer[0]; } /** Set Free Fall interrupt enabled status. @@ -1516,7 +1538,7 @@ * @see MPU6050_INTERRUPT_FF_BIT **/ void MPU6050::setIntFreefallEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, 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. @@ -1525,7 +1547,7 @@ * @see MPU6050_INTERRUPT_MOT_BIT **/ bool MPU6050::getIntMotionEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, buffer); return buffer[0]; } /** Set Motion Detection interrupt enabled status. @@ -1535,7 +1557,7 @@ * @see MPU6050_INTERRUPT_MOT_BIT **/ void MPU6050::setIntMotionEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, 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. @@ -1544,7 +1566,7 @@ * @see MPU6050_INTERRUPT_ZMOT_BIT **/ bool MPU6050::getIntZeroMotionEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, buffer); return buffer[0]; } /** Set Zero Motion Detection interrupt enabled status. @@ -1554,7 +1576,7 @@ * @see MPU6050_INTERRUPT_ZMOT_BIT **/ void MPU6050::setIntZeroMotionEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, 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. @@ -1563,7 +1585,7 @@ * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT **/ bool MPU6050::getIntFIFOBufferOverflowEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer); return buffer[0]; } /** Set FIFO Buffer Overflow interrupt enabled status. @@ -1573,7 +1595,7 @@ * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT **/ void MPU6050::setIntFIFOBufferOverflowEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, 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 @@ -1583,7 +1605,7 @@ * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT **/ bool MPU6050::getIntI2CMasterEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer); return buffer[0]; } /** Set I2C Master interrupt enabled status. @@ -1593,7 +1615,7 @@ * @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); + 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 @@ -1603,7 +1625,7 @@ * @see MPU6050_INTERRUPT_DATA_RDY_BIT */ bool MPU6050::getIntDataReadyEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer); return buffer[0]; } /** Set Data Ready interrupt enabled status. @@ -1613,7 +1635,7 @@ * @see MPU6050_INTERRUPT_DATA_RDY_BIT */ void MPU6050::setIntDataReadyEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, enabled); + I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, enabled); } // INT_STATUS register @@ -1626,7 +1648,7 @@ * @see MPU6050_RA_INT_STATUS */ uint8_t MPU6050::getIntStatus() { - i2cdev.readByte(devAddr, MPU6050_RA_INT_STATUS, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_INT_STATUS, buffer); return buffer[0]; } /** Get Free Fall interrupt status. @@ -1637,7 +1659,7 @@ * @see MPU6050_INTERRUPT_FF_BIT */ bool MPU6050::getIntFreefallStatus() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FF_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FF_BIT, buffer); return buffer[0]; } /** Get Motion Detection interrupt status. @@ -1648,7 +1670,7 @@ * @see MPU6050_INTERRUPT_MOT_BIT */ bool MPU6050::getIntMotionStatus() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_MOT_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_MOT_BIT, buffer); return buffer[0]; } /** Get Zero Motion Detection interrupt status. @@ -1659,7 +1681,7 @@ * @see MPU6050_INTERRUPT_ZMOT_BIT */ bool MPU6050::getIntZeroMotionStatus() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_ZMOT_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_ZMOT_BIT, buffer); return buffer[0]; } /** Get FIFO Buffer Overflow interrupt status. @@ -1670,7 +1692,7 @@ * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT */ bool MPU6050::getIntFIFOBufferOverflowStatus() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer); return buffer[0]; } /** Get I2C Master interrupt status. @@ -1682,7 +1704,7 @@ * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT */ bool MPU6050::getIntI2CMasterStatus() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer); return buffer[0]; } /** Get Data Ready interrupt status. @@ -1693,7 +1715,7 @@ * @see MPU6050_INTERRUPT_DATA_RDY_BIT */ bool MPU6050::getIntDataReadyStatus() { - i2cdev.readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer); return buffer[0]; } @@ -1732,7 +1754,7 @@ * @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); + 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]; @@ -1777,7 +1799,7 @@ * @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); + 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]; @@ -1788,7 +1810,7 @@ * @see MPU6050_RA_ACCEL_XOUT_H */ int16_t MPU6050::getAccelerationX() { - i2cdev.readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } /** Get Y-axis accelerometer reading. @@ -1797,7 +1819,7 @@ * @see MPU6050_RA_ACCEL_YOUT_H */ int16_t MPU6050::getAccelerationY() { - i2cdev.readBytes(devAddr, MPU6050_RA_ACCEL_YOUT_H, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_YOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } /** Get Z-axis accelerometer reading. @@ -1806,7 +1828,7 @@ * @see MPU6050_RA_ACCEL_ZOUT_H */ int16_t MPU6050::getAccelerationZ() { - i2cdev.readBytes(devAddr, MPU6050_RA_ACCEL_ZOUT_H, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_ZOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } @@ -1817,7 +1839,7 @@ * @see MPU6050_RA_TEMP_OUT_H */ int16_t MPU6050::getTemperature() { - i2cdev.readBytes(devAddr, MPU6050_RA_TEMP_OUT_H, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_TEMP_OUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } @@ -1856,7 +1878,7 @@ * @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); + 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]; @@ -1867,7 +1889,7 @@ * @see MPU6050_RA_GYRO_XOUT_H */ int16_t MPU6050::getRotationX() { - i2cdev.readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } /** Get Y-axis gyroscope reading. @@ -1876,7 +1898,7 @@ * @see MPU6050_RA_GYRO_YOUT_H */ int16_t MPU6050::getRotationY() { - i2cdev.readBytes(devAddr, MPU6050_RA_GYRO_YOUT_H, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_YOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } /** Get Z-axis gyroscope reading. @@ -1885,7 +1907,7 @@ * @see MPU6050_RA_GYRO_ZOUT_H */ int16_t MPU6050::getRotationZ() { - i2cdev.readBytes(devAddr, MPU6050_RA_GYRO_ZOUT_H, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_ZOUT_H, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } @@ -1966,7 +1988,7 @@ * @return Byte read from register */ uint8_t MPU6050::getExternalSensorByte(int position) { - i2cdev.readByte(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, buffer); return buffer[0]; } /** Read word (2 bytes) from external sensor data registers. @@ -1975,7 +1997,7 @@ * @see getExternalSensorByte() */ uint16_t MPU6050::getExternalSensorWord(int position) { - i2cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 2, buffer); + 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. @@ -1984,7 +2006,7 @@ * @see getExternalSensorByte() */ uint32_t MPU6050::getExternalSensorDWord(int position) { - i2cdev.readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 4, buffer); + 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]; } @@ -1995,7 +2017,7 @@ * @see MPU6050_RA_MOT_DETECT_STATUS */ uint8_t MPU6050::getMotionStatus() { - i2cdev.readByte(devAddr, MPU6050_RA_MOT_DETECT_STATUS, buffer); + I2Cdev::readByte(devAddr, MPU6050_RA_MOT_DETECT_STATUS, buffer); return buffer[0]; } /** Get X-axis negative motion detection interrupt status. @@ -2004,7 +2026,7 @@ * @see MPU6050_MOTION_MOT_XNEG_BIT */ bool MPU6050::getXNegMotionDetected() { - i2cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XNEG_BIT, buffer); + 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. @@ -2013,7 +2035,7 @@ * @see MPU6050_MOTION_MOT_XPOS_BIT */ bool MPU6050::getXPosMotionDetected() { - i2cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XPOS_BIT, buffer); + 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. @@ -2022,7 +2044,7 @@ * @see MPU6050_MOTION_MOT_YNEG_BIT */ bool MPU6050::getYNegMotionDetected() { - i2cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YNEG_BIT, buffer); + 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. @@ -2031,7 +2053,7 @@ * @see MPU6050_MOTION_MOT_YPOS_BIT */ bool MPU6050::getYPosMotionDetected() { - i2cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YPOS_BIT, buffer); + 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. @@ -2040,7 +2062,7 @@ * @see MPU6050_MOTION_MOT_ZNEG_BIT */ bool MPU6050::getZNegMotionDetected() { - i2cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZNEG_BIT, buffer); + 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. @@ -2049,7 +2071,7 @@ * @see MPU6050_MOTION_MOT_ZPOS_BIT */ bool MPU6050::getZPosMotionDetected() { - i2cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZPOS_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZPOS_BIT, buffer); return buffer[0]; } /** Get zero motion detection interrupt status. @@ -2058,7 +2080,7 @@ * @see MPU6050_MOTION_MOT_ZRMOT_BIT */ bool MPU6050::getZeroMotionDetected() { - i2cdev.readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZRMOT_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZRMOT_BIT, buffer); return buffer[0]; } @@ -2074,7 +2096,7 @@ */ 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 @@ -2088,7 +2110,7 @@ * @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); + 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. @@ -2098,7 +2120,7 @@ * @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); + 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 @@ -2121,7 +2143,7 @@ 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. @@ -2131,7 +2153,7 @@ * @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); + I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, enabled); } // SIGNAL_PATH_RESET register @@ -2143,7 +2165,7 @@ * @see MPU6050_PATHRESET_GYRO_RESET_BIT */ void MPU6050::resetGyroscopePath() { - i2cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_GYRO_RESET_BIT, true); + 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 @@ -2152,7 +2174,7 @@ * @see MPU6050_PATHRESET_ACCEL_RESET_BIT */ void MPU6050::resetAccelerometerPath() { - i2cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_ACCEL_RESET_BIT, true); + 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 @@ -2161,7 +2183,7 @@ * @see MPU6050_PATHRESET_TEMP_RESET_BIT */ void MPU6050::resetTemperaturePath() { - i2cdev.writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_TEMP_RESET_BIT, true); + I2Cdev::writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_TEMP_RESET_BIT, true); } // MOT_DETECT_CTRL register @@ -2181,7 +2203,7 @@ * @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); + 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. @@ -2191,7 +2213,7 @@ * @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); + 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 @@ -2220,7 +2242,7 @@ * @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); + 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. @@ -2230,7 +2252,7 @@ * @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); + 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 @@ -2256,7 +2278,7 @@ * */ uint8_t MPU6050::getMotionDetectionCounterDecrement() { - i2cdev.readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, buffer); + 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. @@ -2266,7 +2288,7 @@ * @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); + I2Cdev::writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, decrement); } // USER_CTRL register @@ -2280,7 +2302,7 @@ * @see MPU6050_USERCTRL_FIFO_EN_BIT */ bool MPU6050::getFIFOEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, buffer); return buffer[0]; } /** Set FIFO enabled status. @@ -2290,7 +2312,7 @@ * @see MPU6050_USERCTRL_FIFO_EN_BIT */ void MPU6050::setFIFOEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, 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 @@ -2304,7 +2326,7 @@ * @see MPU6050_USERCTRL_I2C_MST_EN_BIT */ bool MPU6050::getI2CMasterModeEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, buffer); return buffer[0]; } /** Set I2C Master Mode enabled status. @@ -2314,14 +2336,14 @@ * @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); + 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); + 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 @@ -2330,7 +2352,7 @@ * @see MPU6050_USERCTRL_FIFO_RESET_BIT */ void MPU6050::resetFIFO() { - i2cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_RESET_BIT, true); + 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. @@ -2339,7 +2361,7 @@ * @see MPU6050_USERCTRL_I2C_MST_RESET_BIT */ void MPU6050::resetI2CMaster() { - i2cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_RESET_BIT, true); + 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, @@ -2354,7 +2376,7 @@ * @see MPU6050_USERCTRL_SIG_COND_RESET_BIT */ void MPU6050::resetSensors() { - i2cdev.writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_SIG_COND_RESET_BIT, true); + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_SIG_COND_RESET_BIT, true); } // PWR_MGMT_1 register @@ -2365,7 +2387,7 @@ * @see MPU6050_PWR1_DEVICE_RESET_BIT */ void MPU6050::reset() { - i2cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_DEVICE_RESET_BIT, true); + 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 @@ -2379,7 +2401,7 @@ * @see MPU6050_PWR1_SLEEP_BIT */ bool MPU6050::getSleepEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, buffer); return buffer[0]; } /** Set sleep mode status. @@ -2389,7 +2411,7 @@ * @see MPU6050_PWR1_SLEEP_BIT */ void MPU6050::setSleepEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, 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 @@ -2400,7 +2422,7 @@ * @see MPU6050_PWR1_CYCLE_BIT */ bool MPU6050::getWakeCycleEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, buffer); return buffer[0]; } /** Set wake cycle enabled status. @@ -2410,7 +2432,7 @@ * @see MPU6050_PWR1_CYCLE_BIT */ void MPU6050::setWakeCycleEnabled(bool enabled) { - i2cdev.writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, 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. @@ -2424,7 +2446,7 @@ * @see MPU6050_PWR1_TEMP_DIS_BIT */ bool MPU6050::getTempSensorEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, buffer); + 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. @@ -2439,7 +2461,7 @@ */ 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 @@ -2448,7 +2470,7 @@ * @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); + I2Cdev::readBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, buffer); return buffer[0]; } /** Set clock source setting. @@ -2482,7 +2504,7 @@ * @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); + I2Cdev::writeBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, source); } // PWR_MGMT_2 register @@ -2502,7 +2524,7 @@ * 1 | 2.5 Hz * 2 | 5 Hz * 3 | 10 Hz - * <pre> + * </pre> * * For further information regarding the MPU-60X0's power modes, please refer to * Register 107. @@ -2511,7 +2533,7 @@ * @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); + 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. @@ -2519,7 +2541,7 @@ * @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); + 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. @@ -2529,7 +2551,7 @@ * @see MPU6050_PWR2_STBY_XA_BIT */ bool MPU6050::getStandbyXAccelEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, buffer); return buffer[0]; } /** Set X-axis accelerometer standby enabled status. @@ -2539,7 +2561,7 @@ * @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); + 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). @@ -2548,7 +2570,7 @@ * @see MPU6050_PWR2_STBY_YA_BIT */ bool MPU6050::getStandbyYAccelEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, buffer); return buffer[0]; } /** Set Y-axis accelerometer standby enabled status. @@ -2558,7 +2580,7 @@ * @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); + 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). @@ -2567,7 +2589,7 @@ * @see MPU6050_PWR2_STBY_ZA_BIT */ bool MPU6050::getStandbyZAccelEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, buffer); return buffer[0]; } /** Set Z-axis accelerometer standby enabled status. @@ -2577,7 +2599,7 @@ * @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); + 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). @@ -2586,7 +2608,7 @@ * @see MPU6050_PWR2_STBY_XG_BIT */ bool MPU6050::getStandbyXGyroEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, buffer); return buffer[0]; } /** Set X-axis gyroscope standby enabled status. @@ -2596,7 +2618,7 @@ * @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); + 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). @@ -2605,7 +2627,7 @@ * @see MPU6050_PWR2_STBY_YG_BIT */ bool MPU6050::getStandbyYGyroEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, buffer); return buffer[0]; } /** Set Y-axis gyroscope standby enabled status. @@ -2615,7 +2637,7 @@ * @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); + 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). @@ -2624,7 +2646,7 @@ * @see MPU6050_PWR2_STBY_ZG_BIT */ bool MPU6050::getStandbyZGyroEnabled() { - i2cdev.readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, buffer); + I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, buffer); return buffer[0]; } /** Set Z-axis gyroscope standby enabled status. @@ -2634,7 +2656,7 @@ * @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); + I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, enabled); } // FIFO_COUNT* registers @@ -2647,7 +2669,7 @@ * @return Current FIFO buffer size */ uint16_t MPU6050::getFIFOCount() { - i2cdev.readBytes(devAddr, MPU6050_RA_FIFO_COUNTH, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_FIFO_COUNTH, 2, buffer); return (((uint16_t)buffer[0]) << 8) | buffer[1]; } @@ -2679,18 +2701,22 @@ * @return Byte from FIFO buffer */ uint8_t MPU6050::getFIFOByte() { - i2cdev.readByte(devAddr, MPU6050_RA_FIFO_R_W, buffer); + 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); + if(length > 0){ + I2Cdev::readBytes(devAddr, MPU6050_RA_FIFO_R_W, length, data); + } else { + *data = 0; + } } /** Write byte to FIFO buffer. * @see getFIFOByte() * @see MPU6050_RA_FIFO_R_W */ void MPU6050::setFIFOByte(uint8_t data) { - i2cdev.writeByte(devAddr, MPU6050_RA_FIFO_R_W, data); + I2Cdev::writeByte(devAddr, MPU6050_RA_FIFO_R_W, data); } // WHO_AM_I register @@ -2703,7 +2729,7 @@ * @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); + 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. @@ -2716,7 +2742,7 @@ * @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); + I2Cdev::writeBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, id); } // ======== UNDOCUMENTED/DMP REGISTERS/METHODS ======== @@ -2724,196 +2750,196 @@ // XG_OFFS_TC register uint8_t MPU6050::getOTPBankValid() { - i2cdev.readBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, buffer); + 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); + I2Cdev::writeBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, enabled); } int8_t MPU6050::getXGyroOffsetTC() { - i2cdev.readBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); + I2Cdev::readBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); return buffer[0]; } void MPU6050::setXGyroOffsetTC(int8_t offset) { - i2cdev.writeBits(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, 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::getYGyroOffsetTC() { - i2cdev.readBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); + I2Cdev::readBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); return buffer[0]; } void MPU6050::setYGyroOffsetTC(int8_t offset) { - i2cdev.writeBits(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, 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::getZGyroOffsetTC() { - i2cdev.readBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); + I2Cdev::readBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, buffer); return buffer[0]; } void MPU6050::setZGyroOffsetTC(int8_t offset) { - i2cdev.writeBits(devAddr, MPU6050_RA_ZG_OFFS_TC, MPU6050_TC_OFFSET_BIT, MPU6050_TC_OFFSET_LENGTH, 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + I2Cdev::writeWord(devAddr, MPU6050_RA_ZA_OFFS_H, offset); } // XG_OFFS_USR* registers int16_t MPU6050::getXGyroOffset() { - i2cdev.readBytes(devAddr, MPU6050_RA_XG_OFFS_USRH, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_XG_OFFS_USRH, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } void MPU6050::setXGyroOffset(int16_t offset) { - i2cdev.writeWord(devAddr, MPU6050_RA_XG_OFFS_USRH, offset); + I2Cdev::writeWord(devAddr, MPU6050_RA_XG_OFFS_USRH, offset); } // YG_OFFS_USR* register int16_t MPU6050::getYGyroOffset() { - i2cdev.readBytes(devAddr, MPU6050_RA_YG_OFFS_USRH, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_YG_OFFS_USRH, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } void MPU6050::setYGyroOffset(int16_t offset) { - i2cdev.writeWord(devAddr, MPU6050_RA_YG_OFFS_USRH, offset); + I2Cdev::writeWord(devAddr, MPU6050_RA_YG_OFFS_USRH, offset); } // ZG_OFFS_USR* register int16_t MPU6050::getZGyroOffset() { - i2cdev.readBytes(devAddr, MPU6050_RA_ZG_OFFS_USRH, 2, buffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_ZG_OFFS_USRH, 2, buffer); return (((int16_t)buffer[0]) << 8) | buffer[1]; } void MPU6050::setZGyroOffset(int16_t offset) { - i2cdev.writeWord(devAddr, MPU6050_RA_ZG_OFFS_USRH, 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_RESET_BIT, true); } // BANK_SEL register @@ -2922,23 +2948,23 @@ 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); + 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); + 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); + I2Cdev::writeByte(devAddr, MPU6050_RA_MEM_R_W, data); } void MPU6050::readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address) { setMemoryBank(bank); @@ -2955,8 +2981,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; @@ -2976,7 +3002,7 @@ setMemoryStartAddress(address); uint8_t chunkSize; uint8_t *verifyBuffer; - uint8_t *progBuffer; + uint8_t *progBuffer=0; uint16_t i; uint8_t j; if (verify) verifyBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE); @@ -2990,7 +3016,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); @@ -2999,13 +3025,13 @@ progBuffer = (uint8_t *)data + i; } - i2cdev.writeBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, progBuffer); + I2Cdev::writeBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, progBuffer); // verify data if needed if (verify && verifyBuffer) { setMemoryBank(bank); setMemoryStartAddress(address); - i2cdev.readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, verifyBuffer); + I2Cdev::readBytes(devAddr, MPU6050_RA_MEM_R_W, chunkSize, verifyBuffer); if (memcmp(progBuffer, verifyBuffer, chunkSize) != 0) { /*Serial.print("Block write verification error, bank "); Serial.print(bank, DEC); @@ -3051,7 +3077,8 @@ return writeMemoryBlock(data, dataSize, bank, address, verify, true); } bool MPU6050::writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize, bool useProgMem) { - uint8_t *progBuffer, success, special; + uint8_t *progBuffer = 0; + uint8_t success, special; uint16_t i, j; if (useProgMem) { progBuffer = (uint8_t *)malloc(8); // assume 8-byte blocks, realloc later if necessary @@ -3104,11 +3131,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 { @@ -3116,7 +3143,7 @@ success = false; } } - + if (!success) { if (useProgMem) free(progBuffer); return false; // uh oh @@ -3132,19 +3159,19 @@ // DMP_CFG_1 register uint8_t MPU6050::getDMPConfig1() { - i2cdev.readByte(devAddr, MPU6050_RA_DMP_CFG_1, buffer); + 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); + 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); + 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); -} + I2Cdev::writeByte(devAddr, MPU6050_RA_DMP_CFG_2, config); +} \ No newline at end of file
--- a/MPU6050.h Sat Jan 30 17:12:45 2016 +0000 +++ b/MPU6050.h Sun Jan 31 09:12:19 2016 +0000 @@ -1,39 +1,3 @@ -// 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) -// 10/3/2011 by Jeff Rowberg <jeff@rowberg.net> -// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib -// -// Changelog: -// ... - ongoing debug release - -// NOTE: THIS IS ONLY A PARIAL RELEASE. THIS DEVICE CLASS IS CURRENTLY UNDERGOING ACTIVE -// DEVELOPMENT AND IS STILL MISSING SOME IMPORTANT FEATURES. PLEASE KEEP THIS IN MIND IF -// YOU DECIDE TO USE THIS PARTICULAR CODE FOR ANYTHING. - -/* ============================================ -I2Cdev device library code is placed under the MIT license -Copyright (c) 2012 Jeff Rowberg - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -=============================================== -*/ - #ifndef _MPU6050_H_ #define _MPU6050_H_ @@ -41,14 +5,16 @@ // supporting link: http://forum.arduino.cc/index.php?&topic=143444.msg1079517#msg1079517 // also: http://forum.arduino.cc/index.php?&topic=141571.msg1062899#msg1062899s -#ifndef __arm__ + +#ifdef __AVR__ #include <avr/pgmspace.h> #else #define PROGMEM /* empty */ -#define pgm_read_byte(x) (*(x)) -#define pgm_read_word(x) (*(x)) -#define pgm_read_float(x) (*(x)) -#define PSTR(STR) STR +#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) +#define pgm_read_word(addr) (*(const unsigned short *)(addr)) +#define pgm_read_dword(addr) (*(const unsigned long *)(addr)) +#define pgm_read_float(addr) (*(const float *)(addr)) +#define PSTR(str) (str) #endif @@ -68,6 +34,10 @@ #define MPU6050_RA_YA_OFFS_L_TC 0x09 #define MPU6050_RA_ZA_OFFS_H 0x0A //[15:0] ZA_OFFS #define MPU6050_RA_ZA_OFFS_L_TC 0x0B +#define MPU6050_RA_SELF_TEST_X 0x0D //[7:5] XA_TEST[4-2], [4:0] XG_TEST[4-0] +#define MPU6050_RA_SELF_TEST_Y 0x0E //[7:5] YA_TEST[4-2], [4:0] YG_TEST[4-0] +#define MPU6050_RA_SELF_TEST_Z 0x0F //[7:5] ZA_TEST[4-2], [4:0] ZG_TEST[4-0] +#define MPU6050_RA_SELF_TEST_A 0x10 //[5:4] XA_TEST[1-0], [3:2] YA_TEST[1-0], [1:0] ZA_TEST[1-0] #define MPU6050_RA_XG_OFFS_USRH 0x13 //[15:0] XG_OFFS_USR #define MPU6050_RA_XG_OFFS_USRL 0x14 #define MPU6050_RA_YG_OFFS_USRH 0x15 //[15:0] YG_OFFS_USR @@ -167,6 +137,26 @@ #define MPU6050_RA_FIFO_R_W 0x74 #define MPU6050_RA_WHO_AM_I 0x75 +#define MPU6050_SELF_TEST_XA_1_BIT 0x07 +#define MPU6050_SELF_TEST_XA_1_LENGTH 0x03 +#define MPU6050_SELF_TEST_XA_2_BIT 0x05 +#define MPU6050_SELF_TEST_XA_2_LENGTH 0x02 +#define MPU6050_SELF_TEST_YA_1_BIT 0x07 +#define MPU6050_SELF_TEST_YA_1_LENGTH 0x03 +#define MPU6050_SELF_TEST_YA_2_BIT 0x03 +#define MPU6050_SELF_TEST_YA_2_LENGTH 0x02 +#define MPU6050_SELF_TEST_ZA_1_BIT 0x07 +#define MPU6050_SELF_TEST_ZA_1_LENGTH 0x03 +#define MPU6050_SELF_TEST_ZA_2_BIT 0x01 +#define MPU6050_SELF_TEST_ZA_2_LENGTH 0x02 + +#define MPU6050_SELF_TEST_XG_1_BIT 0x04 +#define MPU6050_SELF_TEST_XG_1_LENGTH 0x05 +#define MPU6050_SELF_TEST_YG_1_BIT 0x04 +#define MPU6050_SELF_TEST_YG_1_LENGTH 0x05 +#define MPU6050_SELF_TEST_ZG_1_BIT 0x04 +#define MPU6050_SELF_TEST_ZG_1_LENGTH 0x05 + #define MPU6050_TC_PWR_MODE_BIT 7 #define MPU6050_TC_OFFSET_BIT 6 #define MPU6050_TC_OFFSET_LENGTH 6 @@ -409,8 +399,6 @@ // note: DMP code memory blocks defined at end of header file class MPU6050 { - private: - I2Cdev i2cdev; public: MPU6050(); MPU6050(uint8_t address); @@ -436,6 +424,15 @@ uint8_t getFullScaleGyroRange(); void setFullScaleGyroRange(uint8_t range); + // SELF_TEST registers + uint8_t getAccelXSelfTestFactoryTrim(); + uint8_t getAccelYSelfTestFactoryTrim(); + uint8_t getAccelZSelfTestFactoryTrim(); + + uint8_t getGyroXSelfTestFactoryTrim(); + uint8_t getGyroYSelfTestFactoryTrim(); + uint8_t getGyroZSelfTestFactoryTrim(); + // ACCEL_CONFIG register bool getAccelXSelfTest(); void setAccelXSelfTest(bool enabled); @@ -689,9 +686,9 @@ // WHO_AM_I register uint8_t getDeviceID(); void setDeviceID(uint8_t id); - + // ======== UNDOCUMENTED/DMP REGISTERS/METHODS ======== - + // XG_OFFS_TC register uint8_t getOTPBankValid(); void setOTPBankValid(bool enabled); @@ -741,13 +738,13 @@ // ZG_OFFS_USR* register int16_t getZGyroOffset(); void setZGyroOffset(int16_t offset); - + // INT_ENABLE register (DMP functions) bool getIntPLLReadyEnabled(); void setIntPLLReadyEnabled(bool enabled); bool getIntDMPEnabled(); void setIntDMPEnabled(bool enabled); - + // DMP_INT_STATUS bool getDMPInt5Status(); bool getDMPInt4Status(); @@ -759,18 +756,18 @@ // INT_STATUS register (DMP functions) bool getIntPLLReadyStatus(); bool getIntDMPStatus(); - + // USER_CTRL register (DMP functions) bool getDMPEnabled(); void setDMPEnabled(bool enabled); void resetDMP(); - + // BANK_SEL register void setMemoryBank(uint8_t bank, bool prefetchEnabled=false, bool userBank=false); - + // MEM_START_ADDR register void setMemoryStartAddress(uint8_t address); - + // MEM_R_W register uint8_t readMemoryByte(); void writeMemoryByte(uint8_t data); @@ -802,12 +799,12 @@ uint8_t dmpGetSampleStepSizeMS(); uint8_t dmpGetSampleFrequency(); int32_t dmpDecodeTemperature(int8_t tempReg); - + // Register callbacks after a packet of FIFO data is processed //uint8_t dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority); //uint8_t dmpUnregisterFIFORateProcess(inv_obj_func func); uint8_t dmpRunFIFORateProcesses(); - + // Setup FIFO for various output uint8_t dmpSendQuaternion(uint_fast16_t accuracy); uint8_t dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy); @@ -867,7 +864,7 @@ uint8_t dmpGetQuantizedAccel(VectorInt16 *v, const uint8_t* packet=0); uint8_t dmpGetExternalSensorData(int32_t *data, uint16_t size, const uint8_t* packet=0); uint8_t dmpGetEIS(int32_t *data, const uint8_t* packet=0); - + uint8_t dmpGetEuler(float *data, Quaternion *q); uint8_t dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity); @@ -903,12 +900,12 @@ uint8_t dmpGetSampleStepSizeMS(); uint8_t dmpGetSampleFrequency(); int32_t dmpDecodeTemperature(int8_t tempReg); - + // Register callbacks after a packet of FIFO data is processed //uint8_t dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority); //uint8_t dmpUnregisterFIFORateProcess(inv_obj_func func); uint8_t dmpRunFIFORateProcesses(); - + // Setup FIFO for various output uint8_t dmpSendQuaternion(uint_fast16_t accuracy); uint8_t dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy); @@ -969,7 +966,7 @@ uint8_t dmpGetQuantizedAccel(VectorInt16 *v, const uint8_t* packet=0); uint8_t dmpGetExternalSensorData(int32_t *data, uint16_t size, const uint8_t* packet=0); uint8_t dmpGetEIS(int32_t *data, const uint8_t* packet=0); - + uint8_t dmpGetEuler(float *data, Quaternion *q); uint8_t dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity);
--- a/MPU6050_6Axis_MotionApps20.h Sat Jan 30 17:12:45 2016 +0000 +++ b/MPU6050_6Axis_MotionApps20.h Sun Jan 31 09:12:19 2016 +0000 @@ -1,35 +1,3 @@ -// I2Cdev library collection - MPU6050 I2C device class, 6-axis MotionApps 2.0 implementation -// Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00) -// 5/20/2013 by Jeff Rowberg <jeff@rowberg.net> -// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib -// -// Changelog: -// ... - ongoing debug release - -/* ============================================ -I2Cdev device library code is placed under the MIT license -Copyright (c) 2012 Jeff Rowberg - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -=============================================== -*/ - #ifndef _MPU6050_6AXIS_MOTIONAPPS20_H_ #define _MPU6050_6AXIS_MOTIONAPPS20_H_ @@ -43,7 +11,7 @@ // Tom Carpenter's conditional PROGMEM code // http://forum.arduino.cc/index.php?topic=129407.0 -#ifndef __arm__ +#ifdef __AVR__ #include <avr/pgmspace.h> #else // Teensy 3.0 library conditional PROGMEM code from Paul Stoffregen @@ -53,7 +21,7 @@ #define PROGMEM #define PGM_P const char * - // #define PSTR(str) (str) + #define PSTR(str) (str) #define F(x) x typedef void prog_void; @@ -65,16 +33,16 @@ typedef uint16_t prog_uint16_t; typedef int32_t prog_int32_t; typedef uint32_t prog_uint32_t; - + #define strcpy_P(dest, src) strcpy((dest), (src)) #define strcat_P(dest, src) strcat((dest), (src)) #define strcmp_P(a, b) strcmp((a), (b)) - + #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) (*(const unsigned short *)(addr)) #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) #define pgm_read_float(addr) (*(const float *)(addr)) - + #define pgm_read_byte_near(addr) pgm_read_byte(addr) #define pgm_read_word_near(addr) pgm_read_word(addr) #define pgm_read_dword_near(addr) pgm_read_dword(addr) @@ -102,34 +70,12 @@ #define DEBUG #ifdef DEBUG - Serial debug_serial(USBTX, USBRX); - template <typename T> - void inline DEBUG_PRINT(T x) { debug_serial.printf("%d", x); } - void inline DEBUG_PRINT(const char* x) { debug_serial.printf(x); } - - template <typename T> - void inline DEBUG_PRINTLN(T x) { DEBUG_PRINT(x);debug_serial.printf("\r\n"); } - - enum Format { BIN, OCT, DEC, HEX }; - - template <typename T> - void inline DEBUG_PRINTF(T x, Format fmt) { - if(fmt == OCT) { - debug_serial.printf("%o", (x)); - } else if (fmt == DEC) { - debug_serial.printf("%d", (x)); - } else if (fmt == HEX) { - debug_serial.printf("%x", (x)); - } else { - debug_serial.printf("We aren't supporting this format: %d", (x)); - } - } - - template <typename T> - void inline DEBUG_PRINTLNF(T x, Format fmt) { - DEBUG_PRINTF(x, fmt); - debug_serial.printf("\r\n"); - } + #include "ArduinoSerial.h" + ArduinoSerial arduinoSerial; + #define DEBUG_PRINT(x) arduinoSerial.print(x) + #define DEBUG_PRINTF(x, y) arduinoSerial.print(x, y) + #define DEBUG_PRINTLN(x) arduinoSerial.println(x) + #define DEBUG_PRINTLNF(x, y) arduinoSerial.println(x, y) #else #define DEBUG_PRINT(x) #define DEBUG_PRINTF(x, y) @@ -368,17 +314,15 @@ DEBUG_PRINTLN(F("Selecting memory byte 6...")); setMemoryStartAddress(0x06); DEBUG_PRINTLN(F("Checking hardware revision...")); - uint8_t hwRevision = readMemoryByte(); DEBUG_PRINT(F("Revision @ user[16][6] = ")); - DEBUG_PRINTLNF(hwRevision, HEX); + DEBUG_PRINTLNF(readMemoryByte(), HEX); DEBUG_PRINTLN(F("Resetting memory bank selection to 0...")); setMemoryBank(0, false, false); // check OTP bank valid DEBUG_PRINTLN(F("Reading OTP bank valid flag...")); - uint8_t otpValid = getOTPBankValid(); DEBUG_PRINT(F("OTP bank is ")); - DEBUG_PRINTLN(otpValid ? F("valid!") : F("invalid!")); + DEBUG_PRINTLN(getOTPBankValid() ? F("valid!") : F("invalid!")); // get X/Y/Z gyro offsets DEBUG_PRINTLN(F("Reading gyro offset TC values...")); @@ -518,10 +462,9 @@ getFIFOBytes(fifoBuffer, fifoCount); DEBUG_PRINTLN(F("Reading interrupt status...")); - uint8_t mpuIntStatus = getIntStatus(); DEBUG_PRINT(F("Current interrupt status=")); - DEBUG_PRINTLNF(mpuIntStatus, HEX); + DEBUG_PRINTLNF(getIntStatus(), HEX); DEBUG_PRINTLN(F("Reading final memory update 6/7 (function unknown)...")); for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); @@ -537,10 +480,9 @@ getFIFOBytes(fifoBuffer, fifoCount); DEBUG_PRINTLN(F("Reading interrupt status...")); - mpuIntStatus = getIntStatus(); DEBUG_PRINT(F("Current interrupt status=")); - DEBUG_PRINTLNF(mpuIntStatus, HEX); + DEBUG_PRINTLNF(getIntStatus(), HEX); DEBUG_PRINTLN(F("Writing final memory update 7/7 (function unknown)...")); for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); @@ -601,43 +543,43 @@ uint8_t MPU6050::dmpGetAccel(int32_t *data, const uint8_t* packet) { // TODO: accommodate different arrangements of sent data (ONLY default supported now) if (packet == 0) packet = dmpPacketBuffer; - data[0] = ((packet[28] << 24) + (packet[29] << 16) + (packet[30] << 8) + packet[31]); - data[1] = ((packet[32] << 24) + (packet[33] << 16) + (packet[34] << 8) + packet[35]); - data[2] = ((packet[36] << 24) + (packet[37] << 16) + (packet[38] << 8) + packet[39]); + data[0] = (((uint32_t)packet[28] << 24) | ((uint32_t)packet[29] << 16) | ((uint32_t)packet[30] << 8) | packet[31]); + data[1] = (((uint32_t)packet[32] << 24) | ((uint32_t)packet[33] << 16) | ((uint32_t)packet[34] << 8) | packet[35]); + data[2] = (((uint32_t)packet[36] << 24) | ((uint32_t)packet[37] << 16) | ((uint32_t)packet[38] << 8) | packet[39]); return 0; } uint8_t MPU6050::dmpGetAccel(int16_t *data, const uint8_t* packet) { // TODO: accommodate different arrangements of sent data (ONLY default supported now) if (packet == 0) packet = dmpPacketBuffer; - data[0] = (packet[28] << 8) + packet[29]; - data[1] = (packet[32] << 8) + packet[33]; - data[2] = (packet[36] << 8) + packet[37]; + data[0] = (packet[28] << 8) | packet[29]; + data[1] = (packet[32] << 8) | packet[33]; + data[2] = (packet[36] << 8) | packet[37]; return 0; } uint8_t MPU6050::dmpGetAccel(VectorInt16 *v, const uint8_t* packet) { // TODO: accommodate different arrangements of sent data (ONLY default supported now) if (packet == 0) packet = dmpPacketBuffer; - v -> x = (packet[28] << 8) + packet[29]; - v -> y = (packet[32] << 8) + packet[33]; - v -> z = (packet[36] << 8) + packet[37]; + v -> x = (packet[28] << 8) | packet[29]; + v -> y = (packet[32] << 8) | packet[33]; + v -> z = (packet[36] << 8) | packet[37]; return 0; } uint8_t MPU6050::dmpGetQuaternion(int32_t *data, const uint8_t* packet) { // TODO: accommodate different arrangements of sent data (ONLY default supported now) if (packet == 0) packet = dmpPacketBuffer; - data[0] = ((packet[0] << 24) + (packet[1] << 16) + (packet[2] << 8) + packet[3]); - data[1] = ((packet[4] << 24) + (packet[5] << 16) + (packet[6] << 8) + packet[7]); - data[2] = ((packet[8] << 24) + (packet[9] << 16) + (packet[10] << 8) + packet[11]); - data[3] = ((packet[12] << 24) + (packet[13] << 16) + (packet[14] << 8) + packet[15]); + data[0] = (((uint32_t)packet[0] << 24) | ((uint32_t)packet[1] << 16) | ((uint32_t)packet[2] << 8) | packet[3]); + data[1] = (((uint32_t)packet[4] << 24) | ((uint32_t)packet[5] << 16) | ((uint32_t)packet[6] << 8) | packet[7]); + data[2] = (((uint32_t)packet[8] << 24) | ((uint32_t)packet[9] << 16) | ((uint32_t)packet[10] << 8) | packet[11]); + data[3] = (((uint32_t)packet[12] << 24) | ((uint32_t)packet[13] << 16) | ((uint32_t)packet[14] << 8) | packet[15]); return 0; } uint8_t MPU6050::dmpGetQuaternion(int16_t *data, const uint8_t* packet) { // TODO: accommodate different arrangements of sent data (ONLY default supported now) if (packet == 0) packet = dmpPacketBuffer; - data[0] = ((packet[0] << 8) + packet[1]); - data[1] = ((packet[4] << 8) + packet[5]); - data[2] = ((packet[8] << 8) + packet[9]); - data[3] = ((packet[12] << 8) + packet[13]); + data[0] = ((packet[0] << 8) | packet[1]); + data[1] = ((packet[4] << 8) | packet[5]); + data[2] = ((packet[8] << 8) | packet[9]); + data[3] = ((packet[12] << 8) | packet[13]); return 0; } uint8_t MPU6050::dmpGetQuaternion(Quaternion *q, const uint8_t* packet) { @@ -658,25 +600,25 @@ uint8_t MPU6050::dmpGetGyro(int32_t *data, const uint8_t* packet) { // TODO: accommodate different arrangements of sent data (ONLY default supported now) if (packet == 0) packet = dmpPacketBuffer; - data[0] = ((packet[16] << 24) + (packet[17] << 16) + (packet[18] << 8) + packet[19]); - data[1] = ((packet[20] << 24) + (packet[21] << 16) + (packet[22] << 8) + packet[23]); - data[2] = ((packet[24] << 24) + (packet[25] << 16) + (packet[26] << 8) + packet[27]); + data[0] = (((uint32_t)packet[16] << 24) | ((uint32_t)packet[17] << 16) | ((uint32_t)packet[18] << 8) | packet[19]); + data[1] = (((uint32_t)packet[20] << 24) | ((uint32_t)packet[21] << 16) | ((uint32_t)packet[22] << 8) | packet[23]); + data[2] = (((uint32_t)packet[24] << 24) | ((uint32_t)packet[25] << 16) | ((uint32_t)packet[26] << 8) | packet[27]); return 0; } uint8_t MPU6050::dmpGetGyro(int16_t *data, const uint8_t* packet) { // TODO: accommodate different arrangements of sent data (ONLY default supported now) if (packet == 0) packet = dmpPacketBuffer; - data[0] = (packet[16] << 8) + packet[17]; - data[1] = (packet[20] << 8) + packet[21]; - data[2] = (packet[24] << 8) + packet[25]; + data[0] = (packet[16] << 8) | packet[17]; + data[1] = (packet[20] << 8) | packet[21]; + data[2] = (packet[24] << 8) | packet[25]; return 0; } uint8_t MPU6050::dmpGetGyro(VectorInt16 *v, const uint8_t* packet) { // TODO: accommodate different arrangements of sent data (ONLY default supported now) if (packet == 0) packet = dmpPacketBuffer; - v -> x = (packet[16] << 8) + packet[17]; - v -> y = (packet[20] << 8) + packet[21]; - v -> z = (packet[24] << 8) + packet[25]; + v -> x = (packet[16] << 8) | packet[17]; + v -> y = (packet[20] << 8) | packet[21]; + v -> z = (packet[24] << 8) | packet[25]; return 0; } // uint8_t MPU6050::dmpSetLinearAccelFilterCoefficient(float coef); @@ -750,9 +692,9 @@ // process packet if ((status = dmpProcessFIFOPacket(buf)) > 0) return status; - + // increment external process count variable, if supplied - if (processed != 0) *processed++; + if (processed != 0) (*processed)++; } return 0; }
--- a/helper_3dmath.h Sat Jan 30 17:12:45 2016 +0000 +++ b/helper_3dmath.h Sun Jan 31 09:12:19 2016 +0000 @@ -1,34 +1,3 @@ -// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class, 3D math helper -// 6/5/2012 by Jeff Rowberg <jeff@rowberg.net> -// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib -// -// Changelog: -// 2012-06-05 - add 3D math helper file to DMP6 example sketch - -/* ============================================ -I2Cdev device library code is placed under the MIT license -Copyright (c) 2012 Jeff Rowberg - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -=============================================== -*/ - #ifndef _HELPER_3DMATH_H_ #define _HELPER_3DMATH_H_ @@ -38,14 +7,14 @@ float x; float y; float z; - + Quaternion() { w = 1.0f; x = 0.0f; y = 0.0f; z = 0.0f; } - + Quaternion(float nw, float nx, float ny, float nz) { w = nw; x = nx; @@ -69,11 +38,11 @@ Quaternion getConjugate() { return Quaternion(w, -x, -y, -z); } - + float getMagnitude() { - return sqrt(w*w + x*x + y*y + z*z); + return sqrt((float)(w*w + x*x + y*y + z*z)); } - + void normalize() { float m = getMagnitude(); w /= m; @@ -81,7 +50,7 @@ y /= m; z /= m; } - + Quaternion getNormalized() { Quaternion r(w, x, y, z); r.normalize(); @@ -100,7 +69,7 @@ y = 0; z = 0; } - + VectorInt16(int16_t nx, int16_t ny, int16_t nz) { x = nx; y = ny; @@ -117,19 +86,19 @@ y /= m; z /= m; } - + VectorInt16 getNormalized() { VectorInt16 r(x, y, z); r.normalize(); return r; } - + void rotate(Quaternion *q) { // http://www.cprogramming.com/tutorial/3d/quaternions.html // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/transforms/index.htm // http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation // ^ or: http://webcache.googleusercontent.com/search?q=cache:xgJAp3bDNhQJ:content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation&hl=en&gl=us&strip=1 - + // P_out = q * P_in * conj(q) // - P_out is the output vector // - q is the orientation quaternion @@ -167,7 +136,7 @@ y = 0; z = 0; } - + VectorFloat(float nx, float ny, float nz) { x = nx; y = ny; @@ -175,7 +144,7 @@ } float getMagnitude() { - return sqrt(x*x + y*y + z*z); + return sqrt((float)(x*x + y*y + z*z)); } void normalize() { @@ -184,13 +153,13 @@ y /= m; z /= m; } - + VectorFloat getNormalized() { VectorFloat r(x, y, z); r.normalize(); return r; } - + void rotate(Quaternion *q) { Quaternion p(0, x, y, z);