First Commit as a new library

Dependents:   Host_Software_MAX32664GWEB_HR_wrist Host_Software_MAX32664GWEC_SpO2_HR Host_Software_MAX32664GWEB_HR_EXTENDED Host_Software_MAX32664GWEC_SpO2_HR-_EXTE ... more

Files at this revision

API Documentation at this revision

Comitter:
j3
Date:
Tue Dec 20 19:32:26 2016 +0000
Parent:
13:5d132f873b07
Child:
15:dc35ccc0b08e
Commit message:
working on docs

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	Tue Dec 20 19:02:36 2016 +0000
+++ b/bmi160.cpp	Tue Dec 20 19:32:26 2016 +0000
@@ -66,12 +66,35 @@
 
 
 //*****************************************************************************
-int32_t setAccConfig(const AccConfig &config)
+int32_t BMI160::setAccConfig(const AccConfig &config)
 {
-    int32_t rtnVal = -1;
     uint8_t data[2];
     
+    data[0] = ((config.us << ACC_US_POS) | (config.bwp << ACC_BWP_POS) | 
+               (config.odr << ACC_ODR_POS));
+    data[1] = config.range;
     
+    return writeBlock(ACC_CONF, ACC_RANGE, data);
+}
+
+
+//*****************************************************************************
+int32_t BMI160::getAccConfig(AccConfig &config)
+{
+    uint8_t data[2];
+    int32_t rtnVal = readBlock(ACC_CONF, ACC_RANGE, data);
+    
+    if(rtnVal == RTN_NO_ERROR)
+    {
+        config.range = static_cast<BMI160::AccRange>(
+        (data[1] & ACC_RANGE_MASK));
+        config.us = static_cast<BMI160::AccUnderSampling>(
+        ((data[0] & ACC_US_MASK) >> ACC_US_POS));
+        config.bwp = static_cast<BMI160::AccBandWidthParam>(
+        ((data[0] & ACC_BWP_MASK) >> ACC_BWP_POS));
+        config.odr = static_cast<BMI160::AccOutPutDataRate>(
+        ((data[0] & ACC_ODR_MASK) >> ACC_ODR_POS));
+    }
     
     return rtnVal;
 }
--- a/bmi160.h	Tue Dec 20 19:02:36 2016 +0000
+++ b/bmi160.h	Tue Dec 20 19:32:26 2016 +0000
@@ -206,11 +206,16 @@
     ///Error register data
     ///@{
         
-    static const uint8_t FATAL_ERR = 0x01;
-    static const uint8_t ERR_CODE = 0x1E;
-    static const uint8_t I2C_FAIL_ERR = 0x20;
-    static const uint8_t DROP_CMD_ERR = 0x40;
-    static const uint8_t MAG_DRDY_ERR = 0x80;
+    static const uint8_t FATAL_ERR_MASK = 0x01;
+    static const uint8_t FATAL_ERR_POS = 0x00;
+    static const uint8_t ERR_CODE_MASK = 0x1E;
+    static const uint8_t ERR_CODE_POS = 0x01;
+    static const uint8_t I2C_FAIL_ERR_MASK = 0x20;
+    static const uint8_t I2C_FAIL_ERR_POS = 0x05;
+    static const uint8_t DROP_CMD_ERR_MASK = 0x40;
+    static const uint8_t DROP_CMD_ERR_POS = 0x06;
+    static const uint8_t MAG_DRDY_ERR_MASK = 0x80;
+    static const uint8_t MAG_DRDY_ERR_POS = 0x08;
     
     ///Enumerated error codes
     enum ErrorCodes
@@ -237,6 +242,8 @@
     static const uint8_t ACC_BWP_POS = 0x04;
     static const uint8_t ACC_US_MASK = 0x80;
     static const uint8_t ACC_US_POS = 0x07;
+    static const uint8_t ACC_RANGE_MASK = 0x0F;
+    static const uint8_t ACC_RANGE_POS = 0x00;
     
     ///Accelerometer output data rates
     enum AccOutPutDataRate
@@ -287,10 +294,10 @@
     ///Accelerometer configuration data structure
     struct AccConfig
     {
-        AccRange range;
-        AccUnderSampling us;
-        AccBandWidthParam bwp;
-        AccOutPutDataRate odr;
+        AccRange range;        ///<Accelerometer range
+        AccUnderSampling us;   ///<Accelerometr undersampling mode
+        AccBandWidthParam bwp; ///<Accelerometer bandwidth param
+        AccOutPutDataRate odr; ///<Accelerometr output data rate
     };
     
     ///Accelerometer default configuration
@@ -298,6 +305,13 @@
     ///@}
     
     
+    ///@name GYR_CONF(0x42) and GYR_RANGE(0x43) 
+    ///Data for configuring gyroscope
+    ///@{
+        
+    ///@}
+    
+    
     ///Enumerated power modes
     enum PowerModes
     {
@@ -422,6 +436,19 @@
     int32_t setAccConfig(const AccConfig &config);
     
     
+    ///@brief Get accelerometer configuration.\n
+    ///
+    ///On Entry:
+    ///@param[in] config - Accelerometer configuration data structure
+    ///
+    ///On Exit:
+    ///@param[out] config - on success, holds accelerometer's current 
+    ///configuration
+    ///
+    ///@returns 0 on success, non 0 on failure
+    int32_t getAccConfig(AccConfig &config);
+    
+    
     ///@brief Get accelerometer axis as float.\n
     ///
     ///On Entry: