Library for Bosch Sensortech BMI160 IMU
Dependents: MAX32630FTHR_BALANCE_BOT MPSMAX_copy MAX32630FTHR_BALANCE_BOT SELF_BALANCING_BOT
bmi160.h@12:64931a80340d, 2016-12-20 (annotated)
- Committer:
- j3
- Date:
- Tue Dec 20 18:38:42 2016 +0000
- Revision:
- 12:64931a80340d
- Parent:
- 11:24602ff07e9f
- Child:
- 13:5d132f873b07
experimenting with doxygen
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:bb5b832891fb | 1 | /********************************************************************** |
j3 | 0:bb5b832891fb | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:bb5b832891fb | 3 | * |
j3 | 0:bb5b832891fb | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:bb5b832891fb | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:bb5b832891fb | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 0:bb5b832891fb | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:bb5b832891fb | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:bb5b832891fb | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:bb5b832891fb | 10 | * |
j3 | 0:bb5b832891fb | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 0:bb5b832891fb | 12 | * in all copies or substantial portions of the Software. |
j3 | 0:bb5b832891fb | 13 | * |
j3 | 0:bb5b832891fb | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:bb5b832891fb | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:bb5b832891fb | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:bb5b832891fb | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:bb5b832891fb | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:bb5b832891fb | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:bb5b832891fb | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:bb5b832891fb | 21 | * |
j3 | 0:bb5b832891fb | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:bb5b832891fb | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:bb5b832891fb | 24 | * Products, Inc. Branding Policy. |
j3 | 0:bb5b832891fb | 25 | * |
j3 | 0:bb5b832891fb | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 0:bb5b832891fb | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:bb5b832891fb | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:bb5b832891fb | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:bb5b832891fb | 30 | * ownership rights. |
j3 | 0:bb5b832891fb | 31 | **********************************************************************/ |
j3 | 0:bb5b832891fb | 32 | |
j3 | 0:bb5b832891fb | 33 | |
j3 | 0:bb5b832891fb | 34 | #ifndef BMI160_H |
j3 | 0:bb5b832891fb | 35 | #define BMI160_H |
j3 | 0:bb5b832891fb | 36 | |
j3 | 0:bb5b832891fb | 37 | #include "mbed.h" |
j3 | 0:bb5b832891fb | 38 | |
j3 | 0:bb5b832891fb | 39 | /** |
j3 | 0:bb5b832891fb | 40 | @brief The BMI160 is a small, low power, low noise 16-bit inertial measurement |
j3 | 0:bb5b832891fb | 41 | unit designed for use in mobile applications like augmented reality or indoor |
j3 | 0:bb5b832891fb | 42 | navigation which require highly accurate, real-time sensor data. |
j3 | 0:bb5b832891fb | 43 | |
j3 | 0:bb5b832891fb | 44 | In full operation mode, with both the accelerometer and gyroscope enabled, the |
j3 | 0:bb5b832891fb | 45 | current consumption is typically 950 μA, enabling always-on applications in |
j3 | 0:bb5b832891fb | 46 | battery driven devices. It is available in a compact 14-pin 2.5 x 3.0 x 0.8 mm³ |
j3 | 0:bb5b832891fb | 47 | LGA package." |
j3 | 2:598e601e5846 | 48 | |
j3 | 2:598e601e5846 | 49 | This class is an abstract base class and can not be instaniated, use BMI160_I2C |
j3 | 2:598e601e5846 | 50 | or BMI160_SPI. |
j3 | 0:bb5b832891fb | 51 | */ |
j3 | 0:bb5b832891fb | 52 | class BMI160 |
j3 | 0:bb5b832891fb | 53 | { |
j3 | 0:bb5b832891fb | 54 | public: |
j3 | 0:bb5b832891fb | 55 | |
j3 | 2:598e601e5846 | 56 | ///Return value on success. |
j3 | 3:e1770675eca4 | 57 | static const uint8_t RTN_NO_ERROR = 0; |
j3 | 0:bb5b832891fb | 58 | |
j3 | 5:35e032c8d8aa | 59 | ///BMI160 Sensors |
j3 | 5:35e032c8d8aa | 60 | enum Sensors |
j3 | 5:35e032c8d8aa | 61 | { |
j3 | 5:35e032c8d8aa | 62 | MAG = 0, ///<Optional external sensor |
j3 | 5:35e032c8d8aa | 63 | GYRO, ///<Angular rate sensor |
j3 | 5:35e032c8d8aa | 64 | ACC ///<g sensor |
j3 | 5:35e032c8d8aa | 65 | }; |
j3 | 5:35e032c8d8aa | 66 | |
j3 | 8:a89b529b1d96 | 67 | ///Sensor Axis |
j3 | 8:a89b529b1d96 | 68 | enum SensorAxis |
j3 | 8:a89b529b1d96 | 69 | { |
j3 | 8:a89b529b1d96 | 70 | X_AXIS = 0, |
j3 | 8:a89b529b1d96 | 71 | Y_AXIS, |
j3 | 8:a89b529b1d96 | 72 | Z_AXIS |
j3 | 8:a89b529b1d96 | 73 | }; |
j3 | 8:a89b529b1d96 | 74 | |
j3 | 8:a89b529b1d96 | 75 | ///Structure for axis data |
j3 | 8:a89b529b1d96 | 76 | struct AxisData |
j3 | 8:a89b529b1d96 | 77 | { |
j3 | 8:a89b529b1d96 | 78 | int16_t raw; ///<Axis raw data |
j3 | 8:a89b529b1d96 | 79 | float scaled; ///<Axis scaled data |
j3 | 8:a89b529b1d96 | 80 | }; |
j3 | 8:a89b529b1d96 | 81 | |
j3 | 8:a89b529b1d96 | 82 | ///Structure for holding sensor data |
j3 | 8:a89b529b1d96 | 83 | struct SensorData |
j3 | 8:a89b529b1d96 | 84 | { |
j3 | 8:a89b529b1d96 | 85 | AxisData xAxis; ///<Sensor X axis data |
j3 | 8:a89b529b1d96 | 86 | AxisData yAxis; ///<Sensor Y axis data |
j3 | 8:a89b529b1d96 | 87 | AxisData zAxis; ///<Sensor Z axis data |
j3 | 8:a89b529b1d96 | 88 | }; |
j3 | 8:a89b529b1d96 | 89 | |
j3 | 1:a4c911640569 | 90 | ///BMI160 registers |
j3 | 0:bb5b832891fb | 91 | enum Registers |
j3 | 0:bb5b832891fb | 92 | { |
j3 | 3:e1770675eca4 | 93 | CHIP_ID = 0x00, ///<Chip Identification. |
j3 | 3:e1770675eca4 | 94 | ERR_REG = 0x02, ///<Reports sensor error flags. Flags reset when read. |
j3 | 3:e1770675eca4 | 95 | PMU_STATUS, ///<Reports current power mode for sensors. |
j3 | 3:e1770675eca4 | 96 | DATA_0, ///<MAG_X axis bits7:0 |
j3 | 3:e1770675eca4 | 97 | DATA_1, ///<MAG_X axis bits15:8 |
j3 | 3:e1770675eca4 | 98 | DATA_2, ///<MAG_Y axis bits7:0 |
j3 | 3:e1770675eca4 | 99 | DATA_3, ///<MAG_Y axis bits15:8 |
j3 | 3:e1770675eca4 | 100 | DATA_4, ///<MAG_Z axis bits7:0 |
j3 | 3:e1770675eca4 | 101 | DATA_5, ///<MAG_Z axis bits15:8 |
j3 | 3:e1770675eca4 | 102 | DATA_6, ///<RHALL bits7:0 |
j3 | 3:e1770675eca4 | 103 | DATA_7, ///<RHALL bits15:8 |
j3 | 3:e1770675eca4 | 104 | DATA_8, ///<GYR_X axis bits7:0 |
j3 | 3:e1770675eca4 | 105 | DATA_9, ///<GYR_X axis bits15:8 |
j3 | 3:e1770675eca4 | 106 | DATA_10, ///<GYR_Y axis bits7:0 |
j3 | 3:e1770675eca4 | 107 | DATA_11, ///<GYR_Y axis bits15:8 |
j3 | 3:e1770675eca4 | 108 | DATA_12, ///<GYR_Z axis bits7:0 |
j3 | 3:e1770675eca4 | 109 | DATA_13, ///<GYR_Z axis bits15:8 |
j3 | 3:e1770675eca4 | 110 | DATA_14, ///<ACC_X axis bits7:0 |
j3 | 3:e1770675eca4 | 111 | DATA_15, ///<ACC_X axis bits15:8 |
j3 | 3:e1770675eca4 | 112 | DATA_16, ///<ACC_Y axis bits7:0 |
j3 | 3:e1770675eca4 | 113 | DATA_17, ///<ACC_Y axis bits15:8 |
j3 | 3:e1770675eca4 | 114 | DATA_18, ///<ACC_Z axis bits7:0 |
j3 | 3:e1770675eca4 | 115 | DATA_19, ///<ACC_Z axis bits15:8 |
j3 | 3:e1770675eca4 | 116 | SENSORTIME_0, ///<24bit counter synchronized with data, bits7:0 |
j3 | 3:e1770675eca4 | 117 | SENSORTIME_1, ///<24bit counter synchronized with data, bits15:8 |
j3 | 3:e1770675eca4 | 118 | SENSORTIME_2, ///<24bit counter synchronized with data, bits23:16 |
j3 | 3:e1770675eca4 | 119 | STATUS, ///<Reports sensors status flags |
j3 | 3:e1770675eca4 | 120 | INT_STATUS_0, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 121 | INT_STATUS_1, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 122 | INT_STATUS_2, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 123 | INT_STATUS_3, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 124 | TEMPERATURE_0, ///<Contains temperature of sensor, bits7:0 |
j3 | 3:e1770675eca4 | 125 | TEMPERATURE_1, ///<Contains temperature of sensor, bits15:8 |
j3 | 3:e1770675eca4 | 126 | FIFO_LENGTH_0, ///<Current fill level of FIFO, bits7:0 |
j3 | 3:e1770675eca4 | 127 | FIFO_LENGTH_1, ///<Current fill level of FIFO, bits10:8 |
j3 | 3:e1770675eca4 | 128 | FIFO_DATA, ///<FIFO data read out register, burst read |
j3 | 3:e1770675eca4 | 129 | ACC_CONF = 0x40, ///<Set ODR, bandwidth, and read mode of accelerometer |
j3 | 3:e1770675eca4 | 130 | ACC_RANGE, ///<Sets accelerometer g-range |
j3 | 3:e1770675eca4 | 131 | GYR_CONF, ///<Set ODR, bandwidth, and read mode of gyroscope |
j3 | 3:e1770675eca4 | 132 | GYR_RANGE, ///<Sets gyroscope angular rate measurement range |
j3 | 3:e1770675eca4 | 133 | MAG_CONF, ///<Sets ODR of magnetometer interface |
j3 | 3:e1770675eca4 | 134 | FIFO_DOWNS, ///<Sets down sampling ratios of accel and gyro data |
j3 | 3:e1770675eca4 | 135 | ///<for FIFO |
j3 | 3:e1770675eca4 | 136 | FIFO_CONFIG_0, ///<Sets FIFO Watermark |
j3 | 3:e1770675eca4 | 137 | FIFO_CONFIG_1, ///<Sets which sensor data is available in FIFO, |
j3 | 3:e1770675eca4 | 138 | ///<Header/Headerless mode, Ext Int tagging, Sensortime |
j3 | 3:e1770675eca4 | 139 | MAG_IF_0 = 0x4B, ///<Magnetometer 7-bit I2C address, bits7:1 |
j3 | 3:e1770675eca4 | 140 | MAG_IF_1, ///<Magnetometer interface configuration |
j3 | 3:e1770675eca4 | 141 | MAG_IF_2, ///<Magnetometer address to read |
j3 | 3:e1770675eca4 | 142 | MAG_IF_3, ///<Magnetometer address to write |
j3 | 3:e1770675eca4 | 143 | MAG_IF_4, ///<Magnetometer data to write |
j3 | 3:e1770675eca4 | 144 | INT_EN_0, ///<Interrupt enable bits |
j3 | 3:e1770675eca4 | 145 | INT_EN_1, ///<Interrupt enable bits |
j3 | 3:e1770675eca4 | 146 | INT_EN_2, ///<Interrupt enable bits |
j3 | 3:e1770675eca4 | 147 | INT_OUT_CTRL, ///<Contains the behavioral configuration of INT pins |
j3 | 3:e1770675eca4 | 148 | INT_LATCH, ///<Contains the interrupt rest bit and the interrupt |
j3 | 3:e1770675eca4 | 149 | ///<mode selection |
j3 | 3:e1770675eca4 | 150 | INT_MAP_0, ///<Controls which interrupt signals are mapped to the |
j3 | 3:e1770675eca4 | 151 | ///<INT1 and INT2 pins |
j3 | 3:e1770675eca4 | 152 | INT_MAP_1, ///<Controls which interrupt signals are mapped to the |
j3 | 3:e1770675eca4 | 153 | ///<INT1 and INT2 pins |
j3 | 3:e1770675eca4 | 154 | INT_MAP_2, ///<Controls which interrupt signals are mapped to the |
j3 | 3:e1770675eca4 | 155 | ///<INT1 and INT2 pins |
j3 | 3:e1770675eca4 | 156 | INT_DATA_0, ///<Contains the data source definition for the two |
j3 | 3:e1770675eca4 | 157 | ///<interrupt groups |
j3 | 3:e1770675eca4 | 158 | INT_DATA_1, ///<Contains the data source definition for the two |
j3 | 3:e1770675eca4 | 159 | ///<interrupt groups |
j3 | 3:e1770675eca4 | 160 | INT_LOWHIGH_0, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 161 | INT_LOWHIGH_1, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 162 | INT_LOWHIGH_2, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 163 | INT_LOWHIGH_3, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 164 | INT_LOWHIGH_4, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 165 | INT_MOTION_0, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 166 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 167 | INT_MOTION_1, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 168 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 169 | INT_MOTION_2, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 170 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 171 | INT_MOTION_3, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 172 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 173 | INT_TAP_0, ///<Contains the configuration for the tap interrupts |
j3 | 3:e1770675eca4 | 174 | INT_TAP_1, ///<Contains the configuration for the tap interrupts |
j3 | 3:e1770675eca4 | 175 | INT_ORIENT_0, ///<Contains the configuration for the oeientation |
j3 | 3:e1770675eca4 | 176 | ///<interrupt |
j3 | 3:e1770675eca4 | 177 | INT_ORIENT_1, ///<Contains the configuration for the oeientation |
j3 | 3:e1770675eca4 | 178 | ///<interrupt |
j3 | 3:e1770675eca4 | 179 | INT_FLAT_0, ///<Contains the configuration for the flat interrupt |
j3 | 3:e1770675eca4 | 180 | INT_FLAT_1, ///<Contains the configuration for the flat interrupt |
j3 | 3:e1770675eca4 | 181 | FOC_CONF, ///<Contains configuration for the fast offset |
j3 | 3:e1770675eca4 | 182 | ///<compensation for the accelerometer and gyroscope |
j3 | 3:e1770675eca4 | 183 | CONF, ///<Configuration of sensor, nvm_prog_en bit |
j3 | 3:e1770675eca4 | 184 | IF_CONF, ///<Contains settings for the digital interface |
j3 | 3:e1770675eca4 | 185 | PMU_TRIGGER, ///<Sets trigger conditions to change gyro power modes |
j3 | 3:e1770675eca4 | 186 | SELF_TEST, ///<Self test configuration |
j3 | 3:e1770675eca4 | 187 | NV_CONF = 0x70, ///<Contains settings for the digital interface |
j3 | 3:e1770675eca4 | 188 | OFFSET_0, ///<Contains offset comp values for acc_off_x7:0 |
j3 | 3:e1770675eca4 | 189 | OFFSET_1, ///<Contains offset comp values for acc_off_y7:0 |
j3 | 3:e1770675eca4 | 190 | OFFSET_2, ///<Contains offset comp values for acc_off_z7:0 |
j3 | 3:e1770675eca4 | 191 | OFFSET_3, ///<Contains offset comp values for gyr_off_x7:0 |
j3 | 3:e1770675eca4 | 192 | OFFSET_4, ///<Contains offset comp values for gyr_off_y7:0 |
j3 | 3:e1770675eca4 | 193 | OFFSET_5, ///<Contains offset comp values for gyr_off_z7:0 |
j3 | 3:e1770675eca4 | 194 | OFFSET_6, ///<gyr/acc offset enable bit and gyr_off_(zyx) bits9:8 |
j3 | 3:e1770675eca4 | 195 | STEP_CNT_0, ///<Step counter bits 15:8 |
j3 | 3:e1770675eca4 | 196 | STEP_CNT_1, ///<Step counter bits 7:0 |
j3 | 3:e1770675eca4 | 197 | STEP_CONF_0, ///<Contains configuration of the step detector |
j3 | 3:e1770675eca4 | 198 | STEP_CONF_1, ///<Contains configuration of the step detector |
j3 | 3:e1770675eca4 | 199 | CMD = 0x7E ///<Command register triggers operations like |
j3 | 3:e1770675eca4 | 200 | ///<softreset, NVM programming, etc. |
j3 | 3:e1770675eca4 | 201 | }; |
j3 | 3:e1770675eca4 | 202 | |
j3 | 8:a89b529b1d96 | 203 | |
j3 | 12:64931a80340d | 204 | ///@name ERR_REG(0x02) Group |
j3 | 12:64931a80340d | 205 | ///Bit masks, positions, and enumerations |
j3 | 12:64931a80340d | 206 | ///@{ |
j3 | 3:e1770675eca4 | 207 | static const uint8_t FATAL_ERR = 0x01; |
j3 | 3:e1770675eca4 | 208 | static const uint8_t ERR_CODE = 0x1E; |
j3 | 3:e1770675eca4 | 209 | static const uint8_t I2C_FAIL_ERR = 0x20; |
j3 | 3:e1770675eca4 | 210 | static const uint8_t DROP_CMD_ERR = 0x40; |
j3 | 3:e1770675eca4 | 211 | static const uint8_t MAG_DRDY_ERR = 0x80; |
j3 | 3:e1770675eca4 | 212 | |
j3 | 3:e1770675eca4 | 213 | enum ErrorCodes |
j3 | 3:e1770675eca4 | 214 | { |
j3 | 3:e1770675eca4 | 215 | NO_ERROR = 0, ///<No Error |
j3 | 3:e1770675eca4 | 216 | ERROR_1, ///<Listed as error |
j3 | 3:e1770675eca4 | 217 | ERROR_2, ///<Listed as error |
j3 | 3:e1770675eca4 | 218 | LPM_INT_PFD, ///<Low-power mode and interrupt uses pre-filtered |
j3 | 3:e1770675eca4 | 219 | ///<data |
j3 | 4:ebac8c8f6347 | 220 | ODR_MISMATCH = 0x06, ///<ODRs of enabled sensors in headerless mode do |
j3 | 4:ebac8c8f6347 | 221 | ///<not match |
j3 | 3:e1770675eca4 | 222 | PFD_USED_LPM ///<Pre-filtered data are used in low power mode |
j3 | 0:bb5b832891fb | 223 | }; |
j3 | 12:64931a80340d | 224 | ///@} |
j3 | 0:bb5b832891fb | 225 | |
j3 | 8:a89b529b1d96 | 226 | |
j3 | 12:64931a80340d | 227 | ///@name ACC_CONF(0x40) and ACC_RANGE(0x41) Group |
j3 | 12:64931a80340d | 228 | ///Bit masks, positions, and enumerations |
j3 | 12:64931a80340d | 229 | ///@{ |
j3 | 8:a89b529b1d96 | 230 | static const uint8_t ACC_ODR = 0x0F; |
j3 | 12:64931a80340d | 231 | static const uint8_t ACC_ODR_POS = 0; |
j3 | 8:a89b529b1d96 | 232 | static const uint8_t ACC_BWP = 0x70; |
j3 | 12:64931a80340d | 233 | static const uint8_t ACC_BWP_POS = 0x04; |
j3 | 8:a89b529b1d96 | 234 | static const uint8_t ACC_US = 0x80; |
j3 | 12:64931a80340d | 235 | static const uint8_t ACC_US_POS = 0x07; |
j3 | 8:a89b529b1d96 | 236 | |
j3 | 8:a89b529b1d96 | 237 | enum AccOutPutDataRate |
j3 | 8:a89b529b1d96 | 238 | { |
j3 | 8:a89b529b1d96 | 239 | ACC_ODR_1 = 1, ///< 25/32Hz |
j3 | 8:a89b529b1d96 | 240 | ACC_ODR_2, ///< 25/16Hz |
j3 | 8:a89b529b1d96 | 241 | ACC_ODR_3, ///< 25/8Hz |
j3 | 8:a89b529b1d96 | 242 | ACC_ODR_4, ///< 25/4Hz |
j3 | 8:a89b529b1d96 | 243 | ACC_ODR_5, ///< 25/2Hz |
j3 | 8:a89b529b1d96 | 244 | ACC_ODR_6, ///< 25Hz |
j3 | 8:a89b529b1d96 | 245 | ACC_ODR_7, ///< 50Hz |
j3 | 8:a89b529b1d96 | 246 | ACC_ODR_8, ///< 100Hz |
j3 | 8:a89b529b1d96 | 247 | ACC_ODR_9, ///< 200Hz |
j3 | 8:a89b529b1d96 | 248 | ACC_ODR_10, ///< 400Hz |
j3 | 8:a89b529b1d96 | 249 | ACC_ODR_11, ///< 800Hz |
j3 | 8:a89b529b1d96 | 250 | ACC_ODR_12 ///< 1600Hz |
j3 | 8:a89b529b1d96 | 251 | }; |
j3 | 8:a89b529b1d96 | 252 | |
j3 | 8:a89b529b1d96 | 253 | enum AccBandWidthParam |
j3 | 8:a89b529b1d96 | 254 | { |
j3 | 8:a89b529b1d96 | 255 | ACC_BWP_0 = 0, ///< Average 1 cycle |
j3 | 8:a89b529b1d96 | 256 | ACC_BWP_1, ///< Average 2 cycles |
j3 | 8:a89b529b1d96 | 257 | ACC_BWP_2, ///< Average 4 cycles, use this setting when acc_us = 0 |
j3 | 8:a89b529b1d96 | 258 | ACC_BWP_3, ///< Average 8 cycles |
j3 | 8:a89b529b1d96 | 259 | ACC_BWP_4, ///< Average 16 cycles |
j3 | 8:a89b529b1d96 | 260 | ACC_BWP_5, ///< Average 32 cycles |
j3 | 8:a89b529b1d96 | 261 | ACC_BWP_6, ///< Average 64 cycles |
j3 | 8:a89b529b1d96 | 262 | ACC_BWP_7 ///< Average 128 cycles |
j3 | 8:a89b529b1d96 | 263 | }; |
j3 | 8:a89b529b1d96 | 264 | |
j3 | 8:a89b529b1d96 | 265 | enum AccUnderSampling |
j3 | 8:a89b529b1d96 | 266 | { |
j3 | 8:a89b529b1d96 | 267 | ACC_US_OFF = 0, |
j3 | 8:a89b529b1d96 | 268 | ACC_US_ON |
j3 | 8:a89b529b1d96 | 269 | }; |
j3 | 8:a89b529b1d96 | 270 | |
j3 | 8:a89b529b1d96 | 271 | enum AccRange |
j3 | 8:a89b529b1d96 | 272 | { |
j3 | 8:a89b529b1d96 | 273 | SENS_2G = 0, ///<Accelerometer range +-2G |
j3 | 8:a89b529b1d96 | 274 | SENS_4G, ///<Accelerometer range +-4G |
j3 | 8:a89b529b1d96 | 275 | SENS_8G, ///<Accelerometer range +-8G |
j3 | 8:a89b529b1d96 | 276 | SENS_16G, ///<Accelerometer range +-16G |
j3 | 8:a89b529b1d96 | 277 | }; |
j3 | 8:a89b529b1d96 | 278 | |
j3 | 9:ca6b5fecdd63 | 279 | struct AccConfig |
j3 | 9:ca6b5fecdd63 | 280 | { |
j3 | 9:ca6b5fecdd63 | 281 | AccRange range; |
j3 | 9:ca6b5fecdd63 | 282 | AccUnderSampling us; |
j3 | 9:ca6b5fecdd63 | 283 | AccBandWidthParam bwp; |
j3 | 9:ca6b5fecdd63 | 284 | AccOutPutDataRate odr; |
j3 | 9:ca6b5fecdd63 | 285 | }; |
j3 | 9:ca6b5fecdd63 | 286 | |
j3 | 9:ca6b5fecdd63 | 287 | static const AccConfig DEFAULT_ACC_CONFIG; |
j3 | 12:64931a80340d | 288 | ///@} |
j3 | 9:ca6b5fecdd63 | 289 | |
j3 | 12:64931a80340d | 290 | |
j3 | 4:ebac8c8f6347 | 291 | enum PowerModes |
j3 | 4:ebac8c8f6347 | 292 | { |
j3 | 4:ebac8c8f6347 | 293 | SUSPEND = 0, ///<Acc and Gyro, No sampling, No FIFO data readout |
j3 | 4:ebac8c8f6347 | 294 | NORMAL, ///<Acc and Gyro, Full chip operation |
j3 | 4:ebac8c8f6347 | 295 | LOW_POWER, ///<Acc duty-cycling between suspend and normal |
j3 | 4:ebac8c8f6347 | 296 | FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms |
j3 | 4:ebac8c8f6347 | 297 | }; |
j3 | 4:ebac8c8f6347 | 298 | |
j3 | 12:64931a80340d | 299 | |
j3 | 5:35e032c8d8aa | 300 | enum Commands |
j3 | 5:35e032c8d8aa | 301 | { |
j3 | 5:35e032c8d8aa | 302 | START_FOC = 0x03, ///<Starts Fast Offset Calibrartion |
j3 | 7:9848196cb65e | 303 | ACC_SET_PMU_MODE = 0x10, ///<Sets acc power mode |
j3 | 8:a89b529b1d96 | 304 | GYR_SET_PMU_MODE = 0x14, ///<Sets gyro power mode |
j3 | 8:a89b529b1d96 | 305 | MAG_SET_PMU_MODE = 0x18, ///<Sets mag power mode |
j3 | 5:35e032c8d8aa | 306 | PROG_NVM = 0xA0, ///<Writes NVM backed registers into NVM |
j3 | 5:35e032c8d8aa | 307 | FIFO_FLUSH = 0xB0, ///<Clears FIFO |
j3 | 5:35e032c8d8aa | 308 | INT_RESET, ///<Clears interrupt engine, INT_STATUS, and |
j3 | 5:35e032c8d8aa | 309 | ///<the interrupt pin |
j3 | 5:35e032c8d8aa | 310 | STEP_CNT_CLR, ///<Triggers reset of the step counter |
j3 | 5:35e032c8d8aa | 311 | SOFT_RESET = 0xB6 ///<Triggers a reset including a reboot. |
j3 | 5:35e032c8d8aa | 312 | }; |
j3 | 5:35e032c8d8aa | 313 | |
j3 | 0:bb5b832891fb | 314 | |
j3 | 0:bb5b832891fb | 315 | ///@brief BMI160 Destructor.\n |
j3 | 0:bb5b832891fb | 316 | /// |
j3 | 0:bb5b832891fb | 317 | ///On Entry: |
j3 | 0:bb5b832891fb | 318 | ///@param[in] none |
j3 | 0:bb5b832891fb | 319 | /// |
j3 | 0:bb5b832891fb | 320 | ///On Exit: |
j3 | 0:bb5b832891fb | 321 | ///@param[out] none |
j3 | 0:bb5b832891fb | 322 | /// |
j3 | 0:bb5b832891fb | 323 | ///@returns none |
j3 | 2:598e601e5846 | 324 | virtual ~BMI160(){ } |
j3 | 0:bb5b832891fb | 325 | |
j3 | 0:bb5b832891fb | 326 | |
j3 | 0:bb5b832891fb | 327 | ///@brief Reads a single register.\n |
j3 | 0:bb5b832891fb | 328 | /// |
j3 | 0:bb5b832891fb | 329 | ///On Entry: |
j3 | 0:bb5b832891fb | 330 | ///@param[in] data - pointer to memory for storing read data |
j3 | 0:bb5b832891fb | 331 | /// |
j3 | 0:bb5b832891fb | 332 | ///On Exit: |
j3 | 0:bb5b832891fb | 333 | ///@param[out] data - holds contents of read register on success |
j3 | 0:bb5b832891fb | 334 | /// |
j3 | 0:bb5b832891fb | 335 | ///@returns 0 on success, non 0 on failure |
j3 | 2:598e601e5846 | 336 | virtual int32_t readRegister(Registers reg, uint8_t *data) = 0; |
j3 | 0:bb5b832891fb | 337 | |
j3 | 0:bb5b832891fb | 338 | |
j3 | 0:bb5b832891fb | 339 | ///@brief Writes a single register.\n |
j3 | 0:bb5b832891fb | 340 | /// |
j3 | 0:bb5b832891fb | 341 | ///On Entry: |
j3 | 0:bb5b832891fb | 342 | ///@param[in] data - data to write to register |
j3 | 0:bb5b832891fb | 343 | /// |
j3 | 0:bb5b832891fb | 344 | ///On Exit: |
j3 | 0:bb5b832891fb | 345 | ///@param[out] none |
j3 | 0:bb5b832891fb | 346 | /// |
j3 | 0:bb5b832891fb | 347 | ///@returns 0 on success, non 0 on failure |
j3 | 2:598e601e5846 | 348 | virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0; |
j3 | 0:bb5b832891fb | 349 | |
j3 | 0:bb5b832891fb | 350 | |
j3 | 0:bb5b832891fb | 351 | ///@brief Reads a block of registers.\n |
j3 | 0:bb5b832891fb | 352 | ///@detail User must ensure that all registers between 'startReg' and |
j3 | 0:bb5b832891fb | 353 | ///'stopReg' exist and are readable. Function reads up to, including, |
j3 | 0:bb5b832891fb | 354 | ///'stopReg'.\n |
j3 | 0:bb5b832891fb | 355 | /// |
j3 | 0:bb5b832891fb | 356 | ///On Entry: |
j3 | 0:bb5b832891fb | 357 | ///@param[in] startReg - register to start reading from |
j3 | 0:bb5b832891fb | 358 | ///@param[in] stopReg - register to stop reading from |
j3 | 0:bb5b832891fb | 359 | ///@param[in] data - pointer to memory for storing read data |
j3 | 0:bb5b832891fb | 360 | /// |
j3 | 0:bb5b832891fb | 361 | ///On Exit: |
j3 | 0:bb5b832891fb | 362 | ///@param[out] data - holds contents of read registers on success |
j3 | 0:bb5b832891fb | 363 | /// |
j3 | 0:bb5b832891fb | 364 | ///@returns 0 on success, non 0 on failure |
j3 | 3:e1770675eca4 | 365 | virtual int32_t readBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 366 | uint8_t *data) = 0; |
j3 | 0:bb5b832891fb | 367 | |
j3 | 0:bb5b832891fb | 368 | |
j3 | 0:bb5b832891fb | 369 | ///@brief Writes a block of registers.\n |
j3 | 0:bb5b832891fb | 370 | ///@detail User must ensure that all registers between 'startReg' and |
j3 | 0:bb5b832891fb | 371 | ///'stopReg' exist and are writeable. Function writes up to, including, |
j3 | 0:bb5b832891fb | 372 | ///'stopReg'.\n |
j3 | 0:bb5b832891fb | 373 | /// |
j3 | 0:bb5b832891fb | 374 | ///On Entry: |
j3 | 0:bb5b832891fb | 375 | ///@param[in] startReg - register to start writing at |
j3 | 0:bb5b832891fb | 376 | ///@param[in] stopReg - register to stop writing at |
j3 | 0:bb5b832891fb | 377 | ///@param[in] data - pointer to data to write to registers |
j3 | 0:bb5b832891fb | 378 | /// |
j3 | 0:bb5b832891fb | 379 | ///On Exit: |
j3 | 0:bb5b832891fb | 380 | ///@param[out] none |
j3 | 0:bb5b832891fb | 381 | /// |
j3 | 0:bb5b832891fb | 382 | ///@returns 0 on success, non 0 on failure |
j3 | 3:e1770675eca4 | 383 | virtual int32_t writeBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 384 | const uint8_t *data) = 0; |
j3 | 3:e1770675eca4 | 385 | |
j3 | 3:e1770675eca4 | 386 | |
j3 | 5:35e032c8d8aa | 387 | ///@brief Sets sensors power mode through CMD register.\n |
j3 | 5:35e032c8d8aa | 388 | ///@details Observe command execution times given in datasheet.\n |
j3 | 5:35e032c8d8aa | 389 | /// |
j3 | 5:35e032c8d8aa | 390 | ///On Entry: |
j3 | 5:35e032c8d8aa | 391 | ///@param[in] sensor - Sensor which power mode we are setting |
j3 | 5:35e032c8d8aa | 392 | ///@param[in] pwrMode - Desired powermode of the sensor |
j3 | 5:35e032c8d8aa | 393 | /// |
j3 | 5:35e032c8d8aa | 394 | ///On Exit: |
j3 | 5:35e032c8d8aa | 395 | ///@param[out] |
j3 | 5:35e032c8d8aa | 396 | /// |
j3 | 5:35e032c8d8aa | 397 | ///@returns 0 on success, non 0 on failure |
j3 | 5:35e032c8d8aa | 398 | int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode); |
j3 | 5:35e032c8d8aa | 399 | |
j3 | 5:35e032c8d8aa | 400 | |
j3 | 12:64931a80340d | 401 | ///@brief Configure Accelerometer.\n |
j3 | 3:e1770675eca4 | 402 | /// |
j3 | 3:e1770675eca4 | 403 | ///On Entry: |
j3 | 12:64931a80340d | 404 | ///@param[in] config - Accelerometer configuration |
j3 | 3:e1770675eca4 | 405 | /// |
j3 | 3:e1770675eca4 | 406 | ///On Exit: |
j3 | 12:64931a80340d | 407 | ///@param[out] none |
j3 | 3:e1770675eca4 | 408 | /// |
j3 | 3:e1770675eca4 | 409 | ///@returns 0 on success, non 0 on failure |
j3 | 12:64931a80340d | 410 | int32_t setAccConfig(const AccConfig &config); |
j3 | 8:a89b529b1d96 | 411 | |
j3 | 8:a89b529b1d96 | 412 | |
j3 | 8:a89b529b1d96 | 413 | ///@brief Get accelerometer axis as float.\n |
j3 | 3:e1770675eca4 | 414 | /// |
j3 | 3:e1770675eca4 | 415 | ///On Entry: |
j3 | 8:a89b529b1d96 | 416 | ///@param[in] axis - Sensor axis |
j3 | 8:a89b529b1d96 | 417 | ///@param[in] data - AxisData structure |
j3 | 12:64931a80340d | 418 | ///@param[in] range - Accelerometer range |
j3 | 8:a89b529b1d96 | 419 | /// |
j3 | 8:a89b529b1d96 | 420 | ///On Exit: |
j3 | 8:a89b529b1d96 | 421 | ///@param[out] data - Structure holds raw and scaled axis data |
j3 | 8:a89b529b1d96 | 422 | /// |
j3 | 8:a89b529b1d96 | 423 | ///@returns 0 on success, non 0 on failure |
j3 | 12:64931a80340d | 424 | int32_t getAccAxis(SensorAxis axis, AxisData &data, AccRange range); |
j3 | 8:a89b529b1d96 | 425 | |
j3 | 8:a89b529b1d96 | 426 | |
j3 | 8:a89b529b1d96 | 427 | ///@brief Get accelerometer xyz axis as float.\n |
j3 | 8:a89b529b1d96 | 428 | /// |
j3 | 8:a89b529b1d96 | 429 | ///On Entry: |
j3 | 8:a89b529b1d96 | 430 | ///@param[in] data - SensorData structure |
j3 | 12:64931a80340d | 431 | ///@param[in] range - Accelerometer range |
j3 | 3:e1770675eca4 | 432 | /// |
j3 | 3:e1770675eca4 | 433 | ///On Exit: |
j3 | 8:a89b529b1d96 | 434 | ///@param[out] data - Structure holds raw and scaled data for all three axis |
j3 | 3:e1770675eca4 | 435 | /// |
j3 | 8:a89b529b1d96 | 436 | ///@returns 0 on success, non 0 on failure |
j3 | 12:64931a80340d | 437 | int32_t getAccXYZ(SensorData &data, AccRange range); |
j3 | 10:9e219f2f1fb3 | 438 | |
j3 | 10:9e219f2f1fb3 | 439 | |
j3 | 10:9e219f2f1fb3 | 440 | ///@brief Get sensor time.\n |
j3 | 10:9e219f2f1fb3 | 441 | /// |
j3 | 10:9e219f2f1fb3 | 442 | ///On Entry: |
j3 | 10:9e219f2f1fb3 | 443 | ///@param[in] data - pointer to float for holding data |
j3 | 10:9e219f2f1fb3 | 444 | /// |
j3 | 10:9e219f2f1fb3 | 445 | ///On Exit: |
j3 | 10:9e219f2f1fb3 | 446 | ///@param[out] data - time in seconds, as float |
j3 | 10:9e219f2f1fb3 | 447 | /// |
j3 | 10:9e219f2f1fb3 | 448 | ///@returns returns 0 on success, non 0 on failure |
j3 | 10:9e219f2f1fb3 | 449 | int32_t getSensorTime(float *data); |
j3 | 12:64931a80340d | 450 | |
j3 | 12:64931a80340d | 451 | |
j3 | 12:64931a80340d | 452 | ///@brief Get die temperature.\n |
j3 | 12:64931a80340d | 453 | /// |
j3 | 12:64931a80340d | 454 | ///On Entry: |
j3 | 12:64931a80340d | 455 | ///@param[in] temp - pointer to float for temperature |
j3 | 12:64931a80340d | 456 | /// |
j3 | 12:64931a80340d | 457 | ///On Exit: |
j3 | 12:64931a80340d | 458 | ///@param[out] temp - on success, holds the die temperature |
j3 | 12:64931a80340d | 459 | /// |
j3 | 12:64931a80340d | 460 | ///@returns 0 on success, non 0 on failure |
j3 | 12:64931a80340d | 461 | int32_t getTemperature(float *temp); |
j3 | 2:598e601e5846 | 462 | }; |
j3 | 2:598e601e5846 | 463 | |
j3 | 2:598e601e5846 | 464 | |
j3 | 2:598e601e5846 | 465 | /** |
j3 | 2:598e601e5846 | 466 | @brief BMI160_I2C - supports BMI160 object with I2C interface |
j3 | 2:598e601e5846 | 467 | */ |
j3 | 2:598e601e5846 | 468 | class BMI160_I2C: public BMI160 |
j3 | 2:598e601e5846 | 469 | { |
j3 | 2:598e601e5846 | 470 | public: |
j3 | 2:598e601e5846 | 471 | |
j3 | 2:598e601e5846 | 472 | ///BMI160 default I2C address. |
j3 | 2:598e601e5846 | 473 | static const uint8_t I2C_ADRS_SDO_LO = 0x68; |
j3 | 2:598e601e5846 | 474 | ///BMI160 optional I2C address. |
j3 | 2:598e601e5846 | 475 | static const uint8_t I2C_ADRS_SDO_HI = 0x69; |
j3 | 0:bb5b832891fb | 476 | |
j3 | 2:598e601e5846 | 477 | |
j3 | 2:598e601e5846 | 478 | ///@brief BMI160_I2C Constructor.\n |
j3 | 0:bb5b832891fb | 479 | /// |
j3 | 0:bb5b832891fb | 480 | ///On Entry: |
j3 | 2:598e601e5846 | 481 | ///@param[in] i2cBus - reference to I2C bus for this device |
j3 | 2:598e601e5846 | 482 | ///@param[in] i2cAdrs - 7-bit I2C address |
j3 | 0:bb5b832891fb | 483 | /// |
j3 | 0:bb5b832891fb | 484 | ///On Exit: |
j3 | 0:bb5b832891fb | 485 | ///@param[out] none |
j3 | 0:bb5b832891fb | 486 | /// |
j3 | 0:bb5b832891fb | 487 | ///@returns none |
j3 | 2:598e601e5846 | 488 | BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs); |
j3 | 2:598e601e5846 | 489 | |
j3 | 2:598e601e5846 | 490 | |
j3 | 2:598e601e5846 | 491 | virtual int32_t readRegister(Registers reg, uint8_t *data); |
j3 | 2:598e601e5846 | 492 | virtual int32_t writeRegister(Registers reg, const uint8_t data); |
j3 | 3:e1770675eca4 | 493 | virtual int32_t readBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 494 | uint8_t *data); |
j3 | 3:e1770675eca4 | 495 | virtual int32_t writeBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 496 | const uint8_t *data); |
j3 | 2:598e601e5846 | 497 | |
j3 | 0:bb5b832891fb | 498 | private: |
j3 | 0:bb5b832891fb | 499 | |
j3 | 0:bb5b832891fb | 500 | I2C m_i2cBus; |
j3 | 0:bb5b832891fb | 501 | uint8_t m_Wadrs, m_Radrs; |
j3 | 0:bb5b832891fb | 502 | }; |
j3 | 0:bb5b832891fb | 503 | |
j3 | 2:598e601e5846 | 504 | |
j3 | 2:598e601e5846 | 505 | /** |
j3 | 2:598e601e5846 | 506 | @brief BMI160_SPI - supports BMI160 object with SPI interface |
j3 | 2:598e601e5846 | 507 | */ |
j3 | 2:598e601e5846 | 508 | class BMI160_SPI: public BMI160 |
j3 | 2:598e601e5846 | 509 | { |
j3 | 2:598e601e5846 | 510 | public: |
j3 | 2:598e601e5846 | 511 | |
j3 | 2:598e601e5846 | 512 | ///@brief BMI160_SPI Constructor.\n |
j3 | 2:598e601e5846 | 513 | /// |
j3 | 2:598e601e5846 | 514 | ///On Entry: |
j3 | 2:598e601e5846 | 515 | ///@param[in] spiBus - reference to SPI bus for this device |
j3 | 2:598e601e5846 | 516 | ///@param[in] cs - reference to DigitalOut used for chip select |
j3 | 2:598e601e5846 | 517 | /// |
j3 | 2:598e601e5846 | 518 | ///On Exit: |
j3 | 2:598e601e5846 | 519 | ///@param[out] none |
j3 | 2:598e601e5846 | 520 | /// |
j3 | 2:598e601e5846 | 521 | ///@returns none |
j3 | 2:598e601e5846 | 522 | BMI160_SPI(SPI &spiBus, DigitalOut &cs); |
j3 | 2:598e601e5846 | 523 | |
j3 | 2:598e601e5846 | 524 | virtual int32_t readRegister(Registers reg, uint8_t *data); |
j3 | 2:598e601e5846 | 525 | virtual int32_t writeRegister(Registers reg, const uint8_t data); |
j3 | 3:e1770675eca4 | 526 | virtual int32_t readBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 527 | uint8_t *data); |
j3 | 3:e1770675eca4 | 528 | virtual int32_t writeBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 529 | const uint8_t *data); |
j3 | 2:598e601e5846 | 530 | |
j3 | 2:598e601e5846 | 531 | private: |
j3 | 2:598e601e5846 | 532 | |
j3 | 2:598e601e5846 | 533 | SPI m_spiBus; |
j3 | 2:598e601e5846 | 534 | DigitalOut m_cs; |
j3 | 2:598e601e5846 | 535 | }; |
j3 | 2:598e601e5846 | 536 | |
j3 | 0:bb5b832891fb | 537 | #endif /* BMI160_H */ |
j3 | 8:a89b529b1d96 | 538 | |
j3 | 8:a89b529b1d96 | 539 | |
j3 | 8:a89b529b1d96 | 540 | ///@brief fx documentation template.\n |
j3 | 8:a89b529b1d96 | 541 | /// |
j3 | 8:a89b529b1d96 | 542 | ///On Entry: |
j3 | 8:a89b529b1d96 | 543 | ///@param[in] none |
j3 | 8:a89b529b1d96 | 544 | /// |
j3 | 8:a89b529b1d96 | 545 | ///On Exit: |
j3 | 8:a89b529b1d96 | 546 | ///@param[out] none |
j3 | 8:a89b529b1d96 | 547 | /// |
j3 | 8:a89b529b1d96 | 548 | ///@returns none |