Library for Bosch Sensortech BMI160 IMU
Fork of BMI160 by
bmi160.h@0:bb5b832891fb, 2016-12-07 (annotated)
- Committer:
- j3
- Date:
- Wed Dec 07 19:45:06 2016 +0000
- Revision:
- 0:bb5b832891fb
- Child:
- 1:a4c911640569
Init Commit, basic skeleton of class
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 | 0:bb5b832891fb | 48 | */ |
j3 | 0:bb5b832891fb | 49 | class BMI160 |
j3 | 0:bb5b832891fb | 50 | { |
j3 | 0:bb5b832891fb | 51 | public: |
j3 | 0:bb5b832891fb | 52 | |
j3 | 0:bb5b832891fb | 53 | static const uint8_t I2C_ADRS_SDO_LO = 0x68; |
j3 | 0:bb5b832891fb | 54 | static const uint8_t I2C_ADRS_SDO_HI = 0x69; |
j3 | 0:bb5b832891fb | 55 | |
j3 | 0:bb5b832891fb | 56 | static const uint8_t NO_ERROR = 0; |
j3 | 0:bb5b832891fb | 57 | |
j3 | 0:bb5b832891fb | 58 | enum Registers |
j3 | 0:bb5b832891fb | 59 | { |
j3 | 0:bb5b832891fb | 60 | CHIP_ID = 0x00, |
j3 | 0:bb5b832891fb | 61 | ERR_REG = 0x02, |
j3 | 0:bb5b832891fb | 62 | PMU_STATUS, |
j3 | 0:bb5b832891fb | 63 | DATA_0, |
j3 | 0:bb5b832891fb | 64 | DATA_1, |
j3 | 0:bb5b832891fb | 65 | DATA_2, |
j3 | 0:bb5b832891fb | 66 | DATA_3, |
j3 | 0:bb5b832891fb | 67 | DATA_4, |
j3 | 0:bb5b832891fb | 68 | DATA_5, |
j3 | 0:bb5b832891fb | 69 | DATA_6, |
j3 | 0:bb5b832891fb | 70 | DATA_7, |
j3 | 0:bb5b832891fb | 71 | DATA_8, |
j3 | 0:bb5b832891fb | 72 | DATA_9, |
j3 | 0:bb5b832891fb | 73 | DATA_10, |
j3 | 0:bb5b832891fb | 74 | DATA_11, |
j3 | 0:bb5b832891fb | 75 | DATA_12, |
j3 | 0:bb5b832891fb | 76 | DATA_13, |
j3 | 0:bb5b832891fb | 77 | DATA_14, |
j3 | 0:bb5b832891fb | 78 | DATA_15, |
j3 | 0:bb5b832891fb | 79 | DATA_16, |
j3 | 0:bb5b832891fb | 80 | DATA_17, |
j3 | 0:bb5b832891fb | 81 | DATA_18, |
j3 | 0:bb5b832891fb | 82 | DATA_19, |
j3 | 0:bb5b832891fb | 83 | SENSORTIME_0, |
j3 | 0:bb5b832891fb | 84 | SENSORTIME_1, |
j3 | 0:bb5b832891fb | 85 | SENSORTIME_2, |
j3 | 0:bb5b832891fb | 86 | STATUS, |
j3 | 0:bb5b832891fb | 87 | INT_STATUS_0, |
j3 | 0:bb5b832891fb | 88 | INT_STATUS_1, |
j3 | 0:bb5b832891fb | 89 | INT_STATUS_2, |
j3 | 0:bb5b832891fb | 90 | INT_STATUS_3, |
j3 | 0:bb5b832891fb | 91 | TEMPERATURE_0, |
j3 | 0:bb5b832891fb | 92 | TEMPERATURE_1, |
j3 | 0:bb5b832891fb | 93 | FIFO_LENGTH_0, |
j3 | 0:bb5b832891fb | 94 | FIFO_LENGTH_1, |
j3 | 0:bb5b832891fb | 95 | FIFO_DATA, |
j3 | 0:bb5b832891fb | 96 | ACC_CONF = 0x40, |
j3 | 0:bb5b832891fb | 97 | ACC_RANGE, |
j3 | 0:bb5b832891fb | 98 | GYR_CONF, |
j3 | 0:bb5b832891fb | 99 | GYR_RANGE, |
j3 | 0:bb5b832891fb | 100 | MAG_CONF, |
j3 | 0:bb5b832891fb | 101 | FIFO_DOWNS, |
j3 | 0:bb5b832891fb | 102 | FIFO_CONFIG_0, |
j3 | 0:bb5b832891fb | 103 | FIFO_CONFIG_1, |
j3 | 0:bb5b832891fb | 104 | MAG_IF_0 = 0x4B, |
j3 | 0:bb5b832891fb | 105 | MAG_IF_1, |
j3 | 0:bb5b832891fb | 106 | MAG_IF_2, |
j3 | 0:bb5b832891fb | 107 | MAG_IF_3, |
j3 | 0:bb5b832891fb | 108 | MAG_IF_4, |
j3 | 0:bb5b832891fb | 109 | INT_EN_0, |
j3 | 0:bb5b832891fb | 110 | INT_EN_1, |
j3 | 0:bb5b832891fb | 111 | INT_EN_2, |
j3 | 0:bb5b832891fb | 112 | INT_OUT_CTRL, |
j3 | 0:bb5b832891fb | 113 | INT_LATCH, |
j3 | 0:bb5b832891fb | 114 | INT_MAP_0, |
j3 | 0:bb5b832891fb | 115 | INT_MAP_1, |
j3 | 0:bb5b832891fb | 116 | INT_MAP_2, |
j3 | 0:bb5b832891fb | 117 | INT_DATA_0, |
j3 | 0:bb5b832891fb | 118 | INT_DATA_1, |
j3 | 0:bb5b832891fb | 119 | INT_LOWHIGH_0, |
j3 | 0:bb5b832891fb | 120 | INT_LOWHIGH_1, |
j3 | 0:bb5b832891fb | 121 | INT_LOWHIGH_2, |
j3 | 0:bb5b832891fb | 122 | INT_LOWHIGH_3, |
j3 | 0:bb5b832891fb | 123 | INT_LOWHIGH_4, |
j3 | 0:bb5b832891fb | 124 | INT_MOTION_0, |
j3 | 0:bb5b832891fb | 125 | INT_MOTION_1, |
j3 | 0:bb5b832891fb | 126 | INT_MOTION_2, |
j3 | 0:bb5b832891fb | 127 | INT_MOTION_3, |
j3 | 0:bb5b832891fb | 128 | INT_TAP_0, |
j3 | 0:bb5b832891fb | 129 | INT_TAP_1, |
j3 | 0:bb5b832891fb | 130 | INT_ORIENT_0, |
j3 | 0:bb5b832891fb | 131 | INT_ORIENT_1, |
j3 | 0:bb5b832891fb | 132 | INT_FLAT_0, |
j3 | 0:bb5b832891fb | 133 | INT_FLAT_1, |
j3 | 0:bb5b832891fb | 134 | FOC_CONF, |
j3 | 0:bb5b832891fb | 135 | CONF, |
j3 | 0:bb5b832891fb | 136 | IF_CONF, |
j3 | 0:bb5b832891fb | 137 | PMU_TRIGGER, |
j3 | 0:bb5b832891fb | 138 | SELF_TEST, |
j3 | 0:bb5b832891fb | 139 | NV_CONF = 0x70, |
j3 | 0:bb5b832891fb | 140 | OFFSET_0, |
j3 | 0:bb5b832891fb | 141 | OFFSET_1, |
j3 | 0:bb5b832891fb | 142 | OFFSET_2, |
j3 | 0:bb5b832891fb | 143 | OFFSET_3, |
j3 | 0:bb5b832891fb | 144 | OFFSET_4, |
j3 | 0:bb5b832891fb | 145 | OFFSET_5, |
j3 | 0:bb5b832891fb | 146 | OFFSET_6, |
j3 | 0:bb5b832891fb | 147 | STEP_CNT_0, |
j3 | 0:bb5b832891fb | 148 | STEP_CNT_1, |
j3 | 0:bb5b832891fb | 149 | STEP_CONF_0, |
j3 | 0:bb5b832891fb | 150 | STEP_CONF_1, |
j3 | 0:bb5b832891fb | 151 | CMD = 0x7E |
j3 | 0:bb5b832891fb | 152 | }; |
j3 | 0:bb5b832891fb | 153 | |
j3 | 0:bb5b832891fb | 154 | ///@brief BMI160 Constructor.\n |
j3 | 0:bb5b832891fb | 155 | /// |
j3 | 0:bb5b832891fb | 156 | ///On Entry: |
j3 | 0:bb5b832891fb | 157 | ///@param[in] i2cBus - reference to I2C bus for this device |
j3 | 0:bb5b832891fb | 158 | ///@param[in] i2cAdrs - 7-bit I2C address |
j3 | 0:bb5b832891fb | 159 | /// |
j3 | 0:bb5b832891fb | 160 | ///On Exit: |
j3 | 0:bb5b832891fb | 161 | ///@param[out] none |
j3 | 0:bb5b832891fb | 162 | /// |
j3 | 0:bb5b832891fb | 163 | ///@returns none |
j3 | 0:bb5b832891fb | 164 | BMI160(I2C &i2cBus, uint8_t i2cAdrs); |
j3 | 0:bb5b832891fb | 165 | |
j3 | 0:bb5b832891fb | 166 | |
j3 | 0:bb5b832891fb | 167 | ///@brief BMI160 Destructor.\n |
j3 | 0:bb5b832891fb | 168 | /// |
j3 | 0:bb5b832891fb | 169 | ///On Entry: |
j3 | 0:bb5b832891fb | 170 | ///@param[in] none |
j3 | 0:bb5b832891fb | 171 | /// |
j3 | 0:bb5b832891fb | 172 | ///On Exit: |
j3 | 0:bb5b832891fb | 173 | ///@param[out] none |
j3 | 0:bb5b832891fb | 174 | /// |
j3 | 0:bb5b832891fb | 175 | ///@returns none |
j3 | 0:bb5b832891fb | 176 | ~BMI160(); |
j3 | 0:bb5b832891fb | 177 | |
j3 | 0:bb5b832891fb | 178 | |
j3 | 0:bb5b832891fb | 179 | ///@brief Reads a single register.\n |
j3 | 0:bb5b832891fb | 180 | /// |
j3 | 0:bb5b832891fb | 181 | ///On Entry: |
j3 | 0:bb5b832891fb | 182 | ///@param[in] data - pointer to memory for storing read data |
j3 | 0:bb5b832891fb | 183 | /// |
j3 | 0:bb5b832891fb | 184 | ///On Exit: |
j3 | 0:bb5b832891fb | 185 | ///@param[out] data - holds contents of read register on success |
j3 | 0:bb5b832891fb | 186 | /// |
j3 | 0:bb5b832891fb | 187 | ///@returns 0 on success, non 0 on failure |
j3 | 0:bb5b832891fb | 188 | int32_t readRegister(Registers reg, uint8_t *data); |
j3 | 0:bb5b832891fb | 189 | |
j3 | 0:bb5b832891fb | 190 | |
j3 | 0:bb5b832891fb | 191 | ///@brief Writes a single register.\n |
j3 | 0:bb5b832891fb | 192 | /// |
j3 | 0:bb5b832891fb | 193 | ///On Entry: |
j3 | 0:bb5b832891fb | 194 | ///@param[in] data - data to write to register |
j3 | 0:bb5b832891fb | 195 | /// |
j3 | 0:bb5b832891fb | 196 | ///On Exit: |
j3 | 0:bb5b832891fb | 197 | ///@param[out] none |
j3 | 0:bb5b832891fb | 198 | /// |
j3 | 0:bb5b832891fb | 199 | ///@returns 0 on success, non 0 on failure |
j3 | 0:bb5b832891fb | 200 | int32_t writeRegister(Registers reg, uint8_t data); |
j3 | 0:bb5b832891fb | 201 | |
j3 | 0:bb5b832891fb | 202 | |
j3 | 0:bb5b832891fb | 203 | ///@brief Reads a block of registers.\n |
j3 | 0:bb5b832891fb | 204 | ///@detail User must ensure that all registers between 'startReg' and |
j3 | 0:bb5b832891fb | 205 | ///'stopReg' exist and are readable. Function reads up to, including, |
j3 | 0:bb5b832891fb | 206 | ///'stopReg'.\n |
j3 | 0:bb5b832891fb | 207 | /// |
j3 | 0:bb5b832891fb | 208 | ///On Entry: |
j3 | 0:bb5b832891fb | 209 | ///@param[in] startReg - register to start reading from |
j3 | 0:bb5b832891fb | 210 | ///@param[in] stopReg - register to stop reading from |
j3 | 0:bb5b832891fb | 211 | ///@param[in] data - pointer to memory for storing read data |
j3 | 0:bb5b832891fb | 212 | /// |
j3 | 0:bb5b832891fb | 213 | ///On Exit: |
j3 | 0:bb5b832891fb | 214 | ///@param[out] data - holds contents of read registers on success |
j3 | 0:bb5b832891fb | 215 | /// |
j3 | 0:bb5b832891fb | 216 | ///@returns 0 on success, non 0 on failure |
j3 | 0:bb5b832891fb | 217 | int32_t readBlock(Registers startReg, Registers stopReg, uint8_t *data); |
j3 | 0:bb5b832891fb | 218 | |
j3 | 0:bb5b832891fb | 219 | |
j3 | 0:bb5b832891fb | 220 | ///@brief Writes a block of registers.\n |
j3 | 0:bb5b832891fb | 221 | ///@detail User must ensure that all registers between 'startReg' and |
j3 | 0:bb5b832891fb | 222 | ///'stopReg' exist and are writeable. Function writes up to, including, |
j3 | 0:bb5b832891fb | 223 | ///'stopReg'.\n |
j3 | 0:bb5b832891fb | 224 | /// |
j3 | 0:bb5b832891fb | 225 | ///On Entry: |
j3 | 0:bb5b832891fb | 226 | ///@param[in] startReg - register to start writing at |
j3 | 0:bb5b832891fb | 227 | ///@param[in] stopReg - register to stop writing at |
j3 | 0:bb5b832891fb | 228 | ///@param[in] data - pointer to data to write to registers |
j3 | 0:bb5b832891fb | 229 | /// |
j3 | 0:bb5b832891fb | 230 | ///On Exit: |
j3 | 0:bb5b832891fb | 231 | ///@param[out] none |
j3 | 0:bb5b832891fb | 232 | /// |
j3 | 0:bb5b832891fb | 233 | ///@returns 0 on success, non 0 on failure |
j3 | 0:bb5b832891fb | 234 | int32_t writeBlock(Registers startReg, Registers stopReg, uint8_t *data); |
j3 | 0:bb5b832891fb | 235 | |
j3 | 0:bb5b832891fb | 236 | |
j3 | 0:bb5b832891fb | 237 | ///@brief fx documentation template.\n |
j3 | 0:bb5b832891fb | 238 | /// |
j3 | 0:bb5b832891fb | 239 | ///On Entry: |
j3 | 0:bb5b832891fb | 240 | ///@param[in] none |
j3 | 0:bb5b832891fb | 241 | /// |
j3 | 0:bb5b832891fb | 242 | ///On Exit: |
j3 | 0:bb5b832891fb | 243 | ///@param[out] none |
j3 | 0:bb5b832891fb | 244 | /// |
j3 | 0:bb5b832891fb | 245 | ///@returns none |
j3 | 0:bb5b832891fb | 246 | |
j3 | 0:bb5b832891fb | 247 | private: |
j3 | 0:bb5b832891fb | 248 | |
j3 | 0:bb5b832891fb | 249 | I2C m_i2cBus; |
j3 | 0:bb5b832891fb | 250 | uint8_t m_Wadrs, m_Radrs; |
j3 | 0:bb5b832891fb | 251 | }; |
j3 | 0:bb5b832891fb | 252 | |
j3 | 0:bb5b832891fb | 253 | #endif /* BMI160_H */ |