Library for Bosch Sensortech BMI160 IMU
Dependents: MAX32630FTHR_BALANCE_BOT MPSMAX_copy MAX32630FTHR_BALANCE_BOT SELF_BALANCING_BOT
bmi160.h@15:dc35ccc0b08e, 2016-12-20 (annotated)
- Committer:
- j3
- Date:
- Tue Dec 20 21:20:22 2016 +0000
- Revision:
- 15:dc35ccc0b08e
- Parent:
- 14:646eb94fa2eb
- Child:
- 16:12782f5d4aa4
working
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 | 13:5d132f873b07 | 59 | ///Sensor types |
j3 | 5:35e032c8d8aa | 60 | enum Sensors |
j3 | 5:35e032c8d8aa | 61 | { |
j3 | 5:35e032c8d8aa | 62 | MAG = 0, ///<Optional external sensor |
j3 | 5:35e032c8d8aa | 63 | GYRO, ///<Angular rate sensor |
j3 | 5:35e032c8d8aa | 64 | ACC ///<g sensor |
j3 | 5:35e032c8d8aa | 65 | }; |
j3 | 5:35e032c8d8aa | 66 | |
j3 | 8:a89b529b1d96 | 67 | ///Sensor Axis |
j3 | 8:a89b529b1d96 | 68 | enum SensorAxis |
j3 | 8:a89b529b1d96 | 69 | { |
j3 | 8:a89b529b1d96 | 70 | X_AXIS = 0, |
j3 | 8:a89b529b1d96 | 71 | Y_AXIS, |
j3 | 15:dc35ccc0b08e | 72 | Z_AXIS |
j3 | 8:a89b529b1d96 | 73 | }; |
j3 | 8:a89b529b1d96 | 74 | |
j3 | 8:a89b529b1d96 | 75 | ///Structure for axis data |
j3 | 8:a89b529b1d96 | 76 | struct AxisData |
j3 | 8:a89b529b1d96 | 77 | { |
j3 | 8:a89b529b1d96 | 78 | int16_t raw; ///<Axis raw data |
j3 | 8:a89b529b1d96 | 79 | float scaled; ///<Axis scaled data |
j3 | 8:a89b529b1d96 | 80 | }; |
j3 | 8:a89b529b1d96 | 81 | |
j3 | 15:dc35ccc0b08e | 82 | ///Structure for sensor time data |
j3 | 15:dc35ccc0b08e | 83 | struct SensorTime |
j3 | 15:dc35ccc0b08e | 84 | { |
j3 | 15:dc35ccc0b08e | 85 | uint32_t raw; ///<raw SensorTime |
j3 | 15:dc35ccc0b08e | 86 | float seconds; ///<SensorTime as seconds |
j3 | 15:dc35ccc0b08e | 87 | }; |
j3 | 15:dc35ccc0b08e | 88 | |
j3 | 15:dc35ccc0b08e | 89 | ///Period of internal counter |
j3 | 15:dc35ccc0b08e | 90 | static const float SENSOR_TIME_LSB = 39e-6; |
j3 | 15:dc35ccc0b08e | 91 | |
j3 | 8:a89b529b1d96 | 92 | ///Structure for holding sensor data |
j3 | 8:a89b529b1d96 | 93 | struct SensorData |
j3 | 8:a89b529b1d96 | 94 | { |
j3 | 8:a89b529b1d96 | 95 | AxisData xAxis; ///<Sensor X axis data |
j3 | 8:a89b529b1d96 | 96 | AxisData yAxis; ///<Sensor Y axis data |
j3 | 8:a89b529b1d96 | 97 | AxisData zAxis; ///<Sensor Z axis data |
j3 | 8:a89b529b1d96 | 98 | }; |
j3 | 8:a89b529b1d96 | 99 | |
j3 | 13:5d132f873b07 | 100 | |
j3 | 1:a4c911640569 | 101 | ///BMI160 registers |
j3 | 0:bb5b832891fb | 102 | enum Registers |
j3 | 0:bb5b832891fb | 103 | { |
j3 | 3:e1770675eca4 | 104 | CHIP_ID = 0x00, ///<Chip Identification. |
j3 | 3:e1770675eca4 | 105 | ERR_REG = 0x02, ///<Reports sensor error flags. Flags reset when read. |
j3 | 3:e1770675eca4 | 106 | PMU_STATUS, ///<Reports current power mode for sensors. |
j3 | 3:e1770675eca4 | 107 | DATA_0, ///<MAG_X axis bits7:0 |
j3 | 3:e1770675eca4 | 108 | DATA_1, ///<MAG_X axis bits15:8 |
j3 | 3:e1770675eca4 | 109 | DATA_2, ///<MAG_Y axis bits7:0 |
j3 | 3:e1770675eca4 | 110 | DATA_3, ///<MAG_Y axis bits15:8 |
j3 | 3:e1770675eca4 | 111 | DATA_4, ///<MAG_Z axis bits7:0 |
j3 | 3:e1770675eca4 | 112 | DATA_5, ///<MAG_Z axis bits15:8 |
j3 | 3:e1770675eca4 | 113 | DATA_6, ///<RHALL bits7:0 |
j3 | 3:e1770675eca4 | 114 | DATA_7, ///<RHALL bits15:8 |
j3 | 3:e1770675eca4 | 115 | DATA_8, ///<GYR_X axis bits7:0 |
j3 | 3:e1770675eca4 | 116 | DATA_9, ///<GYR_X axis bits15:8 |
j3 | 3:e1770675eca4 | 117 | DATA_10, ///<GYR_Y axis bits7:0 |
j3 | 3:e1770675eca4 | 118 | DATA_11, ///<GYR_Y axis bits15:8 |
j3 | 3:e1770675eca4 | 119 | DATA_12, ///<GYR_Z axis bits7:0 |
j3 | 3:e1770675eca4 | 120 | DATA_13, ///<GYR_Z axis bits15:8 |
j3 | 3:e1770675eca4 | 121 | DATA_14, ///<ACC_X axis bits7:0 |
j3 | 3:e1770675eca4 | 122 | DATA_15, ///<ACC_X axis bits15:8 |
j3 | 3:e1770675eca4 | 123 | DATA_16, ///<ACC_Y axis bits7:0 |
j3 | 3:e1770675eca4 | 124 | DATA_17, ///<ACC_Y axis bits15:8 |
j3 | 3:e1770675eca4 | 125 | DATA_18, ///<ACC_Z axis bits7:0 |
j3 | 3:e1770675eca4 | 126 | DATA_19, ///<ACC_Z axis bits15:8 |
j3 | 3:e1770675eca4 | 127 | SENSORTIME_0, ///<24bit counter synchronized with data, bits7:0 |
j3 | 3:e1770675eca4 | 128 | SENSORTIME_1, ///<24bit counter synchronized with data, bits15:8 |
j3 | 3:e1770675eca4 | 129 | SENSORTIME_2, ///<24bit counter synchronized with data, bits23:16 |
j3 | 3:e1770675eca4 | 130 | STATUS, ///<Reports sensors status flags |
j3 | 3:e1770675eca4 | 131 | INT_STATUS_0, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 132 | INT_STATUS_1, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 133 | INT_STATUS_2, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 134 | INT_STATUS_3, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 135 | TEMPERATURE_0, ///<Contains temperature of sensor, bits7:0 |
j3 | 3:e1770675eca4 | 136 | TEMPERATURE_1, ///<Contains temperature of sensor, bits15:8 |
j3 | 3:e1770675eca4 | 137 | FIFO_LENGTH_0, ///<Current fill level of FIFO, bits7:0 |
j3 | 3:e1770675eca4 | 138 | FIFO_LENGTH_1, ///<Current fill level of FIFO, bits10:8 |
j3 | 3:e1770675eca4 | 139 | FIFO_DATA, ///<FIFO data read out register, burst read |
j3 | 3:e1770675eca4 | 140 | ACC_CONF = 0x40, ///<Set ODR, bandwidth, and read mode of accelerometer |
j3 | 3:e1770675eca4 | 141 | ACC_RANGE, ///<Sets accelerometer g-range |
j3 | 3:e1770675eca4 | 142 | GYR_CONF, ///<Set ODR, bandwidth, and read mode of gyroscope |
j3 | 3:e1770675eca4 | 143 | GYR_RANGE, ///<Sets gyroscope angular rate measurement range |
j3 | 3:e1770675eca4 | 144 | MAG_CONF, ///<Sets ODR of magnetometer interface |
j3 | 3:e1770675eca4 | 145 | FIFO_DOWNS, ///<Sets down sampling ratios of accel and gyro data |
j3 | 3:e1770675eca4 | 146 | ///<for FIFO |
j3 | 3:e1770675eca4 | 147 | FIFO_CONFIG_0, ///<Sets FIFO Watermark |
j3 | 3:e1770675eca4 | 148 | FIFO_CONFIG_1, ///<Sets which sensor data is available in FIFO, |
j3 | 3:e1770675eca4 | 149 | ///<Header/Headerless mode, Ext Int tagging, Sensortime |
j3 | 3:e1770675eca4 | 150 | MAG_IF_0 = 0x4B, ///<Magnetometer 7-bit I2C address, bits7:1 |
j3 | 3:e1770675eca4 | 151 | MAG_IF_1, ///<Magnetometer interface configuration |
j3 | 3:e1770675eca4 | 152 | MAG_IF_2, ///<Magnetometer address to read |
j3 | 3:e1770675eca4 | 153 | MAG_IF_3, ///<Magnetometer address to write |
j3 | 3:e1770675eca4 | 154 | MAG_IF_4, ///<Magnetometer data to write |
j3 | 3:e1770675eca4 | 155 | INT_EN_0, ///<Interrupt enable bits |
j3 | 3:e1770675eca4 | 156 | INT_EN_1, ///<Interrupt enable bits |
j3 | 3:e1770675eca4 | 157 | INT_EN_2, ///<Interrupt enable bits |
j3 | 3:e1770675eca4 | 158 | INT_OUT_CTRL, ///<Contains the behavioral configuration of INT pins |
j3 | 3:e1770675eca4 | 159 | INT_LATCH, ///<Contains the interrupt rest bit and the interrupt |
j3 | 3:e1770675eca4 | 160 | ///<mode selection |
j3 | 3:e1770675eca4 | 161 | INT_MAP_0, ///<Controls which interrupt signals are mapped to the |
j3 | 3:e1770675eca4 | 162 | ///<INT1 and INT2 pins |
j3 | 3:e1770675eca4 | 163 | INT_MAP_1, ///<Controls which interrupt signals are mapped to the |
j3 | 3:e1770675eca4 | 164 | ///<INT1 and INT2 pins |
j3 | 3:e1770675eca4 | 165 | INT_MAP_2, ///<Controls which interrupt signals are mapped to the |
j3 | 3:e1770675eca4 | 166 | ///<INT1 and INT2 pins |
j3 | 3:e1770675eca4 | 167 | INT_DATA_0, ///<Contains the data source definition for the two |
j3 | 3:e1770675eca4 | 168 | ///<interrupt groups |
j3 | 3:e1770675eca4 | 169 | INT_DATA_1, ///<Contains the data source definition for the two |
j3 | 3:e1770675eca4 | 170 | ///<interrupt groups |
j3 | 3:e1770675eca4 | 171 | INT_LOWHIGH_0, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 172 | INT_LOWHIGH_1, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 173 | INT_LOWHIGH_2, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 174 | INT_LOWHIGH_3, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 175 | INT_LOWHIGH_4, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 176 | INT_MOTION_0, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 177 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 178 | INT_MOTION_1, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 179 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 180 | INT_MOTION_2, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 181 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 182 | INT_MOTION_3, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 183 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 184 | INT_TAP_0, ///<Contains the configuration for the tap interrupts |
j3 | 3:e1770675eca4 | 185 | INT_TAP_1, ///<Contains the configuration for the tap interrupts |
j3 | 3:e1770675eca4 | 186 | INT_ORIENT_0, ///<Contains the configuration for the oeientation |
j3 | 3:e1770675eca4 | 187 | ///<interrupt |
j3 | 3:e1770675eca4 | 188 | INT_ORIENT_1, ///<Contains the configuration for the oeientation |
j3 | 3:e1770675eca4 | 189 | ///<interrupt |
j3 | 3:e1770675eca4 | 190 | INT_FLAT_0, ///<Contains the configuration for the flat interrupt |
j3 | 3:e1770675eca4 | 191 | INT_FLAT_1, ///<Contains the configuration for the flat interrupt |
j3 | 3:e1770675eca4 | 192 | FOC_CONF, ///<Contains configuration for the fast offset |
j3 | 3:e1770675eca4 | 193 | ///<compensation for the accelerometer and gyroscope |
j3 | 3:e1770675eca4 | 194 | CONF, ///<Configuration of sensor, nvm_prog_en bit |
j3 | 3:e1770675eca4 | 195 | IF_CONF, ///<Contains settings for the digital interface |
j3 | 3:e1770675eca4 | 196 | PMU_TRIGGER, ///<Sets trigger conditions to change gyro power modes |
j3 | 3:e1770675eca4 | 197 | SELF_TEST, ///<Self test configuration |
j3 | 3:e1770675eca4 | 198 | NV_CONF = 0x70, ///<Contains settings for the digital interface |
j3 | 3:e1770675eca4 | 199 | OFFSET_0, ///<Contains offset comp values for acc_off_x7:0 |
j3 | 3:e1770675eca4 | 200 | OFFSET_1, ///<Contains offset comp values for acc_off_y7:0 |
j3 | 3:e1770675eca4 | 201 | OFFSET_2, ///<Contains offset comp values for acc_off_z7:0 |
j3 | 3:e1770675eca4 | 202 | OFFSET_3, ///<Contains offset comp values for gyr_off_x7:0 |
j3 | 3:e1770675eca4 | 203 | OFFSET_4, ///<Contains offset comp values for gyr_off_y7:0 |
j3 | 3:e1770675eca4 | 204 | OFFSET_5, ///<Contains offset comp values for gyr_off_z7:0 |
j3 | 3:e1770675eca4 | 205 | OFFSET_6, ///<gyr/acc offset enable bit and gyr_off_(zyx) bits9:8 |
j3 | 3:e1770675eca4 | 206 | STEP_CNT_0, ///<Step counter bits 15:8 |
j3 | 3:e1770675eca4 | 207 | STEP_CNT_1, ///<Step counter bits 7:0 |
j3 | 3:e1770675eca4 | 208 | STEP_CONF_0, ///<Contains configuration of the step detector |
j3 | 3:e1770675eca4 | 209 | STEP_CONF_1, ///<Contains configuration of the step detector |
j3 | 3:e1770675eca4 | 210 | CMD = 0x7E ///<Command register triggers operations like |
j3 | 3:e1770675eca4 | 211 | ///<softreset, NVM programming, etc. |
j3 | 3:e1770675eca4 | 212 | }; |
j3 | 3:e1770675eca4 | 213 | |
j3 | 8:a89b529b1d96 | 214 | |
j3 | 13:5d132f873b07 | 215 | ///@name ERR_REG(0x02) |
j3 | 13:5d132f873b07 | 216 | ///Error register data |
j3 | 12:64931a80340d | 217 | ///@{ |
j3 | 13:5d132f873b07 | 218 | |
j3 | 14:646eb94fa2eb | 219 | static const uint8_t FATAL_ERR_MASK = 0x01; |
j3 | 14:646eb94fa2eb | 220 | static const uint8_t FATAL_ERR_POS = 0x00; |
j3 | 14:646eb94fa2eb | 221 | static const uint8_t ERR_CODE_MASK = 0x1E; |
j3 | 14:646eb94fa2eb | 222 | static const uint8_t ERR_CODE_POS = 0x01; |
j3 | 14:646eb94fa2eb | 223 | static const uint8_t I2C_FAIL_ERR_MASK = 0x20; |
j3 | 14:646eb94fa2eb | 224 | static const uint8_t I2C_FAIL_ERR_POS = 0x05; |
j3 | 14:646eb94fa2eb | 225 | static const uint8_t DROP_CMD_ERR_MASK = 0x40; |
j3 | 14:646eb94fa2eb | 226 | static const uint8_t DROP_CMD_ERR_POS = 0x06; |
j3 | 14:646eb94fa2eb | 227 | static const uint8_t MAG_DRDY_ERR_MASK = 0x80; |
j3 | 14:646eb94fa2eb | 228 | static const uint8_t MAG_DRDY_ERR_POS = 0x08; |
j3 | 3:e1770675eca4 | 229 | |
j3 | 13:5d132f873b07 | 230 | ///Enumerated error codes |
j3 | 3:e1770675eca4 | 231 | enum ErrorCodes |
j3 | 3:e1770675eca4 | 232 | { |
j3 | 3:e1770675eca4 | 233 | NO_ERROR = 0, ///<No Error |
j3 | 3:e1770675eca4 | 234 | ERROR_1, ///<Listed as error |
j3 | 3:e1770675eca4 | 235 | ERROR_2, ///<Listed as error |
j3 | 3:e1770675eca4 | 236 | LPM_INT_PFD, ///<Low-power mode and interrupt uses pre-filtered |
j3 | 3:e1770675eca4 | 237 | ///<data |
j3 | 4:ebac8c8f6347 | 238 | ODR_MISMATCH = 0x06, ///<ODRs of enabled sensors in headerless mode do |
j3 | 4:ebac8c8f6347 | 239 | ///<not match |
j3 | 3:e1770675eca4 | 240 | PFD_USED_LPM ///<Pre-filtered data are used in low power mode |
j3 | 0:bb5b832891fb | 241 | }; |
j3 | 12:64931a80340d | 242 | ///@} |
j3 | 0:bb5b832891fb | 243 | |
j3 | 8:a89b529b1d96 | 244 | |
j3 | 13:5d132f873b07 | 245 | ///@name ACC_CONF(0x40) and ACC_RANGE(0x41) |
j3 | 13:5d132f873b07 | 246 | ///Data for configuring accelerometer |
j3 | 12:64931a80340d | 247 | ///@{ |
j3 | 13:5d132f873b07 | 248 | |
j3 | 13:5d132f873b07 | 249 | static const uint8_t ACC_ODR_MASK = 0x0F; |
j3 | 13:5d132f873b07 | 250 | static const uint8_t ACC_ODR_POS = 0x00; |
j3 | 13:5d132f873b07 | 251 | static const uint8_t ACC_BWP_MASK = 0x70; |
j3 | 12:64931a80340d | 252 | static const uint8_t ACC_BWP_POS = 0x04; |
j3 | 13:5d132f873b07 | 253 | static const uint8_t ACC_US_MASK = 0x80; |
j3 | 12:64931a80340d | 254 | static const uint8_t ACC_US_POS = 0x07; |
j3 | 14:646eb94fa2eb | 255 | static const uint8_t ACC_RANGE_MASK = 0x0F; |
j3 | 14:646eb94fa2eb | 256 | static const uint8_t ACC_RANGE_POS = 0x00; |
j3 | 8:a89b529b1d96 | 257 | |
j3 | 13:5d132f873b07 | 258 | ///Accelerometer output data rates |
j3 | 8:a89b529b1d96 | 259 | enum AccOutPutDataRate |
j3 | 8:a89b529b1d96 | 260 | { |
j3 | 8:a89b529b1d96 | 261 | ACC_ODR_1 = 1, ///< 25/32Hz |
j3 | 8:a89b529b1d96 | 262 | ACC_ODR_2, ///< 25/16Hz |
j3 | 8:a89b529b1d96 | 263 | ACC_ODR_3, ///< 25/8Hz |
j3 | 8:a89b529b1d96 | 264 | ACC_ODR_4, ///< 25/4Hz |
j3 | 8:a89b529b1d96 | 265 | ACC_ODR_5, ///< 25/2Hz |
j3 | 8:a89b529b1d96 | 266 | ACC_ODR_6, ///< 25Hz |
j3 | 8:a89b529b1d96 | 267 | ACC_ODR_7, ///< 50Hz |
j3 | 8:a89b529b1d96 | 268 | ACC_ODR_8, ///< 100Hz |
j3 | 8:a89b529b1d96 | 269 | ACC_ODR_9, ///< 200Hz |
j3 | 8:a89b529b1d96 | 270 | ACC_ODR_10, ///< 400Hz |
j3 | 8:a89b529b1d96 | 271 | ACC_ODR_11, ///< 800Hz |
j3 | 8:a89b529b1d96 | 272 | ACC_ODR_12 ///< 1600Hz |
j3 | 8:a89b529b1d96 | 273 | }; |
j3 | 8:a89b529b1d96 | 274 | |
j3 | 13:5d132f873b07 | 275 | ///Accelerometer bandwidth parameters |
j3 | 8:a89b529b1d96 | 276 | enum AccBandWidthParam |
j3 | 8:a89b529b1d96 | 277 | { |
j3 | 8:a89b529b1d96 | 278 | ACC_BWP_0 = 0, ///< Average 1 cycle |
j3 | 8:a89b529b1d96 | 279 | ACC_BWP_1, ///< Average 2 cycles |
j3 | 8:a89b529b1d96 | 280 | ACC_BWP_2, ///< Average 4 cycles, use this setting when acc_us = 0 |
j3 | 8:a89b529b1d96 | 281 | ACC_BWP_3, ///< Average 8 cycles |
j3 | 8:a89b529b1d96 | 282 | ACC_BWP_4, ///< Average 16 cycles |
j3 | 8:a89b529b1d96 | 283 | ACC_BWP_5, ///< Average 32 cycles |
j3 | 8:a89b529b1d96 | 284 | ACC_BWP_6, ///< Average 64 cycles |
j3 | 8:a89b529b1d96 | 285 | ACC_BWP_7 ///< Average 128 cycles |
j3 | 8:a89b529b1d96 | 286 | }; |
j3 | 8:a89b529b1d96 | 287 | |
j3 | 13:5d132f873b07 | 288 | ///Accelerometer undersampling |
j3 | 8:a89b529b1d96 | 289 | enum AccUnderSampling |
j3 | 8:a89b529b1d96 | 290 | { |
j3 | 8:a89b529b1d96 | 291 | ACC_US_OFF = 0, |
j3 | 8:a89b529b1d96 | 292 | ACC_US_ON |
j3 | 8:a89b529b1d96 | 293 | }; |
j3 | 8:a89b529b1d96 | 294 | |
j3 | 13:5d132f873b07 | 295 | ///Accelerometer ranges |
j3 | 8:a89b529b1d96 | 296 | enum AccRange |
j3 | 8:a89b529b1d96 | 297 | { |
j3 | 15:dc35ccc0b08e | 298 | SENS_2G = 0x03, ///<Accelerometer range +-2G |
j3 | 15:dc35ccc0b08e | 299 | SENS_4G = 0x05, ///<Accelerometer range +-4G |
j3 | 15:dc35ccc0b08e | 300 | SENS_8G = 0x08, ///<Accelerometer range +-8G |
j3 | 15:dc35ccc0b08e | 301 | SENS_16G = 0x0C, ///<Accelerometer range +-16G |
j3 | 8:a89b529b1d96 | 302 | }; |
j3 | 8:a89b529b1d96 | 303 | |
j3 | 15:dc35ccc0b08e | 304 | static const float SENS_2G_LSB_PER_G = 16384.0F; |
j3 | 15:dc35ccc0b08e | 305 | static const float SENS_4G_LSB_PER_G = 8192.0F; |
j3 | 15:dc35ccc0b08e | 306 | static const float SENS_8G_LSB_PER_G = 4096.0F; |
j3 | 15:dc35ccc0b08e | 307 | static const float SENS_16G_LSB_PER_G = 2048.0F; |
j3 | 15:dc35ccc0b08e | 308 | |
j3 | 13:5d132f873b07 | 309 | ///Accelerometer configuration data structure |
j3 | 9:ca6b5fecdd63 | 310 | struct AccConfig |
j3 | 9:ca6b5fecdd63 | 311 | { |
j3 | 14:646eb94fa2eb | 312 | AccRange range; ///<Accelerometer range |
j3 | 14:646eb94fa2eb | 313 | AccUnderSampling us; ///<Accelerometr undersampling mode |
j3 | 14:646eb94fa2eb | 314 | AccBandWidthParam bwp; ///<Accelerometer bandwidth param |
j3 | 14:646eb94fa2eb | 315 | AccOutPutDataRate odr; ///<Accelerometr output data rate |
j3 | 9:ca6b5fecdd63 | 316 | }; |
j3 | 9:ca6b5fecdd63 | 317 | |
j3 | 13:5d132f873b07 | 318 | ///Accelerometer default configuration |
j3 | 9:ca6b5fecdd63 | 319 | static const AccConfig DEFAULT_ACC_CONFIG; |
j3 | 12:64931a80340d | 320 | ///@} |
j3 | 9:ca6b5fecdd63 | 321 | |
j3 | 12:64931a80340d | 322 | |
j3 | 14:646eb94fa2eb | 323 | ///@name GYR_CONF(0x42) and GYR_RANGE(0x43) |
j3 | 14:646eb94fa2eb | 324 | ///Data for configuring gyroscope |
j3 | 14:646eb94fa2eb | 325 | ///@{ |
j3 | 14:646eb94fa2eb | 326 | |
j3 | 14:646eb94fa2eb | 327 | ///@} |
j3 | 14:646eb94fa2eb | 328 | |
j3 | 14:646eb94fa2eb | 329 | |
j3 | 13:5d132f873b07 | 330 | ///Enumerated power modes |
j3 | 4:ebac8c8f6347 | 331 | enum PowerModes |
j3 | 4:ebac8c8f6347 | 332 | { |
j3 | 4:ebac8c8f6347 | 333 | SUSPEND = 0, ///<Acc and Gyro, No sampling, No FIFO data readout |
j3 | 4:ebac8c8f6347 | 334 | NORMAL, ///<Acc and Gyro, Full chip operation |
j3 | 4:ebac8c8f6347 | 335 | LOW_POWER, ///<Acc duty-cycling between suspend and normal |
j3 | 4:ebac8c8f6347 | 336 | FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms |
j3 | 4:ebac8c8f6347 | 337 | }; |
j3 | 4:ebac8c8f6347 | 338 | |
j3 | 12:64931a80340d | 339 | |
j3 | 13:5d132f873b07 | 340 | ///Enumerated commands used with CMD register |
j3 | 5:35e032c8d8aa | 341 | enum Commands |
j3 | 5:35e032c8d8aa | 342 | { |
j3 | 5:35e032c8d8aa | 343 | START_FOC = 0x03, ///<Starts Fast Offset Calibrartion |
j3 | 7:9848196cb65e | 344 | ACC_SET_PMU_MODE = 0x10, ///<Sets acc power mode |
j3 | 8:a89b529b1d96 | 345 | GYR_SET_PMU_MODE = 0x14, ///<Sets gyro power mode |
j3 | 8:a89b529b1d96 | 346 | MAG_SET_PMU_MODE = 0x18, ///<Sets mag power mode |
j3 | 5:35e032c8d8aa | 347 | PROG_NVM = 0xA0, ///<Writes NVM backed registers into NVM |
j3 | 5:35e032c8d8aa | 348 | FIFO_FLUSH = 0xB0, ///<Clears FIFO |
j3 | 5:35e032c8d8aa | 349 | INT_RESET, ///<Clears interrupt engine, INT_STATUS, and |
j3 | 5:35e032c8d8aa | 350 | ///<the interrupt pin |
j3 | 5:35e032c8d8aa | 351 | STEP_CNT_CLR, ///<Triggers reset of the step counter |
j3 | 5:35e032c8d8aa | 352 | SOFT_RESET = 0xB6 ///<Triggers a reset including a reboot. |
j3 | 5:35e032c8d8aa | 353 | }; |
j3 | 5:35e032c8d8aa | 354 | |
j3 | 0:bb5b832891fb | 355 | |
j3 | 0:bb5b832891fb | 356 | ///@brief BMI160 Destructor.\n |
j3 | 0:bb5b832891fb | 357 | /// |
j3 | 0:bb5b832891fb | 358 | ///On Entry: |
j3 | 0:bb5b832891fb | 359 | ///@param[in] none |
j3 | 0:bb5b832891fb | 360 | /// |
j3 | 0:bb5b832891fb | 361 | ///On Exit: |
j3 | 0:bb5b832891fb | 362 | ///@param[out] none |
j3 | 0:bb5b832891fb | 363 | /// |
j3 | 0:bb5b832891fb | 364 | ///@returns none |
j3 | 2:598e601e5846 | 365 | virtual ~BMI160(){ } |
j3 | 0:bb5b832891fb | 366 | |
j3 | 0:bb5b832891fb | 367 | |
j3 | 0:bb5b832891fb | 368 | ///@brief Reads a single register.\n |
j3 | 0:bb5b832891fb | 369 | /// |
j3 | 0:bb5b832891fb | 370 | ///On Entry: |
j3 | 0:bb5b832891fb | 371 | ///@param[in] data - pointer to memory for storing read data |
j3 | 0:bb5b832891fb | 372 | /// |
j3 | 0:bb5b832891fb | 373 | ///On Exit: |
j3 | 0:bb5b832891fb | 374 | ///@param[out] data - holds contents of read register on success |
j3 | 0:bb5b832891fb | 375 | /// |
j3 | 0:bb5b832891fb | 376 | ///@returns 0 on success, non 0 on failure |
j3 | 2:598e601e5846 | 377 | virtual int32_t readRegister(Registers reg, uint8_t *data) = 0; |
j3 | 0:bb5b832891fb | 378 | |
j3 | 0:bb5b832891fb | 379 | |
j3 | 0:bb5b832891fb | 380 | ///@brief Writes a single register.\n |
j3 | 0:bb5b832891fb | 381 | /// |
j3 | 0:bb5b832891fb | 382 | ///On Entry: |
j3 | 0:bb5b832891fb | 383 | ///@param[in] data - data to write to register |
j3 | 0:bb5b832891fb | 384 | /// |
j3 | 0:bb5b832891fb | 385 | ///On Exit: |
j3 | 0:bb5b832891fb | 386 | ///@param[out] none |
j3 | 0:bb5b832891fb | 387 | /// |
j3 | 0:bb5b832891fb | 388 | ///@returns 0 on success, non 0 on failure |
j3 | 2:598e601e5846 | 389 | virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0; |
j3 | 0:bb5b832891fb | 390 | |
j3 | 0:bb5b832891fb | 391 | |
j3 | 0:bb5b832891fb | 392 | ///@brief Reads a block of registers.\n |
j3 | 0:bb5b832891fb | 393 | ///@detail User must ensure that all registers between 'startReg' and |
j3 | 0:bb5b832891fb | 394 | ///'stopReg' exist and are readable. Function reads up to, including, |
j3 | 0:bb5b832891fb | 395 | ///'stopReg'.\n |
j3 | 0:bb5b832891fb | 396 | /// |
j3 | 0:bb5b832891fb | 397 | ///On Entry: |
j3 | 0:bb5b832891fb | 398 | ///@param[in] startReg - register to start reading from |
j3 | 0:bb5b832891fb | 399 | ///@param[in] stopReg - register to stop reading from |
j3 | 0:bb5b832891fb | 400 | ///@param[in] data - pointer to memory for storing read data |
j3 | 0:bb5b832891fb | 401 | /// |
j3 | 0:bb5b832891fb | 402 | ///On Exit: |
j3 | 0:bb5b832891fb | 403 | ///@param[out] data - holds contents of read registers on success |
j3 | 0:bb5b832891fb | 404 | /// |
j3 | 0:bb5b832891fb | 405 | ///@returns 0 on success, non 0 on failure |
j3 | 3:e1770675eca4 | 406 | virtual int32_t readBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 407 | uint8_t *data) = 0; |
j3 | 0:bb5b832891fb | 408 | |
j3 | 0:bb5b832891fb | 409 | |
j3 | 0:bb5b832891fb | 410 | ///@brief Writes a block of registers.\n |
j3 | 0:bb5b832891fb | 411 | ///@detail User must ensure that all registers between 'startReg' and |
j3 | 0:bb5b832891fb | 412 | ///'stopReg' exist and are writeable. Function writes up to, including, |
j3 | 0:bb5b832891fb | 413 | ///'stopReg'.\n |
j3 | 0:bb5b832891fb | 414 | /// |
j3 | 0:bb5b832891fb | 415 | ///On Entry: |
j3 | 0:bb5b832891fb | 416 | ///@param[in] startReg - register to start writing at |
j3 | 0:bb5b832891fb | 417 | ///@param[in] stopReg - register to stop writing at |
j3 | 0:bb5b832891fb | 418 | ///@param[in] data - pointer to data to write to registers |
j3 | 0:bb5b832891fb | 419 | /// |
j3 | 0:bb5b832891fb | 420 | ///On Exit: |
j3 | 0:bb5b832891fb | 421 | ///@param[out] none |
j3 | 0:bb5b832891fb | 422 | /// |
j3 | 0:bb5b832891fb | 423 | ///@returns 0 on success, non 0 on failure |
j3 | 3:e1770675eca4 | 424 | virtual int32_t writeBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 425 | const uint8_t *data) = 0; |
j3 | 3:e1770675eca4 | 426 | |
j3 | 3:e1770675eca4 | 427 | |
j3 | 5:35e032c8d8aa | 428 | ///@brief Sets sensors power mode through CMD register.\n |
j3 | 5:35e032c8d8aa | 429 | ///@details Observe command execution times given in datasheet.\n |
j3 | 5:35e032c8d8aa | 430 | /// |
j3 | 5:35e032c8d8aa | 431 | ///On Entry: |
j3 | 5:35e032c8d8aa | 432 | ///@param[in] sensor - Sensor which power mode we are setting |
j3 | 5:35e032c8d8aa | 433 | ///@param[in] pwrMode - Desired powermode of the sensor |
j3 | 5:35e032c8d8aa | 434 | /// |
j3 | 5:35e032c8d8aa | 435 | ///On Exit: |
j3 | 5:35e032c8d8aa | 436 | ///@param[out] |
j3 | 5:35e032c8d8aa | 437 | /// |
j3 | 5:35e032c8d8aa | 438 | ///@returns 0 on success, non 0 on failure |
j3 | 5:35e032c8d8aa | 439 | int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode); |
j3 | 5:35e032c8d8aa | 440 | |
j3 | 5:35e032c8d8aa | 441 | |
j3 | 12:64931a80340d | 442 | ///@brief Configure Accelerometer.\n |
j3 | 3:e1770675eca4 | 443 | /// |
j3 | 3:e1770675eca4 | 444 | ///On Entry: |
j3 | 12:64931a80340d | 445 | ///@param[in] config - Accelerometer configuration |
j3 | 3:e1770675eca4 | 446 | /// |
j3 | 3:e1770675eca4 | 447 | ///On Exit: |
j3 | 12:64931a80340d | 448 | ///@param[out] none |
j3 | 3:e1770675eca4 | 449 | /// |
j3 | 3:e1770675eca4 | 450 | ///@returns 0 on success, non 0 on failure |
j3 | 12:64931a80340d | 451 | int32_t setAccConfig(const AccConfig &config); |
j3 | 8:a89b529b1d96 | 452 | |
j3 | 8:a89b529b1d96 | 453 | |
j3 | 14:646eb94fa2eb | 454 | ///@brief Get accelerometer configuration.\n |
j3 | 14:646eb94fa2eb | 455 | /// |
j3 | 14:646eb94fa2eb | 456 | ///On Entry: |
j3 | 14:646eb94fa2eb | 457 | ///@param[in] config - Accelerometer configuration data structure |
j3 | 14:646eb94fa2eb | 458 | /// |
j3 | 14:646eb94fa2eb | 459 | ///On Exit: |
j3 | 14:646eb94fa2eb | 460 | ///@param[out] config - on success, holds accelerometer's current |
j3 | 14:646eb94fa2eb | 461 | ///configuration |
j3 | 14:646eb94fa2eb | 462 | /// |
j3 | 14:646eb94fa2eb | 463 | ///@returns 0 on success, non 0 on failure |
j3 | 14:646eb94fa2eb | 464 | int32_t getAccConfig(AccConfig &config); |
j3 | 14:646eb94fa2eb | 465 | |
j3 | 14:646eb94fa2eb | 466 | |
j3 | 8:a89b529b1d96 | 467 | ///@brief Get accelerometer axis as float.\n |
j3 | 3:e1770675eca4 | 468 | /// |
j3 | 3:e1770675eca4 | 469 | ///On Entry: |
j3 | 8:a89b529b1d96 | 470 | ///@param[in] axis - Sensor axis |
j3 | 8:a89b529b1d96 | 471 | ///@param[in] data - AxisData structure |
j3 | 12:64931a80340d | 472 | ///@param[in] range - Accelerometer range |
j3 | 8:a89b529b1d96 | 473 | /// |
j3 | 8:a89b529b1d96 | 474 | ///On Exit: |
j3 | 8:a89b529b1d96 | 475 | ///@param[out] data - Structure holds raw and scaled axis data |
j3 | 8:a89b529b1d96 | 476 | /// |
j3 | 8:a89b529b1d96 | 477 | ///@returns 0 on success, non 0 on failure |
j3 | 12:64931a80340d | 478 | int32_t getAccAxis(SensorAxis axis, AxisData &data, AccRange range); |
j3 | 8:a89b529b1d96 | 479 | |
j3 | 8:a89b529b1d96 | 480 | |
j3 | 8:a89b529b1d96 | 481 | ///@brief Get accelerometer xyz axis as float.\n |
j3 | 8:a89b529b1d96 | 482 | /// |
j3 | 8:a89b529b1d96 | 483 | ///On Entry: |
j3 | 8:a89b529b1d96 | 484 | ///@param[in] data - SensorData structure |
j3 | 12:64931a80340d | 485 | ///@param[in] range - Accelerometer range |
j3 | 3:e1770675eca4 | 486 | /// |
j3 | 3:e1770675eca4 | 487 | ///On Exit: |
j3 | 8:a89b529b1d96 | 488 | ///@param[out] data - Structure holds raw and scaled data for all three axis |
j3 | 3:e1770675eca4 | 489 | /// |
j3 | 8:a89b529b1d96 | 490 | ///@returns 0 on success, non 0 on failure |
j3 | 15:dc35ccc0b08e | 491 | int32_t getAccXYZ(SensorData &data, AccRange range); |
j3 | 15:dc35ccc0b08e | 492 | |
j3 | 15:dc35ccc0b08e | 493 | |
j3 | 15:dc35ccc0b08e | 494 | ///@brief Get accelerometer xyz axis and sensor time.\n |
j3 | 15:dc35ccc0b08e | 495 | /// |
j3 | 15:dc35ccc0b08e | 496 | ///On Entry: |
j3 | 15:dc35ccc0b08e | 497 | ///@param[in] data - SensorData structure |
j3 | 15:dc35ccc0b08e | 498 | ///@param[in] sensorTime - SensorTime structure for data |
j3 | 15:dc35ccc0b08e | 499 | ///@param[in] range - Accelerometer range |
j3 | 15:dc35ccc0b08e | 500 | /// |
j3 | 15:dc35ccc0b08e | 501 | ///On Exit: |
j3 | 15:dc35ccc0b08e | 502 | ///@param[out] data - Structure holds raw and scaled data for all three axis |
j3 | 15:dc35ccc0b08e | 503 | ///@param[out] sensorTime - Holds sensor time on success |
j3 | 15:dc35ccc0b08e | 504 | /// |
j3 | 15:dc35ccc0b08e | 505 | ///@returns 0 on success, non 0 on failure |
j3 | 15:dc35ccc0b08e | 506 | int32_t getAccXYZandSensorTime(SensorData &data, SensorTime &sensorTime, AccRange range); |
j3 | 10:9e219f2f1fb3 | 507 | |
j3 | 10:9e219f2f1fb3 | 508 | |
j3 | 10:9e219f2f1fb3 | 509 | ///@brief Get sensor time.\n |
j3 | 10:9e219f2f1fb3 | 510 | /// |
j3 | 10:9e219f2f1fb3 | 511 | ///On Entry: |
j3 | 15:dc35ccc0b08e | 512 | ///@param[in] sensorTime - SensorTime structure for data |
j3 | 10:9e219f2f1fb3 | 513 | /// |
j3 | 10:9e219f2f1fb3 | 514 | ///On Exit: |
j3 | 15:dc35ccc0b08e | 515 | ///@param[out] sensorTime - Holds sensor time on success |
j3 | 10:9e219f2f1fb3 | 516 | /// |
j3 | 10:9e219f2f1fb3 | 517 | ///@returns returns 0 on success, non 0 on failure |
j3 | 15:dc35ccc0b08e | 518 | int32_t getSensorTime(SensorTime &sensorTime); |
j3 | 12:64931a80340d | 519 | |
j3 | 12:64931a80340d | 520 | |
j3 | 12:64931a80340d | 521 | ///@brief Get die temperature.\n |
j3 | 12:64931a80340d | 522 | /// |
j3 | 12:64931a80340d | 523 | ///On Entry: |
j3 | 12:64931a80340d | 524 | ///@param[in] temp - pointer to float for temperature |
j3 | 12:64931a80340d | 525 | /// |
j3 | 12:64931a80340d | 526 | ///On Exit: |
j3 | 12:64931a80340d | 527 | ///@param[out] temp - on success, holds the die temperature |
j3 | 12:64931a80340d | 528 | /// |
j3 | 12:64931a80340d | 529 | ///@returns 0 on success, non 0 on failure |
j3 | 12:64931a80340d | 530 | int32_t getTemperature(float *temp); |
j3 | 2:598e601e5846 | 531 | }; |
j3 | 2:598e601e5846 | 532 | |
j3 | 2:598e601e5846 | 533 | |
j3 | 2:598e601e5846 | 534 | /** |
j3 | 2:598e601e5846 | 535 | @brief BMI160_I2C - supports BMI160 object with I2C interface |
j3 | 2:598e601e5846 | 536 | */ |
j3 | 2:598e601e5846 | 537 | class BMI160_I2C: public BMI160 |
j3 | 2:598e601e5846 | 538 | { |
j3 | 2:598e601e5846 | 539 | public: |
j3 | 2:598e601e5846 | 540 | |
j3 | 2:598e601e5846 | 541 | ///BMI160 default I2C address. |
j3 | 2:598e601e5846 | 542 | static const uint8_t I2C_ADRS_SDO_LO = 0x68; |
j3 | 2:598e601e5846 | 543 | ///BMI160 optional I2C address. |
j3 | 2:598e601e5846 | 544 | static const uint8_t I2C_ADRS_SDO_HI = 0x69; |
j3 | 0:bb5b832891fb | 545 | |
j3 | 2:598e601e5846 | 546 | |
j3 | 2:598e601e5846 | 547 | ///@brief BMI160_I2C Constructor.\n |
j3 | 0:bb5b832891fb | 548 | /// |
j3 | 0:bb5b832891fb | 549 | ///On Entry: |
j3 | 2:598e601e5846 | 550 | ///@param[in] i2cBus - reference to I2C bus for this device |
j3 | 2:598e601e5846 | 551 | ///@param[in] i2cAdrs - 7-bit I2C address |
j3 | 0:bb5b832891fb | 552 | /// |
j3 | 0:bb5b832891fb | 553 | ///On Exit: |
j3 | 0:bb5b832891fb | 554 | ///@param[out] none |
j3 | 0:bb5b832891fb | 555 | /// |
j3 | 0:bb5b832891fb | 556 | ///@returns none |
j3 | 2:598e601e5846 | 557 | BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs); |
j3 | 2:598e601e5846 | 558 | |
j3 | 2:598e601e5846 | 559 | |
j3 | 2:598e601e5846 | 560 | virtual int32_t readRegister(Registers reg, uint8_t *data); |
j3 | 2:598e601e5846 | 561 | virtual int32_t writeRegister(Registers reg, const uint8_t data); |
j3 | 3:e1770675eca4 | 562 | virtual int32_t readBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 563 | uint8_t *data); |
j3 | 3:e1770675eca4 | 564 | virtual int32_t writeBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 565 | const uint8_t *data); |
j3 | 2:598e601e5846 | 566 | |
j3 | 0:bb5b832891fb | 567 | private: |
j3 | 0:bb5b832891fb | 568 | |
j3 | 0:bb5b832891fb | 569 | I2C m_i2cBus; |
j3 | 0:bb5b832891fb | 570 | uint8_t m_Wadrs, m_Radrs; |
j3 | 0:bb5b832891fb | 571 | }; |
j3 | 0:bb5b832891fb | 572 | |
j3 | 2:598e601e5846 | 573 | |
j3 | 2:598e601e5846 | 574 | /** |
j3 | 2:598e601e5846 | 575 | @brief BMI160_SPI - supports BMI160 object with SPI interface |
j3 | 2:598e601e5846 | 576 | */ |
j3 | 2:598e601e5846 | 577 | class BMI160_SPI: public BMI160 |
j3 | 2:598e601e5846 | 578 | { |
j3 | 2:598e601e5846 | 579 | public: |
j3 | 2:598e601e5846 | 580 | |
j3 | 2:598e601e5846 | 581 | ///@brief BMI160_SPI Constructor.\n |
j3 | 2:598e601e5846 | 582 | /// |
j3 | 2:598e601e5846 | 583 | ///On Entry: |
j3 | 2:598e601e5846 | 584 | ///@param[in] spiBus - reference to SPI bus for this device |
j3 | 2:598e601e5846 | 585 | ///@param[in] cs - reference to DigitalOut used for chip select |
j3 | 2:598e601e5846 | 586 | /// |
j3 | 2:598e601e5846 | 587 | ///On Exit: |
j3 | 2:598e601e5846 | 588 | ///@param[out] none |
j3 | 2:598e601e5846 | 589 | /// |
j3 | 2:598e601e5846 | 590 | ///@returns none |
j3 | 2:598e601e5846 | 591 | BMI160_SPI(SPI &spiBus, DigitalOut &cs); |
j3 | 2:598e601e5846 | 592 | |
j3 | 2:598e601e5846 | 593 | virtual int32_t readRegister(Registers reg, uint8_t *data); |
j3 | 2:598e601e5846 | 594 | virtual int32_t writeRegister(Registers reg, const uint8_t data); |
j3 | 3:e1770675eca4 | 595 | virtual int32_t readBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 596 | uint8_t *data); |
j3 | 3:e1770675eca4 | 597 | virtual int32_t writeBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 598 | const uint8_t *data); |
j3 | 2:598e601e5846 | 599 | |
j3 | 2:598e601e5846 | 600 | private: |
j3 | 2:598e601e5846 | 601 | |
j3 | 2:598e601e5846 | 602 | SPI m_spiBus; |
j3 | 2:598e601e5846 | 603 | DigitalOut m_cs; |
j3 | 2:598e601e5846 | 604 | }; |
j3 | 2:598e601e5846 | 605 | |
j3 | 0:bb5b832891fb | 606 | #endif /* BMI160_H */ |
j3 | 8:a89b529b1d96 | 607 | |
j3 | 8:a89b529b1d96 | 608 | |
j3 | 8:a89b529b1d96 | 609 | ///@brief fx documentation template.\n |
j3 | 8:a89b529b1d96 | 610 | /// |
j3 | 8:a89b529b1d96 | 611 | ///On Entry: |
j3 | 8:a89b529b1d96 | 612 | ///@param[in] none |
j3 | 8:a89b529b1d96 | 613 | /// |
j3 | 8:a89b529b1d96 | 614 | ///On Exit: |
j3 | 8:a89b529b1d96 | 615 | ///@param[out] none |
j3 | 8:a89b529b1d96 | 616 | /// |
j3 | 8:a89b529b1d96 | 617 | ///@returns none |