-// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
-//
-// Changelog:
-// 2019-07-08 - Added Auto Calibration routine
-// ... - 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"
-
-/** Specific address constructor.
- * @param address I2C address, uses default I2C address if none is specified
- * @see MPU6050_DEFAULT_ADDRESS
- * @see MPU6050_ADDRESS_AD0_LOW
- * @see MPU6050_ADDRESS_AD0_HIGH
- */
-MPU6050::MPU6050(uint8_t address):devAddr(address) {
-}
-
-/** Power on and prepare for general usage.
- * This will activate the device and take it out of sleep mode (which must be done
- * after start-up). This function also sets both the accelerometer and the gyroscope
- * to their most sensitive settings, namely +/- 2g and +/- 250 degrees/sec, and sets
- * the clock source to use the X Gyro for reference, which is slightly better than
- * the default internal clock source.
- */
-void MPU6050::initialize() {
- setClockSource(MPU6050_CLOCK_PLL_XGYRO);
- setFullScaleGyroRange(MPU6050_GYRO_FS_250);
- setFullScaleAccelRange(MPU6050_ACCEL_FS_2);
- setSleepEnabled(false); // thanks to Jack Elston for pointing this one out!
-}
-
-/** Verify the I2C connection.
- * Make sure the device is connected and responds as expected.
- * @return True if connection is valid, false otherwise
- */
-bool MPU6050::testConnection() {
- return getDeviceID() == 0x34;
-}
-
-// AUX_VDDIO register (InvenSense demo code calls this RA_*G_OFFS_TC)
-
-/** Get the auxiliary I2C supply voltage level.
- * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to
- * 0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to
- * the MPU-6000, which does not have a VLOGIC pin.
- * @return I2C supply voltage level (0=VLOGIC, 1=VDD)
- */
-uint8_t MPU6050::getAuxVDDIOLevel() {
- I2Cdev::readBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, buffer);
- return buffer[0];
-}
-/** Set the auxiliary I2C supply voltage level.
- * When set to 1, the auxiliary I2C bus high logic level is VDD. When cleared to
- * 0, the auxiliary I2C bus high logic level is VLOGIC. This does not apply to
- * the MPU-6000, which does not have a VLOGIC pin.
- * @param level I2C supply voltage level (0=VLOGIC, 1=VDD)
- */
-void MPU6050::setAuxVDDIOLevel(uint8_t level) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_YG_OFFS_TC, MPU6050_TC_PWR_MODE_BIT, level);
-}
-
-// SMPLRT_DIV register
-
-/** Get gyroscope output rate divider.
- * The sensor register output, FIFO output, DMP sampling, Motion detection, Zero
- * Motion detection, and Free Fall detection are all based on the Sample Rate.
- * The Sample Rate is generated by dividing the gyroscope output rate by
- * SMPLRT_DIV:
- *
- * Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV)
- *
- * where Gyroscope Output Rate = 8kHz when the DLPF is disabled (DLPF_CFG = 0 or
- * 7), and 1kHz when the DLPF is enabled (see Register 26).
- *
- * Note: The accelerometer output rate is 1kHz. This means that for a Sample
- * Rate greater than 1kHz, the same accelerometer sample may be output to the
- * FIFO, DMP, and sensor registers more than once.
- *
- * For a diagram of the gyroscope and accelerometer signal paths, see Section 8
- * of the MPU-6000/MPU-6050 Product Specification document.
- *
- * @return Current sample rate
- * @see MPU6050_RA_SMPLRT_DIV
- */
-uint8_t MPU6050::getRate() {
- I2Cdev::readByte(devAddr, MPU6050_RA_SMPLRT_DIV, buffer);
- return buffer[0];
-}
-/** Set gyroscope sample rate divider.
- * @param rate New sample rate divider
- * @see getRate()
- * @see MPU6050_RA_SMPLRT_DIV
- */
-void MPU6050::setRate(uint8_t rate) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_SMPLRT_DIV, rate);
-}
-
-// CONFIG register
-
-/** Get external FSYNC configuration.
- * Configures the external Frame Synchronization (FSYNC) pin sampling. An
- * external signal connected to the FSYNC pin can be sampled by configuring
- * EXT_SYNC_SET. Signal changes to the FSYNC pin are latched so that short
- * strobes may be captured. The latched FSYNC signal will be sampled at the
- * Sampling Rate, as defined in register 25. After sampling, the latch will
- * reset to the current FSYNC signal state.
- *
- * The sampled value will be reported in place of the least significant bit in
- * a sensor data register determined by the value of EXT_SYNC_SET according to
- * the following table.
- *
- *
- * EXT_SYNC_SET | FSYNC Bit Location
- * -------------+-------------------
- * 0 | Input disabled
- * 1 | TEMP_OUT_L[0]
- * 2 | GYRO_XOUT_L[0]
- * 3 | GYRO_YOUT_L[0]
- * 4 | GYRO_ZOUT_L[0]
- * 5 | ACCEL_XOUT_L[0]
- * 6 | ACCEL_YOUT_L[0]
- * 7 | ACCEL_ZOUT_L[0]
- *
- *
- * @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);
- return buffer[0];
-}
-/** Set external FSYNC configuration.
- * @see getExternalFrameSync()
- * @see MPU6050_RA_CONFIG
- * @param sync New FSYNC configuration value
- */
-void MPU6050::setExternalFrameSync(uint8_t sync) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_EXT_SYNC_SET_BIT, MPU6050_CFG_EXT_SYNC_SET_LENGTH, sync);
-}
-/** Get digital low-pass filter configuration.
- * The DLPF_CFG parameter sets the digital low pass filter configuration. It
- * also determines the internal sampling rate used by the device as shown in
- * the table below.
- *
- * Note: The accelerometer output rate is 1kHz. This means that for a Sample
- * Rate greater than 1kHz, the same accelerometer sample may be output to the
- * FIFO, DMP, and sensor registers more than once.
- *
- *
- * | ACCELEROMETER | GYROSCOPE
- * DLPF_CFG | Bandwidth | Delay | Bandwidth | Delay | Sample Rate
- * ---------+-----------+--------+-----------+--------+-------------
- * 0 | 260Hz | 0ms | 256Hz | 0.98ms | 8kHz
- * 1 | 184Hz | 2.0ms | 188Hz | 1.9ms | 1kHz
- * 2 | 94Hz | 3.0ms | 98Hz | 2.8ms | 1kHz
- * 3 | 44Hz | 4.9ms | 42Hz | 4.8ms | 1kHz
- * 4 | 21Hz | 8.5ms | 20Hz | 8.3ms | 1kHz
- * 5 | 10Hz | 13.8ms | 10Hz | 13.4ms | 1kHz
- * 6 | 5Hz | 19.0ms | 5Hz | 18.6ms | 1kHz
- * 7 | -- Reserved -- | -- Reserved -- | Reserved
- *
- *
- * @return DLFP configuration
- * @see MPU6050_RA_CONFIG
- * @see MPU6050_CFG_DLPF_CFG_BIT
- * @see MPU6050_CFG_DLPF_CFG_LENGTH
- */
-uint8_t MPU6050::getDLPFMode() {
- I2Cdev::readBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, buffer);
- return buffer[0];
-}
-/** Set digital low-pass filter configuration.
- * @param mode New DLFP configuration setting
- * @see getDLPFBandwidth()
- * @see MPU6050_DLPF_BW_256
- * @see MPU6050_RA_CONFIG
- * @see MPU6050_CFG_DLPF_CFG_BIT
- * @see MPU6050_CFG_DLPF_CFG_LENGTH
- */
-void MPU6050::setDLPFMode(uint8_t mode) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_CONFIG, MPU6050_CFG_DLPF_CFG_BIT, MPU6050_CFG_DLPF_CFG_LENGTH, mode);
-}
-
-// GYRO_CONFIG register
-
-/** Get full-scale gyroscope range.
- * The FS_SEL parameter allows setting the full-scale range of the gyro sensors,
- * as described in the table below.
- *
- *
- * 0 = +/- 250 degrees/sec
- * 1 = +/- 500 degrees/sec
- * 2 = +/- 1000 degrees/sec
- * 3 = +/- 2000 degrees/sec
- *
- *
- * @return Current full-scale gyroscope range setting
- * @see MPU6050_GYRO_FS_250
- * @see MPU6050_RA_GYRO_CONFIG
- * @see MPU6050_GCONFIG_FS_SEL_BIT
- * @see MPU6050_GCONFIG_FS_SEL_LENGTH
- */
-uint8_t MPU6050::getFullScaleGyroRange() {
- I2Cdev::readBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, buffer);
- return buffer[0];
-}
-/** Set full-scale gyroscope range.
- * @param range New full-scale gyroscope range value
- * @see getFullScaleRange()
- * @see MPU6050_GYRO_FS_250
- * @see MPU6050_RA_GYRO_CONFIG
- * @see MPU6050_GCONFIG_FS_SEL_BIT
- * @see MPU6050_GCONFIG_FS_SEL_LENGTH
- */
-void MPU6050::setFullScaleGyroRange(uint8_t range) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_GYRO_CONFIG, MPU6050_GCONFIG_FS_SEL_BIT, MPU6050_GCONFIG_FS_SEL_LENGTH, range);
-}
-
-// 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
-
-/** Get self-test enabled setting for accelerometer X axis.
- * @return Self-test enabled value
- * @see MPU6050_RA_ACCEL_CONFIG
- */
-bool MPU6050::getAccelXSelfTest() {
- I2Cdev::readBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, buffer);
- return buffer[0];
-}
-/** Get self-test enabled setting for accelerometer X axis.
- * @param enabled Self-test enabled value
- * @see MPU6050_RA_ACCEL_CONFIG
- */
-void MPU6050::setAccelXSelfTest(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_XA_ST_BIT, enabled);
-}
-/** 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);
- return buffer[0];
-}
-/** Get self-test enabled value for accelerometer Y axis.
- * @param enabled Self-test enabled value
- * @see MPU6050_RA_ACCEL_CONFIG
- */
-void MPU6050::setAccelYSelfTest(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_YA_ST_BIT, enabled);
-}
-/** 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);
- return buffer[0];
-}
-/** Set self-test enabled value for accelerometer Z axis.
- * @param enabled Self-test enabled value
- * @see MPU6050_RA_ACCEL_CONFIG
- */
-void MPU6050::setAccelZSelfTest(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ZA_ST_BIT, enabled);
-}
-/** Get full-scale accelerometer range.
- * The FS_SEL parameter allows setting the full-scale range of the accelerometer
- * sensors, as described in the table below.
- *
- *
- * 0 = +/- 2g
- * 1 = +/- 4g
- * 2 = +/- 8g
- * 3 = +/- 16g
- *
- *
- * @return Current full-scale accelerometer range setting
- * @see MPU6050_ACCEL_FS_2
- * @see MPU6050_RA_ACCEL_CONFIG
- * @see MPU6050_ACONFIG_AFS_SEL_BIT
- * @see MPU6050_ACONFIG_AFS_SEL_LENGTH
- */
-uint8_t MPU6050::getFullScaleAccelRange() {
- I2Cdev::readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, buffer);
- return buffer[0];
-}
-/** Set full-scale accelerometer range.
- * @param range New full-scale accelerometer range setting
- * @see getFullScaleAccelRange()
- */
-void MPU6050::setFullScaleAccelRange(uint8_t range) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_AFS_SEL_BIT, MPU6050_ACONFIG_AFS_SEL_LENGTH, range);
-}
-/** Get the high-pass filter configuration.
- * The DHPF is a filter module in the path leading to motion detectors (Free
- * Fall, Motion threshold, and Zero Motion). The high pass filter output is not
- * available to the data registers (see Figure in Section 8 of the MPU-6000/
- * MPU-6050 Product Specification document).
- *
- * The high pass filter has three modes:
- *
- *
- * Reset: The filter output settles to zero within one sample. This
- * effectively disables the high pass filter. This mode may be toggled
- * to quickly settle the filter.
- *
- * On: The high pass filter will pass signals above the cut off frequency.
- *
- * Hold: When triggered, the filter holds the present sample. The filter
- * output will be the difference between the input sample and the held
- * sample.
- *
- *
- *
- * ACCEL_HPF | Filter Mode | Cut-off Frequency
- * ----------+-------------+------------------
- * 0 | Reset | None
- * 1 | On | 5Hz
- * 2 | On | 2.5Hz
- * 3 | On | 1.25Hz
- * 4 | On | 0.63Hz
- * 7 | Hold | None
- *
- *
- * @return Current high-pass filter configuration
- * @see MPU6050_DHPF_RESET
- * @see MPU6050_RA_ACCEL_CONFIG
- */
-uint8_t MPU6050::getDHPFMode() {
- I2Cdev::readBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, buffer);
- return buffer[0];
-}
-/** Set the high-pass filter configuration.
- * @param bandwidth New high-pass filter configuration
- * @see setDHPFMode()
- * @see MPU6050_DHPF_RESET
- * @see MPU6050_RA_ACCEL_CONFIG
- */
-void MPU6050::setDHPFMode(uint8_t bandwidth) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_ACCEL_CONFIG, MPU6050_ACONFIG_ACCEL_HPF_BIT, MPU6050_ACONFIG_ACCEL_HPF_LENGTH, bandwidth);
-}
-
-// FF_THR register
-
-/** Get free-fall event acceleration threshold.
- * This register configures the detection threshold for Free Fall event
- * detection. The unit of FF_THR is 1LSB = 2mg. Free Fall is detected when the
- * absolute value of the accelerometer measurements for the three axes are each
- * less than the detection threshold. This condition increments the Free Fall
- * duration counter (Register 30). The Free Fall interrupt is triggered when the
- * Free Fall duration counter reaches the time specified in FF_DUR.
- *
- * For more details on the Free Fall detection interrupt, see Section 8.2 of the
- * MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and
- * 58 of this document.
- *
- * @return Current free-fall acceleration threshold value (LSB = 2mg)
- * @see MPU6050_RA_FF_THR
- */
-uint8_t MPU6050::getFreefallDetectionThreshold() {
- I2Cdev::readByte(devAddr, MPU6050_RA_FF_THR, buffer);
- return buffer[0];
-}
-/** Get free-fall event acceleration threshold.
- * @param threshold New free-fall acceleration threshold value (LSB = 2mg)
- * @see getFreefallDetectionThreshold()
- * @see MPU6050_RA_FF_THR
- */
-void MPU6050::setFreefallDetectionThreshold(uint8_t threshold) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_FF_THR, threshold);
-}
-
-// FF_DUR register
-
-/** Get free-fall event duration threshold.
- * This register configures the duration counter threshold for Free Fall event
- * detection. The duration counter ticks at 1kHz, therefore FF_DUR has a unit
- * of 1 LSB = 1 ms.
- *
- * The Free Fall duration counter increments while the absolute value of the
- * accelerometer measurements are each less than the detection threshold
- * (Register 29). The Free Fall interrupt is triggered when the Free Fall
- * duration counter reaches the time specified in this register.
- *
- * For more details on the Free Fall detection interrupt, see Section 8.2 of
- * the MPU-6000/MPU-6050 Product Specification document as well as Registers 56
- * and 58 of this document.
- *
- * @return Current free-fall duration threshold value (LSB = 1ms)
- * @see MPU6050_RA_FF_DUR
- */
-uint8_t MPU6050::getFreefallDetectionDuration() {
- I2Cdev::readByte(devAddr, MPU6050_RA_FF_DUR, buffer);
- return buffer[0];
-}
-/** Get free-fall event duration threshold.
- * @param duration New free-fall duration threshold value (LSB = 1ms)
- * @see getFreefallDetectionDuration()
- * @see MPU6050_RA_FF_DUR
- */
-void MPU6050::setFreefallDetectionDuration(uint8_t duration) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_FF_DUR, duration);
-}
-
-// MOT_THR register
-
-/** Get motion detection event acceleration threshold.
- * This register configures the detection threshold for Motion interrupt
- * generation. The unit of MOT_THR is 1LSB = 2mg. Motion is detected when the
- * absolute value of any of the accelerometer measurements exceeds this Motion
- * detection threshold. This condition increments the Motion detection duration
- * counter (Register 32). The Motion detection interrupt is triggered when the
- * Motion Detection counter reaches the time count specified in MOT_DUR
- * (Register 32).
- *
- * The Motion interrupt will indicate the axis and polarity of detected motion
- * in MOT_DETECT_STATUS (Register 97).
- *
- * For more details on the Motion detection interrupt, see Section 8.3 of the
- * MPU-6000/MPU-6050 Product Specification document as well as Registers 56 and
- * 58 of this document.
- *
- * @return Current motion detection acceleration threshold value (LSB = 2mg)
- * @see MPU6050_RA_MOT_THR
- */
-uint8_t MPU6050::getMotionDetectionThreshold() {
- I2Cdev::readByte(devAddr, MPU6050_RA_MOT_THR, buffer);
- return buffer[0];
-}
-/** 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);
-}
-
-// MOT_DUR register
-
-/** Get motion detection event duration threshold.
- * This register configures the duration counter threshold for Motion interrupt
- * generation. The duration counter ticks at 1 kHz, therefore MOT_DUR has a unit
- * of 1LSB = 1ms. The Motion detection duration counter increments when the
- * absolute value of any of the accelerometer measurements exceeds the Motion
- * detection threshold (Register 31). The Motion detection interrupt is
- * triggered when the Motion detection counter reaches the time count specified
- * in this register.
- *
- * For more details on the Motion detection interrupt, see Section 8.3 of the
- * MPU-6000/MPU-6050 Product Specification document.
- *
- * @return Current motion detection duration threshold value (LSB = 1ms)
- * @see MPU6050_RA_MOT_DUR
- */
-uint8_t MPU6050::getMotionDetectionDuration() {
- I2Cdev::readByte(devAddr, MPU6050_RA_MOT_DUR, buffer);
- return buffer[0];
-}
-/** Set motion detection event duration threshold.
- * @param duration New motion detection duration threshold value (LSB = 1ms)
- * @see getMotionDetectionDuration()
- * @see MPU6050_RA_MOT_DUR
- */
-void MPU6050::setMotionDetectionDuration(uint8_t duration) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_MOT_DUR, duration);
-}
-
-// ZRMOT_THR register
-
-/** Get zero motion detection event acceleration threshold.
- * This register configures the detection threshold for Zero Motion interrupt
- * generation. The unit of ZRMOT_THR is 1LSB = 2mg. Zero Motion is detected when
- * the absolute value of the accelerometer measurements for the 3 axes are each
- * less than the detection threshold. This condition increments the Zero Motion
- * duration counter (Register 34). The Zero Motion interrupt is triggered when
- * the Zero Motion duration counter reaches the time count specified in
- * ZRMOT_DUR (Register 34).
- *
- * Unlike Free Fall or Motion detection, Zero Motion detection triggers an
- * interrupt both when Zero Motion is first detected and when Zero Motion is no
- * longer detected.
- *
- * When a zero motion event is detected, a Zero Motion Status will be indicated
- * in the MOT_DETECT_STATUS register (Register 97). When a motion-to-zero-motion
- * condition is detected, the status bit is set to 1. When a zero-motion-to-
- * motion condition is detected, the status bit is set to 0.
- *
- * For more details on the Zero Motion detection interrupt, see Section 8.4 of
- * the MPU-6000/MPU-6050 Product Specification document as well as Registers 56
- * and 58 of this document.
- *
- * @return Current zero motion detection acceleration threshold value (LSB = 2mg)
- * @see MPU6050_RA_ZRMOT_THR
- */
-uint8_t MPU6050::getZeroMotionDetectionThreshold() {
- I2Cdev::readByte(devAddr, MPU6050_RA_ZRMOT_THR, buffer);
- return buffer[0];
-}
-/** Set zero motion detection event acceleration threshold.
- * @param threshold New zero motion detection acceleration threshold value (LSB = 2mg)
- * @see getZeroMotionDetectionThreshold()
- * @see MPU6050_RA_ZRMOT_THR
- */
-void MPU6050::setZeroMotionDetectionThreshold(uint8_t threshold) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_ZRMOT_THR, threshold);
-}
-
-// ZRMOT_DUR register
-
-/** Get zero motion detection event duration threshold.
- * This register configures the duration counter threshold for Zero Motion
- * interrupt generation. The duration counter ticks at 16 Hz, therefore
- * ZRMOT_DUR has a unit of 1 LSB = 64 ms. The Zero Motion duration counter
- * increments while the absolute value of the accelerometer measurements are
- * each less than the detection threshold (Register 33). The Zero Motion
- * interrupt is triggered when the Zero Motion duration counter reaches the time
- * count specified in this register.
- *
- * For more details on the Zero Motion detection interrupt, see Section 8.4 of
- * the MPU-6000/MPU-6050 Product Specification document, as well as Registers 56
- * and 58 of this document.
- *
- * @return Current zero motion detection duration threshold value (LSB = 64ms)
- * @see MPU6050_RA_ZRMOT_DUR
- */
-uint8_t MPU6050::getZeroMotionDetectionDuration() {
- I2Cdev::readByte(devAddr, MPU6050_RA_ZRMOT_DUR, buffer);
- return buffer[0];
-}
-/** Set zero motion detection event duration threshold.
- * @param duration New zero motion detection duration threshold value (LSB = 1ms)
- * @see getZeroMotionDetectionDuration()
- * @see MPU6050_RA_ZRMOT_DUR
- */
-void MPU6050::setZeroMotionDetectionDuration(uint8_t duration) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_ZRMOT_DUR, duration);
-}
-
-// FIFO_EN register
-
-/** Get temperature FIFO enabled value.
- * When set to 1, this bit enables TEMP_OUT_H and TEMP_OUT_L (Registers 65 and
- * 66) to be written into the FIFO buffer.
- * @return Current temperature FIFO enabled value
- * @see MPU6050_RA_FIFO_EN
- */
-bool MPU6050::getTempFIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set temperature FIFO enabled value.
- * @param enabled New temperature FIFO enabled value
- * @see getTempFIFOEnabled()
- * @see MPU6050_RA_FIFO_EN
- */
-void MPU6050::setTempFIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_TEMP_FIFO_EN_BIT, enabled);
-}
-/** Get gyroscope X-axis FIFO enabled value.
- * When set to 1, this bit enables GYRO_XOUT_H and GYRO_XOUT_L (Registers 67 and
- * 68) to be written into the FIFO buffer.
- * @return Current gyroscope X-axis FIFO enabled value
- * @see MPU6050_RA_FIFO_EN
- */
-bool MPU6050::getXGyroFIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set gyroscope X-axis FIFO enabled value.
- * @param enabled New gyroscope X-axis FIFO enabled value
- * @see getXGyroFIFOEnabled()
- * @see MPU6050_RA_FIFO_EN
- */
-void MPU6050::setXGyroFIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_XG_FIFO_EN_BIT, enabled);
-}
-/** Get gyroscope Y-axis FIFO enabled value.
- * When set to 1, this bit enables GYRO_YOUT_H and GYRO_YOUT_L (Registers 69 and
- * 70) to be written into the FIFO buffer.
- * @return Current gyroscope Y-axis FIFO enabled value
- * @see MPU6050_RA_FIFO_EN
- */
-bool MPU6050::getYGyroFIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set gyroscope Y-axis FIFO enabled value.
- * @param enabled New gyroscope Y-axis FIFO enabled value
- * @see getYGyroFIFOEnabled()
- * @see MPU6050_RA_FIFO_EN
- */
-void MPU6050::setYGyroFIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_YG_FIFO_EN_BIT, enabled);
-}
-/** Get gyroscope Z-axis FIFO enabled value.
- * When set to 1, this bit enables GYRO_ZOUT_H and GYRO_ZOUT_L (Registers 71 and
- * 72) to be written into the FIFO buffer.
- * @return Current gyroscope Z-axis FIFO enabled value
- * @see MPU6050_RA_FIFO_EN
- */
-bool MPU6050::getZGyroFIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set gyroscope Z-axis FIFO enabled value.
- * @param enabled New gyroscope Z-axis FIFO enabled value
- * @see getZGyroFIFOEnabled()
- * @see MPU6050_RA_FIFO_EN
- */
-void MPU6050::setZGyroFIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ZG_FIFO_EN_BIT, enabled);
-}
-/** Get accelerometer FIFO enabled value.
- * When set to 1, this bit enables ACCEL_XOUT_H, ACCEL_XOUT_L, ACCEL_YOUT_H,
- * ACCEL_YOUT_L, ACCEL_ZOUT_H, and ACCEL_ZOUT_L (Registers 59 to 64) to be
- * written into the FIFO buffer.
- * @return Current accelerometer FIFO enabled value
- * @see MPU6050_RA_FIFO_EN
- */
-bool MPU6050::getAccelFIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set accelerometer FIFO enabled value.
- * @param enabled New accelerometer FIFO enabled value
- * @see getAccelFIFOEnabled()
- * @see MPU6050_RA_FIFO_EN
- */
-void MPU6050::setAccelFIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_ACCEL_FIFO_EN_BIT, enabled);
-}
-/** Get Slave 2 FIFO enabled value.
- * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
- * associated with Slave 2 to be written into the FIFO buffer.
- * @return Current Slave 2 FIFO enabled value
- * @see MPU6050_RA_FIFO_EN
- */
-bool MPU6050::getSlave2FIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set Slave 2 FIFO enabled value.
- * @param enabled New Slave 2 FIFO enabled value
- * @see getSlave2FIFOEnabled()
- * @see MPU6050_RA_FIFO_EN
- */
-void MPU6050::setSlave2FIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV2_FIFO_EN_BIT, enabled);
-}
-/** Get Slave 1 FIFO enabled value.
- * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
- * associated with Slave 1 to be written into the FIFO buffer.
- * @return Current Slave 1 FIFO enabled value
- * @see MPU6050_RA_FIFO_EN
- */
-bool MPU6050::getSlave1FIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set Slave 1 FIFO enabled value.
- * @param enabled New Slave 1 FIFO enabled value
- * @see getSlave1FIFOEnabled()
- * @see MPU6050_RA_FIFO_EN
- */
-void MPU6050::setSlave1FIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV1_FIFO_EN_BIT, enabled);
-}
-/** Get Slave 0 FIFO enabled value.
- * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
- * associated with Slave 0 to be written into the FIFO buffer.
- * @return Current Slave 0 FIFO enabled value
- * @see MPU6050_RA_FIFO_EN
- */
-bool MPU6050::getSlave0FIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set Slave 0 FIFO enabled value.
- * @param enabled New Slave 0 FIFO enabled value
- * @see getSlave0FIFOEnabled()
- * @see MPU6050_RA_FIFO_EN
- */
-void MPU6050::setSlave0FIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_FIFO_EN, MPU6050_SLV0_FIFO_EN_BIT, enabled);
-}
-
-// I2C_MST_CTRL register
-
-/** Get multi-master enabled value.
- * Multi-master capability allows multiple I2C masters to operate on the same
- * bus. In circuits where multi-master capability is required, set MULT_MST_EN
- * to 1. This will increase current drawn by approximately 30uA.
- *
- * In circuits where multi-master capability is required, the state of the I2C
- * bus must always be monitored by each separate I2C Master. Before an I2C
- * Master can assume arbitration of the bus, it must first confirm that no other
- * I2C Master has arbitration of the bus. When MULT_MST_EN is set to 1, the
- * MPU-60X0's bus arbitration detection logic is turned on, enabling it to
- * detect when the bus is available.
- *
- * @return Current multi-master enabled value
- * @see MPU6050_RA_I2C_MST_CTRL
- */
-bool MPU6050::getMultiMasterEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set multi-master enabled value.
- * @param enabled New multi-master enabled value
- * @see getMultiMasterEnabled()
- * @see MPU6050_RA_I2C_MST_CTRL
- */
-void MPU6050::setMultiMasterEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_MULT_MST_EN_BIT, enabled);
-}
-/** Get wait-for-external-sensor-data enabled value.
- * When the WAIT_FOR_ES bit is set to 1, the Data Ready interrupt will be
- * delayed until External Sensor data from the Slave Devices are loaded into the
- * EXT_SENS_DATA registers. This is used to ensure that both the internal sensor
- * data (i.e. from gyro and accel) and external sensor data have been loaded to
- * their respective data registers (i.e. the data is synced) when the Data Ready
- * interrupt is triggered.
- *
- * @return Current wait-for-external-sensor-data enabled value
- * @see MPU6050_RA_I2C_MST_CTRL
- */
-bool MPU6050::getWaitForExternalSensorEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, buffer);
- return buffer[0];
-}
-/** Set wait-for-external-sensor-data enabled value.
- * @param enabled New wait-for-external-sensor-data enabled value
- * @see getWaitForExternalSensorEnabled()
- * @see MPU6050_RA_I2C_MST_CTRL
- */
-void MPU6050::setWaitForExternalSensorEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_WAIT_FOR_ES_BIT, enabled);
-}
-/** Get Slave 3 FIFO enabled value.
- * When set to 1, this bit enables EXT_SENS_DATA registers (Registers 73 to 96)
- * associated with Slave 3 to be written into the FIFO buffer.
- * @return Current Slave 3 FIFO enabled value
- * @see MPU6050_RA_MST_CTRL
- */
-bool MPU6050::getSlave3FIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set Slave 3 FIFO enabled value.
- * @param enabled New Slave 3 FIFO enabled value
- * @see getSlave3FIFOEnabled()
- * @see MPU6050_RA_MST_CTRL
- */
-void MPU6050::setSlave3FIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_SLV_3_FIFO_EN_BIT, enabled);
-}
-/** Get slave read/write transition enabled value.
- * The I2C_MST_P_NSR bit configures the I2C Master's transition from one slave
- * read to the next slave read. If the bit equals 0, there will be a restart
- * between reads. If the bit equals 1, there will be a stop followed by a start
- * of the following read. When a write transaction follows a read transaction,
- * the stop followed by a start of the successive write will be always used.
- *
- * @return Current slave read/write transition enabled value
- * @see MPU6050_RA_I2C_MST_CTRL
- */
-bool MPU6050::getSlaveReadWriteTransitionEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, buffer);
- return buffer[0];
-}
-/** Set slave read/write transition enabled value.
- * @param enabled New slave read/write transition enabled value
- * @see getSlaveReadWriteTransitionEnabled()
- * @see MPU6050_RA_I2C_MST_CTRL
- */
-void MPU6050::setSlaveReadWriteTransitionEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_P_NSR_BIT, enabled);
-}
-/** Get I2C master clock speed.
- * I2C_MST_CLK is a 4 bit unsigned value which configures a divider on the
- * MPU-60X0 internal 8MHz clock. It sets the I2C master clock speed according to
- * the following table:
- *
- *
- * I2C_MST_CLK | I2C Master Clock Speed | 8MHz Clock Divider
- * ------------+------------------------+-------------------
- * 0 | 348kHz | 23
- * 1 | 333kHz | 24
- * 2 | 320kHz | 25
- * 3 | 308kHz | 26
- * 4 | 296kHz | 27
- * 5 | 286kHz | 28
- * 6 | 276kHz | 29
- * 7 | 267kHz | 30
- * 8 | 258kHz | 31
- * 9 | 500kHz | 16
- * 10 | 471kHz | 17
- * 11 | 444kHz | 18
- * 12 | 421kHz | 19
- * 13 | 400kHz | 20
- * 14 | 381kHz | 21
- * 15 | 364kHz | 22
- *
- *
- * @return Current I2C master clock speed
- * @see MPU6050_RA_I2C_MST_CTRL
- */
-uint8_t MPU6050::getMasterClockSpeed() {
- I2Cdev::readBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, buffer);
- return buffer[0];
-}
-/** Set I2C master clock speed.
- * @reparam speed Current I2C master clock speed
- * @see MPU6050_RA_I2C_MST_CTRL
- */
-void MPU6050::setMasterClockSpeed(uint8_t speed) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_I2C_MST_CTRL, MPU6050_I2C_MST_CLK_BIT, MPU6050_I2C_MST_CLK_LENGTH, speed);
-}
-
-// I2C_SLV* registers (Slave 0-3)
-
-/** Get the I2C address of the specified slave (0-3).
- * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read
- * 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
- * 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).
- *
- * The MPU-6050 supports a total of five slaves, but Slave 4 has unique
- * characteristics, and so it has its own functions (getSlave4* and setSlave4*).
- *
- * I2C data transactions are performed at the Sample Rate, as defined in
- * Register 25. The user is responsible for ensuring that I2C data transactions
- * to and from each enabled Slave can be completed within a single period of the
- * Sample Rate.
- *
- * The I2C slave access rate can be reduced relative to the Sample Rate. This
- * reduced access rate is determined by I2C_MST_DLY (Register 52). Whether a
- * slave's access rate is reduced relative to the Sample Rate is determined by
- * I2C_MST_DELAY_CTRL (Register 103).
- *
- * The processing order for the slaves is fixed. The sequence followed for
- * processing the slaves is Slave 0, Slave 1, Slave 2, Slave 3 and Slave 4. If a
- * particular Slave is disabled it will be skipped.
- *
- * Each slave can either be accessed at the sample rate or at a reduced sample
- * rate. In a case where some slaves are accessed at the Sample Rate and some
- * slaves are accessed at the reduced rate, the sequence of accessing the slaves
- * (Slave 0 to Slave 4) is still followed. However, the reduced rate slaves will
- * be skipped if their access rate dictates that they should not be accessed
- * during that particular cycle. For further information regarding the reduced
- * access rate, please refer to Register 52. Whether a slave is accessed at the
- * Sample Rate or at the reduced rate is determined by the Delay Enable bits in
- * Register 103.
- *
- * @param num Slave number (0-3)
- * @return Current address for specified slave
- * @see MPU6050_RA_I2C_SLV0_ADDR
- */
-uint8_t MPU6050::getSlaveAddress(uint8_t num) {
- if (num > 3) return 0;
- I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV0_ADDR + num*3, buffer);
- return buffer[0];
-}
-/** Set the I2C address of the specified slave (0-3).
- * @param num Slave number (0-3)
- * @param address New address for specified slave
- * @see getSlaveAddress()
- * @see MPU6050_RA_I2C_SLV0_ADDR
- */
-void MPU6050::setSlaveAddress(uint8_t num, uint8_t address) {
- if (num > 3) return;
- 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
- * register address is stored in this MPU register.
- *
- * The MPU-6050 supports a total of five slaves, but Slave 4 has unique
- * characteristics, and so it has its own functions.
- *
- * @param num Slave number (0-3)
- * @return Current active register for specified slave
- * @see MPU6050_RA_I2C_SLV0_REG
- */
-uint8_t MPU6050::getSlaveRegister(uint8_t num) {
- if (num > 3) return 0;
- 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).
- * @param num Slave number (0-3)
- * @param reg New active register for specified slave
- * @see getSlaveRegister()
- * @see MPU6050_RA_I2C_SLV0_REG
- */
-void MPU6050::setSlaveRegister(uint8_t num, uint8_t reg) {
- if (num > 3) return;
- I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV0_REG + num*3, reg);
-}
-/** Get the enabled value for the specified slave (0-3).
- * When set to 1, this bit enables Slave 0 for data transfer operations. When
- * cleared to 0, this bit disables Slave 0 from data transfer operations.
- * @param num Slave number (0-3)
- * @return Current enabled value for specified slave
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-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);
- return buffer[0];
-}
-/** Set the enabled value for the specified slave (0-3).
- * @param num Slave number (0-3)
- * @param enabled New enabled value for specified slave
- * @see getSlaveEnabled()
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-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);
-}
-/** 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,
- * the high and low bytes of a word pair are swapped. Please refer to
- * I2C_SLV0_GRP for the pairing convention of the word pairs. When cleared to 0,
- * bytes transferred to and from Slave 0 will be written to EXT_SENS_DATA
- * registers in the order they were transferred.
- *
- * @param num Slave number (0-3)
- * @return Current word pair byte-swapping enabled value for specified slave
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-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);
- return buffer[0];
-}
-/** Set word pair byte-swapping enabled for the specified slave (0-3).
- * @param num Slave number (0-3)
- * @param enabled New word pair byte-swapping enabled value for specified slave
- * @see getSlaveWordByteSwap()
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-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);
-}
-/** Get write mode for the specified slave (0-3).
- * When set to 1, the transaction will read or write data only. When cleared to
- * 0, the transaction will write a register address prior to reading or writing
- * data. This should equal 0 when specifying the register address within the
- * Slave device to/from which the ensuing data transaction will take place.
- *
- * @param num Slave number (0-3)
- * @return Current write mode for specified slave (0 = register address + data, 1 = data only)
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-bool MPU6050::getSlaveWriteMode(uint8_t num) {
- if (num > 3) return 0;
- 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).
- * @param num Slave number (0-3)
- * @param mode New write mode for specified slave (0 = register address + data, 1 = data only)
- * @see getSlaveWriteMode()
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-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);
-}
-/** Get word pair grouping order offset for the specified slave (0-3).
- * This sets specifies the grouping order of word pairs received from registers.
- * When cleared to 0, bytes from register addresses 0 and 1, 2 and 3, etc (even,
- * then odd register addresses) are paired to form a word. When set to 1, bytes
- * from register addresses are paired 1 and 2, 3 and 4, etc. (odd, then even
- * register addresses) are paired to form a word.
- *
- * @param num Slave number (0-3)
- * @return Current word pair grouping order offset for specified slave
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-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);
- return buffer[0];
-}
-/** Set word pair grouping order offset for the specified slave (0-3).
- * @param num Slave number (0-3)
- * @param enabled New word pair grouping order offset for specified slave
- * @see getSlaveWordGroupOffset()
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-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);
-}
-/** 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
- * bit to 0 is equivalent to disabling the register by writing 0 to I2C_SLV0_EN.
- * @param num Slave number (0-3)
- * @return Number of bytes to read for specified slave
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-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);
- return buffer[0];
-}
-/** Set number of bytes to read for the specified slave (0-3).
- * @param num Slave number (0-3)
- * @param length Number of bytes to read for specified slave
- * @see getSlaveDataLength()
- * @see MPU6050_RA_I2C_SLV0_CTRL
- */
-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);
-}
-
-// I2C_SLV* registers (Slave 4)
-
-/** Get the I2C address of Slave 4.
- * Note that Bit 7 (MSB) controls read/write mode. If Bit 7 is set, it's a read
- * 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.
- *
- * @return Current address for Slave 4
- * @see getSlaveAddress()
- * @see MPU6050_RA_I2C_SLV4_ADDR
- */
-uint8_t MPU6050::getSlave4Address() {
- I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, buffer);
- return buffer[0];
-}
-/** Set the I2C address of Slave 4.
- * @param address New address for Slave 4
- * @see getSlave4Address()
- * @see MPU6050_RA_I2C_SLV4_ADDR
- */
-void MPU6050::setSlave4Address(uint8_t address) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV4_ADDR, address);
-}
-/** Get the active internal register for the Slave 4.
- * Read/write operations for this slave will be done to whatever internal
- * register address is stored in this MPU register.
- *
- * @return Current active register for Slave 4
- * @see MPU6050_RA_I2C_SLV4_REG
- */
-uint8_t MPU6050::getSlave4Register() {
- I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_REG, buffer);
- return buffer[0];
-}
-/** Set the active internal register for Slave 4.
- * @param reg New active register for Slave 4
- * @see getSlave4Register()
- * @see MPU6050_RA_I2C_SLV4_REG
- */
-void MPU6050::setSlave4Register(uint8_t reg) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV4_REG, reg);
-}
-/** Set new byte to write to Slave 4.
- * This register stores the data to be written into the Slave 4. If I2C_SLV4_RW
- * is set 1 (set to read), this register has no effect.
- * @param data New byte to write to Slave 4
- * @see MPU6050_RA_I2C_SLV4_DO
- */
-void MPU6050::setSlave4OutputByte(uint8_t data) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV4_DO, data);
-}
-/** Get the enabled value for the Slave 4.
- * When set to 1, this bit enables Slave 4 for data transfer operations. When
- * cleared to 0, this bit disables Slave 4 from data transfer operations.
- * @return Current enabled value for Slave 4
- * @see MPU6050_RA_I2C_SLV4_CTRL
- */
-bool MPU6050::getSlave4Enabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set the enabled value for Slave 4.
- * @param enabled New enabled value for Slave 4
- * @see getSlave4Enabled()
- * @see MPU6050_RA_I2C_SLV4_CTRL
- */
-void MPU6050::setSlave4Enabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_EN_BIT, enabled);
-}
-/** Get the enabled value for Slave 4 transaction interrupts.
- * When set to 1, this bit enables the generation of an interrupt signal upon
- * completion of a Slave 4 transaction. When cleared to 0, this bit disables the
- * generation of an interrupt signal upon completion of a Slave 4 transaction.
- * The interrupt status can be observed in Register 54.
- *
- * @return Current enabled value for Slave 4 transaction interrupts.
- * @see MPU6050_RA_I2C_SLV4_CTRL
- */
-bool MPU6050::getSlave4InterruptEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set the enabled value for Slave 4 transaction interrupts.
- * @param enabled New enabled value for Slave 4 transaction interrupts.
- * @see getSlave4InterruptEnabled()
- * @see MPU6050_RA_I2C_SLV4_CTRL
- */
-void MPU6050::setSlave4InterruptEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_INT_EN_BIT, enabled);
-}
-/** Get write mode for Slave 4.
- * When set to 1, the transaction will read or write data only. When cleared to
- * 0, the transaction will write a register address prior to reading or writing
- * data. This should equal 0 when specifying the register address within the
- * Slave device to/from which the ensuing data transaction will take place.
- *
- * @return Current write mode for Slave 4 (0 = register address + data, 1 = data only)
- * @see MPU6050_RA_I2C_SLV4_CTRL
- */
-bool MPU6050::getSlave4WriteMode() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, buffer);
- return buffer[0];
-}
-/** Set write mode for the Slave 4.
- * @param mode New write mode for Slave 4 (0 = register address + data, 1 = data only)
- * @see getSlave4WriteMode()
- * @see MPU6050_RA_I2C_SLV4_CTRL
- */
-void MPU6050::setSlave4WriteMode(bool mode) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_REG_DIS_BIT, mode);
-}
-/** Get Slave 4 master delay value.
- * This configures the reduced access rate of I2C slaves relative to the Sample
- * Rate. When a slave's access rate is decreased relative to the Sample Rate,
- * the slave is accessed every:
- *
- * 1 / (1 + I2C_MST_DLY) samples
- *
- * This base Sample Rate in turn is determined by SMPLRT_DIV (register 25) and
- * DLPF_CFG (register 26). Whether a slave's access rate is reduced relative to
- * the Sample Rate is determined by I2C_MST_DELAY_CTRL (register 103). For
- * further information regarding the Sample Rate, please refer to register 25.
- *
- * @return Current Slave 4 master delay value
- * @see MPU6050_RA_I2C_SLV4_CTRL
- */
-uint8_t MPU6050::getSlave4MasterDelay() {
- I2Cdev::readBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, buffer);
- return buffer[0];
-}
-/** Set Slave 4 master delay value.
- * @param delay New Slave 4 master delay value
- * @see getSlave4MasterDelay()
- * @see MPU6050_RA_I2C_SLV4_CTRL
- */
-void MPU6050::setSlave4MasterDelay(uint8_t delay) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_I2C_SLV4_CTRL, MPU6050_I2C_SLV4_MST_DLY_BIT, MPU6050_I2C_SLV4_MST_DLY_LENGTH, delay);
-}
-/** Get last available byte read from Slave 4.
- * This register stores the data read from Slave 4. This field is populated
- * after a read transaction.
- * @return Last available byte read from to Slave 4
- * @see MPU6050_RA_I2C_SLV4_DI
- */
-uint8_t MPU6050::getSlate4InputByte() {
- I2Cdev::readByte(devAddr, MPU6050_RA_I2C_SLV4_DI, buffer);
- return buffer[0];
-}
-
-// I2C_MST_STATUS register
-
-/** Get FSYNC interrupt status.
- * This bit reflects the status of the FSYNC interrupt from an external device
- * into the MPU-60X0. This is used as a way to pass an external interrupt
- * through the MPU-60X0 to the host application processor. When set to 1, this
- * bit will cause an interrupt if FSYNC_INT_EN is asserted in INT_PIN_CFG
- * (Register 55).
- * @return FSYNC interrupt status
- * @see MPU6050_RA_I2C_MST_STATUS
- */
-bool MPU6050::getPassthroughStatus() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_PASS_THROUGH_BIT, buffer);
- return buffer[0];
-}
-/** Get Slave 4 transaction done status.
- * Automatically sets to 1 when a Slave 4 transaction has completed. This
- * triggers an interrupt if the I2C_MST_INT_EN bit in the INT_ENABLE register
- * (Register 56) is asserted and if the SLV_4_DONE_INT bit is asserted in the
- * I2C_SLV4_CTRL register (Register 52).
- * @return Slave 4 transaction done status
- * @see MPU6050_RA_I2C_MST_STATUS
- */
-bool MPU6050::getSlave4IsDone() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_DONE_BIT, buffer);
- return buffer[0];
-}
-/** Get master arbitration lost status.
- * This bit automatically sets to 1 when the I2C Master has lost arbitration of
- * the auxiliary I2C bus (an error condition). This triggers an interrupt if the
- * I2C_MST_INT_EN bit in the INT_ENABLE register (Register 56) is asserted.
- * @return Master arbitration lost status
- * @see MPU6050_RA_I2C_MST_STATUS
- */
-bool MPU6050::getLostArbitration() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_LOST_ARB_BIT, buffer);
- return buffer[0];
-}
-/** Get Slave 4 NACK status.
- * This bit automatically sets to 1 when the I2C Master receives a NACK in a
- * transaction with Slave 4. This triggers an interrupt if the I2C_MST_INT_EN
- * bit in the INT_ENABLE register (Register 56) is asserted.
- * @return Slave 4 NACK interrupt status
- * @see MPU6050_RA_I2C_MST_STATUS
- */
-bool MPU6050::getSlave4Nack() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV4_NACK_BIT, buffer);
- return buffer[0];
-}
-/** Get Slave 3 NACK status.
- * This bit automatically sets to 1 when the I2C Master receives a NACK in a
- * transaction with Slave 3. This triggers an interrupt if the I2C_MST_INT_EN
- * bit in the INT_ENABLE register (Register 56) is asserted.
- * @return Slave 3 NACK interrupt status
- * @see MPU6050_RA_I2C_MST_STATUS
- */
-bool MPU6050::getSlave3Nack() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV3_NACK_BIT, buffer);
- return buffer[0];
-}
-/** Get Slave 2 NACK status.
- * This bit automatically sets to 1 when the I2C Master receives a NACK in a
- * transaction with Slave 2. This triggers an interrupt if the I2C_MST_INT_EN
- * bit in the INT_ENABLE register (Register 56) is asserted.
- * @return Slave 2 NACK interrupt status
- * @see MPU6050_RA_I2C_MST_STATUS
- */
-bool MPU6050::getSlave2Nack() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV2_NACK_BIT, buffer);
- return buffer[0];
-}
-/** Get Slave 1 NACK status.
- * This bit automatically sets to 1 when the I2C Master receives a NACK in a
- * transaction with Slave 1. This triggers an interrupt if the I2C_MST_INT_EN
- * bit in the INT_ENABLE register (Register 56) is asserted.
- * @return Slave 1 NACK interrupt status
- * @see MPU6050_RA_I2C_MST_STATUS
- */
-bool MPU6050::getSlave1Nack() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV1_NACK_BIT, buffer);
- return buffer[0];
-}
-/** Get Slave 0 NACK status.
- * This bit automatically sets to 1 when the I2C Master receives a NACK in a
- * transaction with Slave 0. This triggers an interrupt if the I2C_MST_INT_EN
- * bit in the INT_ENABLE register (Register 56) is asserted.
- * @return Slave 0 NACK interrupt status
- * @see MPU6050_RA_I2C_MST_STATUS
- */
-bool MPU6050::getSlave0Nack() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_STATUS, MPU6050_MST_I2C_SLV0_NACK_BIT, buffer);
- return buffer[0];
-}
-
-// INT_PIN_CFG register
-
-/** Get interrupt logic level mode.
- * Will be set 0 for active-high, 1 for active-low.
- * @return Current interrupt mode (0=active-high, 1=active-low)
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_INT_LEVEL_BIT
- */
-bool MPU6050::getInterruptMode() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, buffer);
- return buffer[0];
-}
-/** Set interrupt logic level mode.
- * @param mode New interrupt mode (0=active-high, 1=active-low)
- * @see getInterruptMode()
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_INT_LEVEL_BIT
- */
-void MPU6050::setInterruptMode(bool mode) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_LEVEL_BIT, mode);
-}
-/** Get interrupt drive mode.
- * Will be set 0 for push-pull, 1 for open-drain.
- * @return Current interrupt drive mode (0=push-pull, 1=open-drain)
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_INT_OPEN_BIT
- */
-bool MPU6050::getInterruptDrive() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, buffer);
- return buffer[0];
-}
-/** Set interrupt drive mode.
- * @param drive New interrupt drive mode (0=push-pull, 1=open-drain)
- * @see getInterruptDrive()
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_INT_OPEN_BIT
- */
-void MPU6050::setInterruptDrive(bool drive) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_OPEN_BIT, drive);
-}
-/** Get interrupt latch mode.
- * Will be set 0 for 50us-pulse, 1 for latch-until-int-cleared.
- * @return Current latch mode (0=50us-pulse, 1=latch-until-int-cleared)
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_LATCH_INT_EN_BIT
- */
-bool MPU6050::getInterruptLatch() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set interrupt latch mode.
- * @param latch New latch mode (0=50us-pulse, 1=latch-until-int-cleared)
- * @see getInterruptLatch()
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_LATCH_INT_EN_BIT
- */
-void MPU6050::setInterruptLatch(bool latch) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_LATCH_INT_EN_BIT, latch);
-}
-/** Get interrupt latch clear mode.
- * Will be set 0 for status-read-only, 1 for any-register-read.
- * @return Current latch clear mode (0=status-read-only, 1=any-register-read)
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT
- */
-bool MPU6050::getInterruptLatchClear() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, buffer);
- return buffer[0];
-}
-/** Set interrupt latch clear mode.
- * @param clear New latch clear mode (0=status-read-only, 1=any-register-read)
- * @see getInterruptLatchClear()
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_INT_RD_CLEAR_BIT
- */
-void MPU6050::setInterruptLatchClear(bool clear) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_INT_RD_CLEAR_BIT, clear);
-}
-/** Get FSYNC interrupt logic level mode.
- * @return Current FSYNC interrupt mode (0=active-high, 1=active-low)
- * @see getFSyncInterruptMode()
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT
- */
-bool MPU6050::getFSyncInterruptLevel() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, buffer);
- return buffer[0];
-}
-/** Set FSYNC interrupt logic level mode.
- * @param mode New FSYNC interrupt mode (0=active-high, 1=active-low)
- * @see getFSyncInterruptMode()
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT
- */
-void MPU6050::setFSyncInterruptLevel(bool level) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT, level);
-}
-/** Get FSYNC pin interrupt enabled setting.
- * Will be set 0 for disabled, 1 for enabled.
- * @return Current interrupt enabled setting
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT
- */
-bool MPU6050::getFSyncInterruptEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set FSYNC pin interrupt enabled setting.
- * @param enabled New FSYNC pin interrupt enabled setting
- * @see getFSyncInterruptEnabled()
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_FSYNC_INT_EN_BIT
- */
-void MPU6050::setFSyncInterruptEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_FSYNC_INT_EN_BIT, enabled);
-}
-/** Get I2C bypass enabled status.
- * When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to
- * 0, the host application processor will be able to directly access the
- * auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host
- * application processor will not be able to directly access the auxiliary I2C
- * bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106
- * bit[5]).
- * @return Current I2C bypass enabled status
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT
- */
-bool MPU6050::getI2CBypassEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set I2C bypass enabled status.
- * When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to
- * 0, the host application processor will be able to directly access the
- * auxiliary I2C bus of the MPU-60X0. When this bit is equal to 0, the host
- * application processor will not be able to directly access the auxiliary I2C
- * bus of the MPU-60X0 regardless of the state of I2C_MST_EN (Register 106
- * bit[5]).
- * @param enabled New I2C bypass enabled status
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_I2C_BYPASS_EN_BIT
- */
-void MPU6050::setI2CBypassEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_I2C_BYPASS_EN_BIT, enabled);
-}
-/** Get reference clock output enabled status.
- * When this bit is equal to 1, a reference clock output is provided at the
- * CLKOUT pin. When this bit is equal to 0, the clock output is disabled. For
- * further information regarding CLKOUT, please refer to the MPU-60X0 Product
- * Specification document.
- * @return Current reference clock output enabled status
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_CLKOUT_EN_BIT
- */
-bool MPU6050::getClockOutputEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set reference clock output enabled status.
- * When this bit is equal to 1, a reference clock output is provided at the
- * CLKOUT pin. When this bit is equal to 0, the clock output is disabled. For
- * further information regarding CLKOUT, please refer to the MPU-60X0 Product
- * Specification document.
- * @param enabled New reference clock output enabled status
- * @see MPU6050_RA_INT_PIN_CFG
- * @see MPU6050_INTCFG_CLKOUT_EN_BIT
- */
-void MPU6050::setClockOutputEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_PIN_CFG, MPU6050_INTCFG_CLKOUT_EN_BIT, enabled);
-}
-
-// INT_ENABLE register
-
-/** Get full interrupt enabled status.
- * Full register byte for all interrupts, for quick reading. Each bit will be
- * set 0 for disabled, 1 for enabled.
- * @return Current interrupt enabled status
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_FF_BIT
- **/
-uint8_t MPU6050::getIntEnabled() {
- I2Cdev::readByte(devAddr, MPU6050_RA_INT_ENABLE, buffer);
- return buffer[0];
-}
-/** Set full interrupt enabled status.
- * Full register byte for all interrupts, for quick reading. Each bit should be
- * set 0 for disabled, 1 for enabled.
- * @param enabled New interrupt enabled status
- * @see getIntFreefallEnabled()
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_FF_BIT
- **/
-void MPU6050::setIntEnabled(uint8_t enabled) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_INT_ENABLE, enabled);
-}
-/** Get Free Fall interrupt enabled status.
- * Will be set 0 for disabled, 1 for enabled.
- * @return Current interrupt enabled status
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_FF_BIT
- **/
-bool MPU6050::getIntFreefallEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, buffer);
- return buffer[0];
-}
-/** Set Free Fall interrupt enabled status.
- * @param enabled New interrupt enabled status
- * @see getIntFreefallEnabled()
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_FF_BIT
- **/
-void MPU6050::setIntFreefallEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FF_BIT, enabled);
-}
-/** Get Motion Detection interrupt enabled status.
- * Will be set 0 for disabled, 1 for enabled.
- * @return Current interrupt enabled status
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_MOT_BIT
- **/
-bool MPU6050::getIntMotionEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, buffer);
- return buffer[0];
-}
-/** Set Motion Detection interrupt enabled status.
- * @param enabled New interrupt enabled status
- * @see getIntMotionEnabled()
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_MOT_BIT
- **/
-void MPU6050::setIntMotionEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_MOT_BIT, enabled);
-}
-/** Get Zero Motion Detection interrupt enabled status.
- * Will be set 0 for disabled, 1 for enabled.
- * @return Current interrupt enabled status
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_ZMOT_BIT
- **/
-bool MPU6050::getIntZeroMotionEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, buffer);
- return buffer[0];
-}
-/** Set Zero Motion Detection interrupt enabled status.
- * @param enabled New interrupt enabled status
- * @see getIntZeroMotionEnabled()
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_ZMOT_BIT
- **/
-void MPU6050::setIntZeroMotionEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_ZMOT_BIT, enabled);
-}
-/** Get FIFO Buffer Overflow interrupt enabled status.
- * Will be set 0 for disabled, 1 for enabled.
- * @return Current interrupt enabled status
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
- **/
-bool MPU6050::getIntFIFOBufferOverflowEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer);
- return buffer[0];
-}
-/** Set FIFO Buffer Overflow interrupt enabled status.
- * @param enabled New interrupt enabled status
- * @see getIntFIFOBufferOverflowEnabled()
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
- **/
-void MPU6050::setIntFIFOBufferOverflowEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, enabled);
-}
-/** Get I2C Master interrupt enabled status.
- * This enables any of the I2C Master interrupt sources to generate an
- * interrupt. Will be set 0 for disabled, 1 for enabled.
- * @return Current interrupt enabled status
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
- **/
-bool MPU6050::getIntI2CMasterEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer);
- return buffer[0];
-}
-/** Set I2C Master interrupt enabled status.
- * @param enabled New interrupt enabled status
- * @see getIntI2CMasterEnabled()
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
- **/
-void MPU6050::setIntI2CMasterEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_I2C_MST_INT_BIT, enabled);
-}
-/** Get Data Ready interrupt enabled setting.
- * This event occurs each time a write operation to all of the sensor registers
- * has been completed. Will be set 0 for disabled, 1 for enabled.
- * @return Current interrupt enabled status
- * @see MPU6050_RA_INT_ENABLE
- * @see MPU6050_INTERRUPT_DATA_RDY_BIT
- */
-bool MPU6050::getIntDataReadyEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer);
- return buffer[0];
-}
-/** Set Data Ready interrupt enabled status.
- * @param enabled New interrupt enabled status
- * @see getIntDataReadyEnabled()
- * @see MPU6050_RA_INT_CFG
- * @see MPU6050_INTERRUPT_DATA_RDY_BIT
- */
-void MPU6050::setIntDataReadyEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DATA_RDY_BIT, enabled);
-}
-
-// INT_STATUS register
-
-/** Get full set of interrupt status bits.
- * These bits clear to 0 after the register has been read. Very useful
- * for getting multiple INT statuses, since each single bit read clears
- * all of them because it has to read the whole byte.
- * @return Current interrupt status
- * @see MPU6050_RA_INT_STATUS
- */
-uint8_t MPU6050::getIntStatus() {
- I2Cdev::readByte(devAddr, MPU6050_RA_INT_STATUS, buffer);
- return buffer[0];
-}
-/** Get Free Fall interrupt status.
- * This bit automatically sets to 1 when a Free Fall interrupt has been
- * generated. The bit clears to 0 after the register has been read.
- * @return Current interrupt status
- * @see MPU6050_RA_INT_STATUS
- * @see MPU6050_INTERRUPT_FF_BIT
- */
-bool MPU6050::getIntFreefallStatus() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FF_BIT, buffer);
- return buffer[0];
-}
-/** Get Motion Detection interrupt status.
- * This bit automatically sets to 1 when a Motion Detection interrupt has been
- * generated. The bit clears to 0 after the register has been read.
- * @return Current interrupt status
- * @see MPU6050_RA_INT_STATUS
- * @see MPU6050_INTERRUPT_MOT_BIT
- */
-bool MPU6050::getIntMotionStatus() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_MOT_BIT, buffer);
- return buffer[0];
-}
-/** Get Zero Motion Detection interrupt status.
- * This bit automatically sets to 1 when a Zero Motion Detection interrupt has
- * been generated. The bit clears to 0 after the register has been read.
- * @return Current interrupt status
- * @see MPU6050_RA_INT_STATUS
- * @see MPU6050_INTERRUPT_ZMOT_BIT
- */
-bool MPU6050::getIntZeroMotionStatus() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_ZMOT_BIT, buffer);
- return buffer[0];
-}
-/** Get FIFO Buffer Overflow interrupt status.
- * This bit automatically sets to 1 when a Free Fall interrupt has been
- * generated. The bit clears to 0 after the register has been read.
- * @return Current interrupt status
- * @see MPU6050_RA_INT_STATUS
- * @see MPU6050_INTERRUPT_FIFO_OFLOW_BIT
- */
-bool MPU6050::getIntFIFOBufferOverflowStatus() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_FIFO_OFLOW_BIT, buffer);
- return buffer[0];
-}
-/** Get I2C Master interrupt status.
- * This bit automatically sets to 1 when an I2C Master interrupt has been
- * generated. For a list of I2C Master interrupts, please refer to Register 54.
- * The bit clears to 0 after the register has been read.
- * @return Current interrupt status
- * @see MPU6050_RA_INT_STATUS
- * @see MPU6050_INTERRUPT_I2C_MST_INT_BIT
- */
-bool MPU6050::getIntI2CMasterStatus() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_I2C_MST_INT_BIT, buffer);
- return buffer[0];
-}
-/** Get Data Ready interrupt status.
- * This bit automatically sets to 1 when a Data Ready interrupt has been
- * generated. The bit clears to 0 after the register has been read.
- * @return Current interrupt status
- * @see MPU6050_RA_INT_STATUS
- * @see MPU6050_INTERRUPT_DATA_RDY_BIT
- */
-bool MPU6050::getIntDataReadyStatus() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DATA_RDY_BIT, buffer);
- return buffer[0];
-}
-
-// ACCEL_*OUT_* registers
-
-/** Get raw 9-axis motion sensor readings (accel/gyro/compass).
- * FUNCTION NOT FULLY IMPLEMENTED YET.
- * @param ax 16-bit signed integer container for accelerometer X-axis value
- * @param ay 16-bit signed integer container for accelerometer Y-axis value
- * @param az 16-bit signed integer container for accelerometer Z-axis value
- * @param gx 16-bit signed integer container for gyroscope X-axis value
- * @param gy 16-bit signed integer container for gyroscope Y-axis value
- * @param gz 16-bit signed integer container for gyroscope Z-axis value
- * @param mx 16-bit signed integer container for magnetometer X-axis value
- * @param my 16-bit signed integer container for magnetometer Y-axis value
- * @param mz 16-bit signed integer container for magnetometer Z-axis value
- * @see getMotion6()
- * @see getAcceleration()
- * @see getRotation()
- * @see MPU6050_RA_ACCEL_XOUT_H
- */
-void MPU6050::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz) {
- getMotion6(ax, ay, az, gx, gy, gz);
- // TODO: magnetometer integration
-}
-/** Get raw 6-axis motion sensor readings (accel/gyro).
- * Retrieves all currently available motion sensor values.
- * @param ax 16-bit signed integer container for accelerometer X-axis value
- * @param ay 16-bit signed integer container for accelerometer Y-axis value
- * @param az 16-bit signed integer container for accelerometer Z-axis value
- * @param gx 16-bit signed integer container for gyroscope X-axis value
- * @param gy 16-bit signed integer container for gyroscope Y-axis value
- * @param gz 16-bit signed integer container for gyroscope Z-axis value
- * @see getAcceleration()
- * @see getRotation()
- * @see MPU6050_RA_ACCEL_XOUT_H
- */
-void MPU6050::getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz) {
- I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 14, buffer);
- *ax = (((int16_t)buffer[0]) << 8) | buffer[1];
- *ay = (((int16_t)buffer[2]) << 8) | buffer[3];
- *az = (((int16_t)buffer[4]) << 8) | buffer[5];
- *gx = (((int16_t)buffer[8]) << 8) | buffer[9];
- *gy = (((int16_t)buffer[10]) << 8) | buffer[11];
- *gz = (((int16_t)buffer[12]) << 8) | buffer[13];
-}
-/** Get 3-axis accelerometer readings.
- * These registers store the most recent accelerometer measurements.
- * Accelerometer measurements are written to these registers at the Sample Rate
- * as defined in Register 25.
- *
- * The accelerometer measurement registers, along with the temperature
- * measurement registers, gyroscope measurement registers, and external sensor
- * data registers, are composed of two sets of registers: an internal register
- * set and a user-facing read register set.
- *
- * The data within the accelerometer sensors' internal register set is always
- * updated at the Sample Rate. Meanwhile, the user-facing read register set
- * duplicates the internal register set's data values whenever the serial
- * interface is idle. This guarantees that a burst read of sensor registers will
- * read measurements from the same sampling instant. Note that if burst reads
- * are not used, the user is responsible for ensuring a set of single byte reads
- * correspond to a single sampling instant by checking the Data Ready interrupt.
- *
- * Each 16-bit accelerometer measurement has a full scale defined in ACCEL_FS
- * (Register 28). For each full scale setting, the accelerometers' sensitivity
- * per LSB in ACCEL_xOUT is shown in the table below:
- *
- *
- * AFS_SEL | Full Scale Range | LSB Sensitivity
- * --------+------------------+----------------
- * 0 | +/- 2g | 8192 LSB/mg
- * 1 | +/- 4g | 4096 LSB/mg
- * 2 | +/- 8g | 2048 LSB/mg
- * 3 | +/- 16g | 1024 LSB/mg
- *
- *
- * @param x 16-bit signed integer container for X-axis acceleration
- * @param y 16-bit signed integer container for Y-axis acceleration
- * @param z 16-bit signed integer container for Z-axis acceleration
- * @see MPU6050_RA_GYRO_XOUT_H
- */
-void MPU6050::getAcceleration(int16_t* x, int16_t* y, int16_t* z) {
- I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 6, buffer);
- *x = (((int16_t)buffer[0]) << 8) | buffer[1];
- *y = (((int16_t)buffer[2]) << 8) | buffer[3];
- *z = (((int16_t)buffer[4]) << 8) | buffer[5];
-}
-/** Get X-axis accelerometer reading.
- * @return X-axis acceleration measurement in 16-bit 2's complement format
- * @see getMotion6()
- * @see MPU6050_RA_ACCEL_XOUT_H
- */
-int16_t MPU6050::getAccelerationX() {
- I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_XOUT_H, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-/** Get Y-axis accelerometer reading.
- * @return Y-axis acceleration measurement in 16-bit 2's complement format
- * @see getMotion6()
- * @see MPU6050_RA_ACCEL_YOUT_H
- */
-int16_t MPU6050::getAccelerationY() {
- I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_YOUT_H, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-/** Get Z-axis accelerometer reading.
- * @return Z-axis acceleration measurement in 16-bit 2's complement format
- * @see getMotion6()
- * @see MPU6050_RA_ACCEL_ZOUT_H
- */
-int16_t MPU6050::getAccelerationZ() {
- I2Cdev::readBytes(devAddr, MPU6050_RA_ACCEL_ZOUT_H, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-
-// TEMP_OUT_* registers
-
-/** Get current internal temperature.
- * @return Temperature reading in 16-bit 2's complement format
- * @see MPU6050_RA_TEMP_OUT_H
- */
-int16_t MPU6050::getTemperature() {
- I2Cdev::readBytes(devAddr, MPU6050_RA_TEMP_OUT_H, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-
-// GYRO_*OUT_* registers
-
-/** Get 3-axis gyroscope readings.
- * These gyroscope measurement registers, along with the accelerometer
- * measurement registers, temperature measurement registers, and external sensor
- * data registers, are composed of two sets of registers: an internal register
- * set and a user-facing read register set.
- * The data within the gyroscope sensors' internal register set is always
- * updated at the Sample Rate. Meanwhile, the user-facing read register set
- * duplicates the internal register set's data values whenever the serial
- * interface is idle. This guarantees that a burst read of sensor registers will
- * read measurements from the same sampling instant. Note that if burst reads
- * are not used, the user is responsible for ensuring a set of single byte reads
- * correspond to a single sampling instant by checking the Data Ready interrupt.
- *
- * Each 16-bit gyroscope measurement has a full scale defined in FS_SEL
- * (Register 27). For each full scale setting, the gyroscopes' sensitivity per
- * LSB in GYRO_xOUT is shown in the table below:
- *
- *
- * FS_SEL | Full Scale Range | LSB Sensitivity
- * -------+--------------------+----------------
- * 0 | +/- 250 degrees/s | 131 LSB/deg/s
- * 1 | +/- 500 degrees/s | 65.5 LSB/deg/s
- * 2 | +/- 1000 degrees/s | 32.8 LSB/deg/s
- * 3 | +/- 2000 degrees/s | 16.4 LSB/deg/s
- *
- *
- * @param x 16-bit signed integer container for X-axis rotation
- * @param y 16-bit signed integer container for Y-axis rotation
- * @param z 16-bit signed integer container for Z-axis rotation
- * @see getMotion6()
- * @see MPU6050_RA_GYRO_XOUT_H
- */
-void MPU6050::getRotation(int16_t* x, int16_t* y, int16_t* z) {
- I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 6, buffer);
- *x = (((int16_t)buffer[0]) << 8) | buffer[1];
- *y = (((int16_t)buffer[2]) << 8) | buffer[3];
- *z = (((int16_t)buffer[4]) << 8) | buffer[5];
-}
-/** Get X-axis gyroscope reading.
- * @return X-axis rotation measurement in 16-bit 2's complement format
- * @see getMotion6()
- * @see MPU6050_RA_GYRO_XOUT_H
- */
-int16_t MPU6050::getRotationX() {
- I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_XOUT_H, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-/** Get Y-axis gyroscope reading.
- * @return Y-axis rotation measurement in 16-bit 2's complement format
- * @see getMotion6()
- * @see MPU6050_RA_GYRO_YOUT_H
- */
-int16_t MPU6050::getRotationY() {
- I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_YOUT_H, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-/** Get Z-axis gyroscope reading.
- * @return Z-axis rotation measurement in 16-bit 2's complement format
- * @see getMotion6()
- * @see MPU6050_RA_GYRO_ZOUT_H
- */
-int16_t MPU6050::getRotationZ() {
- I2Cdev::readBytes(devAddr, MPU6050_RA_GYRO_ZOUT_H, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-
-// EXT_SENS_DATA_* registers
-
-/** Read single byte from external sensor data register.
- * These registers store data read from external sensors by the Slave 0, 1, 2,
- * and 3 on the auxiliary I2C interface. Data read by Slave 4 is stored in
- * I2C_SLV4_DI (Register 53).
- *
- * External sensor data is written to these registers at the Sample Rate as
- * defined in Register 25. This access rate can be reduced by using the Slave
- * Delay Enable registers (Register 103).
- *
- * External sensor data registers, along with the gyroscope measurement
- * registers, accelerometer measurement registers, and temperature measurement
- * registers, are composed of two sets of registers: an internal register set
- * and a user-facing read register set.
- *
- * The data within the external sensors' internal register set is always updated
- * at the Sample Rate (or the reduced access rate) whenever the serial interface
- * is idle. This guarantees that a burst read of sensor registers will read
- * measurements from the same sampling instant. Note that if burst reads are not
- * used, the user is responsible for ensuring a set of single byte reads
- * correspond to a single sampling instant by checking the Data Ready interrupt.
- *
- * Data is placed in these external sensor data registers according to
- * I2C_SLV0_CTRL, I2C_SLV1_CTRL, I2C_SLV2_CTRL, and I2C_SLV3_CTRL (Registers 39,
- * 42, 45, and 48). When more than zero bytes are read (I2C_SLVx_LEN > 0) from
- * an enabled slave (I2C_SLVx_EN = 1), the slave is read at the Sample Rate (as
- * defined in Register 25) or delayed rate (if specified in Register 52 and
- * 103). During each Sample cycle, slave reads are performed in order of Slave
- * number. If all slaves are enabled with more than zero bytes to be read, the
- * order will be Slave 0, followed by Slave 1, Slave 2, and Slave 3.
- *
- * Each enabled slave will have EXT_SENS_DATA registers associated with it by
- * number of bytes read (I2C_SLVx_LEN) in order of slave number, starting from
- * EXT_SENS_DATA_00. Note that this means enabling or disabling a slave may
- * change the higher numbered slaves' associated registers. Furthermore, if
- * fewer total bytes are being read from the external sensors as a result of
- * such a change, then the data remaining in the registers which no longer have
- * an associated slave device (i.e. high numbered registers) will remain in
- * these previously allocated registers unless reset.
- *
- * If the sum of the read lengths of all SLVx transactions exceed the number of
- * available EXT_SENS_DATA registers, the excess bytes will be dropped. There
- * are 24 EXT_SENS_DATA registers and hence the total read lengths between all
- * the slaves cannot be greater than 24 or some bytes will be lost.
- *
- * Note: Slave 4's behavior is distinct from that of Slaves 0-3. For further
- * information regarding the characteristics of Slave 4, please refer to
- * Registers 49 to 53.
- *
- * EXAMPLE:
- * Suppose that Slave 0 is enabled with 4 bytes to be read (I2C_SLV0_EN = 1 and
- * I2C_SLV0_LEN = 4) while Slave 1 is enabled with 2 bytes to be read so that
- * I2C_SLV1_EN = 1 and I2C_SLV1_LEN = 2. In such a situation, EXT_SENS_DATA _00
- * through _03 will be associated with Slave 0, while EXT_SENS_DATA _04 and 05
- * will be associated with Slave 1. If Slave 2 is enabled as well, registers
- * starting from EXT_SENS_DATA_06 will be allocated to Slave 2.
- *
- * If Slave 2 is disabled while Slave 3 is enabled in this same situation, then
- * registers starting from EXT_SENS_DATA_06 will be allocated to Slave 3
- * instead.
- *
- * REGISTER ALLOCATION FOR DYNAMIC DISABLE VS. NORMAL DISABLE:
- * If a slave is disabled at any time, the space initially allocated to the
- * slave in the EXT_SENS_DATA register, will remain associated with that slave.
- * This is to avoid dynamic adjustment of the register allocation.
- *
- * The allocation of the EXT_SENS_DATA registers is recomputed only when (1) all
- * slaves are disabled, or (2) the I2C_MST_RST bit is set (Register 106).
- *
- * This above is also true if one of the slaves gets NACKed and stops
- * functioning.
- *
- * @param position Starting position (0-23)
- * @return Byte read from register
- */
-uint8_t MPU6050::getExternalSensorByte(int position) {
- I2Cdev::readByte(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, buffer);
- return buffer[0];
-}
-/** Read word (2 bytes) from external sensor data registers.
- * @param position Starting position (0-21)
- * @return Word read from register
- * @see getExternalSensorByte()
- */
-uint16_t MPU6050::getExternalSensorWord(int position) {
- I2Cdev::readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 2, buffer);
- return (((uint16_t)buffer[0]) << 8) | buffer[1];
-}
-/** Read double word (4 bytes) from external sensor data registers.
- * @param position Starting position (0-20)
- * @return Double word read from registers
- * @see getExternalSensorByte()
- */
-uint32_t MPU6050::getExternalSensorDWord(int position) {
- I2Cdev::readBytes(devAddr, MPU6050_RA_EXT_SENS_DATA_00 + position, 4, buffer);
- return (((uint32_t)buffer[0]) << 24) | (((uint32_t)buffer[1]) << 16) | (((uint16_t)buffer[2]) << 8) | buffer[3];
-}
-
-// MOT_DETECT_STATUS register
-
-/** Get full motion detection status register content (all bits).
- * @return Motion detection status byte
- * @see MPU6050_RA_MOT_DETECT_STATUS
- */
-uint8_t MPU6050::getMotionStatus() {
- I2Cdev::readByte(devAddr, MPU6050_RA_MOT_DETECT_STATUS, buffer);
- return buffer[0];
-}
-/** Get X-axis negative motion detection interrupt status.
- * @return Motion detection status
- * @see MPU6050_RA_MOT_DETECT_STATUS
- * @see MPU6050_MOTION_MOT_XNEG_BIT
- */
-bool MPU6050::getXNegMotionDetected() {
- I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XNEG_BIT, buffer);
- return buffer[0];
-}
-/** Get X-axis positive motion detection interrupt status.
- * @return Motion detection status
- * @see MPU6050_RA_MOT_DETECT_STATUS
- * @see MPU6050_MOTION_MOT_XPOS_BIT
- */
-bool MPU6050::getXPosMotionDetected() {
- I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_XPOS_BIT, buffer);
- return buffer[0];
-}
-/** Get Y-axis negative motion detection interrupt status.
- * @return Motion detection status
- * @see MPU6050_RA_MOT_DETECT_STATUS
- * @see MPU6050_MOTION_MOT_YNEG_BIT
- */
-bool MPU6050::getYNegMotionDetected() {
- I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YNEG_BIT, buffer);
- return buffer[0];
-}
-/** Get Y-axis positive motion detection interrupt status.
- * @return Motion detection status
- * @see MPU6050_RA_MOT_DETECT_STATUS
- * @see MPU6050_MOTION_MOT_YPOS_BIT
- */
-bool MPU6050::getYPosMotionDetected() {
- I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_YPOS_BIT, buffer);
- return buffer[0];
-}
-/** Get Z-axis negative motion detection interrupt status.
- * @return Motion detection status
- * @see MPU6050_RA_MOT_DETECT_STATUS
- * @see MPU6050_MOTION_MOT_ZNEG_BIT
- */
-bool MPU6050::getZNegMotionDetected() {
- I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZNEG_BIT, buffer);
- return buffer[0];
-}
-/** Get Z-axis positive motion detection interrupt status.
- * @return Motion detection status
- * @see MPU6050_RA_MOT_DETECT_STATUS
- * @see MPU6050_MOTION_MOT_ZPOS_BIT
- */
-bool MPU6050::getZPosMotionDetected() {
- I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZPOS_BIT, buffer);
- return buffer[0];
-}
-/** Get zero motion detection interrupt status.
- * @return Motion detection status
- * @see MPU6050_RA_MOT_DETECT_STATUS
- * @see MPU6050_MOTION_MOT_ZRMOT_BIT
- */
-bool MPU6050::getZeroMotionDetected() {
- I2Cdev::readBit(devAddr, MPU6050_RA_MOT_DETECT_STATUS, MPU6050_MOTION_MOT_ZRMOT_BIT, buffer);
- return buffer[0];
-}
-
-// I2C_SLV*_DO register
-
-/** Write byte to Data Output container for specified slave.
- * This register holds the output data written into Slave when Slave is set to
- * write mode. For further information regarding Slave control, please
- * refer to Registers 37 to 39 and immediately following.
- * @param num Slave number (0-3)
- * @param data Byte to write
- * @see MPU6050_RA_I2C_SLV0_DO
- */
-void MPU6050::setSlaveOutputByte(uint8_t num, uint8_t data) {
- if (num > 3) return;
- I2Cdev::writeByte(devAddr, MPU6050_RA_I2C_SLV0_DO + num, data);
-}
-
-// I2C_MST_DELAY_CTRL register
-
-/** Get external data shadow delay enabled status.
- * This register is used to specify the timing of external sensor data
- * shadowing. When DELAY_ES_SHADOW is set to 1, shadowing of external
- * sensor data is delayed until all data has been received.
- * @return Current external data shadow delay enabled status.
- * @see MPU6050_RA_I2C_MST_DELAY_CTRL
- * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT
- */
-bool MPU6050::getExternalShadowDelayEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, buffer);
- return buffer[0];
-}
-/** Set external data shadow delay enabled status.
- * @param enabled New external data shadow delay enabled status.
- * @see getExternalShadowDelayEnabled()
- * @see MPU6050_RA_I2C_MST_DELAY_CTRL
- * @see MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT
- */
-void MPU6050::setExternalShadowDelayEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT, enabled);
-}
-/** Get slave delay enabled status.
- * When a particular slave delay is enabled, the rate of access for the that
- * slave device is reduced. When a slave's access rate is decreased relative to
- * the Sample Rate, the slave is accessed every:
- *
- * 1 / (1 + I2C_MST_DLY) Samples
- *
- * This base Sample Rate in turn is determined by SMPLRT_DIV (register * 25)
- * and DLPF_CFG (register 26).
- *
- * For further information regarding I2C_MST_DLY, please refer to register 52.
- * For further information regarding the Sample Rate, please refer to register 25.
- *
- * @param num Slave number (0-4)
- * @return Current slave delay enabled status.
- * @see MPU6050_RA_I2C_MST_DELAY_CTRL
- * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT
- */
-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);
- return buffer[0];
-}
-/** Set slave delay enabled status.
- * @param num Slave number (0-4)
- * @param enabled New slave delay enabled status.
- * @see MPU6050_RA_I2C_MST_DELAY_CTRL
- * @see MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT
- */
-void MPU6050::setSlaveDelayEnabled(uint8_t num, bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_I2C_MST_DELAY_CTRL, num, enabled);
-}
-
-// SIGNAL_PATH_RESET register
-
-/** Reset gyroscope signal path.
- * The reset will revert the signal path analog to digital converters and
- * filters to their power up configurations.
- * @see MPU6050_RA_SIGNAL_PATH_RESET
- * @see MPU6050_PATHRESET_GYRO_RESET_BIT
- */
-void MPU6050::resetGyroscopePath() {
- I2Cdev::writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_GYRO_RESET_BIT, true);
-}
-/** Reset accelerometer signal path.
- * The reset will revert the signal path analog to digital converters and
- * filters to their power up configurations.
- * @see MPU6050_RA_SIGNAL_PATH_RESET
- * @see MPU6050_PATHRESET_ACCEL_RESET_BIT
- */
-void MPU6050::resetAccelerometerPath() {
- I2Cdev::writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_ACCEL_RESET_BIT, true);
-}
-/** Reset temperature sensor signal path.
- * The reset will revert the signal path analog to digital converters and
- * filters to their power up configurations.
- * @see MPU6050_RA_SIGNAL_PATH_RESET
- * @see MPU6050_PATHRESET_TEMP_RESET_BIT
- */
-void MPU6050::resetTemperaturePath() {
- I2Cdev::writeBit(devAddr, MPU6050_RA_SIGNAL_PATH_RESET, MPU6050_PATHRESET_TEMP_RESET_BIT, true);
-}
-
-// MOT_DETECT_CTRL register
-
-/** Get accelerometer power-on delay.
- * The accelerometer data path provides samples to the sensor registers, Motion
- * detection, Zero Motion detection, and Free Fall detection modules. The
- * signal path contains filters which must be flushed on wake-up with new
- * samples before the detection modules begin operations. The default wake-up
- * delay, of 4ms can be lengthened by up to 3ms. This additional delay is
- * specified in ACCEL_ON_DELAY in units of 1 LSB = 1 ms. The user may select
- * any value above zero unless instructed otherwise by InvenSense. Please refer
- * to Section 8 of the MPU-6000/MPU-6050 Product Specification document for
- * further information regarding the detection modules.
- * @return Current accelerometer power-on delay
- * @see MPU6050_RA_MOT_DETECT_CTRL
- * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT
- */
-uint8_t MPU6050::getAccelerometerPowerOnDelay() {
- I2Cdev::readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, buffer);
- return buffer[0];
-}
-/** Set accelerometer power-on delay.
- * @param delay New accelerometer power-on delay (0-3)
- * @see getAccelerometerPowerOnDelay()
- * @see MPU6050_RA_MOT_DETECT_CTRL
- * @see MPU6050_DETECT_ACCEL_ON_DELAY_BIT
- */
-void MPU6050::setAccelerometerPowerOnDelay(uint8_t delay) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_ACCEL_ON_DELAY_BIT, MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH, delay);
-}
-/** Get Free Fall detection counter decrement configuration.
- * Detection is registered by the Free Fall detection module after accelerometer
- * measurements meet their respective threshold conditions over a specified
- * number of samples. When the threshold conditions are met, the corresponding
- * detection counter increments by 1. The user may control the rate at which the
- * detection counter decrements when the threshold condition is not met by
- * configuring FF_COUNT. The decrement rate can be set according to the
- * following table:
- *
- *
- * FF_COUNT | Counter Decrement
- * ---------+------------------
- * 0 | Reset
- * 1 | 1
- * 2 | 2
- * 3 | 4
- *
- *
- * When FF_COUNT is configured to 0 (reset), any non-qualifying sample will
- * reset the counter to 0. For further information on Free Fall detection,
- * please refer to Registers 29 to 32.
- *
- * @return Current decrement configuration
- * @see MPU6050_RA_MOT_DETECT_CTRL
- * @see MPU6050_DETECT_FF_COUNT_BIT
- */
-uint8_t MPU6050::getFreefallDetectionCounterDecrement() {
- I2Cdev::readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, buffer);
- return buffer[0];
-}
-/** Set Free Fall detection counter decrement configuration.
- * @param decrement New decrement configuration value
- * @see getFreefallDetectionCounterDecrement()
- * @see MPU6050_RA_MOT_DETECT_CTRL
- * @see MPU6050_DETECT_FF_COUNT_BIT
- */
-void MPU6050::setFreefallDetectionCounterDecrement(uint8_t decrement) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_FF_COUNT_BIT, MPU6050_DETECT_FF_COUNT_LENGTH, decrement);
-}
-/** Get Motion detection counter decrement configuration.
- * Detection is registered by the Motion detection module after accelerometer
- * measurements meet their respective threshold conditions over a specified
- * number of samples. When the threshold conditions are met, the corresponding
- * detection counter increments by 1. The user may control the rate at which the
- * detection counter decrements when the threshold condition is not met by
- * configuring MOT_COUNT. The decrement rate can be set according to the
- * following table:
- *
- *
- * MOT_COUNT | Counter Decrement
- * ----------+------------------
- * 0 | Reset
- * 1 | 1
- * 2 | 2
- * 3 | 4
- *
- *
- * When MOT_COUNT is configured to 0 (reset), any non-qualifying sample will
- * reset the counter to 0. For further information on Motion detection,
- * please refer to Registers 29 to 32.
- *
- */
-uint8_t MPU6050::getMotionDetectionCounterDecrement() {
- I2Cdev::readBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, buffer);
- return buffer[0];
-}
-/** Set Motion detection counter decrement configuration.
- * @param decrement New decrement configuration value
- * @see getMotionDetectionCounterDecrement()
- * @see MPU6050_RA_MOT_DETECT_CTRL
- * @see MPU6050_DETECT_MOT_COUNT_BIT
- */
-void MPU6050::setMotionDetectionCounterDecrement(uint8_t decrement) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_MOT_DETECT_CTRL, MPU6050_DETECT_MOT_COUNT_BIT, MPU6050_DETECT_MOT_COUNT_LENGTH, decrement);
-}
-
-// USER_CTRL register
-
-/** Get FIFO enabled status.
- * When this bit is set to 0, the FIFO buffer is disabled. The FIFO buffer
- * cannot be written to or read from while disabled. The FIFO buffer's state
- * does not change unless the MPU-60X0 is power cycled.
- * @return Current FIFO enabled status
- * @see MPU6050_RA_USER_CTRL
- * @see MPU6050_USERCTRL_FIFO_EN_BIT
- */
-bool MPU6050::getFIFOEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set FIFO enabled status.
- * @param enabled New FIFO enabled status
- * @see getFIFOEnabled()
- * @see MPU6050_RA_USER_CTRL
- * @see MPU6050_USERCTRL_FIFO_EN_BIT
- */
-void MPU6050::setFIFOEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_EN_BIT, enabled);
-}
-/** Get I2C Master Mode enabled status.
- * When this mode is enabled, the MPU-60X0 acts as the I2C Master to the
- * external sensor slave devices on the auxiliary I2C bus. When this bit is
- * cleared to 0, the auxiliary I2C bus lines (AUX_DA and AUX_CL) are logically
- * driven by the primary I2C bus (SDA and SCL). This is a precondition to
- * enabling Bypass Mode. For further information regarding Bypass Mode, please
- * refer to Register 55.
- * @return Current I2C Master Mode enabled status
- * @see MPU6050_RA_USER_CTRL
- * @see MPU6050_USERCTRL_I2C_MST_EN_BIT
- */
-bool MPU6050::getI2CMasterModeEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, buffer);
- return buffer[0];
-}
-/** Set I2C Master Mode enabled status.
- * @param enabled New I2C Master Mode enabled status
- * @see getI2CMasterModeEnabled()
- * @see MPU6050_RA_USER_CTRL
- * @see MPU6050_USERCTRL_I2C_MST_EN_BIT
- */
-void MPU6050::setI2CMasterModeEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_EN_BIT, enabled);
-}
-/** 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);
-}
-/** Reset the FIFO.
- * This bit resets the FIFO buffer when set to 1 while FIFO_EN equals 0. This
- * bit automatically clears to 0 after the reset has been triggered.
- * @see MPU6050_RA_USER_CTRL
- * @see MPU6050_USERCTRL_FIFO_RESET_BIT
- */
-void MPU6050::resetFIFO() {
- I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_FIFO_RESET_BIT, true);
-}
-/** Reset the I2C Master.
- * This bit resets the I2C Master when set to 1 while I2C_MST_EN equals 0.
- * This bit automatically clears to 0 after the reset has been triggered.
- * @see MPU6050_RA_USER_CTRL
- * @see MPU6050_USERCTRL_I2C_MST_RESET_BIT
- */
-void MPU6050::resetI2CMaster() {
- I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_I2C_MST_RESET_BIT, true);
-}
-/** Reset all sensor registers and signal paths.
- * When set to 1, this bit resets the signal paths for all sensors (gyroscopes,
- * accelerometers, and temperature sensor). This operation will also clear the
- * sensor registers. This bit automatically clears to 0 after the reset has been
- * triggered.
- *
- * When resetting only the signal path (and not the sensor registers), please
- * use Register 104, SIGNAL_PATH_RESET.
- *
- * @see MPU6050_RA_USER_CTRL
- * @see MPU6050_USERCTRL_SIG_COND_RESET_BIT
- */
-void MPU6050::resetSensors() {
- I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_SIG_COND_RESET_BIT, true);
-}
-
-// PWR_MGMT_1 register
-
-/** Trigger a full device reset.
- * A small delay of ~50ms may be desirable after triggering a reset.
- * @see MPU6050_RA_PWR_MGMT_1
- * @see MPU6050_PWR1_DEVICE_RESET_BIT
- */
-void MPU6050::reset() {
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_DEVICE_RESET_BIT, true);
-}
-/** Get sleep mode status.
- * Setting the SLEEP bit in the register puts the device into very low power
- * sleep mode. In this mode, only the serial interface and internal registers
- * remain active, allowing for a very low standby current. Clearing this bit
- * puts the device back into normal mode. To save power, the individual standby
- * selections for each of the gyros should be used if any gyro axis is not used
- * by the application.
- * @return Current sleep mode enabled status
- * @see MPU6050_RA_PWR_MGMT_1
- * @see MPU6050_PWR1_SLEEP_BIT
- */
-bool MPU6050::getSleepEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, buffer);
- return buffer[0];
-}
-/** Set sleep mode status.
- * @param enabled New sleep mode enabled status
- * @see getSleepEnabled()
- * @see MPU6050_RA_PWR_MGMT_1
- * @see MPU6050_PWR1_SLEEP_BIT
- */
-void MPU6050::setSleepEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_SLEEP_BIT, enabled);
-}
-/** Get wake cycle enabled status.
- * When this bit is set to 1 and SLEEP is disabled, the MPU-60X0 will cycle
- * between sleep mode and waking up to take a single sample of data from active
- * sensors at a rate determined by LP_WAKE_CTRL (register 108).
- * @return Current sleep mode enabled status
- * @see MPU6050_RA_PWR_MGMT_1
- * @see MPU6050_PWR1_CYCLE_BIT
- */
-bool MPU6050::getWakeCycleEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, buffer);
- return buffer[0];
-}
-/** Set wake cycle enabled status.
- * @param enabled New sleep mode enabled status
- * @see getWakeCycleEnabled()
- * @see MPU6050_RA_PWR_MGMT_1
- * @see MPU6050_PWR1_CYCLE_BIT
- */
-void MPU6050::setWakeCycleEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CYCLE_BIT, enabled);
-}
-/** Get temperature sensor enabled status.
- * Control the usage of the internal temperature sensor.
- *
- * Note: this register stores the *disabled* value, but for consistency with the
- * rest of the code, the function is named and used with standard true/false
- * values to indicate whether the sensor is enabled or disabled, respectively.
- *
- * @return Current temperature sensor enabled status
- * @see MPU6050_RA_PWR_MGMT_1
- * @see MPU6050_PWR1_TEMP_DIS_BIT
- */
-bool MPU6050::getTempSensorEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, buffer);
- return buffer[0] == 0; // 1 is actually disabled here
-}
-/** Set temperature sensor enabled status.
- * Note: this register stores the *disabled* value, but for consistency with the
- * rest of the code, the function is named and used with standard true/false
- * values to indicate whether the sensor is enabled or disabled, respectively.
- *
- * @param enabled New temperature sensor enabled status
- * @see getTempSensorEnabled()
- * @see MPU6050_RA_PWR_MGMT_1
- * @see MPU6050_PWR1_TEMP_DIS_BIT
- */
-void MPU6050::setTempSensorEnabled(bool enabled) {
- // 1 is actually disabled here
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_TEMP_DIS_BIT, !enabled);
-}
-/** Get clock source setting.
- * @return Current clock source setting
- * @see MPU6050_RA_PWR_MGMT_1
- * @see MPU6050_PWR1_CLKSEL_BIT
- * @see MPU6050_PWR1_CLKSEL_LENGTH
- */
-uint8_t MPU6050::getClockSource() {
- I2Cdev::readBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, buffer);
- return buffer[0];
-}
-/** Set clock source setting.
- * An internal 8MHz oscillator, gyroscope based clock, or external sources can
- * be selected as the MPU-60X0 clock source. When the internal 8 MHz oscillator
- * or an external source is chosen as the clock source, the MPU-60X0 can operate
- * in low power modes with the gyroscopes disabled.
- *
- * Upon power up, the MPU-60X0 clock source defaults to the internal oscillator.
- * However, it is highly recommended that the device be configured to use one of
- * the gyroscopes (or an external clock source) as the clock reference for
- * improved stability. The clock source can be selected according to the following table:
- *
- *
- * CLK_SEL | Clock Source
- * --------+--------------------------------------
- * 0 | Internal oscillator
- * 1 | PLL with X Gyro reference
- * 2 | PLL with Y Gyro reference
- * 3 | PLL with Z Gyro reference
- * 4 | PLL with external 32.768kHz reference
- * 5 | PLL with external 19.2MHz reference
- * 6 | Reserved
- * 7 | Stops the clock and keeps the timing generator in reset
- *
- *
- * @param source New clock source setting
- * @see getClockSource()
- * @see MPU6050_RA_PWR_MGMT_1
- * @see MPU6050_PWR1_CLKSEL_BIT
- * @see MPU6050_PWR1_CLKSEL_LENGTH
- */
-void MPU6050::setClockSource(uint8_t source) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_PWR_MGMT_1, MPU6050_PWR1_CLKSEL_BIT, MPU6050_PWR1_CLKSEL_LENGTH, source);
-}
-
-// PWR_MGMT_2 register
-
-/** Get wake frequency in Accel-Only Low Power Mode.
- * The MPU-60X0 can be put into Accerlerometer Only Low Power Mode by setting
- * PWRSEL to 1 in the Power Management 1 register (Register 107). In this mode,
- * the device will power off all devices except for the primary I2C interface,
- * waking only the accelerometer at fixed intervals to take a single
- * measurement. The frequency of wake-ups can be configured with LP_WAKE_CTRL
- * as shown below:
- *
- *
- * LP_WAKE_CTRL | Wake-up Frequency
- * -------------+------------------
- * 0 | 1.25 Hz
- * 1 | 2.5 Hz
- * 2 | 5 Hz
- * 3 | 10 Hz
- *
- *
- * For further information regarding the MPU-60X0's power modes, please refer to
- * Register 107.
- *
- * @return Current wake frequency
- * @see MPU6050_RA_PWR_MGMT_2
- */
-uint8_t MPU6050::getWakeFrequency() {
- I2Cdev::readBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, buffer);
- return buffer[0];
-}
-/** Set wake frequency in Accel-Only Low Power Mode.
- * @param frequency New wake frequency
- * @see MPU6050_RA_PWR_MGMT_2
- */
-void MPU6050::setWakeFrequency(uint8_t frequency) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_LP_WAKE_CTRL_BIT, MPU6050_PWR2_LP_WAKE_CTRL_LENGTH, frequency);
-}
-
-/** Get X-axis accelerometer standby enabled status.
- * If enabled, the X-axis will not gather or report data (or use power).
- * @return Current X-axis standby enabled status
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_XA_BIT
- */
-bool MPU6050::getStandbyXAccelEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, buffer);
- return buffer[0];
-}
-/** Set X-axis accelerometer standby enabled status.
- * @param New X-axis standby enabled status
- * @see getStandbyXAccelEnabled()
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_XA_BIT
- */
-void MPU6050::setStandbyXAccelEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XA_BIT, enabled);
-}
-/** Get Y-axis accelerometer standby enabled status.
- * If enabled, the Y-axis will not gather or report data (or use power).
- * @return Current Y-axis standby enabled status
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_YA_BIT
- */
-bool MPU6050::getStandbyYAccelEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, buffer);
- return buffer[0];
-}
-/** Set Y-axis accelerometer standby enabled status.
- * @param New Y-axis standby enabled status
- * @see getStandbyYAccelEnabled()
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_YA_BIT
- */
-void MPU6050::setStandbyYAccelEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YA_BIT, enabled);
-}
-/** Get Z-axis accelerometer standby enabled status.
- * If enabled, the Z-axis will not gather or report data (or use power).
- * @return Current Z-axis standby enabled status
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_ZA_BIT
- */
-bool MPU6050::getStandbyZAccelEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, buffer);
- return buffer[0];
-}
-/** Set Z-axis accelerometer standby enabled status.
- * @param New Z-axis standby enabled status
- * @see getStandbyZAccelEnabled()
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_ZA_BIT
- */
-void MPU6050::setStandbyZAccelEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZA_BIT, enabled);
-}
-/** Get X-axis gyroscope standby enabled status.
- * If enabled, the X-axis will not gather or report data (or use power).
- * @return Current X-axis standby enabled status
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_XG_BIT
- */
-bool MPU6050::getStandbyXGyroEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, buffer);
- return buffer[0];
-}
-/** Set X-axis gyroscope standby enabled status.
- * @param New X-axis standby enabled status
- * @see getStandbyXGyroEnabled()
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_XG_BIT
- */
-void MPU6050::setStandbyXGyroEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_XG_BIT, enabled);
-}
-/** Get Y-axis gyroscope standby enabled status.
- * If enabled, the Y-axis will not gather or report data (or use power).
- * @return Current Y-axis standby enabled status
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_YG_BIT
- */
-bool MPU6050::getStandbyYGyroEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, buffer);
- return buffer[0];
-}
-/** Set Y-axis gyroscope standby enabled status.
- * @param New Y-axis standby enabled status
- * @see getStandbyYGyroEnabled()
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_YG_BIT
- */
-void MPU6050::setStandbyYGyroEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_YG_BIT, enabled);
-}
-/** Get Z-axis gyroscope standby enabled status.
- * If enabled, the Z-axis will not gather or report data (or use power).
- * @return Current Z-axis standby enabled status
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_ZG_BIT
- */
-bool MPU6050::getStandbyZGyroEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, buffer);
- return buffer[0];
-}
-/** Set Z-axis gyroscope standby enabled status.
- * @param New Z-axis standby enabled status
- * @see getStandbyZGyroEnabled()
- * @see MPU6050_RA_PWR_MGMT_2
- * @see MPU6050_PWR2_STBY_ZG_BIT
- */
-void MPU6050::setStandbyZGyroEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_PWR_MGMT_2, MPU6050_PWR2_STBY_ZG_BIT, enabled);
-}
-
-// FIFO_COUNT* registers
-
-/** Get current FIFO buffer size.
- * This value indicates the number of bytes stored in the FIFO buffer. This
- * number is in turn the number of bytes that can be read from the FIFO buffer
- * and it is directly proportional to the number of samples available given the
- * set of sensor data bound to be stored in the FIFO (register 35 and 36).
- * @return Current FIFO buffer size
- */
-uint16_t MPU6050::getFIFOCount() {
- I2Cdev::readBytes(devAddr, MPU6050_RA_FIFO_COUNTH, 2, buffer);
- return (((uint16_t)buffer[0]) << 8) | buffer[1];
-}
-
-// FIFO_R_W register
-
-/** Get byte from FIFO buffer.
- * This register is used to read and write data from the FIFO buffer. Data is
- * written to the FIFO in order of register number (from lowest to highest). If
- * all the FIFO enable flags (see below) are enabled and all External Sensor
- * Data registers (Registers 73 to 96) are associated with a Slave device, the
- * contents of registers 59 through 96 will be written in order at the Sample
- * Rate.
- *
- * The contents of the sensor data registers (Registers 59 to 96) are written
- * into the FIFO buffer when their corresponding FIFO enable flags are set to 1
- * in FIFO_EN (Register 35). An additional flag for the sensor data registers
- * associated with I2C Slave 3 can be found in I2C_MST_CTRL (Register 36).
- *
- * If the FIFO buffer has overflowed, the status bit FIFO_OFLOW_INT is
- * automatically set to 1. This bit is located in INT_STATUS (Register 58).
- * When the FIFO buffer has overflowed, the oldest data will be lost and new
- * data will be written to the FIFO.
- *
- * If the FIFO buffer is empty, reading this register will return the last byte
- * that was previously read from the FIFO until new data is available. The user
- * should check FIFO_COUNT to ensure that the FIFO buffer is not read when
- * empty.
- *
- * @return Byte from FIFO buffer
- */
-uint8_t MPU6050::getFIFOByte() {
- I2Cdev::readByte(devAddr, MPU6050_RA_FIFO_R_W, buffer);
- return buffer[0];
-}
-void MPU6050::getFIFOBytes(uint8_t *data, uint8_t length) {
- 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);
-}
-
-// WHO_AM_I register
-
-/** Get Device ID.
- * This register is used to verify the identity of the device (0b110100, 0x34).
- * @return Device ID (6 bits only! should be 0x34)
- * @see MPU6050_RA_WHO_AM_I
- * @see MPU6050_WHO_AM_I_BIT
- * @see MPU6050_WHO_AM_I_LENGTH
- */
-uint8_t MPU6050::getDeviceID() {
- I2Cdev::readBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, buffer);
- return buffer[0];
-}
-/** Set Device ID.
- * Write a new ID into the WHO_AM_I register (no idea why this should ever be
- * necessary though).
- * @param id New device ID to set.
- * @see getDeviceID()
- * @see MPU6050_RA_WHO_AM_I
- * @see MPU6050_WHO_AM_I_BIT
- * @see MPU6050_WHO_AM_I_LENGTH
- */
-void MPU6050::setDeviceID(uint8_t id) {
- I2Cdev::writeBits(devAddr, MPU6050_RA_WHO_AM_I, MPU6050_WHO_AM_I_BIT, MPU6050_WHO_AM_I_LENGTH, id);
-}
-
-// ======== UNDOCUMENTED/DMP REGISTERS/METHODS ========
-
-// XG_OFFS_TC register
-
-uint8_t MPU6050::getOTPBankValid() {
- I2Cdev::readBit(devAddr, MPU6050_RA_XG_OFFS_TC, MPU6050_TC_OTP_BNK_VLD_BIT, buffer);
- return buffer[0];
-}
-void MPU6050::setOTPBankValid(bool 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);
- 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);
-}
-
-// 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);
- 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);
-}
-
-// 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);
- 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);
-}
-
-// X_FINE_GAIN register
-
-int8_t MPU6050::getXFineGain() {
- I2Cdev::readByte(devAddr, MPU6050_RA_X_FINE_GAIN, buffer);
- return buffer[0];
-}
-void MPU6050::setXFineGain(int8_t gain) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_X_FINE_GAIN, gain);
-}
-
-// Y_FINE_GAIN register
-
-int8_t MPU6050::getYFineGain() {
- I2Cdev::readByte(devAddr, MPU6050_RA_Y_FINE_GAIN, buffer);
- return buffer[0];
-}
-void MPU6050::setYFineGain(int8_t gain) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_Y_FINE_GAIN, gain);
-}
-
-// Z_FINE_GAIN register
-
-int8_t MPU6050::getZFineGain() {
- I2Cdev::readByte(devAddr, MPU6050_RA_Z_FINE_GAIN, buffer);
- return buffer[0];
-}
-void MPU6050::setZFineGain(int8_t gain) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_Z_FINE_GAIN, gain);
-}
-
-// XA_OFFS_* registers
-
-int16_t MPU6050::getXAccelOffset() {
- uint8_t SaveAddress = ((getDeviceID() < 0x38 )? MPU6050_RA_XA_OFFS_H:0x77); // MPU6050,MPU9150 Vs MPU6500,MPU9250
- I2Cdev::readBytes(devAddr, SaveAddress, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-void MPU6050::setXAccelOffset(int16_t offset) {
- uint8_t SaveAddress = ((getDeviceID() < 0x38 )? MPU6050_RA_XA_OFFS_H:0x77); // MPU6050,MPU9150 Vs MPU6500,MPU9250
- I2Cdev::writeWord(devAddr, SaveAddress, offset);
-}
-
-// YA_OFFS_* register
-
-int16_t MPU6050::getYAccelOffset() {
- uint8_t SaveAddress = ((getDeviceID() < 0x38 )? MPU6050_RA_YA_OFFS_H:0x7A); // MPU6050,MPU9150 Vs MPU6500,MPU9250
- I2Cdev::readBytes(devAddr, SaveAddress, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-void MPU6050::setYAccelOffset(int16_t offset) {
- uint8_t SaveAddress = ((getDeviceID() < 0x38 )? MPU6050_RA_YA_OFFS_H:0x7A); // MPU6050,MPU9150 Vs MPU6500,MPU9250
- I2Cdev::writeWord(devAddr, SaveAddress, offset);
-}
-
-// ZA_OFFS_* register
-
-int16_t MPU6050::getZAccelOffset() {
- uint8_t SaveAddress = ((getDeviceID() < 0x38 )? MPU6050_RA_ZA_OFFS_H:0x7D); // MPU6050,MPU9150 Vs MPU6500,MPU9250
- I2Cdev::readBytes(devAddr, SaveAddress, 2, buffer);
- return (((int16_t)buffer[0]) << 8) | buffer[1];
-}
-void MPU6050::setZAccelOffset(int16_t offset) {
- uint8_t SaveAddress = ((getDeviceID() < 0x38 )? MPU6050_RA_ZA_OFFS_H:0x7D); // MPU6050,MPU9150 Vs MPU6500,MPU9250
- I2Cdev::writeWord(devAddr, SaveAddress, offset);
-}
-
-// XG_OFFS_USR* registers
-
-int16_t MPU6050::getXGyroOffset() {
- 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);
-}
-
-// YG_OFFS_USR* register
-
-int16_t MPU6050::getYGyroOffset() {
- 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);
-}
-
-// ZG_OFFS_USR* register
-
-int16_t MPU6050::getZGyroOffset() {
- 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);
-}
-
-// INT_ENABLE register (DMP functions)
-
-bool MPU6050::getIntPLLReadyEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, buffer);
- return buffer[0];
-}
-void MPU6050::setIntPLLReadyEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_PLL_RDY_INT_BIT, enabled);
-}
-bool MPU6050::getIntDMPEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, buffer);
- return buffer[0];
-}
-void MPU6050::setIntDMPEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_INT_ENABLE, MPU6050_INTERRUPT_DMP_INT_BIT, enabled);
-}
-
-// DMP_INT_STATUS
-
-bool MPU6050::getDMPInt5Status() {
- I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_5_BIT, buffer);
- return buffer[0];
-}
-bool MPU6050::getDMPInt4Status() {
- I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_4_BIT, buffer);
- return buffer[0];
-}
-bool MPU6050::getDMPInt3Status() {
- I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_3_BIT, buffer);
- return buffer[0];
-}
-bool MPU6050::getDMPInt2Status() {
- I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_2_BIT, buffer);
- return buffer[0];
-}
-bool MPU6050::getDMPInt1Status() {
- I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_1_BIT, buffer);
- return buffer[0];
-}
-bool MPU6050::getDMPInt0Status() {
- I2Cdev::readBit(devAddr, MPU6050_RA_DMP_INT_STATUS, MPU6050_DMPINT_0_BIT, buffer);
- 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);
- return buffer[0];
-}
-bool MPU6050::getIntDMPStatus() {
- I2Cdev::readBit(devAddr, MPU6050_RA_INT_STATUS, MPU6050_INTERRUPT_DMP_INT_BIT, buffer);
- return buffer[0];
-}
-
-// USER_CTRL register (DMP functions)
-
-bool MPU6050::getDMPEnabled() {
- I2Cdev::readBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, buffer);
- return buffer[0];
-}
-void MPU6050::setDMPEnabled(bool enabled) {
- I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_EN_BIT, enabled);
-}
-void MPU6050::resetDMP() {
- I2Cdev::writeBit(devAddr, MPU6050_RA_USER_CTRL, MPU6050_USERCTRL_DMP_RESET_BIT, true);
-}
-
-// BANK_SEL register
-
-void MPU6050::setMemoryBank(uint8_t bank, bool prefetchEnabled, bool userBank) {
- bank &= 0x1F;
- if (userBank) bank |= 0x20;
- if (prefetchEnabled) bank |= 0x40;
- I2Cdev::writeByte(devAddr, MPU6050_RA_BANK_SEL, bank);
-}
-
-// MEM_START_ADDR register
-
-void MPU6050::setMemoryStartAddress(uint8_t address) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_MEM_START_ADDR, address);
-}
-
-// MEM_R_W register
-
-uint8_t MPU6050::readMemoryByte() {
- I2Cdev::readByte(devAddr, MPU6050_RA_MEM_R_W, buffer);
- return buffer[0];
-}
-void MPU6050::writeMemoryByte(uint8_t data) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_MEM_R_W, data);
-}
-void MPU6050::readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address) {
- setMemoryBank(bank);
- setMemoryStartAddress(address);
- uint8_t chunkSize;
- for (uint16_t i = 0; i < dataSize;) {
- // determine correct chunk size according to bank position and data size
- chunkSize = MPU6050_DMP_MEMORY_CHUNK_SIZE;
-
- // make sure we don't go past the data size
- if (i + chunkSize > dataSize) chunkSize = dataSize - i;
-
- // make sure this chunk doesn't go past the bank boundary (256 bytes)
- 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);
-
- // increase byte index by [chunkSize]
- i += chunkSize;
-
- // uint8_t automatically wraps to 0 at 256
- address += chunkSize;
-
- // if we aren't done, update bank (if necessary) and address
- if (i < dataSize) {
- if (address == 0) bank++;
- setMemoryBank(bank);
- setMemoryStartAddress(address);
- }
- }
-}
-bool MPU6050::writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify, bool useProgMem) {
- setMemoryBank(bank);
- setMemoryStartAddress(address);
- uint8_t chunkSize;
- uint8_t *verifyBuffer=0;
- uint8_t *progBuffer=0;
- uint16_t i;
- uint8_t j;
- if (verify) verifyBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE);
- if (useProgMem) progBuffer = (uint8_t *)malloc(MPU6050_DMP_MEMORY_CHUNK_SIZE);
- for (i = 0; i < dataSize;) {
- // determine correct chunk size according to bank position and data size
- chunkSize = MPU6050_DMP_MEMORY_CHUNK_SIZE;
-
- // make sure we don't go past the data size
- if (i + chunkSize > dataSize) chunkSize = dataSize - i;
-
- // 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);
- } else {
- // write the chunk of data as specified
- progBuffer = (uint8_t *)data + i;
- }
-
- 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);
- if (memcmp(progBuffer, verifyBuffer, chunkSize) != 0) {
- /*Serial.print("Block write verification error, bank ");
- Serial.print(bank, DEC);
- Serial.print(", address ");
- Serial.print(address, DEC);
- Serial.print("!\nExpected:");
- for (j = 0; j < chunkSize; j++) {
- Serial.print(" 0x");
- if (progBuffer[j] < 16) Serial.print("0");
- Serial.print(progBuffer[j], HEX);
- }
- Serial.print("\nReceived:");
- for (uint8_t j = 0; j < chunkSize; j++) {
- Serial.print(" 0x");
- if (verifyBuffer[i + j] < 16) Serial.print("0");
- Serial.print(verifyBuffer[i + j], HEX);
- }
- Serial.print("\n");*/
- free(verifyBuffer);
- if (useProgMem) free(progBuffer);
- return false; // uh oh.
- }
- }
-
- // increase byte index by [chunkSize]
- i += chunkSize;
-
- // uint8_t automatically wraps to 0 at 256
- address += chunkSize;
-
- // if we aren't done, update bank (if necessary) and address
- if (i < dataSize) {
- if (address == 0) bank++;
- setMemoryBank(bank);
- setMemoryStartAddress(address);
- }
- }
- if (verify) free(verifyBuffer);
- if (useProgMem) free(progBuffer);
- return true;
-}
-bool MPU6050::writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank, uint8_t address, bool verify) {
- return writeMemoryBlock(data, dataSize, bank, address, verify, true);
-}
-bool MPU6050::writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize, bool useProgMem) {
- uint8_t *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
- }
-
- // config set data is a long string of blocks with the following structure:
- // [bank] [offset] [length] [byte[0], byte[1], ..., byte[length]]
- uint8_t bank, offset, length;
- for (i = 0; i < dataSize;) {
- if (useProgMem) {
- bank = pgm_read_byte(data + i++);
- offset = pgm_read_byte(data + i++);
- length = pgm_read_byte(data + i++);
- } else {
- bank = data[i++];
- offset = data[i++];
- length = data[i++];
- }
-
- // write data or perform special action
- if (length > 0) {
- // regular block of data to write
- /*Serial.print("Writing config block to bank ");
- Serial.print(bank);
- Serial.print(", offset ");
- Serial.print(offset);
- Serial.print(", length=");
- Serial.println(length);*/
- if (useProgMem) {
- if (sizeof(progBuffer) < length) progBuffer = (uint8_t *)realloc(progBuffer, length);
- for (j = 0; j < length; j++) progBuffer[j] = pgm_read_byte(data + i + j);
- } else {
- progBuffer = (uint8_t *)data + i;
- }
- success = writeMemoryBlock(progBuffer, length, bank, offset, true);
- i += length;
- } else {
- // special instruction
- // NOTE: this kind of behavior (what and when to do certain things)
- // is totally undocumented. This code is in here based on observed
- // behavior only, and exactly why (or even whether) it has to be here
- // is anybody's guess for now.
- if (useProgMem) {
- special = pgm_read_byte(data + i++);
- } else {
- special = data[i++];
- }
- /*Serial.print("Special command code ");
- Serial.print(special, HEX);
- 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
-
- success = true;
- } else {
- // unknown special command
- success = false;
- }
- }
-
- if (!success) {
- if (useProgMem) free(progBuffer);
- return false; // uh oh
- }
- }
- if (useProgMem) free(progBuffer);
- return true;
-}
-bool MPU6050::writeProgDMPConfigurationSet(const uint8_t *data, uint16_t dataSize) {
- return writeDMPConfigurationSet(data, dataSize, true);
-}
-
-// DMP_CFG_1 register
-
-uint8_t MPU6050::getDMPConfig1() {
- I2Cdev::readByte(devAddr, MPU6050_RA_DMP_CFG_1, buffer);
- return buffer[0];
-}
-void MPU6050::setDMPConfig1(uint8_t config) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_DMP_CFG_1, config);
-}
-
-// DMP_CFG_2 register
-
-uint8_t MPU6050::getDMPConfig2() {
- I2Cdev::readByte(devAddr, MPU6050_RA_DMP_CFG_2, buffer);
- return buffer[0];
-}
-void MPU6050::setDMPConfig2(uint8_t config) {
- I2Cdev::writeByte(devAddr, MPU6050_RA_DMP_CFG_2, config);
-}
-
-
-//***************************************************************************************
-//********************** Calibration Routines **********************
-//***************************************************************************************
-/**
- @brief Fully calibrate Gyro from ZERO in about 6-7 Loops 600-700 readings
-*/
-void MPU6050::CalibrateGyro(uint8_t Loops ) {
- double kP = 0.3;
- double kI = 90;
- float x;
- x = (100 - map(Loops, 1, 5, 20, 0)) * .01;
- kP *= x;
- kI *= x;
-
- PID( 0x43, kP, kI, Loops);
-}
-
-/**
- @brief Fully calibrate Accel from ZERO in about 6-7 Loops 600-700 readings
-*/
-void MPU6050::CalibrateAccel(uint8_t Loops ) {
-
- float kP = 0.3;
- float kI = 20;
- float x;
- x = (100 - map(Loops, 1, 5, 20, 0)) * .01;
- kP *= x;
- kI *= x;
- PID( 0x3B, kP, kI, Loops);
-}
-
-void MPU6050::PID(uint8_t ReadAddress, float kP,float kI, uint8_t Loops){
- uint8_t SaveAddress = (ReadAddress == 0x3B)?((getDeviceID() < 0x38 )? 0x06:0x77):0x13;
-
- int16_t Data;
- float Reading;
- int16_t BitZero[3];
- uint8_t shift =(SaveAddress == 0x77)?3:2;
- float Error, PTerm, ITerm[3];
- int16_t eSample;
- uint32_t eSum ;
- Serial.write('>');
- for (int i = 0; i < 3; i++) {
- I2Cdev::readWords(devAddr, SaveAddress + (i * shift), 1, (uint16_t *)&Data); // reads 1 or more 16 bit integers (Word)
- Reading = Data;
- if(SaveAddress != 0x13){
- BitZero[i] = Data & 1; // Capture Bit Zero to properly handle Accelerometer calibration
- ITerm[i] = ((float)Reading) * 8;
- } else {
- ITerm[i] = Reading * 4;
- }
- }
- for (int L = 0; L < Loops; L++) {
- eSample = 0;
- for (int c = 0; c < 100; c++) {// 100 PI Calculations
- eSum = 0;
- for (int i = 0; i < 3; i++) {
- I2Cdev::readWords(devAddr, ReadAddress + (i * 2), 1, (uint16_t *)&Data); // reads 1 or more 16 bit integers (Word)
- Reading = Data;
- if ((ReadAddress == 0x3B)&&(i == 2)) Reading -= 16384; //remove Gravity
- Error = -Reading;
- eSum += abs(Reading);
- PTerm = kP * Error;
- ITerm[i] += (Error * 0.001) * kI; // Integral term 1000 Calculations a second = 0.001
- if(SaveAddress != 0x13){
- Data = round((PTerm + ITerm[i] ) / 8); //Compute PID Output
- Data = ((Data)&0xFFFE) |BitZero[i]; // Insert Bit0 Saved at beginning
- } else Data = round((PTerm + ITerm[i] ) / 4); //Compute PID Output
- I2Cdev::writeWords(devAddr, SaveAddress + (i * shift), 1, (uint16_t *)&Data);
- }
- if((c == 99) && eSum > 1000){ // Error is still to great to continue
- c = 0;
- Serial.write('*');
- }
- if((eSum * ((ReadAddress == 0x3B)?.05: 1)) < 5) eSample++; // Successfully found offsets prepare to advance
- if((eSum < 100) && (c > 10) && (eSample >= 10)) break; // Advance to next Loop
- delay(1);
- }
- Serial.write('.');
- kP *= .75;
- kI *= .75;
- for (int i = 0; i < 3; i++){
- if(SaveAddress != 0x13) {
- Data = round((ITerm[i] ) / 8); //Compute PID Output
- Data = ((Data)&0xFFFE) |BitZero[i]; // Insert Bit0 Saved at beginning
- } else Data = round((ITerm[i]) / 4);
- I2Cdev::writeWords(devAddr, SaveAddress + (i * shift), 1, (uint16_t *)&Data);
- }
- }
- resetFIFO();
- resetDMP();
-}
-
-#define printfloatx(Name,Variable,Spaces,Precision,EndTxt) { Serial.print(F(Name)); {char S[(Spaces + Precision + 3)];Serial.print(F(" ")); Serial.print(dtostrf((float)Variable,Spaces,Precision ,S));}Serial.print(F(EndTxt)); }//Name,Variable,Spaces,Precision,EndTxt
-void MPU6050::PrintActiveOffsets() {
- uint8_t AOffsetRegister = (getDeviceID() < 0x38 )? MPU6050_RA_XA_OFFS_H:0x77;
- int16_t Data[3];
- //Serial.print(F("Offset Register 0x"));
- //Serial.print(AOffsetRegister>>4,HEX);Serial.print(AOffsetRegister&0x0F,HEX);
- Serial.print(F("\n// X Accel Y Accel Z Accel X Gyro Y Gyro Z Gyro\n//OFFSETS "));
- if(AOffsetRegister == 0x06) I2Cdev::readWords(devAddr, AOffsetRegister, 3, (uint16_t *)Data);
- else {
- I2Cdev::readWords(devAddr, AOffsetRegister, 1, (uint16_t *)Data);
- I2Cdev::readWords(devAddr, AOffsetRegister+3, 1, (uint16_t *)Data+1);
- I2Cdev::readWords(devAddr, AOffsetRegister+6, 1, (uint16_t *)Data+2);
- }
- // A_OFFSET_H_READ_A_OFFS(Data);
- printfloatx("", Data[0], 5, 0, ", ");
- printfloatx("", Data[1], 5, 0, ", ");
- printfloatx("", Data[2], 5, 0, ", ");
- I2Cdev::readWords(devAddr, 0x13, 3, (uint16_t *)Data);
- // XG_OFFSET_H_READ_OFFS_USR(Data);
- printfloatx("", Data[0], 5, 0, ", ");
- printfloatx("", Data[1], 5, 0, ", ");
- printfloatx("", Data[2], 5, 0, "\n");
-}
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050.h b/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050.h
deleted file mode 100644
index 871f423a..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050.h
+++ /dev/null
@@ -1,1041 +0,0 @@
-// 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
-// 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_
-
-#include "I2Cdev.h"
-
-// supporting link: http://forum.arduino.cc/index.php?&topic=143444.msg1079517#msg1079517
-// also: http://forum.arduino.cc/index.php?&topic=141571.msg1062899#msg1062899s
-
-#ifdef __AVR__
-#include
-#elif defined(ARDUINO_ARCH_SAMD)
-#include
-#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
-#endif
-
-
-#define MPU6050_ADDRESS_AD0_LOW 0x68 // address pin low (GND), default for InvenSense evaluation board
-#define MPU6050_ADDRESS_AD0_HIGH 0x69 // address pin high (VCC)
-#define MPU6050_DEFAULT_ADDRESS MPU6050_ADDRESS_AD0_LOW
-
-#define MPU6050_RA_XG_OFFS_TC 0x00 //[7] PWR_MODE, [6:1] XG_OFFS_TC, [0] OTP_BNK_VLD
-#define MPU6050_RA_YG_OFFS_TC 0x01 //[7] PWR_MODE, [6:1] YG_OFFS_TC, [0] OTP_BNK_VLD
-#define MPU6050_RA_ZG_OFFS_TC 0x02 //[7] PWR_MODE, [6:1] ZG_OFFS_TC, [0] OTP_BNK_VLD
-#define MPU6050_RA_X_FINE_GAIN 0x03 //[7:0] X_FINE_GAIN
-#define MPU6050_RA_Y_FINE_GAIN 0x04 //[7:0] Y_FINE_GAIN
-#define MPU6050_RA_Z_FINE_GAIN 0x05 //[7:0] Z_FINE_GAIN
-#define MPU6050_RA_XA_OFFS_H 0x06 //[15:0] XA_OFFS
-#define MPU6050_RA_XA_OFFS_L_TC 0x07
-#define MPU6050_RA_YA_OFFS_H 0x08 //[15:0] YA_OFFS
-#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
-#define MPU6050_RA_YG_OFFS_USRL 0x16
-#define MPU6050_RA_ZG_OFFS_USRH 0x17 //[15:0] ZG_OFFS_USR
-#define MPU6050_RA_ZG_OFFS_USRL 0x18
-#define MPU6050_RA_SMPLRT_DIV 0x19
-#define MPU6050_RA_CONFIG 0x1A
-#define MPU6050_RA_GYRO_CONFIG 0x1B
-#define MPU6050_RA_ACCEL_CONFIG 0x1C
-#define MPU6050_RA_FF_THR 0x1D
-#define MPU6050_RA_FF_DUR 0x1E
-#define MPU6050_RA_MOT_THR 0x1F
-#define MPU6050_RA_MOT_DUR 0x20
-#define MPU6050_RA_ZRMOT_THR 0x21
-#define MPU6050_RA_ZRMOT_DUR 0x22
-#define MPU6050_RA_FIFO_EN 0x23
-#define MPU6050_RA_I2C_MST_CTRL 0x24
-#define MPU6050_RA_I2C_SLV0_ADDR 0x25
-#define MPU6050_RA_I2C_SLV0_REG 0x26
-#define MPU6050_RA_I2C_SLV0_CTRL 0x27
-#define MPU6050_RA_I2C_SLV1_ADDR 0x28
-#define MPU6050_RA_I2C_SLV1_REG 0x29
-#define MPU6050_RA_I2C_SLV1_CTRL 0x2A
-#define MPU6050_RA_I2C_SLV2_ADDR 0x2B
-#define MPU6050_RA_I2C_SLV2_REG 0x2C
-#define MPU6050_RA_I2C_SLV2_CTRL 0x2D
-#define MPU6050_RA_I2C_SLV3_ADDR 0x2E
-#define MPU6050_RA_I2C_SLV3_REG 0x2F
-#define MPU6050_RA_I2C_SLV3_CTRL 0x30
-#define MPU6050_RA_I2C_SLV4_ADDR 0x31
-#define MPU6050_RA_I2C_SLV4_REG 0x32
-#define MPU6050_RA_I2C_SLV4_DO 0x33
-#define MPU6050_RA_I2C_SLV4_CTRL 0x34
-#define MPU6050_RA_I2C_SLV4_DI 0x35
-#define MPU6050_RA_I2C_MST_STATUS 0x36
-#define MPU6050_RA_INT_PIN_CFG 0x37
-#define MPU6050_RA_INT_ENABLE 0x38
-#define MPU6050_RA_DMP_INT_STATUS 0x39
-#define MPU6050_RA_INT_STATUS 0x3A
-#define MPU6050_RA_ACCEL_XOUT_H 0x3B
-#define MPU6050_RA_ACCEL_XOUT_L 0x3C
-#define MPU6050_RA_ACCEL_YOUT_H 0x3D
-#define MPU6050_RA_ACCEL_YOUT_L 0x3E
-#define MPU6050_RA_ACCEL_ZOUT_H 0x3F
-#define MPU6050_RA_ACCEL_ZOUT_L 0x40
-#define MPU6050_RA_TEMP_OUT_H 0x41
-#define MPU6050_RA_TEMP_OUT_L 0x42
-#define MPU6050_RA_GYRO_XOUT_H 0x43
-#define MPU6050_RA_GYRO_XOUT_L 0x44
-#define MPU6050_RA_GYRO_YOUT_H 0x45
-#define MPU6050_RA_GYRO_YOUT_L 0x46
-#define MPU6050_RA_GYRO_ZOUT_H 0x47
-#define MPU6050_RA_GYRO_ZOUT_L 0x48
-#define MPU6050_RA_EXT_SENS_DATA_00 0x49
-#define MPU6050_RA_EXT_SENS_DATA_01 0x4A
-#define MPU6050_RA_EXT_SENS_DATA_02 0x4B
-#define MPU6050_RA_EXT_SENS_DATA_03 0x4C
-#define MPU6050_RA_EXT_SENS_DATA_04 0x4D
-#define MPU6050_RA_EXT_SENS_DATA_05 0x4E
-#define MPU6050_RA_EXT_SENS_DATA_06 0x4F
-#define MPU6050_RA_EXT_SENS_DATA_07 0x50
-#define MPU6050_RA_EXT_SENS_DATA_08 0x51
-#define MPU6050_RA_EXT_SENS_DATA_09 0x52
-#define MPU6050_RA_EXT_SENS_DATA_10 0x53
-#define MPU6050_RA_EXT_SENS_DATA_11 0x54
-#define MPU6050_RA_EXT_SENS_DATA_12 0x55
-#define MPU6050_RA_EXT_SENS_DATA_13 0x56
-#define MPU6050_RA_EXT_SENS_DATA_14 0x57
-#define MPU6050_RA_EXT_SENS_DATA_15 0x58
-#define MPU6050_RA_EXT_SENS_DATA_16 0x59
-#define MPU6050_RA_EXT_SENS_DATA_17 0x5A
-#define MPU6050_RA_EXT_SENS_DATA_18 0x5B
-#define MPU6050_RA_EXT_SENS_DATA_19 0x5C
-#define MPU6050_RA_EXT_SENS_DATA_20 0x5D
-#define MPU6050_RA_EXT_SENS_DATA_21 0x5E
-#define MPU6050_RA_EXT_SENS_DATA_22 0x5F
-#define MPU6050_RA_EXT_SENS_DATA_23 0x60
-#define MPU6050_RA_MOT_DETECT_STATUS 0x61
-#define MPU6050_RA_I2C_SLV0_DO 0x63
-#define MPU6050_RA_I2C_SLV1_DO 0x64
-#define MPU6050_RA_I2C_SLV2_DO 0x65
-#define MPU6050_RA_I2C_SLV3_DO 0x66
-#define MPU6050_RA_I2C_MST_DELAY_CTRL 0x67
-#define MPU6050_RA_SIGNAL_PATH_RESET 0x68
-#define MPU6050_RA_MOT_DETECT_CTRL 0x69
-#define MPU6050_RA_USER_CTRL 0x6A
-#define MPU6050_RA_PWR_MGMT_1 0x6B
-#define MPU6050_RA_PWR_MGMT_2 0x6C
-#define MPU6050_RA_BANK_SEL 0x6D
-#define MPU6050_RA_MEM_START_ADDR 0x6E
-#define MPU6050_RA_MEM_R_W 0x6F
-#define MPU6050_RA_DMP_CFG_1 0x70
-#define MPU6050_RA_DMP_CFG_2 0x71
-#define MPU6050_RA_FIFO_COUNTH 0x72
-#define MPU6050_RA_FIFO_COUNTL 0x73
-#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
-#define MPU6050_TC_OTP_BNK_VLD_BIT 0
-
-#define MPU6050_VDDIO_LEVEL_VLOGIC 0
-#define MPU6050_VDDIO_LEVEL_VDD 1
-
-#define MPU6050_CFG_EXT_SYNC_SET_BIT 5
-#define MPU6050_CFG_EXT_SYNC_SET_LENGTH 3
-#define MPU6050_CFG_DLPF_CFG_BIT 2
-#define MPU6050_CFG_DLPF_CFG_LENGTH 3
-
-#define MPU6050_EXT_SYNC_DISABLED 0x0
-#define MPU6050_EXT_SYNC_TEMP_OUT_L 0x1
-#define MPU6050_EXT_SYNC_GYRO_XOUT_L 0x2
-#define MPU6050_EXT_SYNC_GYRO_YOUT_L 0x3
-#define MPU6050_EXT_SYNC_GYRO_ZOUT_L 0x4
-#define MPU6050_EXT_SYNC_ACCEL_XOUT_L 0x5
-#define MPU6050_EXT_SYNC_ACCEL_YOUT_L 0x6
-#define MPU6050_EXT_SYNC_ACCEL_ZOUT_L 0x7
-
-#define MPU6050_DLPF_BW_256 0x00
-#define MPU6050_DLPF_BW_188 0x01
-#define MPU6050_DLPF_BW_98 0x02
-#define MPU6050_DLPF_BW_42 0x03
-#define MPU6050_DLPF_BW_20 0x04
-#define MPU6050_DLPF_BW_10 0x05
-#define MPU6050_DLPF_BW_5 0x06
-
-#define MPU6050_GCONFIG_FS_SEL_BIT 4
-#define MPU6050_GCONFIG_FS_SEL_LENGTH 2
-
-#define MPU6050_GYRO_FS_250 0x00
-#define MPU6050_GYRO_FS_500 0x01
-#define MPU6050_GYRO_FS_1000 0x02
-#define MPU6050_GYRO_FS_2000 0x03
-
-#define MPU6050_ACONFIG_XA_ST_BIT 7
-#define MPU6050_ACONFIG_YA_ST_BIT 6
-#define MPU6050_ACONFIG_ZA_ST_BIT 5
-#define MPU6050_ACONFIG_AFS_SEL_BIT 4
-#define MPU6050_ACONFIG_AFS_SEL_LENGTH 2
-#define MPU6050_ACONFIG_ACCEL_HPF_BIT 2
-#define MPU6050_ACONFIG_ACCEL_HPF_LENGTH 3
-
-#define MPU6050_ACCEL_FS_2 0x00
-#define MPU6050_ACCEL_FS_4 0x01
-#define MPU6050_ACCEL_FS_8 0x02
-#define MPU6050_ACCEL_FS_16 0x03
-
-#define MPU6050_DHPF_RESET 0x00
-#define MPU6050_DHPF_5 0x01
-#define MPU6050_DHPF_2P5 0x02
-#define MPU6050_DHPF_1P25 0x03
-#define MPU6050_DHPF_0P63 0x04
-#define MPU6050_DHPF_HOLD 0x07
-
-#define MPU6050_TEMP_FIFO_EN_BIT 7
-#define MPU6050_XG_FIFO_EN_BIT 6
-#define MPU6050_YG_FIFO_EN_BIT 5
-#define MPU6050_ZG_FIFO_EN_BIT 4
-#define MPU6050_ACCEL_FIFO_EN_BIT 3
-#define MPU6050_SLV2_FIFO_EN_BIT 2
-#define MPU6050_SLV1_FIFO_EN_BIT 1
-#define MPU6050_SLV0_FIFO_EN_BIT 0
-
-#define MPU6050_MULT_MST_EN_BIT 7
-#define MPU6050_WAIT_FOR_ES_BIT 6
-#define MPU6050_SLV_3_FIFO_EN_BIT 5
-#define MPU6050_I2C_MST_P_NSR_BIT 4
-#define MPU6050_I2C_MST_CLK_BIT 3
-#define MPU6050_I2C_MST_CLK_LENGTH 4
-
-#define MPU6050_CLOCK_DIV_348 0x0
-#define MPU6050_CLOCK_DIV_333 0x1
-#define MPU6050_CLOCK_DIV_320 0x2
-#define MPU6050_CLOCK_DIV_308 0x3
-#define MPU6050_CLOCK_DIV_296 0x4
-#define MPU6050_CLOCK_DIV_286 0x5
-#define MPU6050_CLOCK_DIV_276 0x6
-#define MPU6050_CLOCK_DIV_267 0x7
-#define MPU6050_CLOCK_DIV_258 0x8
-#define MPU6050_CLOCK_DIV_500 0x9
-#define MPU6050_CLOCK_DIV_471 0xA
-#define MPU6050_CLOCK_DIV_444 0xB
-#define MPU6050_CLOCK_DIV_421 0xC
-#define MPU6050_CLOCK_DIV_400 0xD
-#define MPU6050_CLOCK_DIV_381 0xE
-#define MPU6050_CLOCK_DIV_364 0xF
-
-#define MPU6050_I2C_SLV_RW_BIT 7
-#define MPU6050_I2C_SLV_ADDR_BIT 6
-#define MPU6050_I2C_SLV_ADDR_LENGTH 7
-#define MPU6050_I2C_SLV_EN_BIT 7
-#define MPU6050_I2C_SLV_BYTE_SW_BIT 6
-#define MPU6050_I2C_SLV_REG_DIS_BIT 5
-#define MPU6050_I2C_SLV_GRP_BIT 4
-#define MPU6050_I2C_SLV_LEN_BIT 3
-#define MPU6050_I2C_SLV_LEN_LENGTH 4
-
-#define MPU6050_I2C_SLV4_RW_BIT 7
-#define MPU6050_I2C_SLV4_ADDR_BIT 6
-#define MPU6050_I2C_SLV4_ADDR_LENGTH 7
-#define MPU6050_I2C_SLV4_EN_BIT 7
-#define MPU6050_I2C_SLV4_INT_EN_BIT 6
-#define MPU6050_I2C_SLV4_REG_DIS_BIT 5
-#define MPU6050_I2C_SLV4_MST_DLY_BIT 4
-#define MPU6050_I2C_SLV4_MST_DLY_LENGTH 5
-
-#define MPU6050_MST_PASS_THROUGH_BIT 7
-#define MPU6050_MST_I2C_SLV4_DONE_BIT 6
-#define MPU6050_MST_I2C_LOST_ARB_BIT 5
-#define MPU6050_MST_I2C_SLV4_NACK_BIT 4
-#define MPU6050_MST_I2C_SLV3_NACK_BIT 3
-#define MPU6050_MST_I2C_SLV2_NACK_BIT 2
-#define MPU6050_MST_I2C_SLV1_NACK_BIT 1
-#define MPU6050_MST_I2C_SLV0_NACK_BIT 0
-
-#define MPU6050_INTCFG_INT_LEVEL_BIT 7
-#define MPU6050_INTCFG_INT_OPEN_BIT 6
-#define MPU6050_INTCFG_LATCH_INT_EN_BIT 5
-#define MPU6050_INTCFG_INT_RD_CLEAR_BIT 4
-#define MPU6050_INTCFG_FSYNC_INT_LEVEL_BIT 3
-#define MPU6050_INTCFG_FSYNC_INT_EN_BIT 2
-#define MPU6050_INTCFG_I2C_BYPASS_EN_BIT 1
-#define MPU6050_INTCFG_CLKOUT_EN_BIT 0
-
-#define MPU6050_INTMODE_ACTIVEHIGH 0x00
-#define MPU6050_INTMODE_ACTIVELOW 0x01
-
-#define MPU6050_INTDRV_PUSHPULL 0x00
-#define MPU6050_INTDRV_OPENDRAIN 0x01
-
-#define MPU6050_INTLATCH_50USPULSE 0x00
-#define MPU6050_INTLATCH_WAITCLEAR 0x01
-
-#define MPU6050_INTCLEAR_STATUSREAD 0x00
-#define MPU6050_INTCLEAR_ANYREAD 0x01
-
-#define MPU6050_INTERRUPT_FF_BIT 7
-#define MPU6050_INTERRUPT_MOT_BIT 6
-#define MPU6050_INTERRUPT_ZMOT_BIT 5
-#define MPU6050_INTERRUPT_FIFO_OFLOW_BIT 4
-#define MPU6050_INTERRUPT_I2C_MST_INT_BIT 3
-#define MPU6050_INTERRUPT_PLL_RDY_INT_BIT 2
-#define MPU6050_INTERRUPT_DMP_INT_BIT 1
-#define MPU6050_INTERRUPT_DATA_RDY_BIT 0
-
-// TODO: figure out what these actually do
-// UMPL source code is not very obivous
-#define MPU6050_DMPINT_5_BIT 5
-#define MPU6050_DMPINT_4_BIT 4
-#define MPU6050_DMPINT_3_BIT 3
-#define MPU6050_DMPINT_2_BIT 2
-#define MPU6050_DMPINT_1_BIT 1
-#define MPU6050_DMPINT_0_BIT 0
-
-#define MPU6050_MOTION_MOT_XNEG_BIT 7
-#define MPU6050_MOTION_MOT_XPOS_BIT 6
-#define MPU6050_MOTION_MOT_YNEG_BIT 5
-#define MPU6050_MOTION_MOT_YPOS_BIT 4
-#define MPU6050_MOTION_MOT_ZNEG_BIT 3
-#define MPU6050_MOTION_MOT_ZPOS_BIT 2
-#define MPU6050_MOTION_MOT_ZRMOT_BIT 0
-
-#define MPU6050_DELAYCTRL_DELAY_ES_SHADOW_BIT 7
-#define MPU6050_DELAYCTRL_I2C_SLV4_DLY_EN_BIT 4
-#define MPU6050_DELAYCTRL_I2C_SLV3_DLY_EN_BIT 3
-#define MPU6050_DELAYCTRL_I2C_SLV2_DLY_EN_BIT 2
-#define MPU6050_DELAYCTRL_I2C_SLV1_DLY_EN_BIT 1
-#define MPU6050_DELAYCTRL_I2C_SLV0_DLY_EN_BIT 0
-
-#define MPU6050_PATHRESET_GYRO_RESET_BIT 2
-#define MPU6050_PATHRESET_ACCEL_RESET_BIT 1
-#define MPU6050_PATHRESET_TEMP_RESET_BIT 0
-
-#define MPU6050_DETECT_ACCEL_ON_DELAY_BIT 5
-#define MPU6050_DETECT_ACCEL_ON_DELAY_LENGTH 2
-#define MPU6050_DETECT_FF_COUNT_BIT 3
-#define MPU6050_DETECT_FF_COUNT_LENGTH 2
-#define MPU6050_DETECT_MOT_COUNT_BIT 1
-#define MPU6050_DETECT_MOT_COUNT_LENGTH 2
-
-#define MPU6050_DETECT_DECREMENT_RESET 0x0
-#define MPU6050_DETECT_DECREMENT_1 0x1
-#define MPU6050_DETECT_DECREMENT_2 0x2
-#define MPU6050_DETECT_DECREMENT_4 0x3
-
-#define MPU6050_USERCTRL_DMP_EN_BIT 7
-#define MPU6050_USERCTRL_FIFO_EN_BIT 6
-#define MPU6050_USERCTRL_I2C_MST_EN_BIT 5
-#define MPU6050_USERCTRL_I2C_IF_DIS_BIT 4
-#define MPU6050_USERCTRL_DMP_RESET_BIT 3
-#define MPU6050_USERCTRL_FIFO_RESET_BIT 2
-#define MPU6050_USERCTRL_I2C_MST_RESET_BIT 1
-#define MPU6050_USERCTRL_SIG_COND_RESET_BIT 0
-
-#define MPU6050_PWR1_DEVICE_RESET_BIT 7
-#define MPU6050_PWR1_SLEEP_BIT 6
-#define MPU6050_PWR1_CYCLE_BIT 5
-#define MPU6050_PWR1_TEMP_DIS_BIT 3
-#define MPU6050_PWR1_CLKSEL_BIT 2
-#define MPU6050_PWR1_CLKSEL_LENGTH 3
-
-#define MPU6050_CLOCK_INTERNAL 0x00
-#define MPU6050_CLOCK_PLL_XGYRO 0x01
-#define MPU6050_CLOCK_PLL_YGYRO 0x02
-#define MPU6050_CLOCK_PLL_ZGYRO 0x03
-#define MPU6050_CLOCK_PLL_EXT32K 0x04
-#define MPU6050_CLOCK_PLL_EXT19M 0x05
-#define MPU6050_CLOCK_KEEP_RESET 0x07
-
-#define MPU6050_PWR2_LP_WAKE_CTRL_BIT 7
-#define MPU6050_PWR2_LP_WAKE_CTRL_LENGTH 2
-#define MPU6050_PWR2_STBY_XA_BIT 5
-#define MPU6050_PWR2_STBY_YA_BIT 4
-#define MPU6050_PWR2_STBY_ZA_BIT 3
-#define MPU6050_PWR2_STBY_XG_BIT 2
-#define MPU6050_PWR2_STBY_YG_BIT 1
-#define MPU6050_PWR2_STBY_ZG_BIT 0
-
-#define MPU6050_WAKE_FREQ_1P25 0x0
-#define MPU6050_WAKE_FREQ_2P5 0x1
-#define MPU6050_WAKE_FREQ_5 0x2
-#define MPU6050_WAKE_FREQ_10 0x3
-
-#define MPU6050_BANKSEL_PRFTCH_EN_BIT 6
-#define MPU6050_BANKSEL_CFG_USER_BANK_BIT 5
-#define MPU6050_BANKSEL_MEM_SEL_BIT 4
-#define MPU6050_BANKSEL_MEM_SEL_LENGTH 5
-
-#define MPU6050_WHO_AM_I_BIT 6
-#define MPU6050_WHO_AM_I_LENGTH 6
-
-#define MPU6050_DMP_MEMORY_BANKS 8
-#define MPU6050_DMP_MEMORY_BANK_SIZE 256
-#define MPU6050_DMP_MEMORY_CHUNK_SIZE 16
-
-// note: DMP code memory blocks defined at end of header file
-
-class MPU6050 {
- public:
- MPU6050(uint8_t address=MPU6050_DEFAULT_ADDRESS);
-
- void initialize();
- bool testConnection();
-
- // AUX_VDDIO register
- uint8_t getAuxVDDIOLevel();
- void setAuxVDDIOLevel(uint8_t level);
-
- // SMPLRT_DIV register
- uint8_t getRate();
- void setRate(uint8_t rate);
-
- // CONFIG register
- uint8_t getExternalFrameSync();
- void setExternalFrameSync(uint8_t sync);
- uint8_t getDLPFMode();
- void setDLPFMode(uint8_t bandwidth);
-
- // GYRO_CONFIG register
- 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);
- bool getAccelYSelfTest();
- void setAccelYSelfTest(bool enabled);
- bool getAccelZSelfTest();
- void setAccelZSelfTest(bool enabled);
- uint8_t getFullScaleAccelRange();
- void setFullScaleAccelRange(uint8_t range);
- uint8_t getDHPFMode();
- void setDHPFMode(uint8_t mode);
-
- // FF_THR register
- uint8_t getFreefallDetectionThreshold();
- void setFreefallDetectionThreshold(uint8_t threshold);
-
- // FF_DUR register
- uint8_t getFreefallDetectionDuration();
- void setFreefallDetectionDuration(uint8_t duration);
-
- // MOT_THR register
- uint8_t getMotionDetectionThreshold();
- void setMotionDetectionThreshold(uint8_t threshold);
-
- // MOT_DUR register
- uint8_t getMotionDetectionDuration();
- void setMotionDetectionDuration(uint8_t duration);
-
- // ZRMOT_THR register
- uint8_t getZeroMotionDetectionThreshold();
- void setZeroMotionDetectionThreshold(uint8_t threshold);
-
- // ZRMOT_DUR register
- uint8_t getZeroMotionDetectionDuration();
- void setZeroMotionDetectionDuration(uint8_t duration);
-
- // FIFO_EN register
- bool getTempFIFOEnabled();
- void setTempFIFOEnabled(bool enabled);
- bool getXGyroFIFOEnabled();
- void setXGyroFIFOEnabled(bool enabled);
- bool getYGyroFIFOEnabled();
- void setYGyroFIFOEnabled(bool enabled);
- bool getZGyroFIFOEnabled();
- void setZGyroFIFOEnabled(bool enabled);
- bool getAccelFIFOEnabled();
- void setAccelFIFOEnabled(bool enabled);
- bool getSlave2FIFOEnabled();
- void setSlave2FIFOEnabled(bool enabled);
- bool getSlave1FIFOEnabled();
- void setSlave1FIFOEnabled(bool enabled);
- bool getSlave0FIFOEnabled();
- void setSlave0FIFOEnabled(bool enabled);
-
- // I2C_MST_CTRL register
- bool getMultiMasterEnabled();
- void setMultiMasterEnabled(bool enabled);
- bool getWaitForExternalSensorEnabled();
- void setWaitForExternalSensorEnabled(bool enabled);
- bool getSlave3FIFOEnabled();
- void setSlave3FIFOEnabled(bool enabled);
- bool getSlaveReadWriteTransitionEnabled();
- void setSlaveReadWriteTransitionEnabled(bool enabled);
- uint8_t getMasterClockSpeed();
- void setMasterClockSpeed(uint8_t speed);
-
- // I2C_SLV* registers (Slave 0-3)
- uint8_t getSlaveAddress(uint8_t num);
- void setSlaveAddress(uint8_t num, uint8_t address);
- uint8_t getSlaveRegister(uint8_t num);
- void setSlaveRegister(uint8_t num, uint8_t reg);
- bool getSlaveEnabled(uint8_t num);
- void setSlaveEnabled(uint8_t num, bool enabled);
- bool getSlaveWordByteSwap(uint8_t num);
- void setSlaveWordByteSwap(uint8_t num, bool enabled);
- bool getSlaveWriteMode(uint8_t num);
- void setSlaveWriteMode(uint8_t num, bool mode);
- bool getSlaveWordGroupOffset(uint8_t num);
- void setSlaveWordGroupOffset(uint8_t num, bool enabled);
- uint8_t getSlaveDataLength(uint8_t num);
- void setSlaveDataLength(uint8_t num, uint8_t length);
-
- // I2C_SLV* registers (Slave 4)
- uint8_t getSlave4Address();
- void setSlave4Address(uint8_t address);
- uint8_t getSlave4Register();
- void setSlave4Register(uint8_t reg);
- void setSlave4OutputByte(uint8_t data);
- bool getSlave4Enabled();
- void setSlave4Enabled(bool enabled);
- bool getSlave4InterruptEnabled();
- void setSlave4InterruptEnabled(bool enabled);
- bool getSlave4WriteMode();
- void setSlave4WriteMode(bool mode);
- uint8_t getSlave4MasterDelay();
- void setSlave4MasterDelay(uint8_t delay);
- uint8_t getSlate4InputByte();
-
- // I2C_MST_STATUS register
- bool getPassthroughStatus();
- bool getSlave4IsDone();
- bool getLostArbitration();
- bool getSlave4Nack();
- bool getSlave3Nack();
- bool getSlave2Nack();
- bool getSlave1Nack();
- bool getSlave0Nack();
-
- // INT_PIN_CFG register
- bool getInterruptMode();
- void setInterruptMode(bool mode);
- bool getInterruptDrive();
- void setInterruptDrive(bool drive);
- bool getInterruptLatch();
- void setInterruptLatch(bool latch);
- bool getInterruptLatchClear();
- void setInterruptLatchClear(bool clear);
- bool getFSyncInterruptLevel();
- void setFSyncInterruptLevel(bool level);
- bool getFSyncInterruptEnabled();
- void setFSyncInterruptEnabled(bool enabled);
- bool getI2CBypassEnabled();
- void setI2CBypassEnabled(bool enabled);
- bool getClockOutputEnabled();
- void setClockOutputEnabled(bool enabled);
-
- // INT_ENABLE register
- uint8_t getIntEnabled();
- void setIntEnabled(uint8_t enabled);
- bool getIntFreefallEnabled();
- void setIntFreefallEnabled(bool enabled);
- bool getIntMotionEnabled();
- void setIntMotionEnabled(bool enabled);
- bool getIntZeroMotionEnabled();
- void setIntZeroMotionEnabled(bool enabled);
- bool getIntFIFOBufferOverflowEnabled();
- void setIntFIFOBufferOverflowEnabled(bool enabled);
- bool getIntI2CMasterEnabled();
- void setIntI2CMasterEnabled(bool enabled);
- bool getIntDataReadyEnabled();
- void setIntDataReadyEnabled(bool enabled);
-
- // INT_STATUS register
- uint8_t getIntStatus();
- bool getIntFreefallStatus();
- bool getIntMotionStatus();
- bool getIntZeroMotionStatus();
- bool getIntFIFOBufferOverflowStatus();
- bool getIntI2CMasterStatus();
- bool getIntDataReadyStatus();
-
- // ACCEL_*OUT_* registers
- void getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz);
- void getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz);
- void getAcceleration(int16_t* x, int16_t* y, int16_t* z);
- int16_t getAccelerationX();
- int16_t getAccelerationY();
- int16_t getAccelerationZ();
-
- // TEMP_OUT_* registers
- int16_t getTemperature();
-
- // GYRO_*OUT_* registers
- void getRotation(int16_t* x, int16_t* y, int16_t* z);
- int16_t getRotationX();
- int16_t getRotationY();
- int16_t getRotationZ();
-
- // EXT_SENS_DATA_* registers
- uint8_t getExternalSensorByte(int position);
- uint16_t getExternalSensorWord(int position);
- uint32_t getExternalSensorDWord(int position);
-
- // MOT_DETECT_STATUS register
- uint8_t getMotionStatus();
- bool getXNegMotionDetected();
- bool getXPosMotionDetected();
- bool getYNegMotionDetected();
- bool getYPosMotionDetected();
- bool getZNegMotionDetected();
- bool getZPosMotionDetected();
- bool getZeroMotionDetected();
-
- // I2C_SLV*_DO register
- void setSlaveOutputByte(uint8_t num, uint8_t data);
-
- // I2C_MST_DELAY_CTRL register
- bool getExternalShadowDelayEnabled();
- void setExternalShadowDelayEnabled(bool enabled);
- bool getSlaveDelayEnabled(uint8_t num);
- void setSlaveDelayEnabled(uint8_t num, bool enabled);
-
- // SIGNAL_PATH_RESET register
- void resetGyroscopePath();
- void resetAccelerometerPath();
- void resetTemperaturePath();
-
- // MOT_DETECT_CTRL register
- uint8_t getAccelerometerPowerOnDelay();
- void setAccelerometerPowerOnDelay(uint8_t delay);
- uint8_t getFreefallDetectionCounterDecrement();
- void setFreefallDetectionCounterDecrement(uint8_t decrement);
- uint8_t getMotionDetectionCounterDecrement();
- void setMotionDetectionCounterDecrement(uint8_t decrement);
-
- // USER_CTRL register
- bool getFIFOEnabled();
- void setFIFOEnabled(bool enabled);
- bool getI2CMasterModeEnabled();
- void setI2CMasterModeEnabled(bool enabled);
- void switchSPIEnabled(bool enabled);
- void resetFIFO();
- void resetI2CMaster();
- void resetSensors();
-
- // PWR_MGMT_1 register
- void reset();
- bool getSleepEnabled();
- void setSleepEnabled(bool enabled);
- bool getWakeCycleEnabled();
- void setWakeCycleEnabled(bool enabled);
- bool getTempSensorEnabled();
- void setTempSensorEnabled(bool enabled);
- uint8_t getClockSource();
- void setClockSource(uint8_t source);
-
- // PWR_MGMT_2 register
- uint8_t getWakeFrequency();
- void setWakeFrequency(uint8_t frequency);
- bool getStandbyXAccelEnabled();
- void setStandbyXAccelEnabled(bool enabled);
- bool getStandbyYAccelEnabled();
- void setStandbyYAccelEnabled(bool enabled);
- bool getStandbyZAccelEnabled();
- void setStandbyZAccelEnabled(bool enabled);
- bool getStandbyXGyroEnabled();
- void setStandbyXGyroEnabled(bool enabled);
- bool getStandbyYGyroEnabled();
- void setStandbyYGyroEnabled(bool enabled);
- bool getStandbyZGyroEnabled();
- void setStandbyZGyroEnabled(bool enabled);
-
- // FIFO_COUNT_* registers
- uint16_t getFIFOCount();
-
- // FIFO_R_W register
- uint8_t getFIFOByte();
- void setFIFOByte(uint8_t data);
- void getFIFOBytes(uint8_t *data, uint8_t length);
-
- // 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);
- int8_t getXGyroOffsetTC();
- void setXGyroOffsetTC(int8_t offset);
-
- // YG_OFFS_TC register
- int8_t getYGyroOffsetTC();
- void setYGyroOffsetTC(int8_t offset);
-
- // ZG_OFFS_TC register
- int8_t getZGyroOffsetTC();
- void setZGyroOffsetTC(int8_t offset);
-
- // X_FINE_GAIN register
- int8_t getXFineGain();
- void setXFineGain(int8_t gain);
-
- // Y_FINE_GAIN register
- int8_t getYFineGain();
- void setYFineGain(int8_t gain);
-
- // Z_FINE_GAIN register
- int8_t getZFineGain();
- void setZFineGain(int8_t gain);
-
- // XA_OFFS_* registers
- int16_t getXAccelOffset();
- void setXAccelOffset(int16_t offset);
-
- // YA_OFFS_* register
- int16_t getYAccelOffset();
- void setYAccelOffset(int16_t offset);
-
- // ZA_OFFS_* register
- int16_t getZAccelOffset();
- void setZAccelOffset(int16_t offset);
-
- // XG_OFFS_USR* registers
- int16_t getXGyroOffset();
- void setXGyroOffset(int16_t offset);
-
- // YG_OFFS_USR* register
- int16_t getYGyroOffset();
- void setYGyroOffset(int16_t offset);
-
- // 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();
- bool getDMPInt3Status();
- bool getDMPInt2Status();
- bool getDMPInt1Status();
- bool getDMPInt0Status();
-
- // 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);
- void readMemoryBlock(uint8_t *data, uint16_t dataSize, uint8_t bank=0, uint8_t address=0);
- bool writeMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank=0, uint8_t address=0, bool verify=true, bool useProgMem=false);
- bool writeProgMemoryBlock(const uint8_t *data, uint16_t dataSize, uint8_t bank=0, uint8_t address=0, bool verify=true);
-
- bool writeDMPConfigurationSet(const uint8_t *data, uint16_t dataSize, bool useProgMem=false);
- bool writeProgDMPConfigurationSet(const uint8_t *data, uint16_t dataSize);
-
- // DMP_CFG_1 register
- uint8_t getDMPConfig1();
- void setDMPConfig1(uint8_t config);
-
- // DMP_CFG_2 register
- uint8_t getDMPConfig2();
- void setDMPConfig2(uint8_t config);
-
- // Calibration Routines
- void CalibrateGyro(uint8_t Loops = 15); // Fine tune after setting offsets with less Loops.
- void CalibrateAccel(uint8_t Loops = 15);// Fine tune after setting offsets with less Loops.
- void PID(uint8_t ReadAddress, float kP,float kI, uint8_t Loops); // Does the math
- void PrintActiveOffsets(); // See the results of the Calibration
-
-
-
- // special methods for MotionApps 2.0 implementation
- #ifdef MPU6050_INCLUDE_DMP_MOTIONAPPS20
-
- uint8_t dmpInitialize();
- bool dmpPacketAvailable();
-
- uint8_t dmpSetFIFORate(uint8_t fifoRate);
- uint8_t dmpGetFIFORate();
- 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);
- uint8_t dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendPacketNumber(uint_fast16_t accuracy);
- uint8_t dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy);
-
- // Get Fixed Point data from FIFO
- uint8_t dmpGetAccel(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetAccel(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetAccel(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetQuaternion(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetQuaternion(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetQuaternion(Quaternion *q, const uint8_t* packet=0);
- uint8_t dmpGet6AxisQuaternion(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGet6AxisQuaternion(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGet6AxisQuaternion(Quaternion *q, const uint8_t* packet=0);
- uint8_t dmpGetRelativeQuaternion(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetRelativeQuaternion(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetRelativeQuaternion(Quaternion *data, const uint8_t* packet=0);
- uint8_t dmpGetGyro(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyro(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyro(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpSetLinearAccelFilterCoefficient(float coef);
- uint8_t dmpGetLinearAccel(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccel(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccel(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity);
- uint8_t dmpGetLinearAccelInWorld(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccelInWorld(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccelInWorld(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q);
- uint8_t dmpGetGyroAndAccelSensor(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyroAndAccelSensor(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyroAndAccelSensor(VectorInt16 *g, VectorInt16 *a, const uint8_t* packet=0);
- uint8_t dmpGetGyroSensor(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyroSensor(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyroSensor(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetControlData(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetTemperature(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGravity(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGravity(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGravity(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetGravity(VectorFloat *v, Quaternion *q);
- uint8_t dmpGetUnquantizedAccel(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetUnquantizedAccel(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetUnquantizedAccel(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetQuantizedAccel(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetQuantizedAccel(int16_t *data, const uint8_t* packet=0);
- 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);
-
- // Get Floating Point data from FIFO
- uint8_t dmpGetAccelFloat(float *data, const uint8_t* packet=0);
- uint8_t dmpGetQuaternionFloat(float *data, const uint8_t* packet=0);
-
- uint8_t dmpProcessFIFOPacket(const unsigned char *dmpData);
- uint8_t dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed=NULL);
-
- uint8_t dmpSetFIFOProcessedCallback(void (*func) (void));
-
- uint8_t dmpInitFIFOParam();
- uint8_t dmpCloseFIFO();
- uint8_t dmpSetGyroDataSource(uint8_t source);
- uint8_t dmpDecodeQuantizedAccel();
- uint32_t dmpGetGyroSumOfSquare();
- uint32_t dmpGetAccelSumOfSquare();
- void dmpOverrideQuaternion(long *q);
- uint16_t dmpGetFIFOPacketSize();
- #endif
-
- // special methods for MotionApps 4.1 implementation
- #ifdef MPU6050_INCLUDE_DMP_MOTIONAPPS41
-
- uint8_t dmpInitialize();
- bool dmpPacketAvailable();
-
- uint8_t dmpSetFIFORate(uint8_t fifoRate);
- uint8_t dmpGetFIFORate();
- 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);
- uint8_t dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendPacketNumber(uint_fast16_t accuracy);
- uint8_t dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy);
- uint8_t dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy);
-
- // Get Fixed Point data from FIFO
- uint8_t dmpGetAccel(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetAccel(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetAccel(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetQuaternion(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetQuaternion(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetQuaternion(Quaternion *q, const uint8_t* packet=0);
- uint8_t dmpGet6AxisQuaternion(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGet6AxisQuaternion(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGet6AxisQuaternion(Quaternion *q, const uint8_t* packet=0);
- uint8_t dmpGetRelativeQuaternion(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetRelativeQuaternion(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetRelativeQuaternion(Quaternion *data, const uint8_t* packet=0);
- uint8_t dmpGetGyro(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyro(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyro(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetMag(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpSetLinearAccelFilterCoefficient(float coef);
- uint8_t dmpGetLinearAccel(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccel(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccel(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity);
- uint8_t dmpGetLinearAccelInWorld(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccelInWorld(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccelInWorld(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q);
- uint8_t dmpGetGyroAndAccelSensor(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyroAndAccelSensor(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyroAndAccelSensor(VectorInt16 *g, VectorInt16 *a, const uint8_t* packet=0);
- uint8_t dmpGetGyroSensor(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyroSensor(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGyroSensor(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetControlData(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetTemperature(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGravity(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGravity(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetGravity(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetGravity(VectorFloat *v, Quaternion *q);
- uint8_t dmpGetUnquantizedAccel(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetUnquantizedAccel(int16_t *data, const uint8_t* packet=0);
- uint8_t dmpGetUnquantizedAccel(VectorInt16 *v, const uint8_t* packet=0);
- uint8_t dmpGetQuantizedAccel(int32_t *data, const uint8_t* packet=0);
- uint8_t dmpGetQuantizedAccel(int16_t *data, const uint8_t* packet=0);
- 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);
-
- // Get Floating Point data from FIFO
- uint8_t dmpGetAccelFloat(float *data, const uint8_t* packet=0);
- uint8_t dmpGetQuaternionFloat(float *data, const uint8_t* packet=0);
-
- uint8_t dmpProcessFIFOPacket(const unsigned char *dmpData);
- uint8_t dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed=NULL);
-
- uint8_t dmpSetFIFOProcessedCallback(void (*func) (void));
-
- uint8_t dmpInitFIFOParam();
- uint8_t dmpCloseFIFO();
- uint8_t dmpSetGyroDataSource(uint8_t source);
- uint8_t dmpDecodeQuantizedAccel();
- uint32_t dmpGetGyroSumOfSquare();
- uint32_t dmpGetAccelSumOfSquare();
- void dmpOverrideQuaternion(long *q);
- uint16_t dmpGetFIFOPacketSize();
- #endif
-
- private:
- uint8_t devAddr;
- uint8_t buffer[14];
- #if defined(MPU6050_INCLUDE_DMP_MOTIONAPPS20) or defined(MPU6050_INCLUDE_DMP_MOTIONAPPS41)
- uint8_t *dmpPacketBuffer;
- uint16_t dmpPacketSize;
- #endif
-};
-
-#endif /* _MPU6050_H_ */
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050_6Axis_MotionApps20.h b/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050_6Axis_MotionApps20.h
deleted file mode 100644
index 97dfdcbd..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050_6Axis_MotionApps20.h
+++ /dev/null
@@ -1,617 +0,0 @@
-// 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
-// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
-//
-// Changelog:
-// 2019/07/08 - merged all DMP Firmware configuration items into the dmpMemory array
-// - Simplified dmpInitialize() to accomidate the dmpmemory array alterations
-// ... - 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_
-
-#include "I2Cdev.h"
-#include "helper_3dmath.h"
-
-// MotionApps 2.0 DMP implementation, built using the MPU-6050EVB evaluation board
-#define MPU6050_INCLUDE_DMP_MOTIONAPPS20
-
-#include "MPU6050.h"
-
-// Tom Carpenter's conditional PROGMEM code
-// http://forum.arduino.cc/index.php?topic=129407.0
-#ifdef __AVR__
- #include
-#elif defined(ESP8266) || defined(ESP32)
- #include
-#else
- // Teensy 3.0 library conditional PROGMEM code from Paul Stoffregen
- #ifndef __PGMSPACE_H_
- #define __PGMSPACE_H_ 1
- #include
-
- #define PROGMEM
- #define PGM_P const char *
- #define PSTR(str) (str)
- #define F(x) x
-
- typedef void prog_void;
- typedef char prog_char;
- typedef unsigned char prog_uchar;
- typedef int8_t prog_int8_t;
- typedef uint8_t prog_uint8_t;
- typedef int16_t prog_int16_t;
- 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)
- #define pgm_read_float_near(addr) pgm_read_float(addr)
- #define pgm_read_byte_far(addr) pgm_read_byte(addr)
- #define pgm_read_word_far(addr) pgm_read_word(addr)
- #define pgm_read_dword_far(addr) pgm_read_dword(addr)
- #define pgm_read_float_far(addr) pgm_read_float(addr)
- #endif
-#endif
-
-/* Source is from the InvenSense MotionApps v2 demo code. Original source is
- * unavailable, unless you happen to be amazing as decompiling binary by
- * hand (in which case, please contact me, and I'm totally serious).
- *
- * Also, I'd like to offer many, many thanks to Noah Zerkin for all of the
- * DMP reverse-engineering he did to help make this bit of wizardry
- * possible.
- */
-
-// NOTE! Enabling DEBUG adds about 3.3kB to the flash program size.
-// Debug output is now working even on ATMega328P MCUs (e.g. Arduino Uno)
-// after moving string constants to flash memory storage using the F()
-// compiler macro (Arduino IDE 1.0+ required).
-
-//#define DEBUG
-#ifdef DEBUG
- #define DEBUG_PRINT(x) Serial.print(x)
- #define DEBUG_PRINTF(x, y) Serial.print(x, y)
- #define DEBUG_PRINTLN(x) Serial.println(x)
- #define DEBUG_PRINTLNF(x, y) Serial.println(x, y)
-#else
- #define DEBUG_PRINT(x)
- #define DEBUG_PRINTF(x, y)
- #define DEBUG_PRINTLN(x)
- #define DEBUG_PRINTLNF(x, y)
-#endif
-
-#define MPU6050_DMP_CODE_SIZE 1929 // dmpMemory[]
-#define MPU6050_DMP_CONFIG_SIZE 192 // dmpConfig[]
-#define MPU6050_DMP_UPDATES_SIZE 47 // dmpUpdates[]
-
-/* ================================================================================================ *
- | Default MotionApps v2.0 42-byte FIFO packet structure: |
- | |
- | [QUAT W][ ][QUAT X][ ][QUAT Y][ ][QUAT Z][ ][GYRO X][ ][GYRO Y][ ] |
- | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
- | |
- | [GYRO Z][ ][ACC X ][ ][ACC Y ][ ][ACC Z ][ ][ ] |
- | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
- * ================================================================================================ */
-
-// this block of memory gets written to the MPU on start-up, and it seems
-// to be volatile memory, so it has to be done each time (it only takes ~1
-// second though)
-
-// I Only Changed this by applying all the configuration data and capturing it before startup:
-// *** this is a capture of the DMP Firmware after all the messy changes were made so we can just load it
-const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = {
- /* bank # 0 */
- 0xFB, 0x00, 0x00, 0x3E, 0x00, 0x0B, 0x00, 0x36, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
- 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0xFA, 0x80, 0x00, 0x0B, 0x12, 0x82, 0x00, 0x01,
- 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x28, 0x00, 0x00, 0xFF, 0xFF, 0x45, 0x81, 0xFF, 0xFF, 0xFA, 0x72, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x03, 0xE8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7F, 0xFF, 0xFF, 0xFE, 0x80, 0x01,
- 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x40, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x02, 0xCB, 0x47, 0xA2, 0x20, 0x00, 0x00, 0x00,
- 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
- 0x41, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x2A, 0x00, 0x00, 0x16, 0x55, 0x00, 0x00, 0x21, 0x82,
- 0xFD, 0x87, 0x26, 0x50, 0xFD, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x05, 0x80, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
- 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x02, 0x65, 0x32, 0x00, 0x00, 0x5E, 0xC0,
- 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFB, 0x8C, 0x6F, 0x5D, 0xFD, 0x5D, 0x08, 0xD9, 0x00, 0x7C, 0x73, 0x3B, 0x00, 0x6C, 0x12, 0xCC,
- 0x32, 0x00, 0x13, 0x9D, 0x32, 0x00, 0xD0, 0xD6, 0x32, 0x00, 0x08, 0x00, 0x40, 0x00, 0x01, 0xF4,
- 0xFF, 0xE6, 0x80, 0x79, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xD6, 0x00, 0x00, 0x27, 0x10,
- /* bank # 1 */
- 0xFB, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xFA, 0x36, 0xFF, 0xBC, 0x30, 0x8E, 0x00, 0x05, 0xFB, 0xF0, 0xFF, 0xD9, 0x5B, 0xC8,
- 0xFF, 0xD0, 0x9A, 0xBE, 0x00, 0x00, 0x10, 0xA9, 0xFF, 0xF4, 0x1E, 0xB2, 0x00, 0xCE, 0xBB, 0xF7,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x0C,
- 0xFF, 0xC2, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0xCF, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x09, 0x23, 0xA1, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x03, 0x3F, 0x68, 0xB6, 0x79, 0x35, 0x28, 0xBC, 0xC6, 0x7E, 0xD1, 0x6C,
- 0x80, 0x00, 0xFF, 0xFF, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2, 0x6A, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x30,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
- 0x00, 0x00, 0x25, 0x4D, 0x00, 0x2F, 0x70, 0x6D, 0x00, 0x00, 0x05, 0xAE, 0x00, 0x0C, 0x02, 0xD0,
- /* bank # 2 */
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x00, 0x01, 0x00, 0x05, 0x8B, 0xC1, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0xFF, 0xEF, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- /* bank # 3 */
- 0xD8, 0xDC, 0xBA, 0xA2, 0xF1, 0xDE, 0xB2, 0xB8, 0xB4, 0xA8, 0x81, 0x91, 0xF7, 0x4A, 0x90, 0x7F,
- 0x91, 0x6A, 0xF3, 0xF9, 0xDB, 0xA8, 0xF9, 0xB0, 0xBA, 0xA0, 0x80, 0xF2, 0xCE, 0x81, 0xF3, 0xC2,
- 0xF1, 0xC1, 0xF2, 0xC3, 0xF3, 0xCC, 0xA2, 0xB2, 0x80, 0xF1, 0xC6, 0xD8, 0x80, 0xBA, 0xA7, 0xDF,
- 0xDF, 0xDF, 0xF2, 0xA7, 0xC3, 0xCB, 0xC5, 0xB6, 0xF0, 0x87, 0xA2, 0x94, 0x24, 0x48, 0x70, 0x3C,
- 0x95, 0x40, 0x68, 0x34, 0x58, 0x9B, 0x78, 0xA2, 0xF1, 0x83, 0x92, 0x2D, 0x55, 0x7D, 0xD8, 0xB1,
- 0xB4, 0xB8, 0xA1, 0xD0, 0x91, 0x80, 0xF2, 0x70, 0xF3, 0x70, 0xF2, 0x7C, 0x80, 0xA8, 0xF1, 0x01,
- 0xB0, 0x98, 0x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-
-#ifndef MPU6050_DMP_FIFO_RATE_DIVISOR
-#define MPU6050_DMP_FIFO_RATE_DIVISOR 0x01 // The New instance of the Firmware has this as the default
-#endif
-
-// I Simplified this:
-uint8_t MPU6050::dmpInitialize() {
- // reset device
- DEBUG_PRINTLN(F("\n\nResetting MPU6050..."));
- reset();
- delay(30); // wait after reset
-
- // enable sleep mode and wake cycle
- /*Serial.println(F("Enabling sleep mode..."));
- setSleepEnabled(true);
- Serial.println(F("Enabling wake cycle..."));
- setWakeCycleEnabled(true);*/
-
- // disable sleep mode
- setSleepEnabled(false);
-
- // get MPU hardware revision
- setMemoryBank(0x10, true, true);
- setMemoryStartAddress(0x06);
- Serial.println(F("Checking hardware revision..."));
- Serial.print(F("Revision @ user[16][6] = "));
- Serial.println(readMemoryByte(), HEX);
- Serial.println(F("Resetting memory bank selection to 0..."));
- setMemoryBank(0, false, false);
-
- // check OTP bank valid
- DEBUG_PRINTLN(F("Reading OTP bank valid flag..."));
- DEBUG_PRINT(F("OTP bank is "));
- DEBUG_PRINTLN(getOTPBankValid() ? F("valid!") : F("invalid!"));
-
- // setup weird slave stuff (?)
- DEBUG_PRINTLN(F("Setting slave 0 address to 0x7F..."));
- setSlaveAddress(0, 0x7F);
- DEBUG_PRINTLN(F("Disabling I2C Master mode..."));
- setI2CMasterModeEnabled(false);
- DEBUG_PRINTLN(F("Setting slave 0 address to 0x68 (self)..."));
- setSlaveAddress(0, 0x68);
- DEBUG_PRINTLN(F("Resetting I2C Master control..."));
- resetI2CMaster();
- delay(20);
- DEBUG_PRINTLN(F("Setting clock source to Z Gyro..."));
- setClockSource(MPU6050_CLOCK_PLL_ZGYRO);
-
- DEBUG_PRINTLN(F("Setting DMP and FIFO_OFLOW interrupts enabled..."));
- setIntEnabled(1<= dmpGetFIFOPacketSize();
-}
-
-// uint8_t MPU6050::dmpSetFIFORate(uint8_t fifoRate);
-// uint8_t MPU6050::dmpGetFIFORate();
-// uint8_t MPU6050::dmpGetSampleStepSizeMS();
-// uint8_t MPU6050::dmpGetSampleFrequency();
-// int32_t MPU6050::dmpDecodeTemperature(int8_t tempReg);
-
-//uint8_t MPU6050::dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority);
-//uint8_t MPU6050::dmpUnregisterFIFORateProcess(inv_obj_func func);
-//uint8_t MPU6050::dmpRunFIFORateProcesses();
-
-// uint8_t MPU6050::dmpSendQuaternion(uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendPacketNumber(uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy);
-
-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] = (((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];
- 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];
- 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] = (((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]);
- return 0;
-}
-uint8_t MPU6050::dmpGetQuaternion(Quaternion *q, const uint8_t* packet) {
- // TODO: accommodate different arrangements of sent data (ONLY default supported now)
- int16_t qI[4];
- uint8_t status = dmpGetQuaternion(qI, packet);
- if (status == 0) {
- q -> w = (float)qI[0] / 16384.0f;
- q -> x = (float)qI[1] / 16384.0f;
- q -> y = (float)qI[2] / 16384.0f;
- q -> z = (float)qI[3] / 16384.0f;
- return 0;
- }
- return status; // int16 return value, indicates error if this line is reached
-}
-// uint8_t MPU6050::dmpGet6AxisQuaternion(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetRelativeQuaternion(long *data, const uint8_t* packet);
-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] = (((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];
- 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];
- return 0;
-}
-// uint8_t MPU6050::dmpSetLinearAccelFilterCoefficient(float coef);
-// uint8_t MPU6050::dmpGetLinearAccel(long *data, const uint8_t* packet);
-uint8_t MPU6050::dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity) {
- // get rid of the gravity component (+1g = +8192 in standard DMP FIFO packet, sensitivity is 2g)
- v -> x = vRaw -> x - gravity -> x*8192;
- v -> y = vRaw -> y - gravity -> y*8192;
- v -> z = vRaw -> z - gravity -> z*8192;
- return 0;
-}
-// uint8_t MPU6050::dmpGetLinearAccelInWorld(long *data, const uint8_t* packet);
-uint8_t MPU6050::dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q) {
- // rotate measured 3D acceleration vector into original state
- // frame of reference based on orientation quaternion
- memcpy(v, vReal, sizeof(VectorInt16));
- v -> rotate(q);
- return 0;
-}
-// uint8_t MPU6050::dmpGetGyroAndAccelSensor(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetGyroSensor(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetControlData(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetTemperature(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetGravity(long *data, const uint8_t* packet);
-uint8_t MPU6050::dmpGetGravity(int16_t *data, const uint8_t* packet) {
- /* +1g corresponds to +8192, sensitivity is 2g. */
- int16_t qI[4];
- uint8_t status = dmpGetQuaternion(qI, packet);
- data[0] = ((int32_t)qI[1] * qI[3] - (int32_t)qI[0] * qI[2]) / 16384;
- data[1] = ((int32_t)qI[0] * qI[1] + (int32_t)qI[2] * qI[3]) / 16384;
- data[2] = ((int32_t)qI[0] * qI[0] - (int32_t)qI[1] * qI[1]
- - (int32_t)qI[2] * qI[2] + (int32_t)qI[3] * qI[3]) / (2 * 16384);
- return status;
-}
-
-uint8_t MPU6050::dmpGetGravity(VectorFloat *v, Quaternion *q) {
- v -> x = 2 * (q -> x*q -> z - q -> w*q -> y);
- v -> y = 2 * (q -> w*q -> x + q -> y*q -> z);
- v -> z = q -> w*q -> w - q -> x*q -> x - q -> y*q -> y + q -> z*q -> z;
- return 0;
-}
-// uint8_t MPU6050::dmpGetUnquantizedAccel(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetQuantizedAccel(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetExternalSensorData(long *data, int size, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetEIS(long *data, const uint8_t* packet);
-
-uint8_t MPU6050::dmpGetEuler(float *data, Quaternion *q) {
- data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); // psi
- data[1] = -asin(2*q -> x*q -> z + 2*q -> w*q -> y); // theta
- data[2] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> z*q -> z - 1); // phi
- return 0;
-}
-
-#ifdef USE_OLD_DMPGETYAWPITCHROLL
-uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
- // yaw: (about Z axis)
- data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
- // pitch: (nose up/down, about Y axis)
- data[1] = atan(gravity -> x / sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
- // roll: (tilt left/right, about X axis)
- data[2] = atan(gravity -> y / sqrt(gravity -> x*gravity -> x + gravity -> z*gravity -> z));
- return 0;
-}
-#else
-uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
- // yaw: (about Z axis)
- data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
- // pitch: (nose up/down, about Y axis)
- data[1] = atan2(gravity -> x , sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
- // roll: (tilt left/right, about X axis)
- data[2] = atan2(gravity -> y , gravity -> z);
- if (gravity -> z < 0) {
- if(data[1] > 0) {
- data[1] = PI - data[1];
- } else {
- data[1] = -PI - data[1];
- }
- }
- return 0;
-}
-#endif
-
-// uint8_t MPU6050::dmpGetAccelFloat(float *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetQuaternionFloat(float *data, const uint8_t* packet);
-
-uint8_t MPU6050::dmpProcessFIFOPacket(const unsigned char *dmpData) {
- /*for (uint8_t k = 0; k < dmpPacketSize; k++) {
- if (dmpData[k] < 0x10) Serial.print("0");
- Serial.print(dmpData[k], HEX);
- Serial.print(" ");
- }
- Serial.print("\n");*/
- //Serial.println((uint16_t)dmpPacketBuffer);
- return 0;
-}
-uint8_t MPU6050::dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed) {
- uint8_t status;
- uint8_t buf[dmpPacketSize];
- for (uint8_t i = 0; i < numPackets; i++) {
- // read packet from FIFO
- getFIFOBytes(buf, dmpPacketSize);
-
- // process packet
- if ((status = dmpProcessFIFOPacket(buf)) > 0) return status;
-
- // increment external process count variable, if supplied
- if (processed != 0) (*processed)++;
- }
- return 0;
-}
-
-// uint8_t MPU6050::dmpSetFIFOProcessedCallback(void (*func) (void));
-
-// uint8_t MPU6050::dmpInitFIFOParam();
-// uint8_t MPU6050::dmpCloseFIFO();
-// uint8_t MPU6050::dmpSetGyroDataSource(uint_fast8_t source);
-// uint8_t MPU6050::dmpDecodeQuantizedAccel();
-// uint32_t MPU6050::dmpGetGyroSumOfSquare();
-// uint32_t MPU6050::dmpGetAccelSumOfSquare();
-// void MPU6050::dmpOverrideQuaternion(long *q);
-uint16_t MPU6050::dmpGetFIFOPacketSize() {
- return dmpPacketSize;
-}
-
-#endif /* _MPU6050_6AXIS_MOTIONAPPS20_H_ */
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050_6Axis_MotionApps_V6_12.h b/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050_6Axis_MotionApps_V6_12.h
deleted file mode 100644
index 34a4ccc5..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050_6Axis_MotionApps_V6_12.h
+++ /dev/null
@@ -1,617 +0,0 @@
-// I2Cdev library collection - MPU6050 I2C device class, 6-axis MotionApps 6.12 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
-// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
-//
-// Changelog:
-// 2019/7/10 - I incorporated DMP Firmware Version 6.12 Latest as of today with many features and bug fixes.
-// - MPU6050 Registers have not changed just the DMP Image so that full backwards compatibility is present
-// - Run-time calibration routine is enabled which calibrates after no motion state is detected
-// - once no motion state is detected Calibration completes within 0.5 seconds
-// - The Drawback is that the firmware image is larger.
-// ... - 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_
-
-#include "I2Cdev.h"
-#include "helper_3dmath.h"
-
-// MotionApps 2.0 DMP implementation, built using the MPU-6050EVB evaluation board
-#define MPU6050_INCLUDE_DMP_MOTIONAPPS20 // same definitions Should work with V6.12
-
-#include "MPU6050.h"
-
-// Tom Carpenter's conditional PROGMEM code
-// http://forum.arduino.cc/index.php?topic=129407.0
-#ifdef __AVR__
- #include
-#elif defined(ESP8266) || defined(ESP32)
- #include
-#else
- // Teensy 3.0 library conditional PROGMEM code from Paul Stoffregen
- #ifndef __PGMSPACE_H_
- #define __PGMSPACE_H_ 1
- #include
-
- #define PROGMEM
- #define PGM_P const char *
- #define PSTR(str) (str)
- #define F(x) x
-
- typedef void prog_void;
- typedef char prog_char;
- typedef unsigned char prog_uchar;
- typedef int8_t prog_int8_t;
- typedef uint8_t prog_uint8_t;
- typedef int16_t prog_int16_t;
- 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)
- #define pgm_read_float_near(addr) pgm_read_float(addr)
- #define pgm_read_byte_far(addr) pgm_read_byte(addr)
- #define pgm_read_word_far(addr) pgm_read_word(addr)
- #define pgm_read_dword_far(addr) pgm_read_dword(addr)
- #define pgm_read_float_far(addr) pgm_read_float(addr)
- #endif
-#endif
-
-/* Source is from the InvenSense MotionApps v2 demo code. Original source is
- * unavailable, unless you happen to be amazing as decompiling binary by
- * hand (in which case, please contact me, and I'm totally serious).
- *
- * Also, I'd like to offer many, many thanks to Noah Zerkin for all of the
- * DMP reverse-engineering he did to help make this bit of wizardry
- * possible.
- */
-
-// NOTE! Enabling DEBUG adds about 3.3kB to the flash program size.
-// Debug output is now working even on ATMega328P MCUs (e.g. Arduino Uno)
-// after moving string constants to flash memory storage using the F()
-// compiler macro (Arduino IDE 1.0+ required).
-
-//#define DEBUG
-#ifdef DEBUG
- #define DEBUG_PRINT(x) Serial.print(x)
- #define DEBUG_PRINTF(x, y) Serial.print(x, y)
- #define DEBUG_PRINTLN(x) Serial.println(x)
- #define DEBUG_PRINTLNF(x, y) Serial.println(x, y)
-#else
- #define DEBUG_PRINT(x)
- #define DEBUG_PRINTF(x, y)
- #define DEBUG_PRINTLN(x)
- #define DEBUG_PRINTLNF(x, y)
-#endif
-
-#define MPU6050_DMP_CODE_SIZE 3062 // dmpMemory[]
-
-/* ================================================================ *
- | Default MotionApps v6.12 28-byte FIFO packet structure: |
- | |
- | [QUAT W][ ][QUAT X][ ][QUAT Y][ ][QUAT Z][ ] |
- | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
- | |
- | [GYRO X][GYRO Y][GYRO Z][ACC X ][ACC Y ][ACC Z ] |
- | 16 17 18 19 20 21 22 23 24 25 26 27 |
- * ================================================================ */
-
-// this block of memory gets written to the MPU on start-up, and it seems
-// to be volatile memory, so it has to be done each time (it only takes ~1
-// second though)
-
-// *** this is a capture of the DMP Firmware V6.1.2 after all the messy changes were made so we can just load it
-const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = {
-/* bank # 0 */
-0x00, 0xF8, 0xF6, 0x2A, 0x3F, 0x68, 0xF5, 0x7A, 0x00, 0x06, 0xFF, 0xFE, 0x00, 0x03, 0x00, 0x00,
-0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0xFA, 0x80, 0x00, 0x0B, 0x12, 0x82, 0x00, 0x01,
-0x03, 0x0C, 0x30, 0xC3, 0x0A, 0x74, 0x56, 0x2D, 0x0D, 0x62, 0xDB, 0xC7, 0x16, 0xF4, 0xBA, 0x02,
-0x38, 0x83, 0xF8, 0x83, 0x30, 0x00, 0xF8, 0x83, 0x25, 0x8E, 0xF8, 0x83, 0x30, 0x00, 0xF8, 0x83,
-0xFF, 0xFF, 0xFF, 0xFF, 0x0C, 0xBD, 0xD8, 0x11, 0x24, 0x00, 0x04, 0x00, 0x1A, 0x82, 0x79, 0xA1,
-0x00, 0x36, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x38, 0x83, 0x6F, 0xA2,
-0x00, 0x3E, 0x03, 0x30, 0x40, 0x00, 0x00, 0x00, 0x02, 0xCA, 0xE3, 0x09, 0x3E, 0x80, 0x00, 0x00,
-0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
-0x1F, 0xA4, 0xE8, 0xE4, 0xFF, 0xF5, 0xDC, 0xB9, 0x00, 0x5B, 0x79, 0xCF, 0x1F, 0x3F, 0x78, 0x76,
-0x00, 0x86, 0x7C, 0x5A, 0x00, 0x86, 0x23, 0x47, 0xFA, 0xB9, 0x86, 0x31, 0x00, 0x74, 0x87, 0x8A,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x05, 0xFF, 0xFF, 0xE9, 0xA8, 0x00, 0x00, 0x21, 0x82,
-0xFA, 0xB8, 0x4D, 0x46, 0xFF, 0xFA, 0xDF, 0x3D, 0xFF, 0xFF, 0xB2, 0xB3, 0x00, 0x00, 0x00, 0x00,
-0x3F, 0xFF, 0xBA, 0x98, 0x00, 0x5D, 0xAC, 0x08, 0x00, 0x0A, 0x63, 0x78, 0x00, 0x01, 0x46, 0x21,
-0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x42, 0xB5, 0x00, 0x06, 0x00, 0x64, 0x00, 0x64, 0x00, 0x06,
-0x14, 0x06, 0x02, 0x9F, 0x0F, 0x47, 0x91, 0x32, 0xD9, 0x0E, 0x9F, 0xC9, 0x1D, 0xCF, 0x4C, 0x34,
-0x3B, 0xB6, 0x7A, 0xE8, 0x00, 0x64, 0x00, 0x06, 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFE,
-/* bank # 1 */
-0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x07, 0x00, 0x00, 0xFF, 0xF1, 0x00, 0x00, 0xFA, 0x46, 0x00, 0x00, 0xA2, 0xB8, 0x00, 0x00,
-0x10, 0x00, 0x00, 0x00, 0x04, 0xD6, 0x00, 0x00, 0x04, 0xCC, 0x00, 0x00, 0x04, 0xCC, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x06, 0x00, 0x02, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x05, 0x00, 0x64, 0x00, 0x20, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x03, 0x00,
-0x00, 0x00, 0x00, 0x32, 0xF8, 0x98, 0x00, 0x00, 0xFF, 0x65, 0x00, 0x00, 0x83, 0x0F, 0x00, 0x00,
-0x00, 0x06, 0x00, 0x00, 0xFF, 0xF1, 0x00, 0x00, 0xFA, 0x46, 0x00, 0x00, 0xA2, 0xB8, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
-0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0xB2, 0x6A, 0x00, 0x02, 0x00, 0x00,
-0x00, 0x01, 0xFB, 0x83, 0x00, 0x7C, 0x00, 0x00, 0xFB, 0x15, 0xFC, 0x00, 0x1F, 0xB4, 0xFF, 0x83,
-0x00, 0x00, 0x00, 0x01, 0x00, 0x65, 0x00, 0x07, 0x00, 0x64, 0x03, 0xE8, 0x00, 0x64, 0x00, 0x28,
-0x00, 0x00, 0xFF, 0xFD, 0x00, 0x00, 0x00, 0x00, 0x16, 0xA0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x10, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x01, 0xF4, 0x00, 0x00, 0x10, 0x00,
-/* bank # 2 */
-0x00, 0x28, 0x00, 0x00, 0xFF, 0xFF, 0x45, 0x81, 0xFF, 0xFF, 0xFA, 0x72, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x01, 0x00, 0x05, 0xBA, 0xC6, 0x00, 0x47, 0x78, 0xA2,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14,
-0x00, 0x00, 0x23, 0xBB, 0x00, 0x2E, 0xA2, 0x5B, 0x00, 0x00, 0x05, 0x68, 0x00, 0x0B, 0xCF, 0x49,
-0x00, 0x04, 0xFF, 0xFD, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x64, 0x00, 0x07, 0x00, 0x08, 0x00, 0x06, 0x00, 0x06, 0xFF, 0xFE, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x2E, 0xA2, 0x5B, 0x00, 0x00, 0x05, 0x68, 0x00, 0x0B, 0xCF, 0x49, 0x00, 0x00, 0x00, 0x00,
-0x00, 0xF8, 0xF6, 0x2A, 0x3F, 0x68, 0xF5, 0x7A, 0x00, 0x04, 0xFF, 0xFD, 0x00, 0x02, 0x00, 0x00,
-0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x0E,
-0xFF, 0xFF, 0xFF, 0xCF, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0xFF, 0xFF, 0xFF, 0x9C,
-0x00, 0x00, 0x43, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x64,
-0xFF, 0xE5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-/* bank # 3 */
-0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x24, 0x26, 0xD3,
-0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00, 0x96, 0x00, 0x3C,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x9E, 0x65, 0x5D,
-0x0C, 0x0A, 0x4E, 0x68, 0xCD, 0xCF, 0x77, 0x09, 0x50, 0x16, 0x67, 0x59, 0xC6, 0x19, 0xCE, 0x82,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x71, 0x1C,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0xD7, 0x84, 0x00, 0x03, 0x00, 0x00, 0x00,
-0x00, 0x11, 0xDC, 0x47, 0x03, 0x00, 0x00, 0x00, 0xC7, 0x93, 0x8F, 0x9D, 0x1E, 0x1B, 0x1C, 0x19,
-0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0E, 0xDF, 0xA4, 0x38, 0x1F, 0x9E, 0x65, 0x5D,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x71, 0x1C, 0x02, 0x03, 0x18, 0x85, 0x00, 0x00, 0x40, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x3F, 0xFF, 0xFF, 0xFD, 0xFF, 0xFF, 0xF4, 0xC9, 0xFF, 0xFF, 0xBC, 0xF0, 0x00, 0x01, 0x0C, 0x0F,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-0xF5, 0xB7, 0xBA, 0xB3, 0x67, 0x7D, 0xDF, 0x7E, 0x72, 0x90, 0x2E, 0x55, 0x4C, 0xF6, 0xE6, 0x88,
-0x00, 0x00, 0x00, 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0x31, 0x80, 0xDA, 0x2E, 0xD8, 0xA8, 0x86, 0x96, 0x31, 0x80, 0xDA, 0x2E, 0xD8, 0xA8,
-0x87, 0x31, 0x80, 0xDA, 0x2E, 0xD8, 0xA8, 0x82, 0x92, 0xF3, 0x41, 0x80, 0xF1, 0xD9, 0x2E, 0xD8,
-0xA8, 0x82, 0xF3, 0x19, 0x80, 0xF1, 0xD9, 0x2E, 0xD8, 0x82, 0xAC, 0xF3, 0xC0, 0xA2, 0x80, 0x22,
-0xF1, 0xA6, 0x2E, 0xA7, 0x2E, 0xA9, 0x22, 0x98, 0xA8, 0x29, 0xDA, 0xAC, 0xDE, 0xFF, 0xD8, 0xA2,
-0xF2, 0x2A, 0xF1, 0xA9, 0x2E, 0x82, 0x92, 0xA8, 0xF2, 0x31, 0x80, 0xA6, 0x96, 0xF1, 0xD9, 0x00,
-0xAC, 0x8C, 0x9C, 0x0C, 0x30, 0xAC, 0xDE, 0xD0, 0xDE, 0xFF, 0xD8, 0x8C, 0x9C, 0xAC, 0xD0, 0x10,
-0xAC, 0xDE, 0x80, 0x92, 0xA2, 0xF2, 0x4C, 0x82, 0xA8, 0xF1, 0xCA, 0xF2, 0x35, 0xF1, 0x96, 0x88,
-0xA6, 0xD9, 0x00, 0xD8, 0xF1, 0xFF,
-};
-
-// this divisor is pre configured into the above image and can't be modified at this time.
-#ifndef MPU6050_DMP_FIFO_RATE_DIVISOR
-#define MPU6050_DMP_FIFO_RATE_DIVISOR 0x01 // The New instance of the Firmware has this as the default
-#endif
-
-// this is the most basic initialization I can create. with the intent that we access the register bytes as few times as needed to get the job done.
-// for detailed descriptins of all registers and there purpose google "MPU-6000/MPU-6050 Register Map and Descriptions"
-uint8_t MPU6050::dmpInitialize() { // Lets get it over with fast Write everything once and set it up necely
- uint8_t val;
- uint16_t ival;
- // Reset procedure per instructions in the "MPU-6000/MPU-6050 Register Map and Descriptions" page 41
- I2Cdev::writeBit(devAddr,0x6B, 7, (val = 1)); //PWR_MGMT_1: reset with 100ms delay
- delay(100);
- I2Cdev::writeBits(devAddr,0x6A, 2, 3, (val = 0b111)); // full SIGNAL_PATH_RESET: with another 100ms delay
- delay(100);
- I2Cdev::writeBytes(devAddr,0x6B, 1, &(val = 0x01)); // 1000 0001 PWR_MGMT_1:Clock Source Select PLL_X_gyro
- I2Cdev::writeBytes(devAddr,0x38, 1, &(val = 0x00)); // 0000 0000 INT_ENABLE: no Interrupt
- I2Cdev::writeBytes(devAddr,0x23, 1, &(val = 0x00)); // 0000 0000 MPU FIFO_EN: (all off) Using DMP's FIFO instead
- I2Cdev::writeBytes(devAddr,0x1C, 1, &(val = 0x00)); // 0000 0000 ACCEL_CONFIG: 0 = Accel Full Scale Select: 2g
- I2Cdev::writeBytes(devAddr,0x37, 1, &(val = 0x80)); // 1001 0000 INT_PIN_CFG: ACTL The logic level for int pin is active low. and interrupt status bits are cleared on any read
- I2Cdev::writeBytes(devAddr,0x6B, 1, &(val = 0x01)); // 0000 0001 PWR_MGMT_1: Clock Source Select PLL_X_gyro
- I2Cdev::writeBytes(devAddr,0x19, 1, &(val = 0x04)); // 0000 0100 SMPLRT_DIV: Divides the internal sample rate 400Hz ( Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV))
- I2Cdev::writeBytes(devAddr,0x1A, 1, &(val = 0x01)); // 0000 0001 CONFIG: Digital Low Pass Filter (DLPF) Configuration 188HZ //Im betting this will be the beat
- if (!writeProgMemoryBlock(dmpMemory, MPU6050_DMP_CODE_SIZE)) return 1; // Loads the DMP image into the MPU6050 Memory // Should Never Fail
- I2Cdev::writeWords(devAddr, 0x70, 1, &(ival = 0x0400)); // DMP Program Start Address
- I2Cdev::writeBytes(devAddr,0x1B, 1, &(val = 0x18)); // 0001 1000 GYRO_CONFIG: 3 = +2000 Deg/sec
- I2Cdev::writeBytes(devAddr,0x6A, 1, &(val = 0xC0)); // 1100 1100 USER_CTRL: Enable Fifo and Reset Fifo
- I2Cdev::writeBytes(devAddr,0x38, 1, &(val = 0x02)); // 0000 0010 INT_ENABLE: RAW_DMP_INT_EN on
- I2Cdev::writeBit(devAddr,0x6A, 2, 1); // Reset FIFO one last time just for kicks. (MPUi2cWrite reads 0x6A first and only alters 1 bit and then saves the byte)
-
- setDMPEnabled(false); // disable DMP for compatibility with the MPU6050 library
-/*
- dmpPacketSize += 16;//DMP_FEATURE_6X_LP_QUAT
- dmpPacketSize += 6;//DMP_FEATURE_SEND_RAW_ACCEL
- dmpPacketSize += 6;//DMP_FEATURE_SEND_RAW_GYRO
-*/
- dmpPacketSize = 28;
- return 0;
-}
-
-bool MPU6050::dmpPacketAvailable() {
- return getFIFOCount() >= dmpGetFIFOPacketSize();
-}
-
-// uint8_t MPU6050::dmpSetFIFORate(uint8_t fifoRate);
-// uint8_t MPU6050::dmpGetFIFORate();
-// uint8_t MPU6050::dmpGetSampleStepSizeMS();
-// uint8_t MPU6050::dmpGetSampleFrequency();
-// int32_t MPU6050::dmpDecodeTemperature(int8_t tempReg);
-
-//uint8_t MPU6050::dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority);
-//uint8_t MPU6050::dmpUnregisterFIFORateProcess(inv_obj_func func);
-//uint8_t MPU6050::dmpRunFIFORateProcesses();
-
-// uint8_t MPU6050::dmpSendQuaternion(uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendPacketNumber(uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy);
-
-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] = (((uint32_t)packet[16] << 8) | packet[17]);
- data[1] = (((uint32_t)packet[18] << 8) | packet[19]);
- data[2] = (((uint32_t)packet[20] << 8) | packet[21]);
- 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[16] << 8) | packet[17];
- data[1] = (packet[18] << 8) | packet[19];
- data[2] = (packet[20] << 8) | packet[21];
- 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[16] << 8) | packet[17];
- v -> y = (packet[18] << 8) | packet[19];
- v -> z = (packet[20] << 8) | packet[21];
- 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] = (((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]);
- return 0;
-}
-uint8_t MPU6050::dmpGetQuaternion(Quaternion *q, const uint8_t* packet) {
- // TODO: accommodate different arrangements of sent data (ONLY default supported now)
- int16_t qI[4];
- uint8_t status = dmpGetQuaternion(qI, packet);
- if (status == 0) {
- q -> w = (float)qI[0] / 16384.0f;
- q -> x = (float)qI[1] / 16384.0f;
- q -> y = (float)qI[2] / 16384.0f;
- q -> z = (float)qI[3] / 16384.0f;
- return 0;
- }
- return status; // int16 return value, indicates error if this line is reached
-}
-// uint8_t MPU6050::dmpGet6AxisQuaternion(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetRelativeQuaternion(long *data, const uint8_t* packet);
-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] = (((uint32_t)packet[22] << 8) | packet[23]);
- data[1] = (((uint32_t)packet[24] << 8) | packet[25]);
- data[2] = (((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[22] << 8) | packet[23];
- data[1] = (packet[24] << 8) | packet[25];
- data[2] = (packet[26] << 8) | packet[27];
- 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[22] << 8) | packet[23];
- v -> y = (packet[24] << 8) | packet[25];
- v -> z = (packet[26] << 8) | packet[27];
- return 0;
-}
-// uint8_t MPU6050::dmpSetLinearAccelFilterCoefficient(float coef);
-// uint8_t MPU6050::dmpGetLinearAccel(long *data, const uint8_t* packet);
-uint8_t MPU6050::dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity) {
- // get rid of the gravity component (+1g = +8192 in standard DMP FIFO packet, sensitivity is 2g)
- v -> x = vRaw -> x - gravity -> x*8192;
- v -> y = vRaw -> y - gravity -> y*8192;
- v -> z = vRaw -> z - gravity -> z*8192;
- return 0;
-}
-// uint8_t MPU6050::dmpGetLinearAccelInWorld(long *data, const uint8_t* packet);
-uint8_t MPU6050::dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q) {
- // rotate measured 3D acceleration vector into original state
- // frame of reference based on orientation quaternion
- memcpy(v, vReal, sizeof(VectorInt16));
- v -> rotate(q);
- return 0;
-}
-// uint8_t MPU6050::dmpGetGyroAndAccelSensor(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetGyroSensor(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetControlData(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetTemperature(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetGravity(long *data, const uint8_t* packet);
-uint8_t MPU6050::dmpGetGravity(int16_t *data, const uint8_t* packet) {
- /* +1g corresponds to +8192, sensitivity is 2g. */
- int16_t qI[4];
- uint8_t status = dmpGetQuaternion(qI, packet);
- data[0] = ((int32_t)qI[1] * qI[3] - (int32_t)qI[0] * qI[2]) / 16384;
- data[1] = ((int32_t)qI[0] * qI[1] + (int32_t)qI[2] * qI[3]) / 16384;
- data[2] = ((int32_t)qI[0] * qI[0] - (int32_t)qI[1] * qI[1]
- - (int32_t)qI[2] * qI[2] + (int32_t)qI[3] * qI[3]) / (2 * 16384);
- return status;
-}
-
-uint8_t MPU6050::dmpGetGravity(VectorFloat *v, Quaternion *q) {
- v -> x = 2 * (q -> x*q -> z - q -> w*q -> y);
- v -> y = 2 * (q -> w*q -> x + q -> y*q -> z);
- v -> z = q -> w*q -> w - q -> x*q -> x - q -> y*q -> y + q -> z*q -> z;
- return 0;
-}
-// uint8_t MPU6050::dmpGetUnquantizedAccel(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetQuantizedAccel(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetExternalSensorData(long *data, int size, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetEIS(long *data, const uint8_t* packet);
-
-uint8_t MPU6050::dmpGetEuler(float *data, Quaternion *q) {
- data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); // psi
- data[1] = -asin(2*q -> x*q -> z + 2*q -> w*q -> y); // theta
- data[2] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> z*q -> z - 1); // phi
- return 0;
-}
-
-#ifdef USE_OLD_DMPGETYAWPITCHROLL
-uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
- // yaw: (about Z axis)
- data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
- // pitch: (nose up/down, about Y axis)
- data[1] = atan(gravity -> x / sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
- // roll: (tilt left/right, about X axis)
- data[2] = atan(gravity -> y / sqrt(gravity -> x*gravity -> x + gravity -> z*gravity -> z));
- return 0;
-}
-#else
-uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
- // yaw: (about Z axis)
- data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
- // pitch: (nose up/down, about Y axis)
- data[1] = atan2(gravity -> x , sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
- // roll: (tilt left/right, about X axis)
- data[2] = atan2(gravity -> y , gravity -> z);
- if (gravity -> z < 0) {
- if(data[1] > 0) {
- data[1] = PI - data[1];
- } else {
- data[1] = -PI - data[1];
- }
- }
- return 0;
-}
-#endif
-
-// uint8_t MPU6050::dmpGetAccelFloat(float *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetQuaternionFloat(float *data, const uint8_t* packet);
-
-uint8_t MPU6050::dmpProcessFIFOPacket(const unsigned char *dmpData) {
- /*for (uint8_t k = 0; k < dmpPacketSize; k++) {
- if (dmpData[k] < 0x10) Serial.print("0");
- Serial.print(dmpData[k], HEX);
- Serial.print(" ");
- }
- Serial.print("\n");*/
- //Serial.println((uint16_t)dmpPacketBuffer);
- return 0;
-}
-uint8_t MPU6050::dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed) {
- uint8_t status;
- uint8_t buf[dmpPacketSize];
- for (uint8_t i = 0; i < numPackets; i++) {
- // read packet from FIFO
- getFIFOBytes(buf, dmpPacketSize);
-
- // process packet
- if ((status = dmpProcessFIFOPacket(buf)) > 0) return status;
-
- // increment external process count variable, if supplied
- if (processed != 0) (*processed)++;
- }
- return 0;
-}
-
-// uint8_t MPU6050::dmpSetFIFOProcessedCallback(void (*func) (void));
-
-// uint8_t MPU6050::dmpInitFIFOParam();
-// uint8_t MPU6050::dmpCloseFIFO();
-// uint8_t MPU6050::dmpSetGyroDataSource(uint_fast8_t source);
-// uint8_t MPU6050::dmpDecodeQuantizedAccel();
-// uint32_t MPU6050::dmpGetGyroSumOfSquare();
-// uint32_t MPU6050::dmpGetAccelSumOfSquare();
-// void MPU6050::dmpOverrideQuaternion(long *q);
-uint16_t MPU6050::dmpGetFIFOPacketSize() {
- return dmpPacketSize;
-}
-
-#endif /* _MPU6050_6AXIS_MOTIONAPPS20_H_ */
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050_9Axis_MotionApps41.h b/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050_9Axis_MotionApps41.h
deleted file mode 100644
index 763a49b9..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/MPU6050_9Axis_MotionApps41.h
+++ /dev/null
@@ -1,887 +0,0 @@
-// I2Cdev library collection - MPU6050 I2C device class, 9-axis MotionApps 4.1 implementation
-// Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
-// 6/18/2012 by Jeff Rowberg
-// 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_9AXIS_MOTIONAPPS41_H_
-#define _MPU6050_9AXIS_MOTIONAPPS41_H_
-
-#include "I2Cdev.h"
-#include "helper_3dmath.h"
-
-// MotionApps 4.1 DMP implementation, built using the MPU-9150 "MotionFit" board
-#define MPU6050_INCLUDE_DMP_MOTIONAPPS41
-
-#include "MPU6050.h"
-
-// Tom Carpenter's conditional PROGMEM code
-// http://forum.arduino.cc/index.php?topic=129407.0
-#ifdef __AVR__
- #include
-#else
- // Teensy 3.0 library conditional PROGMEM code from Paul Stoffregen
- #ifndef __PGMSPACE_H_
- #define __PGMSPACE_H_ 1
- #include
-
- #define PROGMEM
- #define PGM_P const char *
- #define PSTR(str) (str)
- #define F(x) x
-
- typedef void prog_void;
- typedef char prog_char;
- //typedef unsigned char prog_uchar;
- typedef int8_t prog_int8_t;
- typedef uint8_t prog_uint8_t;
- typedef int16_t prog_int16_t;
- 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)
- #define pgm_read_float_near(addr) pgm_read_float(addr)
- #define pgm_read_byte_far(addr) pgm_read_byte(addr)
- #define pgm_read_word_far(addr) pgm_read_word(addr)
- #define pgm_read_dword_far(addr) pgm_read_dword(addr)
- #define pgm_read_float_far(addr) pgm_read_float(addr)
- #endif
-#endif
-
-// NOTE! Enabling DEBUG adds about 3.3kB to the flash program size.
-// Debug output is now working even on ATMega328P MCUs (e.g. Arduino Uno)
-// after moving string constants to flash memory storage using the F()
-// compiler macro (Arduino IDE 1.0+ required).
-
-//#define DEBUG
-#ifdef DEBUG
- #define DEBUG_PRINT(x) Serial.print(x)
- #define DEBUG_PRINTF(x, y) Serial.print(x, y)
- #define DEBUG_PRINTLN(x) Serial.println(x)
- #define DEBUG_PRINTLNF(x, y) Serial.println(x, y)
-#else
- #define DEBUG_PRINT(x)
- #define DEBUG_PRINTF(x, y)
- #define DEBUG_PRINTLN(x)
- #define DEBUG_PRINTLNF(x, y)
-#endif
-
-#define MPU6050_DMP_CODE_SIZE 1962 // dmpMemory[]
-#define MPU6050_DMP_CONFIG_SIZE 232 // dmpConfig[]
-#define MPU6050_DMP_UPDATES_SIZE 140 // dmpUpdates[]
-
-/* ================================================================================================ *
- | Default MotionApps v4.1 48-byte FIFO packet structure: |
- | |
- | [QUAT W][ ][QUAT X][ ][QUAT Y][ ][QUAT Z][ ][GYRO X][ ][GYRO Y][ ] |
- | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
- | |
- | [GYRO Z][ ][MAG X ][MAG Y ][MAG Z ][ACC X ][ ][ACC Y ][ ][ACC Z ][ ][ ] |
- | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
- * ================================================================================================ */
-
-// this block of memory gets written to the MPU on start-up, and it seems
-// to be volatile memory, so it has to be done each time (it only takes ~1
-// second though)
-const unsigned char dmpMemory[MPU6050_DMP_CODE_SIZE] PROGMEM = {
- // bank 0, 256 bytes
- 0xFB, 0x00, 0x00, 0x3E, 0x00, 0x0B, 0x00, 0x36, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00,
- 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0xFA, 0x80, 0x00, 0x0B, 0x12, 0x82, 0x00, 0x01,
- 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x28, 0x00, 0x00, 0xFF, 0xFF, 0x45, 0x81, 0xFF, 0xFF, 0xFA, 0x72, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x03, 0xE8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7F, 0xFF, 0xFF, 0xFE, 0x80, 0x01,
- 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x3E, 0x03, 0x30, 0x40, 0x00, 0x00, 0x00, 0x02, 0xCA, 0xE3, 0x09, 0x3E, 0x80, 0x00, 0x00,
- 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
- 0x41, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x2A, 0x00, 0x00, 0x16, 0x55, 0x00, 0x00, 0x21, 0x82,
- 0xFD, 0x87, 0x26, 0x50, 0xFD, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x05, 0x80, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
- 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x02, 0x65, 0x32, 0x00, 0x00, 0x5E, 0xC0,
- 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xFB, 0x8C, 0x6F, 0x5D, 0xFD, 0x5D, 0x08, 0xD9, 0x00, 0x7C, 0x73, 0x3B, 0x00, 0x6C, 0x12, 0xCC,
- 0x32, 0x00, 0x13, 0x9D, 0x32, 0x00, 0xD0, 0xD6, 0x32, 0x00, 0x08, 0x00, 0x40, 0x00, 0x01, 0xF4,
- 0xFF, 0xE6, 0x80, 0x79, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xD6, 0x00, 0x00, 0x27, 0x10,
-
- // bank 1, 256 bytes
- 0xFB, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0xFA, 0x36, 0xFF, 0xBC, 0x30, 0x8E, 0x00, 0x05, 0xFB, 0xF0, 0xFF, 0xD9, 0x5B, 0xC8,
- 0xFF, 0xD0, 0x9A, 0xBE, 0x00, 0x00, 0x10, 0xA9, 0xFF, 0xF4, 0x1E, 0xB2, 0x00, 0xCE, 0xBB, 0xF7,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x0C,
- 0xFF, 0xC2, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0xCF, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x03, 0x3F, 0x68, 0xB6, 0x79, 0x35, 0x28, 0xBC, 0xC6, 0x7E, 0xD1, 0x6C,
- 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2, 0x6A, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x30,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x25, 0x4D, 0x00, 0x2F, 0x70, 0x6D, 0x00, 0x00, 0x05, 0xAE, 0x00, 0x0C, 0x02, 0xD0,
-
- // bank 2, 256 bytes
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0xFF, 0xEF, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
- 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x78, 0xA2,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- // bank 3, 256 bytes
- 0xD8, 0xDC, 0xF4, 0xD8, 0xB9, 0xAB, 0xF3, 0xF8, 0xFA, 0xF1, 0xBA, 0xA2, 0xDE, 0xB2, 0xB8, 0xB4,
- 0xA8, 0x81, 0x98, 0xF7, 0x4A, 0x90, 0x7F, 0x91, 0x6A, 0xF3, 0xF9, 0xDB, 0xA8, 0xF9, 0xB0, 0xBA,
- 0xA0, 0x80, 0xF2, 0xCE, 0x81, 0xF3, 0xC2, 0xF1, 0xC1, 0xF2, 0xC3, 0xF3, 0xCC, 0xA2, 0xB2, 0x80,
- 0xF1, 0x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x9C, 0xA8, 0x29, 0x51, 0x79, 0xB0, 0x8B, 0x29, 0x51, 0x79, 0xB1, 0x83, 0x24,
-
- // bank 6, 256 bytes
- 0x70, 0x59, 0xB0, 0x8B, 0x20, 0x58, 0x71, 0xB1, 0x83, 0x44, 0x69, 0x38, 0xB0, 0x8B, 0x39, 0x40,
- 0x68, 0xB1, 0x83, 0x64, 0x48, 0x31, 0xB0, 0x8B, 0x30, 0x49, 0x60, 0xA5, 0x88, 0x20, 0x09, 0x71,
- 0x58, 0x44, 0x68, 0x11, 0x39, 0x64, 0x49, 0x30, 0x19, 0xF1, 0xAC, 0x00, 0x2C, 0x54, 0x7C, 0xF0,
- 0x8C, 0xA8, 0x04, 0x28, 0x50, 0x78, 0xF1, 0x88, 0x97, 0x26, 0xA8, 0x59, 0x98, 0xAC, 0x8C, 0x02,
- 0x26, 0x46, 0x66, 0xF0, 0x89, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44, 0x69, 0x38,
- 0x64, 0x48, 0x31, 0xA9, 0x88, 0x09, 0x20, 0x59, 0x70, 0xAB, 0x11, 0x38, 0x40, 0x69, 0xA8, 0x19,
- 0x31, 0x48, 0x60, 0x8C, 0xA8, 0x3C, 0x41, 0x5C, 0x20, 0x7C, 0x00, 0xF1, 0x87, 0x98, 0x19, 0x86,
- 0xA8, 0x6E, 0x76, 0x7E, 0xA9, 0x99, 0x88, 0x2D, 0x55, 0x7D, 0x9E, 0xB9, 0xA3, 0x8A, 0x22, 0x8A,
- 0x6E, 0x8A, 0x56, 0x8A, 0x5E, 0x9F, 0xB1, 0x83, 0x06, 0x26, 0x46, 0x66, 0x0E, 0x2E, 0x4E, 0x6E,
- 0x9D, 0xB8, 0xAD, 0x00, 0x2C, 0x54, 0x7C, 0xF2, 0xB1, 0x8C, 0xB4, 0x99, 0xB9, 0xA3, 0x2D, 0x55,
- 0x7D, 0x81, 0x91, 0xAC, 0x38, 0xAD, 0x3A, 0xB5, 0x83, 0x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6, 0x09, 0xB4, 0xD9, 0xAB, 0xDE, 0xB0, 0x87, 0x9C, 0xB9,
- 0xA3, 0xDD, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x95, 0xF1, 0xA3, 0xA3, 0xA3, 0x9D, 0xF1, 0xA3, 0xA3,
- 0xA3, 0xA3, 0xF2, 0xA3, 0xB4, 0x90, 0x80, 0xF2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3,
- 0xA3, 0xA3, 0xB2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xB0, 0x87, 0xB5, 0x99, 0xF1, 0xA3, 0xA3,
- 0xA3, 0x98, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x97, 0xA3, 0xA3, 0xA3, 0xA3, 0xF3, 0x9B, 0xA3, 0xA3,
- 0xDC, 0xB9, 0xA7, 0xF1, 0x26, 0x26, 0x26, 0xD8, 0xD8, 0xFF
-};
-
-#ifndef MPU6050_DMP_FIFO_RATE_DIVISOR
-#define MPU6050_DMP_FIFO_RATE_DIVISOR 0x03
-#endif
-
-const unsigned char dmpConfig[MPU6050_DMP_CONFIG_SIZE] PROGMEM = {
-// BANK OFFSET LENGTH [DATA]
- 0x02, 0xEC, 0x04, 0x00, 0x47, 0x7D, 0x1A, // ?
- 0x03, 0x82, 0x03, 0x4C, 0xCD, 0x6C, // FCFG_1 inv_set_gyro_calibration
- 0x03, 0xB2, 0x03, 0x36, 0x56, 0x76, // FCFG_3 inv_set_gyro_calibration
- 0x00, 0x68, 0x04, 0x02, 0xCA, 0xE3, 0x09, // D_0_104 inv_set_gyro_calibration
- 0x01, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // D_1_152 inv_set_accel_calibration
- 0x03, 0x86, 0x03, 0x0C, 0xC9, 0x2C, // FCFG_2 inv_set_accel_calibration
- 0x03, 0x90, 0x03, 0x26, 0x46, 0x66, // (continued)...FCFG_2 inv_set_accel_calibration
- 0x00, 0x6C, 0x02, 0x40, 0x00, // D_0_108 inv_set_accel_calibration
-
- 0x02, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_00 inv_set_compass_calibration
- 0x02, 0x44, 0x04, 0x40, 0x00, 0x00, 0x00, // CPASS_MTX_01
- 0x02, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_02
- 0x02, 0x4C, 0x04, 0x40, 0x00, 0x00, 0x00, // CPASS_MTX_10
- 0x02, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_11
- 0x02, 0x54, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_12
- 0x02, 0x58, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_20
- 0x02, 0x5C, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_21
- 0x02, 0xBC, 0x04, 0xC0, 0x00, 0x00, 0x00, // CPASS_MTX_22
-
- 0x01, 0xEC, 0x04, 0x00, 0x00, 0x40, 0x00, // D_1_236 inv_apply_endian_accel
- 0x03, 0x86, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, // FCFG_2 inv_set_mpu_sensors
- 0x04, 0x22, 0x03, 0x0D, 0x35, 0x5D, // CFG_MOTION_BIAS inv_turn_on_bias_from_no_motion
- 0x00, 0xA3, 0x01, 0x00, // ?
- 0x04, 0x29, 0x04, 0x87, 0x2D, 0x35, 0x3D, // FCFG_5 inv_set_bias_update
- 0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // CFG_8 inv_send_quaternion
- 0x07, 0x9F, 0x01, 0x30, // CFG_16 inv_set_footer
- 0x07, 0x67, 0x01, 0x9A, // CFG_GYRO_SOURCE inv_send_gyro
- 0x07, 0x68, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_9 inv_send_gyro -> inv_construct3_fifo
- 0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // ?
- 0x02, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // ?
- 0x07, 0x83, 0x06, 0xC2, 0xCA, 0xC4, 0xA3, 0xA3, 0xA3, // ?
- // SPECIAL 0x01 = enable interrupts
- 0x00, 0x00, 0x00, 0x01, // SET INT_ENABLE, SPECIAL INSTRUCTION
- 0x07, 0xA7, 0x01, 0xFE, // ?
- 0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // ?
- 0x07, 0x67, 0x01, 0x9A, // ?
- 0x07, 0x68, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_12 inv_send_accel -> inv_construct3_fifo
- 0x07, 0x8D, 0x04, 0xF1, 0x28, 0x30, 0x38, // ??? CFG_12 inv_send_mag -> inv_construct3_fifo
- 0x02, 0x16, 0x02, 0x00, MPU6050_DMP_FIFO_RATE_DIVISOR // D_0_22 inv_set_fifo_rate
-
- // This very last 0x03 WAS a 0x09, which drops the FIFO rate down to 20 Hz. 0x07 is 25 Hz,
- // 0x01 is 100Hz. Going faster than 100Hz (0x00=200Hz) tends to result in very noisy data.
- // DMP output frequency is calculated easily using this equation: (200Hz / (1 + value))
-
- // It is important to make sure the host processor can keep up with reading and processing
- // the FIFO output at the desired rate. Handling FIFO overflow cleanly is also a good idea.
-};
-
-const unsigned char dmpUpdates[MPU6050_DMP_UPDATES_SIZE] PROGMEM = {
- 0x01, 0xB2, 0x02, 0xFF, 0xF5,
- 0x01, 0x90, 0x04, 0x0A, 0x0D, 0x97, 0xC0,
- 0x00, 0xA3, 0x01, 0x00,
- 0x04, 0x29, 0x04, 0x87, 0x2D, 0x35, 0x3D,
- 0x01, 0x6A, 0x02, 0x06, 0x00,
- 0x01, 0x60, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00,
- 0x02, 0x60, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x08, 0x02, 0x01, 0x20,
- 0x01, 0x0A, 0x02, 0x00, 0x4E,
- 0x01, 0x02, 0x02, 0xFE, 0xB3,
- 0x02, 0x6C, 0x04, 0x00, 0x00, 0x00, 0x00, // READ
- 0x02, 0x6C, 0x04, 0xFA, 0xFE, 0x00, 0x00,
- 0x02, 0x60, 0x0C, 0xFF, 0xFF, 0xCB, 0x4D, 0x00, 0x01, 0x08, 0xC1, 0xFF, 0xFF, 0xBC, 0x2C,
- 0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00,
- 0x02, 0xF8, 0x04, 0x00, 0x00, 0x00, 0x00,
- 0x02, 0xFC, 0x04, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00,
- 0x00, 0x60, 0x04, 0x00, 0x40, 0x00, 0x00
-};
-
-uint8_t MPU6050::dmpInitialize() {
- // reset device
- DEBUG_PRINTLN(F("\n\nResetting MPU6050..."));
- reset();
- delay(30); // wait after reset
-
- // disable sleep mode
- DEBUG_PRINTLN(F("Disabling sleep mode..."));
- setSleepEnabled(false);
-
- // get MPU product ID
- DEBUG_PRINTLN(F("Getting product ID..."));
- //uint8_t productID = 0; //getProductID();
- DEBUG_PRINT(F("Product ID = "));
- DEBUG_PRINT(productID);
-
- // get MPU hardware revision
- DEBUG_PRINTLN(F("Selecting user bank 16..."));
- setMemoryBank(0x10, true, true);
- 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_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!"));
-
- // get X/Y/Z gyro offsets
- DEBUG_PRINTLN(F("Reading gyro offset values..."));
- int8_t xgOffset = getXGyroOffset();
- int8_t ygOffset = getYGyroOffset();
- int8_t zgOffset = getZGyroOffset();
- DEBUG_PRINT(F("X gyro offset = "));
- DEBUG_PRINTLN(xgOffset);
- DEBUG_PRINT(F("Y gyro offset = "));
- DEBUG_PRINTLN(ygOffset);
- DEBUG_PRINT(F("Z gyro offset = "));
- DEBUG_PRINTLN(zgOffset);
-
- I2Cdev::readByte(devAddr, MPU6050_RA_USER_CTRL, buffer); // ?
-
- DEBUG_PRINTLN(F("Enabling interrupt latch, clear on any read, AUX bypass enabled"));
- I2Cdev::writeByte(devAddr, MPU6050_RA_INT_PIN_CFG, 0x32);
-
- // enable MPU AUX I2C bypass mode
- //DEBUG_PRINTLN(F("Enabling AUX I2C bypass mode..."));
- //setI2CBypassEnabled(true);
-
- DEBUG_PRINTLN(F("Setting magnetometer mode to power-down..."));
- //mag -> setMode(0);
- I2Cdev::writeByte(0x0E, 0x0A, 0x00);
-
- DEBUG_PRINTLN(F("Setting magnetometer mode to fuse access..."));
- //mag -> setMode(0x0F);
- I2Cdev::writeByte(0x0E, 0x0A, 0x0F);
-
- DEBUG_PRINTLN(F("Reading mag magnetometer factory calibration..."));
- int8_t asax, asay, asaz;
- //mag -> getAdjustment(&asax, &asay, &asaz);
- I2Cdev::readBytes(0x0E, 0x10, 3, buffer);
- asax = (int8_t)buffer[0];
- asay = (int8_t)buffer[1];
- asaz = (int8_t)buffer[2];
- DEBUG_PRINT(F("Adjustment X/Y/Z = "));
- DEBUG_PRINT(asax);
- DEBUG_PRINT(F(" / "));
- DEBUG_PRINT(asay);
- DEBUG_PRINT(F(" / "));
- DEBUG_PRINTLN(asaz);
-
- DEBUG_PRINTLN(F("Setting magnetometer mode to power-down..."));
- //mag -> setMode(0);
- I2Cdev::writeByte(0x0E, 0x0A, 0x00);
-
- // load DMP code into memory banks
- DEBUG_PRINT(F("Writing DMP code to MPU memory banks ("));
- DEBUG_PRINT(MPU6050_DMP_CODE_SIZE);
- DEBUG_PRINTLN(F(" bytes)"));
- if (writeProgMemoryBlock(dmpMemory, MPU6050_DMP_CODE_SIZE)) {
- DEBUG_PRINTLN(F("Success! DMP code written and verified."));
-
- DEBUG_PRINTLN(F("Configuring DMP and related settings..."));
-
- // write DMP configuration
- DEBUG_PRINT(F("Writing DMP configuration to MPU memory banks ("));
- DEBUG_PRINT(MPU6050_DMP_CONFIG_SIZE);
- DEBUG_PRINTLN(F(" bytes in config def)"));
- if (writeProgDMPConfigurationSet(dmpConfig, MPU6050_DMP_CONFIG_SIZE)) {
- DEBUG_PRINTLN(F("Success! DMP configuration written and verified."));
-
- DEBUG_PRINTLN(F("Setting DMP and FIFO_OFLOW interrupts enabled..."));
- setIntEnabled(1< setMode(1);
- I2Cdev::writeByte(0x0E, 0x0A, 0x01);
-
- // setup AK8975 (0x0E) as Slave 0 in read mode
- DEBUG_PRINTLN(F("Setting up AK8975 read slave 0..."));
- I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV0_ADDR, 0x8E);
- I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV0_REG, 0x01);
- I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV0_CTRL, 0xDA);
-
- // setup AK8975 (0x0E) as Slave 2 in write mode
- DEBUG_PRINTLN(F("Setting up AK8975 write slave 2..."));
- I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_ADDR, 0x0E);
- I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_REG, 0x0A);
- I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_CTRL, 0x81);
- I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV2_DO, 0x01);
-
- // setup I2C timing/delay control
- DEBUG_PRINTLN(F("Setting up slave access delay..."));
- I2Cdev::writeByte(0x68, MPU6050_RA_I2C_SLV4_CTRL, 0x18);
- I2Cdev::writeByte(0x68, MPU6050_RA_I2C_MST_DELAY_CTRL, 0x05);
-
- // enable interrupts
- DEBUG_PRINTLN(F("Enabling default interrupt behavior/no bypass..."));
- I2Cdev::writeByte(0x68, MPU6050_RA_INT_PIN_CFG, 0x00);
-
- // enable I2C master mode and reset DMP/FIFO
- DEBUG_PRINTLN(F("Enabling I2C master mode..."));
- I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0x20);
- DEBUG_PRINTLN(F("Resetting FIFO..."));
- I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0x24);
- DEBUG_PRINTLN(F("Rewriting I2C master mode enabled because...I don't know"));
- I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0x20);
- DEBUG_PRINTLN(F("Enabling and resetting DMP/FIFO..."));
- I2Cdev::writeByte(0x68, MPU6050_RA_USER_CTRL, 0xE8);
-
- DEBUG_PRINTLN(F("Writing final memory update 5/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 6/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 7/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 8/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 9/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 10/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 11/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
-
- DEBUG_PRINTLN(F("Reading final memory update 12/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- readMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- #ifdef DEBUG
- DEBUG_PRINT(F("Read bytes: "));
- for (j = 0; j < 4; j++) {
- DEBUG_PRINTF(dmpUpdate[3 + j], HEX);
- DEBUG_PRINT(" ");
- }
- DEBUG_PRINTLN("");
- #endif
-
- DEBUG_PRINTLN(F("Writing final memory update 13/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 14/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 15/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 16/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
- DEBUG_PRINTLN(F("Writing final memory update 17/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
-
- DEBUG_PRINTLN(F("Waiting for FIRO count >= 46..."));
- while ((fifoCount = getFIFOCount()) < 46);
- DEBUG_PRINTLN(F("Reading FIFO..."));
- getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
- DEBUG_PRINTLN(F("Reading interrupt status..."));
- getIntStatus();
-
- DEBUG_PRINTLN(F("Writing final memory update 18/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
-
- DEBUG_PRINTLN(F("Waiting for FIRO count >= 48..."));
- while ((fifoCount = getFIFOCount()) < 48);
- DEBUG_PRINTLN(F("Reading FIFO..."));
- getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
- DEBUG_PRINTLN(F("Reading interrupt status..."));
- getIntStatus();
- DEBUG_PRINTLN(F("Waiting for FIRO count >= 48..."));
- while ((fifoCount = getFIFOCount()) < 48);
- DEBUG_PRINTLN(F("Reading FIFO..."));
- getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes
- DEBUG_PRINTLN(F("Reading interrupt status..."));
- getIntStatus();
-
- DEBUG_PRINTLN(F("Writing final memory update 19/19 (function unknown)..."));
- for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]);
- writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]);
-
- DEBUG_PRINTLN(F("Disabling DMP (you turn it on later)..."));
- setDMPEnabled(false);
-
- DEBUG_PRINTLN(F("Setting up internal 48-byte (default) DMP packet buffer..."));
- dmpPacketSize = 48;
- /*if ((dmpPacketBuffer = (uint8_t *)malloc(42)) == 0) {
- return 3; // TODO: proper error code for no memory
- }*/
-
- DEBUG_PRINTLN(F("Resetting FIFO and clearing INT status one last time..."));
- resetFIFO();
- getIntStatus();
- } else {
- DEBUG_PRINTLN(F("ERROR! DMP configuration verification failed."));
- return 2; // configuration block loading failed
- }
- } else {
- DEBUG_PRINTLN(F("ERROR! DMP code verification failed."));
- return 1; // main binary block loading failed
- }
- return 0; // success
-}
-
-bool MPU6050::dmpPacketAvailable() {
- return getFIFOCount() >= dmpGetFIFOPacketSize();
-}
-
-// uint8_t MPU6050::dmpSetFIFORate(uint8_t fifoRate);
-// uint8_t MPU6050::dmpGetFIFORate();
-// uint8_t MPU6050::dmpGetSampleStepSizeMS();
-// uint8_t MPU6050::dmpGetSampleFrequency();
-// int32_t MPU6050::dmpDecodeTemperature(int8_t tempReg);
-
-//uint8_t MPU6050::dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority);
-//uint8_t MPU6050::dmpUnregisterFIFORateProcess(inv_obj_func func);
-//uint8_t MPU6050::dmpRunFIFORateProcesses();
-
-// uint8_t MPU6050::dmpSendQuaternion(uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendPacketNumber(uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy);
-// uint8_t MPU6050::dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy);
-
-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] = (((uint32_t)packet[34] << 24) | ((uint32_t)packet[35] << 16) | ((uint32_t)packet[36] << 8) | packet[37]);
- data[1] = (((uint32_t)packet[38] << 24) | ((uint32_t)packet[39] << 16) | ((uint32_t)packet[40] << 8) | packet[41]);
- data[2] = (((uint32_t)packet[42] << 24) | ((uint32_t)packet[43] << 16) | ((uint32_t)packet[44] << 8) | packet[45]);
- 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[34] << 8) | packet[35];
- data[1] = (packet[38] << 8) | packet[39];
- data[2] = (packet[42] << 8) | packet[43];
- 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[34] << 8) | packet[35];
- v -> y = (packet[38] << 8) | packet[39];
- v -> z = (packet[42] << 8) | packet[43];
- 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] = (((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]);
- return 0;
-}
-uint8_t MPU6050::dmpGetQuaternion(Quaternion *q, const uint8_t* packet) {
- // TODO: accommodate different arrangements of sent data (ONLY default supported now)
- int16_t qI[4];
- uint8_t status = dmpGetQuaternion(qI, packet);
- if (status == 0) {
- q -> w = (float)qI[0] / 16384.0f;
- q -> x = (float)qI[1] / 16384.0f;
- q -> y = (float)qI[2] / 16384.0f;
- q -> z = (float)qI[3] / 16384.0f;
- return 0;
- }
- return status; // int16 return value, indicates error if this line is reached
-}
-// uint8_t MPU6050::dmpGet6AxisQuaternion(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetRelativeQuaternion(long *data, const uint8_t* packet);
-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] = (((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];
- return 0;
-}
-uint8_t MPU6050::dmpGetMag(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[30] << 8) | packet[31];
- data[2] = (packet[32] << 8) | packet[33];
- return 0;
-}
-// uint8_t MPU6050::dmpSetLinearAccelFilterCoefficient(float coef);
-// uint8_t MPU6050::dmpGetLinearAccel(long *data, const uint8_t* packet);
-uint8_t MPU6050::dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity) {
- // get rid of the gravity component (+1g = +4096 in standard DMP FIFO packet)
- v -> x = vRaw -> x - gravity -> x*4096;
- v -> y = vRaw -> y - gravity -> y*4096;
- v -> z = vRaw -> z - gravity -> z*4096;
- return 0;
-}
-// uint8_t MPU6050::dmpGetLinearAccelInWorld(long *data, const uint8_t* packet);
-uint8_t MPU6050::dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q) {
- // rotate measured 3D acceleration vector into original state
- // frame of reference based on orientation quaternion
- memcpy(v, vReal, sizeof(VectorInt16));
- v -> rotate(q);
- return 0;
-}
-// uint8_t MPU6050::dmpGetGyroAndAccelSensor(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetGyroSensor(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetControlData(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetTemperature(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetGravity(long *data, const uint8_t* packet);
-uint8_t MPU6050::dmpGetGravity(int16_t *data, const uint8_t* packet) {
- /* +1g corresponds to +8192, sensitivity is 2g. */
- int16_t qI[4];
- uint8_t status = dmpGetQuaternion(qI, packet);
- data[0] = ((int32_t)qI[1] * qI[3] - (int32_t)qI[0] * qI[2]) / 16384;
- data[1] = ((int32_t)qI[0] * qI[1] + (int32_t)qI[2] * qI[3]) / 16384;
- data[2] = ((int32_t)qI[0] * qI[0] - (int32_t)qI[1] * qI[1]
- - (int32_t)qI[2] * qI[2] + (int32_t)qI[3] * qI[3]) / (2 * 16384);
- return status;
-}
-
-uint8_t MPU6050::dmpGetGravity(VectorFloat *v, Quaternion *q) {
- v -> x = 2 * (q -> x*q -> z - q -> w*q -> y);
- v -> y = 2 * (q -> w*q -> x + q -> y*q -> z);
- v -> z = q -> w*q -> w - q -> x*q -> x - q -> y*q -> y + q -> z*q -> z;
- return 0;
-}
-// uint8_t MPU6050::dmpGetUnquantizedAccel(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetQuantizedAccel(long *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetExternalSensorData(long *data, int size, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetEIS(long *data, const uint8_t* packet);
-
-uint8_t MPU6050::dmpGetEuler(float *data, Quaternion *q) {
- data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); // psi
- data[1] = -asin(2*q -> x*q -> z + 2*q -> w*q -> y); // theta
- data[2] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> z*q -> z - 1); // phi
- return 0;
-}
-
-#ifdef USE_OLD_DMPGETYAWPITCHROLL
-uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
- // yaw: (about Z axis)
- data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
- // pitch: (nose up/down, about Y axis)
- data[1] = atan(gravity -> x / sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
- // roll: (tilt left/right, about X axis)
- data[2] = atan(gravity -> y / sqrt(gravity -> x*gravity -> x + gravity -> z*gravity -> z));
- return 0;
-}
-#else
-uint8_t MPU6050::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) {
- // yaw: (about Z axis)
- data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1);
- // pitch: (nose up/down, about Y axis)
- data[1] = atan2(gravity -> x , sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z));
- // roll: (tilt left/right, about X axis)
- data[2] = atan2(gravity -> y , gravity -> z);
- if(gravity->z<0) {
- if(data[1]>0) {
- data[1] = PI - data[1];
- } else {
- data[1] = -PI - data[1];
- }
- }
- return 0;
-}
-#endif
-
-// uint8_t MPU6050::dmpGetAccelFloat(float *data, const uint8_t* packet);
-// uint8_t MPU6050::dmpGetQuaternionFloat(float *data, const uint8_t* packet);
-
-uint8_t MPU6050::dmpProcessFIFOPacket(const unsigned char *dmpData) {
- /*for (uint8_t k = 0; k < dmpPacketSize; k++) {
- if (dmpData[k] < 0x10) Serial.print("0");
- Serial.print(dmpData[k], HEX);
- Serial.print(" ");
- }
- Serial.print("\n");*/
- //Serial.println((uint16_t)dmpPacketBuffer);
- return 0;
-}
-uint8_t MPU6050::dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed) {
- uint8_t status;
- uint8_t buf[dmpPacketSize];
- for (uint8_t i = 0; i < numPackets; i++) {
- // read packet from FIFO
- getFIFOBytes(buf, dmpPacketSize);
-
- // process packet
- if ((status = dmpProcessFIFOPacket(buf)) > 0) return status;
-
- // increment external process count variable, if supplied
- if (processed != 0) *processed++;
- }
- return 0;
-}
-
-// uint8_t MPU6050::dmpSetFIFOProcessedCallback(void (*func) (void));
-
-// uint8_t MPU6050::dmpInitFIFOParam();
-// uint8_t MPU6050::dmpCloseFIFO();
-// uint8_t MPU6050::dmpSetGyroDataSource(uint_fast8_t source);
-// uint8_t MPU6050::dmpDecodeQuantizedAccel();
-// uint32_t MPU6050::dmpGetGyroSumOfSquare();
-// uint32_t MPU6050::dmpGetAccelSumOfSquare();
-// void MPU6050::dmpOverrideQuaternion(long *q);
-uint16_t MPU6050::dmpGetFIFOPacketSize() {
- return dmpPacketSize;
-}
-
-#endif /* _MPU6050_9AXIS_MOTIONAPPS41_H_ */
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/helper_3dmath.h b/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/helper_3dmath.h
deleted file mode 100644
index 9ed260ec..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU6050/helper_3dmath.h
+++ /dev/null
@@ -1,216 +0,0 @@
-// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class, 3D math helper
-// 6/5/2012 by Jeff Rowberg
-// 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_
-
-class Quaternion {
- public:
- float w;
- 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;
- y = ny;
- z = nz;
- }
-
- Quaternion getProduct(Quaternion q) {
- // Quaternion multiplication is defined by:
- // (Q1 * Q2).w = (w1w2 - x1x2 - y1y2 - z1z2)
- // (Q1 * Q2).x = (w1x2 + x1w2 + y1z2 - z1y2)
- // (Q1 * Q2).y = (w1y2 - x1z2 + y1w2 + z1x2)
- // (Q1 * Q2).z = (w1z2 + x1y2 - y1x2 + z1w2
- return Quaternion(
- w*q.w - x*q.x - y*q.y - z*q.z, // new w
- w*q.x + x*q.w + y*q.z - z*q.y, // new x
- w*q.y - x*q.z + y*q.w + z*q.x, // new y
- w*q.z + x*q.y - y*q.x + z*q.w); // new z
- }
-
- Quaternion getConjugate() {
- return Quaternion(w, -x, -y, -z);
- }
-
- float getMagnitude() {
- return sqrt(w*w + x*x + y*y + z*z);
- }
-
- void normalize() {
- float m = getMagnitude();
- w /= m;
- x /= m;
- y /= m;
- z /= m;
- }
-
- Quaternion getNormalized() {
- Quaternion r(w, x, y, z);
- r.normalize();
- return r;
- }
-};
-
-class VectorInt16 {
- public:
- int16_t x;
- int16_t y;
- int16_t z;
-
- VectorInt16() {
- x = 0;
- y = 0;
- z = 0;
- }
-
- VectorInt16(int16_t nx, int16_t ny, int16_t nz) {
- x = nx;
- y = ny;
- z = nz;
- }
-
- float getMagnitude() {
- return sqrt(x*x + y*y + z*z);
- }
-
- void normalize() {
- float m = getMagnitude();
- x /= m;
- 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
- // - P_in is the input vector (a*aReal)
- // - conj(q) is the conjugate of the orientation quaternion (q=[w,x,y,z], q*=[w,-x,-y,-z])
- Quaternion p(0, x, y, z);
-
- // quaternion multiplication: q * p, stored back in p
- p = q -> getProduct(p);
-
- // quaternion multiplication: p * conj(q), stored back in p
- p = p.getProduct(q -> getConjugate());
-
- // p quaternion is now [0, x', y', z']
- x = p.x;
- y = p.y;
- z = p.z;
- }
-
- VectorInt16 getRotated(Quaternion *q) {
- VectorInt16 r(x, y, z);
- r.rotate(q);
- return r;
- }
-};
-
-class VectorFloat {
- public:
- float x;
- float y;
- float z;
-
- VectorFloat() {
- x = 0;
- y = 0;
- z = 0;
- }
-
- VectorFloat(float nx, float ny, float nz) {
- x = nx;
- y = ny;
- z = nz;
- }
-
- float getMagnitude() {
- return sqrt(x*x + y*y + z*z);
- }
-
- void normalize() {
- float m = getMagnitude();
- x /= m;
- 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);
-
- // quaternion multiplication: q * p, stored back in p
- p = q -> getProduct(p);
-
- // quaternion multiplication: p * conj(q), stored back in p
- p = p.getProduct(q -> getConjugate());
-
- // p quaternion is now [0, x', y', z']
- x = p.x;
- y = p.y;
- z = p.z;
- }
-
- VectorFloat getRotated(Quaternion *q) {
- VectorFloat r(x, y, z);
- r.rotate(q);
- return r;
- }
-};
-
-#endif /* _HELPER_3DMATH_H_ */
\ No newline at end of file
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU9250/MPU9250.cpp b/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU9250/MPU9250.cpp
deleted file mode 100644
index 7d2722a8..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU9250/MPU9250.cpp
+++ /dev/null
@@ -1,1202 +0,0 @@
-/*
-MPU9250.cpp
-Brian R Taylor
-brian.taylor@bolderflight.com
-Copyright (c) 2017 Bolder Flight Systems
-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 "Arduino.h"
-#include "MPU9250.h"
-
-/* MPU9250 object, input the I2C bus and address */
-MPU9250::MPU9250(TwoWire &bus,uint8_t address){
- _i2c = &bus; // I2C bus
- _address = address; // I2C address
- _useSPI = false; // set to use I2C
-}
-
-/* MPU9250 object, input the SPI bus and chip select pin */
-MPU9250::MPU9250(SPIClass &bus,uint8_t csPin){
- _spi = &bus; // SPI bus
- _csPin = csPin; // chip select pin
- _useSPI = true; // set to use SPI
-}
-
-/* starts communication with the MPU-9250 */
-int MPU9250::begin(){
- if( _useSPI ) { // using SPI for communication
- // use low speed SPI for register setting
- _useSPIHS = false;
- // setting CS pin to output
- pinMode(_csPin,OUTPUT);
- // setting CS pin high
- digitalWrite(_csPin,HIGH);
- // begin SPI communication
- _spi->begin();
- } else { // using I2C for communication
- // starting the I2C bus
- _i2c->begin();
- // setting the I2C clock
- _i2c->setClock(_i2cRate);
- }
- // select clock source to gyro
- if(writeRegister(PWR_MGMNT_1,CLOCK_SEL_PLL) < 0){
- return -1;
- }
- // enable I2C master mode
- if(writeRegister(USER_CTRL,I2C_MST_EN) < 0){
- return -2;
- }
- // set the I2C bus speed to 400 kHz
- if(writeRegister(I2C_MST_CTRL,I2C_MST_CLK) < 0){
- return -3;
- }
- // set AK8963 to Power Down
- writeAK8963Register(AK8963_CNTL1,AK8963_PWR_DOWN);
- // reset the MPU9250
- writeRegister(PWR_MGMNT_1,PWR_RESET);
- // wait for MPU-9250 to come back up
- delay(1);
- // reset the AK8963
- writeAK8963Register(AK8963_CNTL2,AK8963_RESET);
- // select clock source to gyro
- if(writeRegister(PWR_MGMNT_1,CLOCK_SEL_PLL) < 0){
- return -4;
- }
- // check the WHO AM I byte, expected value is 0x71 (decimal 113) or 0x73 (decimal 115)
- if((whoAmI() != 113)&&(whoAmI() != 115)){
- return -5;
- }
- // enable accelerometer and gyro
- if(writeRegister(PWR_MGMNT_2,SEN_ENABLE) < 0){
- return -6;
- }
- // setting accel range to 16G as default
- if(writeRegister(ACCEL_CONFIG,ACCEL_FS_SEL_16G) < 0){
- return -7;
- }
- _accelScale = G * 16.0f/32767.5f; // setting the accel scale to 16G
- _accelRange = ACCEL_RANGE_16G;
- // setting the gyro range to 2000DPS as default
- if(writeRegister(GYRO_CONFIG,GYRO_FS_SEL_2000DPS) < 0){
- return -8;
- }
- _gyroScale = 2000.0f/32767.5f * _d2r; // setting the gyro scale to 2000DPS
- _gyroRange = GYRO_RANGE_2000DPS;
- // setting bandwidth to 184Hz as default
- if(writeRegister(ACCEL_CONFIG2,ACCEL_DLPF_184) < 0){
- return -9;
- }
- if(writeRegister(CONFIG,GYRO_DLPF_184) < 0){ // setting gyro bandwidth to 184Hz
- return -10;
- }
- _bandwidth = DLPF_BANDWIDTH_184HZ;
- // setting the sample rate divider to 0 as default
- if(writeRegister(SMPDIV,0x00) < 0){
- return -11;
- }
- _srd = 0;
- // enable I2C master mode
- if(writeRegister(USER_CTRL,I2C_MST_EN) < 0){
- return -12;
- }
- // set the I2C bus speed to 400 kHz
- if( writeRegister(I2C_MST_CTRL,I2C_MST_CLK) < 0){
- return -13;
- }
- // check AK8963 WHO AM I register, expected value is 0x48 (decimal 72)
- if( whoAmIAK8963() != 72 ){
- return -14;
- }
- /* get the magnetometer calibration */
- // set AK8963 to Power Down
- if(writeAK8963Register(AK8963_CNTL1,AK8963_PWR_DOWN) < 0){
- return -15;
- }
- delay(100); // long wait between AK8963 mode changes
- // set AK8963 to FUSE ROM access
- if(writeAK8963Register(AK8963_CNTL1,AK8963_FUSE_ROM) < 0){
- return -16;
- }
- delay(100); // long wait between AK8963 mode changes
- // read the AK8963 ASA registers and compute magnetometer scale factors
- readAK8963Registers(AK8963_ASA,3,_buffer);
- _magScaleX = ((((float)_buffer[0]) - 128.0f)/(256.0f) + 1.0f) * 4912.0f / 32760.0f; // micro Tesla
- _magScaleY = ((((float)_buffer[1]) - 128.0f)/(256.0f) + 1.0f) * 4912.0f / 32760.0f; // micro Tesla
- _magScaleZ = ((((float)_buffer[2]) - 128.0f)/(256.0f) + 1.0f) * 4912.0f / 32760.0f; // micro Tesla
- // set AK8963 to Power Down
- if(writeAK8963Register(AK8963_CNTL1,AK8963_PWR_DOWN) < 0){
- return -17;
- }
- delay(100); // long wait between AK8963 mode changes
- // set AK8963 to 16 bit resolution, 100 Hz update rate
- if(writeAK8963Register(AK8963_CNTL1,AK8963_CNT_MEAS2) < 0){
- return -18;
- }
- delay(100); // long wait between AK8963 mode changes
- // select clock source to gyro
- if(writeRegister(PWR_MGMNT_1,CLOCK_SEL_PLL) < 0){
- return -19;
- }
- // instruct the MPU9250 to get 7 bytes of data from the AK8963 at the sample rate
- readAK8963Registers(AK8963_HXL,7,_buffer);
- // estimate gyro bias
- if (calibrateGyro() < 0) {
- return -20;
- }
- // successful init, return 1
- return 1;
-}
-
-/* sets the accelerometer full scale range to values other than default */
-int MPU9250::setAccelRange(AccelRange range) {
- // use low speed SPI for register setting
- _useSPIHS = false;
- switch(range) {
- case ACCEL_RANGE_2G: {
- // setting the accel range to 2G
- if(writeRegister(ACCEL_CONFIG,ACCEL_FS_SEL_2G) < 0){
- return -1;
- }
- _accelScale = G * 2.0f/32767.5f; // setting the accel scale to 2G
- break;
- }
- case ACCEL_RANGE_4G: {
- // setting the accel range to 4G
- if(writeRegister(ACCEL_CONFIG,ACCEL_FS_SEL_4G) < 0){
- return -1;
- }
- _accelScale = G * 4.0f/32767.5f; // setting the accel scale to 4G
- break;
- }
- case ACCEL_RANGE_8G: {
- // setting the accel range to 8G
- if(writeRegister(ACCEL_CONFIG,ACCEL_FS_SEL_8G) < 0){
- return -1;
- }
- _accelScale = G * 8.0f/32767.5f; // setting the accel scale to 8G
- break;
- }
- case ACCEL_RANGE_16G: {
- // setting the accel range to 16G
- if(writeRegister(ACCEL_CONFIG,ACCEL_FS_SEL_16G) < 0){
- return -1;
- }
- _accelScale = G * 16.0f/32767.5f; // setting the accel scale to 16G
- break;
- }
- }
- _accelRange = range;
- return 1;
-}
-
-/* sets the gyro full scale range to values other than default */
-int MPU9250::setGyroRange(GyroRange range) {
- // use low speed SPI for register setting
- _useSPIHS = false;
- switch(range) {
- case GYRO_RANGE_250DPS: {
- // setting the gyro range to 250DPS
- if(writeRegister(GYRO_CONFIG,GYRO_FS_SEL_250DPS) < 0){
- return -1;
- }
- _gyroScale = 250.0f/32767.5f * _d2r; // setting the gyro scale to 250DPS
- break;
- }
- case GYRO_RANGE_500DPS: {
- // setting the gyro range to 500DPS
- if(writeRegister(GYRO_CONFIG,GYRO_FS_SEL_500DPS) < 0){
- return -1;
- }
- _gyroScale = 500.0f/32767.5f * _d2r; // setting the gyro scale to 500DPS
- break;
- }
- case GYRO_RANGE_1000DPS: {
- // setting the gyro range to 1000DPS
- if(writeRegister(GYRO_CONFIG,GYRO_FS_SEL_1000DPS) < 0){
- return -1;
- }
- _gyroScale = 1000.0f/32767.5f * _d2r; // setting the gyro scale to 1000DPS
- break;
- }
- case GYRO_RANGE_2000DPS: {
- // setting the gyro range to 2000DPS
- if(writeRegister(GYRO_CONFIG,GYRO_FS_SEL_2000DPS) < 0){
- return -1;
- }
- _gyroScale = 2000.0f/32767.5f * _d2r; // setting the gyro scale to 2000DPS
- break;
- }
- }
- _gyroRange = range;
- return 1;
-}
-
-/* sets the DLPF bandwidth to values other than default */
-int MPU9250::setDlpfBandwidth(DlpfBandwidth bandwidth) {
- // use low speed SPI for register setting
- _useSPIHS = false;
- switch(bandwidth) {
- case DLPF_BANDWIDTH_184HZ: {
- if(writeRegister(ACCEL_CONFIG2,ACCEL_DLPF_184) < 0){ // setting accel bandwidth to 184Hz
- return -1;
- }
- if(writeRegister(CONFIG,GYRO_DLPF_184) < 0){ // setting gyro bandwidth to 184Hz
- return -2;
- }
- break;
- }
- case DLPF_BANDWIDTH_92HZ: {
- if(writeRegister(ACCEL_CONFIG2,ACCEL_DLPF_92) < 0){ // setting accel bandwidth to 92Hz
- return -1;
- }
- if(writeRegister(CONFIG,GYRO_DLPF_92) < 0){ // setting gyro bandwidth to 92Hz
- return -2;
- }
- break;
- }
- case DLPF_BANDWIDTH_41HZ: {
- if(writeRegister(ACCEL_CONFIG2,ACCEL_DLPF_41) < 0){ // setting accel bandwidth to 41Hz
- return -1;
- }
- if(writeRegister(CONFIG,GYRO_DLPF_41) < 0){ // setting gyro bandwidth to 41Hz
- return -2;
- }
- break;
- }
- case DLPF_BANDWIDTH_20HZ: {
- if(writeRegister(ACCEL_CONFIG2,ACCEL_DLPF_20) < 0){ // setting accel bandwidth to 20Hz
- return -1;
- }
- if(writeRegister(CONFIG,GYRO_DLPF_20) < 0){ // setting gyro bandwidth to 20Hz
- return -2;
- }
- break;
- }
- case DLPF_BANDWIDTH_10HZ: {
- if(writeRegister(ACCEL_CONFIG2,ACCEL_DLPF_10) < 0){ // setting accel bandwidth to 10Hz
- return -1;
- }
- if(writeRegister(CONFIG,GYRO_DLPF_10) < 0){ // setting gyro bandwidth to 10Hz
- return -2;
- }
- break;
- }
- case DLPF_BANDWIDTH_5HZ: {
- if(writeRegister(ACCEL_CONFIG2,ACCEL_DLPF_5) < 0){ // setting accel bandwidth to 5Hz
- return -1;
- }
- if(writeRegister(CONFIG,GYRO_DLPF_5) < 0){ // setting gyro bandwidth to 5Hz
- return -2;
- }
- break;
- }
- }
- _bandwidth = bandwidth;
- return 1;
-}
-
-/* sets the sample rate divider to values other than default */
-int MPU9250::setSrd(uint8_t srd) {
- // use low speed SPI for register setting
- _useSPIHS = false;
- /* setting the sample rate divider to 19 to facilitate setting up magnetometer */
- if(writeRegister(SMPDIV,19) < 0){ // setting the sample rate divider
- return -1;
- }
- if(srd > 9){
- // set AK8963 to Power Down
- if(writeAK8963Register(AK8963_CNTL1,AK8963_PWR_DOWN) < 0){
- return -2;
- }
- delay(100); // long wait between AK8963 mode changes
- // set AK8963 to 16 bit resolution, 8 Hz update rate
- if(writeAK8963Register(AK8963_CNTL1,AK8963_CNT_MEAS1) < 0){
- return -3;
- }
- delay(100); // long wait between AK8963 mode changes
- // instruct the MPU9250 to get 7 bytes of data from the AK8963 at the sample rate
- readAK8963Registers(AK8963_HXL,7,_buffer);
- } else {
- // set AK8963 to Power Down
- if(writeAK8963Register(AK8963_CNTL1,AK8963_PWR_DOWN) < 0){
- return -2;
- }
- delay(100); // long wait between AK8963 mode changes
- // set AK8963 to 16 bit resolution, 100 Hz update rate
- if(writeAK8963Register(AK8963_CNTL1,AK8963_CNT_MEAS2) < 0){
- return -3;
- }
- delay(100); // long wait between AK8963 mode changes
- // instruct the MPU9250 to get 7 bytes of data from the AK8963 at the sample rate
- readAK8963Registers(AK8963_HXL,7,_buffer);
- }
- /* setting the sample rate divider */
- if(writeRegister(SMPDIV,srd) < 0){ // setting the sample rate divider
- return -4;
- }
- _srd = srd;
- return 1;
-}
-
-/* enables the data ready interrupt */
-int MPU9250::enableDataReadyInterrupt() {
- // use low speed SPI for register setting
- _useSPIHS = false;
- /* setting the interrupt */
- if (writeRegister(INT_PIN_CFG,INT_PULSE_50US) < 0){ // setup interrupt, 50 us pulse
- return -1;
- }
- if (writeRegister(INT_ENABLE,INT_RAW_RDY_EN) < 0){ // set to data ready
- return -2;
- }
- return 1;
-}
-
-/* disables the data ready interrupt */
-int MPU9250::disableDataReadyInterrupt() {
- // use low speed SPI for register setting
- _useSPIHS = false;
- if(writeRegister(INT_ENABLE,INT_DISABLE) < 0){ // disable interrupt
- return -1;
- }
- return 1;
-}
-
-/* configures and enables wake on motion, low power mode */
-int MPU9250::enableWakeOnMotion(float womThresh_mg,LpAccelOdr odr) {
- // use low speed SPI for register setting
- _useSPIHS = false;
- // set AK8963 to Power Down
- writeAK8963Register(AK8963_CNTL1,AK8963_PWR_DOWN);
- // reset the MPU9250
- writeRegister(PWR_MGMNT_1,PWR_RESET);
- // wait for MPU-9250 to come back up
- delay(1);
- if(writeRegister(PWR_MGMNT_1,0x00) < 0){ // cycle 0, sleep 0, standby 0
- return -1;
- }
- if(writeRegister(PWR_MGMNT_2,DIS_GYRO) < 0){ // disable gyro measurements
- return -2;
- }
- if(writeRegister(ACCEL_CONFIG2,ACCEL_DLPF_184) < 0){ // setting accel bandwidth to 184Hz
- return -3;
- }
- if(writeRegister(INT_ENABLE,INT_WOM_EN) < 0){ // enabling interrupt to wake on motion
- return -4;
- }
- if(writeRegister(MOT_DETECT_CTRL,(ACCEL_INTEL_EN | ACCEL_INTEL_MODE)) < 0){ // enabling accel hardware intelligence
- return -5;
- }
- _womThreshold = map(womThresh_mg, 0, 1020, 0, 255);
- if(writeRegister(WOM_THR,_womThreshold) < 0){ // setting wake on motion threshold
- return -6;
- }
- if(writeRegister(LP_ACCEL_ODR,(uint8_t)odr) < 0){ // set frequency of wakeup
- return -7;
- }
- if(writeRegister(PWR_MGMNT_1,PWR_CYCLE) < 0){ // switch to accel low power mode
- return -8;
- }
- return 1;
-}
-
-/* configures and enables the FIFO buffer */
-int MPU9250FIFO::enableFifo(bool accel,bool gyro,bool mag,bool temp) {
- // use low speed SPI for register setting
- _useSPIHS = false;
- if(writeRegister(USER_CTRL, (0x40 | I2C_MST_EN)) < 0){
- return -1;
- }
- if(writeRegister(FIFO_EN,(accel*FIFO_ACCEL)|(gyro*FIFO_GYRO)|(mag*FIFO_MAG)|(temp*FIFO_TEMP)) < 0){
- return -2;
- }
- _enFifoAccel = accel;
- _enFifoGyro = gyro;
- _enFifoMag = mag;
- _enFifoTemp = temp;
- _fifoFrameSize = accel*6 + gyro*6 + mag*7 + temp*2;
- return 1;
-}
-
-/* reads the most current data from MPU9250 and stores in buffer */
-int MPU9250::readSensor() {
- _useSPIHS = true; // use the high speed SPI for data readout
- // grab the data from the MPU9250
- if (readRegisters(ACCEL_OUT, 21, _buffer) < 0) {
- return -1;
- }
- // combine into 16 bit values
- _axcounts = (((int16_t)_buffer[0]) << 8) | _buffer[1];
- _aycounts = (((int16_t)_buffer[2]) << 8) | _buffer[3];
- _azcounts = (((int16_t)_buffer[4]) << 8) | _buffer[5];
- _tcounts = (((int16_t)_buffer[6]) << 8) | _buffer[7];
- _gxcounts = (((int16_t)_buffer[8]) << 8) | _buffer[9];
- _gycounts = (((int16_t)_buffer[10]) << 8) | _buffer[11];
- _gzcounts = (((int16_t)_buffer[12]) << 8) | _buffer[13];
- _hxcounts = (((int16_t)_buffer[15]) << 8) | _buffer[14];
- _hycounts = (((int16_t)_buffer[17]) << 8) | _buffer[16];
- _hzcounts = (((int16_t)_buffer[19]) << 8) | _buffer[18];
- // transform and convert to float values
- _ax = (((float)(tX[0]*_axcounts + tX[1]*_aycounts + tX[2]*_azcounts) * _accelScale) - _axb)*_axs;
- _ay = (((float)(tY[0]*_axcounts + tY[1]*_aycounts + tY[2]*_azcounts) * _accelScale) - _ayb)*_ays;
- _az = (((float)(tZ[0]*_axcounts + tZ[1]*_aycounts + tZ[2]*_azcounts) * _accelScale) - _azb)*_azs;
- _gx = ((float)(tX[0]*_gxcounts + tX[1]*_gycounts + tX[2]*_gzcounts) * _gyroScale) - _gxb;
- _gy = ((float)(tY[0]*_gxcounts + tY[1]*_gycounts + tY[2]*_gzcounts) * _gyroScale) - _gyb;
- _gz = ((float)(tZ[0]*_gxcounts + tZ[1]*_gycounts + tZ[2]*_gzcounts) * _gyroScale) - _gzb;
- _hx = (((float)(_hxcounts) * _magScaleX) - _hxb)*_hxs;
- _hy = (((float)(_hycounts) * _magScaleY) - _hyb)*_hys;
- _hz = (((float)(_hzcounts) * _magScaleZ) - _hzb)*_hzs;
- _t = ((((float) _tcounts) - _tempOffset)/_tempScale) + _tempOffset;
- return 1;
-}
-
-/* returns the accelerometer measurement in the x direction, m/s/s */
-float MPU9250::getAccelX_mss() {
- return _ax;
-}
-
-/* returns the accelerometer measurement in the y direction, m/s/s */
-float MPU9250::getAccelY_mss() {
- return _ay;
-}
-
-/* returns the accelerometer measurement in the z direction, m/s/s */
-float MPU9250::getAccelZ_mss() {
- return _az;
-}
-
-/* returns the gyroscope measurement in the x direction, rad/s */
-float MPU9250::getGyroX_rads() {
- return _gx;
-}
-
-/* returns the gyroscope measurement in the y direction, rad/s */
-float MPU9250::getGyroY_rads() {
- return _gy;
-}
-
-/* returns the gyroscope measurement in the z direction, rad/s */
-float MPU9250::getGyroZ_rads() {
- return _gz;
-}
-
-/* returns the magnetometer measurement in the x direction, uT */
-float MPU9250::getMagX_uT() {
- return _hx;
-}
-
-/* returns the magnetometer measurement in the y direction, uT */
-float MPU9250::getMagY_uT() {
- return _hy;
-}
-
-/* returns the magnetometer measurement in the z direction, uT */
-float MPU9250::getMagZ_uT() {
- return _hz;
-}
-
-/* returns the die temperature, C */
-float MPU9250::getTemperature_C() {
- return _t;
-}
-
-/* reads data from the MPU9250 FIFO and stores in buffer */
-int MPU9250FIFO::readFifo() {
- _useSPIHS = true; // use the high speed SPI for data readout
- // get the fifo size
- readRegisters(FIFO_COUNT, 2, _buffer);
- _fifoSize = (((uint16_t) (_buffer[0]&0x0F)) <<8) + (((uint16_t) _buffer[1]));
- // read and parse the buffer
- for (size_t i=0; i < _fifoSize/_fifoFrameSize; i++) {
- // grab the data from the MPU9250
- if (readRegisters(FIFO_READ,_fifoFrameSize,_buffer) < 0) {
- return -1;
- }
- if (_enFifoAccel) {
- // combine into 16 bit values
- _axcounts = (((int16_t)_buffer[0]) << 8) | _buffer[1];
- _aycounts = (((int16_t)_buffer[2]) << 8) | _buffer[3];
- _azcounts = (((int16_t)_buffer[4]) << 8) | _buffer[5];
- // transform and convert to float values
- _axFifo[i] = (((float)(tX[0]*_axcounts + tX[1]*_aycounts + tX[2]*_azcounts) * _accelScale)-_axb)*_axs;
- _ayFifo[i] = (((float)(tY[0]*_axcounts + tY[1]*_aycounts + tY[2]*_azcounts) * _accelScale)-_ayb)*_ays;
- _azFifo[i] = (((float)(tZ[0]*_axcounts + tZ[1]*_aycounts + tZ[2]*_azcounts) * _accelScale)-_azb)*_azs;
- _aSize = _fifoSize/_fifoFrameSize;
- }
- if (_enFifoTemp) {
- // combine into 16 bit values
- _tcounts = (((int16_t)_buffer[0 + _enFifoAccel*6]) << 8) | _buffer[1 + _enFifoAccel*6];
- // transform and convert to float values
- _tFifo[i] = ((((float) _tcounts) - _tempOffset)/_tempScale) + _tempOffset;
- _tSize = _fifoSize/_fifoFrameSize;
- }
- if (_enFifoGyro) {
- // combine into 16 bit values
- _gxcounts = (((int16_t)_buffer[0 + _enFifoAccel*6 + _enFifoTemp*2]) << 8) | _buffer[1 + _enFifoAccel*6 + _enFifoTemp*2];
- _gycounts = (((int16_t)_buffer[2 + _enFifoAccel*6 + _enFifoTemp*2]) << 8) | _buffer[3 + _enFifoAccel*6 + _enFifoTemp*2];
- _gzcounts = (((int16_t)_buffer[4 + _enFifoAccel*6 + _enFifoTemp*2]) << 8) | _buffer[5 + _enFifoAccel*6 + _enFifoTemp*2];
- // transform and convert to float values
- _gxFifo[i] = ((float)(tX[0]*_gxcounts + tX[1]*_gycounts + tX[2]*_gzcounts) * _gyroScale) - _gxb;
- _gyFifo[i] = ((float)(tY[0]*_gxcounts + tY[1]*_gycounts + tY[2]*_gzcounts) * _gyroScale) - _gyb;
- _gzFifo[i] = ((float)(tZ[0]*_gxcounts + tZ[1]*_gycounts + tZ[2]*_gzcounts) * _gyroScale) - _gzb;
- _gSize = _fifoSize/_fifoFrameSize;
- }
- if (_enFifoMag) {
- // combine into 16 bit values
- _hxcounts = (((int16_t)_buffer[1 + _enFifoAccel*6 + _enFifoTemp*2 + _enFifoGyro*6]) << 8) | _buffer[0 + _enFifoAccel*6 + _enFifoTemp*2 + _enFifoGyro*6];
- _hycounts = (((int16_t)_buffer[3 + _enFifoAccel*6 + _enFifoTemp*2 + _enFifoGyro*6]) << 8) | _buffer[2 + _enFifoAccel*6 + _enFifoTemp*2 + _enFifoGyro*6];
- _hzcounts = (((int16_t)_buffer[5 + _enFifoAccel*6 + _enFifoTemp*2 + _enFifoGyro*6]) << 8) | _buffer[4 + _enFifoAccel*6 + _enFifoTemp*2 + _enFifoGyro*6];
- // transform and convert to float values
- _hxFifo[i] = (((float)(_hxcounts) * _magScaleX) - _hxb)*_hxs;
- _hyFifo[i] = (((float)(_hycounts) * _magScaleY) - _hyb)*_hys;
- _hzFifo[i] = (((float)(_hzcounts) * _magScaleZ) - _hzb)*_hzs;
- _hSize = _fifoSize/_fifoFrameSize;
- }
- }
- return 1;
-}
-
-/* returns the accelerometer FIFO size and data in the x direction, m/s/s */
-void MPU9250FIFO::getFifoAccelX_mss(size_t *size,float* data) {
- *size = _aSize;
- memcpy(data,_axFifo,_aSize*sizeof(float));
-}
-
-/* returns the accelerometer FIFO size and data in the y direction, m/s/s */
-void MPU9250FIFO::getFifoAccelY_mss(size_t *size,float* data) {
- *size = _aSize;
- memcpy(data,_ayFifo,_aSize*sizeof(float));
-}
-
-/* returns the accelerometer FIFO size and data in the z direction, m/s/s */
-void MPU9250FIFO::getFifoAccelZ_mss(size_t *size,float* data) {
- *size = _aSize;
- memcpy(data,_azFifo,_aSize*sizeof(float));
-}
-
-/* returns the gyroscope FIFO size and data in the x direction, rad/s */
-void MPU9250FIFO::getFifoGyroX_rads(size_t *size,float* data) {
- *size = _gSize;
- memcpy(data,_gxFifo,_gSize*sizeof(float));
-}
-
-/* returns the gyroscope FIFO size and data in the y direction, rad/s */
-void MPU9250FIFO::getFifoGyroY_rads(size_t *size,float* data) {
- *size = _gSize;
- memcpy(data,_gyFifo,_gSize*sizeof(float));
-}
-
-/* returns the gyroscope FIFO size and data in the z direction, rad/s */
-void MPU9250FIFO::getFifoGyroZ_rads(size_t *size,float* data) {
- *size = _gSize;
- memcpy(data,_gzFifo,_gSize*sizeof(float));
-}
-
-/* returns the magnetometer FIFO size and data in the x direction, uT */
-void MPU9250FIFO::getFifoMagX_uT(size_t *size,float* data) {
- *size = _hSize;
- memcpy(data,_hxFifo,_hSize*sizeof(float));
-}
-
-/* returns the magnetometer FIFO size and data in the y direction, uT */
-void MPU9250FIFO::getFifoMagY_uT(size_t *size,float* data) {
- *size = _hSize;
- memcpy(data,_hyFifo,_hSize*sizeof(float));
-}
-
-/* returns the magnetometer FIFO size and data in the z direction, uT */
-void MPU9250FIFO::getFifoMagZ_uT(size_t *size,float* data) {
- *size = _hSize;
- memcpy(data,_hzFifo,_hSize*sizeof(float));
-}
-
-/* returns the die temperature FIFO size and data, C */
-void MPU9250FIFO::getFifoTemperature_C(size_t *size,float* data) {
- *size = _tSize;
- memcpy(data,_tFifo,_tSize*sizeof(float));
-}
-
-/* estimates the gyro biases */
-int MPU9250::calibrateGyro() {
- // set the range, bandwidth, and srd
- if (setGyroRange(GYRO_RANGE_250DPS) < 0) {
- return -1;
- }
- if (setDlpfBandwidth(DLPF_BANDWIDTH_20HZ) < 0) {
- return -2;
- }
- if (setSrd(19) < 0) {
- return -3;
- }
-
- // take samples and find bias
- _gxbD = 0;
- _gybD = 0;
- _gzbD = 0;
- for (size_t i=0; i < _numSamples; i++) {
- readSensor();
- _gxbD += (getGyroX_rads() + _gxb)/((double)_numSamples);
- _gybD += (getGyroY_rads() + _gyb)/((double)_numSamples);
- _gzbD += (getGyroZ_rads() + _gzb)/((double)_numSamples);
- delay(20);
- }
- _gxb = (float)_gxbD;
- _gyb = (float)_gybD;
- _gzb = (float)_gzbD;
-
- // set the range, bandwidth, and srd back to what they were
- if (setGyroRange(_gyroRange) < 0) {
- return -4;
- }
- if (setDlpfBandwidth(_bandwidth) < 0) {
- return -5;
- }
- if (setSrd(_srd) < 0) {
- return -6;
- }
- return 1;
-}
-
-/* returns the gyro bias in the X direction, rad/s */
-float MPU9250::getGyroBiasX_rads() {
- return _gxb;
-}
-
-/* returns the gyro bias in the Y direction, rad/s */
-float MPU9250::getGyroBiasY_rads() {
- return _gyb;
-}
-
-/* returns the gyro bias in the Z direction, rad/s */
-float MPU9250::getGyroBiasZ_rads() {
- return _gzb;
-}
-
-/* sets the gyro bias in the X direction to bias, rad/s */
-void MPU9250::setGyroBiasX_rads(float bias) {
- _gxb = bias;
-}
-
-/* sets the gyro bias in the Y direction to bias, rad/s */
-void MPU9250::setGyroBiasY_rads(float bias) {
- _gyb = bias;
-}
-
-/* sets the gyro bias in the Z direction to bias, rad/s */
-void MPU9250::setGyroBiasZ_rads(float bias) {
- _gzb = bias;
-}
-
-/* finds bias and scale factor calibration for the accelerometer,
-this should be run for each axis in each direction (6 total) to find
-the min and max values along each */
-int MPU9250::calibrateAccel() {
- // set the range, bandwidth, and srd
- if (setAccelRange(ACCEL_RANGE_2G) < 0) {
- return -1;
- }
- if (setDlpfBandwidth(DLPF_BANDWIDTH_20HZ) < 0) {
- return -2;
- }
- if (setSrd(19) < 0) {
- return -3;
- }
-
- // take samples and find min / max
- _axbD = 0;
- _aybD = 0;
- _azbD = 0;
- for (size_t i=0; i < _numSamples; i++) {
- readSensor();
- _axbD += (getAccelX_mss()/_axs + _axb)/((double)_numSamples);
- _aybD += (getAccelY_mss()/_ays + _ayb)/((double)_numSamples);
- _azbD += (getAccelZ_mss()/_azs + _azb)/((double)_numSamples);
- delay(20);
- }
- if (_axbD > 9.0f) {
- _axmax = (float)_axbD;
- }
- if (_aybD > 9.0f) {
- _aymax = (float)_aybD;
- }
- if (_azbD > 9.0f) {
- _azmax = (float)_azbD;
- }
- if (_axbD < -9.0f) {
- _axmin = (float)_axbD;
- }
- if (_aybD < -9.0f) {
- _aymin = (float)_aybD;
- }
- if (_azbD < -9.0f) {
- _azmin = (float)_azbD;
- }
-
- // find bias and scale factor
- if ((abs(_axmin) > 9.0f) && (abs(_axmax) > 9.0f)) {
- _axb = (_axmin + _axmax) / 2.0f;
- _axs = G/((abs(_axmin) + abs(_axmax)) / 2.0f);
- }
- if ((abs(_aymin) > 9.0f) && (abs(_aymax) > 9.0f)) {
- _ayb = (_aymin + _aymax) / 2.0f;
- _ays = G/((abs(_aymin) + abs(_aymax)) / 2.0f);
- }
- if ((abs(_azmin) > 9.0f) && (abs(_azmax) > 9.0f)) {
- _azb = (_azmin + _azmax) / 2.0f;
- _azs = G/((abs(_azmin) + abs(_azmax)) / 2.0f);
- }
-
- // set the range, bandwidth, and srd back to what they were
- if (setAccelRange(_accelRange) < 0) {
- return -4;
- }
- if (setDlpfBandwidth(_bandwidth) < 0) {
- return -5;
- }
- if (setSrd(_srd) < 0) {
- return -6;
- }
- return 1;
-}
-
-/* returns the accelerometer bias in the X direction, m/s/s */
-float MPU9250::getAccelBiasX_mss() {
- return _axb;
-}
-
-/* returns the accelerometer scale factor in the X direction */
-float MPU9250::getAccelScaleFactorX() {
- return _axs;
-}
-
-/* returns the accelerometer bias in the Y direction, m/s/s */
-float MPU9250::getAccelBiasY_mss() {
- return _ayb;
-}
-
-/* returns the accelerometer scale factor in the Y direction */
-float MPU9250::getAccelScaleFactorY() {
- return _ays;
-}
-
-/* returns the accelerometer bias in the Z direction, m/s/s */
-float MPU9250::getAccelBiasZ_mss() {
- return _azb;
-}
-
-/* returns the accelerometer scale factor in the Z direction */
-float MPU9250::getAccelScaleFactorZ() {
- return _azs;
-}
-
-/* sets the accelerometer bias (m/s/s) and scale factor in the X direction */
-void MPU9250::setAccelCalX(float bias,float scaleFactor) {
- _axb = bias;
- _axs = scaleFactor;
-}
-
-/* sets the accelerometer bias (m/s/s) and scale factor in the Y direction */
-void MPU9250::setAccelCalY(float bias,float scaleFactor) {
- _ayb = bias;
- _ays = scaleFactor;
-}
-
-/* sets the accelerometer bias (m/s/s) and scale factor in the Z direction */
-void MPU9250::setAccelCalZ(float bias,float scaleFactor) {
- _azb = bias;
- _azs = scaleFactor;
-}
-
-/* finds bias and scale factor calibration for the magnetometer,
-the sensor should be rotated in a figure 8 motion until complete */
-int MPU9250::calibrateMag() {
- // set the srd
- if (setSrd(19) < 0) {
- return -1;
- }
-
- // get a starting set of data
- readSensor();
- _hxmax = getMagX_uT();
- _hxmin = getMagX_uT();
- _hymax = getMagY_uT();
- _hymin = getMagY_uT();
- _hzmax = getMagZ_uT();
- _hzmin = getMagZ_uT();
-
- // collect data to find max / min in each channel
- _counter = 0;
- while (_counter < _maxCounts) {
- _delta = 0.0f;
- _framedelta = 0.0f;
- readSensor();
- _hxfilt = (_hxfilt*((float)_coeff-1)+(getMagX_uT()/_hxs+_hxb))/((float)_coeff);
- _hyfilt = (_hyfilt*((float)_coeff-1)+(getMagY_uT()/_hys+_hyb))/((float)_coeff);
- _hzfilt = (_hzfilt*((float)_coeff-1)+(getMagZ_uT()/_hzs+_hzb))/((float)_coeff);
- if (_hxfilt > _hxmax) {
- _delta = _hxfilt - _hxmax;
- _hxmax = _hxfilt;
- }
- if (_delta > _framedelta) {
- _framedelta = _delta;
- }
- if (_hyfilt > _hymax) {
- _delta = _hyfilt - _hymax;
- _hymax = _hyfilt;
- }
- if (_delta > _framedelta) {
- _framedelta = _delta;
- }
- if (_hzfilt > _hzmax) {
- _delta = _hzfilt - _hzmax;
- _hzmax = _hzfilt;
- }
- if (_delta > _framedelta) {
- _framedelta = _delta;
- }
- if (_hxfilt < _hxmin) {
- _delta = abs(_hxfilt - _hxmin);
- _hxmin = _hxfilt;
- }
- if (_delta > _framedelta) {
- _framedelta = _delta;
- }
- if (_hyfilt < _hymin) {
- _delta = abs(_hyfilt - _hymin);
- _hymin = _hyfilt;
- }
- if (_delta > _framedelta) {
- _framedelta = _delta;
- }
- if (_hzfilt < _hzmin) {
- _delta = abs(_hzfilt - _hzmin);
- _hzmin = _hzfilt;
- }
- if (_delta > _framedelta) {
- _framedelta = _delta;
- }
- if (_framedelta > _deltaThresh) {
- _counter = 0;
- } else {
- _counter++;
- }
- delay(20);
- }
-
- // find the magnetometer bias
- _hxb = (_hxmax + _hxmin) / 2.0f;
- _hyb = (_hymax + _hymin) / 2.0f;
- _hzb = (_hzmax + _hzmin) / 2.0f;
-
- // find the magnetometer scale factor
- _hxs = (_hxmax - _hxmin) / 2.0f;
- _hys = (_hymax - _hymin) / 2.0f;
- _hzs = (_hzmax - _hzmin) / 2.0f;
- _avgs = (_hxs + _hys + _hzs) / 3.0f;
- _hxs = _avgs/_hxs;
- _hys = _avgs/_hys;
- _hzs = _avgs/_hzs;
-
- // set the srd back to what it was
- if (setSrd(_srd) < 0) {
- return -2;
- }
- return 1;
-}
-
-/* returns the magnetometer bias in the X direction, uT */
-float MPU9250::getMagBiasX_uT() {
- return _hxb;
-}
-
-/* returns the magnetometer scale factor in the X direction */
-float MPU9250::getMagScaleFactorX() {
- return _hxs;
-}
-
-/* returns the magnetometer bias in the Y direction, uT */
-float MPU9250::getMagBiasY_uT() {
- return _hyb;
-}
-
-/* returns the magnetometer scale factor in the Y direction */
-float MPU9250::getMagScaleFactorY() {
- return _hys;
-}
-
-/* returns the magnetometer bias in the Z direction, uT */
-float MPU9250::getMagBiasZ_uT() {
- return _hzb;
-}
-
-/* returns the magnetometer scale factor in the Z direction */
-float MPU9250::getMagScaleFactorZ() {
- return _hzs;
-}
-
-/* sets the magnetometer bias (uT) and scale factor in the X direction */
-void MPU9250::setMagCalX(float bias,float scaleFactor) {
- _hxb = bias;
- _hxs = scaleFactor;
-}
-
-/* sets the magnetometer bias (uT) and scale factor in the Y direction */
-void MPU9250::setMagCalY(float bias,float scaleFactor) {
- _hyb = bias;
- _hys = scaleFactor;
-}
-
-/* sets the magnetometer bias (uT) and scale factor in the Z direction */
-void MPU9250::setMagCalZ(float bias,float scaleFactor) {
- _hzb = bias;
- _hzs = scaleFactor;
-}
-
-#if defined(__IMXRT1062__)
-/* writes a byte to MPU9250 register given a register address and data */
-int MPU9250::writeRegister(uint8_t subAddress, uint8_t data){
- /* write data to device */
- if( _useSPI ){
- _spi->beginTransaction(SPISettings(SPI_LS_CLOCK, MSBFIRST, SPI_MODE3)); // begin the transaction
- digitalWriteFast(_csPin,LOW); // select the MPU9250 chip
- delayNanoseconds(200);
- _spi->transfer(subAddress); // write the register address
- _spi->transfer(data); // write the data
- digitalWriteFast(_csPin,HIGH); // deselect the MPU9250 chip
- delayNanoseconds(200);
- _spi->endTransaction(); // end the transaction
- }
- else{
- _i2c->beginTransmission(_address); // open the device
- _i2c->write(subAddress); // write the register address
- _i2c->write(data); // write the data
- _i2c->endTransmission();
- }
-
- delay(10);
-
- /* read back the register */
- readRegisters(subAddress,1,_buffer);
- /* check the read back register against the written register */
- if(_buffer[0] == data) {
- return 1;
- }
- else{
- return -1;
- }
-}
-
-/* reads registers from MPU9250 given a starting register address, number of bytes, and a pointer to store data */
-int MPU9250::readRegisters(uint8_t subAddress, uint8_t count, uint8_t* dest){
- if( _useSPI ){
- // begin the transaction
- if(_useSPIHS){
- _spi->beginTransaction(SPISettings(SPI_HS_CLOCK, MSBFIRST, SPI_MODE3));
- }
- else{
- _spi->beginTransaction(SPISettings(SPI_LS_CLOCK, MSBFIRST, SPI_MODE3));
- }
- digitalWriteFast(_csPin,LOW); // select the MPU9250 chip
- delayNanoseconds(200);
- _spi->transfer(subAddress | SPI_READ); // specify the starting register address
- for(uint8_t i = 0; i < count; i++){
- dest[i] = _spi->transfer(0x00); // read the data
- }
- digitalWriteFast(_csPin,HIGH); // deselect the MPU9250 chip
- delayNanoseconds(200);
- _spi->endTransaction(); // end the transaction
- return 1;
- }
- else{
- _i2c->beginTransmission(_address); // open the device
- _i2c->write(subAddress); // specify the starting register address
- _i2c->endTransmission(false);
- _numBytes = _i2c->requestFrom(_address, count); // specify the number of bytes to receive
- if (_numBytes == count) {
- for(uint8_t i = 0; i < count; i++){
- dest[i] = _i2c->read();
- }
- return 1;
- } else {
- return -1;
- }
- }
-}
-#else
-/* writes a byte to MPU9250 register given a register address and data */
-int MPU9250::writeRegister(uint8_t subAddress, uint8_t data){
- /* write data to device */
- if( _useSPI ){
- _spi->beginTransaction(SPISettings(SPI_LS_CLOCK, MSBFIRST, SPI_MODE3)); // begin the transaction
- digitalWrite(_csPin,LOW); // select the MPU9250 chip
- _spi->transfer(subAddress); // write the register address
- _spi->transfer(data); // write the data
- digitalWrite(_csPin,HIGH); // deselect the MPU9250 chip
- _spi->endTransaction(); // end the transaction
- }
- else{
- _i2c->beginTransmission(_address); // open the device
- _i2c->write(subAddress); // write the register address
- _i2c->write(data); // write the data
- _i2c->endTransmission();
- }
-
- delay(10);
-
- /* read back the register */
- readRegisters(subAddress,1,_buffer);
- /* check the read back register against the written register */
- if(_buffer[0] == data) {
- return 1;
- }
- else{
- return -1;
- }
-}
-
-/* reads registers from MPU9250 given a starting register address, number of bytes, and a pointer to store data */
-int MPU9250::readRegisters(uint8_t subAddress, uint8_t count, uint8_t* dest){
- if( _useSPI ){
- // begin the transaction
- if(_useSPIHS){
- _spi->beginTransaction(SPISettings(SPI_HS_CLOCK, MSBFIRST, SPI_MODE3));
- }
- else{
- _spi->beginTransaction(SPISettings(SPI_LS_CLOCK, MSBFIRST, SPI_MODE3));
- }
- digitalWrite(_csPin,LOW); // select the MPU9250 chip
- _spi->transfer(subAddress | SPI_READ); // specify the starting register address
- for(uint8_t i = 0; i < count; i++){
- dest[i] = _spi->transfer(0x00); // read the data
- }
- digitalWrite(_csPin,HIGH); // deselect the MPU9250 chip
- _spi->endTransaction(); // end the transaction
- return 1;
- }
- else{
- _i2c->beginTransmission(_address); // open the device
- _i2c->write(subAddress); // specify the starting register address
- _i2c->endTransmission(false);
- _numBytes = _i2c->requestFrom(_address, count); // specify the number of bytes to receive
- if (_numBytes == count) {
- for(uint8_t i = 0; i < count; i++){
- dest[i] = _i2c->read();
- }
- return 1;
- } else {
- return -1;
- }
- }
-}
-#endif
-
-/* writes a register to the AK8963 given a register address and data */
-int MPU9250::writeAK8963Register(uint8_t subAddress, uint8_t data){
- // set slave 0 to the AK8963 and set for write
- if (writeRegister(I2C_SLV0_ADDR,AK8963_I2C_ADDR) < 0) {
- return -1;
- }
- // set the register to the desired AK8963 sub address
- if (writeRegister(I2C_SLV0_REG,subAddress) < 0) {
- return -2;
- }
- // store the data for write
- if (writeRegister(I2C_SLV0_DO,data) < 0) {
- return -3;
- }
- // enable I2C and send 1 byte
- if (writeRegister(I2C_SLV0_CTRL,I2C_SLV0_EN | (uint8_t)1) < 0) {
- return -4;
- }
- // read the register and confirm
- if (readAK8963Registers(subAddress,1,_buffer) < 0) {
- return -5;
- }
- if(_buffer[0] == data) {
- return 1;
- } else{
- return -6;
- }
-}
-
-/* reads registers from the AK8963 */
-int MPU9250::readAK8963Registers(uint8_t subAddress, uint8_t count, uint8_t* dest){
- // set slave 0 to the AK8963 and set for read
- if (writeRegister(I2C_SLV0_ADDR,AK8963_I2C_ADDR | I2C_READ_FLAG) < 0) {
- return -1;
- }
- // set the register to the desired AK8963 sub address
- if (writeRegister(I2C_SLV0_REG,subAddress) < 0) {
- return -2;
- }
- // enable I2C and request the bytes
- if (writeRegister(I2C_SLV0_CTRL,I2C_SLV0_EN | count) < 0) {
- return -3;
- }
- delay(1); // takes some time for these registers to fill
- // read the bytes off the MPU9250 EXT_SENS_DATA registers
- _status = readRegisters(EXT_SENS_DATA_00,count,dest);
- return _status;
-}
-
-/* gets the MPU9250 WHO_AM_I register value, expected to be 0x71 */
-int MPU9250::whoAmI(){
- // read the WHO AM I register
- if (readRegisters(WHO_AM_I,1,_buffer) < 0) {
- return -1;
- }
- // return the register value
- return _buffer[0];
-}
-
-/* gets the AK8963 WHO_AM_I register value, expected to be 0x48 */
-int MPU9250::whoAmIAK8963(){
- // read the WHO AM I register
- if (readAK8963Registers(AK8963_WHO_AM_I,1,_buffer) < 0) {
- return -1;
- }
- // return the register value
- return _buffer[0];
-}
-
-// jihlein additions start
-
-void MPU9250::getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz) {
- uint8_t buffer[14];
- readRegisters(ACCEL_OUT, 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];
- *gx = (((int16_t)buffer[8]) << 8) | buffer[9];
- *gy = (((int16_t)buffer[10]) << 8) | buffer[11];
- *gz = (((int16_t)buffer[12]) << 8) | buffer[13];
-}
-
-void MPU9250::getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz) {
- uint8_t buffer[20];
- readRegisters(ACCEL_OUT, 20, 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];
- *gx = (((int16_t)buffer[8]) << 8) | buffer[9];
- *gy = (((int16_t)buffer[10]) << 8) | buffer[11];
- *gz = (((int16_t)buffer[12]) << 8) | buffer[13];
- *mx = (((int16_t)buffer[15]) << 8) | buffer[14];
- *my = (((int16_t)buffer[17]) << 8) | buffer[16];
- *mz = (((int16_t)buffer[19]) << 8) | buffer[18];
-}
-
-// jihlein additions end
\ No newline at end of file
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU9250/MPU9250.h b/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU9250/MPU9250.h
deleted file mode 100644
index bbbe2c5a..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/MPU9250/MPU9250.h
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- MPU9250.h
- Brian R Taylor
- brian.taylor@bolderflight.com
-
- Copyright (c) 2017 Bolder Flight Systems
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#ifndef MPU9250_h
-#define MPU9250_h
-
-#include "Arduino.h"
-#include "Wire.h" // I2C library
-#include "SPI.h" // SPI library
-
-class MPU9250{
- public:
- enum GyroRange
- {
- GYRO_RANGE_250DPS,
- GYRO_RANGE_500DPS,
- GYRO_RANGE_1000DPS,
- GYRO_RANGE_2000DPS
- };
- enum AccelRange
- {
- ACCEL_RANGE_2G,
- ACCEL_RANGE_4G,
- ACCEL_RANGE_8G,
- ACCEL_RANGE_16G
- };
- enum DlpfBandwidth
- {
- DLPF_BANDWIDTH_184HZ,
- DLPF_BANDWIDTH_92HZ,
- DLPF_BANDWIDTH_41HZ,
- DLPF_BANDWIDTH_20HZ,
- DLPF_BANDWIDTH_10HZ,
- DLPF_BANDWIDTH_5HZ
- };
- enum LpAccelOdr
- {
- LP_ACCEL_ODR_0_24HZ = 0,
- LP_ACCEL_ODR_0_49HZ = 1,
- LP_ACCEL_ODR_0_98HZ = 2,
- LP_ACCEL_ODR_1_95HZ = 3,
- LP_ACCEL_ODR_3_91HZ = 4,
- LP_ACCEL_ODR_7_81HZ = 5,
- LP_ACCEL_ODR_15_63HZ = 6,
- LP_ACCEL_ODR_31_25HZ = 7,
- LP_ACCEL_ODR_62_50HZ = 8,
- LP_ACCEL_ODR_125HZ = 9,
- LP_ACCEL_ODR_250HZ = 10,
- LP_ACCEL_ODR_500HZ = 11
- };
- MPU9250(TwoWire &bus,uint8_t address);
- MPU9250(SPIClass &bus,uint8_t csPin);
- int begin();
- int setAccelRange(AccelRange range);
- int setGyroRange(GyroRange range);
- int setDlpfBandwidth(DlpfBandwidth bandwidth);
- int setSrd(uint8_t srd);
- int enableDataReadyInterrupt();
- int disableDataReadyInterrupt();
- int enableWakeOnMotion(float womThresh_mg,LpAccelOdr odr);
- int readSensor();
- float getAccelX_mss();
- float getAccelY_mss();
- float getAccelZ_mss();
- float getGyroX_rads();
- float getGyroY_rads();
- float getGyroZ_rads();
- float getMagX_uT();
- float getMagY_uT();
- float getMagZ_uT();
- float getTemperature_C();
-
- int calibrateGyro();
- float getGyroBiasX_rads();
- float getGyroBiasY_rads();
- float getGyroBiasZ_rads();
- void setGyroBiasX_rads(float bias);
- void setGyroBiasY_rads(float bias);
- void setGyroBiasZ_rads(float bias);
- int calibrateAccel();
- float getAccelBiasX_mss();
- float getAccelScaleFactorX();
- float getAccelBiasY_mss();
- float getAccelScaleFactorY();
- float getAccelBiasZ_mss();
- float getAccelScaleFactorZ();
- void setAccelCalX(float bias,float scaleFactor);
- void setAccelCalY(float bias,float scaleFactor);
- void setAccelCalZ(float bias,float scaleFactor);
- int calibrateMag();
- float getMagBiasX_uT();
- float getMagScaleFactorX();
- float getMagBiasY_uT();
- float getMagScaleFactorY();
- float getMagBiasZ_uT();
- float getMagScaleFactorZ();
- void setMagCalX(float bias,float scaleFactor);
- void setMagCalY(float bias,float scaleFactor);
- void setMagCalZ(float bias,float scaleFactor);
- // jihlein additions start
- void getMotion9(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz, int16_t* mx, int16_t* my, int16_t* mz);
- void getMotion6(int16_t* ax, int16_t* ay, int16_t* az, int16_t* gx, int16_t* gy, int16_t* gz);
- // jihlein additions end
- protected:
- // i2c
- uint8_t _address;
- TwoWire *_i2c;
- const uint32_t _i2cRate = 400000; // 400 kHz
- size_t _numBytes; // number of bytes received from I2C
- // spi
- SPIClass *_spi;
- uint8_t _csPin;
- bool _useSPI;
- bool _useSPIHS;
- const uint8_t SPI_READ = 0x80;
- const uint32_t SPI_LS_CLOCK = 1000000; // 1 MHz
- const uint32_t SPI_HS_CLOCK = 15000000; // 15 MHz
- // track success of interacting with sensor
- int _status;
- // buffer for reading from sensor
- uint8_t _buffer[21];
- // data counts
- int16_t _axcounts,_aycounts,_azcounts;
- int16_t _gxcounts,_gycounts,_gzcounts;
- int16_t _hxcounts,_hycounts,_hzcounts;
- int16_t _tcounts;
- // data buffer
- float _ax, _ay, _az;
- float _gx, _gy, _gz;
- float _hx, _hy, _hz;
- float _t;
- // wake on motion
- uint8_t _womThreshold;
- // scale factors
- float _accelScale;
- float _gyroScale;
- float _magScaleX, _magScaleY, _magScaleZ;
- const float _tempScale = 333.87f;
- const float _tempOffset = 21.0f;
- // configuration
- AccelRange _accelRange;
- GyroRange _gyroRange;
- DlpfBandwidth _bandwidth;
- uint8_t _srd;
- // gyro bias estimation
- size_t _numSamples = 100;
- double _gxbD, _gybD, _gzbD;
- float _gxb, _gyb, _gzb;
- // accel bias and scale factor estimation
- double _axbD, _aybD, _azbD;
- float _axmax, _aymax, _azmax;
- float _axmin, _aymin, _azmin;
- float _axb, _ayb, _azb;
- float _axs = 1.0f;
- float _ays = 1.0f;
- float _azs = 1.0f;
- // magnetometer bias and scale factor estimation
- uint16_t _maxCounts = 1000;
- float _deltaThresh = 0.3f;
- uint8_t _coeff = 8;
- uint16_t _counter;
- float _framedelta, _delta;
- float _hxfilt, _hyfilt, _hzfilt;
- float _hxmax, _hymax, _hzmax;
- float _hxmin, _hymin, _hzmin;
- float _hxb, _hyb, _hzb;
- float _hxs = 1.0f;
- float _hys = 1.0f;
- float _hzs = 1.0f;
- float _avgs;
- // transformation matrix
- /* transform the accel and gyro axes to match the magnetometer axes */
- const int16_t tX[3] = {0, 1, 0};
- const int16_t tY[3] = {1, 0, 0};
- const int16_t tZ[3] = {0, 0, -1};
- // constants
- const float G = 9.807f;
- const float _d2r = 3.14159265359f/180.0f;
- // MPU9250 registers
- const uint8_t ACCEL_OUT = 0x3B;
- const uint8_t GYRO_OUT = 0x43;
- const uint8_t TEMP_OUT = 0x41;
- const uint8_t EXT_SENS_DATA_00 = 0x49;
- const uint8_t ACCEL_CONFIG = 0x1C;
- const uint8_t ACCEL_FS_SEL_2G = 0x00;
- const uint8_t ACCEL_FS_SEL_4G = 0x08;
- const uint8_t ACCEL_FS_SEL_8G = 0x10;
- const uint8_t ACCEL_FS_SEL_16G = 0x18;
- const uint8_t GYRO_CONFIG = 0x1B;
- const uint8_t GYRO_FS_SEL_250DPS = 0x00;
- const uint8_t GYRO_FS_SEL_500DPS = 0x08;
- const uint8_t GYRO_FS_SEL_1000DPS = 0x10;
- const uint8_t GYRO_FS_SEL_2000DPS = 0x18;
- const uint8_t ACCEL_CONFIG2 = 0x1D;
- const uint8_t ACCEL_DLPF_184 = 0x01;
- const uint8_t ACCEL_DLPF_92 = 0x02;
- const uint8_t ACCEL_DLPF_41 = 0x03;
- const uint8_t ACCEL_DLPF_20 = 0x04;
- const uint8_t ACCEL_DLPF_10 = 0x05;
- const uint8_t ACCEL_DLPF_5 = 0x06;
- const uint8_t CONFIG = 0x1A;
- const uint8_t GYRO_DLPF_184 = 0x01;
- const uint8_t GYRO_DLPF_92 = 0x02;
- const uint8_t GYRO_DLPF_41 = 0x03;
- const uint8_t GYRO_DLPF_20 = 0x04;
- const uint8_t GYRO_DLPF_10 = 0x05;
- const uint8_t GYRO_DLPF_5 = 0x06;
- const uint8_t SMPDIV = 0x19;
- const uint8_t INT_PIN_CFG = 0x37;
- const uint8_t INT_ENABLE = 0x38;
- const uint8_t INT_DISABLE = 0x00;
- const uint8_t INT_PULSE_50US = 0x00;
- const uint8_t INT_WOM_EN = 0x40;
- const uint8_t INT_RAW_RDY_EN = 0x01;
- const uint8_t PWR_MGMNT_1 = 0x6B;
- const uint8_t PWR_CYCLE = 0x20;
- const uint8_t PWR_RESET = 0x80;
- const uint8_t CLOCK_SEL_PLL = 0x01;
- const uint8_t PWR_MGMNT_2 = 0x6C;
- const uint8_t SEN_ENABLE = 0x00;
- const uint8_t DIS_GYRO = 0x07;
- const uint8_t USER_CTRL = 0x6A;
- const uint8_t I2C_MST_EN = 0x20;
- const uint8_t I2C_MST_CLK = 0x0D;
- const uint8_t I2C_MST_CTRL = 0x24;
- const uint8_t I2C_SLV0_ADDR = 0x25;
- const uint8_t I2C_SLV0_REG = 0x26;
- const uint8_t I2C_SLV0_DO = 0x63;
- const uint8_t I2C_SLV0_CTRL = 0x27;
- const uint8_t I2C_SLV0_EN = 0x80;
- const uint8_t I2C_READ_FLAG = 0x80;
- const uint8_t MOT_DETECT_CTRL = 0x69;
- const uint8_t ACCEL_INTEL_EN = 0x80;
- const uint8_t ACCEL_INTEL_MODE = 0x40;
- const uint8_t LP_ACCEL_ODR = 0x1E;
- const uint8_t WOM_THR = 0x1F;
- const uint8_t WHO_AM_I = 0x75;
- const uint8_t FIFO_EN = 0x23;
- const uint8_t FIFO_TEMP = 0x80;
- const uint8_t FIFO_GYRO = 0x70;
- const uint8_t FIFO_ACCEL = 0x08;
- const uint8_t FIFO_MAG = 0x01;
- const uint8_t FIFO_COUNT = 0x72;
- const uint8_t FIFO_READ = 0x74;
- // AK8963 registers
- const uint8_t AK8963_I2C_ADDR = 0x0C;
- const uint8_t AK8963_HXL = 0x03;
- const uint8_t AK8963_CNTL1 = 0x0A;
- const uint8_t AK8963_PWR_DOWN = 0x00;
- const uint8_t AK8963_CNT_MEAS1 = 0x12;
- const uint8_t AK8963_CNT_MEAS2 = 0x16;
- const uint8_t AK8963_FUSE_ROM = 0x0F;
- const uint8_t AK8963_CNTL2 = 0x0B;
- const uint8_t AK8963_RESET = 0x01;
- const uint8_t AK8963_ASA = 0x10;
- const uint8_t AK8963_WHO_AM_I = 0x00;
- // private functions
- int writeRegister(uint8_t subAddress, uint8_t data);
- int readRegisters(uint8_t subAddress, uint8_t count, uint8_t* dest);
- int writeAK8963Register(uint8_t subAddress, uint8_t data);
- int readAK8963Registers(uint8_t subAddress, uint8_t count, uint8_t* dest);
- int whoAmI();
- int whoAmIAK8963();
-};
-
-class MPU9250FIFO: public MPU9250 {
- public:
- using MPU9250::MPU9250;
- int enableFifo(bool accel,bool gyro,bool mag,bool temp);
- int readFifo();
- void getFifoAccelX_mss(size_t *size,float* data);
- void getFifoAccelY_mss(size_t *size,float* data);
- void getFifoAccelZ_mss(size_t *size,float* data);
- void getFifoGyroX_rads(size_t *size,float* data);
- void getFifoGyroY_rads(size_t *size,float* data);
- void getFifoGyroZ_rads(size_t *size,float* data);
- void getFifoMagX_uT(size_t *size,float* data);
- void getFifoMagY_uT(size_t *size,float* data);
- void getFifoMagZ_uT(size_t *size,float* data);
- void getFifoTemperature_C(size_t *size,float* data);
- protected:
- // fifo
- bool _enFifoAccel,_enFifoGyro,_enFifoMag,_enFifoTemp;
- size_t _fifoSize,_fifoFrameSize;
- float _axFifo[85], _ayFifo[85], _azFifo[85];
- size_t _aSize;
- float _gxFifo[85], _gyFifo[85], _gzFifo[85];
- size_t _gSize;
- float _hxFifo[73], _hyFifo[73], _hzFifo[73];
- size_t _hSize;
- float _tFifo[256];
- size_t _tSize;
-};
-
-#endif
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/SBUS/SBUS.cpp b/Versions/dRehmFlight_Teensy_BETA_1.2/src/SBUS/SBUS.cpp
deleted file mode 100644
index 07085420..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/SBUS/SBUS.cpp
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- SBUS.cpp
- Brian R Taylor
- brian.taylor@bolderflight.com
-
- Copyright (c) 2016 Bolder Flight Systems
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#include "SBUS.h"
-
-// SEE: https://learn.adafruit.com/adafruit-feather-m0-basic-proto/adapting-sketches-to-m0
-#if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL)
- // Required for Serial on Zero based boards
- #define Serial SERIAL_PORT_USBVIRTUAL
-#endif
-
-#if defined(__MK20DX128__) || defined(__MK20DX256__)
- // globals needed for emulating two stop bytes on Teensy 3.0 and 3.1/3.2
- IntervalTimer serialTimer;
- HardwareSerial* SERIALPORT;
- uint8_t PACKET[25];
- volatile int SENDINDEX;
- void sendByte();
-#endif
-/* SBUS object, input the serial bus */
-SBUS::SBUS(HardwareSerial& bus)
-{
- _bus = &bus;
-}
-
-/* starts the serial communication */
-void SBUS::begin()
-{
- // initialize parsing state
- _parserState = 0;
- // initialize default scale factors and biases
- for (uint8_t i = 0; i < _numChannels; i++) {
- setEndPoints(i,_defaultMin,_defaultMax);
- }
- // begin the serial port for SBUS
- #if defined(__MK20DX128__) || defined(__MK20DX256__) // Teensy 3.0 || Teensy 3.1/3.2
- _bus->begin(_sbusBaud,SERIAL_8E1_RXINV_TXINV);
- SERIALPORT = _bus;
- #elif defined(__IMXRT1062__) || defined(__IMXRT1052__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__) // Teensy 4.0 || Teensy 4.0 Beta || Teensy 3.5 || Teensy 3.6 || Teensy LC
- _bus->begin(_sbusBaud,SERIAL_8E2_RXINV_TXINV);
- #elif defined(STM32L496xx) || defined(STM32L476xx) || defined(STM32L433xx) || defined(STM32L432xx) // STM32L4
- _bus->begin(_sbusBaud,SERIAL_SBUS);
- #elif defined(_BOARD_MAPLE_MINI_H_) // Maple Mini
- _bus->begin(_sbusBaud,SERIAL_8E2);
- #elif defined(ESP32) // ESP32
- _bus->begin(_sbusBaud,SERIAL_8E2);
- #elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32U4__) // Arduino Mega 2560, 328P or 32u4
- _bus->begin(_sbusBaud, SERIAL_8E2);
- #elif defined(ARDUINO_SAMD_ZERO) // Adafruit Feather M0
- _bus->begin(_sbusBaud, SERIAL_8E2);
- #else
- #error unsupported device
- #endif
-}
-
-/* read the SBUS data */
-bool SBUS::read(uint16_t* channels, bool* failsafe, bool* lostFrame)
-{
- // parse the SBUS packet
- if (parse()) {
- if (channels) {
- // 16 channels of 11 bit data
- channels[0] = (uint16_t) ((_payload[0] |_payload[1] <<8) & 0x07FF);
- channels[1] = (uint16_t) ((_payload[1]>>3 |_payload[2] <<5) & 0x07FF);
- channels[2] = (uint16_t) ((_payload[2]>>6 |_payload[3] <<2 |_payload[4]<<10) & 0x07FF);
- channels[3] = (uint16_t) ((_payload[4]>>1 |_payload[5] <<7) & 0x07FF);
- channels[4] = (uint16_t) ((_payload[5]>>4 |_payload[6] <<4) & 0x07FF);
- channels[5] = (uint16_t) ((_payload[6]>>7 |_payload[7] <<1 |_payload[8]<<9) & 0x07FF);
- channels[6] = (uint16_t) ((_payload[8]>>2 |_payload[9] <<6) & 0x07FF);
- channels[7] = (uint16_t) ((_payload[9]>>5 |_payload[10]<<3) & 0x07FF);
- channels[8] = (uint16_t) ((_payload[11] |_payload[12]<<8) & 0x07FF);
- channels[9] = (uint16_t) ((_payload[12]>>3|_payload[13]<<5) & 0x07FF);
- channels[10] = (uint16_t) ((_payload[13]>>6|_payload[14]<<2 |_payload[15]<<10) & 0x07FF);
- channels[11] = (uint16_t) ((_payload[15]>>1|_payload[16]<<7) & 0x07FF);
- channels[12] = (uint16_t) ((_payload[16]>>4|_payload[17]<<4) & 0x07FF);
- channels[13] = (uint16_t) ((_payload[17]>>7|_payload[18]<<1 |_payload[19]<<9) & 0x07FF);
- channels[14] = (uint16_t) ((_payload[19]>>2|_payload[20]<<6) & 0x07FF);
- channels[15] = (uint16_t) ((_payload[20]>>5|_payload[21]<<3) & 0x07FF);
- }
- if (lostFrame) {
- // count lost frames
- if (_payload[22] & _sbusLostFrame) {
- *lostFrame = true;
- } else {
- *lostFrame = false;
- }
- }
- if (failsafe) {
- // failsafe state
- if (_payload[22] & _sbusFailSafe) {
- *failsafe = true;
- }
- else{
- *failsafe = false;
- }
- }
- // return true on receiving a full packet
- return true;
- } else {
- // return false if a full packet is not received
- return false;
- }
-}
-
-/* read the SBUS data and calibrate it to +/- 1 */
-bool SBUS::readCal(float* calChannels, bool* failsafe, bool* lostFrame)
-{
- uint16_t channels[_numChannels];
- // read the SBUS data
- if(read(&channels[0],failsafe,lostFrame)) {
- // linear calibration
- for (uint8_t i = 0; i < _numChannels; i++) {
- calChannels[i] = channels[i] * _sbusScale[i] + _sbusBias[i];
- if (_useReadCoeff[i]) {
- calChannels[i] = PolyVal(_readLen[i],_readCoeff[i],calChannels[i]);
- }
- }
- // return true on receiving a full packet
- return true;
- } else {
- // return false if a full packet is not received
- return false;
- }
-}
-
-/* write SBUS packets */
-void SBUS::write(uint16_t* channels)
-{
- static uint8_t packet[25];
- /* assemble the SBUS packet */
- // SBUS header
- packet[0] = _sbusHeader;
- // 16 channels of 11 bit data
- if (channels) {
- packet[1] = (uint8_t) ((channels[0] & 0x07FF));
- packet[2] = (uint8_t) ((channels[0] & 0x07FF)>>8 | (channels[1] & 0x07FF)<<3);
- packet[3] = (uint8_t) ((channels[1] & 0x07FF)>>5 | (channels[2] & 0x07FF)<<6);
- packet[4] = (uint8_t) ((channels[2] & 0x07FF)>>2);
- packet[5] = (uint8_t) ((channels[2] & 0x07FF)>>10 | (channels[3] & 0x07FF)<<1);
- packet[6] = (uint8_t) ((channels[3] & 0x07FF)>>7 | (channels[4] & 0x07FF)<<4);
- packet[7] = (uint8_t) ((channels[4] & 0x07FF)>>4 | (channels[5] & 0x07FF)<<7);
- packet[8] = (uint8_t) ((channels[5] & 0x07FF)>>1);
- packet[9] = (uint8_t) ((channels[5] & 0x07FF)>>9 | (channels[6] & 0x07FF)<<2);
- packet[10] = (uint8_t) ((channels[6] & 0x07FF)>>6 | (channels[7] & 0x07FF)<<5);
- packet[11] = (uint8_t) ((channels[7] & 0x07FF)>>3);
- packet[12] = (uint8_t) ((channels[8] & 0x07FF));
- packet[13] = (uint8_t) ((channels[8] & 0x07FF)>>8 | (channels[9] & 0x07FF)<<3);
- packet[14] = (uint8_t) ((channels[9] & 0x07FF)>>5 | (channels[10] & 0x07FF)<<6);
- packet[15] = (uint8_t) ((channels[10] & 0x07FF)>>2);
- packet[16] = (uint8_t) ((channels[10] & 0x07FF)>>10 | (channels[11] & 0x07FF)<<1);
- packet[17] = (uint8_t) ((channels[11] & 0x07FF)>>7 | (channels[12] & 0x07FF)<<4);
- packet[18] = (uint8_t) ((channels[12] & 0x07FF)>>4 | (channels[13] & 0x07FF)<<7);
- packet[19] = (uint8_t) ((channels[13] & 0x07FF)>>1);
- packet[20] = (uint8_t) ((channels[13] & 0x07FF)>>9 | (channels[14] & 0x07FF)<<2);
- packet[21] = (uint8_t) ((channels[14] & 0x07FF)>>6 | (channels[15] & 0x07FF)<<5);
- packet[22] = (uint8_t) ((channels[15] & 0x07FF)>>3);
- }
- // flags
- packet[23] = 0x00;
- // footer
- packet[24] = _sbusFooter;
- #if defined(__MK20DX128__) || defined(__MK20DX256__) // Teensy 3.0 || Teensy 3.1/3.2
- // use ISR to send byte at a time,
- // 130 us between bytes to emulate 2 stop bits
- noInterrupts();
- memcpy(&PACKET,&packet,sizeof(packet));
- interrupts();
- serialTimer.priority(255);
- serialTimer.begin(sendByte,130);
- #else
- // write packet
- _bus->write(packet,25);
- #endif
-}
-
-/* write SBUS packets from calibrated inputs */
-void SBUS::writeCal(float* calChannels)
-{
- uint16_t channels[_numChannels] = {0};
- // linear calibration
- if (calChannels) {
- for (uint8_t i = 0; i < _numChannels; i++) {
- if (_useWriteCoeff[i]) {
- calChannels[i] = PolyVal(_writeLen[i],_writeCoeff[i],calChannels[i]);
- }
- channels[i] = (calChannels[i] - _sbusBias[i]) / _sbusScale[i];
- }
- }
- write(channels);
-}
-
-void SBUS::setEndPoints(uint8_t channel,uint16_t min,uint16_t max)
-{
- _sbusMin[channel] = min;
- _sbusMax[channel] = max;
- scaleBias(channel);
-}
-
-void SBUS::getEndPoints(uint8_t channel,uint16_t *min,uint16_t *max)
-{
- if (min&&max) {
- *min = _sbusMin[channel];
- *max = _sbusMax[channel];
- }
-}
-
-void SBUS::setReadCal(uint8_t channel,float *coeff,uint8_t len)
-{
- if (coeff) {
- if (!_readCoeff) {
- _readCoeff = (float**) malloc(sizeof(float*)*_numChannels);
- }
- if (!_readCoeff[channel]) {
- _readCoeff[channel] = (float*) malloc(sizeof(float)*len);
- } else {
- free(_readCoeff[channel]);
- _readCoeff[channel] = (float*) malloc(sizeof(float)*len);
- }
- for (uint8_t i = 0; i < len; i++) {
- _readCoeff[channel][i] = coeff[i];
- }
- _readLen[channel] = len;
- _useReadCoeff[channel] = true;
- }
-}
-
-void SBUS::getReadCal(uint8_t channel,float *coeff,uint8_t len)
-{
- if (coeff) {
- for (uint8_t i = 0; (i < _readLen[channel]) && (i < len); i++) {
- coeff[i] = _readCoeff[channel][i];
- }
- }
-}
-
-void SBUS::setWriteCal(uint8_t channel,float *coeff,uint8_t len)
-{
- if (coeff) {
- if (!_writeCoeff) {
- _writeCoeff = (float**) malloc(sizeof(float*)*_numChannels);
- }
- if (!_writeCoeff[channel]) {
- _writeCoeff[channel] = (float*) malloc(sizeof(float)*len);
- } else {
- free(_writeCoeff[channel]);
- _writeCoeff[channel] = (float*) malloc(sizeof(float)*len);
- }
- for (uint8_t i = 0; i < len; i++) {
- _writeCoeff[channel][i] = coeff[i];
- }
- _writeLen[channel] = len;
- _useWriteCoeff[channel] = true;
- }
-}
-
-void SBUS::getWriteCal(uint8_t channel,float *coeff,uint8_t len)
-{
- if (coeff) {
- for (uint8_t i = 0; (i < _writeLen[channel]) && (i < len); i++) {
- coeff[i] = _writeCoeff[channel][i];
- }
- }
-}
-
-/* destructor, free dynamically allocated memory */
-SBUS::~SBUS()
-{
- if (_readCoeff) {
- for (uint8_t i = 0; i < _numChannels; i++) {
- if (_readCoeff[i]) {
- free(_readCoeff[i]);
- }
- }
- free(_readCoeff);
- }
- if (_writeCoeff) {
- for (uint8_t i = 0; i < _numChannels; i++) {
- if (_writeCoeff[i]) {
- free(_writeCoeff[i]);
- }
- }
- free(_writeCoeff);
- }
-}
-
-/* parse the SBUS data */
-bool SBUS::parse()
-{
- // reset the parser state if too much time has passed
- static elapsedMicros _sbusTime = 0;
- if (_sbusTime > SBUS_TIMEOUT_US) {_parserState = 0;}
- // see if serial data is available
- while (_bus->available() > 0) {
- _sbusTime = 0;
- _curByte = _bus->read();
- // find the header
- if (_parserState == 0) {
- if ((_curByte == _sbusHeader) && ((_prevByte == _sbusFooter) || ((_prevByte & _sbus2Mask) == _sbus2Footer))) {
- _parserState++;
- } else {
- _parserState = 0;
- }
- } else {
- // strip off the data
- if ((_parserState-1) < _payloadSize) {
- _payload[_parserState-1] = _curByte;
- _parserState++;
- }
- // check the end byte
- if ((_parserState-1) == _payloadSize) {
- if ((_curByte == _sbusFooter) || ((_curByte & _sbus2Mask) == _sbus2Footer)) {
- _parserState = 0;
- return true;
- } else {
- _parserState = 0;
- return false;
- }
- }
- }
- _prevByte = _curByte;
- }
- // return false if a partial packet
- return false;
-}
-
-/* compute scale factor and bias from end points */
-void SBUS::scaleBias(uint8_t channel)
-{
- _sbusScale[channel] = 2.0f / ((float)_sbusMax[channel] - (float)_sbusMin[channel]);
- _sbusBias[channel] = -1.0f*((float)_sbusMin[channel] + ((float)_sbusMax[channel] - (float)_sbusMin[channel]) / 2.0f) * _sbusScale[channel];
-}
-
-float SBUS::PolyVal(size_t PolySize, float *Coefficients, float X) {
- if (Coefficients) {
- float Y = Coefficients[0];
- for (uint8_t i = 1; i < PolySize; i++) {
- Y = Y*X + Coefficients[i];
- }
- return(Y);
- } else {
- return 0;
- }
-}
-
-// function to send byte at a time with
-// ISR to emulate 2 stop bits on Teensy 3.0 and 3.1/3.2
-#if defined(__MK20DX128__) || defined(__MK20DX256__) // Teensy 3.0 || Teensy 3.1/3.2
- void sendByte()
- {
- if (SENDINDEX < 25) {
- SERIALPORT->write(PACKET[SENDINDEX]);
- SENDINDEX++;
- } else {
- serialTimer.end();
- SENDINDEX = 0;
- }
- }
-#endif
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/SBUS/SBUS.h b/Versions/dRehmFlight_Teensy_BETA_1.2/src/SBUS/SBUS.h
deleted file mode 100644
index 215cb9b7..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/SBUS/SBUS.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- SBUS.h
- Brian R Taylor
- brian.taylor@bolderflight.com
-
- Copyright (c) 2016 Bolder Flight Systems
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-*/
-
-#ifndef SBUS_h
-#define SBUS_h
-
-#include "Arduino.h"
-#include "elapsedMillis.h"
-
-/*
-* Hardware Serial Supported:
-* Teensy 3.0 || Teensy 3.1/3.2 || Teensy 3.5 || Teensy 3.6 || Teensy LC || STM32L4 || Maple Mini || Arduino Mega 2560 || ESP32
-*/
-#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) \
- || defined(__MK66FX1M0__) || defined(__MKL26Z64__) || defined(__IMXRT1052__) \
- || defined(STM32L496xx) || defined(STM32L476xx) || defined(STM32L433xx) \
- || defined(STM32L432xx) || defined(_BOARD_MAPLE_MINI_H_) \
- || defined(__AVR_ATmega2560__) || defined(ESP32)
-#endif
-
-class SBUS{
- public:
- SBUS(HardwareSerial& bus);
- void begin();
- bool read(uint16_t* channels, bool* failsafe, bool* lostFrame);
- bool readCal(float* calChannels, bool* failsafe, bool* lostFrame);
- void write(uint16_t* channels);
- void writeCal(float *channels);
- void setEndPoints(uint8_t channel,uint16_t min,uint16_t max);
- void getEndPoints(uint8_t channel,uint16_t *min,uint16_t *max);
- void setReadCal(uint8_t channel,float *coeff,uint8_t len);
- void getReadCal(uint8_t channel,float *coeff,uint8_t len);
- void setWriteCal(uint8_t channel,float *coeff,uint8_t len);
- void getWriteCal(uint8_t channel,float *coeff,uint8_t len);
- ~SBUS();
- private:
- const uint32_t _sbusBaud = 100000;
- static const uint8_t _numChannels = 16;
- const uint8_t _sbusHeader = 0x0F;
- const uint8_t _sbusFooter = 0x00;
- const uint8_t _sbus2Footer = 0x04;
- const uint8_t _sbus2Mask = 0x0F;
- const uint32_t SBUS_TIMEOUT_US = 7000;
- uint8_t _parserState, _prevByte = _sbusFooter, _curByte;
- static const uint8_t _payloadSize = 24;
- uint8_t _payload[_payloadSize];
- const uint8_t _sbusLostFrame = 0x04;
- const uint8_t _sbusFailSafe = 0x08;
- const uint16_t _defaultMin = 172;
- const uint16_t _defaultMax = 1811;
- uint16_t _sbusMin[_numChannels];
- uint16_t _sbusMax[_numChannels];
- float _sbusScale[_numChannels];
- float _sbusBias[_numChannels];
- float **_readCoeff, **_writeCoeff;
- uint8_t _readLen[_numChannels],_writeLen[_numChannels];
- bool _useReadCoeff[_numChannels], _useWriteCoeff[_numChannels];
- HardwareSerial* _bus;
- bool parse();
- void scaleBias(uint8_t channel);
- float PolyVal(size_t PolySize, float *Coefficients, float X);
-};
-
-#endif
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.2/src/SBUS/elapsedMillis.h b/Versions/dRehmFlight_Teensy_BETA_1.2/src/SBUS/elapsedMillis.h
deleted file mode 100644
index 48cff11d..00000000
--- a/Versions/dRehmFlight_Teensy_BETA_1.2/src/SBUS/elapsedMillis.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Elapsed time types - for easy-to-use measurements of elapsed time
- * http://www.pjrc.com/teensy/
- * Copyright (c) 2017 PJRC.COM, LLC
- *
- * 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 elapsedMillis_h
-#define elapsedMillis_h
-#ifdef __cplusplus
-
-#if ARDUINO >= 100
-#include "Arduino.h"
-#else
-#include "WProgram.h"
-#endif
-
-class elapsedMillis
-{
-private:
- unsigned long ms;
-public:
- elapsedMillis(void) { ms = millis(); }
- elapsedMillis(unsigned long val) { ms = millis() - val; }
- elapsedMillis(const elapsedMillis &orig) { ms = orig.ms; }
- operator unsigned long () const { return millis() - ms; }
- elapsedMillis & operator = (const elapsedMillis &rhs) { ms = rhs.ms; return *this; }
- elapsedMillis & operator = (unsigned long val) { ms = millis() - val; return *this; }
- elapsedMillis & operator -= (unsigned long val) { ms += val ; return *this; }
- elapsedMillis & operator += (unsigned long val) { ms -= val ; return *this; }
- elapsedMillis operator - (int val) const { elapsedMillis r(*this); r.ms += val; return r; }
- elapsedMillis operator - (unsigned int val) const { elapsedMillis r(*this); r.ms += val; return r; }
- elapsedMillis operator - (long val) const { elapsedMillis r(*this); r.ms += val; return r; }
- elapsedMillis operator - (unsigned long val) const { elapsedMillis r(*this); r.ms += val; return r; }
- elapsedMillis operator + (int val) const { elapsedMillis r(*this); r.ms -= val; return r; }
- elapsedMillis operator + (unsigned int val) const { elapsedMillis r(*this); r.ms -= val; return r; }
- elapsedMillis operator + (long val) const { elapsedMillis r(*this); r.ms -= val; return r; }
- elapsedMillis operator + (unsigned long val) const { elapsedMillis r(*this); r.ms -= val; return r; }
-};
-
-class elapsedMicros
-{
-private:
- unsigned long us;
-public:
- elapsedMicros(void) { us = micros(); }
- elapsedMicros(unsigned long val) { us = micros() - val; }
- elapsedMicros(const elapsedMicros &orig) { us = orig.us; }
- operator unsigned long () const { return micros() - us; }
- elapsedMicros & operator = (const elapsedMicros &rhs) { us = rhs.us; return *this; }
- elapsedMicros & operator = (unsigned long val) { us = micros() - val; return *this; }
- elapsedMicros & operator -= (unsigned long val) { us += val ; return *this; }
- elapsedMicros & operator += (unsigned long val) { us -= val ; return *this; }
- elapsedMicros operator - (int val) const { elapsedMicros r(*this); r.us += val; return r; }
- elapsedMicros operator - (unsigned int val) const { elapsedMicros r(*this); r.us += val; return r; }
- elapsedMicros operator - (long val) const { elapsedMicros r(*this); r.us += val; return r; }
- elapsedMicros operator - (unsigned long val) const { elapsedMicros r(*this); r.us += val; return r; }
- elapsedMicros operator + (int val) const { elapsedMicros r(*this); r.us -= val; return r; }
- elapsedMicros operator + (unsigned int val) const { elapsedMicros r(*this); r.us -= val; return r; }
- elapsedMicros operator + (long val) const { elapsedMicros r(*this); r.us -= val; return r; }
- elapsedMicros operator + (unsigned long val) const { elapsedMicros r(*this); r.us -= val; return r; }
-};
-
-#endif // __cplusplus
-#endif // elapsedMillis_h
diff --git a/Versions/dRehmFlight_Teensy_BETA_1.3/dRehmFlight_Teensy_BETA_1.3.ino b/Versions/dRehmFlight_Teensy_BETA_1.3/dRehmFlight_Teensy_BETA_1.3.ino
index 9e4cceee..2a1d71b1 100644
--- a/Versions/dRehmFlight_Teensy_BETA_1.3/dRehmFlight_Teensy_BETA_1.3.ino
+++ b/Versions/dRehmFlight_Teensy_BETA_1.3/dRehmFlight_Teensy_BETA_1.3.ino
@@ -1124,13 +1124,13 @@ void scaleCommands() {
m6_command_PWM = constrain(m6_command_PWM, 125, 250);
//Scaled to 0-180 for servo library
- s1_command_PWM = s1_command_scaled*180;
- s2_command_PWM = s2_command_scaled*180;
- s3_command_PWM = s3_command_scaled*180;
- s4_command_PWM = s4_command_scaled*180;
- s5_command_PWM = s5_command_scaled*180;
- s6_command_PWM = s6_command_scaled*180;
- s7_command_PWM = s7_command_scaled*180;
+ s1_command_PWM = 90 + (s1_command_scaled*90);
+ s2_command_PWM = 90 + (s2_command_scaled*90);
+ s3_command_PWM = 90 + (s3_command_scaled*90);
+ s4_command_PWM = 90 + (s4_command_scaled*90);
+ s5_command_PWM = 90 + (s5_command_scaled*90);
+ s6_command_PWM = 90 + (s6_command_scaled*90);
+ s7_command_PWM = 90 + (s7_command_scaled*90);
//Constrain commands to servos within servo library bounds
s1_command_PWM = constrain(s1_command_PWM, 0, 180);
s2_command_PWM = constrain(s2_command_PWM, 0, 180);