BMI160 Initial

Dependents:   MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_Pitch_Charles Maxim_Squeeks

Revision:
16:12782f5d4aa4
Parent:
15:dc35ccc0b08e
Child:
17:0ae99e97bcf5
--- a/bmi160.h	Tue Dec 20 21:20:22 2016 +0000
+++ b/bmi160.h	Tue Dec 20 23:57:54 2016 +0000
@@ -256,7 +256,7 @@
     static const uint8_t ACC_RANGE_POS = 0x00;
     
     ///Accelerometer output data rates
-    enum AccOutPutDataRate
+    enum AccOutputDataRate
     {
         ACC_ODR_1 = 1,  ///< 25/32Hz
         ACC_ODR_2,      ///< 25/16Hz
@@ -275,9 +275,9 @@
     ///Accelerometer bandwidth parameters
     enum AccBandWidthParam
     {
-        ACC_BWP_0 = 0, ///< Average 1 cycle
-        ACC_BWP_1,     ///< Average 2 cycles
-        ACC_BWP_2,     ///< Average 4 cycles, use this setting when acc_us = 0
+        ACC_BWP_0 = 0, ///< Average 1 cycle;  when acc_us = 0 OSR4
+        ACC_BWP_1,     ///< Average 2 cycles; when acc_us = 0 OSR2
+        ACC_BWP_2,     ///< Average 4 cycles; when acc_us = 0 normal mode
         ACC_BWP_3,     ///< Average 8 cycles
         ACC_BWP_4,     ///< Average 16 cycles
         ACC_BWP_5,     ///< Average 32 cycles
@@ -298,7 +298,7 @@
         SENS_2G = 0x03,  ///<Accelerometer range +-2G
         SENS_4G = 0x05,  ///<Accelerometer range +-4G
         SENS_8G = 0x08,  ///<Accelerometer range +-8G
-        SENS_16G = 0x0C, ///<Accelerometer range +-16G
+        SENS_16G = 0x0C ///<Accelerometer range +-16G
     };
     
     static const float SENS_2G_LSB_PER_G = 16384.0F;
@@ -312,7 +312,7 @@
         AccRange range;        ///<Accelerometer range
         AccUnderSampling us;   ///<Accelerometr undersampling mode
         AccBandWidthParam bwp; ///<Accelerometer bandwidth param
-        AccOutPutDataRate odr; ///<Accelerometr output data rate
+        AccOutputDataRate odr; ///<Accelerometr output data rate
     };
     
     ///Accelerometer default configuration
@@ -323,7 +323,61 @@
     ///@name GYR_CONF(0x42) and GYR_RANGE(0x43) 
     ///Data for configuring gyroscope
     ///@{
-        
+    
+    static const uint8_t GYRO_ODR_MASK = 0x0F;
+    static const uint8_t GYRO_ODR_POS = 0x00;
+    static const uint8_t GYRO_BWP_MASK = 0x30;
+    static const uint8_t GYRO_BWP_POS = 0x04;
+    static const uint8_t GYRO_RANGE_MASK = 0x07;
+    static const uint8_t GYRO_RANGE_POS = 0x00;
+    
+    ///Gyroscope output data rates
+    enum GyroOutputDataRate
+    {
+        GYRO_ODR_6 = 0x06,  ///<25Hz 
+        GYRO_ODR_7 = 0x07,  ///<50Hz
+        GYRO_ODR_8 = 0x08,  ///<100Hz
+        GYRO_ODR_9 = 0x09,  ///<200Hz
+        GYRO_ODR_10 = 0x0A, ///<400Hz
+        GYRO_ODR_11 = 0x0B, ///<800Hz
+        GYRO_ODR_12 = 0x0C, ///<1600Hz
+        GYRO_ODR_13 = 0x0D  ///<3200Hz
+    };
+    
+    ///Gyroscope bandwidth paramaters
+    enum GyroBandWidthParam
+    {
+        GYRO_BWP_0 = 0, ///<OSR4 Over Sampling Rate of 4
+        GYRO_BWP_1,     ///<OSR2 Over Sampling Rate of 2
+        GYRO_BWP_2      ///<Normal Mode, Equidistant Sampling
+    };
+    
+    ///Gyroscope ranges
+    enum GyroRange
+    {
+        DPS_2000 = 0, ///<+-2000dps, 16.4LSB/dps
+        DPS_1000,     ///<+-1000dps, 32.8LSB/dps
+        DPS_500,      ///<+-500dps, 65.6LSB/dps
+        DPS_250,      ///<+-250dps, 131.2LSB/dps
+        DPS_125       ///<+-125dps, 262.4LSB/dps, 
+    };
+    
+    static const float SENS_2000_DPS_LSB_PER_DPS = 16.4F;
+    static const float SENS_1000_DPS_LSB_PER_DPS = 32.8F;
+    static const float SENS_500_DPS_LSB_PER_DPS = 65.6F;
+    static const float SENS_250_DPS_LSB_PER_DPS = 131.2F;
+    static const float SENS_125_DPS_LSB_PER_DPS = 262.4F;
+    
+    ///Gyroscope configuration data structure    
+    struct GyroConfig
+    {
+        GyroRange range;        ///<Gyroscope range
+        GyroBandWidthParam bwp; ///<Gyroscope bandwidth param
+        GyroOutputDataRate odr; ///<Gyroscope output data rate
+    };
+    
+    ///Gyroscope default configuration
+    static const GyroConfig DEFAULT_GYRO_CONFIG;
     ///@}
     
     
