Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BLE_Nano_MPU6050Service
Diff: MPU6050.h
- Revision:
- 1:96a227d1ca7e
- Parent:
- 0:95916b07e8be
- Child:
- 2:32b13cc64cb0
--- a/MPU6050.h Tue Jun 30 23:52:31 2015 +0000 +++ b/MPU6050.h Thu Jul 02 00:39:12 2015 +0000 @@ -17,6 +17,10 @@ class MPU6050 { public: + /** + * Constants + */ + enum BaseAddress { // left shift by 1 bit is neccessary for mbed's I2C abstraction class @@ -57,7 +61,7 @@ REG_I2C_SLV4_DO = 0x33, // R/W REG_I2C_SLV4_CTRL = 0x34, // R/W REG_I2C_SLV4_DI = 0x35, // R - REG_I2C_MST_STATUS = 0x36, // R */ + REG_I2C_MST_STATUS = 0x36, // R */ REG_INT_PIN_CFG = 0x37, // R/W REG_INT_ENABLE = 0x38, // R/W REG_INT_STATUS = 0x3A, // R @@ -75,7 +79,7 @@ REG_GYRO_YOUT_L = 0x46, // R REG_GYRO_ZOUT_H = 0x47, // R REG_GYRO_ZOUT_L = 0x48, // R - REG_EXT_SENS_DATA_00 = 0x49, // R +/* REG_EXT_SENS_DATA_00 = 0x49, // R REG_EXT_SENS_DATA_01 = 0x4A, // R REG_EXT_SENS_DATA_02 = 0x4B, // R REG_EXT_SENS_DATA_03 = 0x4C, // R @@ -98,7 +102,7 @@ REG_EXT_SENS_DATA_20 = 0x5D, // R REG_EXT_SENS_DATA_21 = 0x5E, // R REG_EXT_SENS_DATA_22 = 0x5F, // R - REG_EXT_SENS_DATA_23 = 0x60, // R + REG_EXT_SENS_DATA_23 = 0x60, // R */ REG_MOT_DETECT_STATUS = 0x61, // R REG_I2C_SLV0_DO = 0x63, // R/W REG_I2C_SLV1_DO = 0x64, // R/W @@ -192,6 +196,61 @@ static const uint8_t GYRO_Z_FIFO_EN_MASK = BYTE(00010000); static const uint8_t ACCEL_FIFO_EN_MASK = BYTE(00001000); + static const uint8_t INT_LEVEL_MASK = BYTE(10000000); + enum InterruptLevel + { + INT_LEVEL_ACTIVE_HIGH = BYTE(00000000), + INT_LEVEL_ACTIVE_LOW = BYTE(10000000) + }; + + static const uint8_t INT_DRIVE_MASK = BYTE(01000000); + enum InterruptDrive + { + INT_DRIVE_PUSH_PULL = BYTE(00000000), + INT_DRIVE_OPEN_DRAIN = BYTE(01000000) + }; + + static const uint8_t INT_LATCH_MASK = BYTE(00100000); + enum InterruptLatch + { + INT_LATCH_50US_PULSE = BYTE(00000000), + INT_LATCH_WAIT_CLEARED = BYTE(00100000) + }; + + static const uint8_t INT_CLEAR_MASK = BYTE(00010000); + enum InterruptClear + { + INT_CLEAR_STATUS_ONLY_READ = BYTE(00000000), + INT_CLEAR_ANY_READ = BYTE(00010000) + }; + + static const uint8_t INT_FSYNC_LEVEL_MASK = BYTE(00001000); + enum InterruptFSyncLevel + { + INT_FSYNC_LEVEL_ACTIVE_HIGH = BYTE(00000000), + INT_FSYNC_LEVEL_ACTIVE_LOW = BYTE(00001000) + }; + + static const uint8_t INT_FSYNC_EN_MASK = BYTE(00000100); + + enum Interrupt + { + INT_FREEFALL = BYTE(10000000), + INT_MOTION = BYTE(01000000), + INT_ZERO_MOTION = BYTE(00100000), + INT_FIFO_OVERFLOW = BYTE(00010000), +/* INT_I2C_MASTER = BYTE(00001000), + INT_PLL_READY = BYTE(00000100), + INT_DMP_INIT = BYTE(00000010), */ + INT_DATA_READY = BYTE(00000001) + }; + friend inline Interrupt operator|(Interrupt a, Interrupt b) { return static_cast<Interrupt>(static_cast<int>(a) | static_cast<int>(b)); } + friend inline Interrupt operator&(Interrupt a, Interrupt b) { return static_cast<Interrupt>(static_cast<int>(a) & static_cast<int>(b)); } + + /** + * basic members + */ + MPU6050(PinName sda, PinName scl, BaseAddress address = ADDRESS_0) : i2c(sda, scl), baseAddress(address) { } @@ -318,6 +377,113 @@ bool setAccelFIFOEnabled(bool enabled, float timeout_secs = defaultTimeout_secs); /** + * REG_INT_PIN_CFG register + */ + + bool getInterruptLevel(InterruptLevel *level, float timeout_secs = defaultTimeout_secs); + bool setInterruptLevel(InterruptLevel level, float timeout_secs = defaultTimeout_secs); + + bool getInterruptDrive(InterruptDrive *drive, float timeout_secs = defaultTimeout_secs); + bool setInterruptDrive(InterruptDrive drive, float timeout_secs = defaultTimeout_secs); + + bool getInterruptLatch(InterruptLatch *latch, float timeout_secs = defaultTimeout_secs); + bool setInterruptLatch(InterruptLatch latch, float timeout_secs = defaultTimeout_secs); + + bool getInterruptLatchClear(InterruptClear *latchClear, float timeout_secs = defaultTimeout_secs); + bool setInterruptLatchClear(InterruptClear latchClear, float timeout_secs = defaultTimeout_secs); + + bool getInterruptFSyncLevel(InterruptFSyncLevel *fsyncLevel, float timeout_secs = defaultTimeout_secs); + bool setInterruptFSyncLevel(InterruptFSyncLevel fsyncLevel, float timeout_secs = defaultTimeout_secs); + + bool getInterruptFSyncEnabled(bool *enabled, float timeout_secs = defaultTimeout_secs); + bool setInterruptFSyncEnabled(bool enabled, float timeout_secs = defaultTimeout_secs); + + /** + * REG_INT_ENABLE register + */ + + bool getInterruptsEnabled(Interrupt *interruptSet, float timeout_secs = defaultTimeout_secs); + bool setInterruptsEnabled(Interrupt interruptSet, float timeout_secs = defaultTimeout_secs); + + bool getInterruptFreefallEnabled(bool *enabled, float timeout_secs = defaultTimeout_secs); + bool setInterruptFreefallEnabled(bool enabled, float timeout_secs = defaultTimeout_secs); + + bool getInterruptMotionEnabled(bool *enabled, float timeout_secs = defaultTimeout_secs); + bool setInterruptMotionEnabled(bool enabled, float timeout_secs = defaultTimeout_secs); + + bool getInterruptZeroMotionEnabled(bool *enabled, float timeout_secs = defaultTimeout_secs); + bool setInterruptZeroMotionEnabled(bool enabled, float timeout_secs = defaultTimeout_secs); + + bool getInterruptFIFOOverflowEnabled(bool *enabled, float timeout_secs = defaultTimeout_secs); + bool setInterruptFIFOOverflowEnabled(bool enabled, float timeout_secs = defaultTimeout_secs); + + bool getInterruptDataReadyEnabled(bool *enabled, float timeout_secs = defaultTimeout_secs); + bool setInterruptDataReadyEnabled(bool enabled, float timeout_secs = defaultTimeout_secs); + + /** + * REG_INT_STATUS register + */ + + bool getInterruptStatuses(Interrupt *interruptSet, float timeout_secs = defaultTimeout_secs); + + bool getInterruptFreefallStatus(bool *status, float timeout_secs = defaultTimeout_secs); + + bool getInterruptMotionStatus(bool *status, float timeout_secs = defaultTimeout_secs); + + bool getInterruptZeroMotionStatus(bool *status, float timeout_secs = defaultTimeout_secs); + + bool getInterruptFIFOOverflowStatus(bool *status, float timeout_secs = defaultTimeout_secs); + + bool getInterruptDataReadyStatus(bool *status, float timeout_secs = defaultTimeout_secs); + + /** + * REG_ACCEL_XOUT_H + * REG_ACCEL_XOUT_L + * REG_ACCEL_YOUT_H + * REG_ACCEL_YOUT_L + * REG_ACCEL_ZOUT_H + * REG_ACCEL_ZOUT_L + * REG_TEMP_OUT_H + * REG_TEMP_OUT_L + * REG_GYRO_XOUT_H + * REG_GYRO_XOUT_L + * REG_GYRO_YOUT_H + * REG_GYRO_YOUT_L + * REG_GYRO_ZOUT_H + * REG_GYRO_ZOUT_L registers + */ + + /** Acceleration */ + + bool getAcceleration(int16_t *ax, int16_t *ay, int16_t *az, float timeout_secs = defaultTimeout_secs); + + bool getAccelerationX(int16_t* ax, float timeout_secs = defaultTimeout_secs); + + bool getAccelerationY(int16_t* ay, float timeout_secs = defaultTimeout_secs); + + bool getAccelerationZ(int16_t* az, float timeout_secs = defaultTimeout_secs); + + /** Temperature */ + + bool getTemperature(int16_t* temp, float timeout_secs = defaultTimeout_secs); + + /** Rotation speed */ + + bool getRotationSpeed(int16_t *ox, int16_t *oy, int16_t *oz, float timeout_secs = defaultTimeout_secs); + + bool getRotationSpeedX(int16_t* ox, float timeout_secs = defaultTimeout_secs); + + bool getRotationSpeedY(int16_t* oy, float timeout_secs = defaultTimeout_secs); + + bool getRotationSpeedZ(int16_t* oz, float timeout_secs = defaultTimeout_secs); + + /** All three */ + + bool getMotionAndTemperature(int16_t* ax, int16_t* ay, int16_t* az, + int16_t* ox, int16_t* oy, int16_t* oz, + int16_t* temp, float timeout_secs = defaultTimeout_secs); + + /** * Read and write registers */