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