BMI160 Initial

Dependents:   MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_Pitch_Charles Maxim_Squeeks

Committer:
CharlesMaxim
Date:
Tue Dec 04 09:50:52 2018 +0000
Revision:
21:0b28b9d13164
Parent:
20:a521606048bb
Initial Release for BMI160

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