Library for Bosch Sensortec BMI160 IMU

Dependents:   Rocket MAX32630FTHR_JOYSTICK MAX32630FTHR_IMU_Hello_World Pike_the_Flipper_Main_Branch ... more

Fork of BMI160 by Justin Jordan

Committer:
j3
Date:
Tue Dec 20 01:27:13 2016 +0000
Revision:
10:9e219f2f1fb3
Parent:
9:ca6b5fecdd63
Child:
11:24602ff07e9f
Added get sensor time fx

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:bb5b832891fb 1 /**********************************************************************
j3 0:bb5b832891fb 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 0:bb5b832891fb 3 *
j3 0:bb5b832891fb 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 0:bb5b832891fb 5 * copy of this software and associated documentation files (the "Software"),
j3 0:bb5b832891fb 6 * to deal in the Software without restriction, including without limitation
j3 0:bb5b832891fb 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 0:bb5b832891fb 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 0:bb5b832891fb 9 * Software is furnished to do so, subject to the following conditions:
j3 0:bb5b832891fb 10 *
j3 0:bb5b832891fb 11 * The above copyright notice and this permission notice shall be included
j3 0:bb5b832891fb 12 * in all copies or substantial portions of the Software.
j3 0:bb5b832891fb 13 *
j3 0:bb5b832891fb 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 0:bb5b832891fb 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 0:bb5b832891fb 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 0:bb5b832891fb 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 0:bb5b832891fb 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 0:bb5b832891fb 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 0:bb5b832891fb 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 0:bb5b832891fb 21 *
j3 0:bb5b832891fb 22 * Except as contained in this notice, the name of Maxim Integrated
j3 0:bb5b832891fb 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 0:bb5b832891fb 24 * Products, Inc. Branding Policy.
j3 0:bb5b832891fb 25 *
j3 0:bb5b832891fb 26 * The mere transfer of this software does not imply any licenses
j3 0:bb5b832891fb 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 0:bb5b832891fb 28 * trademarks, maskwork rights, or any other form of intellectual
j3 0:bb5b832891fb 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 0:bb5b832891fb 30 * ownership rights.
j3 0:bb5b832891fb 31 **********************************************************************/
j3 0:bb5b832891fb 32
j3 0:bb5b832891fb 33
j3 0:bb5b832891fb 34 #ifndef BMI160_H
j3 0:bb5b832891fb 35 #define BMI160_H
j3 0:bb5b832891fb 36
j3 0:bb5b832891fb 37 #include "mbed.h"
j3 0:bb5b832891fb 38
j3 0:bb5b832891fb 39 /**
j3 0:bb5b832891fb 40 @brief The BMI160 is a small, low power, low noise 16-bit inertial measurement
j3 0:bb5b832891fb 41 unit designed for use in mobile applications like augmented reality or indoor
j3 0:bb5b832891fb 42 navigation which require highly accurate, real-time sensor data.
j3 0:bb5b832891fb 43
j3 0:bb5b832891fb 44 In full operation mode, with both the accelerometer and gyroscope enabled, the
j3 0:bb5b832891fb 45 current consumption is typically 950 μA, enabling always-on applications in
j3 0:bb5b832891fb 46 battery driven devices. It is available in a compact 14-pin 2.5 x 3.0 x 0.8 mm³
j3 0:bb5b832891fb 47 LGA package."
j3 2:598e601e5846 48
j3 2:598e601e5846 49 This class is an abstract base class and can not be instaniated, use BMI160_I2C
j3 2:598e601e5846 50 or BMI160_SPI.
j3 0:bb5b832891fb 51 */
j3 0:bb5b832891fb 52 class BMI160
j3 0:bb5b832891fb 53 {
j3 0:bb5b832891fb 54 public:
j3 0:bb5b832891fb 55
j3 2:598e601e5846 56 ///Return value on success.
j3 3:e1770675eca4 57 static const uint8_t RTN_NO_ERROR = 0;
j3 0:bb5b832891fb 58
j3 5:35e032c8d8aa 59 ///BMI160 Sensors
j3 5:35e032c8d8aa 60 enum Sensors
j3 5:35e032c8d8aa 61 {
j3 5:35e032c8d8aa 62 MAG = 0, ///<Optional external sensor
j3 5:35e032c8d8aa 63 GYRO, ///<Angular rate sensor
j3 5:35e032c8d8aa 64 ACC ///<g sensor
j3 5:35e032c8d8aa 65 };
j3 5:35e032c8d8aa 66
j3 8:a89b529b1d96 67 ///Sensor Axis
j3 8:a89b529b1d96 68 enum SensorAxis
j3 8:a89b529b1d96 69 {
j3 8:a89b529b1d96 70 X_AXIS = 0,
j3 8:a89b529b1d96 71 Y_AXIS,
j3 8:a89b529b1d96 72 Z_AXIS
j3 8:a89b529b1d96 73 };
j3 8:a89b529b1d96 74
j3 8:a89b529b1d96 75 ///Structure for axis data
j3 8:a89b529b1d96 76 struct AxisData
j3 8:a89b529b1d96 77 {
j3 8:a89b529b1d96 78 int16_t raw; ///<Axis raw data
j3 8:a89b529b1d96 79 float scaled; ///<Axis scaled data
j3 8:a89b529b1d96 80 };
j3 8:a89b529b1d96 81
j3 8:a89b529b1d96 82 ///Structure for holding sensor data
j3 8:a89b529b1d96 83 struct SensorData
j3 8:a89b529b1d96 84 {
j3 8:a89b529b1d96 85 AxisData xAxis; ///<Sensor X axis data
j3 8:a89b529b1d96 86 AxisData yAxis; ///<Sensor Y axis data
j3 8:a89b529b1d96 87 AxisData zAxis; ///<Sensor Z axis data
j3 8:a89b529b1d96 88 };
j3 8:a89b529b1d96 89
j3 1:a4c911640569 90 ///BMI160 registers
j3 0:bb5b832891fb 91 enum Registers
j3 0:bb5b832891fb 92 {
j3 3:e1770675eca4 93 CHIP_ID = 0x00, ///<Chip Identification.
j3 3:e1770675eca4 94 ERR_REG = 0x02, ///<Reports sensor error flags. Flags reset when read.
j3 3:e1770675eca4 95 PMU_STATUS, ///<Reports current power mode for sensors.
j3 3:e1770675eca4 96 DATA_0, ///<MAG_X axis bits7:0
j3 3:e1770675eca4 97 DATA_1, ///<MAG_X axis bits15:8
j3 3:e1770675eca4 98 DATA_2, ///<MAG_Y axis bits7:0
j3 3:e1770675eca4 99 DATA_3, ///<MAG_Y axis bits15:8
j3 3:e1770675eca4 100 DATA_4, ///<MAG_Z axis bits7:0
j3 3:e1770675eca4 101 DATA_5, ///<MAG_Z axis bits15:8
j3 3:e1770675eca4 102 DATA_6, ///<RHALL bits7:0
j3 3:e1770675eca4 103 DATA_7, ///<RHALL bits15:8
j3 3:e1770675eca4 104 DATA_8, ///<GYR_X axis bits7:0
j3 3:e1770675eca4 105 DATA_9, ///<GYR_X axis bits15:8
j3 3:e1770675eca4 106 DATA_10, ///<GYR_Y axis bits7:0
j3 3:e1770675eca4 107 DATA_11, ///<GYR_Y axis bits15:8
j3 3:e1770675eca4 108 DATA_12, ///<GYR_Z axis bits7:0
j3 3:e1770675eca4 109 DATA_13, ///<GYR_Z axis bits15:8
j3 3:e1770675eca4 110 DATA_14, ///<ACC_X axis bits7:0
j3 3:e1770675eca4 111 DATA_15, ///<ACC_X axis bits15:8
j3 3:e1770675eca4 112 DATA_16, ///<ACC_Y axis bits7:0
j3 3:e1770675eca4 113 DATA_17, ///<ACC_Y axis bits15:8
j3 3:e1770675eca4 114 DATA_18, ///<ACC_Z axis bits7:0
j3 3:e1770675eca4 115 DATA_19, ///<ACC_Z axis bits15:8
j3 3:e1770675eca4 116 SENSORTIME_0, ///<24bit counter synchronized with data, bits7:0
j3 3:e1770675eca4 117 SENSORTIME_1, ///<24bit counter synchronized with data, bits15:8
j3 3:e1770675eca4 118 SENSORTIME_2, ///<24bit counter synchronized with data, bits23:16
j3 3:e1770675eca4 119 STATUS, ///<Reports sensors status flags
j3 3:e1770675eca4 120 INT_STATUS_0, ///<Contains interrupt status flags
j3 3:e1770675eca4 121 INT_STATUS_1, ///<Contains interrupt status flags
j3 3:e1770675eca4 122 INT_STATUS_2, ///<Contains interrupt status flags
j3 3:e1770675eca4 123 INT_STATUS_3, ///<Contains interrupt status flags
j3 3:e1770675eca4 124 TEMPERATURE_0, ///<Contains temperature of sensor, bits7:0
j3 3:e1770675eca4 125 TEMPERATURE_1, ///<Contains temperature of sensor, bits15:8
j3 3:e1770675eca4 126 FIFO_LENGTH_0, ///<Current fill level of FIFO, bits7:0
j3 3:e1770675eca4 127 FIFO_LENGTH_1, ///<Current fill level of FIFO, bits10:8
j3 3:e1770675eca4 128 FIFO_DATA, ///<FIFO data read out register, burst read
j3 3:e1770675eca4 129 ACC_CONF = 0x40, ///<Set ODR, bandwidth, and read mode of accelerometer
j3 3:e1770675eca4 130 ACC_RANGE, ///<Sets accelerometer g-range
j3 3:e1770675eca4 131 GYR_CONF, ///<Set ODR, bandwidth, and read mode of gyroscope
j3 3:e1770675eca4 132 GYR_RANGE, ///<Sets gyroscope angular rate measurement range
j3 3:e1770675eca4 133 MAG_CONF, ///<Sets ODR of magnetometer interface
j3 3:e1770675eca4 134 FIFO_DOWNS, ///<Sets down sampling ratios of accel and gyro data
j3 3:e1770675eca4 135 ///<for FIFO
j3 3:e1770675eca4 136 FIFO_CONFIG_0, ///<Sets FIFO Watermark
j3 3:e1770675eca4 137 FIFO_CONFIG_1, ///<Sets which sensor data is available in FIFO,
j3 3:e1770675eca4 138 ///<Header/Headerless mode, Ext Int tagging, Sensortime
j3 3:e1770675eca4 139 MAG_IF_0 = 0x4B, ///<Magnetometer 7-bit I2C address, bits7:1
j3 3:e1770675eca4 140 MAG_IF_1, ///<Magnetometer interface configuration
j3 3:e1770675eca4 141 MAG_IF_2, ///<Magnetometer address to read
j3 3:e1770675eca4 142 MAG_IF_3, ///<Magnetometer address to write
j3 3:e1770675eca4 143 MAG_IF_4, ///<Magnetometer data to write
j3 3:e1770675eca4 144 INT_EN_0, ///<Interrupt enable bits
j3 3:e1770675eca4 145 INT_EN_1, ///<Interrupt enable bits
j3 3:e1770675eca4 146 INT_EN_2, ///<Interrupt enable bits
j3 3:e1770675eca4 147 INT_OUT_CTRL, ///<Contains the behavioral configuration of INT pins
j3 3:e1770675eca4 148 INT_LATCH, ///<Contains the interrupt rest bit and the interrupt
j3 3:e1770675eca4 149 ///<mode selection
j3 3:e1770675eca4 150 INT_MAP_0, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 151 ///<INT1 and INT2 pins
j3 3:e1770675eca4 152 INT_MAP_1, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 153 ///<INT1 and INT2 pins
j3 3:e1770675eca4 154 INT_MAP_2, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 155 ///<INT1 and INT2 pins
j3 3:e1770675eca4 156 INT_DATA_0, ///<Contains the data source definition for the two
j3 3:e1770675eca4 157 ///<interrupt groups
j3 3:e1770675eca4 158 INT_DATA_1, ///<Contains the data source definition for the two
j3 3:e1770675eca4 159 ///<interrupt groups
j3 3:e1770675eca4 160 INT_LOWHIGH_0, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 161 INT_LOWHIGH_1, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 162 INT_LOWHIGH_2, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 163 INT_LOWHIGH_3, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 164 INT_LOWHIGH_4, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 165 INT_MOTION_0, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 166 ///<no motion interrupts
j3 3:e1770675eca4 167 INT_MOTION_1, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 168 ///<no motion interrupts
j3 3:e1770675eca4 169 INT_MOTION_2, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 170 ///<no motion interrupts
j3 3:e1770675eca4 171 INT_MOTION_3, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 172 ///<no motion interrupts
j3 3:e1770675eca4 173 INT_TAP_0, ///<Contains the configuration for the tap interrupts
j3 3:e1770675eca4 174 INT_TAP_1, ///<Contains the configuration for the tap interrupts
j3 3:e1770675eca4 175 INT_ORIENT_0, ///<Contains the configuration for the oeientation
j3 3:e1770675eca4 176 ///<interrupt
j3 3:e1770675eca4 177 INT_ORIENT_1, ///<Contains the configuration for the oeientation
j3 3:e1770675eca4 178 ///<interrupt
j3 3:e1770675eca4 179 INT_FLAT_0, ///<Contains the configuration for the flat interrupt
j3 3:e1770675eca4 180 INT_FLAT_1, ///<Contains the configuration for the flat interrupt
j3 3:e1770675eca4 181 FOC_CONF, ///<Contains configuration for the fast offset
j3 3:e1770675eca4 182 ///<compensation for the accelerometer and gyroscope
j3 3:e1770675eca4 183 CONF, ///<Configuration of sensor, nvm_prog_en bit
j3 3:e1770675eca4 184 IF_CONF, ///<Contains settings for the digital interface
j3 3:e1770675eca4 185 PMU_TRIGGER, ///<Sets trigger conditions to change gyro power modes
j3 3:e1770675eca4 186 SELF_TEST, ///<Self test configuration
j3 3:e1770675eca4 187 NV_CONF = 0x70, ///<Contains settings for the digital interface
j3 3:e1770675eca4 188 OFFSET_0, ///<Contains offset comp values for acc_off_x7:0
j3 3:e1770675eca4 189 OFFSET_1, ///<Contains offset comp values for acc_off_y7:0
j3 3:e1770675eca4 190 OFFSET_2, ///<Contains offset comp values for acc_off_z7:0
j3 3:e1770675eca4 191 OFFSET_3, ///<Contains offset comp values for gyr_off_x7:0
j3 3:e1770675eca4 192 OFFSET_4, ///<Contains offset comp values for gyr_off_y7:0
j3 3:e1770675eca4 193 OFFSET_5, ///<Contains offset comp values for gyr_off_z7:0
j3 3:e1770675eca4 194 OFFSET_6, ///<gyr/acc offset enable bit and gyr_off_(zyx) bits9:8
j3 3:e1770675eca4 195 STEP_CNT_0, ///<Step counter bits 15:8
j3 3:e1770675eca4 196 STEP_CNT_1, ///<Step counter bits 7:0
j3 3:e1770675eca4 197 STEP_CONF_0, ///<Contains configuration of the step detector
j3 3:e1770675eca4 198 STEP_CONF_1, ///<Contains configuration of the step detector
j3 3:e1770675eca4 199 CMD = 0x7E ///<Command register triggers operations like
j3 3:e1770675eca4 200 ///<softreset, NVM programming, etc.
j3 3:e1770675eca4 201 };
j3 3:e1770675eca4 202
j3 8:a89b529b1d96 203
j3 3:e1770675eca4 204 ///ERR_REG Bit Mask bit0
j3 3:e1770675eca4 205 static const uint8_t FATAL_ERR = 0x01;
j3 3:e1770675eca4 206 ///ERR_REG Bit Mask bits4:1
j3 3:e1770675eca4 207 static const uint8_t ERR_CODE = 0x1E;
j3 3:e1770675eca4 208 ///ERR_REG Bit Mask bit5
j3 3:e1770675eca4 209 static const uint8_t I2C_FAIL_ERR = 0x20;
j3 3:e1770675eca4 210 ///ERR_REG Bit Mask bit6
j3 3:e1770675eca4 211 static const uint8_t DROP_CMD_ERR = 0x40;
j3 3:e1770675eca4 212 ///ERR_REG Bit Mask bit7
j3 3:e1770675eca4 213 static const uint8_t MAG_DRDY_ERR = 0x80;
j3 3:e1770675eca4 214
j3 3:e1770675eca4 215 ///ERR_REG bits4:1 codes
j3 3:e1770675eca4 216 enum ErrorCodes
j3 3:e1770675eca4 217 {
j3 3:e1770675eca4 218 NO_ERROR = 0, ///<No Error
j3 3:e1770675eca4 219 ERROR_1, ///<Listed as error
j3 3:e1770675eca4 220 ERROR_2, ///<Listed as error
j3 3:e1770675eca4 221 LPM_INT_PFD, ///<Low-power mode and interrupt uses pre-filtered
j3 3:e1770675eca4 222 ///<data
j3 4:ebac8c8f6347 223 ODR_MISMATCH = 0x06, ///<ODRs of enabled sensors in headerless mode do
j3 4:ebac8c8f6347 224 ///<not match
j3 3:e1770675eca4 225 PFD_USED_LPM ///<Pre-filtered data are used in low power mode
j3 0:bb5b832891fb 226 };
j3 0:bb5b832891fb 227
j3 8:a89b529b1d96 228
j3 8:a89b529b1d96 229 ///ACC_CONF Bit Mask bits3:0
j3 8:a89b529b1d96 230 static const uint8_t ACC_ODR = 0x0F;
j3 8:a89b529b1d96 231 ///ACC_CONF Bit Mask bits6:4
j3 8:a89b529b1d96 232 static const uint8_t ACC_BWP = 0x70;
j3 8:a89b529b1d96 233 ///ACC_CONF Bit Mask bit7
j3 8:a89b529b1d96 234 static const uint8_t ACC_US = 0x80;
j3 8:a89b529b1d96 235
j3 8:a89b529b1d96 236 ///ACC_CONF bits3:0 codes
j3 8:a89b529b1d96 237 enum AccOutPutDataRate
j3 8:a89b529b1d96 238 {
j3 8:a89b529b1d96 239 ACC_ODR_1 = 1, ///< 25/32Hz
j3 8:a89b529b1d96 240 ACC_ODR_2, ///< 25/16Hz
j3 8:a89b529b1d96 241 ACC_ODR_3, ///< 25/8Hz
j3 8:a89b529b1d96 242 ACC_ODR_4, ///< 25/4Hz
j3 8:a89b529b1d96 243 ACC_ODR_5, ///< 25/2Hz
j3 8:a89b529b1d96 244 ACC_ODR_6, ///< 25Hz
j3 8:a89b529b1d96 245 ACC_ODR_7, ///< 50Hz
j3 8:a89b529b1d96 246 ACC_ODR_8, ///< 100Hz
j3 8:a89b529b1d96 247 ACC_ODR_9, ///< 200Hz
j3 8:a89b529b1d96 248 ACC_ODR_10, ///< 400Hz
j3 8:a89b529b1d96 249 ACC_ODR_11, ///< 800Hz
j3 8:a89b529b1d96 250 ACC_ODR_12 ///< 1600Hz
j3 8:a89b529b1d96 251 };
j3 8:a89b529b1d96 252
j3 8:a89b529b1d96 253 ///ACC_CONF bits6:4 codes
j3 8:a89b529b1d96 254 enum AccBandWidthParam
j3 8:a89b529b1d96 255 {
j3 8:a89b529b1d96 256 ACC_BWP_0 = 0, ///< Average 1 cycle
j3 8:a89b529b1d96 257 ACC_BWP_1, ///< Average 2 cycles
j3 8:a89b529b1d96 258 ACC_BWP_2, ///< Average 4 cycles, use this setting when acc_us = 0
j3 8:a89b529b1d96 259 ACC_BWP_3, ///< Average 8 cycles
j3 8:a89b529b1d96 260 ACC_BWP_4, ///< Average 16 cycles
j3 8:a89b529b1d96 261 ACC_BWP_5, ///< Average 32 cycles
j3 8:a89b529b1d96 262 ACC_BWP_6, ///< Average 64 cycles
j3 8:a89b529b1d96 263 ACC_BWP_7 ///< Average 128 cycles
j3 8:a89b529b1d96 264 };
j3 8:a89b529b1d96 265
j3 8:a89b529b1d96 266 ///ACC_CONF bit7
j3 8:a89b529b1d96 267 enum AccUnderSampling
j3 8:a89b529b1d96 268 {
j3 8:a89b529b1d96 269 ACC_US_OFF = 0,
j3 8:a89b529b1d96 270 ACC_US_ON
j3 8:a89b529b1d96 271 };
j3 8:a89b529b1d96 272
j3 8:a89b529b1d96 273 ///Accelerometer range values
j3 8:a89b529b1d96 274 enum AccRange
j3 8:a89b529b1d96 275 {
j3 8:a89b529b1d96 276 SENS_2G = 0, ///<Accelerometer range +-2G
j3 8:a89b529b1d96 277 SENS_4G, ///<Accelerometer range +-4G
j3 8:a89b529b1d96 278 SENS_8G, ///<Accelerometer range +-8G
j3 8:a89b529b1d96 279 SENS_16G, ///<Accelerometer range +-16G
j3 8:a89b529b1d96 280 };
j3 8:a89b529b1d96 281
j3 9:ca6b5fecdd63 282 ///Structure for holding accelerometer configuration
j3 9:ca6b5fecdd63 283 struct AccConfig
j3 9:ca6b5fecdd63 284 {
j3 9:ca6b5fecdd63 285 AccRange range;
j3 9:ca6b5fecdd63 286 AccUnderSampling us;
j3 9:ca6b5fecdd63 287 AccBandWidthParam bwp;
j3 9:ca6b5fecdd63 288 AccOutPutDataRate odr;
j3 9:ca6b5fecdd63 289 };
j3 9:ca6b5fecdd63 290
j3 9:ca6b5fecdd63 291 ///Accelerometer default configuration
j3 9:ca6b5fecdd63 292 static const AccConfig DEFAULT_ACC_CONFIG;
j3 9:ca6b5fecdd63 293
j3 5:35e032c8d8aa 294 ///BMI160 Power Modes
j3 4:ebac8c8f6347 295 enum PowerModes
j3 4:ebac8c8f6347 296 {
j3 4:ebac8c8f6347 297 SUSPEND = 0, ///<Acc and Gyro, No sampling, No FIFO data readout
j3 4:ebac8c8f6347 298 NORMAL, ///<Acc and Gyro, Full chip operation
j3 4:ebac8c8f6347 299 LOW_POWER, ///<Acc duty-cycling between suspend and normal
j3 4:ebac8c8f6347 300 FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms
j3 4:ebac8c8f6347 301 };
j3 4:ebac8c8f6347 302
j3 5:35e032c8d8aa 303 ///BMI160 Commands for CMD register
j3 5:35e032c8d8aa 304 enum Commands
j3 5:35e032c8d8aa 305 {
j3 5:35e032c8d8aa 306 START_FOC = 0x03, ///<Starts Fast Offset Calibrartion
j3 7:9848196cb65e 307 ACC_SET_PMU_MODE = 0x10, ///<Sets acc power mode
j3 8:a89b529b1d96 308 GYR_SET_PMU_MODE = 0x14, ///<Sets gyro power mode
j3 8:a89b529b1d96 309 MAG_SET_PMU_MODE = 0x18, ///<Sets mag power mode
j3 5:35e032c8d8aa 310 PROG_NVM = 0xA0, ///<Writes NVM backed registers into NVM
j3 5:35e032c8d8aa 311 FIFO_FLUSH = 0xB0, ///<Clears FIFO
j3 5:35e032c8d8aa 312 INT_RESET, ///<Clears interrupt engine, INT_STATUS, and
j3 5:35e032c8d8aa 313 ///<the interrupt pin
j3 5:35e032c8d8aa 314 STEP_CNT_CLR, ///<Triggers reset of the step counter
j3 5:35e032c8d8aa 315 SOFT_RESET = 0xB6 ///<Triggers a reset including a reboot.
j3 5:35e032c8d8aa 316 };
j3 5:35e032c8d8aa 317
j3 0:bb5b832891fb 318
j3 0:bb5b832891fb 319 ///@brief BMI160 Destructor.\n
j3 0:bb5b832891fb 320 ///
j3 0:bb5b832891fb 321 ///On Entry:
j3 0:bb5b832891fb 322 ///@param[in] none
j3 0:bb5b832891fb 323 ///
j3 0:bb5b832891fb 324 ///On Exit:
j3 0:bb5b832891fb 325 ///@param[out] none
j3 0:bb5b832891fb 326 ///
j3 0:bb5b832891fb 327 ///@returns none
j3 2:598e601e5846 328 virtual ~BMI160(){ }
j3 0:bb5b832891fb 329
j3 0:bb5b832891fb 330
j3 0:bb5b832891fb 331 ///@brief Reads a single register.\n
j3 0:bb5b832891fb 332 ///
j3 0:bb5b832891fb 333 ///On Entry:
j3 0:bb5b832891fb 334 ///@param[in] data - pointer to memory for storing read data
j3 0:bb5b832891fb 335 ///
j3 0:bb5b832891fb 336 ///On Exit:
j3 0:bb5b832891fb 337 ///@param[out] data - holds contents of read register on success
j3 0:bb5b832891fb 338 ///
j3 0:bb5b832891fb 339 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 340 virtual int32_t readRegister(Registers reg, uint8_t *data) = 0;
j3 0:bb5b832891fb 341
j3 0:bb5b832891fb 342
j3 0:bb5b832891fb 343 ///@brief Writes a single register.\n
j3 0:bb5b832891fb 344 ///
j3 0:bb5b832891fb 345 ///On Entry:
j3 0:bb5b832891fb 346 ///@param[in] data - data to write to register
j3 0:bb5b832891fb 347 ///
j3 0:bb5b832891fb 348 ///On Exit:
j3 0:bb5b832891fb 349 ///@param[out] none
j3 0:bb5b832891fb 350 ///
j3 0:bb5b832891fb 351 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 352 virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0;
j3 0:bb5b832891fb 353
j3 0:bb5b832891fb 354
j3 0:bb5b832891fb 355 ///@brief Reads a block of registers.\n
j3 0:bb5b832891fb 356 ///@detail User must ensure that all registers between 'startReg' and
j3 0:bb5b832891fb 357 ///'stopReg' exist and are readable. Function reads up to, including,
j3 0:bb5b832891fb 358 ///'stopReg'.\n
j3 0:bb5b832891fb 359 ///
j3 0:bb5b832891fb 360 ///On Entry:
j3 0:bb5b832891fb 361 ///@param[in] startReg - register to start reading from
j3 0:bb5b832891fb 362 ///@param[in] stopReg - register to stop reading from
j3 0:bb5b832891fb 363 ///@param[in] data - pointer to memory for storing read data
j3 0:bb5b832891fb 364 ///
j3 0:bb5b832891fb 365 ///On Exit:
j3 0:bb5b832891fb 366 ///@param[out] data - holds contents of read registers on success
j3 0:bb5b832891fb 367 ///
j3 0:bb5b832891fb 368 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 369 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 370 uint8_t *data) = 0;
j3 0:bb5b832891fb 371
j3 0:bb5b832891fb 372
j3 0:bb5b832891fb 373 ///@brief Writes a block of registers.\n
j3 0:bb5b832891fb 374 ///@detail User must ensure that all registers between 'startReg' and
j3 0:bb5b832891fb 375 ///'stopReg' exist and are writeable. Function writes up to, including,
j3 0:bb5b832891fb 376 ///'stopReg'.\n
j3 0:bb5b832891fb 377 ///
j3 0:bb5b832891fb 378 ///On Entry:
j3 0:bb5b832891fb 379 ///@param[in] startReg - register to start writing at
j3 0:bb5b832891fb 380 ///@param[in] stopReg - register to stop writing at
j3 0:bb5b832891fb 381 ///@param[in] data - pointer to data to write to registers
j3 0:bb5b832891fb 382 ///
j3 0:bb5b832891fb 383 ///On Exit:
j3 0:bb5b832891fb 384 ///@param[out] none
j3 0:bb5b832891fb 385 ///
j3 0:bb5b832891fb 386 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 387 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 388 const uint8_t *data) = 0;
j3 3:e1770675eca4 389
j3 3:e1770675eca4 390
j3 5:35e032c8d8aa 391 ///@brief Sets sensors power mode through CMD register.\n
j3 5:35e032c8d8aa 392 ///@details Observe command execution times given in datasheet.\n
j3 5:35e032c8d8aa 393 ///
j3 5:35e032c8d8aa 394 ///On Entry:
j3 5:35e032c8d8aa 395 ///@param[in] sensor - Sensor which power mode we are setting
j3 5:35e032c8d8aa 396 ///@param[in] pwrMode - Desired powermode of the sensor
j3 5:35e032c8d8aa 397 ///
j3 5:35e032c8d8aa 398 ///On Exit:
j3 5:35e032c8d8aa 399 ///@param[out]
j3 5:35e032c8d8aa 400 ///
j3 5:35e032c8d8aa 401 ///@returns 0 on success, non 0 on failure
j3 5:35e032c8d8aa 402 int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode);
j3 5:35e032c8d8aa 403
j3 5:35e032c8d8aa 404
j3 3:e1770675eca4 405 ///@brief Get die temperature.\n
j3 3:e1770675eca4 406 ///
j3 3:e1770675eca4 407 ///On Entry:
j3 3:e1770675eca4 408 ///@param[in] temp - pointer to float for temperature
j3 3:e1770675eca4 409 ///
j3 3:e1770675eca4 410 ///On Exit:
j3 3:e1770675eca4 411 ///@param[out] temp - on success, holds the die temperature
j3 3:e1770675eca4 412 ///
j3 3:e1770675eca4 413 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 414 int32_t getTemperature(float *temp);
j3 3:e1770675eca4 415
j3 3:e1770675eca4 416
j3 8:a89b529b1d96 417 ///@brief Read data registers and sensortime.\n
j3 8:a89b529b1d96 418 ///
j3 8:a89b529b1d96 419 ///On Entry:
j3 8:a89b529b1d96 420 ///@param[in] data - buffer at least 23 bytes long
j3 8:a89b529b1d96 421 ///
j3 8:a89b529b1d96 422 ///On Exit:
j3 8:a89b529b1d96 423 ///@param[out] data - holds raw sensor data on success
j3 8:a89b529b1d96 424 ///
j3 8:a89b529b1d96 425 ///@returns 0 on success, non 0 on failure
j3 8:a89b529b1d96 426 int32_t getSensorDataAndTime(uint8_t *data);
j3 8:a89b529b1d96 427
j3 8:a89b529b1d96 428
j3 8:a89b529b1d96 429 ///@brief Get accelerometer axis as float.\n
j3 3:e1770675eca4 430 ///
j3 3:e1770675eca4 431 ///On Entry:
j3 8:a89b529b1d96 432 ///@param[in] axis - Sensor axis
j3 8:a89b529b1d96 433 ///@param[in] data - AxisData structure
j3 9:ca6b5fecdd63 434 ///@param[in] accConfig - Accelerometer configuration structure
j3 8:a89b529b1d96 435 ///
j3 8:a89b529b1d96 436 ///On Exit:
j3 8:a89b529b1d96 437 ///@param[out] data - Structure holds raw and scaled axis data
j3 8:a89b529b1d96 438 ///
j3 8:a89b529b1d96 439 ///@returns 0 on success, non 0 on failure
j3 9:ca6b5fecdd63 440 int32_t getAccAxis(SensorAxis axis, AxisData &data, AccConfig accConfig);
j3 8:a89b529b1d96 441
j3 8:a89b529b1d96 442
j3 8:a89b529b1d96 443 ///@brief Get accelerometer xyz axis as float.\n
j3 8:a89b529b1d96 444 ///
j3 8:a89b529b1d96 445 ///On Entry:
j3 8:a89b529b1d96 446 ///@param[in] data - SensorData structure
j3 9:ca6b5fecdd63 447 ///@param[in] accConfig - Accelerometer configuration structure
j3 3:e1770675eca4 448 ///
j3 3:e1770675eca4 449 ///On Exit:
j3 8:a89b529b1d96 450 ///@param[out] data - Structure holds raw and scaled data for all three axis
j3 3:e1770675eca4 451 ///
j3 8:a89b529b1d96 452 ///@returns 0 on success, non 0 on failure
j3 9:ca6b5fecdd63 453 int32_t getAccXYZ(SensorData &data, AccConfig accConfig);
j3 10:9e219f2f1fb3 454
j3 10:9e219f2f1fb3 455
j3 10:9e219f2f1fb3 456 ///@brief Get sensor time.\n
j3 10:9e219f2f1fb3 457 ///
j3 10:9e219f2f1fb3 458 ///On Entry:
j3 10:9e219f2f1fb3 459 ///@param[in] data - pointer to float for holding data
j3 10:9e219f2f1fb3 460 ///
j3 10:9e219f2f1fb3 461 ///On Exit:
j3 10:9e219f2f1fb3 462 ///@param[out] data - time in seconds, as float
j3 10:9e219f2f1fb3 463 ///
j3 10:9e219f2f1fb3 464 ///@returns returns 0 on success, non 0 on failure
j3 10:9e219f2f1fb3 465 int32_t getSensorTime(float *data);
j3 10:9e219f2f1fb3 466
j3 10:9e219f2f1fb3 467
j3 2:598e601e5846 468 };
j3 2:598e601e5846 469
j3 2:598e601e5846 470
j3 2:598e601e5846 471 /**
j3 2:598e601e5846 472 @brief BMI160_I2C - supports BMI160 object with I2C interface
j3 2:598e601e5846 473 */
j3 2:598e601e5846 474 class BMI160_I2C: public BMI160
j3 2:598e601e5846 475 {
j3 2:598e601e5846 476 public:
j3 2:598e601e5846 477
j3 2:598e601e5846 478 ///BMI160 default I2C address.
j3 2:598e601e5846 479 static const uint8_t I2C_ADRS_SDO_LO = 0x68;
j3 2:598e601e5846 480 ///BMI160 optional I2C address.
j3 2:598e601e5846 481 static const uint8_t I2C_ADRS_SDO_HI = 0x69;
j3 0:bb5b832891fb 482
j3 2:598e601e5846 483
j3 2:598e601e5846 484 ///@brief BMI160_I2C Constructor.\n
j3 0:bb5b832891fb 485 ///
j3 0:bb5b832891fb 486 ///On Entry:
j3 2:598e601e5846 487 ///@param[in] i2cBus - reference to I2C bus for this device
j3 2:598e601e5846 488 ///@param[in] i2cAdrs - 7-bit I2C address
j3 0:bb5b832891fb 489 ///
j3 0:bb5b832891fb 490 ///On Exit:
j3 0:bb5b832891fb 491 ///@param[out] none
j3 0:bb5b832891fb 492 ///
j3 0:bb5b832891fb 493 ///@returns none
j3 2:598e601e5846 494 BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs);
j3 2:598e601e5846 495
j3 2:598e601e5846 496
j3 2:598e601e5846 497 virtual int32_t readRegister(Registers reg, uint8_t *data);
j3 2:598e601e5846 498 virtual int32_t writeRegister(Registers reg, const uint8_t data);
j3 3:e1770675eca4 499 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 500 uint8_t *data);
j3 3:e1770675eca4 501 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 502 const uint8_t *data);
j3 2:598e601e5846 503
j3 0:bb5b832891fb 504 private:
j3 0:bb5b832891fb 505
j3 0:bb5b832891fb 506 I2C m_i2cBus;
j3 0:bb5b832891fb 507 uint8_t m_Wadrs, m_Radrs;
j3 0:bb5b832891fb 508 };
j3 0:bb5b832891fb 509
j3 2:598e601e5846 510
j3 2:598e601e5846 511 /**
j3 2:598e601e5846 512 @brief BMI160_SPI - supports BMI160 object with SPI interface
j3 2:598e601e5846 513 */
j3 2:598e601e5846 514 class BMI160_SPI: public BMI160
j3 2:598e601e5846 515 {
j3 2:598e601e5846 516 public:
j3 2:598e601e5846 517
j3 2:598e601e5846 518 ///@brief BMI160_SPI Constructor.\n
j3 2:598e601e5846 519 ///
j3 2:598e601e5846 520 ///On Entry:
j3 2:598e601e5846 521 ///@param[in] spiBus - reference to SPI bus for this device
j3 2:598e601e5846 522 ///@param[in] cs - reference to DigitalOut used for chip select
j3 2:598e601e5846 523 ///
j3 2:598e601e5846 524 ///On Exit:
j3 2:598e601e5846 525 ///@param[out] none
j3 2:598e601e5846 526 ///
j3 2:598e601e5846 527 ///@returns none
j3 2:598e601e5846 528 BMI160_SPI(SPI &spiBus, DigitalOut &cs);
j3 2:598e601e5846 529
j3 2:598e601e5846 530 virtual int32_t readRegister(Registers reg, uint8_t *data);
j3 2:598e601e5846 531 virtual int32_t writeRegister(Registers reg, const uint8_t data);
j3 3:e1770675eca4 532 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 533 uint8_t *data);
j3 3:e1770675eca4 534 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 535 const uint8_t *data);
j3 2:598e601e5846 536
j3 2:598e601e5846 537 private:
j3 2:598e601e5846 538
j3 2:598e601e5846 539 SPI m_spiBus;
j3 2:598e601e5846 540 DigitalOut m_cs;
j3 2:598e601e5846 541 };
j3 2:598e601e5846 542
j3 0:bb5b832891fb 543 #endif /* BMI160_H */
j3 8:a89b529b1d96 544
j3 8:a89b529b1d96 545
j3 8:a89b529b1d96 546 ///@brief fx documentation template.\n
j3 8:a89b529b1d96 547 ///
j3 8:a89b529b1d96 548 ///On Entry:
j3 8:a89b529b1d96 549 ///@param[in] none
j3 8:a89b529b1d96 550 ///
j3 8:a89b529b1d96 551 ///On Exit:
j3 8:a89b529b1d96 552 ///@param[out] none
j3 8:a89b529b1d96 553 ///
j3 8:a89b529b1d96 554 ///@returns none