@@ -439,71 +493,99 @@
     int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode);
     
     
-    ///@brief Configure Accelerometer.\n
+    ///@brief Configure sensor.\n
     ///
     ///On Entry:
-    ///@param[in] config - Accelerometer configuration 
+    ///@param[in] config - sSensor configuration data structure
     ///
     ///On Exit:
     ///@param[out] none
     ///
     ///@returns 0 on success, non 0 on failure
-    int32_t setAccConfig(const AccConfig &config);
+    int32_t setSensorConfig(const AccConfig &config);
+    int32_t setSensorConfig(const GyroConfig &config);
     
     
-    ///@brief Get accelerometer configuration.\n
+    ///@brief Get sensor configuration.\n
     ///
     ///On Entry:
-    ///@param[in] config - Accelerometer configuration data structure
+    ///@param[in] config - Sensor configuration data structure
     ///
     ///On Exit:
-    ///@param[out] config - on success, holds accelerometer's current 
+    ///@param[out] config - on success, holds sensor's current 
     ///configuration
     ///
     ///@returns 0 on success, non 0 on failure
-    int32_t getAccConfig(AccConfig &config);
+    int32_t getSensorConfig(AccConfig &config);
+    int32_t getSensorConfig(GyroConfig &config);
     
     
-    ///@brief Get accelerometer axis as float.\n
+    ///@brief Get sensor axis.\n
     ///
     ///On Entry:
     ///@param[in] axis - Sensor axis
     ///@param[in] data - AxisData structure
-    ///@param[in] range - Accelerometer range
+    ///@param[in] range - Sensor range
     ///
     ///On Exit:
     ///@param[out] data - Structure holds raw and scaled axis data
     ///
     ///@returns 0 on success, non 0 on failure
-    int32_t getAccAxis(SensorAxis axis, AxisData &data, AccRange range);
+    int32_t getSensorAxis(SensorAxis axis, AxisData &data, AccRange range);
+    int32_t getSensorAxis(SensorAxis axis, AxisData &data, GyroRange range);
     
     
-    ///@brief Get accelerometer xyz axis as float.\n
+    ///@brief Get sensor xyz axis.\n
     ///
     ///On Entry:
     ///@param[in] data - SensorData structure
-    ///@param[in] range - Accelerometer range
+    ///@param[in] range - Sensor range
     ///
     ///On Exit:
     ///@param[out] data - Structure holds raw and scaled data for all three axis
     ///
     ///@returns 0 on success, non 0 on failure
-    int32_t getAccXYZ(SensorData &data, AccRange range); 
+    int32_t getSensorXYZ(SensorData &data, AccRange range);
+    int32_t getSensorXYZ(SensorData &data, GyroRange range);
     
     
-    ///@brief Get accelerometer xyz axis and sensor time.\n
+    ///@brief Get sensor xyz axis and sensor time.\n
     ///
     ///On Entry:
     ///@param[in] data - SensorData structure
     ///@param[in] sensorTime - SensorTime structure for data
-    ///@param[in] range - Accelerometer range
+    ///@param[in] range - Sensor range
     ///
     ///On Exit:
     ///@param[out] data - Structure holds raw and scaled data for all three axis
     ///@param[out] sensorTime - Holds sensor time on success
     ///
     ///@returns 0 on success, non 0 on failure
-    int32_t getAccXYZandSensorTime(SensorData &data, SensorTime &sensorTime, AccRange range); 
+    int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime, 
+                                      AccRange range);
+    int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime, 
+                                      GyroRange range);
+    
+    
+    ///@brief Get Gyroscope/Accelerometer data and sensor time.\n
+    ///
+    ///On Entry:
+    ///@param[in] accData -  Sensor data structure for accelerometer
+    ///@param[in] gyroData - Sensor data structure for gyroscope
+    ///@param[in] sensorTime - SensorTime data structure
+    ///@param[in] accRange - Accelerometer range
+    ///@param[in] gyroRange - Gyroscope range
+    ///
+    ///On Exit:
+    ///@param[out] accData -  Synchronized accelerometer data
+    ///@param[out] gyroData - Synchronized gyroscope data
+    ///@param[out] sensorTime - Synchronized sensor time
+    ///
+    ///@returns 0 on success, non 0 on failure
+    int32_t getGyroAccXYZandSensorTime(SensorData &accData, 
+                                       SensorData &gyroData, 
+                                       SensorTime &sensorTime, 
+                                       AccRange accRange, GyroRange gyroRange);
     
     
     ///@brief Get sensor time.\n