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