Maxim Integrated / BMI160

Dependents:   Rocket MAX32630FTHR_JOYSTICK MAX32630FTHR_IMU_Hello_World Pike_the_Flipper_Main_Branch ... more

Fork of BMI160 by Justin Jordan

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bmi160.h Source File

bmi160.h

00001 /**********************************************************************
00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003 *
00004 * Permission is hereby granted, free of charge, to any person obtaining a
00005 * copy of this software and associated documentation files (the "Software"),
00006 * to deal in the Software without restriction, including without limitation
00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008 * and/or sell copies of the Software, and to permit persons to whom the
00009 * Software is furnished to do so, subject to the following conditions:
00010 *
00011 * The above copyright notice and this permission notice shall be included
00012 * in all copies or substantial portions of the Software.
00013 *
00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020 * OTHER DEALINGS IN THE SOFTWARE.
00021 *
00022 * Except as contained in this notice, the name of Maxim Integrated
00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024 * Products, Inc. Branding Policy.
00025 *
00026 * The mere transfer of this software does not imply any licenses
00027 * of trade secrets, proprietary technology, copyrights, patents,
00028 * trademarks, maskwork rights, or any other form of intellectual
00029 * property whatsoever. Maxim Integrated Products, Inc. retains all
00030 * ownership rights.
00031 **********************************************************************/
00032 
00033 
00034 #ifndef BMI160_H
00035 #define BMI160_H
00036 
00037 #include "mbed.h"
00038 
00039 /**
00040 @brief The BMI160 is a small, low power, low noise 16-bit inertial measurement
00041 unit designed for use in mobile applications like augmented reality or indoor
00042 navigation which require highly accurate, real-time sensor data.
00043 
00044 In full operation mode, with both the accelerometer and gyroscope enabled, the
00045 current consumption is typically 950 μA, enabling always-on applications in
00046 battery driven devices. It is available in a compact 14-pin 2.5 x 3.0 x 0.8 mm³
00047 LGA package."
00048 
00049 This class is an abstract base class and can not be instaniated, use BMI160_I2C 
00050 or BMI160_SPI.
00051 */
00052 class BMI160
00053 {
00054 public:
00055 
00056     ///Return value on success.
00057     static const uint8_t RTN_NO_ERROR = 0;
00058     
00059     ///Sensor types
00060     enum Sensors
00061     {
00062         MAG = 0, ///<Optional external sensor
00063         GYRO,    ///<Angular rate sensor
00064         ACC      ///<g sensor
00065     };
00066     
00067     ///Sensor Axis
00068     enum SensorAxis
00069     {
00070         X_AXIS = 0,
00071         Y_AXIS,
00072         Z_AXIS
00073     };
00074     
00075     ///Structure for axis data
00076     struct AxisData
00077     {
00078         int16_t raw;  ///<Axis raw data
00079         float scaled; ///<Axis scaled data 
00080     };
00081     
00082     ///Structure for sensor time data
00083     struct SensorTime
00084     {
00085         uint32_t raw;  ///<raw SensorTime
00086         float seconds; ///<SensorTime as seconds
00087     };
00088     
00089     ///Structure for holding sensor data
00090     struct SensorData
00091     {
00092         AxisData xAxis; ///<Sensor X axis data
00093         AxisData yAxis; ///<Sensor Y axis data
00094         AxisData zAxis; ///<Sensor Z axis data
00095     };
00096     
00097     
00098     ///BMI160 registers
00099     enum Registers
00100     {
00101         CHIP_ID = 0x00,  ///<Chip Identification. 
00102         ERR_REG = 0x02,  ///<Reports sensor error flags.  Flags reset when read.
00103         PMU_STATUS,      ///<Reports current power mode for sensors.
00104         DATA_0,          ///<MAG_X axis bits7:0
00105         DATA_1,          ///<MAG_X axis bits15:8
00106         DATA_2,          ///<MAG_Y axis bits7:0
00107         DATA_3,          ///<MAG_Y axis bits15:8
00108         DATA_4,          ///<MAG_Z axis bits7:0
00109         DATA_5,          ///<MAG_Z axis bits15:8
00110         DATA_6,          ///<RHALL bits7:0
00111         DATA_7,          ///<RHALL bits15:8
00112         DATA_8,          ///<GYR_X axis bits7:0
00113         DATA_9,          ///<GYR_X axis bits15:8
00114         DATA_10,         ///<GYR_Y axis bits7:0
00115         DATA_11,         ///<GYR_Y axis bits15:8
00116         DATA_12,         ///<GYR_Z axis bits7:0
00117         DATA_13,         ///<GYR_Z axis bits15:8
00118         DATA_14,         ///<ACC_X axis bits7:0
00119         DATA_15,         ///<ACC_X axis bits15:8
00120         DATA_16,         ///<ACC_Y axis bits7:0
00121         DATA_17,         ///<ACC_Y axis bits15:8
00122         DATA_18,         ///<ACC_Z axis bits7:0
00123         DATA_19,         ///<ACC_Z axis bits15:8
00124         SENSORTIME_0,    ///<24bit counter synchronized with data, bits7:0
00125         SENSORTIME_1,    ///<24bit counter synchronized with data, bits15:8
00126         SENSORTIME_2,    ///<24bit counter synchronized with data, bits23:16
00127         STATUS,          ///<Reports sensors status flags
00128         INT_STATUS_0,    ///<Contains interrupt status flags
00129         INT_STATUS_1,    ///<Contains interrupt status flags
00130         INT_STATUS_2,    ///<Contains interrupt status flags
00131         INT_STATUS_3,    ///<Contains interrupt status flags
00132         TEMPERATURE_0,   ///<Contains temperature of sensor, bits7:0
00133         TEMPERATURE_1,   ///<Contains temperature of sensor, bits15:8
00134         FIFO_LENGTH_0,   ///<Current fill level of FIFO, bits7:0
00135         FIFO_LENGTH_1,   ///<Current fill level of FIFO, bits10:8
00136         FIFO_DATA,       ///<FIFO data read out register, burst read
00137         ACC_CONF = 0x40, ///<Set ODR, bandwidth, and read mode of accelerometer
00138         ACC_RANGE,       ///<Sets accelerometer g-range
00139         GYR_CONF,        ///<Set ODR, bandwidth, and read mode of gyroscope
00140         GYR_RANGE,       ///<Sets gyroscope angular rate measurement range
00141         MAG_CONF,        ///<Sets ODR of magnetometer interface
00142         FIFO_DOWNS,      ///<Sets down sampling ratios of accel and gyro data 
00143                          ///<for FIFO
00144         FIFO_CONFIG_0,   ///<Sets FIFO Watermark
00145         FIFO_CONFIG_1,   ///<Sets which sensor data is available in FIFO, 
00146                          ///<Header/Headerless mode, Ext Int tagging, Sensortime
00147         MAG_IF_0 = 0x4B, ///<Magnetometer 7-bit I2C address, bits7:1
00148         MAG_IF_1,        ///<Magnetometer interface configuration
00149         MAG_IF_2,        ///<Magnetometer address to read
00150         MAG_IF_3,        ///<Magnetometer address to write
00151         MAG_IF_4,        ///<Magnetometer data to write
00152         INT_EN_0,        ///<Interrupt enable bits
00153         INT_EN_1,        ///<Interrupt enable bits
00154         INT_EN_2,        ///<Interrupt enable bits
00155         INT_OUT_CTRL,    ///<Contains the behavioral configuration of INT pins
00156         INT_LATCH,       ///<Contains the interrupt rest bit and the interrupt 
00157                          ///<mode selection
00158         INT_MAP_0,       ///<Controls which interrupt signals are mapped to the 
00159                          ///<INT1 and INT2 pins
00160         INT_MAP_1,       ///<Controls which interrupt signals are mapped to the 
00161                          ///<INT1 and INT2 pins
00162         INT_MAP_2,       ///<Controls which interrupt signals are mapped to the 
00163                          ///<INT1 and INT2 pins
00164         INT_DATA_0,      ///<Contains the data source definition for the two 
00165                          ///<interrupt groups
00166         INT_DATA_1,      ///<Contains the data source definition for the two 
00167                          ///<interrupt groups
00168         INT_LOWHIGH_0,   ///<Contains the configuration for the low g interrupt
00169         INT_LOWHIGH_1,   ///<Contains the configuration for the low g interrupt
00170         INT_LOWHIGH_2,   ///<Contains the configuration for the low g interrupt
00171         INT_LOWHIGH_3,   ///<Contains the configuration for the low g interrupt
00172         INT_LOWHIGH_4,   ///<Contains the configuration for the low g interrupt
00173         INT_MOTION_0,    ///<Contains the configuration for the any motion and 
00174                          ///<no motion interrupts
00175         INT_MOTION_1,    ///<Contains the configuration for the any motion and 
00176                          ///<no motion interrupts
00177         INT_MOTION_2,    ///<Contains the configuration for the any motion and 
00178                          ///<no motion interrupts
00179         INT_MOTION_3,    ///<Contains the configuration for the any motion and 
00180                          ///<no motion interrupts
00181         INT_TAP_0,       ///<Contains the configuration for the tap interrupts
00182         INT_TAP_1,       ///<Contains the configuration for the tap interrupts
00183         INT_ORIENT_0,    ///<Contains the configuration for the oeientation 
00184                          ///<interrupt
00185         INT_ORIENT_1,    ///<Contains the configuration for the oeientation 
00186                          ///<interrupt
00187         INT_FLAT_0,      ///<Contains the configuration for the flat interrupt
00188         INT_FLAT_1,      ///<Contains the configuration for the flat interrupt
00189         FOC_CONF,        ///<Contains configuration for the fast offset 
00190                          ///<compensation for the accelerometer and gyroscope
00191         CONF,            ///<Configuration of sensor, nvm_prog_en bit
00192         IF_CONF,         ///<Contains settings for the digital interface
00193         PMU_TRIGGER,     ///<Sets trigger conditions to change gyro power modes
00194         SELF_TEST,       ///<Self test configuration
00195         NV_CONF = 0x70,  ///<Contains settings for the digital interface
00196         OFFSET_0,        ///<Contains offset comp values for acc_off_x7:0
00197         OFFSET_1,        ///<Contains offset comp values for acc_off_y7:0
00198         OFFSET_2,        ///<Contains offset comp values for acc_off_z7:0
00199         OFFSET_3,        ///<Contains offset comp values for gyr_off_x7:0
00200         OFFSET_4,        ///<Contains offset comp values for gyr_off_y7:0
00201         OFFSET_5,        ///<Contains offset comp values for gyr_off_z7:0
00202         OFFSET_6,        ///<gyr/acc offset enable bit and gyr_off_(zyx) bits9:8
00203         STEP_CNT_0,      ///<Step counter bits 15:8
00204         STEP_CNT_1,      ///<Step counter bits 7:0
00205         STEP_CONF_0,     ///<Contains configuration of the step detector
00206         STEP_CONF_1,     ///<Contains configuration of the step detector
00207         CMD = 0x7E       ///<Command register triggers operations like 
00208                          ///<softreset, NVM programming, etc.
00209     };
00210     
00211     
00212     ///@name ERR_REG(0x02)
00213     ///Error register data
00214     ///@{
00215         
00216     static const uint8_t FATAL_ERR_MASK = 0x01;
00217     static const uint8_t FATAL_ERR_POS = 0x00;
00218     static const uint8_t ERR_CODE_MASK = 0x1E;
00219     static const uint8_t ERR_CODE_POS = 0x01;
00220     static const uint8_t I2C_FAIL_ERR_MASK = 0x20;
00221     static const uint8_t I2C_FAIL_ERR_POS = 0x05;
00222     static const uint8_t DROP_CMD_ERR_MASK = 0x40;
00223     static const uint8_t DROP_CMD_ERR_POS = 0x06;
00224     static const uint8_t MAG_DRDY_ERR_MASK = 0x80;
00225     static const uint8_t MAG_DRDY_ERR_POS = 0x08;
00226     
00227     ///Enumerated error codes
00228     enum ErrorCodes
00229     {
00230         NO_ERROR = 0,        ///<No Error
00231         ERROR_1,             ///<Listed as error   
00232         ERROR_2,             ///<Listed as error
00233         LPM_INT_PFD,         ///<Low-power mode and interrupt uses pre-filtered 
00234                              ///<data
00235         ODR_MISMATCH = 0x06, ///<ODRs of enabled sensors in headerless mode do 
00236                              ///<not match
00237         PFD_USED_LPM         ///<Pre-filtered data are used in low power mode
00238     };
00239     ///@}
00240     
00241     
00242     ///@name ACC_CONF(0x40) and ACC_RANGE(0x41) 
00243     ///Data for configuring accelerometer
00244     ///@{
00245         
00246     static const uint8_t ACC_ODR_MASK = 0x0F;
00247     static const uint8_t ACC_ODR_POS = 0x00;
00248     static const uint8_t ACC_BWP_MASK = 0x70;
00249     static const uint8_t ACC_BWP_POS = 0x04;
00250     static const uint8_t ACC_US_MASK = 0x80;
00251     static const uint8_t ACC_US_POS = 0x07;
00252     static const uint8_t ACC_RANGE_MASK = 0x0F;
00253     static const uint8_t ACC_RANGE_POS = 0x00;
00254     
00255     ///Accelerometer output data rates
00256     enum AccOutputDataRate
00257     {
00258         ACC_ODR_1 = 1,  ///< 25/32Hz
00259         ACC_ODR_2,      ///< 25/16Hz
00260         ACC_ODR_3,      ///< 25/8Hz
00261         ACC_ODR_4,      ///< 25/4Hz
00262         ACC_ODR_5,      ///< 25/2Hz
00263         ACC_ODR_6,      ///< 25Hz
00264         ACC_ODR_7,      ///< 50Hz
00265         ACC_ODR_8,      ///< 100Hz
00266         ACC_ODR_9,      ///< 200Hz
00267         ACC_ODR_10,     ///< 400Hz
00268         ACC_ODR_11,     ///< 800Hz
00269         ACC_ODR_12      ///< 1600Hz
00270     };
00271     
00272     ///Accelerometer bandwidth parameters
00273     enum AccBandWidthParam
00274     {
00275         ACC_BWP_0 = 0, ///< Average 1 cycle;  when acc_us = 0 OSR4
00276         ACC_BWP_1,     ///< Average 2 cycles; when acc_us = 0 OSR2
00277         ACC_BWP_2,     ///< Average 4 cycles; when acc_us = 0 normal mode
00278         ACC_BWP_3,     ///< Average 8 cycles
00279         ACC_BWP_4,     ///< Average 16 cycles
00280         ACC_BWP_5,     ///< Average 32 cycles
00281         ACC_BWP_6,     ///< Average 64 cycles
00282         ACC_BWP_7      ///< Average 128 cycles
00283     };
00284     
00285     ///Accelerometer undersampling
00286     enum AccUnderSampling
00287     {
00288         ACC_US_OFF = 0,
00289         ACC_US_ON
00290     };
00291     
00292     ///Accelerometer ranges
00293     enum AccRange
00294     {
00295         SENS_2G = 0x03,  ///<Accelerometer range +-2G
00296         SENS_4G = 0x05,  ///<Accelerometer range +-4G
00297         SENS_8G = 0x08,  ///<Accelerometer range +-8G
00298         SENS_16G = 0x0C ///<Accelerometer range +-16G
00299     };
00300     
00301     ///Accelerometer configuration data structure
00302     struct AccConfig
00303     {
00304         AccRange range;        ///<Accelerometer range
00305         AccUnderSampling us;   ///<Accelerometr undersampling mode
00306         AccBandWidthParam bwp; ///<Accelerometer bandwidth param
00307         AccOutputDataRate odr; ///<Accelerometr output data rate
00308     };
00309     
00310     ///Accelerometer default configuration
00311     static const AccConfig DEFAULT_ACC_CONFIG;
00312     ///@}
00313     
00314     
00315     ///@name GYR_CONF(0x42) and GYR_RANGE(0x43) 
00316     ///Data for configuring gyroscope
00317     ///@{
00318     
00319     static const uint8_t GYRO_ODR_MASK = 0x0F;
00320     static const uint8_t GYRO_ODR_POS = 0x00;
00321     static const uint8_t GYRO_BWP_MASK = 0x30;
00322     static const uint8_t GYRO_BWP_POS = 0x04;
00323     static const uint8_t GYRO_RANGE_MASK = 0x07;
00324     static const uint8_t GYRO_RANGE_POS = 0x00;
00325     
00326     ///Gyroscope output data rates
00327     enum GyroOutputDataRate
00328     {
00329         GYRO_ODR_6 = 0x06,  ///<25Hz 
00330         GYRO_ODR_7 = 0x07,  ///<50Hz
00331         GYRO_ODR_8 = 0x08,  ///<100Hz
00332         GYRO_ODR_9 = 0x09,  ///<200Hz
00333         GYRO_ODR_10 = 0x0A, ///<400Hz
00334         GYRO_ODR_11 = 0x0B, ///<800Hz
00335         GYRO_ODR_12 = 0x0C, ///<1600Hz
00336         GYRO_ODR_13 = 0x0D  ///<3200Hz
00337     };
00338     
00339     ///Gyroscope bandwidth paramaters
00340     enum GyroBandWidthParam
00341     {
00342         GYRO_BWP_0 = 0, ///<OSR4 Over Sampling Rate of 4
00343         GYRO_BWP_1,     ///<OSR2 Over Sampling Rate of 2
00344         GYRO_BWP_2      ///<Normal Mode, Equidistant Sampling
00345     };
00346     
00347     ///Gyroscope ranges
00348     enum GyroRange
00349     {
00350         DPS_2000 = 0, ///<+-2000dps, 16.4LSB/dps
00351         DPS_1000,     ///<+-1000dps, 32.8LSB/dps
00352         DPS_500,      ///<+-500dps, 65.6LSB/dps
00353         DPS_250,      ///<+-250dps, 131.2LSB/dps
00354         DPS_125       ///<+-125dps, 262.4LSB/dps, 
00355     };
00356     
00357     ///Gyroscope configuration data structure    
00358     struct GyroConfig
00359     {
00360         GyroRange range;        ///<Gyroscope range
00361         GyroBandWidthParam bwp; ///<Gyroscope bandwidth param
00362         GyroOutputDataRate odr; ///<Gyroscope output data rate
00363     };
00364     
00365     ///Gyroscope default configuration
00366     static const GyroConfig DEFAULT_GYRO_CONFIG;
00367     ///@}
00368     
00369     
00370     ///Enumerated power modes
00371     enum PowerModes
00372     {
00373         SUSPEND = 0,  ///<Acc and Gyro, No sampling, No FIFO data readout
00374         NORMAL,       ///<Acc and Gyro, Full chip operation
00375         LOW_POWER,    ///<Acc duty-cycling between suspend and normal
00376         FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms
00377     };
00378     
00379     
00380     ///Enumerated commands used with CMD register
00381     enum Commands
00382     {
00383         START_FOC = 0x03,        ///<Starts Fast Offset Calibrartion 
00384         ACC_SET_PMU_MODE = 0x10, ///<Sets acc power mode
00385         GYR_SET_PMU_MODE = 0x14, ///<Sets gyro power mode
00386         MAG_SET_PMU_MODE = 0x18, ///<Sets mag power mode
00387         PROG_NVM = 0xA0,         ///<Writes NVM backed registers into NVM
00388         FIFO_FLUSH = 0xB0,       ///<Clears FIFO
00389         INT_RESET,               ///<Clears interrupt engine, INT_STATUS, and 
00390                                  ///<the interrupt pin
00391         STEP_CNT_CLR,            ///<Triggers reset of the step counter
00392         SOFT_RESET = 0xB6        ///<Triggers a reset including a reboot.
00393     };
00394     
00395     
00396     ///@brief BMI160 Destructor.\n
00397     ///
00398     ///On Entry:
00399     ///@param[in] none 
00400     ///
00401     ///On Exit:
00402     ///@param[out] none
00403     ///
00404     ///@returns none
00405     virtual ~BMI160(){ }
00406     
00407     
00408     ///@brief Reads a single register.\n
00409     ///
00410     ///On Entry:
00411     ///@param[in] data - pointer to memory for storing read data
00412     ///
00413     ///On Exit:
00414     ///@param[out] data - holds contents of read register on success
00415     ///
00416     ///@returns 0 on success, non 0 on failure
00417     virtual int32_t readRegister(Registers reg, uint8_t *data) = 0;
00418     
00419     
00420     ///@brief Writes a single register.\n
00421     ///
00422     ///On Entry:
00423     ///@param[in] data - data to write to register
00424     ///
00425     ///On Exit:
00426     ///@param[out] none
00427     ///
00428     ///@returns 0 on success, non 0 on failure
00429     virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0;
00430     
00431     
00432     ///@brief Reads a block of registers.\n
00433     ///@detail User must ensure that all registers between 'startReg' and 
00434     ///'stopReg' exist and are readable.  Function reads up to, including, 
00435     ///'stopReg'.\n
00436     ///
00437     ///On Entry:
00438     ///@param[in] startReg - register to start reading from
00439     ///@param[in] stopReg - register to stop reading from
00440     ///@param[in] data - pointer to memory for storing read data
00441     ///
00442     ///On Exit:
00443     ///@param[out] data - holds contents of read registers on success
00444     ///
00445     ///@returns 0 on success, non 0 on failure
00446     virtual int32_t readBlock(Registers startReg, Registers stopReg, 
00447     uint8_t *data) = 0;
00448     
00449     
00450     ///@brief Writes a block of registers.\n
00451     ///@detail User must ensure that all registers between 'startReg' and 
00452     ///'stopReg' exist and are writeable.  Function writes up to, including, 
00453     ///'stopReg'.\n
00454     ///
00455     ///On Entry:
00456     ///@param[in] startReg - register to start writing at 
00457     ///@param[in] stopReg - register to stop writing at
00458     ///@param[in] data - pointer to data to write to registers
00459     ///
00460     ///On Exit:
00461     ///@param[out] none
00462     ///
00463     ///@returns 0 on success, non 0 on failure
00464     virtual int32_t writeBlock(Registers startReg, Registers stopReg, 
00465     const uint8_t *data) = 0;
00466     
00467     
00468     ///@brief Sets sensors power mode through CMD register.\n
00469     ///@details Observe command execution times given in datasheet.\n 
00470     ///
00471     ///On Entry:
00472     ///@param[in] sensor - Sensor which power mode we are setting
00473     ///@param[in] pwrMode - Desired powermode of the sensor
00474     ///
00475     ///On Exit:
00476     ///@param[out] 
00477     ///
00478     ///@returns 0 on success, non 0 on failure
00479     int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode);
00480     
00481     
00482     ///@brief Configure sensor.\n
00483     ///
00484     ///On Entry:
00485     ///@param[in] config - sSensor configuration data structure
00486     ///
00487     ///On Exit:
00488     ///@param[out] none
00489     ///
00490     ///@returns 0 on success, non 0 on failure
00491     int32_t setSensorConfig(const AccConfig &config);
00492     int32_t setSensorConfig(const GyroConfig &config);
00493     
00494     
00495     ///@brief Get sensor configuration.\n
00496     ///
00497     ///On Entry:
00498     ///@param[in] config - Sensor configuration data structure
00499     ///
00500     ///On Exit:
00501     ///@param[out] config - on success, holds sensor's current 
00502     ///configuration
00503     ///
00504     ///@returns 0 on success, non 0 on failure
00505     int32_t getSensorConfig(AccConfig &config);
00506     int32_t getSensorConfig(GyroConfig &config);
00507     
00508     
00509     ///@brief Get sensor axis.\n
00510     ///
00511     ///On Entry:
00512     ///@param[in] axis - Sensor axis
00513     ///@param[in] data - AxisData structure
00514     ///@param[in] range - Sensor range
00515     ///
00516     ///On Exit:
00517     ///@param[out] data - Structure holds raw and scaled axis data
00518     ///
00519     ///@returns 0 on success, non 0 on failure
00520     int32_t getSensorAxis(SensorAxis axis, AxisData &data, AccRange range);
00521     int32_t getSensorAxis(SensorAxis axis, AxisData &data, GyroRange range);
00522     
00523     
00524     ///@brief Get sensor xyz axis.\n
00525     ///
00526     ///On Entry:
00527     ///@param[in] data - SensorData structure
00528     ///@param[in] range - Sensor range
00529     ///
00530     ///On Exit:
00531     ///@param[out] data - Structure holds raw and scaled data for all three axis
00532     ///
00533     ///@returns 0 on success, non 0 on failure
00534     int32_t getSensorXYZ(SensorData &data, AccRange range);
00535     int32_t getSensorXYZ(SensorData &data, GyroRange range);
00536     
00537     
00538     ///@brief Get sensor xyz axis and sensor time.\n
00539     ///
00540     ///On Entry:
00541     ///@param[in] data - SensorData structure
00542     ///@param[in] sensorTime - SensorTime structure for data
00543     ///@param[in] range - Sensor range
00544     ///
00545     ///On Exit:
00546     ///@param[out] data - Structure holds raw and scaled data for all three axis
00547     ///@param[out] sensorTime - Holds sensor time on success
00548     ///
00549     ///@returns 0 on success, non 0 on failure
00550     int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime, 
00551                                       AccRange range);
00552     int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime, 
00553                                       GyroRange range);
00554     
00555     
00556     ///@brief Get Gyroscope/Accelerometer data and sensor time.\n
00557     ///
00558     ///On Entry:
00559     ///@param[in] accData -  Sensor data structure for accelerometer
00560     ///@param[in] gyroData - Sensor data structure for gyroscope
00561     ///@param[in] sensorTime - SensorTime data structure
00562     ///@param[in] accRange - Accelerometer range
00563     ///@param[in] gyroRange - Gyroscope range
00564     ///
00565     ///On Exit:
00566     ///@param[out] accData -  Synchronized accelerometer data
00567     ///@param[out] gyroData - Synchronized gyroscope data
00568     ///@param[out] sensorTime - Synchronized sensor time
00569     ///
00570     ///@returns 0 on success, non 0 on failure
00571     int32_t getGyroAccXYZandSensorTime(SensorData &accData, 
00572                                        SensorData &gyroData, 
00573                                        SensorTime &sensorTime, 
00574                                        AccRange accRange, GyroRange gyroRange);
00575     
00576     
00577     ///@brief Get sensor time.\n
00578     ///
00579     ///On Entry:
00580     ///@param[in] sensorTime - SensorTime structure for data
00581     ///
00582     ///On Exit:
00583     ///@param[out] sensorTime - Holds sensor time on success
00584     ///
00585     ///@returns returns 0 on success, non 0 on failure
00586     int32_t getSensorTime(SensorTime &sensorTime);
00587     
00588     
00589     ///@brief Get die temperature.\n
00590     ///
00591     ///On Entry:
00592     ///@param[in] temp - pointer to float for temperature 
00593     ///
00594     ///On Exit:
00595     ///@param[out] temp - on success, holds the die temperature
00596     ///
00597     ///@returns 0 on success, non 0 on failure
00598     int32_t getTemperature(float *temp);
00599 };
00600 
00601 
00602 /**
00603 @brief BMI160_I2C - supports BMI160 object with I2C interface
00604 */
00605 class BMI160_I2C: public BMI160
00606 {
00607 public:
00608 
00609     ///BMI160 default I2C address.
00610     static const uint8_t I2C_ADRS_SDO_LO = 0x68;
00611     ///BMI160 optional I2C address.
00612     static const uint8_t I2C_ADRS_SDO_HI = 0x69;
00613     
00614 
00615     ///@brief BMI160_I2C Constructor.\n
00616     ///
00617     ///On Entry:
00618     ///@param[in] i2cBus - reference to I2C bus for this device
00619     ///@param[in] i2cAdrs - 7-bit I2C address
00620     ///
00621     ///On Exit:
00622     ///@param[out] none
00623     ///
00624     ///@returns none
00625     BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs);
00626     
00627     
00628     ///@brief Reads a single register.\n
00629     ///
00630     ///On Entry:
00631     ///@param[in] data - pointer to memory for storing read data
00632     ///
00633     ///On Exit:
00634     ///@param[out] data - holds contents of read register on success
00635     ///
00636     ///@returns 0 on success, non 0 on failure
00637     virtual int32_t readRegister(Registers reg, uint8_t *data);
00638     
00639     
00640     ///@brief Writes a single register.\n
00641     ///
00642     ///On Entry:
00643     ///@param[in] data - data to write to register
00644     ///
00645     ///On Exit:
00646     ///@param[out] none
00647     ///
00648     ///@returns 0 on success, non 0 on failure
00649     virtual int32_t writeRegister(Registers reg, const uint8_t data);
00650     
00651     
00652     ///@brief Reads a block of registers.\n
00653     ///@detail User must ensure that all registers between 'startReg' and 
00654     ///'stopReg' exist and are readable.  Function reads up to, including, 
00655     ///'stopReg'.\n
00656     ///
00657     ///On Entry:
00658     ///@param[in] startReg - register to start reading from
00659     ///@param[in] stopReg - register to stop reading from
00660     ///@param[in] data - pointer to memory for storing read data
00661     ///
00662     ///On Exit:
00663     ///@param[out] data - holds contents of read registers on success
00664     ///
00665     ///@returns 0 on success, non 0 on failure
00666     virtual int32_t readBlock(Registers startReg, Registers stopReg, 
00667     uint8_t *data);
00668     
00669     
00670     ///@brief Writes a block of registers.\n
00671     ///@detail User must ensure that all registers between 'startReg' and 
00672     ///'stopReg' exist and are writeable.  Function writes up to, including, 
00673     ///'stopReg'.\n
00674     ///
00675     ///On Entry:
00676     ///@param[in] startReg - register to start writing at 
00677     ///@param[in] stopReg - register to stop writing at
00678     ///@param[in] data - pointer to data to write to registers
00679     ///
00680     ///On Exit:
00681     ///@param[out] none
00682     ///
00683     ///@returns 0 on success, non 0 on failure
00684     virtual int32_t writeBlock(Registers startReg, Registers stopReg, 
00685     const uint8_t *data);
00686     
00687 private:
00688 
00689     I2C &m_i2cBus;
00690     uint8_t m_Wadrs, m_Radrs;
00691 };
00692 
00693 
00694 /**
00695 @brief BMI160_SPI - supports BMI160 object with SPI interface
00696 */
00697 class BMI160_SPI: public BMI160
00698 {
00699 public:
00700 
00701     ///@brief BMI160_SPI Constructor.\n
00702     ///
00703     ///On Entry:
00704     ///@param[in] spiBus - reference to SPI bus for this device
00705     ///@param[in] cs - reference to DigitalOut used for chip select
00706     ///
00707     ///On Exit:
00708     ///@param[out] none
00709     ///
00710     ///@returns none
00711     BMI160_SPI(SPI &spiBus, DigitalOut &cs);
00712     
00713     
00714     ///@brief Reads a single register.\n
00715     ///
00716     ///On Entry:
00717     ///@param[in] data - pointer to memory for storing read data
00718     ///
00719     ///On Exit:
00720     ///@param[out] data - holds contents of read register on success
00721     ///
00722     ///@returns 0 on success, non 0 on failure
00723     virtual int32_t readRegister(Registers reg, uint8_t *data);
00724     
00725     
00726     ///@brief Writes a single register.\n
00727     ///
00728     ///On Entry:
00729     ///@param[in] data - data to write to register
00730     ///
00731     ///On Exit:
00732     ///@param[out] none
00733     ///
00734     ///@returns 0 on success, non 0 on failure
00735     virtual int32_t writeRegister(Registers reg, const uint8_t data);
00736     
00737     
00738     ///@brief Reads a block of registers.\n
00739     ///@detail User must ensure that all registers between 'startReg' and 
00740     ///'stopReg' exist and are readable.  Function reads up to, including, 
00741     ///'stopReg'.\n
00742     ///
00743     ///On Entry:
00744     ///@param[in] startReg - register to start reading from
00745     ///@param[in] stopReg - register to stop reading from
00746     ///@param[in] data - pointer to memory for storing read data
00747     ///
00748     ///On Exit:
00749     ///@param[out] data - holds contents of read registers on success
00750     ///
00751     ///@returns 0 on success, non 0 on failure
00752     virtual int32_t readBlock(Registers startReg, Registers stopReg, 
00753     uint8_t *data);
00754     
00755     
00756     ///@brief Writes a block of registers.\n
00757     ///@detail User must ensure that all registers between 'startReg' and 
00758     ///'stopReg' exist and are writeable.  Function writes up to, including, 
00759     ///'stopReg'.\n
00760     ///
00761     ///On Entry:
00762     ///@param[in] startReg - register to start writing at 
00763     ///@param[in] stopReg - register to stop writing at
00764     ///@param[in] data - pointer to data to write to registers
00765     ///
00766     ///On Exit:
00767     ///@param[out] none
00768     ///
00769     ///@returns 0 on success, non 0 on failure
00770     virtual int32_t writeBlock(Registers startReg, Registers stopReg, 
00771     const uint8_t *data);
00772     
00773 private:
00774 
00775     SPI &m_spiBus;
00776     DigitalOut m_cs;
00777 };
00778 
00779 #endif /* BMI160_H */
00780 
00781 
00782 ///@brief fx documentation template.\n
00783 ///
00784 ///On Entry:
00785 ///@param[in] none 
00786 ///
00787 ///On Exit:
00788 ///@param[out] none
00789 ///
00790 ///@returns none