First Commit as a new library

Dependents:   Host_Software_MAX32664GWEB_HR_wrist Host_Software_MAX32664GWEC_SpO2_HR Host_Software_MAX32664GWEB_HR_EXTENDED Host_Software_MAX32664GWEC_SpO2_HR-_EXTE ... more

Committer:
seyhmuscacina
Date:
Wed Dec 19 14:54:05 2018 +0300
Revision:
21:f7216b5dc6c0
Parent:
20:a521606048bb
adds interrupt support to the BMI160 library

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
Emre.Eken 20:a521606048bb 45 current consumption is typically 950 μA, enabling always-on applications in
Emre.Eken 20:a521606048bb 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
seyhmuscacina 21:f7216b5dc6c0 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;
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 79 float scaled; ///<Axis scaled data
j3 8:a89b529b1d96 80 };
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 88
seyhmuscacina 21:f7216b5dc6c0 89 ///Period of internal counter
seyhmuscacina 21:f7216b5dc6c0 90 static const float SENSOR_TIME_LSB = 39e-6;
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 99
seyhmuscacina 21:f7216b5dc6c0 100
j3 1:a4c911640569 101 ///BMI160 registers
j3 0:bb5b832891fb 102 enum Registers
j3 0:bb5b832891fb 103 {
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 159 INT_LATCH, ///<Contains the interrupt rest bit and the interrupt
j3 3:e1770675eca4 160 ///<mode selection
seyhmuscacina 21:f7216b5dc6c0 161 INT_MAP_0, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 162 ///<INT1 and INT2 pins
seyhmuscacina 21:f7216b5dc6c0 163 INT_MAP_1, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 164 ///<INT1 and INT2 pins
seyhmuscacina 21:f7216b5dc6c0 165 INT_MAP_2, ///<Controls which interrupt signals are mapped to the
j3 3:e1770675eca4 166 ///<INT1 and INT2 pins
seyhmuscacina 21:f7216b5dc6c0 167 INT_DATA_0, ///<Contains the data source definition for the two
j3 3:e1770675eca4 168 ///<interrupt groups
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 176 INT_MOTION_0, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 177 ///<no motion interrupts
seyhmuscacina 21:f7216b5dc6c0 178 INT_MOTION_1, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 179 ///<no motion interrupts
seyhmuscacina 21:f7216b5dc6c0 180 INT_MOTION_2, ///<Contains the configuration for the any motion and
j3 3:e1770675eca4 181 ///<no motion interrupts
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 186 INT_ORIENT_0, ///<Contains the configuration for the oeientation
j3 3:e1770675eca4 187 ///<interrupt
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 210 CMD = 0x7E ///<Command register triggers operations like
j3 3:e1770675eca4 211 ///<softreset, NVM programming, etc.
j3 3:e1770675eca4 212 };
seyhmuscacina 21:f7216b5dc6c0 213
seyhmuscacina 21:f7216b5dc6c0 214
j3 13:5d132f873b07 215 ///@name ERR_REG(0x02)
j3 13:5d132f873b07 216 ///Error register data
j3 12:64931a80340d 217 ///@{
seyhmuscacina 21:f7216b5dc6c0 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;
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 234 ERROR_1, ///<Listed as error
j3 3:e1770675eca4 235 ERROR_2, ///<Listed as error
seyhmuscacina 21:f7216b5dc6c0 236 LPM_INT_PFD, ///<Low-power mode and interrupt uses pre-filtered
j3 3:e1770675eca4 237 ///<data
seyhmuscacina 21:f7216b5dc6c0 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 ///@}
seyhmuscacina 21:f7216b5dc6c0 243
seyhmuscacina 21:f7216b5dc6c0 244
seyhmuscacina 21:f7216b5dc6c0 245 ///@name ACC_CONF(0x40) and ACC_RANGE(0x41)
j3 13:5d132f873b07 246 ///Data for configuring accelerometer
j3 12:64931a80340d 247 ///@{
seyhmuscacina 21:f7216b5dc6c0 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;
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 303
seyhmuscacina 21:f7216b5dc6c0 304 static const float SENS_2G_LSB_PER_G = 16384.0F;
seyhmuscacina 21:f7216b5dc6c0 305 static const float SENS_4G_LSB_PER_G = 8192.0F;
seyhmuscacina 21:f7216b5dc6c0 306 static const float SENS_8G_LSB_PER_G = 4096.0F;
seyhmuscacina 21:f7216b5dc6c0 307 static const float SENS_16G_LSB_PER_G = 2048.0F;
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 317
j3 13:5d132f873b07 318 ///Accelerometer default configuration
j3 9:ca6b5fecdd63 319 static const AccConfig DEFAULT_ACC_CONFIG;
j3 12:64931a80340d 320 ///@}
seyhmuscacina 21:f7216b5dc6c0 321
seyhmuscacina 21:f7216b5dc6c0 322
seyhmuscacina 21:f7216b5dc6c0 323 ///@name GYR_CONF(0x42) and GYR_RANGE(0x43)
j3 14:646eb94fa2eb 324 ///Data for configuring gyroscope
j3 14:646eb94fa2eb 325 ///@{
seyhmuscacina 21:f7216b5dc6c0 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;
seyhmuscacina 21:f7216b5dc6c0 333
j3 16:12782f5d4aa4 334 ///Gyroscope output data rates
j3 16:12782f5d4aa4 335 enum GyroOutputDataRate
j3 16:12782f5d4aa4 336 {
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 362 DPS_125 ///<+-125dps, 262.4LSB/dps,
j3 16:12782f5d4aa4 363 };
seyhmuscacina 21:f7216b5dc6c0 364
seyhmuscacina 21:f7216b5dc6c0 365 static const float SENS_2000_DPS_LSB_PER_DPS = 16.4F;
seyhmuscacina 21:f7216b5dc6c0 366 static const float SENS_1000_DPS_LSB_PER_DPS = 32.8F;
seyhmuscacina 21:f7216b5dc6c0 367 static const float SENS_500_DPS_LSB_PER_DPS = 65.6F;
seyhmuscacina 21:f7216b5dc6c0 368 static const float SENS_250_DPS_LSB_PER_DPS = 131.2F;
seyhmuscacina 21:f7216b5dc6c0 369 static const float SENS_125_DPS_LSB_PER_DPS = 262.4F;
seyhmuscacina 21:f7216b5dc6c0 370
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 378
j3 16:12782f5d4aa4 379 ///Gyroscope default configuration
j3 16:12782f5d4aa4 380 static const GyroConfig DEFAULT_GYRO_CONFIG;
j3 14:646eb94fa2eb 381 ///@}
seyhmuscacina 21:f7216b5dc6c0 382
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 392
seyhmuscacina 21:f7216b5dc6c0 393
j3 13:5d132f873b07 394 ///Enumerated commands used with CMD register
j3 5:35e032c8d8aa 395 enum Commands
j3 5:35e032c8d8aa 396 {
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 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 };
seyhmuscacina 21:f7216b5dc6c0 408
seyhmuscacina 21:f7216b5dc6c0 409
j3 0:bb5b832891fb 410 ///@brief BMI160 Destructor.\n
j3 0:bb5b832891fb 411 ///
j3 0:bb5b832891fb 412 ///On Entry:
seyhmuscacina 21:f7216b5dc6c0 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(){ }
seyhmuscacina 21:f7216b5dc6c0 420
seyhmuscacina 21:f7216b5dc6c0 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;
seyhmuscacina 21:f7216b5dc6c0 432
seyhmuscacina 21:f7216b5dc6c0 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;
seyhmuscacina 21:f7216b5dc6c0 444
seyhmuscacina 21:f7216b5dc6c0 445
j3 0:bb5b832891fb 446 ///@brief Reads a block of registers.\n
seyhmuscacina 21:f7216b5dc6c0 447 ///@detail User must ensure that all registers between 'startReg' and
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 460 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 461 uint8_t *data) = 0;
seyhmuscacina 21:f7216b5dc6c0 462
seyhmuscacina 21:f7216b5dc6c0 463
j3 0:bb5b832891fb 464 ///@brief Writes a block of registers.\n
seyhmuscacina 21:f7216b5dc6c0 465 ///@detail User must ensure that all registers between 'startReg' and
seyhmuscacina 21:f7216b5dc6c0 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:
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 478 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 479 const uint8_t *data) = 0;
seyhmuscacina 21:f7216b5dc6c0 480
seyhmuscacina 21:f7216b5dc6c0 481
j3 5:35e032c8d8aa 482 ///@brief Sets sensors power mode through CMD register.\n
seyhmuscacina 21:f7216b5dc6c0 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:
seyhmuscacina 21:f7216b5dc6c0 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);
seyhmuscacina 21:f7216b5dc6c0 494
seyhmuscacina 21:f7216b5dc6c0 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);
seyhmuscacina 21:f7216b5dc6c0 507
seyhmuscacina 21:f7216b5dc6c0 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:
seyhmuscacina 21:f7216b5dc6c0 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);
seyhmuscacina 21:f7216b5dc6c0 521
seyhmuscacina 21:f7216b5dc6c0 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);
seyhmuscacina 21:f7216b5dc6c0 536
seyhmuscacina 21:f7216b5dc6c0 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);
seyhmuscacina 21:f7216b5dc6c0 550
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 564 int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime,
j3 16:12782f5d4aa4 565 AccRange range);
seyhmuscacina 21:f7216b5dc6c0 566 int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime,
j3 16:12782f5d4aa4 567 GyroRange range);
seyhmuscacina 21:f7216b5dc6c0 568
seyhmuscacina 21:f7216b5dc6c0 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
seyhmuscacina 21:f7216b5dc6c0 585 int32_t getGyroAccXYZandSensorTime(SensorData &accData,
seyhmuscacina 21:f7216b5dc6c0 586 SensorData &gyroData,
seyhmuscacina 21:f7216b5dc6c0 587 SensorTime &sensorTime,
j3 16:12782f5d4aa4 588 AccRange accRange, GyroRange gyroRange);
seyhmuscacina 21:f7216b5dc6c0 589
seyhmuscacina 21:f7216b5dc6c0 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);
seyhmuscacina 21:f7216b5dc6c0 601
seyhmuscacina 21:f7216b5dc6c0 602
j3 12:64931a80340d 603 ///@brief Get die temperature.\n
j3 12:64931a80340d 604 ///
j3 12:64931a80340d 605 ///On Entry:
seyhmuscacina 21:f7216b5dc6c0 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);
seyhmuscacina 21:f7216b5dc6c0 613
seyhmuscacina 21:f7216b5dc6c0 614 // Initialize BMI160 with default parameters:
seyhmuscacina 21:f7216b5dc6c0 615 // set GYRO: Suspended, Acc Normal Mode, ODR:25 Hz
seyhmuscacina 21:f7216b5dc6c0 616 int32_t BMI160_DefaultInitalize();
seyhmuscacina 21:f7216b5dc6c0 617
seyhmuscacina 21:f7216b5dc6c0 618 //
seyhmuscacina 21:f7216b5dc6c0 619 //
seyhmuscacina 21:f7216b5dc6c0 620 int32_t enable_data_ready_interrupt();
seyhmuscacina 21:f7216b5dc6c0 621
seyhmuscacina 21:f7216b5dc6c0 622 //
seyhmuscacina 21:f7216b5dc6c0 623 // Set sample rate
seyhmuscacina 21:f7216b5dc6c0 624 // This function can be alled after BMI160_DefaultInitalize
seyhmuscacina 21:f7216b5dc6c0 625 int32_t setSampleRate(int sample_rate);
seyhmuscacina 21:f7216b5dc6c0 626
seyhmuscacina 21:f7216b5dc6c0 627 /// @brief Soft reset
seyhmuscacina 21:f7216b5dc6c0 628 ///
seyhmuscacina 21:f7216b5dc6c0 629 int32_t reset();
seyhmuscacina 21:f7216b5dc6c0 630
seyhmuscacina 21:f7216b5dc6c0 631 private:
seyhmuscacina 21:f7216b5dc6c0 632 bool m_use_irq;
seyhmuscacina 21:f7216b5dc6c0 633 bool bmi160_irq_asserted;
seyhmuscacina 21:f7216b5dc6c0 634 InterruptIn *m_bmi160_irq;
seyhmuscacina 21:f7216b5dc6c0 635 void irq_handler();
seyhmuscacina 21:f7216b5dc6c0 636
seyhmuscacina 21:f7216b5dc6c0 637 protected:
seyhmuscacina 21:f7216b5dc6c0 638 BMI160(InterruptIn *int_pin): m_bmi160_irq(int_pin), m_use_irq(true) {
seyhmuscacina 21:f7216b5dc6c0 639 bmi160_irq_asserted = false;
seyhmuscacina 21:f7216b5dc6c0 640 }
seyhmuscacina 21:f7216b5dc6c0 641
seyhmuscacina 21:f7216b5dc6c0 642 BMI160(): m_use_irq(false) { }
j3 2:598e601e5846 643 };
j3 2:598e601e5846 644
j3 2:598e601e5846 645
j3 2:598e601e5846 646 /**
j3 2:598e601e5846 647 @brief BMI160_I2C - supports BMI160 object with I2C interface
j3 2:598e601e5846 648 */
j3 2:598e601e5846 649 class BMI160_I2C: public BMI160
j3 2:598e601e5846 650 {
j3 2:598e601e5846 651 public:
j3 2:598e601e5846 652
j3 2:598e601e5846 653 ///BMI160 default I2C address.
j3 2:598e601e5846 654 static const uint8_t I2C_ADRS_SDO_LO = 0x68;
j3 2:598e601e5846 655 ///BMI160 optional I2C address.
j3 2:598e601e5846 656 static const uint8_t I2C_ADRS_SDO_HI = 0x69;
seyhmuscacina 21:f7216b5dc6c0 657
j3 2:598e601e5846 658
j3 2:598e601e5846 659 ///@brief BMI160_I2C Constructor.\n
j3 0:bb5b832891fb 660 ///
j3 0:bb5b832891fb 661 ///On Entry:
j3 2:598e601e5846 662 ///@param[in] i2cBus - reference to I2C bus for this device
j3 2:598e601e5846 663 ///@param[in] i2cAdrs - 7-bit I2C address
j3 0:bb5b832891fb 664 ///
j3 0:bb5b832891fb 665 ///On Exit:
j3 0:bb5b832891fb 666 ///@param[out] none
j3 0:bb5b832891fb 667 ///
j3 0:bb5b832891fb 668 ///@returns none
seyhmuscacina 21:f7216b5dc6c0 669 BMI160_I2C(I2C *i2cBus, uint8_t i2cAdrs);
seyhmuscacina 21:f7216b5dc6c0 670
seyhmuscacina 21:f7216b5dc6c0 671 ///@brief BMI160_I2C Constructor.\n
seyhmuscacina 21:f7216b5dc6c0 672 ///
seyhmuscacina 21:f7216b5dc6c0 673 ///On Entry:
seyhmuscacina 21:f7216b5dc6c0 674 ///@param[in] i2cBus - reference to I2C bus for this device
seyhmuscacina 21:f7216b5dc6c0 675 ///@param[in] i2cAdrs - 7-bit I2C address
seyhmuscacina 21:f7216b5dc6c0 676 ///@param[in] int_pin - Interrupt pin
seyhmuscacina 21:f7216b5dc6c0 677 ///
seyhmuscacina 21:f7216b5dc6c0 678 ///On Exit:
seyhmuscacina 21:f7216b5dc6c0 679 ///@param[out] none
seyhmuscacina 21:f7216b5dc6c0 680 ///
seyhmuscacina 21:f7216b5dc6c0 681 ///@returns none
seyhmuscacina 21:f7216b5dc6c0 682 BMI160_I2C(I2C *i2cBus, uint8_t i2cAdrs, InterruptIn *int_pin);
seyhmuscacina 21:f7216b5dc6c0 683
j3 17:0ae99e97bcf5 684 ///@brief Reads a single register.\n
j3 17:0ae99e97bcf5 685 ///
j3 17:0ae99e97bcf5 686 ///On Entry:
j3 17:0ae99e97bcf5 687 ///@param[in] data - pointer to memory for storing read data
j3 17:0ae99e97bcf5 688 ///
j3 17:0ae99e97bcf5 689 ///On Exit:
j3 17:0ae99e97bcf5 690 ///@param[out] data - holds contents of read register on success
j3 17:0ae99e97bcf5 691 ///
j3 17:0ae99e97bcf5 692 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 693 virtual int32_t readRegister(Registers reg, uint8_t *data);
seyhmuscacina 21:f7216b5dc6c0 694
seyhmuscacina 21:f7216b5dc6c0 695
j3 17:0ae99e97bcf5 696 ///@brief Writes a single register.\n
j3 17:0ae99e97bcf5 697 ///
j3 17:0ae99e97bcf5 698 ///On Entry:
j3 17:0ae99e97bcf5 699 ///@param[in] data - data to write to register
j3 17:0ae99e97bcf5 700 ///
j3 17:0ae99e97bcf5 701 ///On Exit:
j3 17:0ae99e97bcf5 702 ///@param[out] none
j3 17:0ae99e97bcf5 703 ///
j3 17:0ae99e97bcf5 704 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 705 virtual int32_t writeRegister(Registers reg, const uint8_t data);
seyhmuscacina 21:f7216b5dc6c0 706
seyhmuscacina 21:f7216b5dc6c0 707
j3 17:0ae99e97bcf5 708 ///@brief Reads a block of registers.\n
seyhmuscacina 21:f7216b5dc6c0 709 ///@detail User must ensure that all registers between 'startReg' and
seyhmuscacina 21:f7216b5dc6c0 710 ///'stopReg' exist and are readable. Function reads up to, including,
j3 17:0ae99e97bcf5 711 ///'stopReg'.\n
j3 17:0ae99e97bcf5 712 ///
j3 17:0ae99e97bcf5 713 ///On Entry:
j3 17:0ae99e97bcf5 714 ///@param[in] startReg - register to start reading from
j3 17:0ae99e97bcf5 715 ///@param[in] stopReg - register to stop reading from
j3 17:0ae99e97bcf5 716 ///@param[in] data - pointer to memory for storing read data
j3 17:0ae99e97bcf5 717 ///
j3 17:0ae99e97bcf5 718 ///On Exit:
j3 17:0ae99e97bcf5 719 ///@param[out] data - holds contents of read registers on success
j3 17:0ae99e97bcf5 720 ///
j3 17:0ae99e97bcf5 721 ///@returns 0 on success, non 0 on failure
seyhmuscacina 21:f7216b5dc6c0 722 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 723 uint8_t *data);
seyhmuscacina 21:f7216b5dc6c0 724
seyhmuscacina 21:f7216b5dc6c0 725
j3 17:0ae99e97bcf5 726 ///@brief Writes a block of registers.\n
seyhmuscacina 21:f7216b5dc6c0 727 ///@detail User must ensure that all registers between 'startReg' and
seyhmuscacina 21:f7216b5dc6c0 728 ///'stopReg' exist and are writeable. Function writes up to, including,
j3 17:0ae99e97bcf5 729 ///'stopReg'.\n
j3 17:0ae99e97bcf5 730 ///
j3 17:0ae99e97bcf5 731 ///On Entry:
seyhmuscacina 21:f7216b5dc6c0 732 ///@param[in] startReg - register to start writing at
j3 17:0ae99e97bcf5 733 ///@param[in] stopReg - register to stop writing at
j3 17:0ae99e97bcf5 734 ///@param[in] data - pointer to data to write to registers
j3 17:0ae99e97bcf5 735 ///
j3 17:0ae99e97bcf5 736 ///On Exit:
j3 17:0ae99e97bcf5 737 ///@param[out] none
j3 17:0ae99e97bcf5 738 ///
j3 17:0ae99e97bcf5 739 ///@returns 0 on success, non 0 on failure
seyhmuscacina 21:f7216b5dc6c0 740 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 741 const uint8_t *data);
seyhmuscacina 21:f7216b5dc6c0 742
j3 0:bb5b832891fb 743 private:
seyhmuscacina 21:f7216b5dc6c0 744 I2C *m_i2cBus;
j3 0:bb5b832891fb 745 uint8_t m_Wadrs, m_Radrs;
j3 0:bb5b832891fb 746 };
j3 0:bb5b832891fb 747
j3 2:598e601e5846 748
j3 2:598e601e5846 749 /**
j3 2:598e601e5846 750 @brief BMI160_SPI - supports BMI160 object with SPI interface
j3 2:598e601e5846 751 */
j3 2:598e601e5846 752 class BMI160_SPI: public BMI160
j3 2:598e601e5846 753 {
j3 2:598e601e5846 754 public:
j3 2:598e601e5846 755
j3 2:598e601e5846 756 ///@brief BMI160_SPI Constructor.\n
j3 2:598e601e5846 757 ///
j3 2:598e601e5846 758 ///On Entry:
j3 2:598e601e5846 759 ///@param[in] spiBus - reference to SPI bus for this device
j3 2:598e601e5846 760 ///@param[in] cs - reference to DigitalOut used for chip select
j3 2:598e601e5846 761 ///
j3 2:598e601e5846 762 ///On Exit:
j3 2:598e601e5846 763 ///@param[out] none
j3 2:598e601e5846 764 ///
j3 2:598e601e5846 765 ///@returns none
seyhmuscacina 21:f7216b5dc6c0 766 BMI160_SPI(SPI *spiBus, DigitalOut &cs);
seyhmuscacina 21:f7216b5dc6c0 767
seyhmuscacina 21:f7216b5dc6c0 768
j3 17:0ae99e97bcf5 769 ///@brief Reads a single register.\n
j3 17:0ae99e97bcf5 770 ///
j3 17:0ae99e97bcf5 771 ///On Entry:
j3 17:0ae99e97bcf5 772 ///@param[in] data - pointer to memory for storing read data
j3 17:0ae99e97bcf5 773 ///
j3 17:0ae99e97bcf5 774 ///On Exit:
j3 17:0ae99e97bcf5 775 ///@param[out] data - holds contents of read register on success
j3 17:0ae99e97bcf5 776 ///
j3 17:0ae99e97bcf5 777 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 778 virtual int32_t readRegister(Registers reg, uint8_t *data);
seyhmuscacina 21:f7216b5dc6c0 779
seyhmuscacina 21:f7216b5dc6c0 780
j3 17:0ae99e97bcf5 781 ///@brief Writes a single register.\n
j3 17:0ae99e97bcf5 782 ///
j3 17:0ae99e97bcf5 783 ///On Entry:
j3 17:0ae99e97bcf5 784 ///@param[in] data - data to write to register
j3 17:0ae99e97bcf5 785 ///
j3 17:0ae99e97bcf5 786 ///On Exit:
j3 17:0ae99e97bcf5 787 ///@param[out] none
j3 17:0ae99e97bcf5 788 ///
j3 17:0ae99e97bcf5 789 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 790 virtual int32_t writeRegister(Registers reg, const uint8_t data);
seyhmuscacina 21:f7216b5dc6c0 791
seyhmuscacina 21:f7216b5dc6c0 792
j3 17:0ae99e97bcf5 793 ///@brief Reads a block of registers.\n
seyhmuscacina 21:f7216b5dc6c0 794 ///@detail User must ensure that all registers between 'startReg' and
seyhmuscacina 21:f7216b5dc6c0 795 ///'stopReg' exist and are readable. Function reads up to, including,
j3 17:0ae99e97bcf5 796 ///'stopReg'.\n
j3 17:0ae99e97bcf5 797 ///
j3 17:0ae99e97bcf5 798 ///On Entry:
j3 17:0ae99e97bcf5 799 ///@param[in] startReg - register to start reading from
j3 17:0ae99e97bcf5 800 ///@param[in] stopReg - register to stop reading from
j3 17:0ae99e97bcf5 801 ///@param[in] data - pointer to memory for storing read data
j3 17:0ae99e97bcf5 802 ///
j3 17:0ae99e97bcf5 803 ///On Exit:
j3 17:0ae99e97bcf5 804 ///@param[out] data - holds contents of read registers on success
j3 17:0ae99e97bcf5 805 ///
j3 17:0ae99e97bcf5 806 ///@returns 0 on success, non 0 on failure
seyhmuscacina 21:f7216b5dc6c0 807 virtual int32_t readBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 808 uint8_t *data);
seyhmuscacina 21:f7216b5dc6c0 809
seyhmuscacina 21:f7216b5dc6c0 810
j3 17:0ae99e97bcf5 811 ///@brief Writes a block of registers.\n
seyhmuscacina 21:f7216b5dc6c0 812 ///@detail User must ensure that all registers between 'startReg' and
seyhmuscacina 21:f7216b5dc6c0 813 ///'stopReg' exist and are writeable. Function writes up to, including,
j3 17:0ae99e97bcf5 814 ///'stopReg'.\n
j3 17:0ae99e97bcf5 815 ///
j3 17:0ae99e97bcf5 816 ///On Entry:
seyhmuscacina 21:f7216b5dc6c0 817 ///@param[in] startReg - register to start writing at
j3 17:0ae99e97bcf5 818 ///@param[in] stopReg - register to stop writing at
j3 17:0ae99e97bcf5 819 ///@param[in] data - pointer to data to write to registers
j3 17:0ae99e97bcf5 820 ///
j3 17:0ae99e97bcf5 821 ///On Exit:
j3 17:0ae99e97bcf5 822 ///@param[out] none
j3 17:0ae99e97bcf5 823 ///
j3 17:0ae99e97bcf5 824 ///@returns 0 on success, non 0 on failure
seyhmuscacina 21:f7216b5dc6c0 825 virtual int32_t writeBlock(Registers startReg, Registers stopReg,
j3 3:e1770675eca4 826 const uint8_t *data);
seyhmuscacina 21:f7216b5dc6c0 827
j3 2:598e601e5846 828 private:
j3 2:598e601e5846 829
seyhmuscacina 21:f7216b5dc6c0 830 SPI *m_spiBus;
j3 2:598e601e5846 831 DigitalOut m_cs;
j3 2:598e601e5846 832 };
j3 2:598e601e5846 833
j3 0:bb5b832891fb 834 #endif /* BMI160_H */
j3 8:a89b529b1d96 835
j3 8:a89b529b1d96 836
j3 8:a89b529b1d96 837 ///@brief fx documentation template.\n
j3 8:a89b529b1d96 838 ///
j3 8:a89b529b1d96 839 ///On Entry:
seyhmuscacina 21:f7216b5dc6c0 840 ///@param[in] none
j3 8:a89b529b1d96 841 ///
j3 8:a89b529b1d96 842 ///On Exit:
j3 8:a89b529b1d96 843 ///@param[out] none
j3 8:a89b529b1d96 844 ///
j3 8:a89b529b1d96 845 ///@returns none