BMI160 Initial

Dependents:   MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_Pitch_Charles Maxim_Squeeks

Files at this revision

API Documentation at this revision

Comitter:
j3
Date:
Wed Dec 14 23:48:07 2016 +0000
Parent:
4:ebac8c8f6347
Child:
6:9615aa90087d
Commit message:
working on lib

Changed in this revision

bmi160.cpp Show annotated file Show diff for this revision Revisions of this file
bmi160.h Show annotated file Show diff for this revision Revisions of this file
--- a/bmi160.cpp	Fri Dec 09 00:45:10 2016 +0000
+++ b/bmi160.cpp	Wed Dec 14 23:48:07 2016 +0000
@@ -35,9 +35,43 @@
 
 
 //*****************************************************************************
-int32_t BMI160::getTemperature(float *temp)
+int32_t BMI160::setSensorPowerMode(Sensors sensor, PowerModes pwrMode)
 {
     int32_t rtnVal = -1;
     
+    switch(sensor)
+    {
+        case MAG:
+            rtnVal = writeRegister(CMD, (MAG_SET_PMU_MODE | pwrMode));
+        break;
+        
+        case GYRO:
+            rtnVal = writeRegister(CMD, (GYR_SET_PMU_MODE | pwrMode));
+        break;
+        
+        case ACC:
+            rtnVal = writeRegister(CMD, (ACC_SET_PMU_MODE | pwrMode));
+        break;
+        
+        default:
+            rtnVal = -1;
+        break;
+    }
+    
     return rtnVal;
 }
+
+
+//*****************************************************************************
+int32_t BMI160::getTemperature(float *temp)
+{
+    uint8_t data[2];
+    
+    int32_t rtnVal = readBlock(TEMPERATURE_0, TEMPERATURE_1, data);
+    if(rtnVal == RTN_NO_ERROR)
+    {
+        *temp = (((data[1] << 8) | data[0])/512.0);
+    }
+    
+    return rtnVal;
+}
--- a/bmi160.h	Fri Dec 09 00:45:10 2016 +0000
+++ b/bmi160.h	Wed Dec 14 23:48:07 2016 +0000
@@ -56,6 +56,14 @@
     ///Return value on success.
     static const uint8_t RTN_NO_ERROR = 0;
     
+    ///BMI160 Sensors
+    enum Sensors
+    {
+        MAG = 0, ///<Optional external sensor
+        GYRO,    ///<Angular rate sensor
+        ACC      ///<g sensor
+    };
+    
     ///BMI160 registers
     enum Registers
     {
@@ -193,6 +201,7 @@
         PFD_USED_LPM         ///<Pre-filtered data are used in low power mode
     };
     
+    ///BMI160 Power Modes
     enum PowerModes
     {
         SUSPEND = 0,  ///<Acc and Gyro, No sampling, No FIFO data readout
@@ -201,6 +210,21 @@
         FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms
     };
     
+    ///BMI160 Commands for CMD register
+    enum Commands
+    {
+        START_FOC = 0x03,        ///<Starts Fast Offset Calibrartion 
+        ACC_SET_PMU_MODE = 0x14, ///<Sets acc power mode
+        GYR_SET_PMU_MODE,        ///<Sets gyro power mode
+        MAG_SET_PMU_MODE,        ///<Sets mag power mode
+        PROG_NVM = 0xA0,         ///<Writes NVM backed registers into NVM
+        FIFO_FLUSH = 0xB0,       ///<Clears FIFO
+        INT_RESET,               ///<Clears interrupt engine, INT_STATUS, and 
+                                 ///<the interrupt pin
+        STEP_CNT_CLR,            ///<Triggers reset of the step counter
+        SOFT_RESET = 0xB6        ///<Triggers a reset including a reboot.
+    };
+    
     
     ///@brief BMI160 Destructor.\n
     ///
@@ -274,6 +298,20 @@
     const uint8_t *data) = 0;
     
     
+    ///@brief Sets sensors power mode through CMD register.\n
+    ///@details Observe command execution times given in datasheet.\n 
+    ///
+    ///On Entry:
+    ///@param[in] sensor - Sensor which power mode we are setting
+    ///@param[in] pwrMode - Desired powermode of the sensor
+    ///
+    ///On Exit:
+    ///@param[out] 
+    ///
+    ///@returns 0 on success, non 0 on failure
+    int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode);
+    
+    
     ///@brief Get die temperature.\n
     ///
     ///On Entry:
@@ -295,8 +333,6 @@
     ///@param[out] none
     ///
     ///@returns none
-    
-private:
 
 };