BMI160 Initial

Dependents:   MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_IMU_HelloWorld MAX32630HSP3_Pitch_Charles Maxim_Squeeks

Committer:
j3
Date:
Thu Dec 08 00:32:41 2016 +0000
Revision:
2:598e601e5846
Parent:
1:a4c911640569
Child:
3:e1770675eca4
Made BMI160 abstract base class and created derived classes BMI160_I2C and BMI160_SPI to support both interfaces.

Who changed what in which revision?

UserRevisionLine numberNew 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 0:bb5b832891fb 57 static const uint8_t NO_ERROR = 0;
j3 0:bb5b832891fb 58
j3 1:a4c911640569 59 ///BMI160 registers
j3 0:bb5b832891fb 60 enum Registers
j3 0:bb5b832891fb 61 {
j3 0:bb5b832891fb 62 CHIP_ID = 0x00,
j3 0:bb5b832891fb 63 ERR_REG = 0x02,
j3 0:bb5b832891fb 64 PMU_STATUS,
j3 0:bb5b832891fb 65 DATA_0,
j3 0:bb5b832891fb 66 DATA_1,
j3 0:bb5b832891fb 67 DATA_2,
j3 0:bb5b832891fb 68 DATA_3,
j3 0:bb5b832891fb 69 DATA_4,
j3 0:bb5b832891fb 70 DATA_5,
j3 0:bb5b832891fb 71 DATA_6,
j3 0:bb5b832891fb 72 DATA_7,
j3 0:bb5b832891fb 73 DATA_8,
j3 0:bb5b832891fb 74 DATA_9,
j3 0:bb5b832891fb 75 DATA_10,
j3 0:bb5b832891fb 76 DATA_11,
j3 0:bb5b832891fb 77 DATA_12,
j3 0:bb5b832891fb 78 DATA_13,
j3 0:bb5b832891fb 79 DATA_14,
j3 0:bb5b832891fb 80 DATA_15,
j3 0:bb5b832891fb 81 DATA_16,
j3 0:bb5b832891fb 82 DATA_17,
j3 0:bb5b832891fb 83 DATA_18,
j3 0:bb5b832891fb 84 DATA_19,
j3 0:bb5b832891fb 85 SENSORTIME_0,
j3 0:bb5b832891fb 86 SENSORTIME_1,
j3 0:bb5b832891fb 87 SENSORTIME_2,
j3 0:bb5b832891fb 88 STATUS,
j3 0:bb5b832891fb 89 INT_STATUS_0,
j3 0:bb5b832891fb 90 INT_STATUS_1,
j3 0:bb5b832891fb 91 INT_STATUS_2,
j3 0:bb5b832891fb 92 INT_STATUS_3,
j3 0:bb5b832891fb 93 TEMPERATURE_0,
j3 0:bb5b832891fb 94 TEMPERATURE_1,
j3 0:bb5b832891fb 95 FIFO_LENGTH_0,
j3 0:bb5b832891fb 96 FIFO_LENGTH_1,
j3 0:bb5b832891fb 97 FIFO_DATA,
j3 0:bb5b832891fb 98 ACC_CONF = 0x40,
j3 0:bb5b832891fb 99 ACC_RANGE,
j3 0:bb5b832891fb 100 GYR_CONF,
j3 0:bb5b832891fb 101 GYR_RANGE,
j3 0:bb5b832891fb 102 MAG_CONF,
j3 0:bb5b832891fb 103 FIFO_DOWNS,
j3 0:bb5b832891fb 104 FIFO_CONFIG_0,
j3 0:bb5b832891fb 105 FIFO_CONFIG_1,
j3 0:bb5b832891fb 106 MAG_IF_0 = 0x4B,
j3 0:bb5b832891fb 107 MAG_IF_1,
j3 0:bb5b832891fb 108 MAG_IF_2,
j3 0:bb5b832891fb 109 MAG_IF_3,
j3 0:bb5b832891fb 110 MAG_IF_4,
j3 0:bb5b832891fb 111 INT_EN_0,
j3 0:bb5b832891fb 112 INT_EN_1,
j3 0:bb5b832891fb 113 INT_EN_2,
j3 0:bb5b832891fb 114 INT_OUT_CTRL,
j3 0:bb5b832891fb 115 INT_LATCH,
j3 0:bb5b832891fb 116 INT_MAP_0,
j3 0:bb5b832891fb 117 INT_MAP_1,
j3 0:bb5b832891fb 118 INT_MAP_2,
j3 0:bb5b832891fb 119 INT_DATA_0,
j3 0:bb5b832891fb 120 INT_DATA_1,
j3 0:bb5b832891fb 121 INT_LOWHIGH_0,
j3 0:bb5b832891fb 122 INT_LOWHIGH_1,
j3 0:bb5b832891fb 123 INT_LOWHIGH_2,
j3 0:bb5b832891fb 124 INT_LOWHIGH_3,
j3 0:bb5b832891fb 125 INT_LOWHIGH_4,
j3 0:bb5b832891fb 126 INT_MOTION_0,
j3 0:bb5b832891fb 127 INT_MOTION_1,
j3 0:bb5b832891fb 128 INT_MOTION_2,
j3 0:bb5b832891fb 129 INT_MOTION_3,
j3 0:bb5b832891fb 130 INT_TAP_0,
j3 0:bb5b832891fb 131 INT_TAP_1,
j3 0:bb5b832891fb 132 INT_ORIENT_0,
j3 0:bb5b832891fb 133 INT_ORIENT_1,
j3 0:bb5b832891fb 134 INT_FLAT_0,
j3 0:bb5b832891fb 135 INT_FLAT_1,
j3 0:bb5b832891fb 136 FOC_CONF,
j3 0:bb5b832891fb 137 CONF,
j3 0:bb5b832891fb 138 IF_CONF,
j3 0:bb5b832891fb 139 PMU_TRIGGER,
j3 0:bb5b832891fb 140 SELF_TEST,
j3 0:bb5b832891fb 141 NV_CONF = 0x70,
j3 0:bb5b832891fb 142 OFFSET_0,
j3 0:bb5b832891fb 143 OFFSET_1,
j3 0:bb5b832891fb 144 OFFSET_2,
j3 0:bb5b832891fb 145 OFFSET_3,
j3 0:bb5b832891fb 146 OFFSET_4,
j3 0:bb5b832891fb 147 OFFSET_5,
j3 0:bb5b832891fb 148 OFFSET_6,
j3 0:bb5b832891fb 149 STEP_CNT_0,
j3 0:bb5b832891fb 150 STEP_CNT_1,
j3 0:bb5b832891fb 151 STEP_CONF_0,
j3 0:bb5b832891fb 152 STEP_CONF_1,
j3 0:bb5b832891fb 153 CMD = 0x7E
j3 0:bb5b832891fb 154 };
j3 0:bb5b832891fb 155
j3 0:bb5b832891fb 156
j3 0:bb5b832891fb 157 ///@brief BMI160 Destructor.\n
j3 0:bb5b832891fb 158 ///
j3 0:bb5b832891fb 159 ///On Entry:
j3 0:bb5b832891fb 160 ///@param[in] none
j3 0:bb5b832891fb 161 ///
j3 0:bb5b832891fb 162 ///On Exit:
j3 0:bb5b832891fb 163 ///@param[out] none
j3 0:bb5b832891fb 164 ///
j3 0:bb5b832891fb 165 ///@returns none
j3 2:598e601e5846 166 virtual ~BMI160(){ }
j3 0:bb5b832891fb 167
j3 0:bb5b832891fb 168
j3 0:bb5b832891fb 169 ///@brief Reads a single register.\n
j3 0:bb5b832891fb 170 ///
j3 0:bb5b832891fb 171 ///On Entry:
j3 0:bb5b832891fb 172 ///@param[in] data - pointer to memory for storing read data
j3 0:bb5b832891fb 173 ///
j3 0:bb5b832891fb 174 ///On Exit:
j3 0:bb5b832891fb 175 ///@param[out] data - holds contents of read register on success
j3 0:bb5b832891fb 176 ///
j3 0:bb5b832891fb 177 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 178 virtual int32_t readRegister(Registers reg, uint8_t *data) = 0;
j3 0:bb5b832891fb 179
j3 0:bb5b832891fb 180
j3 0:bb5b832891fb 181 ///@brief Writes a single register.\n
j3 0:bb5b832891fb 182 ///
j3 0:bb5b832891fb 183 ///On Entry:
j3 0:bb5b832891fb 184 ///@param[in] data - data to write to register
j3 0:bb5b832891fb 185 ///
j3 0:bb5b832891fb 186 ///On Exit:
j3 0:bb5b832891fb 187 ///@param[out] none
j3 0:bb5b832891fb 188 ///
j3 0:bb5b832891fb 189 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 190 virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0;
j3 0:bb5b832891fb 191
j3 0:bb5b832891fb 192
j3 0:bb5b832891fb 193 ///@brief Reads a block of registers.\n
j3 0:bb5b832891fb 194 ///@detail User must ensure that all registers between 'startReg' and
j3 0:bb5b832891fb 195 ///'stopReg' exist and are readable. Function reads up to, including,
j3 0:bb5b832891fb 196 ///'stopReg'.\n
j3 0:bb5b832891fb 197 ///
j3 0:bb5b832891fb 198 ///On Entry:
j3 0:bb5b832891fb 199 ///@param[in] startReg - register to start reading from
j3 0:bb5b832891fb 200 ///@param[in] stopReg - register to stop reading from
j3 0:bb5b832891fb 201 ///@param[in] data - pointer to memory for storing read data
j3 0:bb5b832891fb 202 ///
j3 0:bb5b832891fb 203 ///On Exit:
j3 0:bb5b832891fb 204 ///@param[out] data - holds contents of read registers on success
j3 0:bb5b832891fb 205 ///
j3 0:bb5b832891fb 206 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 207 virtual int32_t readBlock(Registers startReg, Registers stopReg, uint8_t *data) = 0;
j3 0:bb5b832891fb 208
j3 0:bb5b832891fb 209
j3 0:bb5b832891fb 210 ///@brief Writes a block of registers.\n
j3 0:bb5b832891fb 211 ///@detail User must ensure that all registers between 'startReg' and
j3 0:bb5b832891fb 212 ///'stopReg' exist and are writeable. Function writes up to, including,
j3 0:bb5b832891fb 213 ///'stopReg'.\n
j3 0:bb5b832891fb 214 ///
j3 0:bb5b832891fb 215 ///On Entry:
j3 0:bb5b832891fb 216 ///@param[in] startReg - register to start writing at
j3 0:bb5b832891fb 217 ///@param[in] stopReg - register to stop writing at
j3 0:bb5b832891fb 218 ///@param[in] data - pointer to data to write to registers
j3 0:bb5b832891fb 219 ///
j3 0:bb5b832891fb 220 ///On Exit:
j3 0:bb5b832891fb 221 ///@param[out] none
j3 0:bb5b832891fb 222 ///
j3 0:bb5b832891fb 223 ///@returns 0 on success, non 0 on failure
j3 2:598e601e5846 224 virtual int32_t writeBlock(Registers startReg, Registers stopReg, const uint8_t *data) = 0;
j3 0:bb5b832891fb 225
j3 2:598e601e5846 226 private:
j3 2:598e601e5846 227
j3 2:598e601e5846 228 };
j3 2:598e601e5846 229
j3 2:598e601e5846 230
j3 2:598e601e5846 231 /**
j3 2:598e601e5846 232 @brief BMI160_I2C - supports BMI160 object with I2C interface
j3 2:598e601e5846 233 */
j3 2:598e601e5846 234 class BMI160_I2C: public BMI160
j3 2:598e601e5846 235 {
j3 2:598e601e5846 236 public:
j3 2:598e601e5846 237
j3 2:598e601e5846 238 ///BMI160 default I2C address.
j3 2:598e601e5846 239 static const uint8_t I2C_ADRS_SDO_LO = 0x68;
j3 2:598e601e5846 240 ///BMI160 optional I2C address.
j3 2:598e601e5846 241 static const uint8_t I2C_ADRS_SDO_HI = 0x69;
j3 0:bb5b832891fb 242
j3 2:598e601e5846 243
j3 2:598e601e5846 244 ///@brief BMI160_I2C Constructor.\n
j3 0:bb5b832891fb 245 ///
j3 0:bb5b832891fb 246 ///On Entry:
j3 2:598e601e5846 247 ///@param[in] i2cBus - reference to I2C bus for this device
j3 2:598e601e5846 248 ///@param[in] i2cAdrs - 7-bit I2C address
j3 0:bb5b832891fb 249 ///
j3 0:bb5b832891fb 250 ///On Exit:
j3 0:bb5b832891fb 251 ///@param[out] none
j3 0:bb5b832891fb 252 ///
j3 0:bb5b832891fb 253 ///@returns none
j3 2:598e601e5846 254 BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs);
j3 2:598e601e5846 255
j3 2:598e601e5846 256
j3 2:598e601e5846 257 virtual int32_t readRegister(Registers reg, uint8_t *data);
j3 2:598e601e5846 258 virtual int32_t writeRegister(Registers reg, const uint8_t data);
j3 2:598e601e5846 259 virtual int32_t readBlock(Registers startReg, Registers stopReg, uint8_t *data);
j3 2:598e601e5846 260 virtual int32_t writeBlock(Registers startReg, Registers stopReg, const uint8_t *data);
j3 2:598e601e5846 261
j3 0:bb5b832891fb 262 private:
j3 0:bb5b832891fb 263
j3 0:bb5b832891fb 264 I2C m_i2cBus;
j3 0:bb5b832891fb 265 uint8_t m_Wadrs, m_Radrs;
j3 0:bb5b832891fb 266 };
j3 0:bb5b832891fb 267
j3 2:598e601e5846 268
j3 2:598e601e5846 269 /**
j3 2:598e601e5846 270 @brief BMI160_SPI - supports BMI160 object with SPI interface
j3 2:598e601e5846 271 */
j3 2:598e601e5846 272 class BMI160_SPI: public BMI160
j3 2:598e601e5846 273 {
j3 2:598e601e5846 274 public:
j3 2:598e601e5846 275
j3 2:598e601e5846 276 ///@brief BMI160_SPI Constructor.\n
j3 2:598e601e5846 277 ///
j3 2:598e601e5846 278 ///On Entry:
j3 2:598e601e5846 279 ///@param[in] spiBus - reference to SPI bus for this device
j3 2:598e601e5846 280 ///@param[in] cs - reference to DigitalOut used for chip select
j3 2:598e601e5846 281 ///
j3 2:598e601e5846 282 ///On Exit:
j3 2:598e601e5846 283 ///@param[out] none
j3 2:598e601e5846 284 ///
j3 2:598e601e5846 285 ///@returns none
j3 2:598e601e5846 286 BMI160_SPI(SPI &spiBus, DigitalOut &cs);
j3 2:598e601e5846 287
j3 2:598e601e5846 288 virtual int32_t readRegister(Registers reg, uint8_t *data);
j3 2:598e601e5846 289 virtual int32_t writeRegister(Registers reg, const uint8_t data);
j3 2:598e601e5846 290 virtual int32_t readBlock(Registers startReg, Registers stopReg, uint8_t *data);
j3 2:598e601e5846 291 virtual int32_t writeBlock(Registers startReg, Registers stopReg, const uint8_t *data);
j3 2:598e601e5846 292
j3 2:598e601e5846 293 private:
j3 2:598e601e5846 294
j3 2:598e601e5846 295 SPI m_spiBus;
j3 2:598e601e5846 296 DigitalOut m_cs;
j3 2:598e601e5846 297 };
j3 2:598e601e5846 298
j3 0:bb5b832891fb 299 #endif /* BMI160_H */
j3 2:598e601e5846 300
j3 2:598e601e5846 301
j3 2:598e601e5846 302 ///@brief fx documentation template.\n
j3 2:598e601e5846 303 ///
j3 2:598e601e5846 304 ///On Entry:
j3 2:598e601e5846 305 ///@param[in] none
j3 2:598e601e5846 306 ///
j3 2:598e601e5846 307 ///On Exit:
j3 2:598e601e5846 308 ///@param[out] none
j3 2:598e601e5846 309 ///
j3 2:598e601e5846 310 ///@returns none