Library for Bosch Sensortech BMI160 IMU
Fork of BMI160 by
Embed:
(wiki syntax)
Show/hide line numbers
bmi160.h
00001 /********************************************************************** 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 **********************************************************************/ 00032 00033 00034 #ifndef BMI160_H 00035 #define BMI160_H 00036 00037 #include "mbed.h" 00038 00039 /** 00040 @brief The BMI160 is a small, low power, low noise 16-bit inertial measurement 00041 unit designed for use in mobile applications like augmented reality or indoor 00042 navigation which require highly accurate, real-time sensor data. 00043 00044 In full operation mode, with both the accelerometer and gyroscope enabled, the 00045 current consumption is typically 950 μA, enabling always-on applications in 00046 battery driven devices. It is available in a compact 14-pin 2.5 x 3.0 x 0.8 mm³ 00047 LGA package." 00048 00049 This class is an abstract base class and can not be instaniated, use BMI160_I2C 00050 or BMI160_SPI. 00051 */ 00052 class BMI160 00053 { 00054 public: 00055 00056 ///Return value on success. 00057 static const uint8_t RTN_NO_ERROR = 0; 00058 00059 ///Sensor types 00060 enum Sensors 00061 { 00062 MAG = 0, ///<Optional external sensor 00063 GYRO, ///<Angular rate sensor 00064 ACC ///<g sensor 00065 }; 00066 00067 ///Sensor Axis 00068 enum SensorAxis 00069 { 00070 X_AXIS = 0, 00071 Y_AXIS, 00072 Z_AXIS 00073 }; 00074 00075 ///Structure for axis data 00076 struct AxisData 00077 { 00078 int16_t raw; ///<Axis raw data 00079 float scaled; ///<Axis scaled data 00080 }; 00081 00082 ///Structure for sensor time data 00083 struct SensorTime 00084 { 00085 uint32_t raw; ///<raw SensorTime 00086 float seconds; ///<SensorTime as seconds 00087 }; 00088 00089 ///Period of internal counter 00090 static const float SENSOR_TIME_LSB = 39e-6; 00091 00092 ///Structure for holding sensor data 00093 struct SensorData 00094 { 00095 AxisData xAxis; ///<Sensor X axis data 00096 AxisData yAxis; ///<Sensor Y axis data 00097 AxisData zAxis; ///<Sensor Z axis data 00098 }; 00099 00100 00101 ///BMI160 registers 00102 enum Registers 00103 { 00104 CHIP_ID = 0x00, ///<Chip Identification. 00105 ERR_REG = 0x02, ///<Reports sensor error flags. Flags reset when read. 00106 PMU_STATUS, ///<Reports current power mode for sensors. 00107 DATA_0, ///<MAG_X axis bits7:0 00108 DATA_1, ///<MAG_X axis bits15:8 00109 DATA_2, ///<MAG_Y axis bits7:0 00110 DATA_3, ///<MAG_Y axis bits15:8 00111 DATA_4, ///<MAG_Z axis bits7:0 00112 DATA_5, ///<MAG_Z axis bits15:8 00113 DATA_6, ///<RHALL bits7:0 00114 DATA_7, ///<RHALL bits15:8 00115 DATA_8, ///<GYR_X axis bits7:0 00116 DATA_9, ///<GYR_X axis bits15:8 00117 DATA_10, ///<GYR_Y axis bits7:0 00118 DATA_11, ///<GYR_Y axis bits15:8 00119 DATA_12, ///<GYR_Z axis bits7:0 00120 DATA_13, ///<GYR_Z axis bits15:8 00121 DATA_14, ///<ACC_X axis bits7:0 00122 DATA_15, ///<ACC_X axis bits15:8 00123 DATA_16, ///<ACC_Y axis bits7:0 00124 DATA_17, ///<ACC_Y axis bits15:8 00125 DATA_18, ///<ACC_Z axis bits7:0 00126 DATA_19, ///<ACC_Z axis bits15:8 00127 SENSORTIME_0, ///<24bit counter synchronized with data, bits7:0 00128 SENSORTIME_1, ///<24bit counter synchronized with data, bits15:8 00129 SENSORTIME_2, ///<24bit counter synchronized with data, bits23:16 00130 STATUS, ///<Reports sensors status flags 00131 INT_STATUS_0, ///<Contains interrupt status flags 00132 INT_STATUS_1, ///<Contains interrupt status flags 00133 INT_STATUS_2, ///<Contains interrupt status flags 00134 INT_STATUS_3, ///<Contains interrupt status flags 00135 TEMPERATURE_0, ///<Contains temperature of sensor, bits7:0 00136 TEMPERATURE_1, ///<Contains temperature of sensor, bits15:8 00137 FIFO_LENGTH_0, ///<Current fill level of FIFO, bits7:0 00138 FIFO_LENGTH_1, ///<Current fill level of FIFO, bits10:8 00139 FIFO_DATA, ///<FIFO data read out register, burst read 00140 ACC_CONF = 0x40, ///<Set ODR, bandwidth, and read mode of accelerometer 00141 ACC_RANGE, ///<Sets accelerometer g-range 00142 GYR_CONF, ///<Set ODR, bandwidth, and read mode of gyroscope 00143 GYR_RANGE, ///<Sets gyroscope angular rate measurement range 00144 MAG_CONF, ///<Sets ODR of magnetometer interface 00145 FIFO_DOWNS, ///<Sets down sampling ratios of accel and gyro data 00146 ///<for FIFO 00147 FIFO_CONFIG_0, ///<Sets FIFO Watermark 00148 FIFO_CONFIG_1, ///<Sets which sensor data is available in FIFO, 00149 ///<Header/Headerless mode, Ext Int tagging, Sensortime 00150 MAG_IF_0 = 0x4B, ///<Magnetometer 7-bit I2C address, bits7:1 00151 MAG_IF_1, ///<Magnetometer interface configuration 00152 MAG_IF_2, ///<Magnetometer address to read 00153 MAG_IF_3, ///<Magnetometer address to write 00154 MAG_IF_4, ///<Magnetometer data to write 00155 INT_EN_0 = 0x50, ///<Interrupt enable bits 00156 INT_EN_1 = 0x51, ///<Interrupt enable bits 00157 INT_EN_2 = 0x52, ///<Interrupt enable bits 00158 INT_OUT_CTRL = 0x53, ///<Contains the behavioral configuration of INT pins 00159 INT_LATCH = 0x54, ///<Contains the interrupt rest bit and the interrupt 00160 ///<mode selection 00161 INT_MAP_0 = 0x55, ///<Controls which interrupt signals are mapped to the 00162 ///<INT1 and INT2 pins 00163 INT_MAP_1 = 0x56, ///<Controls which interrupt signals are mapped to the 00164 ///<INT1 and INT2 pins 00165 INT_MAP_2 = 0x57, ///<Controls which interrupt signals are mapped to the 00166 ///<INT1 and INT2 pins 00167 INT_DATA_0, ///<Contains the data source definition for the two 00168 ///<interrupt groups 00169 INT_DATA_1, ///<Contains the data source definition for the two 00170 ///<interrupt groups 00171 INT_LOWHIGH_0, ///<Contains the configuration for the low g interrupt 00172 INT_LOWHIGH_1, ///<Contains the configuration for the low g interrupt 00173 INT_LOWHIGH_2, ///<Contains the configuration for the low g interrupt 00174 INT_LOWHIGH_3, ///<Contains the configuration for the low g interrupt 00175 INT_LOWHIGH_4, ///<Contains the configuration for the low g interrupt 00176 INT_MOTION_0, ///<Contains the configuration for the any motion and 00177 ///<no motion interrupts 00178 INT_MOTION_1, ///<Contains the configuration for the any motion and 00179 ///<no motion interrupts 00180 INT_MOTION_2, ///<Contains the configuration for the any motion and 00181 ///<no motion interrupts 00182 INT_MOTION_3, ///<Contains the configuration for the any motion and 00183 ///<no motion interrupts 00184 INT_TAP_0 = 0x63, ///<Contains the configuration for the tap interrupts 00185 INT_TAP_1 = 0x64, ///<Contains the configuration for the tap interrupts 00186 INT_ORIENT_0, ///<Contains the configuration for the oeientation 00187 ///<interrupt 00188 INT_ORIENT_1, ///<Contains the configuration for the oeientation 00189 ///<interrupt 00190 INT_FLAT_0, ///<Contains the configuration for the flat interrupt 00191 INT_FLAT_1, ///<Contains the configuration for the flat interrupt 00192 FOC_CONF, ///<Contains configuration for the fast offset 00193 ///<compensation for the accelerometer and gyroscope 00194 CONF, ///<Configuration of sensor, nvm_prog_en bit 00195 IF_CONF, ///<Contains settings for the digital interface 00196 PMU_TRIGGER, ///<Sets trigger conditions to change gyro power modes 00197 SELF_TEST, ///<Self test configuration 00198 NV_CONF = 0x70, ///<Contains settings for the digital interface 00199 OFFSET_0, ///<Contains offset comp values for acc_off_x7:0 00200 OFFSET_1, ///<Contains offset comp values for acc_off_y7:0 00201 OFFSET_2, ///<Contains offset comp values for acc_off_z7:0 00202 OFFSET_3, ///<Contains offset comp values for gyr_off_x7:0 00203 OFFSET_4, ///<Contains offset comp values for gyr_off_y7:0 00204 OFFSET_5, ///<Contains offset comp values for gyr_off_z7:0 00205 OFFSET_6, ///<gyr/acc offset enable bit and gyr_off_(zyx) bits9:8 00206 STEP_CNT_0, ///<Step counter bits 15:8 00207 STEP_CNT_1, ///<Step counter bits 7:0 00208 STEP_CONF_0, ///<Contains configuration of the step detector 00209 STEP_CONF_1, ///<Contains configuration of the step detector 00210 CMD = 0x7E ///<Command register triggers operations like 00211 ///<softreset, NVM programming, etc. 00212 }; 00213 00214 00215 ///@name ERR_REG(0x02) 00216 ///Error register data 00217 ///@{ 00218 00219 static const uint8_t FATAL_ERR_MASK = 0x01; 00220 static const uint8_t FATAL_ERR_POS = 0x00; 00221 static const uint8_t ERR_CODE_MASK = 0x1E; 00222 static const uint8_t ERR_CODE_POS = 0x01; 00223 static const uint8_t I2C_FAIL_ERR_MASK = 0x20; 00224 static const uint8_t I2C_FAIL_ERR_POS = 0x05; 00225 static const uint8_t DROP_CMD_ERR_MASK = 0x40; 00226 static const uint8_t DROP_CMD_ERR_POS = 0x06; 00227 static const uint8_t MAG_DRDY_ERR_MASK = 0x80; 00228 static const uint8_t MAG_DRDY_ERR_POS = 0x08; 00229 00230 ///Enumerated error codes 00231 enum ErrorCodes 00232 { 00233 NO_ERROR = 0, ///<No Error 00234 ERROR_1, ///<Listed as error 00235 ERROR_2, ///<Listed as error 00236 LPM_INT_PFD, ///<Low-power mode and interrupt uses pre-filtered 00237 ///<data 00238 ODR_MISMATCH = 0x06, ///<ODRs of enabled sensors in headerless mode do 00239 ///<not match 00240 PFD_USED_LPM ///<Pre-filtered data are used in low power mode 00241 }; 00242 ///@} 00243 00244 00245 ///@name ACC_CONF(0x40) and ACC_RANGE(0x41) 00246 ///Data for configuring accelerometer 00247 ///@{ 00248 00249 static const uint8_t ACC_ODR_MASK = 0x0F; 00250 static const uint8_t ACC_ODR_POS = 0x00; 00251 static const uint8_t ACC_BWP_MASK = 0x70; 00252 static const uint8_t ACC_BWP_POS = 0x04; 00253 static const uint8_t ACC_US_MASK = 0x80; 00254 static const uint8_t ACC_US_POS = 0x07; 00255 static const uint8_t ACC_RANGE_MASK = 0x0F; 00256 static const uint8_t ACC_RANGE_POS = 0x00; 00257 00258 ///Accelerometer output data rates 00259 enum AccOutputDataRate 00260 { 00261 ACC_ODR_1 = 1, ///< 25/32Hz 00262 ACC_ODR_2, ///< 25/16Hz 00263 ACC_ODR_3, ///< 25/8Hz 00264 ACC_ODR_4, ///< 25/4Hz 00265 ACC_ODR_5, ///< 25/2Hz 00266 ACC_ODR_6, ///< 25Hz 00267 ACC_ODR_7, ///< 50Hz 00268 ACC_ODR_8, ///< 100Hz 00269 ACC_ODR_9, ///< 200Hz 00270 ACC_ODR_10, ///< 400Hz 00271 ACC_ODR_11, ///< 800Hz 00272 ACC_ODR_12 ///< 1600Hz 00273 }; 00274 00275 ///Accelerometer bandwidth parameters 00276 enum AccBandWidthParam 00277 { 00278 ACC_BWP_0 = 0, ///< Average 1 cycle; when acc_us = 0 OSR4 00279 ACC_BWP_1, ///< Average 2 cycles; when acc_us = 0 OSR2 00280 ACC_BWP_2, ///< Average 4 cycles; when acc_us = 0 normal mode 00281 ACC_BWP_3, ///< Average 8 cycles 00282 ACC_BWP_4, ///< Average 16 cycles 00283 ACC_BWP_5, ///< Average 32 cycles 00284 ACC_BWP_6, ///< Average 64 cycles 00285 ACC_BWP_7 ///< Average 128 cycles 00286 }; 00287 00288 ///Accelerometer undersampling 00289 enum AccUnderSampling 00290 { 00291 ACC_US_OFF = 0, 00292 ACC_US_ON 00293 }; 00294 00295 ///Accelerometer ranges 00296 enum AccRange 00297 { 00298 SENS_2G = 0x03, ///<Accelerometer range +-2G 00299 SENS_4G = 0x05, ///<Accelerometer range +-4G 00300 SENS_8G = 0x08, ///<Accelerometer range +-8G 00301 SENS_16G = 0x0C ///<Accelerometer range +-16G 00302 }; 00303 00304 static const float SENS_2G_LSB_PER_G = 16384.0F; 00305 static const float SENS_4G_LSB_PER_G = 8192.0F; 00306 static const float SENS_8G_LSB_PER_G = 4096.0F; 00307 static const float SENS_16G_LSB_PER_G = 2048.0F; 00308 00309 ///Accelerometer configuration data structure 00310 struct AccConfig 00311 { 00312 AccRange range; ///<Accelerometer range 00313 AccUnderSampling us; ///<Accelerometr undersampling mode 00314 AccBandWidthParam bwp; ///<Accelerometer bandwidth param 00315 AccOutputDataRate odr; ///<Accelerometr output data rate 00316 }; 00317 00318 ///Accelerometer default configuration 00319 static const AccConfig DEFAULT_ACC_CONFIG; 00320 ///@} 00321 00322 00323 ///@name GYR_CONF(0x42) and GYR_RANGE(0x43) 00324 ///Data for configuring gyroscope 00325 ///@{ 00326 00327 static const uint8_t GYRO_ODR_MASK = 0x0F; 00328 static const uint8_t GYRO_ODR_POS = 0x00; 00329 static const uint8_t GYRO_BWP_MASK = 0x30; 00330 static const uint8_t GYRO_BWP_POS = 0x04; 00331 static const uint8_t GYRO_RANGE_MASK = 0x07; 00332 static const uint8_t GYRO_RANGE_POS = 0x00; 00333 00334 ///Gyroscope output data rates 00335 enum GyroOutputDataRate 00336 { 00337 GYRO_ODR_6 = 0x06, ///<25Hz 00338 GYRO_ODR_7 = 0x07, ///<50Hz 00339 GYRO_ODR_8 = 0x08, ///<100Hz 00340 GYRO_ODR_9 = 0x09, ///<200Hz 00341 GYRO_ODR_10 = 0x0A, ///<400Hz 00342 GYRO_ODR_11 = 0x0B, ///<800Hz 00343 GYRO_ODR_12 = 0x0C, ///<1600Hz 00344 GYRO_ODR_13 = 0x0D ///<3200Hz 00345 }; 00346 00347 ///Gyroscope bandwidth paramaters 00348 enum GyroBandWidthParam 00349 { 00350 GYRO_BWP_0 = 0, ///<OSR4 Over Sampling Rate of 4 00351 GYRO_BWP_1, ///<OSR2 Over Sampling Rate of 2 00352 GYRO_BWP_2 ///<Normal Mode, Equidistant Sampling 00353 }; 00354 00355 ///Gyroscope ranges 00356 enum GyroRange 00357 { 00358 DPS_2000 = 0, ///<+-2000dps, 16.4LSB/dps 00359 DPS_1000, ///<+-1000dps, 32.8LSB/dps 00360 DPS_500, ///<+-500dps, 65.6LSB/dps 00361 DPS_250, ///<+-250dps, 131.2LSB/dps 00362 DPS_125 ///<+-125dps, 262.4LSB/dps, 00363 }; 00364 00365 static const float SENS_2000_DPS_LSB_PER_DPS = 16.4F; 00366 static const float SENS_1000_DPS_LSB_PER_DPS = 32.8F; 00367 static const float SENS_500_DPS_LSB_PER_DPS = 65.6F; 00368 static const float SENS_250_DPS_LSB_PER_DPS = 131.2F; 00369 static const float SENS_125_DPS_LSB_PER_DPS = 262.4F; 00370 00371 ///Gyroscope configuration data structure 00372 struct GyroConfig 00373 { 00374 GyroRange range; ///<Gyroscope range 00375 GyroBandWidthParam bwp; ///<Gyroscope bandwidth param 00376 GyroOutputDataRate odr; ///<Gyroscope output data rate 00377 }; 00378 00379 ///Gyroscope default configuration 00380 static const GyroConfig DEFAULT_GYRO_CONFIG; 00381 ///@} 00382 00383 00384 ///Enumerated power modes 00385 enum PowerModes 00386 { 00387 SUSPEND = 0, ///<Acc and Gyro, No sampling, No FIFO data readout 00388 NORMAL, ///<Acc and Gyro, Full chip operation 00389 LOW_POWER, ///<Acc duty-cycling between suspend and normal 00390 FAST_START_UP ///<Gyro start up delay time to normal mode <= 10 ms 00391 }; 00392 00393 00394 ///Enumerated commands used with CMD register 00395 enum Commands 00396 { 00397 START_FOC = 0x03, ///<Starts Fast Offset Calibrartion 00398 ACC_SET_PMU_MODE = 0x10, ///<Sets acc power mode 00399 GYR_SET_PMU_MODE = 0x14, ///<Sets gyro power mode 00400 MAG_SET_PMU_MODE = 0x18, ///<Sets mag power mode 00401 PROG_NVM = 0xA0, ///<Writes NVM backed registers into NVM 00402 FIFO_FLUSH = 0xB0, ///<Clears FIFO 00403 INT_RESET, ///<Clears interrupt engine, INT_STATUS, and 00404 ///<the interrupt pin 00405 STEP_CNT_CLR, ///<Triggers reset of the step counter 00406 SOFT_RESET = 0xB6 ///<Triggers a reset including a reboot. 00407 }; 00408 00409 00410 ///@brief BMI160 Destructor.\n 00411 /// 00412 ///On Entry: 00413 ///@param[in] none 00414 /// 00415 ///On Exit: 00416 ///@param[out] none 00417 /// 00418 ///@returns none 00419 virtual ~BMI160(){ } 00420 00421 00422 ///@brief Reads a single register.\n 00423 /// 00424 ///On Entry: 00425 ///@param[in] data - pointer to memory for storing read data 00426 /// 00427 ///On Exit: 00428 ///@param[out] data - holds contents of read register on success 00429 /// 00430 ///@returns 0 on success, non 0 on failure 00431 virtual int32_t readRegister(Registers reg, uint8_t *data) = 0; 00432 00433 00434 ///@brief Writes a single register.\n 00435 /// 00436 ///On Entry: 00437 ///@param[in] data - data to write to register 00438 /// 00439 ///On Exit: 00440 ///@param[out] none 00441 /// 00442 ///@returns 0 on success, non 0 on failure 00443 virtual int32_t writeRegister(Registers reg, const uint8_t data) = 0; 00444 00445 00446 ///@brief Reads a block of registers.\n 00447 ///@detail User must ensure that all registers between 'startReg' and 00448 ///'stopReg' exist and are readable. Function reads up to, including, 00449 ///'stopReg'.\n 00450 /// 00451 ///On Entry: 00452 ///@param[in] startReg - register to start reading from 00453 ///@param[in] stopReg - register to stop reading from 00454 ///@param[in] data - pointer to memory for storing read data 00455 /// 00456 ///On Exit: 00457 ///@param[out] data - holds contents of read registers on success 00458 /// 00459 ///@returns 0 on success, non 0 on failure 00460 virtual int32_t readBlock(Registers startReg, Registers stopReg, 00461 uint8_t *data) = 0; 00462 00463 00464 ///@brief Writes a block of registers.\n 00465 ///@detail User must ensure that all registers between 'startReg' and 00466 ///'stopReg' exist and are writeable. Function writes up to, including, 00467 ///'stopReg'.\n 00468 /// 00469 ///On Entry: 00470 ///@param[in] startReg - register to start writing at 00471 ///@param[in] stopReg - register to stop writing at 00472 ///@param[in] data - pointer to data to write to registers 00473 /// 00474 ///On Exit: 00475 ///@param[out] none 00476 /// 00477 ///@returns 0 on success, non 0 on failure 00478 virtual int32_t writeBlock(Registers startReg, Registers stopReg, 00479 const uint8_t *data) = 0; 00480 00481 00482 ///@brief Sets sensors power mode through CMD register.\n 00483 ///@details Observe command execution times given in datasheet.\n 00484 /// 00485 ///On Entry: 00486 ///@param[in] sensor - Sensor which power mode we are setting 00487 ///@param[in] pwrMode - Desired powermode of the sensor 00488 /// 00489 ///On Exit: 00490 ///@param[out] 00491 /// 00492 ///@returns 0 on success, non 0 on failure 00493 int32_t setSensorPowerMode(Sensors sensor, PowerModes pwrMode); 00494 00495 00496 ///@brief Configure sensor.\n 00497 /// 00498 ///On Entry: 00499 ///@param[in] config - sSensor configuration data structure 00500 /// 00501 ///On Exit: 00502 ///@param[out] none 00503 /// 00504 ///@returns 0 on success, non 0 on failure 00505 int32_t setSensorConfig(const AccConfig &config); 00506 int32_t setSensorConfig(const GyroConfig &config); 00507 00508 00509 ///@brief Get sensor configuration.\n 00510 /// 00511 ///On Entry: 00512 ///@param[in] config - Sensor configuration data structure 00513 /// 00514 ///On Exit: 00515 ///@param[out] config - on success, holds sensor's current 00516 ///configuration 00517 /// 00518 ///@returns 0 on success, non 0 on failure 00519 int32_t getSensorConfig(AccConfig &config); 00520 int32_t getSensorConfig(GyroConfig &config); 00521 00522 00523 ///@brief Get sensor axis.\n 00524 /// 00525 ///On Entry: 00526 ///@param[in] axis - Sensor axis 00527 ///@param[in] data - AxisData structure 00528 ///@param[in] range - Sensor range 00529 /// 00530 ///On Exit: 00531 ///@param[out] data - Structure holds raw and scaled axis data 00532 /// 00533 ///@returns 0 on success, non 0 on failure 00534 int32_t getSensorAxis(SensorAxis axis, AxisData &data, AccRange range); 00535 int32_t getSensorAxis(SensorAxis axis, AxisData &data, GyroRange range); 00536 00537 00538 ///@brief Get sensor xyz axis.\n 00539 /// 00540 ///On Entry: 00541 ///@param[in] data - SensorData structure 00542 ///@param[in] range - Sensor range 00543 /// 00544 ///On Exit: 00545 ///@param[out] data - Structure holds raw and scaled data for all three axis 00546 /// 00547 ///@returns 0 on success, non 0 on failure 00548 int32_t getSensorXYZ(SensorData &data, AccRange range); 00549 int32_t getSensorXYZ(SensorData &data, GyroRange range); 00550 00551 00552 ///@brief Get sensor xyz axis and sensor time.\n 00553 /// 00554 ///On Entry: 00555 ///@param[in] data - SensorData structure 00556 ///@param[in] sensorTime - SensorTime structure for data 00557 ///@param[in] range - Sensor range 00558 /// 00559 ///On Exit: 00560 ///@param[out] data - Structure holds raw and scaled data for all three axis 00561 ///@param[out] sensorTime - Holds sensor time on success 00562 /// 00563 ///@returns 0 on success, non 0 on failure 00564 int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime, 00565 AccRange range); 00566 int32_t getSensorXYZandSensorTime(SensorData &data, SensorTime &sensorTime, 00567 GyroRange range); 00568 00569 00570 ///@brief Get Gyroscope/Accelerometer data and sensor time.\n 00571 /// 00572 ///On Entry: 00573 ///@param[in] accData - Sensor data structure for accelerometer 00574 ///@param[in] gyroData - Sensor data structure for gyroscope 00575 ///@param[in] sensorTime - SensorTime data structure 00576 ///@param[in] accRange - Accelerometer range 00577 ///@param[in] gyroRange - Gyroscope range 00578 /// 00579 ///On Exit: 00580 ///@param[out] accData - Synchronized accelerometer data 00581 ///@param[out] gyroData - Synchronized gyroscope data 00582 ///@param[out] sensorTime - Synchronized sensor time 00583 /// 00584 ///@returns 0 on success, non 0 on failure 00585 int32_t getGyroAccXYZandSensorTime(SensorData &accData, 00586 SensorData &gyroData, 00587 SensorTime &sensorTime, 00588 AccRange accRange, GyroRange gyroRange); 00589 00590 00591 ///@brief Get sensor time.\n 00592 /// 00593 ///On Entry: 00594 ///@param[in] sensorTime - SensorTime structure for data 00595 /// 00596 ///On Exit: 00597 ///@param[out] sensorTime - Holds sensor time on success 00598 /// 00599 ///@returns returns 0 on success, non 0 on failure 00600 int32_t getSensorTime(SensorTime &sensorTime); 00601 00602 00603 ///@brief Get die temperature.\n 00604 /// 00605 ///On Entry: 00606 ///@param[in] temp - pointer to float for temperature 00607 /// 00608 ///On Exit: 00609 ///@param[out] temp - on success, holds the die temperature 00610 /// 00611 ///@returns 0 on success, non 0 on failure 00612 int32_t getTemperature(float *temp); 00613 }; 00614 00615 00616 /** 00617 @brief BMI160_I2C - supports BMI160 object with I2C interface 00618 */ 00619 class BMI160_I2C: public BMI160 00620 { 00621 public: 00622 00623 ///BMI160 default I2C address. 00624 static const uint8_t I2C_ADRS_SDO_LO = 0x68; 00625 ///BMI160 optional I2C address. 00626 static const uint8_t I2C_ADRS_SDO_HI = 0x69; 00627 00628 00629 ///@brief BMI160_I2C Constructor.\n 00630 /// 00631 ///On Entry: 00632 ///@param[in] i2cBus - reference to I2C bus for this device 00633 ///@param[in] i2cAdrs - 7-bit I2C address 00634 /// 00635 ///On Exit: 00636 ///@param[out] none 00637 /// 00638 ///@returns none 00639 BMI160_I2C(I2C &i2cBus, uint8_t i2cAdrs); 00640 00641 00642 ///@brief Reads a single register.\n 00643 /// 00644 ///On Entry: 00645 ///@param[in] data - pointer to memory for storing read data 00646 /// 00647 ///On Exit: 00648 ///@param[out] data - holds contents of read register on success 00649 /// 00650 ///@returns 0 on success, non 0 on failure 00651 virtual int32_t readRegister(Registers reg, uint8_t *data); 00652 00653 00654 ///@brief Writes a single register.\n 00655 /// 00656 ///On Entry: 00657 ///@param[in] data - data to write to register 00658 /// 00659 ///On Exit: 00660 ///@param[out] none 00661 /// 00662 ///@returns 0 on success, non 0 on failure 00663 virtual int32_t writeRegister(Registers reg, const uint8_t data); 00664 00665 00666 ///@brief Reads a block of registers.\n 00667 ///@detail User must ensure that all registers between 'startReg' and 00668 ///'stopReg' exist and are readable. Function reads up to, including, 00669 ///'stopReg'.\n 00670 /// 00671 ///On Entry: 00672 ///@param[in] startReg - register to start reading from 00673 ///@param[in] stopReg - register to stop reading from 00674 ///@param[in] data - pointer to memory for storing read data 00675 /// 00676 ///On Exit: 00677 ///@param[out] data - holds contents of read registers on success 00678 /// 00679 ///@returns 0 on success, non 0 on failure 00680 virtual int32_t readBlock(Registers startReg, Registers stopReg, 00681 uint8_t *data); 00682 00683 00684 ///@brief Writes a block of registers.\n 00685 ///@detail User must ensure that all registers between 'startReg' and 00686 ///'stopReg' exist and are writeable. Function writes up to, including, 00687 ///'stopReg'.\n 00688 /// 00689 ///On Entry: 00690 ///@param[in] startReg - register to start writing at 00691 ///@param[in] stopReg - register to stop writing at 00692 ///@param[in] data - pointer to data to write to registers 00693 /// 00694 ///On Exit: 00695 ///@param[out] none 00696 /// 00697 ///@returns 0 on success, non 0 on failure 00698 virtual int32_t writeBlock(Registers startReg, Registers stopReg, 00699 const uint8_t *data); 00700 00701 private: 00702 00703 I2C m_i2cBus; 00704 uint8_t m_Wadrs, m_Radrs; 00705 }; 00706 00707 00708 /** 00709 @brief BMI160_SPI - supports BMI160 object with SPI interface 00710 */ 00711 class BMI160_SPI: public BMI160 00712 { 00713 public: 00714 00715 ///@brief BMI160_SPI Constructor.\n 00716 /// 00717 ///On Entry: 00718 ///@param[in] spiBus - reference to SPI bus for this device 00719 ///@param[in] cs - reference to DigitalOut used for chip select 00720 /// 00721 ///On Exit: 00722 ///@param[out] none 00723 /// 00724 ///@returns none 00725 BMI160_SPI(SPI &spiBus, DigitalOut &cs); 00726 00727 00728 ///@brief Reads a single register.\n 00729 /// 00730 ///On Entry: 00731 ///@param[in] data - pointer to memory for storing read data 00732 /// 00733 ///On Exit: 00734 ///@param[out] data - holds contents of read register on success 00735 /// 00736 ///@returns 0 on success, non 0 on failure 00737 virtual int32_t readRegister(Registers reg, uint8_t *data); 00738 00739 00740 ///@brief Writes a single register.\n 00741 /// 00742 ///On Entry: 00743 ///@param[in] data - data to write to register 00744 /// 00745 ///On Exit: 00746 ///@param[out] none 00747 /// 00748 ///@returns 0 on success, non 0 on failure 00749 virtual int32_t writeRegister(Registers reg, const uint8_t data); 00750 00751 00752 ///@brief Reads a block of registers.\n 00753 ///@detail User must ensure that all registers between 'startReg' and 00754 ///'stopReg' exist and are readable. Function reads up to, including, 00755 ///'stopReg'.\n 00756 /// 00757 ///On Entry: 00758 ///@param[in] startReg - register to start reading from 00759 ///@param[in] stopReg - register to stop reading from 00760 ///@param[in] data - pointer to memory for storing read data 00761 /// 00762 ///On Exit: 00763 ///@param[out] data - holds contents of read registers on success 00764 /// 00765 ///@returns 0 on success, non 0 on failure 00766 virtual int32_t readBlock(Registers startReg, Registers stopReg, 00767 uint8_t *data); 00768 00769 00770 ///@brief Writes a block of registers.\n 00771 ///@detail User must ensure that all registers between 'startReg' and 00772 ///'stopReg' exist and are writeable. Function writes up to, including, 00773 ///'stopReg'.\n 00774 /// 00775 ///On Entry: 00776 ///@param[in] startReg - register to start writing at 00777 ///@param[in] stopReg - register to stop writing at 00778 ///@param[in] data - pointer to data to write to registers 00779 /// 00780 ///On Exit: 00781 ///@param[out] none 00782 /// 00783 ///@returns 0 on success, non 0 on failure 00784 virtual int32_t writeBlock(Registers startReg, Registers stopReg, 00785 const uint8_t *data); 00786 00787 private: 00788 00789 SPI m_spiBus; 00790 DigitalOut m_cs; 00791 }; 00792 00793 #endif /* BMI160_H */ 00794 00795 00796 ///@brief fx documentation template.\n 00797 /// 00798 ///On Entry: 00799 ///@param[in] none 00800 /// 00801 ///On Exit: 00802 ///@param[out] none 00803 /// 00804 ///@returns none
Generated on Wed Jul 13 2022 23:21:00 by 1.7.2