Library for Bosch Sensortech BMI160 IMU
Fork of BMI160 by
bmi160.h@4:ebac8c8f6347, 2016-12-09 (annotated)
- Committer:
- j3
- Date:
- Fri Dec 09 00:45:10 2016 +0000
- Revision:
- 4:ebac8c8f6347
- Parent:
- 3:e1770675eca4
- Child:
- 5:35e032c8d8aa
Fixed typo, added power modes
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 | 1:a4c911640569 | 59 | ///BMI160 registers |
j3 | 0:bb5b832891fb | 60 | enum Registers |
j3 | 0:bb5b832891fb | 61 | { |
j3 | 3:e1770675eca4 | 62 | CHIP_ID = 0x00, ///<Chip Identification. |
j3 | 3:e1770675eca4 | 63 | ERR_REG = 0x02, ///<Reports sensor error flags. Flags reset when read. |
j3 | 3:e1770675eca4 | 64 | PMU_STATUS, ///<Reports current power mode for sensors. |
j3 | 3:e1770675eca4 | 65 | DATA_0, ///<MAG_X axis bits7:0 |
j3 | 3:e1770675eca4 | 66 | DATA_1, ///<MAG_X axis bits15:8 |
j3 | 3:e1770675eca4 | 67 | DATA_2, ///<MAG_Y axis bits7:0 |
j3 | 3:e1770675eca4 | 68 | DATA_3, ///<MAG_Y axis bits15:8 |
j3 | 3:e1770675eca4 | 69 | DATA_4, ///<MAG_Z axis bits7:0 |
j3 | 3:e1770675eca4 | 70 | DATA_5, ///<MAG_Z axis bits15:8 |
j3 | 3:e1770675eca4 | 71 | DATA_6, ///<RHALL bits7:0 |
j3 | 3:e1770675eca4 | 72 | DATA_7, ///<RHALL bits15:8 |
j3 | 3:e1770675eca4 | 73 | DATA_8, ///<GYR_X axis bits7:0 |
j3 | 3:e1770675eca4 | 74 | DATA_9, ///<GYR_X axis bits15:8 |
j3 | 3:e1770675eca4 | 75 | DATA_10, ///<GYR_Y axis bits7:0 |
j3 | 3:e1770675eca4 | 76 | DATA_11, ///<GYR_Y axis bits15:8 |
j3 | 3:e1770675eca4 | 77 | DATA_12, ///<GYR_Z axis bits7:0 |
j3 | 3:e1770675eca4 | 78 | DATA_13, ///<GYR_Z axis bits15:8 |
j3 | 3:e1770675eca4 | 79 | DATA_14, ///<ACC_X axis bits7:0 |
j3 | 3:e1770675eca4 | 80 | DATA_15, ///<ACC_X axis bits15:8 |
j3 | 3:e1770675eca4 | 81 | DATA_16, ///<ACC_Y axis bits7:0 |
j3 | 3:e1770675eca4 | 82 | DATA_17, ///<ACC_Y axis bits15:8 |
j3 | 3:e1770675eca4 | 83 | DATA_18, ///<ACC_Z axis bits7:0 |
j3 | 3:e1770675eca4 | 84 | DATA_19, ///<ACC_Z axis bits15:8 |
j3 | 3:e1770675eca4 | 85 | SENSORTIME_0, ///<24bit counter synchronized with data, bits7:0 |
j3 | 3:e1770675eca4 | 86 | SENSORTIME_1, ///<24bit counter synchronized with data, bits15:8 |
j3 | 3:e1770675eca4 | 87 | SENSORTIME_2, ///<24bit counter synchronized with data, bits23:16 |
j3 | 3:e1770675eca4 | 88 | STATUS, ///<Reports sensors status flags |
j3 | 3:e1770675eca4 | 89 | INT_STATUS_0, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 90 | INT_STATUS_1, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 91 | INT_STATUS_2, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 92 | INT_STATUS_3, ///<Contains interrupt status flags |
j3 | 3:e1770675eca4 | 93 | TEMPERATURE_0, ///<Contains temperature of sensor, bits7:0 |
j3 | 3:e1770675eca4 | 94 | TEMPERATURE_1, ///<Contains temperature of sensor, bits15:8 |
j3 | 3:e1770675eca4 | 95 | FIFO_LENGTH_0, ///<Current fill level of FIFO, bits7:0 |
j3 | 3:e1770675eca4 | 96 | FIFO_LENGTH_1, ///<Current fill level of FIFO, bits10:8 |
j3 | 3:e1770675eca4 | 97 | FIFO_DATA, ///<FIFO data read out register, burst read |
j3 | 3:e1770675eca4 | 98 | ACC_CONF = 0x40, ///<Set ODR, bandwidth, and read mode of accelerometer |
j3 | 3:e1770675eca4 | 99 | ACC_RANGE, ///<Sets accelerometer g-range |
j3 | 3:e1770675eca4 | 100 | GYR_CONF, ///<Set ODR, bandwidth, and read mode of gyroscope |
j3 | 3:e1770675eca4 | 101 | GYR_RANGE, ///<Sets gyroscope angular rate measurement range |
j3 | 3:e1770675eca4 | 102 | MAG_CONF, ///<Sets ODR of magnetometer interface |
j3 | 3:e1770675eca4 | 103 | FIFO_DOWNS, ///<Sets down sampling ratios of accel and gyro data |
j3 | 3:e1770675eca4 | 104 | ///<for FIFO |
j3 | 3:e1770675eca4 | 105 | FIFO_CONFIG_0, ///<Sets FIFO Watermark |
j3 | 3:e1770675eca4 | 106 | FIFO_CONFIG_1, ///<Sets which sensor data is available in FIFO, |
j3 | 3:e1770675eca4 | 107 | ///<Header/Headerless mode, Ext Int tagging, Sensortime |
j3 | 3:e1770675eca4 | 108 | MAG_IF_0 = 0x4B, ///<Magnetometer 7-bit I2C address, bits7:1 |
j3 | 3:e1770675eca4 | 109 | MAG_IF_1, ///<Magnetometer interface configuration |
j3 | 3:e1770675eca4 | 110 | MAG_IF_2, ///<Magnetometer address to read |
j3 | 3:e1770675eca4 | 111 | MAG_IF_3, ///<Magnetometer address to write |
j3 | 3:e1770675eca4 | 112 | MAG_IF_4, ///<Magnetometer data to write |
j3 | 3:e1770675eca4 | 113 | INT_EN_0, ///<Interrupt enable bits |
j3 | 3:e1770675eca4 | 114 | INT_EN_1, ///<Interrupt enable bits |
j3 | 3:e1770675eca4 | 115 | INT_EN_2, ///<Interrupt enable bits |
j3 | 3:e1770675eca4 | 116 | INT_OUT_CTRL, ///<Contains the behavioral configuration of INT pins |
j3 | 3:e1770675eca4 | 117 | INT_LATCH, ///<Contains the interrupt rest bit and the interrupt |
j3 | 3:e1770675eca4 | 118 | ///<mode selection |
j3 | 3:e1770675eca4 | 119 | INT_MAP_0, ///<Controls which interrupt signals are mapped to the |
j3 | 3:e1770675eca4 | 120 | ///<INT1 and INT2 pins |
j3 | 3:e1770675eca4 | 121 | INT_MAP_1, ///<Controls which interrupt signals are mapped to the |
j3 | 3:e1770675eca4 | 122 | ///<INT1 and INT2 pins |
j3 | 3:e1770675eca4 | 123 | INT_MAP_2, ///<Controls which interrupt signals are mapped to the |
j3 | 3:e1770675eca4 | 124 | ///<INT1 and INT2 pins |
j3 | 3:e1770675eca4 | 125 | INT_DATA_0, ///<Contains the data source definition for the two |
j3 | 3:e1770675eca4 | 126 | ///<interrupt groups |
j3 | 3:e1770675eca4 | 127 | INT_DATA_1, ///<Contains the data source definition for the two |
j3 | 3:e1770675eca4 | 128 | ///<interrupt groups |
j3 | 3:e1770675eca4 | 129 | INT_LOWHIGH_0, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 130 | INT_LOWHIGH_1, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 131 | INT_LOWHIGH_2, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 132 | INT_LOWHIGH_3, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 133 | INT_LOWHIGH_4, ///<Contains the configuration for the low g interrupt |
j3 | 3:e1770675eca4 | 134 | INT_MOTION_0, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 135 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 136 | INT_MOTION_1, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 137 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 138 | INT_MOTION_2, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 139 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 140 | INT_MOTION_3, ///<Contains the configuration for the any motion and |
j3 | 3:e1770675eca4 | 141 | ///<no motion interrupts |
j3 | 3:e1770675eca4 | 142 | INT_TAP_0, ///<Contains the configuration for the tap interrupts |
j3 | 3:e1770675eca4 | 143 | INT_TAP_1, ///<Contains the configuration for the tap interrupts |
j3 | 3:e1770675eca4 | 144 | INT_ORIENT_0, ///<Contains the configuration for the oeientation |
j3 | 3:e1770675eca4 | 145 | ///<interrupt |
j3 | 3:e1770675eca4 | 146 | INT_ORIENT_1, ///<Contains the configuration for the oeientation |
j3 | 3:e1770675eca4 | 147 | ///<interrupt |
j3 | 3:e1770675eca4 | 148 | INT_FLAT_0, ///<Contains the configuration for the flat interrupt |
j3 | 3:e1770675eca4 | 149 | INT_FLAT_1, ///<Contains the configuration for the flat interrupt |
j3 | 3:e1770675eca4 | 150 | FOC_CONF, ///<Contains configuration for the fast offset |
j3 | 3:e1770675eca4 | 151 | ///<compensation for the accelerometer and gyroscope |
j3 | 3:e1770675eca4 | 152 | CONF, ///<Configuration of sensor, nvm_prog_en bit |
j3 | 3:e1770675eca4 | 153 | IF_CONF, ///<Contains settings for the digital interface |
j3 | 3:e1770675eca4 | 154 | PMU_TRIGGER, ///<Sets trigger conditions to change gyro power modes |
j3 | 3:e1770675eca4 | 155 | SELF_TEST, ///<Self test configuration |
j3 | 3:e1770675eca4 | 156 | NV_CONF = 0x70, ///<Contains settings for the digital interface |
j3 | 3:e1770675eca4 | 157 | OFFSET_0, ///<Contains offset comp values for acc_off_x7:0 |
j3 | 3:e1770675eca4 | 158 | OFFSET_1, ///<Contains offset comp values for acc_off_y7:0 |
j3 | 3:e1770675eca4 | 159 | OFFSET_2, ///<Contains offset comp values for acc_off_z7:0 |
j3 | 3:e1770675eca4 | 160 | OFFSET_3, ///<Contains offset comp values for gyr_off_x7:0 |
j3 | 3:e1770675eca4 | 161 | OFFSET_4, ///<Contains offset comp values for gyr_off_y7:0 |
j3 | 3:e1770675eca4 | 162 | OFFSET_5, ///<Contains offset comp values for gyr_off_z7:0 |
j3 | 3:e1770675eca4 | 163 | OFFSET_6, ///<gyr/acc offset enable bit and gyr_off_(zyx) bits9:8 |
j3 | 3:e1770675eca4 | 164 | STEP_CNT_0, ///<Step counter bits 15:8 |
j3 | 3:e1770675eca4 | 165 | STEP_CNT_1, ///<Step counter bits 7:0 |
j3 | 3:e1770675eca4 | 166 | STEP_CONF_0, ///<Contains configuration of the step detector |
j3 | 3:e1770675eca4 | 167 | STEP_CONF_1, ///<Contains configuration of the step detector |
j3 | 3:e1770675eca4 | 168 | CMD = 0x7E ///<Command register triggers operations like |
j3 | 3:e1770675eca4 | 169 | ///<softreset, NVM programming, etc. |
j3 | 3:e1770675eca4 | 170 | }; |
j3 | 3:e1770675eca4 | 171 | |
j3 | 3:e1770675eca4 | 172 | ///ERR_REG Bit Mask bit0 |
j3 | 3:e1770675eca4 | 173 | static const uint8_t FATAL_ERR = 0x01; |
j3 | 3:e1770675eca4 | 174 | ///ERR_REG Bit Mask bits4:1 |
j3 | 3:e1770675eca4 | 175 | static const uint8_t ERR_CODE = 0x1E; |
j3 | 3:e1770675eca4 | 176 | ///ERR_REG Bit Mask bit5 |
j3 | 3:e1770675eca4 | 177 | static const uint8_t I2C_FAIL_ERR = 0x20; |
j3 | 3:e1770675eca4 | 178 | ///ERR_REG Bit Mask bit6 |
j3 | 3:e1770675eca4 | 179 | static const uint8_t DROP_CMD_ERR = 0x40; |
j3 | 3:e1770675eca4 | 180 | ///ERR_REG Bit Mask bit7 |
j3 | 3:e1770675eca4 | 181 | static const uint8_t MAG_DRDY_ERR = 0x80; |
j3 | 3:e1770675eca4 | 182 | |
j3 | 3:e1770675eca4 | 183 | ///ERR_REG bits4:1 codes |
j3 | 3:e1770675eca4 | 184 | enum ErrorCodes |
j3 | 3:e1770675eca4 | 185 | { |
j3 | 3:e1770675eca4 | 186 | NO_ERROR = 0, ///<No Error |
j3 | 3:e1770675eca4 | 187 | ERROR_1, ///<Listed as error |
j3 | 3:e1770675eca4 | 188 | ERROR_2, ///<Listed as error |
j3 | 3:e1770675eca4 | 189 | LPM_INT_PFD, ///<Low-power mode and interrupt uses pre-filtered |
j3 | 3:e1770675eca4 | 190 | ///<data |
j3 | 4:ebac8c8f6347 | 191 | ODR_MISMATCH = 0x06, ///<ODRs of enabled sensors in headerless mode do |
j3 | 4:ebac8c8f6347 | 192 | ///<not match |
j3 | 3:e1770675eca4 | 193 | PFD_USED_LPM ///<Pre-filtered data are used in low power mode |
j3 | 0:bb5b832891fb | 194 | }; |
j3 | 0:bb5b832891fb | 195 | |
j3 | 4:ebac8c8f6347 | 196 | enum PowerModes |
j3 | 4:ebac8c8f6347 | 197 | { |
j3 | 4:ebac8c8f6347 | 198 | SUSPEND = 0, ///<Acc and Gyro, No sampling, No FIFO data readout |
j3 | 4:ebac8c8f6347 | 199 | NORMAL, ///<Acc and Gyro, Full chip operation |
j3 | 4:ebac8c8f6347 | 200 | LOW_POWER, ///<Acc duty-cycling between suspend and normal |
j3 | 4:ebac8c8f6347 | 201 | FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms |
j3 | 4:ebac8c8f6347 | 202 | }; |
j3 | 4:ebac8c8f6347 | 203 | |
j3 | 0:bb5b832891fb | 204 | |
j3 | 0:bb5b832891fb | 205 | ///@brief BMI160 Destructor.\n |
j3 | 0:bb5b832891fb | 206 | /// |
j3 | 0:bb5b832891fb | 207 | ///On Entry: |
j3 | 0:bb5b832891fb | 208 | ///@param[in] none |
j3 | 0:bb5b832891fb | 209 | /// |
j3 | 0:bb5b832891fb | 210 | ///On Exit: |
j3 | 0:bb5b832891fb | 211 | ///@param[out] none |
j3 | 0:bb5b832891fb | 212 | /// |
j3 | 0:bb5b832891fb | 213 | ///@returns none |
j3 | 2:598e601e5846 | 214 | virtual ~BMI160(){ } |
j3 | 0:bb5b832891fb | 215 | |
j3 | 0:bb5b832891fb | 216 | |
j3 | 0:bb5b832891fb | 217 | ///@brief Reads a single register.\n |
j3 | 0:bb5b832891fb | 218 | /// |
j3 | 0:bb5b832891fb | 219 | ///On Entry: |
j3 | 0:bb5b832891fb | 220 | ///@param[in] data - pointer to memory for storing read data |
j3 | 0:bb5b832891fb | 221 | /// |
j3 | 0:bb5b832891fb | 222 | ///On Exit: |
j3 | 0:bb5b832891fb | 223 | ///@param[out] data - holds contents of read register on success |
j3 | 0:bb5b832891fb | 224 | /// |
j3 | 0:bb5b832891fb | 225 | ///@returns 0 on success, non 0 on failure |
j3 | 2:598e601e5846 | 226 | virtual int32_t readRegister(Registers reg, uint8_t *data) = 0; |
j3 | 0:bb5b832891fb | 227 | |
j3 | 0:bb5b832891fb | 228 | |
j3 | 0:bb5b832891fb | 229 | ///@brief Writes a single register.\n |
j3 | 0:bb5b832891fb | 230 | /// |
j3 | 0:bb5b832891fb | 231 | ///On Entry: |
j3 | 0:bb5b832891fb | 232 | ///@param[in] data - data to write to register |
j3 | 0:bb5b832891fb | 233 | /// |
j3 | 0:bb5b832891fb | 234 | ///On Exit: |
j3 | 0:bb5b832891fb | 235 | ///@param[out] none |
j3 | 0:bb5b832891fb | 236 | /// |
j3 | 0:bb5b832891fb | 237 | ///@returns 0 on success, non 0 on failure |
j3 | 2:598e601e5846 | 238 | virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0; |
j3 | 0:bb5b832891fb | 239 | |
j3 | 0:bb5b832891fb | 240 | |
j3 | 0:bb5b832891fb | 241 | ///@brief Reads a block of registers.\n |
j3 | 0:bb5b832891fb | 242 | ///@detail User must ensure that all registers between 'startReg' and |
j3 | 0:bb5b832891fb | 243 | ///'stopReg' exist and are readable. Function reads up to, including, |
j3 | 0:bb5b832891fb | 244 | ///'stopReg'.\n |
j3 | 0:bb5b832891fb | 245 | /// |
j3 | 0:bb5b832891fb | 246 | ///On Entry: |
j3 | 0:bb5b832891fb | 247 | ///@param[in] startReg - register to start reading from |
j3 | 0:bb5b832891fb | 248 | ///@param[in] stopReg - register to stop reading from |
j3 | 0:bb5b832891fb | 249 | ///@param[in] data - pointer to memory for storing read data |
j3 | 0:bb5b832891fb | 250 | /// |
j3 | 0:bb5b832891fb | 251 | ///On Exit: |
j3 | 0:bb5b832891fb | 252 | ///@param[out] data - holds contents of read registers on success |
j3 | 0:bb5b832891fb | 253 | /// |
j3 | 0:bb5b832891fb | 254 | ///@returns 0 on success, non 0 on failure |
j3 | 3:e1770675eca4 | 255 | virtual int32_t readBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 256 | uint8_t *data) = 0; |
j3 | 0:bb5b832891fb | 257 | |
j3 | 0:bb5b832891fb | 258 | |
j3 | 0:bb5b832891fb | 259 | ///@brief Writes a block of registers.\n |
j3 | 0:bb5b832891fb | 260 | ///@detail User must ensure that all registers between 'startReg' and |
j3 | 0:bb5b832891fb | 261 | ///'stopReg' exist and are writeable. Function writes up to, including, |
j3 | 0:bb5b832891fb | 262 | ///'stopReg'.\n |
j3 | 0:bb5b832891fb | 263 | /// |
j3 | 0:bb5b832891fb | 264 | ///On Entry: |
j3 | 0:bb5b832891fb | 265 | ///@param[in] startReg - register to start writing at |
j3 | 0:bb5b832891fb | 266 | ///@param[in] stopReg - register to stop writing at |
j3 | 0:bb5b832891fb | 267 | ///@param[in] data - pointer to data to write to registers |
j3 | 0:bb5b832891fb | 268 | /// |
j3 | 0:bb5b832891fb | 269 | ///On Exit: |
j3 | 0:bb5b832891fb | 270 | ///@param[out] none |
j3 | 0:bb5b832891fb | 271 | /// |
j3 | 0:bb5b832891fb | 272 | ///@returns 0 on success, non 0 on failure |
j3 | 3:e1770675eca4 | 273 | virtual int32_t writeBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 274 | const uint8_t *data) = 0; |
j3 | 3:e1770675eca4 | 275 | |
j3 | 3:e1770675eca4 | 276 | |
j3 | 3:e1770675eca4 | 277 | ///@brief Get die temperature.\n |
j3 | 3:e1770675eca4 | 278 | /// |
j3 | 3:e1770675eca4 | 279 | ///On Entry: |
j3 | 3:e1770675eca4 | 280 | ///@param[in] temp - pointer to float for temperature |
j3 | 3:e1770675eca4 | 281 | /// |
j3 | 3:e1770675eca4 | 282 | ///On Exit: |
j3 | 3:e1770675eca4 | 283 | ///@param[out] temp - on success, holds the die temperature |
j3 | 3:e1770675eca4 | 284 | /// |
j3 | 3:e1770675eca4 | 285 | ///@returns 0 on success, non 0 on failure |
j3 | 3:e1770675eca4 | 286 | int32_t getTemperature(float *temp); |
j3 | 3:e1770675eca4 | 287 | |
j3 | 3:e1770675eca4 | 288 | |
j3 | 3:e1770675eca4 | 289 | ///@brief fx documentation template.\n |
j3 | 3:e1770675eca4 | 290 | /// |
j3 | 3:e1770675eca4 | 291 | ///On Entry: |
j3 | 3:e1770675eca4 | 292 | ///@param[in] none |
j3 | 3:e1770675eca4 | 293 | /// |
j3 | 3:e1770675eca4 | 294 | ///On Exit: |
j3 | 3:e1770675eca4 | 295 | ///@param[out] none |
j3 | 3:e1770675eca4 | 296 | /// |
j3 | 3:e1770675eca4 | 297 | ///@returns none |
j3 | 0:bb5b832891fb | 298 | |
j3 | 2:598e601e5846 | 299 | private: |
j3 | 2:598e601e5846 | 300 | |
j3 | 2:598e601e5846 | 301 | }; |
j3 | 2:598e601e5846 | 302 | |
j3 | 2:598e601e5846 | 303 | |
j3 | 2:598e601e5846 | 304 | /** |
j3 | 2:598e601e5846 | 305 | @brief BMI160_I2C - supports BMI160 object with I2C interface |
j3 | 2:598e601e5846 | 306 | */ |
j3 | 2:598e601e5846 | 307 | class BMI160_I2C: public BMI160 |
j3 | 2:598e601e5846 | 308 | { |
j3 | 2:598e601e5846 | 309 | public: |
j3 | 2:598e601e5846 | 310 | |
j3 | 2:598e601e5846 | 311 | ///BMI160 default I2C address. |
j3 | 2:598e601e5846 | 312 | static const uint8_t I2C_ADRS_SDO_LO = 0x68; |
j3 | 2:598e601e5846 | 313 | ///BMI160 optional I2C address. |
j3 | 2:598e601e5846 | 314 | static const uint8_t I2C_ADRS_SDO_HI = 0x69; |
j3 | 0:bb5b832891fb | 315 | |
j3 | 2:598e601e5846 | 316 | |
j3 | 2:598e601e5846 | 317 | ///@brief BMI160_I2C Constructor.\n |
j3 | 0:bb5b832891fb | 318 | /// |
j3 | 0:bb5b832891fb | 319 | ///On Entry: |
j3 | 2:598e601e5846 | 320 | ///@param[in] i2cBus - reference to I2C bus for this device |
j3 | 2:598e601e5846 | 321 | ///@param[in] i2cAdrs - 7-bit I2C address |
j3 | 0:bb5b832891fb | 322 | /// |
j3 | 0:bb5b832891fb | 323 | ///On Exit: |
j3 | 0:bb5b832891fb | 324 | ///@param[out] none |
j3 | 0:bb5b832891fb | 325 | /// |
j3 | 0:bb5b832891fb | 326 | ///@returns none |
j3 | 2:598e601e5846 | 327 | BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs); |
j3 | 2:598e601e5846 | 328 | |
j3 | 2:598e601e5846 | 329 | |
j3 | 2:598e601e5846 | 330 | virtual int32_t readRegister(Registers reg, uint8_t *data); |
j3 | 2:598e601e5846 | 331 | virtual int32_t writeRegister(Registers reg, const uint8_t data); |
j3 | 3:e1770675eca4 | 332 | virtual int32_t readBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 333 | uint8_t *data); |
j3 | 3:e1770675eca4 | 334 | virtual int32_t writeBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 335 | const uint8_t *data); |
j3 | 2:598e601e5846 | 336 | |
j3 | 0:bb5b832891fb | 337 | private: |
j3 | 0:bb5b832891fb | 338 | |
j3 | 0:bb5b832891fb | 339 | I2C m_i2cBus; |
j3 | 0:bb5b832891fb | 340 | uint8_t m_Wadrs, m_Radrs; |
j3 | 0:bb5b832891fb | 341 | }; |
j3 | 0:bb5b832891fb | 342 | |
j3 | 2:598e601e5846 | 343 | |
j3 | 2:598e601e5846 | 344 | /** |
j3 | 2:598e601e5846 | 345 | @brief BMI160_SPI - supports BMI160 object with SPI interface |
j3 | 2:598e601e5846 | 346 | */ |
j3 | 2:598e601e5846 | 347 | class BMI160_SPI: public BMI160 |
j3 | 2:598e601e5846 | 348 | { |
j3 | 2:598e601e5846 | 349 | public: |
j3 | 2:598e601e5846 | 350 | |
j3 | 2:598e601e5846 | 351 | ///@brief BMI160_SPI Constructor.\n |
j3 | 2:598e601e5846 | 352 | /// |
j3 | 2:598e601e5846 | 353 | ///On Entry: |
j3 | 2:598e601e5846 | 354 | ///@param[in] spiBus - reference to SPI bus for this device |
j3 | 2:598e601e5846 | 355 | ///@param[in] cs - reference to DigitalOut used for chip select |
j3 | 2:598e601e5846 | 356 | /// |
j3 | 2:598e601e5846 | 357 | ///On Exit: |
j3 | 2:598e601e5846 | 358 | ///@param[out] none |
j3 | 2:598e601e5846 | 359 | /// |
j3 | 2:598e601e5846 | 360 | ///@returns none |
j3 | 2:598e601e5846 | 361 | BMI160_SPI(SPI &spiBus, DigitalOut &cs); |
j3 | 2:598e601e5846 | 362 | |
j3 | 2:598e601e5846 | 363 | virtual int32_t readRegister(Registers reg, uint8_t *data); |
j3 | 2:598e601e5846 | 364 | virtual int32_t writeRegister(Registers reg, const uint8_t data); |
j3 | 3:e1770675eca4 | 365 | virtual int32_t readBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 366 | uint8_t *data); |
j3 | 3:e1770675eca4 | 367 | virtual int32_t writeBlock(Registers startReg, Registers stopReg, |
j3 | 3:e1770675eca4 | 368 | const uint8_t *data); |
j3 | 2:598e601e5846 | 369 | |
j3 | 2:598e601e5846 | 370 | private: |
j3 | 2:598e601e5846 | 371 | |
j3 | 2:598e601e5846 | 372 | SPI m_spiBus; |
j3 | 2:598e601e5846 | 373 | DigitalOut m_cs; |
j3 | 2:598e601e5846 | 374 | }; |
j3 | 2:598e601e5846 | 375 | |
j3 | 0:bb5b832891fb | 376 | #endif /* BMI160_H */ |