BMI160 Initial
Dependents: MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_Pitch_Charles Maxim_Squeeks
Revision 12:64931a80340d, committed 2016-12-20
- Comitter:
- j3
- Date:
- Tue Dec 20 18:38:42 2016 +0000
- Parent:
- 11:24602ff07e9f
- Child:
- 13:5d132f873b07
- Commit message:
- experimenting with doxygen
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 01:29:56 2016 +0000
+++ b/bmi160.cpp Tue Dec 20 18:38:42 2016 +0000
@@ -66,38 +66,19 @@
//*****************************************************************************
-int32_t BMI160::getTemperature(float *temp)
+int32_t setAccConfig(const AccConfig &config)
{
+ int32_t rtnVal = -1;
uint8_t data[2];
- uint16_t rawTemp;
- int32_t rtnVal = readBlock(TEMPERATURE_0, TEMPERATURE_1, data);
- if(rtnVal == RTN_NO_ERROR)
- {
- rawTemp = ((data[1] << 8) | data[0]);
- if(rawTemp & 0x8000)
- {
- *temp = (23.0F - ((0x10000 - rawTemp)/512.0F));
- }
- else
- {
- *temp = ((rawTemp/512.0F) + 23.0F);
- }
- }
+
return rtnVal;
}
//*****************************************************************************
-int32_t BMI160::getSensorDataAndTime(uint8_t *data)
-{
- return readBlock(DATA_0, SENSORTIME_2, data);
-}
-
-
-//*****************************************************************************
-int32_t BMI160::getAccAxis(SensorAxis axis, AxisData &data, AccConfig accConfig)
+int32_t BMI160::getAccAxis(SensorAxis axis, AxisData &data, AccRange range)
{
uint8_t localData[2];
int32_t rtnVal;
@@ -124,7 +105,7 @@
if(rtnVal == RTN_NO_ERROR)
{
data.raw = ((localData[1] << 8) | localData[0]);
- switch(accConfig.range)
+ switch(range)
{
//magic numbers are typical values for LSB/g from EC table
case SENS_2G:
@@ -150,7 +131,7 @@
//*****************************************************************************
-int32_t BMI160::getAccXYZ(SensorData &data, AccConfig accConfig)
+int32_t BMI160::getAccXYZ(SensorData &data, AccRange range)
{
uint8_t localData[6];
int32_t rtnVal = readBlock(DATA_14, DATA_19, localData);
@@ -161,7 +142,7 @@
data.yAxis.raw = ((localData[3] << 8) | localData[2]);
data.zAxis.raw = ((localData[5] << 8) | localData[4]);
- switch(accConfig.range)
+ switch(range)
{
//magic numbers are typical values for LSB/g from EC table
case SENS_2G:
@@ -208,3 +189,26 @@
return rtnVal;
}
+
+//*****************************************************************************
+int32_t BMI160::getTemperature(float *temp)
+{
+ uint8_t data[2];
+ uint16_t rawTemp;
+
+ int32_t rtnVal = readBlock(TEMPERATURE_0, TEMPERATURE_1, data);
+ if(rtnVal == RTN_NO_ERROR)
+ {
+ rawTemp = ((data[1] << 8) | data[0]);
+ if(rawTemp & 0x8000)
+ {
+ *temp = (23.0F - ((0x10000 - rawTemp)/512.0F));
+ }
+ else
+ {
+ *temp = ((rawTemp/512.0F) + 23.0F);
+ }
+ }
+
+ return rtnVal;
+}
--- a/bmi160.h Tue Dec 20 01:29:56 2016 +0000
+++ b/bmi160.h Tue Dec 20 18:38:42 2016 +0000
@@ -201,18 +201,15 @@
};
- ///ERR_REG Bit Mask bit0
+ ///@name ERR_REG(0x02) Group
+ ///Bit masks, positions, and enumerations
+ ///@{
static const uint8_t FATAL_ERR = 0x01;
- ///ERR_REG Bit Mask bits4:1
static const uint8_t ERR_CODE = 0x1E;
- ///ERR_REG Bit Mask bit5
static const uint8_t I2C_FAIL_ERR = 0x20;
- ///ERR_REG Bit Mask bit6
static const uint8_t DROP_CMD_ERR = 0x40;
- ///ERR_REG Bit Mask bit7
static const uint8_t MAG_DRDY_ERR = 0x80;
- ///ERR_REG bits4:1 codes
enum ErrorCodes
{
NO_ERROR = 0, ///<No Error
@@ -224,16 +221,19 @@
///<not match
PFD_USED_LPM ///<Pre-filtered data are used in low power mode
};
+ ///@}
- ///ACC_CONF Bit Mask bits3:0
+ ///@name ACC_CONF(0x40) and ACC_RANGE(0x41) Group
+ ///Bit masks, positions, and enumerations
+ ///@{
static const uint8_t ACC_ODR = 0x0F;
- ///ACC_CONF Bit Mask bits6:4
+ static const uint8_t ACC_ODR_POS = 0;
static const uint8_t ACC_BWP = 0x70;
- ///ACC_CONF Bit Mask bit7
+ static const uint8_t ACC_BWP_POS = 0x04;
static const uint8_t ACC_US = 0x80;
+ static const uint8_t ACC_US_POS = 0x07;
- ///ACC_CONF bits3:0 codes
enum AccOutPutDataRate
{
ACC_ODR_1 = 1, ///< 25/32Hz
@@ -250,7 +250,6 @@
ACC_ODR_12 ///< 1600Hz
};
- ///ACC_CONF bits6:4 codes
enum AccBandWidthParam
{
ACC_BWP_0 = 0, ///< Average 1 cycle
@@ -263,14 +262,12 @@
ACC_BWP_7 ///< Average 128 cycles
};
- ///ACC_CONF bit7
enum AccUnderSampling
{
ACC_US_OFF = 0,
ACC_US_ON
};
- ///Accelerometer range values
enum AccRange
{
SENS_2G = 0, ///<Accelerometer range +-2G
@@ -279,7 +276,6 @@
SENS_16G, ///<Accelerometer range +-16G
};
- ///Structure for holding accelerometer configuration
struct AccConfig
{
AccRange range;
@@ -288,10 +284,10 @@
AccOutPutDataRate odr;
};
- ///Accelerometer default configuration
static const AccConfig DEFAULT_ACC_CONFIG;
+ ///@}
- ///BMI160 Power Modes
+
enum PowerModes
{
SUSPEND = 0, ///<Acc and Gyro, No sampling, No FIFO data readout
@@ -300,7 +296,7 @@
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
@@ -402,28 +398,16 @@
int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode);
- ///@brief Get die temperature.\n
+ ///@brief Configure Accelerometer.\n
///
///On Entry:
- ///@param[in] temp - pointer to float for temperature
+ ///@param[in] config - Accelerometer configuration
///
///On Exit:
- ///@param[out] temp - on success, holds the die temperature
+ ///@param[out] none
///
///@returns 0 on success, non 0 on failure
- int32_t getTemperature(float *temp);
-
-
- ///@brief Read data registers and sensortime.\n
- ///
- ///On Entry:
- ///@param[in] data - buffer at least 23 bytes long
- ///
- ///On Exit:
- ///@param[out] data - holds raw sensor data on success
- ///
- ///@returns 0 on success, non 0 on failure
- int32_t getSensorDataAndTime(uint8_t *data);
+ int32_t setAccConfig(const AccConfig &config);
///@brief Get accelerometer axis as float.\n
@@ -431,26 +415,26 @@
///On Entry:
///@param[in] axis - Sensor axis
///@param[in] data - AxisData structure
- ///@param[in] accConfig - Accelerometer configuration structure
+ ///@param[in] range - Accelerometer 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, AccConfig accConfig);
+ int32_t getAccAxis(SensorAxis axis, AxisData &data, AccRange range);
///@brief Get accelerometer xyz axis as float.\n
///
///On Entry:
///@param[in] data - SensorData structure
- ///@param[in] accConfig - Accelerometer configuration structure
+ ///@param[in] range - Accelerometer 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, AccConfig accConfig);
+ int32_t getAccXYZ(SensorData &data, AccRange range);
///@brief Get sensor time.\n
@@ -463,6 +447,18 @@
///
///@returns returns 0 on success, non 0 on failure
int32_t getSensorTime(float *data);
+
+
+ ///@brief Get die temperature.\n
+ ///
+ ///On Entry:
+ ///@param[in] temp - pointer to float for temperature
+ ///
+ ///On Exit:
+ ///@param[out] temp - on success, holds the die temperature
+ ///
+ ///@returns 0 on success, non 0 on failure
+ int32_t getTemperature(float *temp);
};