BMI160 Initial

Dependents:   MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_Pitch_Charles Maxim_Squeeks

Committer:
j3
Date:
Tue Dec 20 19:02:36 2016 +0000
Revision:
13:5d132f873b07
Parent:
12:64931a80340d
Child:
14:646eb94fa2eb
working on docs

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 13:5d132f873b07 59 ///Sensor types
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 13:5d132f873b07 90
j3 1:a4c911640569 91 ///BMI160 registers
j3 0:bb5b832891fb 92 enum Registers
j3 0:bb5b832891fb 93 {
j3 3:e1770675eca4 94 CHIP_ID = 0x00, ///<Chip Identification.
j3 3:e1770675eca4 95 ERR_REG = 0x02, ///<Reports sensor error flags. Flags reset when read.
j3 3:e1770675eca4 96 PMU_STATUS, ///<Reports current power mode for sensors.
j3 3:e1770675eca4 97 DATA_0, ///<MAG_X axis bits7:0
j3 3:e1770675eca4 98 DATA_1, ///<MAG_X axis bits15:8
j3 3:e1770675eca4 99 DATA_2, ///<MAG_Y axis bits7:0
j3 3:e1770675eca4 100 DATA_3, ///<MAG_Y axis bits15:8
j3 3:e1770675eca4 101 DATA_4, ///<MAG_Z axis bits7:0
j3 3:e1770675eca4 102 DATA_5, ///<MAG_Z axis bits15:8
j3 3:e1770675eca4 103 DATA_6, ///<RHALL bits7:0
j3 3:e1770675eca4 104 DATA_7, ///<RHALL bits15:8
j3 3:e1770675eca4 105 DATA_8, ///<GYR_X axis bits7:0
j3 3:e1770675eca4 106 DATA_9, ///<GYR_X axis bits15:8
j3 3:e1770675eca4 107 DATA_10, ///<GYR_Y axis bits7:0
j3 3:e1770675eca4 108 DATA_11, ///<GYR_Y axis bits15:8
j3 3:e1770675eca4 109 DATA_12, ///<GYR_Z axis bits7:0
j3 3:e1770675eca4 110 DATA_13, ///<GYR_Z axis bits15:8
j3 3:e1770675eca4 111 DATA_14, ///<ACC_X axis bits7:0
j3 3:e1770675eca4 112 DATA_15, ///<ACC_X axis bits15:8
j3 3:e1770675eca4 113 DATA_16, ///<ACC_Y axis bits7:0
j3 3:e1770675eca4 114 DATA_17, ///<ACC_Y axis bits15:8
j3 3:e1770675eca4 115 DATA_18, ///<ACC_Z axis bits7:0
j3 3:e1770675eca4 116 DATA_19, ///<ACC_Z axis bits15:8
j3 3:e1770675eca4 117 SENSORTIME_0, ///<24bit counter synchronized with data, bits7:0
j3 3:e1770675eca4 118 SENSORTIME_1, ///<24bit counter synchronized with data, bits15:8
j3 3:e1770675eca4 119 SENSORTIME_2, ///<24bit counter synchronized with data, bits23:16
j3 3:e1770675eca4 120 STATUS, ///<Reports sensors status flags
j3 3:e1770675eca4 121 INT_STATUS_0, ///<Contains interrupt status flags
j3 3:e1770675eca4 122 INT_STATUS_1, ///<Contains interrupt status flags
j3 3:e1770675eca4 123 INT_STATUS_2, ///<Contains interrupt status flags
j3 3:e1770675eca4 124 INT_STATUS_3, ///<Contains interrupt status flags
j3 3:e1770675eca4 125 TEMPERATURE_0, ///<Contains temperature of sensor, bits7:0
j3 3:e1770675eca4 126 TEMPERATURE_1, ///<Contains temperature of sensor, bits15:8
j3 3:e1770675eca4 127 FIFO_LENGTH_0, ///<Current fill level of FIFO, bits7:0
j3 3:e1770675eca4 128 FIFO_LENGTH_1, ///<Current fill level of FIFO, bits10:8
j3 3:e1770675eca4 129 FIFO_DATA, ///<FIFO data read out register, burst read
j3 3:e1770675eca4 130 ACC_CONF = 0x40, ///<Set ODR, bandwidth, and read mode of accelerometer
j3 3:e1770675eca4 131 ACC_RANGE, ///<Sets accelerometer g-range
j3 3:e1770675eca4 132 GYR_CONF, ///<Set ODR, bandwidth, and read mode of gyroscope
j3 3:e1770675eca4 133 GYR_RANGE, ///<Sets gyroscope angular rate measurement range
j3 3:e1770675eca4 134 MAG_CONF, ///<Sets ODR of magnetometer interface
j3 3:e1770675eca4 135 FIFO_DOWNS, ///<Sets down sampling ratios of accel and gyro data
j3 3:e1770675eca4 136 ///<for FIFO
j3 3:e1770675eca4 137 FIFO_CONFIG_0, ///<Sets FIFO Watermark
j3 3:e1770675eca4 138 FIFO_CONFIG_1, ///<Sets which sensor data is available in FIFO,
j3 3:e1770675eca4 139 ///<Header/Headerless mode, Ext Int tagging, Sensortime
j3 3:e1770675eca4 140 MAG_IF_0 = 0x4B, ///<Magnetometer 7-bit I2C address, bits7:1
j3 3:e1770675eca4 141 MAG_IF_1, ///<Magnetometer interface configuration
j3 3:e1770675eca4 142 MAG_IF_2, ///<Magnetometer address to read
j3 3:e1770675eca4 143 MAG_IF_3, ///<Magnetometer address to write
j3 3:e1770675eca4 144 MAG_IF_4, ///<Magnetometer data to write
j3 3:e1770675eca4 145 INT_EN_0, ///<Interrupt enable bits
j3 3:e1770675eca4 146 INT_EN_1, ///<Interrupt enable bits
j3 3:e1770675eca4 147 INT_EN_2, ///<Interrupt enable bits
j3 3:e1770675eca4 148 INT_OUT_CTRL, ///<Contains the behavioral configuration of INT pins
j3 3:e1770675eca4 149 INT_LATCH, ///<Contains the interrupt rest bit and the interrupt
j3 3:e1770675eca4 150 ///<mode selection
j3 3:e1770675eca4 151 INT_MAP_0, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 152 ///<INT1 and INT2 pins
j3 3:e1770675eca4 153 INT_MAP_1, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 154 ///<INT1 and INT2 pins
j3 3:e1770675eca4 155 INT_MAP_2, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 156 ///<INT1 and INT2 pins
j3 3:e1770675eca4 157 INT_DATA_0, ///<Contains the data source definition for the two
j3 3:e1770675eca4 158 ///<interrupt groups
j3 3:e1770675eca4 159 INT_DATA_1, ///<Contains the data source definition for the two
j3 3:e1770675eca4 160 ///<interrupt groups
j3 3:e1770675eca4 161 INT_LOWHIGH_0, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 162 INT_LOWHIGH_1, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 163 INT_LOWHIGH_2, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 164 INT_LOWHIGH_3, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 165 INT_LOWHIGH_4, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 166 INT_MOTION_0, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 167 ///<no motion interrupts
j3 3:e1770675eca4 168 INT_MOTION_1, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 169 ///<no motion interrupts
j3 3:e1770675eca4 170 INT_MOTION_2, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 171 ///<no motion interrupts
j3 3:e1770675eca4 172 INT_MOTION_3, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 173 ///<no motion interrupts
j3 3:e1770675eca4 174 INT_TAP_0, ///<Contains the configuration for the tap interrupts
j3 3:e1770675eca4 175 INT_TAP_1, ///<Contains the configuration for the tap interrupts
j3 3:e1770675eca4 176 INT_ORIENT_0, ///<Contains the configuration for the oeientation
j3 3:e1770675eca4 177 ///<interrupt
j3 3:e1770675eca4 178 INT_ORIENT_1, ///<Contains the configuration for the oeientation
j3 3:e1770675eca4 179 ///<interrupt
j3 3:e1770675eca4 180 INT_FLAT_0, ///<Contains the configuration for the flat interrupt
j3 3:e1770675eca4 181 INT_FLAT_1, ///<Contains the configuration for the flat interrupt
j3 3:e1770675eca4 182 FOC_CONF, ///<Contains configuration for the fast offset
j3 3:e1770675eca4 183 ///<compensation for the accelerometer and gyroscope
j3 3:e1770675eca4 184 CONF, ///<Configuration of sensor, nvm_prog_en bit
j3 3:e1770675eca4 185 IF_CONF, ///<Contains settings for the digital interface
j3 3:e1770675eca4 186 PMU_TRIGGER, ///<Sets trigger conditions to change gyro power modes
j3 3:e1770675eca4 187 SELF_TEST, ///<Self test configuration
j3 3:e1770675eca4 188 NV_CONF = 0x70, ///<Contains settings for the digital interface
j3 3:e1770675eca4 189 OFFSET_0, ///<Contains offset comp values for acc_off_x7:0
j3 3:e1770675eca4 190 OFFSET_1, ///<Contains offset comp values for acc_off_y7:0
j3 3:e1770675eca4 191 OFFSET_2, ///<Contains offset comp values for acc_off_z7:0
j3 3:e1770675eca4 192 OFFSET_3, ///<Contains offset comp values for gyr_off_x7:0
j3 3:e1770675eca4 193 OFFSET_4, ///<Contains offset comp values for gyr_off_y7:0
j3 3:e1770675eca4 194 OFFSET_5, ///<Contains offset comp values for gyr_off_z7:0
j3 3:e1770675eca4 195 OFFSET_6, ///<gyr/acc offset enable bit and gyr_off_(zyx) bits9:8
j3 3:e1770675eca4 196 STEP_CNT_0, ///<Step counter bits 15:8
j3 3:e1770675eca4 197 STEP_CNT_1, ///<Step counter bits 7:0
j3 3:e1770675eca4 198 STEP_CONF_0, ///<Contains configuration of the step detector
j3 3:e1770675eca4 199 STEP_CONF_1, ///<Contains configuration of the step detector
j3 3:e1770675eca4 200 CMD = 0x7E ///<Command register triggers operations like
j3 3:e1770675eca4 201 ///<softreset, NVM programming, etc.
j3 3:e1770675eca4 202 };
j3 3:e1770675eca4 203
j3 8:a89b529b1d96 204
j3 13:5d132f873b07 205 ///@name ERR_REG(0x02)
j3 13:5d132f873b07 206 ///Error register data
j3 12:64931a80340d 207 ///@{
j3 13:5d132f873b07 208
j3 3:e1770675eca4 209 static const uint8_t FATAL_ERR = 0x01;
j3 3:e1770675eca4 210 static const uint8_t ERR_CODE = 0x1E;
j3 3:e1770675eca4 211 static const uint8_t I2C_FAIL_ERR = 0x20;
j3 3:e1770675eca4 212 static const uint8_t DROP_CMD_ERR = 0x40;
j3 3:e1770675eca4 213 static const uint8_t MAG_DRDY_ERR = 0x80;
j3 3:e1770675eca4 214
j3 13:5d132f873b07 215 ///Enumerated error 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 12:64931a80340d 227 ///@}
j3 0:bb5b832891fb 228
j3 8:a89b529b1d96 229
j3 13:5d132f873b07 230 ///@name ACC_CONF(0x40) and ACC_RANGE(0x41)
j3 13:5d132f873b07 231 ///Data for configuring accelerometer
j3 12:64931a80340d 232 ///@{
j3 13:5d132f873b07 233
j3 13:5d132f873b07 234 static const uint8_t ACC_ODR_MASK = 0x0F;
j3 13:5d132f873b07 235 static const uint8_t ACC_ODR_POS = 0x00;
j3 13:5d132f873b07 236 static const uint8_t ACC_BWP_MASK = 0x70;
j3 12:64931a80340d 237 static const uint8_t ACC_BWP_POS = 0x04;
j3 13:5d132f873b07 238 static const uint8_t ACC_US_MASK = 0x80;
j3 12:64931a80340d 239 static const uint8_t ACC_US_POS = 0x07;
j3 8:a89b529b1d96 240
j3 13:5d132f873b07 241 ///Accelerometer output data rates
j3 8:a89b529b1d96 242 enum AccOutPutDataRate
j3 8:a89b529b1d96 243 {
j3 8:a89b529b1d96 244 ACC_ODR_1 = 1, ///< 25/32Hz
j3 8:a89b529b1d96 245 ACC_ODR_2, ///< 25/16Hz
j3 8:a89b529b1d96 246 ACC_ODR_3, ///< 25/8Hz
j3 8:a89b529b1d96 247 ACC_ODR_4, ///< 25/4Hz
j3 8:a89b529b1d96 248 ACC_ODR_5, ///< 25/2Hz
j3 8:a89b529b1d96 249 ACC_ODR_6, ///< 25Hz
j3 8:a89b529b1d96 250 ACC_ODR_7, ///< 50Hz
j3 8:a89b529b1d96 251 ACC_ODR_8, ///< 100Hz
j3 8:a89b529b1d96 252 ACC_ODR_9, ///< 200Hz
j3 8:a89b529b1d96 253 ACC_ODR_10, ///< 400Hz
j3 8:a89b529b1d96 254 ACC_ODR_11, ///< 800Hz
j3 8:a89b529b1d96 255 ACC_ODR_12 ///< 1600Hz
j3 8:a89b529b1d96 256 };
j3 8:a89b529b1d96 257
j3 13:5d132f873b07 258 ///Accelerometer bandwidth parameters
j3 8:a89b529b1d96 259 enum AccBandWidthParam
j3 8:a89b529b1d96 260 {
j3 8:a89b529b1d96 261 ACC_BWP_0 = 0, ///< Average 1 cycle
j3 8:a89b529b1d96 262 ACC_BWP_1, ///< Average 2 cycles
j3 8:a89b529b1d96 263 ACC_BWP_2, ///< Average 4 cycles, use this setting when acc_us = 0
j3 8:a89b529b1d96 264 ACC_BWP_3, ///< Average 8 cycles
j3 8:a89b529b1d96 265 ACC_BWP_4, ///< Average 16 cycles
j3 8:a89b529b1d96 266 ACC_BWP_5, ///< Average 32 cycles
j3 8:a89b529b1d96 267 ACC_BWP_6, ///< Average 64 cycles
j3 8:a89b529b1d96 268 ACC_BWP_7 ///< Average 128 cycles
j3 8:a89b529b1d96 269 };
j3 8:a89b529b1d96 270
j3 13:5d132f873b07 271 ///Accelerometer undersampling
j3 8:a89b529b1d96 272 enum AccUnderSampling
j3 8:a89b529b1d96 273 {
j3 8:a89b529b1d96 274 ACC_US_OFF = 0,
j3 8:a89b529b1d96 275 ACC_US_ON
j3 8:a89b529b1d96 276 };
j3 8:a89b529b1d96 277
j3 13:5d132f873b07 278 ///Accelerometer ranges
j3 8:a89b529b1d96 279 enum AccRange
j3 8:a89b529b1d96 280 {
j3 8:a89b529b1d96 281 SENS_2G = 0, ///<Accelerometer range +-2G
j3 8:a89b529b1d96 282 SENS_4G, ///<Accelerometer range +-4G
j3 8:a89b529b1d96 283 SENS_8G, ///<Accelerometer range +-8G
j3 8:a89b529b1d96 284 SENS_16G, ///<Accelerometer range +-16G
j3 8:a89b529b1d96 285 };
j3 8:a89b529b1d96 286
j3 13:5d132f873b07 287 ///Accelerometer configuration data structure
j3 9:ca6b5fecdd63 288 struct AccConfig
j3 9:ca6b5fecdd63 289 {
j3 9:ca6b5fecdd63 290 AccRange range;
j3 9:ca6b5fecdd63 291 AccUnderSampling us;
j3 9:ca6b5fecdd63 292 AccBandWidthParam bwp;
j3 9:ca6b5fecdd63 293 AccOutPutDataRate odr;
j3 9:ca6b5fecdd63 294 };
j3 9:ca6b5fecdd63 295
j3 13:5d132f873b07 296 ///Accelerometer default configuration
j3 9:ca6b5fecdd63 297 static const AccConfig DEFAULT_ACC_CONFIG;
j3 12:64931a80340d 298 ///@}
j3 9:ca6b5fecdd63 299
j3 12:64931a80340d 300
j3 13:5d132f873b07 301 ///Enumerated power modes
j3 4:ebac8c8f6347 302 enum PowerModes
j3 4:ebac8c8f6347 303 {
j3 4:ebac8c8f6347 304 SUSPEND = 0, ///<Acc and Gyro, No sampling, No FIFO data readout
j3 4:ebac8c8f6347 305 NORMAL, ///<Acc and Gyro, Full chip operation
j3 4:ebac8c8f6347 306 LOW_POWER, ///<Acc duty-cycling between suspend and normal
j3 4:ebac8c8f6347 307 FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms
j3 4:ebac8c8f6347 308 };
j3 4:ebac8c8f6347 309
j3 12:64931a80340d 310
j3 13:5d132f873b07 311 ///Enumerated commands used with CMD register
j3 5:35e032c8d8aa 312 enum Commands
j3 5:35e032c8d8aa 313 {
j3 5:35e032c8d8aa 314 START_FOC = 0x03, ///<Starts Fast Offset Calibrartion
j3 7:9848196cb65e 315 ACC_SET_PMU_MODE = 0x10, ///<Sets acc power mode
j3 8:a89b529b1d96 316 GYR_SET_PMU_MODE = 0x14, ///<Sets gyro power mode
j3 8:a89b529b1d96 317 MAG_SET_PMU_MODE = 0x18, ///<Sets mag power mode
j3 5:35e032c8d8aa 318 PROG_NVM = 0xA0, ///<Writes NVM backed registers into NVM
j3 5:35e032c8d8aa 319 FIFO_FLUSH = 0xB0, ///<Clears FIFO
j3 5:35e032c8d8aa 320 INT_RESET, ///<Clears interrupt engine, INT_STATUS, and
j3 5:35e032c8d8aa 321 ///<the interrupt pin
j3 5:35e032c8d8aa 322 STEP_CNT_CLR, ///<Triggers reset of the step counter
j3 5:35e032c8d8aa 323 SOFT_RESET = 0xB6 ///<Triggers a reset including a reboot.
j3 5:35e032c8d8aa 324 };
j3 5:35e032c8d8aa 325
j3 0:bb5b832891fb 326
j3 0:bb5b832891fb 327 ///@brief BMI160 Destructor.\n
j3 0:bb5b832891fb 328 ///
j3 0:bb5b832891fb 329 ///On Entry:
j3 0:bb5b832891fb 330 ///@param[in] none
j3 0:bb5b832891fb 331 ///
j3 0:bb5b832891fb 332 ///On Exit:
j3 0:bb5b832891fb 333 ///@param[out] none
j3 0:bb5b832891fb 334 ///
j3 0:bb5b832891fb 335 ///@returns none
j3 2:598e601e5846 336 virtual ~BMI160(){ }
j3 0:bb5b832891fb 337
j3 0:bb5b832891fb 338
j3 0:bb5b832891fb 339 ///@brief Reads a single register.\n
j3 0:bb5b832891fb 340 ///
j3 0:bb5b832891fb 341 ///On Entry:
j3 0:bb5b832891fb 342 ///@param[in] data - pointer to memory for storing read data
j3 0:bb5b832891fb 343 ///
j3 0:bb5b832891fb 344 ///On Exit:
j3 0:bb5b832891fb 345 ///@param[out] data - holds contents of read register on success
j3 0:bb5b832891fb 346 ///
j3 0:bb5b832891fb 347 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 348 virtual int32_t readRegister(Registers reg, uint8_t *data) = 0;
j3 0:bb5b832891fb 349
j3 0:bb5b832891fb 350
j3 0:bb5b832891fb 351 ///@brief Writes a single register.\n
j3 0:bb5b832891fb 352 ///
j3 0:bb5b832891fb 353 ///On Entry:
j3 0:bb5b832891fb 354 ///@param[in] data - data to write to register
j3 0:bb5b832891fb 355 ///
j3 0:bb5b832891fb 356 ///On Exit:
j3 0:bb5b832891fb 357 ///@param[out] none
j3 0:bb5b832891fb 358 ///
j3 0:bb5b832891fb 359 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 360 virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0;
j3 0:bb5b832891fb 361
j3 0:bb5b832891fb 362
j3 0:bb5b832891fb 363 ///@brief Reads a block of registers.\n
j3 0:bb5b832891fb 364 ///@detail User must ensure that all registers between 'startReg' and
j3 0:bb5b832891fb 365 ///'stopReg' exist and are readable. Function reads up to, including,
j3 0:bb5b832891fb 366 ///'stopReg'.\n
j3 0:bb5b832891fb 367 ///
j3 0:bb5b832891fb 368 ///On Entry:
j3 0:bb5b832891fb 369 ///@param[in] startReg - register to start reading from
j3 0:bb5b832891fb 370 ///@param[in] stopReg - register to stop reading from
j3 0:bb5b832891fb 371 ///@param[in] data - pointer to memory for storing read data
j3 0:bb5b832891fb 372 ///
j3 0:bb5b832891fb 373 ///On Exit:
j3 0:bb5b832891fb 374 ///@param[out] data - holds contents of read registers on success
j3 0:bb5b832891fb 375 ///
j3 0:bb5b832891fb 376 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 377 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 378 uint8_t *data) = 0;
j3 0:bb5b832891fb 379
j3 0:bb5b832891fb 380
j3 0:bb5b832891fb 381 ///@brief Writes a block of registers.\n
j3 0:bb5b832891fb 382 ///@detail User must ensure that all registers between 'startReg' and
j3 0:bb5b832891fb 383 ///'stopReg' exist and are writeable. Function writes up to, including,
j3 0:bb5b832891fb 384 ///'stopReg'.\n
j3 0:bb5b832891fb 385 ///
j3 0:bb5b832891fb 386 ///On Entry:
j3 0:bb5b832891fb 387 ///@param[in] startReg - register to start writing at
j3 0:bb5b832891fb 388 ///@param[in] stopReg - register to stop writing at
j3 0:bb5b832891fb 389 ///@param[in] data - pointer to data to write to registers
j3 0:bb5b832891fb 390 ///
j3 0:bb5b832891fb 391 ///On Exit:
j3 0:bb5b832891fb 392 ///@param[out] none
j3 0:bb5b832891fb 393 ///
j3 0:bb5b832891fb 394 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 395 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 396 const uint8_t *data) = 0;
j3 3:e1770675eca4 397
j3 3:e1770675eca4 398
j3 5:35e032c8d8aa 399 ///@brief Sets sensors power mode through CMD register.\n
j3 5:35e032c8d8aa 400 ///@details Observe command execution times given in datasheet.\n
j3 5:35e032c8d8aa 401 ///
j3 5:35e032c8d8aa 402 ///On Entry:
j3 5:35e032c8d8aa 403 ///@param[in] sensor - Sensor which power mode we are setting
j3 5:35e032c8d8aa 404 ///@param[in] pwrMode - Desired powermode of the sensor
j3 5:35e032c8d8aa 405 ///
j3 5:35e032c8d8aa 406 ///On Exit:
j3 5:35e032c8d8aa 407 ///@param[out]
j3 5:35e032c8d8aa 408 ///
j3 5:35e032c8d8aa 409 ///@returns 0 on success, non 0 on failure
j3 5:35e032c8d8aa 410 int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode);
j3 5:35e032c8d8aa 411
j3 5:35e032c8d8aa 412
j3 12:64931a80340d 413 ///@brief Configure Accelerometer.\n
j3 3:e1770675eca4 414 ///
j3 3:e1770675eca4 415 ///On Entry:
j3 12:64931a80340d 416 ///@param[in] config - Accelerometer configuration
j3 3:e1770675eca4 417 ///
j3 3:e1770675eca4 418 ///On Exit:
j3 12:64931a80340d 419 ///@param[out] none
j3 3:e1770675eca4 420 ///
j3 3:e1770675eca4 421 ///@returns 0 on success, non 0 on failure
j3 12:64931a80340d 422 int32_t setAccConfig(const AccConfig &config);
j3 8:a89b529b1d96 423
j3 8:a89b529b1d96 424
j3 8:a89b529b1d96 425 ///@brief Get accelerometer axis as float.\n
j3 3:e1770675eca4 426 ///
j3 3:e1770675eca4 427 ///On Entry:
j3 8:a89b529b1d96 428 ///@param[in] axis - Sensor axis
j3 8:a89b529b1d96 429 ///@param[in] data - AxisData structure
j3 12:64931a80340d 430 ///@param[in] range - Accelerometer range
j3 8:a89b529b1d96 431 ///
j3 8:a89b529b1d96 432 ///On Exit:
j3 8:a89b529b1d96 433 ///@param[out] data - Structure holds raw and scaled axis data
j3 8:a89b529b1d96 434 ///
j3 8:a89b529b1d96 435 ///@returns 0 on success, non 0 on failure
j3 12:64931a80340d 436 int32_t getAccAxis(SensorAxis axis, AxisData &data, AccRange range);
j3 8:a89b529b1d96 437
j3 8:a89b529b1d96 438
j3 8:a89b529b1d96 439 ///@brief Get accelerometer xyz axis as float.\n
j3 8:a89b529b1d96 440 ///
j3 8:a89b529b1d96 441 ///On Entry:
j3 8:a89b529b1d96 442 ///@param[in] data - SensorData structure
j3 12:64931a80340d 443 ///@param[in] range - Accelerometer range
j3 3:e1770675eca4 444 ///
j3 3:e1770675eca4 445 ///On Exit:
j3 8:a89b529b1d96 446 ///@param[out] data - Structure holds raw and scaled data for all three axis
j3 3:e1770675eca4 447 ///
j3 8:a89b529b1d96 448 ///@returns 0 on success, non 0 on failure
j3 12:64931a80340d 449 int32_t getAccXYZ(SensorData &data, AccRange range);
j3 10:9e219f2f1fb3 450
j3 10:9e219f2f1fb3 451
j3 10:9e219f2f1fb3 452 ///@brief Get sensor time.\n
j3 10:9e219f2f1fb3 453 ///
j3 10:9e219f2f1fb3 454 ///On Entry:
j3 10:9e219f2f1fb3 455 ///@param[in] data - pointer to float for holding data
j3 10:9e219f2f1fb3 456 ///
j3 10:9e219f2f1fb3 457 ///On Exit:
j3 10:9e219f2f1fb3 458 ///@param[out] data - time in seconds, as float
j3 10:9e219f2f1fb3 459 ///
j3 10:9e219f2f1fb3 460 ///@returns returns 0 on success, non 0 on failure
j3 10:9e219f2f1fb3 461 int32_t getSensorTime(float *data);
j3 12:64931a80340d 462
j3 12:64931a80340d 463
j3 12:64931a80340d 464 ///@brief Get die temperature.\n
j3 12:64931a80340d 465 ///
j3 12:64931a80340d 466 ///On Entry:
j3 12:64931a80340d 467 ///@param[in] temp - pointer to float for temperature
j3 12:64931a80340d 468 ///
j3 12:64931a80340d 469 ///On Exit:
j3 12:64931a80340d 470 ///@param[out] temp - on success, holds the die temperature
j3 12:64931a80340d 471 ///
j3 12:64931a80340d 472 ///@returns 0 on success, non 0 on failure
j3 12:64931a80340d 473 int32_t getTemperature(float *temp);
j3 2:598e601e5846 474 };
j3 2:598e601e5846 475
j3 2:598e601e5846 476
j3 2:598e601e5846 477 /**
j3 2:598e601e5846 478 @brief BMI160_I2C - supports BMI160 object with I2C interface
j3 2:598e601e5846 479 */
j3 2:598e601e5846 480 class BMI160_I2C: public BMI160
j3 2:598e601e5846 481 {
j3 2:598e601e5846 482 public:
j3 2:598e601e5846 483
j3 2:598e601e5846 484 ///BMI160 default I2C address.
j3 2:598e601e5846 485 static const uint8_t I2C_ADRS_SDO_LO = 0x68;
j3 2:598e601e5846 486 ///BMI160 optional I2C address.
j3 2:598e601e5846 487 static const uint8_t I2C_ADRS_SDO_HI = 0x69;
j3 0:bb5b832891fb 488
j3 2:598e601e5846 489
j3 2:598e601e5846 490 ///@brief BMI160_I2C Constructor.\n
j3 0:bb5b832891fb 491 ///
j3 0:bb5b832891fb 492 ///On Entry:
j3 2:598e601e5846 493 ///@param[in] i2cBus - reference to I2C bus for this device
j3 2:598e601e5846 494 ///@param[in] i2cAdrs - 7-bit I2C address
j3 0:bb5b832891fb 495 ///
j3 0:bb5b832891fb 496 ///On Exit:
j3 0:bb5b832891fb 497 ///@param[out] none
j3 0:bb5b832891fb 498 ///
j3 0:bb5b832891fb 499 ///@returns none
j3 2:598e601e5846 500 BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs);
j3 2:598e601e5846 501
j3 2:598e601e5846 502
j3 2:598e601e5846 503 virtual int32_t readRegister(Registers reg, uint8_t *data);
j3 2:598e601e5846 504 virtual int32_t writeRegister(Registers reg, const uint8_t data);
j3 3:e1770675eca4 505 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 506 uint8_t *data);
j3 3:e1770675eca4 507 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 508 const uint8_t *data);
j3 2:598e601e5846 509
j3 0:bb5b832891fb 510 private:
j3 0:bb5b832891fb 511
j3 0:bb5b832891fb 512 I2C m_i2cBus;
j3 0:bb5b832891fb 513 uint8_t m_Wadrs, m_Radrs;
j3 0:bb5b832891fb 514 };
j3 0:bb5b832891fb 515
j3 2:598e601e5846 516
j3 2:598e601e5846 517 /**
j3 2:598e601e5846 518 @brief BMI160_SPI - supports BMI160 object with SPI interface
j3 2:598e601e5846 519 */
j3 2:598e601e5846 520 class BMI160_SPI: public BMI160
j3 2:598e601e5846 521 {
j3 2:598e601e5846 522 public:
j3 2:598e601e5846 523
j3 2:598e601e5846 524 ///@brief BMI160_SPI Constructor.\n
j3 2:598e601e5846 525 ///
j3 2:598e601e5846 526 ///On Entry:
j3 2:598e601e5846 527 ///@param[in] spiBus - reference to SPI bus for this device
j3 2:598e601e5846 528 ///@param[in] cs - reference to DigitalOut used for chip select
j3 2:598e601e5846 529 ///
j3 2:598e601e5846 530 ///On Exit:
j3 2:598e601e5846 531 ///@param[out] none
j3 2:598e601e5846 532 ///
j3 2:598e601e5846 533 ///@returns none
j3 2:598e601e5846 534 BMI160_SPI(SPI &spiBus, DigitalOut &cs);
j3 2:598e601e5846 535
j3 2:598e601e5846 536 virtual int32_t readRegister(Registers reg, uint8_t *data);
j3 2:598e601e5846 537 virtual int32_t writeRegister(Registers reg, const uint8_t data);
j3 3:e1770675eca4 538 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 539 uint8_t *data);
j3 3:e1770675eca4 540 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 541 const uint8_t *data);
j3 2:598e601e5846 542
j3 2:598e601e5846 543 private:
j3 2:598e601e5846 544
j3 2:598e601e5846 545 SPI m_spiBus;
j3 2:598e601e5846 546 DigitalOut m_cs;
j3 2:598e601e5846 547 };
j3 2:598e601e5846 548
j3 0:bb5b832891fb 549 #endif /* BMI160_H */
j3 8:a89b529b1d96 550
j3 8:a89b529b1d96 551
j3 8:a89b529b1d96 552 ///@brief fx documentation template.\n
j3 8:a89b529b1d96 553 ///
j3 8:a89b529b1d96 554 ///On Entry:
j3 8:a89b529b1d96 555 ///@param[in] none
j3 8:a89b529b1d96 556 ///
j3 8:a89b529b1d96 557 ///On Exit:
j3 8:a89b529b1d96 558 ///@param[out] none
j3 8:a89b529b1d96 559 ///
j3 8:a89b529b1d96 560 ///@returns none