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:
Thu Jan 05 21:11:47 2017 +0000
Revision:
17:0ae99e97bcf5
Parent:
16:12782f5d4aa4
Child:
18:4949e9b15b6e
Updated docs for virtual fxs;

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 15:dc35ccc0b08e 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 15:dc35ccc0b08e 82 ///Structure for sensor time data
j3 15:dc35ccc0b08e 83 struct SensorTime
j3 15:dc35ccc0b08e 84 {
j3 15:dc35ccc0b08e 85 uint32_t raw; ///<raw SensorTime
j3 15:dc35ccc0b08e 86 float seconds; ///<SensorTime as seconds
j3 15:dc35ccc0b08e 87 };
j3 15:dc35ccc0b08e 88
j3 15:dc35ccc0b08e 89 ///Period of internal counter
j3 15:dc35ccc0b08e 90 static const float SENSOR_TIME_LSB = 39e-6;
j3 15:dc35ccc0b08e 91
j3 8:a89b529b1d96 92 ///Structure for holding sensor data
j3 8:a89b529b1d96 93 struct SensorData
j3 8:a89b529b1d96 94 {
j3 8:a89b529b1d96 95 AxisData xAxis; ///<Sensor X axis data
j3 8:a89b529b1d96 96 AxisData yAxis; ///<Sensor Y axis data
j3 8:a89b529b1d96 97 AxisData zAxis; ///<Sensor Z axis data
j3 8:a89b529b1d96 98 };
j3 8:a89b529b1d96 99
j3 13:5d132f873b07 100
j3 1:a4c911640569 101 ///BMI160 registers
j3 0:bb5b832891fb 102 enum Registers
j3 0:bb5b832891fb 103 {
j3 3:e1770675eca4 104 CHIP_ID = 0x00, ///<Chip Identification.
j3 3:e1770675eca4 105 ERR_REG = 0x02, ///<Reports sensor error flags. Flags reset when read.
j3 3:e1770675eca4 106 PMU_STATUS, ///<Reports current power mode for sensors.
j3 3:e1770675eca4 107 DATA_0, ///<MAG_X axis bits7:0
j3 3:e1770675eca4 108 DATA_1, ///<MAG_X axis bits15:8
j3 3:e1770675eca4 109 DATA_2, ///<MAG_Y axis bits7:0
j3 3:e1770675eca4 110 DATA_3, ///<MAG_Y axis bits15:8
j3 3:e1770675eca4 111 DATA_4, ///<MAG_Z axis bits7:0
j3 3:e1770675eca4 112 DATA_5, ///<MAG_Z axis bits15:8
j3 3:e1770675eca4 113 DATA_6, ///<RHALL bits7:0
j3 3:e1770675eca4 114 DATA_7, ///<RHALL bits15:8
j3 3:e1770675eca4 115 DATA_8, ///<GYR_X axis bits7:0
j3 3:e1770675eca4 116 DATA_9, ///<GYR_X axis bits15:8
j3 3:e1770675eca4 117 DATA_10, ///<GYR_Y axis bits7:0
j3 3:e1770675eca4 118 DATA_11, ///<GYR_Y axis bits15:8
j3 3:e1770675eca4 119 DATA_12, ///<GYR_Z axis bits7:0
j3 3:e1770675eca4 120 DATA_13, ///<GYR_Z axis bits15:8
j3 3:e1770675eca4 121 DATA_14, ///<ACC_X axis bits7:0
j3 3:e1770675eca4 122 DATA_15, ///<ACC_X axis bits15:8
j3 3:e1770675eca4 123 DATA_16, ///<ACC_Y axis bits7:0
j3 3:e1770675eca4 124 DATA_17, ///<ACC_Y axis bits15:8
j3 3:e1770675eca4 125 DATA_18, ///<ACC_Z axis bits7:0
j3 3:e1770675eca4 126 DATA_19, ///<ACC_Z axis bits15:8
j3 3:e1770675eca4 127 SENSORTIME_0, ///<24bit counter synchronized with data, bits7:0
j3 3:e1770675eca4 128 SENSORTIME_1, ///<24bit counter synchronized with data, bits15:8
j3 3:e1770675eca4 129 SENSORTIME_2, ///<24bit counter synchronized with data, bits23:16
j3 3:e1770675eca4 130 STATUS, ///<Reports sensors status flags
j3 3:e1770675eca4 131 INT_STATUS_0, ///<Contains interrupt status flags
j3 3:e1770675eca4 132 INT_STATUS_1, ///<Contains interrupt status flags
j3 3:e1770675eca4 133 INT_STATUS_2, ///<Contains interrupt status flags
j3 3:e1770675eca4 134 INT_STATUS_3, ///<Contains interrupt status flags
j3 3:e1770675eca4 135 TEMPERATURE_0, ///<Contains temperature of sensor, bits7:0
j3 3:e1770675eca4 136 TEMPERATURE_1, ///<Contains temperature of sensor, bits15:8
j3 3:e1770675eca4 137 FIFO_LENGTH_0, ///<Current fill level of FIFO, bits7:0
j3 3:e1770675eca4 138 FIFO_LENGTH_1, ///<Current fill level of FIFO, bits10:8
j3 3:e1770675eca4 139 FIFO_DATA, ///<FIFO data read out register, burst read
j3 3:e1770675eca4 140 ACC_CONF = 0x40, ///<Set ODR, bandwidth, and read mode of accelerometer
j3 3:e1770675eca4 141 ACC_RANGE, ///<Sets accelerometer g-range
j3 3:e1770675eca4 142 GYR_CONF, ///<Set ODR, bandwidth, and read mode of gyroscope
j3 3:e1770675eca4 143 GYR_RANGE, ///<Sets gyroscope angular rate measurement range
j3 3:e1770675eca4 144 MAG_CONF, ///<Sets ODR of magnetometer interface
j3 3:e1770675eca4 145 FIFO_DOWNS, ///<Sets down sampling ratios of accel and gyro data
j3 3:e1770675eca4 146 ///<for FIFO
j3 3:e1770675eca4 147 FIFO_CONFIG_0, ///<Sets FIFO Watermark
j3 3:e1770675eca4 148 FIFO_CONFIG_1, ///<Sets which sensor data is available in FIFO,
j3 3:e1770675eca4 149 ///<Header/Headerless mode, Ext Int tagging, Sensortime
j3 3:e1770675eca4 150 MAG_IF_0 = 0x4B, ///<Magnetometer 7-bit I2C address, bits7:1
j3 3:e1770675eca4 151 MAG_IF_1, ///<Magnetometer interface configuration
j3 3:e1770675eca4 152 MAG_IF_2, ///<Magnetometer address to read
j3 3:e1770675eca4 153 MAG_IF_3, ///<Magnetometer address to write
j3 3:e1770675eca4 154 MAG_IF_4, ///<Magnetometer data to write
j3 3:e1770675eca4 155 INT_EN_0, ///<Interrupt enable bits
j3 3:e1770675eca4 156 INT_EN_1, ///<Interrupt enable bits
j3 3:e1770675eca4 157 INT_EN_2, ///<Interrupt enable bits
j3 3:e1770675eca4 158 INT_OUT_CTRL, ///<Contains the behavioral configuration of INT pins
j3 3:e1770675eca4 159 INT_LATCH, ///<Contains the interrupt rest bit and the interrupt
j3 3:e1770675eca4 160 ///<mode selection
j3 3:e1770675eca4 161 INT_MAP_0, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 162 ///<INT1 and INT2 pins
j3 3:e1770675eca4 163 INT_MAP_1, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 164 ///<INT1 and INT2 pins
j3 3:e1770675eca4 165 INT_MAP_2, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 166 ///<INT1 and INT2 pins
j3 3:e1770675eca4 167 INT_DATA_0, ///<Contains the data source definition for the two
j3 3:e1770675eca4 168 ///<interrupt groups
j3 3:e1770675eca4 169 INT_DATA_1, ///<Contains the data source definition for the two
j3 3:e1770675eca4 170 ///<interrupt groups
j3 3:e1770675eca4 171 INT_LOWHIGH_0, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 172 INT_LOWHIGH_1, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 173 INT_LOWHIGH_2, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 174 INT_LOWHIGH_3, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 175 INT_LOWHIGH_4, ///<Contains the configuration for the low g interrupt
j3 3:e1770675eca4 176 INT_MOTION_0, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 177 ///<no motion interrupts
j3 3:e1770675eca4 178 INT_MOTION_1, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 179 ///<no motion interrupts
j3 3:e1770675eca4 180 INT_MOTION_2, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 181 ///<no motion interrupts
j3 3:e1770675eca4 182 INT_MOTION_3, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 183 ///<no motion interrupts
j3 3:e1770675eca4 184 INT_TAP_0, ///<Contains the configuration for the tap interrupts
j3 3:e1770675eca4 185 INT_TAP_1, ///<Contains the configuration for the tap interrupts
j3 3:e1770675eca4 186 INT_ORIENT_0, ///<Contains the configuration for the oeientation
j3 3:e1770675eca4 187 ///<interrupt
j3 3:e1770675eca4 188 INT_ORIENT_1, ///<Contains the configuration for the oeientation
j3 3:e1770675eca4 189 ///<interrupt
j3 3:e1770675eca4 190 INT_FLAT_0, ///<Contains the configuration for the flat interrupt
j3 3:e1770675eca4 191 INT_FLAT_1, ///<Contains the configuration for the flat interrupt
j3 3:e1770675eca4 192 FOC_CONF, ///<Contains configuration for the fast offset
j3 3:e1770675eca4 193 ///<compensation for the accelerometer and gyroscope
j3 3:e1770675eca4 194 CONF, ///<Configuration of sensor, nvm_prog_en bit
j3 3:e1770675eca4 195 IF_CONF, ///<Contains settings for the digital interface
j3 3:e1770675eca4 196 PMU_TRIGGER, ///<Sets trigger conditions to change gyro power modes
j3 3:e1770675eca4 197 SELF_TEST, ///<Self test configuration
j3 3:e1770675eca4 198 NV_CONF = 0x70, ///<Contains settings for the digital interface
j3 3:e1770675eca4 199 OFFSET_0, ///<Contains offset comp values for acc_off_x7:0
j3 3:e1770675eca4 200 OFFSET_1, ///<Contains offset comp values for acc_off_y7:0
j3 3:e1770675eca4 201 OFFSET_2, ///<Contains offset comp values for acc_off_z7:0
j3 3:e1770675eca4 202 OFFSET_3, ///<Contains offset comp values for gyr_off_x7:0
j3 3:e1770675eca4 203 OFFSET_4, ///<Contains offset comp values for gyr_off_y7:0
j3 3:e1770675eca4 204 OFFSET_5, ///<Contains offset comp values for gyr_off_z7:0
j3 3:e1770675eca4 205 OFFSET_6, ///<gyr/acc offset enable bit and gyr_off_(zyx) bits9:8
j3 3:e1770675eca4 206 STEP_CNT_0, ///<Step counter bits 15:8
j3 3:e1770675eca4 207 STEP_CNT_1, ///<Step counter bits 7:0
j3 3:e1770675eca4 208 STEP_CONF_0, ///<Contains configuration of the step detector
j3 3:e1770675eca4 209 STEP_CONF_1, ///<Contains configuration of the step detector
j3 3:e1770675eca4 210 CMD = 0x7E ///<Command register triggers operations like
j3 3:e1770675eca4 211 ///<softreset, NVM programming, etc.
j3 3:e1770675eca4 212 };
j3 3:e1770675eca4 213
j3 8:a89b529b1d96 214
j3 13:5d132f873b07 215 ///@name ERR_REG(0x02)
j3 13:5d132f873b07 216 ///Error register data
j3 12:64931a80340d 217 ///@{
j3 13:5d132f873b07 218
j3 14:646eb94fa2eb 219 static const uint8_t FATAL_ERR_MASK = 0x01;
j3 14:646eb94fa2eb 220 static const uint8_t FATAL_ERR_POS = 0x00;
j3 14:646eb94fa2eb 221 static const uint8_t ERR_CODE_MASK = 0x1E;
j3 14:646eb94fa2eb 222 static const uint8_t ERR_CODE_POS = 0x01;
j3 14:646eb94fa2eb 223 static const uint8_t I2C_FAIL_ERR_MASK = 0x20;
j3 14:646eb94fa2eb 224 static const uint8_t I2C_FAIL_ERR_POS = 0x05;
j3 14:646eb94fa2eb 225 static const uint8_t DROP_CMD_ERR_MASK = 0x40;
j3 14:646eb94fa2eb 226 static const uint8_t DROP_CMD_ERR_POS = 0x06;
j3 14:646eb94fa2eb 227 static const uint8_t MAG_DRDY_ERR_MASK = 0x80;
j3 14:646eb94fa2eb 228 static const uint8_t MAG_DRDY_ERR_POS = 0x08;
j3 3:e1770675eca4 229
j3 13:5d132f873b07 230 ///Enumerated error codes
j3 3:e1770675eca4 231 enum ErrorCodes
j3 3:e1770675eca4 232 {
j3 3:e1770675eca4 233 NO_ERROR = 0, ///<No Error
j3 3:e1770675eca4 234 ERROR_1, ///<Listed as error
j3 3:e1770675eca4 235 ERROR_2, ///<Listed as error
j3 3:e1770675eca4 236 LPM_INT_PFD, ///<Low-power mode and interrupt uses pre-filtered
j3 3:e1770675eca4 237 ///<data
j3 4:ebac8c8f6347 238 ODR_MISMATCH = 0x06, ///<ODRs of enabled sensors in headerless mode do
j3 4:ebac8c8f6347 239 ///<not match
j3 3:e1770675eca4 240 PFD_USED_LPM ///<Pre-filtered data are used in low power mode
j3 0:bb5b832891fb 241 };
j3 12:64931a80340d 242 ///@}
j3 0:bb5b832891fb 243
j3 8:a89b529b1d96 244
j3 13:5d132f873b07 245 ///@name ACC_CONF(0x40) and ACC_RANGE(0x41)
j3 13:5d132f873b07 246 ///Data for configuring accelerometer
j3 12:64931a80340d 247 ///@{
j3 13:5d132f873b07 248
j3 13:5d132f873b07 249 static const uint8_t ACC_ODR_MASK = 0x0F;
j3 13:5d132f873b07 250 static const uint8_t ACC_ODR_POS = 0x00;
j3 13:5d132f873b07 251 static const uint8_t ACC_BWP_MASK = 0x70;
j3 12:64931a80340d 252 static const uint8_t ACC_BWP_POS = 0x04;
j3 13:5d132f873b07 253 static const uint8_t ACC_US_MASK = 0x80;
j3 12:64931a80340d 254 static const uint8_t ACC_US_POS = 0x07;
j3 14:646eb94fa2eb 255 static const uint8_t ACC_RANGE_MASK = 0x0F;
j3 14:646eb94fa2eb 256 static const uint8_t ACC_RANGE_POS = 0x00;
j3 8:a89b529b1d96 257
j3 13:5d132f873b07 258 ///Accelerometer output data rates
j3 16:12782f5d4aa4 259 enum AccOutputDataRate
j3 8:a89b529b1d96 260 {
j3 8:a89b529b1d96 261 ACC_ODR_1 = 1, ///< 25/32Hz
j3 8:a89b529b1d96 262 ACC_ODR_2, ///< 25/16Hz
j3 8:a89b529b1d96 263 ACC_ODR_3, ///< 25/8Hz
j3 8:a89b529b1d96 264 ACC_ODR_4, ///< 25/4Hz
j3 8:a89b529b1d96 265 ACC_ODR_5, ///< 25/2Hz
j3 8:a89b529b1d96 266 ACC_ODR_6, ///< 25Hz
j3 8:a89b529b1d96 267 ACC_ODR_7, ///< 50Hz
j3 8:a89b529b1d96 268 ACC_ODR_8, ///< 100Hz
j3 8:a89b529b1d96 269 ACC_ODR_9, ///< 200Hz
j3 8:a89b529b1d96 270 ACC_ODR_10, ///< 400Hz
j3 8:a89b529b1d96 271 ACC_ODR_11, ///< 800Hz
j3 8:a89b529b1d96 272 ACC_ODR_12 ///< 1600Hz
j3 8:a89b529b1d96 273 };
j3 8:a89b529b1d96 274
j3 13:5d132f873b07 275 ///Accelerometer bandwidth parameters
j3 8:a89b529b1d96 276 enum AccBandWidthParam
j3 8:a89b529b1d96 277 {
j3 16:12782f5d4aa4 278 ACC_BWP_0 = 0, ///< Average 1 cycle; when acc_us = 0 OSR4
j3 16:12782f5d4aa4 279 ACC_BWP_1, ///< Average 2 cycles; when acc_us = 0 OSR2
j3 16:12782f5d4aa4 280 ACC_BWP_2, ///< Average 4 cycles; when acc_us = 0 normal mode
j3 8:a89b529b1d96 281 ACC_BWP_3, ///< Average 8 cycles
j3 8:a89b529b1d96 282 ACC_BWP_4, ///< Average 16 cycles
j3 8:a89b529b1d96 283 ACC_BWP_5, ///< Average 32 cycles
j3 8:a89b529b1d96 284 ACC_BWP_6, ///< Average 64 cycles
j3 8:a89b529b1d96 285 ACC_BWP_7 ///< Average 128 cycles
j3 8:a89b529b1d96 286 };
j3 8:a89b529b1d96 287
j3 13:5d132f873b07 288 ///Accelerometer undersampling
j3 8:a89b529b1d96 289 enum AccUnderSampling
j3 8:a89b529b1d96 290 {
j3 8:a89b529b1d96 291 ACC_US_OFF = 0,
j3 8:a89b529b1d96 292 ACC_US_ON
j3 8:a89b529b1d96 293 };
j3 8:a89b529b1d96 294
j3 13:5d132f873b07 295 ///Accelerometer ranges
j3 8:a89b529b1d96 296 enum AccRange
j3 8:a89b529b1d96 297 {
j3 15:dc35ccc0b08e 298 SENS_2G = 0x03, ///<Accelerometer range +-2G
j3 15:dc35ccc0b08e 299 SENS_4G = 0x05, ///<Accelerometer range +-4G
j3 15:dc35ccc0b08e 300 SENS_8G = 0x08, ///<Accelerometer range +-8G
j3 16:12782f5d4aa4 301 SENS_16G = 0x0C ///<Accelerometer range +-16G
j3 8:a89b529b1d96 302 };
j3 8:a89b529b1d96 303
j3 15:dc35ccc0b08e 304 static const float SENS_2G_LSB_PER_G = 16384.0F;
j3 15:dc35ccc0b08e 305 static const float SENS_4G_LSB_PER_G = 8192.0F;
j3 15:dc35ccc0b08e 306 static const float SENS_8G_LSB_PER_G = 4096.0F;
j3 15:dc35ccc0b08e 307 static const float SENS_16G_LSB_PER_G = 2048.0F;
j3 15:dc35ccc0b08e 308
j3 13:5d132f873b07 309 ///Accelerometer configuration data structure
j3 9:ca6b5fecdd63 310 struct AccConfig
j3 9:ca6b5fecdd63 311 {
j3 14:646eb94fa2eb 312 AccRange range; ///<Accelerometer range
j3 14:646eb94fa2eb 313 AccUnderSampling us; ///<Accelerometr undersampling mode
j3 14:646eb94fa2eb 314 AccBandWidthParam bwp; ///<Accelerometer bandwidth param
j3 16:12782f5d4aa4 315 AccOutputDataRate odr; ///<Accelerometr output data rate
j3 9:ca6b5fecdd63 316 };
j3 9:ca6b5fecdd63 317
j3 13:5d132f873b07 318 ///Accelerometer default configuration
j3 9:ca6b5fecdd63 319 static const AccConfig DEFAULT_ACC_CONFIG;
j3 12:64931a80340d 320 ///@}
j3 9:ca6b5fecdd63 321
j3 12:64931a80340d 322
j3 14:646eb94fa2eb 323 ///@name GYR_CONF(0x42) and GYR_RANGE(0x43)
j3 14:646eb94fa2eb 324 ///Data for configuring gyroscope
j3 14:646eb94fa2eb 325 ///@{
j3 16:12782f5d4aa4 326
j3 16:12782f5d4aa4 327 static const uint8_t GYRO_ODR_MASK = 0x0F;
j3 16:12782f5d4aa4 328 static const uint8_t GYRO_ODR_POS = 0x00;
j3 16:12782f5d4aa4 329 static const uint8_t GYRO_BWP_MASK = 0x30;
j3 16:12782f5d4aa4 330 static const uint8_t GYRO_BWP_POS = 0x04;
j3 16:12782f5d4aa4 331 static const uint8_t GYRO_RANGE_MASK = 0x07;
j3 16:12782f5d4aa4 332 static const uint8_t GYRO_RANGE_POS = 0x00;
j3 16:12782f5d4aa4 333
j3 16:12782f5d4aa4 334 ///Gyroscope output data rates
j3 16:12782f5d4aa4 335 enum GyroOutputDataRate
j3 16:12782f5d4aa4 336 {
j3 16:12782f5d4aa4 337 GYRO_ODR_6 = 0x06, ///<25Hz
j3 16:12782f5d4aa4 338 GYRO_ODR_7 = 0x07, ///<50Hz
j3 16:12782f5d4aa4 339 GYRO_ODR_8 = 0x08, ///<100Hz
j3 16:12782f5d4aa4 340 GYRO_ODR_9 = 0x09, ///<200Hz
j3 16:12782f5d4aa4 341 GYRO_ODR_10 = 0x0A, ///<400Hz
j3 16:12782f5d4aa4 342 GYRO_ODR_11 = 0x0B, ///<800Hz
j3 16:12782f5d4aa4 343 GYRO_ODR_12 = 0x0C, ///<1600Hz
j3 16:12782f5d4aa4 344 GYRO_ODR_13 = 0x0D ///<3200Hz
j3 16:12782f5d4aa4 345 };
j3 16:12782f5d4aa4 346
j3 16:12782f5d4aa4 347 ///Gyroscope bandwidth paramaters
j3 16:12782f5d4aa4 348 enum GyroBandWidthParam
j3 16:12782f5d4aa4 349 {
j3 16:12782f5d4aa4 350 GYRO_BWP_0 = 0, ///<OSR4 Over Sampling Rate of 4
j3 16:12782f5d4aa4 351 GYRO_BWP_1, ///<OSR2 Over Sampling Rate of 2
j3 16:12782f5d4aa4 352 GYRO_BWP_2 ///<Normal Mode, Equidistant Sampling
j3 16:12782f5d4aa4 353 };
j3 16:12782f5d4aa4 354
j3 16:12782f5d4aa4 355 ///Gyroscope ranges
j3 16:12782f5d4aa4 356 enum GyroRange
j3 16:12782f5d4aa4 357 {
j3 16:12782f5d4aa4 358 DPS_2000 = 0, ///<+-2000dps, 16.4LSB/dps
j3 16:12782f5d4aa4 359 DPS_1000, ///<+-1000dps, 32.8LSB/dps
j3 16:12782f5d4aa4 360 DPS_500, ///<+-500dps, 65.6LSB/dps
j3 16:12782f5d4aa4 361 DPS_250, ///<+-250dps, 131.2LSB/dps
j3 16:12782f5d4aa4 362 DPS_125 ///<+-125dps, 262.4LSB/dps,
j3 16:12782f5d4aa4 363 };
j3 16:12782f5d4aa4 364
j3 16:12782f5d4aa4 365 static const float SENS_2000_DPS_LSB_PER_DPS = 16.4F;
j3 16:12782f5d4aa4 366 static const float SENS_1000_DPS_LSB_PER_DPS = 32.8F;
j3 16:12782f5d4aa4 367 static const float SENS_500_DPS_LSB_PER_DPS = 65.6F;
j3 16:12782f5d4aa4 368 static const float SENS_250_DPS_LSB_PER_DPS = 131.2F;
j3 16:12782f5d4aa4 369 static const float SENS_125_DPS_LSB_PER_DPS = 262.4F;
j3 16:12782f5d4aa4 370
j3 16:12782f5d4aa4 371 ///Gyroscope configuration data structure
j3 16:12782f5d4aa4 372 struct GyroConfig
j3 16:12782f5d4aa4 373 {
j3 16:12782f5d4aa4 374 GyroRange range; ///<Gyroscope range
j3 16:12782f5d4aa4 375 GyroBandWidthParam bwp; ///<Gyroscope bandwidth param
j3 16:12782f5d4aa4 376 GyroOutputDataRate odr; ///<Gyroscope output data rate
j3 16:12782f5d4aa4 377 };
j3 16:12782f5d4aa4 378
j3 16:12782f5d4aa4 379 ///Gyroscope default configuration
j3 16:12782f5d4aa4 380 static const GyroConfig DEFAULT_GYRO_CONFIG;
j3 14:646eb94fa2eb 381 ///@}
j3 14:646eb94fa2eb 382
j3 14:646eb94fa2eb 383
j3 13:5d132f873b07 384 ///Enumerated power modes
j3 4:ebac8c8f6347 385 enum PowerModes
j3 4:ebac8c8f6347 386 {
j3 4:ebac8c8f6347 387 SUSPEND = 0, ///<Acc and Gyro, No sampling, No FIFO data readout
j3 4:ebac8c8f6347 388 NORMAL, ///<Acc and Gyro, Full chip operation
j3 4:ebac8c8f6347 389 LOW_POWER, ///<Acc duty-cycling between suspend and normal
j3 4:ebac8c8f6347 390 FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms
j3 4:ebac8c8f6347 391 };
j3 4:ebac8c8f6347 392
j3 12:64931a80340d 393
j3 13:5d132f873b07 394 ///Enumerated commands used with CMD register
j3 5:35e032c8d8aa 395 enum Commands
j3 5:35e032c8d8aa 396 {
j3 5:35e032c8d8aa 397 START_FOC = 0x03, ///<Starts Fast Offset Calibrartion
j3 7:9848196cb65e 398 ACC_SET_PMU_MODE = 0x10, ///<Sets acc power mode
j3 8:a89b529b1d96 399 GYR_SET_PMU_MODE = 0x14, ///<Sets gyro power mode
j3 8:a89b529b1d96 400 MAG_SET_PMU_MODE = 0x18, ///<Sets mag power mode
j3 5:35e032c8d8aa 401 PROG_NVM = 0xA0, ///<Writes NVM backed registers into NVM
j3 5:35e032c8d8aa 402 FIFO_FLUSH = 0xB0, ///<Clears FIFO
j3 5:35e032c8d8aa 403 INT_RESET, ///<Clears interrupt engine, INT_STATUS, and
j3 5:35e032c8d8aa 404 ///<the interrupt pin
j3 5:35e032c8d8aa 405 STEP_CNT_CLR, ///<Triggers reset of the step counter
j3 5:35e032c8d8aa 406 SOFT_RESET = 0xB6 ///<Triggers a reset including a reboot.
j3 5:35e032c8d8aa 407 };
j3 5:35e032c8d8aa 408
j3 0:bb5b832891fb 409
j3 0:bb5b832891fb 410 ///@brief BMI160 Destructor.\n
j3 0:bb5b832891fb 411 ///
j3 0:bb5b832891fb 412 ///On Entry:
j3 0:bb5b832891fb 413 ///@param[in] none
j3 0:bb5b832891fb 414 ///
j3 0:bb5b832891fb 415 ///On Exit:
j3 0:bb5b832891fb 416 ///@param[out] none
j3 0:bb5b832891fb 417 ///
j3 0:bb5b832891fb 418 ///@returns none
j3 2:598e601e5846 419 virtual ~BMI160(){ }
j3 0:bb5b832891fb 420
j3 0:bb5b832891fb 421
j3 0:bb5b832891fb 422 ///@brief Reads a single register.\n
j3 0:bb5b832891fb 423 ///
j3 0:bb5b832891fb 424 ///On Entry:
j3 0:bb5b832891fb 425 ///@param[in] data - pointer to memory for storing read data
j3 0:bb5b832891fb 426 ///
j3 0:bb5b832891fb 427 ///On Exit:
j3 0:bb5b832891fb 428 ///@param[out] data - holds contents of read register on success
j3 0:bb5b832891fb 429 ///
j3 0:bb5b832891fb 430 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 431 virtual int32_t readRegister(Registers reg, uint8_t *data) = 0;
j3 0:bb5b832891fb 432
j3 0:bb5b832891fb 433
j3 0:bb5b832891fb 434 ///@brief Writes a single register.\n
j3 0:bb5b832891fb 435 ///
j3 0:bb5b832891fb 436 ///On Entry:
j3 0:bb5b832891fb 437 ///@param[in] data - data to write to register
j3 0:bb5b832891fb 438 ///
j3 0:bb5b832891fb 439 ///On Exit:
j3 0:bb5b832891fb 440 ///@param[out] none
j3 0:bb5b832891fb 441 ///
j3 0:bb5b832891fb 442 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 443 virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0;
j3 0:bb5b832891fb 444
j3 0:bb5b832891fb 445
j3 0:bb5b832891fb 446 ///@brief Reads a block of registers.\n
j3 0:bb5b832891fb 447 ///@detail User must ensure that all registers between 'startReg' and
j3 0:bb5b832891fb 448 ///'stopReg' exist and are readable. Function reads up to, including,
j3 0:bb5b832891fb 449 ///'stopReg'.\n
j3 0:bb5b832891fb 450 ///
j3 0:bb5b832891fb 451 ///On Entry:
j3 0:bb5b832891fb 452 ///@param[in] startReg - register to start reading from
j3 0:bb5b832891fb 453 ///@param[in] stopReg - register to stop reading from
j3 0:bb5b832891fb 454 ///@param[in] data - pointer to memory for storing read data
j3 0:bb5b832891fb 455 ///
j3 0:bb5b832891fb 456 ///On Exit:
j3 0:bb5b832891fb 457 ///@param[out] data - holds contents of read registers on success
j3 0:bb5b832891fb 458 ///
j3 0:bb5b832891fb 459 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 460 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 461 uint8_t *data) = 0;
j3 0:bb5b832891fb 462
j3 0:bb5b832891fb 463
j3 0:bb5b832891fb 464 ///@brief Writes a block of registers.\n
j3 0:bb5b832891fb 465 ///@detail User must ensure that all registers between 'startReg' and
j3 0:bb5b832891fb 466 ///'stopReg' exist and are writeable. Function writes up to, including,
j3 0:bb5b832891fb 467 ///'stopReg'.\n
j3 0:bb5b832891fb 468 ///
j3 0:bb5b832891fb 469 ///On Entry:
j3 0:bb5b832891fb 470 ///@param[in] startReg - register to start writing at
j3 0:bb5b832891fb 471 ///@param[in] stopReg - register to stop writing at
j3 0:bb5b832891fb 472 ///@param[in] data - pointer to data to write to registers
j3 0:bb5b832891fb 473 ///
j3 0:bb5b832891fb 474 ///On Exit:
j3 0:bb5b832891fb 475 ///@param[out] none
j3 0:bb5b832891fb 476 ///
j3 0:bb5b832891fb 477 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 478 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 479 const uint8_t *data) = 0;
j3 3:e1770675eca4 480
j3 3:e1770675eca4 481
j3 5:35e032c8d8aa 482 ///@brief Sets sensors power mode through CMD register.\n
j3 5:35e032c8d8aa 483 ///@details Observe command execution times given in datasheet.\n
j3 5:35e032c8d8aa 484 ///
j3 5:35e032c8d8aa 485 ///On Entry:
j3 5:35e032c8d8aa 486 ///@param[in] sensor - Sensor which power mode we are setting
j3 5:35e032c8d8aa 487 ///@param[in] pwrMode - Desired powermode of the sensor
j3 5:35e032c8d8aa 488 ///
j3 5:35e032c8d8aa 489 ///On Exit:
j3 5:35e032c8d8aa 490 ///@param[out]
j3 5:35e032c8d8aa 491 ///
j3 5:35e032c8d8aa 492 ///@returns 0 on success, non 0 on failure
j3 5:35e032c8d8aa 493 int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode);
j3 5:35e032c8d8aa 494
j3 5:35e032c8d8aa 495
j3 16:12782f5d4aa4 496 ///@brief Configure sensor.\n
j3 3:e1770675eca4 497 ///
j3 3:e1770675eca4 498 ///On Entry:
j3 16:12782f5d4aa4 499 ///@param[in] config - sSensor configuration data structure
j3 3:e1770675eca4 500 ///
j3 3:e1770675eca4 501 ///On Exit:
j3 12:64931a80340d 502 ///@param[out] none
j3 3:e1770675eca4 503 ///
j3 3:e1770675eca4 504 ///@returns 0 on success, non 0 on failure
j3 16:12782f5d4aa4 505 int32_t setSensorConfig(const AccConfig &config);
j3 16:12782f5d4aa4 506 int32_t setSensorConfig(const GyroConfig &config);
j3 8:a89b529b1d96 507
j3 8:a89b529b1d96 508
j3 16:12782f5d4aa4 509 ///@brief Get sensor configuration.\n
j3 14:646eb94fa2eb 510 ///
j3 14:646eb94fa2eb 511 ///On Entry:
j3 16:12782f5d4aa4 512 ///@param[in] config - Sensor configuration data structure
j3 14:646eb94fa2eb 513 ///
j3 14:646eb94fa2eb 514 ///On Exit:
j3 16:12782f5d4aa4 515 ///@param[out] config - on success, holds sensor's current
j3 14:646eb94fa2eb 516 ///configuration
j3 14:646eb94fa2eb 517 ///
j3 14:646eb94fa2eb 518 ///@returns 0 on success, non 0 on failure
j3 16:12782f5d4aa4 519 int32_t getSensorConfig(AccConfig &config);
j3 16:12782f5d4aa4 520 int32_t getSensorConfig(GyroConfig &config);
j3 14:646eb94fa2eb 521
j3 14:646eb94fa2eb 522
j3 16:12782f5d4aa4 523 ///@brief Get sensor axis.\n
j3 3:e1770675eca4 524 ///
j3 3:e1770675eca4 525 ///On Entry:
j3 8:a89b529b1d96 526 ///@param[in] axis - Sensor axis
j3 8:a89b529b1d96 527 ///@param[in] data - AxisData structure
j3 16:12782f5d4aa4 528 ///@param[in] range - Sensor range
j3 8:a89b529b1d96 529 ///
j3 8:a89b529b1d96 530 ///On Exit:
j3 8:a89b529b1d96 531 ///@param[out] data - Structure holds raw and scaled axis data
j3 8:a89b529b1d96 532 ///
j3 8:a89b529b1d96 533 ///@returns 0 on success, non 0 on failure
j3 16:12782f5d4aa4 534 int32_t getSensorAxis(SensorAxis axis, AxisData &data, AccRange range);
j3 16:12782f5d4aa4 535 int32_t getSensorAxis(SensorAxis axis, AxisData &data, GyroRange range);
j3 8:a89b529b1d96 536
j3 8:a89b529b1d96 537
j3 16:12782f5d4aa4 538 ///@brief Get sensor xyz axis.\n
j3 8:a89b529b1d96 539 ///
j3 8:a89b529b1d96 540 ///On Entry:
j3 8:a89b529b1d96 541 ///@param[in] data - SensorData structure
j3 16:12782f5d4aa4 542 ///@param[in] range - Sensor range
j3 3:e1770675eca4 543 ///
j3 3:e1770675eca4 544 ///On Exit:
j3 8:a89b529b1d96 545 ///@param[out] data - Structure holds raw and scaled data for all three axis
j3 3:e1770675eca4 546 ///
j3 8:a89b529b1d96 547 ///@returns 0 on success, non 0 on failure
j3 16:12782f5d4aa4 548 int32_t getSensorXYZ(SensorData &data, AccRange range);
j3 16:12782f5d4aa4 549 int32_t getSensorXYZ(SensorData &data, GyroRange range);
j3 15:dc35ccc0b08e 550
j3 15:dc35ccc0b08e 551
j3 16:12782f5d4aa4 552 ///@brief Get sensor xyz axis and sensor time.\n
j3 15:dc35ccc0b08e 553 ///
j3 15:dc35ccc0b08e 554 ///On Entry:
j3 15:dc35ccc0b08e 555 ///@param[in] data - SensorData structure
j3 15:dc35ccc0b08e 556 ///@param[in] sensorTime - SensorTime structure for data
j3 16:12782f5d4aa4 557 ///@param[in] range - Sensor range
j3 15:dc35ccc0b08e 558 ///
j3 15:dc35ccc0b08e 559 ///On Exit:
j3 15:dc35ccc0b08e 560 ///@param[out] data - Structure holds raw and scaled data for all three axis
j3 15:dc35ccc0b08e 561 ///@param[out] sensorTime - Holds sensor time on success
j3 15:dc35ccc0b08e 562 ///
j3 15:dc35ccc0b08e 563 ///@returns 0 on success, non 0 on failure
j3 16:12782f5d4aa4 564 int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime,
j3 16:12782f5d4aa4 565 AccRange range);
j3 16:12782f5d4aa4 566 int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime,
j3 16:12782f5d4aa4 567 GyroRange range);
j3 16:12782f5d4aa4 568
j3 16:12782f5d4aa4 569
j3 16:12782f5d4aa4 570 ///@brief Get Gyroscope/Accelerometer data and sensor time.\n
j3 16:12782f5d4aa4 571 ///
j3 16:12782f5d4aa4 572 ///On Entry:
j3 16:12782f5d4aa4 573 ///@param[in] accData - Sensor data structure for accelerometer
j3 16:12782f5d4aa4 574 ///@param[in] gyroData - Sensor data structure for gyroscope
j3 16:12782f5d4aa4 575 ///@param[in] sensorTime - SensorTime data structure
j3 16:12782f5d4aa4 576 ///@param[in] accRange - Accelerometer range
j3 16:12782f5d4aa4 577 ///@param[in] gyroRange - Gyroscope range
j3 16:12782f5d4aa4 578 ///
j3 16:12782f5d4aa4 579 ///On Exit:
j3 16:12782f5d4aa4 580 ///@param[out] accData - Synchronized accelerometer data
j3 16:12782f5d4aa4 581 ///@param[out] gyroData - Synchronized gyroscope data
j3 16:12782f5d4aa4 582 ///@param[out] sensorTime - Synchronized sensor time
j3 16:12782f5d4aa4 583 ///
j3 16:12782f5d4aa4 584 ///@returns 0 on success, non 0 on failure
j3 16:12782f5d4aa4 585 int32_t getGyroAccXYZandSensorTime(SensorData &accData,
j3 16:12782f5d4aa4 586 SensorData &gyroData,
j3 16:12782f5d4aa4 587 SensorTime &sensorTime,
j3 16:12782f5d4aa4 588 AccRange accRange, GyroRange gyroRange);
j3 10:9e219f2f1fb3 589
j3 10:9e219f2f1fb3 590
j3 10:9e219f2f1fb3 591 ///@brief Get sensor time.\n
j3 10:9e219f2f1fb3 592 ///
j3 10:9e219f2f1fb3 593 ///On Entry:
j3 15:dc35ccc0b08e 594 ///@param[in] sensorTime - SensorTime structure for data
j3 10:9e219f2f1fb3 595 ///
j3 10:9e219f2f1fb3 596 ///On Exit:
j3 15:dc35ccc0b08e 597 ///@param[out] sensorTime - Holds sensor time on success
j3 10:9e219f2f1fb3 598 ///
j3 10:9e219f2f1fb3 599 ///@returns returns 0 on success, non 0 on failure
j3 15:dc35ccc0b08e 600 int32_t getSensorTime(SensorTime &sensorTime);
j3 12:64931a80340d 601
j3 12:64931a80340d 602
j3 12:64931a80340d 603 ///@brief Get die temperature.\n
j3 12:64931a80340d 604 ///
j3 12:64931a80340d 605 ///On Entry:
j3 12:64931a80340d 606 ///@param[in] temp - pointer to float for temperature
j3 12:64931a80340d 607 ///
j3 12:64931a80340d 608 ///On Exit:
j3 12:64931a80340d 609 ///@param[out] temp - on success, holds the die temperature
j3 12:64931a80340d 610 ///
j3 12:64931a80340d 611 ///@returns 0 on success, non 0 on failure
j3 12:64931a80340d 612 int32_t getTemperature(float *temp);
j3 2:598e601e5846 613 };
j3 2:598e601e5846 614
j3 2:598e601e5846 615
j3 2:598e601e5846 616 /**
j3 2:598e601e5846 617 @brief BMI160_I2C - supports BMI160 object with I2C interface
j3 2:598e601e5846 618 */
j3 2:598e601e5846 619 class BMI160_I2C: public BMI160
j3 2:598e601e5846 620 {
j3 2:598e601e5846 621 public:
j3 2:598e601e5846 622
j3 2:598e601e5846 623 ///BMI160 default I2C address.
j3 2:598e601e5846 624 static const uint8_t I2C_ADRS_SDO_LO = 0x68;
j3 2:598e601e5846 625 ///BMI160 optional I2C address.
j3 2:598e601e5846 626 static const uint8_t I2C_ADRS_SDO_HI = 0x69;
j3 0:bb5b832891fb 627
j3 2:598e601e5846 628
j3 2:598e601e5846 629 ///@brief BMI160_I2C Constructor.\n
j3 0:bb5b832891fb 630 ///
j3 0:bb5b832891fb 631 ///On Entry:
j3 2:598e601e5846 632 ///@param[in] i2cBus - reference to I2C bus for this device
j3 2:598e601e5846 633 ///@param[in] i2cAdrs - 7-bit I2C address
j3 0:bb5b832891fb 634 ///
j3 0:bb5b832891fb 635 ///On Exit:
j3 0:bb5b832891fb 636 ///@param[out] none
j3 0:bb5b832891fb 637 ///
j3 0:bb5b832891fb 638 ///@returns none
j3 2:598e601e5846 639 BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs);
j3 2:598e601e5846 640
j3 2:598e601e5846 641
j3 17:0ae99e97bcf5 642 ///@brief Reads a single register.\n
j3 17:0ae99e97bcf5 643 ///
j3 17:0ae99e97bcf5 644 ///On Entry:
j3 17:0ae99e97bcf5 645 ///@param[in] data - pointer to memory for storing read data
j3 17:0ae99e97bcf5 646 ///
j3 17:0ae99e97bcf5 647 ///On Exit:
j3 17:0ae99e97bcf5 648 ///@param[out] data - holds contents of read register on success
j3 17:0ae99e97bcf5 649 ///
j3 17:0ae99e97bcf5 650 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 651 virtual int32_t readRegister(Registers reg, uint8_t *data);
j3 17:0ae99e97bcf5 652
j3 17:0ae99e97bcf5 653
j3 17:0ae99e97bcf5 654 ///@brief Writes a single register.\n
j3 17:0ae99e97bcf5 655 ///
j3 17:0ae99e97bcf5 656 ///On Entry:
j3 17:0ae99e97bcf5 657 ///@param[in] data - data to write to register
j3 17:0ae99e97bcf5 658 ///
j3 17:0ae99e97bcf5 659 ///On Exit:
j3 17:0ae99e97bcf5 660 ///@param[out] none
j3 17:0ae99e97bcf5 661 ///
j3 17:0ae99e97bcf5 662 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 663 virtual int32_t writeRegister(Registers reg, const uint8_t data);
j3 17:0ae99e97bcf5 664
j3 17:0ae99e97bcf5 665
j3 17:0ae99e97bcf5 666 ///@brief Reads a block of registers.\n
j3 17:0ae99e97bcf5 667 ///@detail User must ensure that all registers between 'startReg' and
j3 17:0ae99e97bcf5 668 ///'stopReg' exist and are readable. Function reads up to, including,
j3 17:0ae99e97bcf5 669 ///'stopReg'.\n
j3 17:0ae99e97bcf5 670 ///
j3 17:0ae99e97bcf5 671 ///On Entry:
j3 17:0ae99e97bcf5 672 ///@param[in] startReg - register to start reading from
j3 17:0ae99e97bcf5 673 ///@param[in] stopReg - register to stop reading from
j3 17:0ae99e97bcf5 674 ///@param[in] data - pointer to memory for storing read data
j3 17:0ae99e97bcf5 675 ///
j3 17:0ae99e97bcf5 676 ///On Exit:
j3 17:0ae99e97bcf5 677 ///@param[out] data - holds contents of read registers on success
j3 17:0ae99e97bcf5 678 ///
j3 17:0ae99e97bcf5 679 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 680 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 681 uint8_t *data);
j3 17:0ae99e97bcf5 682
j3 17:0ae99e97bcf5 683
j3 17:0ae99e97bcf5 684 ///@brief Writes a block of registers.\n
j3 17:0ae99e97bcf5 685 ///@detail User must ensure that all registers between 'startReg' and
j3 17:0ae99e97bcf5 686 ///'stopReg' exist and are writeable. Function writes up to, including,
j3 17:0ae99e97bcf5 687 ///'stopReg'.\n
j3 17:0ae99e97bcf5 688 ///
j3 17:0ae99e97bcf5 689 ///On Entry:
j3 17:0ae99e97bcf5 690 ///@param[in] startReg - register to start writing at
j3 17:0ae99e97bcf5 691 ///@param[in] stopReg - register to stop writing at
j3 17:0ae99e97bcf5 692 ///@param[in] data - pointer to data to write to registers
j3 17:0ae99e97bcf5 693 ///
j3 17:0ae99e97bcf5 694 ///On Exit:
j3 17:0ae99e97bcf5 695 ///@param[out] none
j3 17:0ae99e97bcf5 696 ///
j3 17:0ae99e97bcf5 697 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 698 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 699 const uint8_t *data);
j3 2:598e601e5846 700
j3 0:bb5b832891fb 701 private:
j3 0:bb5b832891fb 702
j3 0:bb5b832891fb 703 I2C m_i2cBus;
j3 0:bb5b832891fb 704 uint8_t m_Wadrs, m_Radrs;
j3 0:bb5b832891fb 705 };
j3 0:bb5b832891fb 706
j3 2:598e601e5846 707
j3 2:598e601e5846 708 /**
j3 2:598e601e5846 709 @brief BMI160_SPI - supports BMI160 object with SPI interface
j3 2:598e601e5846 710 */
j3 2:598e601e5846 711 class BMI160_SPI: public BMI160
j3 2:598e601e5846 712 {
j3 2:598e601e5846 713 public:
j3 2:598e601e5846 714
j3 2:598e601e5846 715 ///@brief BMI160_SPI Constructor.\n
j3 2:598e601e5846 716 ///
j3 2:598e601e5846 717 ///On Entry:
j3 2:598e601e5846 718 ///@param[in] spiBus - reference to SPI bus for this device
j3 2:598e601e5846 719 ///@param[in] cs - reference to DigitalOut used for chip select
j3 2:598e601e5846 720 ///
j3 2:598e601e5846 721 ///On Exit:
j3 2:598e601e5846 722 ///@param[out] none
j3 2:598e601e5846 723 ///
j3 2:598e601e5846 724 ///@returns none
j3 2:598e601e5846 725 BMI160_SPI(SPI &spiBus, DigitalOut &cs);
j3 2:598e601e5846 726
j3 17:0ae99e97bcf5 727
j3 17:0ae99e97bcf5 728 ///@brief Reads a single register.\n
j3 17:0ae99e97bcf5 729 ///
j3 17:0ae99e97bcf5 730 ///On Entry:
j3 17:0ae99e97bcf5 731 ///@param[in] data - pointer to memory for storing read data
j3 17:0ae99e97bcf5 732 ///
j3 17:0ae99e97bcf5 733 ///On Exit:
j3 17:0ae99e97bcf5 734 ///@param[out] data - holds contents of read register on success
j3 17:0ae99e97bcf5 735 ///
j3 17:0ae99e97bcf5 736 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 737 virtual int32_t readRegister(Registers reg, uint8_t *data);
j3 17:0ae99e97bcf5 738
j3 17:0ae99e97bcf5 739
j3 17:0ae99e97bcf5 740 ///@brief Writes a single register.\n
j3 17:0ae99e97bcf5 741 ///
j3 17:0ae99e97bcf5 742 ///On Entry:
j3 17:0ae99e97bcf5 743 ///@param[in] data - data to write to register
j3 17:0ae99e97bcf5 744 ///
j3 17:0ae99e97bcf5 745 ///On Exit:
j3 17:0ae99e97bcf5 746 ///@param[out] none
j3 17:0ae99e97bcf5 747 ///
j3 17:0ae99e97bcf5 748 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 749 virtual int32_t writeRegister(Registers reg, const uint8_t data);
j3 17:0ae99e97bcf5 750
j3 17:0ae99e97bcf5 751
j3 17:0ae99e97bcf5 752 ///@brief Reads a block of registers.\n
j3 17:0ae99e97bcf5 753 ///@detail User must ensure that all registers between 'startReg' and
j3 17:0ae99e97bcf5 754 ///'stopReg' exist and are readable. Function reads up to, including,
j3 17:0ae99e97bcf5 755 ///'stopReg'.\n
j3 17:0ae99e97bcf5 756 ///
j3 17:0ae99e97bcf5 757 ///On Entry:
j3 17:0ae99e97bcf5 758 ///@param[in] startReg - register to start reading from
j3 17:0ae99e97bcf5 759 ///@param[in] stopReg - register to stop reading from
j3 17:0ae99e97bcf5 760 ///@param[in] data - pointer to memory for storing read data
j3 17:0ae99e97bcf5 761 ///
j3 17:0ae99e97bcf5 762 ///On Exit:
j3 17:0ae99e97bcf5 763 ///@param[out] data - holds contents of read registers on success
j3 17:0ae99e97bcf5 764 ///
j3 17:0ae99e97bcf5 765 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 766 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 767 uint8_t *data);
j3 17:0ae99e97bcf5 768
j3 17:0ae99e97bcf5 769
j3 17:0ae99e97bcf5 770 ///@brief Writes a block of registers.\n
j3 17:0ae99e97bcf5 771 ///@detail User must ensure that all registers between 'startReg' and
j3 17:0ae99e97bcf5 772 ///'stopReg' exist and are writeable. Function writes up to, including,
j3 17:0ae99e97bcf5 773 ///'stopReg'.\n
j3 17:0ae99e97bcf5 774 ///
j3 17:0ae99e97bcf5 775 ///On Entry:
j3 17:0ae99e97bcf5 776 ///@param[in] startReg - register to start writing at
j3 17:0ae99e97bcf5 777 ///@param[in] stopReg - register to stop writing at
j3 17:0ae99e97bcf5 778 ///@param[in] data - pointer to data to write to registers
j3 17:0ae99e97bcf5 779 ///
j3 17:0ae99e97bcf5 780 ///On Exit:
j3 17:0ae99e97bcf5 781 ///@param[out] none
j3 17:0ae99e97bcf5 782 ///
j3 17:0ae99e97bcf5 783 ///@returns 0 on success, non 0 on failure
j3 3:e1770675eca4 784 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 785 const uint8_t *data);
j3 2:598e601e5846 786
j3 2:598e601e5846 787 private:
j3 2:598e601e5846 788
j3 2:598e601e5846 789 SPI m_spiBus;
j3 2:598e601e5846 790 DigitalOut m_cs;
j3 2:598e601e5846 791 };
j3 2:598e601e5846 792
j3 0:bb5b832891fb 793 #endif /* BMI160_H */
j3 8:a89b529b1d96 794
j3 8:a89b529b1d96 795
j3 8:a89b529b1d96 796 ///@brief fx documentation template.\n
j3 8:a89b529b1d96 797 ///
j3 8:a89b529b1d96 798 ///On Entry:
j3 8:a89b529b1d96 799 ///@param[in] none
j3 8:a89b529b1d96 800 ///
j3 8:a89b529b1d96 801 ///On Exit:
j3 8:a89b529b1d96 802 ///@param[out] none
j3 8:a89b529b1d96 803 ///
j3 8:a89b529b1d96 804 ///@returns none