Utility library for HSP SPo2 HR demo including user interface, board support adn accelerometer.

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     ///Period of internal counter
00090     static const float SENSOR_TIME_LSB = 39e-6;
00091 
00092     ///Structure for holding sensor data
00093     struct SensorData
00094     {
00095         AxisData xAxis; ///<Sensor X axis data
00096         AxisData yAxis; ///<Sensor Y axis data
00097         AxisData zAxis; ///<Sensor Z axis data
00098     };
00099 
00100 
00101     ///BMI160 registers
00102     enum Registers
00103     {
00104         CHIP_ID = 0x00,  ///<Chip Identification.
00105         ERR_REG = 0x02,  ///<Reports sensor error flags.  Flags reset when read.
00106         PMU_STATUS,      ///<Reports current power mode for sensors.
00107         DATA_0,          ///<MAG_X axis bits7:0
00108         DATA_1,          ///<MAG_X axis bits15:8
00109         DATA_2,          ///<MAG_Y axis bits7:0
00110         DATA_3,          ///<MAG_Y axis bits15:8
00111         DATA_4,          ///<MAG_Z axis bits7:0
00112         DATA_5,          ///<MAG_Z axis bits15:8
00113         DATA_6,          ///<RHALL bits7:0
00114         DATA_7,          ///<RHALL bits15:8
00115         DATA_8,          ///<GYR_X axis bits7:0
00116         DATA_9,          ///<GYR_X axis bits15:8
00117         DATA_10,         ///<GYR_Y axis bits7:0
00118         DATA_11,         ///<GYR_Y axis bits15:8
00119         DATA_12,         ///<GYR_Z axis bits7:0
00120         DATA_13,         ///<GYR_Z axis bits15:8
00121         DATA_14,         ///<ACC_X axis bits7:0
00122         DATA_15,         ///<ACC_X axis bits15:8
00123         DATA_16,         ///<ACC_Y axis bits7:0
00124         DATA_17,         ///<ACC_Y axis bits15:8
00125         DATA_18,         ///<ACC_Z axis bits7:0
00126         DATA_19,         ///<ACC_Z axis bits15:8
00127         SENSORTIME_0,    ///<24bit counter synchronized with data, bits7:0
00128         SENSORTIME_1,    ///<24bit counter synchronized with data, bits15:8
00129         SENSORTIME_2,    ///<24bit counter synchronized with data, bits23:16
00130         STATUS,          ///<Reports sensors status flags
00131         INT_STATUS_0,    ///<Contains interrupt status flags
00132         INT_STATUS_1,    ///<Contains interrupt status flags
00133         INT_STATUS_2,    ///<Contains interrupt status flags
00134         INT_STATUS_3,    ///<Contains interrupt status flags
00135         TEMPERATURE_0,   ///<Contains temperature of sensor, bits7:0
00136         TEMPERATURE_1,   ///<Contains temperature of sensor, bits15:8
00137         FIFO_LENGTH_0,   ///<Current fill level of FIFO, bits7:0
00138         FIFO_LENGTH_1,   ///<Current fill level of FIFO, bits10:8
00139         FIFO_DATA,       ///<FIFO data read out register, burst read
00140         ACC_CONF = 0x40, ///<Set ODR, bandwidth, and read mode of accelerometer
00141         ACC_RANGE,       ///<Sets accelerometer g-range
00142         GYR_CONF,        ///<Set ODR, bandwidth, and read mode of gyroscope
00143         GYR_RANGE,       ///<Sets gyroscope angular rate measurement range
00144         MAG_CONF,        ///<Sets ODR of magnetometer interface
00145         FIFO_DOWNS,      ///<Sets down sampling ratios of accel and gyro data
00146                          ///<for FIFO
00147         FIFO_CONFIG_0,   ///<Sets FIFO Watermark
00148         FIFO_CONFIG_1,   ///<Sets which sensor data is available in FIFO,
00149                          ///<Header/Headerless mode, Ext Int tagging, Sensortime
00150         MAG_IF_0 = 0x4B, ///<Magnetometer 7-bit I2C address, bits7:1
00151         MAG_IF_1,        ///<Magnetometer interface configuration
00152         MAG_IF_2,        ///<Magnetometer address to read
00153         MAG_IF_3,        ///<Magnetometer address to write
00154         MAG_IF_4,        ///<Magnetometer data to write
00155         INT_EN_0,        ///<Interrupt enable bits
00156         INT_EN_1,        ///<Interrupt enable bits
00157         INT_EN_2,        ///<Interrupt enable bits
00158         INT_OUT_CTRL,    ///<Contains the behavioral configuration of INT pins
00159         INT_LATCH,       ///<Contains the interrupt rest bit and the interrupt
00160                          ///<mode selection
00161         INT_MAP_0,       ///<Controls which interrupt signals are mapped to the
00162                          ///<INT1 and INT2 pins
00163         INT_MAP_1,       ///<Controls which interrupt signals are mapped to the
00164                          ///<INT1 and INT2 pins
00165         INT_MAP_2,       ///<Controls which interrupt signals are mapped to the
00166                          ///<INT1 and INT2 pins
00167         INT_DATA_0,      ///<Contains the data source definition for the two
00168                          ///<interrupt groups
00169         INT_DATA_1,      ///<Contains the data source definition for the two
00170                          ///<interrupt groups
00171         INT_LOWHIGH_0,   ///<Contains the configuration for the low g interrupt
00172         INT_LOWHIGH_1,   ///<Contains the configuration for the low g interrupt
00173         INT_LOWHIGH_2,   ///<Contains the configuration for the low g interrupt
00174         INT_LOWHIGH_3,   ///<Contains the configuration for the low g interrupt
00175         INT_LOWHIGH_4,   ///<Contains the configuration for the low g interrupt
00176         INT_MOTION_0,    ///<Contains the configuration for the any motion and
00177                          ///<no motion interrupts
00178         INT_MOTION_1,    ///<Contains the configuration for the any motion and
00179                          ///<no motion interrupts
00180         INT_MOTION_2,    ///<Contains the configuration for the any motion and
00181                          ///<no motion interrupts
00182         INT_MOTION_3,    ///<Contains the configuration for the any motion and
00183                          ///<no motion interrupts
00184         INT_TAP_0,       ///<Contains the configuration for the tap interrupts
00185         INT_TAP_1,       ///<Contains the configuration for the tap interrupts
00186         INT_ORIENT_0,    ///<Contains the configuration for the oeientation
00187                          ///<interrupt
00188         INT_ORIENT_1,    ///<Contains the configuration for the oeientation
00189                          ///<interrupt
00190         INT_FLAT_0,      ///<Contains the configuration for the flat interrupt
00191         INT_FLAT_1,      ///<Contains the configuration for the flat interrupt
00192         FOC_CONF,        ///<Contains configuration for the fast offset
00193                          ///<compensation for the accelerometer and gyroscope
00194         CONF,            ///<Configuration of sensor, nvm_prog_en bit
00195         IF_CONF,         ///<Contains settings for the digital interface
00196         PMU_TRIGGER,     ///<Sets trigger conditions to change gyro power modes
00197         SELF_TEST,       ///<Self test configuration
00198         NV_CONF = 0x70,  ///<Contains settings for the digital interface
00199         OFFSET_0,        ///<Contains offset comp values for acc_off_x7:0
00200         OFFSET_1,        ///<Contains offset comp values for acc_off_y7:0
00201         OFFSET_2,        ///<Contains offset comp values for acc_off_z7:0
00202         OFFSET_3,        ///<Contains offset comp values for gyr_off_x7:0
00203         OFFSET_4,        ///<Contains offset comp values for gyr_off_y7:0
00204         OFFSET_5,        ///<Contains offset comp values for gyr_off_z7:0
00205         OFFSET_6,        ///<gyr/acc offset enable bit and gyr_off_(zyx) bits9:8
00206         STEP_CNT_0,      ///<Step counter bits 15:8
00207         STEP_CNT_1,      ///<Step counter bits 7:0
00208         STEP_CONF_0,     ///<Contains configuration of the step detector
00209         STEP_CONF_1,     ///<Contains configuration of the step detector
00210         CMD = 0x7E       ///<Command register triggers operations like
00211                          ///<softreset, NVM programming, etc.
00212     };
00213 
00214 
00215     ///@name ERR_REG(0x02)
00216     ///Error register data
00217     ///@{
00218 
00219     static const uint8_t FATAL_ERR_MASK = 0x01;
00220     static const uint8_t FATAL_ERR_POS = 0x00;
00221     static const uint8_t ERR_CODE_MASK = 0x1E;
00222     static const uint8_t ERR_CODE_POS = 0x01;
00223     static const uint8_t I2C_FAIL_ERR_MASK = 0x20;
00224     static const uint8_t I2C_FAIL_ERR_POS = 0x05;
00225     static const uint8_t DROP_CMD_ERR_MASK = 0x40;
00226     static const uint8_t DROP_CMD_ERR_POS = 0x06;
00227     static const uint8_t MAG_DRDY_ERR_MASK = 0x80;
00228     static const uint8_t MAG_DRDY_ERR_POS = 0x08;
00229 
00230     ///Enumerated error codes
00231     enum ErrorCodes
00232     {
00233         NO_ERROR = 0,        ///<No Error
00234         ERROR_1,             ///<Listed as error
00235         ERROR_2,             ///<Listed as error
00236         LPM_INT_PFD,         ///<Low-power mode and interrupt uses pre-filtered
00237                              ///<data
00238         ODR_MISMATCH = 0x06, ///<ODRs of enabled sensors in headerless mode do
00239                              ///<not match
00240         PFD_USED_LPM         ///<Pre-filtered data are used in low power mode
00241     };
00242     ///@}
00243 
00244 
00245     ///@name ACC_CONF(0x40) and ACC_RANGE(0x41)
00246     ///Data for configuring accelerometer
00247     ///@{
00248 
00249     static const uint8_t ACC_ODR_MASK = 0x0F;
00250     static const uint8_t ACC_ODR_POS = 0x00;
00251     static const uint8_t ACC_BWP_MASK = 0x70;
00252     static const uint8_t ACC_BWP_POS = 0x04;
00253     static const uint8_t ACC_US_MASK = 0x80;
00254     static const uint8_t ACC_US_POS = 0x07;
00255     static const uint8_t ACC_RANGE_MASK = 0x0F;
00256     static const uint8_t ACC_RANGE_POS = 0x00;
00257 
00258     ///Accelerometer output data rates
00259     enum AccOutputDataRate
00260     {
00261         ACC_ODR_1 = 1,  ///< 25/32Hz
00262         ACC_ODR_2,      ///< 25/16Hz
00263         ACC_ODR_3,      ///< 25/8Hz
00264         ACC_ODR_4,      ///< 25/4Hz
00265         ACC_ODR_5,      ///< 25/2Hz
00266         ACC_ODR_6,      ///< 25Hz
00267         ACC_ODR_7,      ///< 50Hz
00268         ACC_ODR_8,      ///< 100Hz
00269         ACC_ODR_9,      ///< 200Hz
00270         ACC_ODR_10,     ///< 400Hz
00271         ACC_ODR_11,     ///< 800Hz
00272         ACC_ODR_12      ///< 1600Hz
00273     };
00274 
00275     ///Accelerometer bandwidth parameters
00276     enum AccBandWidthParam
00277     {
00278         ACC_BWP_0 = 0, ///< Average 1 cycle;  when acc_us = 0 OSR4
00279         ACC_BWP_1,     ///< Average 2 cycles; when acc_us = 0 OSR2
00280         ACC_BWP_2,     ///< Average 4 cycles; when acc_us = 0 normal mode
00281         ACC_BWP_3,     ///< Average 8 cycles
00282         ACC_BWP_4,     ///< Average 16 cycles
00283         ACC_BWP_5,     ///< Average 32 cycles
00284         ACC_BWP_6,     ///< Average 64 cycles
00285         ACC_BWP_7      ///< Average 128 cycles
00286     };
00287 
00288     ///Accelerometer undersampling
00289     enum AccUnderSampling
00290     {
00291         ACC_US_OFF = 0,
00292         ACC_US_ON
00293     };
00294 
00295     ///Accelerometer ranges
00296     enum AccRange
00297     {
00298         SENS_2G = 0x03,  ///<Accelerometer range +-2G
00299         SENS_4G = 0x05,  ///<Accelerometer range +-4G
00300         SENS_8G = 0x08,  ///<Accelerometer range +-8G
00301         SENS_16G = 0x0C ///<Accelerometer range +-16G
00302     };
00303 
00304     static const float SENS_2G_LSB_PER_G = 16384.0F;
00305     static const float SENS_4G_LSB_PER_G = 8192.0F;
00306     static const float SENS_8G_LSB_PER_G = 4096.0F;
00307     static const float SENS_16G_LSB_PER_G = 2048.0F;
00308 
00309     ///Accelerometer configuration data structure
00310     struct AccConfig
00311     {
00312         AccRange range;        ///<Accelerometer range
00313         AccUnderSampling us;   ///<Accelerometr undersampling mode
00314         AccBandWidthParam bwp; ///<Accelerometer bandwidth param
00315         AccOutputDataRate odr; ///<Accelerometr output data rate
00316     };
00317 
00318     ///Accelerometer default configuration
00319     static const AccConfig DEFAULT_ACC_CONFIG;
00320     ///@}
00321 
00322 
00323     ///@name GYR_CONF(0x42) and GYR_RANGE(0x43)
00324     ///Data for configuring gyroscope
00325     ///@{
00326 
00327     static const uint8_t GYRO_ODR_MASK = 0x0F;
00328     static const uint8_t GYRO_ODR_POS = 0x00;
00329     static const uint8_t GYRO_BWP_MASK = 0x30;
00330     static const uint8_t GYRO_BWP_POS = 0x04;
00331     static const uint8_t GYRO_RANGE_MASK = 0x07;
00332     static const uint8_t GYRO_RANGE_POS = 0x00;
00333 
00334     ///Gyroscope output data rates
00335     enum GyroOutputDataRate
00336     {
00337         GYRO_ODR_6 = 0x06,  ///<25Hz
00338         GYRO_ODR_7 = 0x07,  ///<50Hz
00339         GYRO_ODR_8 = 0x08,  ///<100Hz
00340         GYRO_ODR_9 = 0x09,  ///<200Hz
00341         GYRO_ODR_10 = 0x0A, ///<400Hz
00342         GYRO_ODR_11 = 0x0B, ///<800Hz
00343         GYRO_ODR_12 = 0x0C, ///<1600Hz
00344         GYRO_ODR_13 = 0x0D  ///<3200Hz
00345     };
00346 
00347     ///Gyroscope bandwidth paramaters
00348     enum GyroBandWidthParam
00349     {
00350         GYRO_BWP_0 = 0, ///<OSR4 Over Sampling Rate of 4
00351         GYRO_BWP_1,     ///<OSR2 Over Sampling Rate of 2
00352         GYRO_BWP_2      ///<Normal Mode, Equidistant Sampling
00353     };
00354 
00355     ///Gyroscope ranges
00356     enum GyroRange
00357     {
00358         DPS_2000 = 0, ///<+-2000dps, 16.4LSB/dps
00359         DPS_1000,     ///<+-1000dps, 32.8LSB/dps
00360         DPS_500,      ///<+-500dps, 65.6LSB/dps
00361         DPS_250,      ///<+-250dps, 131.2LSB/dps
00362         DPS_125       ///<+-125dps, 262.4LSB/dps,
00363     };
00364 
00365     static const float SENS_2000_DPS_LSB_PER_DPS = 16.4F;
00366     static const float SENS_1000_DPS_LSB_PER_DPS = 32.8F;
00367     static const float SENS_500_DPS_LSB_PER_DPS = 65.6F;
00368     static const float SENS_250_DPS_LSB_PER_DPS = 131.2F;
00369     static const float SENS_125_DPS_LSB_PER_DPS = 262.4F;
00370 
00371     ///Gyroscope configuration data structure
00372     struct GyroConfig
00373     {
00374         GyroRange range;        ///<Gyroscope range
00375         GyroBandWidthParam bwp; ///<Gyroscope bandwidth param
00376         GyroOutputDataRate odr; ///<Gyroscope output data rate
00377     };
00378 
00379     ///Gyroscope default configuration
00380     static const GyroConfig DEFAULT_GYRO_CONFIG;
00381     ///@}
00382 
00383 
00384     ///Enumerated power modes
00385     enum PowerModes
00386     {
00387         SUSPEND = 0,  ///<Acc and Gyro, No sampling, No FIFO data readout
00388         NORMAL,       ///<Acc and Gyro, Full chip operation
00389         LOW_POWER,    ///<Acc duty-cycling between suspend and normal
00390         FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms
00391     };
00392 
00393 
00394     ///Enumerated commands used with CMD register
00395     enum Commands
00396     {
00397         START_FOC = 0x03,        ///<Starts Fast Offset Calibrartion
00398         ACC_SET_PMU_MODE = 0x10, ///<Sets acc power mode
00399         GYR_SET_PMU_MODE = 0x14, ///<Sets gyro power mode
00400         MAG_SET_PMU_MODE = 0x18, ///<Sets mag power mode
00401         PROG_NVM = 0xA0,         ///<Writes NVM backed registers into NVM
00402         FIFO_FLUSH = 0xB0,       ///<Clears FIFO
00403         INT_RESET,               ///<Clears interrupt engine, INT_STATUS, and
00404                                  ///<the interrupt pin
00405         STEP_CNT_CLR,            ///<Triggers reset of the step counter
00406         SOFT_RESET = 0xB6        ///<Triggers a reset including a reboot.
00407     };
00408 
00409 
00410     ///@brief BMI160 Destructor.\n
00411     ///
00412     ///On Entry:
00413     ///@param[in] none
00414     ///
00415     ///On Exit:
00416     ///@param[out] none
00417     ///
00418     ///@returns none
00419     virtual ~BMI160(){ }
00420 
00421 
00422     ///@brief Reads a single register.\n
00423     ///
00424     ///On Entry:
00425     ///@param[in] data - pointer to memory for storing read data
00426     ///
00427     ///On Exit:
00428     ///@param[out] data - holds contents of read register on success
00429     ///
00430     ///@returns 0 on success, non 0 on failure
00431     virtual int32_t readRegister(Registers reg, uint8_t *data) = 0;
00432 
00433 
00434     ///@brief Writes a single register.\n
00435     ///
00436     ///On Entry:
00437     ///@param[in] data - data to write to register
00438     ///
00439     ///On Exit:
00440     ///@param[out] none
00441     ///
00442     ///@returns 0 on success, non 0 on failure
00443     virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0;
00444 
00445 
00446     ///@brief Reads a block of registers.\n
00447     ///@detail User must ensure that all registers between 'startReg' and
00448     ///'stopReg' exist and are readable.  Function reads up to, including,
00449     ///'stopReg'.\n
00450     ///
00451     ///On Entry:
00452     ///@param[in] startReg - register to start reading from
00453     ///@param[in] stopReg - register to stop reading from
00454     ///@param[in] data - pointer to memory for storing read data
00455     ///
00456     ///On Exit:
00457     ///@param[out] data - holds contents of read registers on success
00458     ///
00459     ///@returns 0 on success, non 0 on failure
00460     virtual int32_t readBlock(Registers startReg, Registers stopReg,
00461     uint8_t *data) = 0;
00462 
00463 
00464     ///@brief Writes a block of registers.\n
00465     ///@detail User must ensure that all registers between 'startReg' and
00466     ///'stopReg' exist and are writeable.  Function writes up to, including,
00467     ///'stopReg'.\n
00468     ///
00469     ///On Entry:
00470     ///@param[in] startReg - register to start writing at
00471     ///@param[in] stopReg - register to stop writing at
00472     ///@param[in] data - pointer to data to write to registers
00473     ///
00474     ///On Exit:
00475     ///@param[out] none
00476     ///
00477     ///@returns 0 on success, non 0 on failure
00478     virtual int32_t writeBlock(Registers startReg, Registers stopReg,
00479     const uint8_t *data) = 0;
00480 
00481 
00482     ///@brief Sets sensors power mode through CMD register.\n
00483     ///@details Observe command execution times given in datasheet.\n
00484     ///
00485     ///On Entry:
00486     ///@param[in] sensor - Sensor which power mode we are setting
00487     ///@param[in] pwrMode - Desired powermode of the sensor
00488     ///
00489     ///On Exit:
00490     ///@param[out]
00491     ///
00492     ///@returns 0 on success, non 0 on failure
00493     int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode);
00494 
00495 
00496     ///@brief Configure sensor.\n
00497     ///
00498     ///On Entry:
00499     ///@param[in] config - sSensor configuration data structure
00500     ///
00501     ///On Exit:
00502     ///@param[out] none
00503     ///
00504     ///@returns 0 on success, non 0 on failure
00505     int32_t setSensorConfig(const AccConfig &config);
00506     int32_t setSensorConfig(const GyroConfig &config);
00507 
00508 
00509     ///@brief Get sensor configuration.\n
00510     ///
00511     ///On Entry:
00512     ///@param[in] config - Sensor configuration data structure
00513     ///
00514     ///On Exit:
00515     ///@param[out] config - on success, holds sensor's current
00516     ///configuration
00517     ///
00518     ///@returns 0 on success, non 0 on failure
00519     int32_t getSensorConfig(AccConfig &config);
00520     int32_t getSensorConfig(GyroConfig &config);
00521 
00522 
00523     ///@brief Get sensor axis.\n
00524     ///
00525     ///On Entry:
00526     ///@param[in] axis - Sensor axis
00527     ///@param[in] data - AxisData structure
00528     ///@param[in] range - Sensor range
00529     ///
00530     ///On Exit:
00531     ///@param[out] data - Structure holds raw and scaled axis data
00532     ///
00533     ///@returns 0 on success, non 0 on failure
00534     int32_t getSensorAxis(SensorAxis axis, AxisData &data, AccRange range);
00535     int32_t getSensorAxis(SensorAxis axis, AxisData &data, GyroRange range);
00536 
00537 
00538     ///@brief Get sensor xyz axis.\n
00539     ///
00540     ///On Entry:
00541     ///@param[in] data - SensorData structure
00542     ///@param[in] range - Sensor range
00543     ///
00544     ///On Exit:
00545     ///@param[out] data - Structure holds raw and scaled data for all three axis
00546     ///
00547     ///@returns 0 on success, non 0 on failure
00548     int32_t getSensorXYZ(SensorData &data, AccRange range);
00549     int32_t getSensorXYZ(SensorData &data, GyroRange range);
00550 
00551 
00552     ///@brief Get sensor xyz axis and sensor time.\n
00553     ///
00554     ///On Entry:
00555     ///@param[in] data - SensorData structure
00556     ///@param[in] sensorTime - SensorTime structure for data
00557     ///@param[in] range - Sensor range
00558     ///
00559     ///On Exit:
00560     ///@param[out] data - Structure holds raw and scaled data for all three axis
00561     ///@param[out] sensorTime - Holds sensor time on success
00562     ///
00563     ///@returns 0 on success, non 0 on failure
00564     int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime,
00565                                       AccRange range);
00566     int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime,
00567                                       GyroRange range);
00568 
00569 
00570     ///@brief Get Gyroscope/Accelerometer data and sensor time.\n
00571     ///
00572     ///On Entry:
00573     ///@param[in] accData -  Sensor data structure for accelerometer
00574     ///@param[in] gyroData - Sensor data structure for gyroscope
00575     ///@param[in] sensorTime - SensorTime data structure
00576     ///@param[in] accRange - Accelerometer range
00577     ///@param[in] gyroRange - Gyroscope range
00578     ///
00579     ///On Exit:
00580     ///@param[out] accData -  Synchronized accelerometer data
00581     ///@param[out] gyroData - Synchronized gyroscope data
00582     ///@param[out] sensorTime - Synchronized sensor time
00583     ///
00584     ///@returns 0 on success, non 0 on failure
00585     int32_t getGyroAccXYZandSensorTime(SensorData &accData,
00586                                        SensorData &gyroData,
00587                                        SensorTime &sensorTime,
00588                                        AccRange accRange, GyroRange gyroRange);
00589 
00590 
00591     ///@brief Get sensor time.\n
00592     ///
00593     ///On Entry:
00594     ///@param[in] sensorTime - SensorTime structure for data
00595     ///
00596     ///On Exit:
00597     ///@param[out] sensorTime - Holds sensor time on success
00598     ///
00599     ///@returns returns 0 on success, non 0 on failure
00600     int32_t getSensorTime(SensorTime &sensorTime);
00601 
00602 
00603     ///@brief Get die temperature.\n
00604     ///
00605     ///On Entry:
00606     ///@param[in] temp - pointer to float for temperature
00607     ///
00608     ///On Exit:
00609     ///@param[out] temp - on success, holds the die temperature
00610     ///
00611     ///@returns 0 on success, non 0 on failure
00612     int32_t getTemperature(float *temp);
00613 
00614     // Initialize BMI160 with default parameters:
00615     // set GYRO: Suspended, Acc Normal Mode, ODR:25 Hz
00616     int32_t BMI160_DefaultInitalize();
00617 
00618     //
00619     //
00620     int32_t enable_data_ready_interrupt();
00621 
00622     //
00623     // Set sample rate
00624     // This function can be alled after BMI160_DefaultInitalize
00625     int32_t setSampleRate(int sample_rate);
00626 
00627     /// @brief Soft reset
00628     ///
00629     int32_t reset();
00630 
00631 private:
00632     bool m_use_irq;
00633     bool bmi160_irq_asserted;
00634     InterruptIn *m_bmi160_irq;
00635     void irq_handler();
00636 
00637 protected:
00638     BMI160(InterruptIn *int_pin): m_bmi160_irq(int_pin), m_use_irq(true) {
00639         bmi160_irq_asserted = false;
00640     }
00641 
00642     BMI160(): m_use_irq(false) { }
00643 };
00644 
00645 
00646 /**
00647 @brief BMI160_I2C - supports BMI160 object with I2C interface
00648 */
00649 class BMI160_I2C: public BMI160
00650 {
00651 public:
00652 
00653     ///BMI160 default I2C address.
00654     static const uint8_t I2C_ADRS_SDO_LO = 0x68;
00655     ///BMI160 optional I2C address.
00656     static const uint8_t I2C_ADRS_SDO_HI = 0x69;
00657 
00658 
00659     ///@brief BMI160_I2C Constructor.\n
00660     ///
00661     ///On Entry:
00662     ///@param[in] i2cBus - reference to I2C bus for this device
00663     ///@param[in] i2cAdrs - 7-bit I2C address
00664     ///
00665     ///On Exit:
00666     ///@param[out] none
00667     ///
00668     ///@returns none
00669     BMI160_I2C(I2C *i2cBus, uint8_t i2cAdrs);
00670 
00671     ///@brief BMI160_I2C Constructor.\n
00672     ///
00673     ///On Entry:
00674     ///@param[in] i2cBus - reference to I2C bus for this device
00675     ///@param[in] i2cAdrs - 7-bit I2C address
00676     ///@param[in] int_pin - Interrupt pin
00677     ///
00678     ///On Exit:
00679     ///@param[out] none
00680     ///
00681     ///@returns none
00682     BMI160_I2C(I2C *i2cBus, uint8_t i2cAdrs, InterruptIn *int_pin);
00683 
00684     ///@brief Reads a single register.\n
00685     ///
00686     ///On Entry:
00687     ///@param[in] data - pointer to memory for storing read data
00688     ///
00689     ///On Exit:
00690     ///@param[out] data - holds contents of read register on success
00691     ///
00692     ///@returns 0 on success, non 0 on failure
00693     virtual int32_t readRegister(Registers reg, uint8_t *data);
00694 
00695 
00696     ///@brief Writes a single register.\n
00697     ///
00698     ///On Entry:
00699     ///@param[in] data - data to write to register
00700     ///
00701     ///On Exit:
00702     ///@param[out] none
00703     ///
00704     ///@returns 0 on success, non 0 on failure
00705     virtual int32_t writeRegister(Registers reg, const uint8_t data);
00706 
00707 
00708     ///@brief Reads a block of registers.\n
00709     ///@detail User must ensure that all registers between 'startReg' and
00710     ///'stopReg' exist and are readable.  Function reads up to, including,
00711     ///'stopReg'.\n
00712     ///
00713     ///On Entry:
00714     ///@param[in] startReg - register to start reading from
00715     ///@param[in] stopReg - register to stop reading from
00716     ///@param[in] data - pointer to memory for storing read data
00717     ///
00718     ///On Exit:
00719     ///@param[out] data - holds contents of read registers on success
00720     ///
00721     ///@returns 0 on success, non 0 on failure
00722     virtual int32_t readBlock(Registers startReg, Registers stopReg,
00723     uint8_t *data);
00724 
00725 
00726     ///@brief Writes a block of registers.\n
00727     ///@detail User must ensure that all registers between 'startReg' and
00728     ///'stopReg' exist and are writeable.  Function writes up to, including,
00729     ///'stopReg'.\n
00730     ///
00731     ///On Entry:
00732     ///@param[in] startReg - register to start writing at
00733     ///@param[in] stopReg - register to stop writing at
00734     ///@param[in] data - pointer to data to write to registers
00735     ///
00736     ///On Exit:
00737     ///@param[out] none
00738     ///
00739     ///@returns 0 on success, non 0 on failure
00740     virtual int32_t writeBlock(Registers startReg, Registers stopReg,
00741     const uint8_t *data);
00742 
00743 private:
00744     I2C *m_i2cBus;
00745     uint8_t m_Wadrs, m_Radrs;
00746 };
00747 
00748 
00749 /**
00750 @brief BMI160_SPI - supports BMI160 object with SPI interface
00751 */
00752 class BMI160_SPI: public BMI160
00753 {
00754 public:
00755 
00756     ///@brief BMI160_SPI Constructor.\n
00757     ///
00758     ///On Entry:
00759     ///@param[in] spiBus - reference to SPI bus for this device
00760     ///@param[in] cs - reference to DigitalOut used for chip select
00761     ///
00762     ///On Exit:
00763     ///@param[out] none
00764     ///
00765     ///@returns none
00766     BMI160_SPI(SPI *spiBus, DigitalOut &cs);
00767 
00768 
00769     ///@brief Reads a single register.\n
00770     ///
00771     ///On Entry:
00772     ///@param[in] data - pointer to memory for storing read data
00773     ///
00774     ///On Exit:
00775     ///@param[out] data - holds contents of read register on success
00776     ///
00777     ///@returns 0 on success, non 0 on failure
00778     virtual int32_t readRegister(Registers reg, uint8_t *data);
00779 
00780 
00781     ///@brief Writes a single register.\n
00782     ///
00783     ///On Entry:
00784     ///@param[in] data - data to write to register
00785     ///
00786     ///On Exit:
00787     ///@param[out] none
00788     ///
00789     ///@returns 0 on success, non 0 on failure
00790     virtual int32_t writeRegister(Registers reg, const uint8_t data);
00791 
00792 
00793     ///@brief Reads a block of registers.\n
00794     ///@detail User must ensure that all registers between 'startReg' and
00795     ///'stopReg' exist and are readable.  Function reads up to, including,
00796     ///'stopReg'.\n
00797     ///
00798     ///On Entry:
00799     ///@param[in] startReg - register to start reading from
00800     ///@param[in] stopReg - register to stop reading from
00801     ///@param[in] data - pointer to memory for storing read data
00802     ///
00803     ///On Exit:
00804     ///@param[out] data - holds contents of read registers on success
00805     ///
00806     ///@returns 0 on success, non 0 on failure
00807     virtual int32_t readBlock(Registers startReg, Registers stopReg,
00808     uint8_t *data);
00809 
00810 
00811     ///@brief Writes a block of registers.\n
00812     ///@detail User must ensure that all registers between 'startReg' and
00813     ///'stopReg' exist and are writeable.  Function writes up to, including,
00814     ///'stopReg'.\n
00815     ///
00816     ///On Entry:
00817     ///@param[in] startReg - register to start writing at
00818     ///@param[in] stopReg - register to stop writing at
00819     ///@param[in] data - pointer to data to write to registers
00820     ///
00821     ///On Exit:
00822     ///@param[out] none
00823     ///
00824     ///@returns 0 on success, non 0 on failure
00825     virtual int32_t writeBlock(Registers startReg, Registers stopReg,
00826     const uint8_t *data);
00827 
00828 private:
00829 
00830     SPI *m_spiBus;
00831     DigitalOut m_cs;
00832 };
00833 
00834 #endif /* BMI160_H */
00835 
00836 
00837 ///@brief fx documentation template.\n
00838 ///
00839 ///On Entry:
00840 ///@param[in] none
00841 ///
00842 ///On Exit:
00843 ///@param[out] none
00844 ///
00845 ///@returns none