TEST

Dependencies:   max32630fthr Adafruit_FeatherOLED USBDevice

Committer:
gmehmet
Date:
Wed Apr 10 14:56:25 2019 +0300
Revision:
1:f60eafbf009a
upload from local

Who changed what in which revision?

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