Felix Rüdiger / MPU6050_lib

Dependents:   BLE_Nano_MPU6050Service

Revision:
2:32b13cc64cb0
Parent:
1:96a227d1ca7e
Child:
3:a6e53ab2c8c0
--- a/MPU6050.h	Thu Jul 02 00:39:12 2015 +0000
+++ b/MPU6050.h	Mon Jul 13 15:23:35 2015 +0000
@@ -13,13 +13,20 @@
  
 #include "mbed.h"
 #include "helpers.h"
- 
+
+typedef struct 
+{
+    int16_t ax, ay, az;
+    int16_t temp;
+    int16_t ox, oy, oz;
+} MPU6050SensorReading;
+
 class MPU6050
 {
     public:
         /**
          * Constants
-         */
+         */  
     
         enum BaseAddress
         {
@@ -104,11 +111,11 @@
             REG_EXT_SENS_DATA_22                    = 0x5F, // R  
             REG_EXT_SENS_DATA_23                    = 0x60, // R            */
             REG_MOT_DETECT_STATUS                   = 0x61, // R  
-            REG_I2C_SLV0_DO                         = 0x63, // R/W
+/*          REG_I2C_SLV0_DO                         = 0x63, // R/W
             REG_I2C_SLV1_DO                         = 0x64, // R/W
             REG_I2C_SLV2_DO                         = 0x65, // R/W
-            REG_I2C_SLV3_DO                         = 0x66, // R/W
-            REG_I2C_MST_DELAY_CTRL                  = 0x67, // R/W
+            REG_I2C_SLV3_DO                         = 0x66, // R/W          
+            REG_I2C_MST_DELAY_CTRL                  = 0x67, // R/W          */
             REG_SIGNAL_PATH_RESET                   = 0x68, // R/W
             REG_MOT_DETECT_CTRL                     = 0x69, // R/W
             REG_USER_CTRL                           = 0x6A, // R/W
@@ -247,12 +254,29 @@
         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)); }
         
+        enum Motion
+        {
+            MOT_NEGATIVE_X                          = BYTE(10000000),
+            MOT_POSITIVE_X                          = BYTE(01000000),
+            MOT_NEGATIVE_Y                          = BYTE(00100000),
+            MOT_POSITIVE_Y                          = BYTE(00010000),
+            MOT_NEGATIVE_Z                          = BYTE(00001000),
+            MOT_POSITIVE_Z                          = BYTE(00000100),
+            MOT_ZERO                                = BYTE(00000001)
+        };
+        friend inline Motion operator|(Motion a, Motion b) { return static_cast<Motion>(static_cast<int>(a) | static_cast<int>(b)); }
+        friend inline Motion operator&(Motion a, Motion b) { return static_cast<Motion>(static_cast<int>(a) & static_cast<int>(b)); }
+        
+        static const uint8_t GYRO_PATH_RESET_MASK   = BYTE(00000100);
+        static const uint8_t ACCEL_PATH_RESET_MASK  = BYTE(00000010);
+        static const uint8_t TEMP_PATH_RESET_MASK   = BYTE(00000001);
+        
         /**
          * basic members
          */
         
         MPU6050(PinName sda, PinName scl, BaseAddress address = ADDRESS_0) : i2c(sda, scl), baseAddress(address)
-        { }
+        { i2c.frequency(500); }
         
         BaseAddress getAddress() { return baseAddress; }         
         
@@ -482,6 +506,38 @@
         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);
+                                            
+        bool        getMotionAndTemperature(MPU6050SensorReading *sensorReading,    float timeout_secs = defaultTimeout_secs);
+        
+        /**
+         * REG_MOT_DETECT_STATUS register
+         */
+         
+        bool        getMotionStatus(Motion *motionSet,  float timeout_secs = defaultTimeout_secs);
+        
+        bool        getNegativeXMotionDetected(bool *detected,  float timeout_secs = defaultTimeout_secs);
+        
+        bool        getPositiveXMotionDetected(bool *detected,  float timeout_secs = defaultTimeout_secs); 
+        
+        bool        getNegativeYMotionDetected(bool *detected,  float timeout_secs = defaultTimeout_secs);
+        
+        bool        getPositiveYMotionDetected(bool *detected,  float timeout_secs = defaultTimeout_secs);
+        
+        bool        getNegativeZMotionDetected(bool *detected,  float timeout_secs = defaultTimeout_secs);
+        
+        bool        getPositiveZMotionDetected(bool *detected,  float timeout_secs = defaultTimeout_secs);
+        
+        bool        getZeroMotionDetected(bool *detected,   float timeout_secs = defaultTimeout_secs);
+        
+        /**
+         * REG_SIGNAL_PATH_RESET register
+         */
+         
+        bool        resetGyroscopeSignalPath(float timeout_secs = defaultTimeout_secs);
+        
+        bool        resetAccelerometerSignalPath(float timeout_secs = defaultTimeout_secs);
+        
+        bool        resetTemperatureSignalPath(float timeout_secs = defaultTimeout_secs);
                  
         /**
          * Read and write registers
@@ -499,6 +555,24 @@
     
         I2C         i2c;
         BaseAddress baseAddress;
+        
+        union
+        {
+            struct
+            {
+                uint8_t ax_h,   ax_l;
+                uint8_t ay_h,   ay_l;
+                uint8_t az_h,   az_l;
+                
+                uint8_t temp_h, temp_l;
+                
+                uint8_t ox_h,   ox_l;
+                uint8_t oy_h,   oy_l;
+                uint8_t oz_h,   oz_l;
+            } reg;
+            
+            MPU6050SensorReading value;
+        } converter;
 };
 
 #endif
\ No newline at end of file