Library for Bosch Sensortech BMI160 IMU
Dependents: MAX32630FTHR_BALANCE_BOT MPSMAX_copy MAX32630FTHR_BALANCE_BOT SELF_BALANCING_BOT
bmi160.cpp@17:0ae99e97bcf5, 2017-01-05 (annotated)
- Committer:
- j3
- Date:
- Thu Jan 05 21:11:47 2017 +0000
- Revision:
- 17:0ae99e97bcf5
- Parent:
- 16:12782f5d4aa4
Updated docs for virtual fxs;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 3:e1770675eca4 | 1 | /********************************************************************** |
j3 | 3:e1770675eca4 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 3:e1770675eca4 | 3 | * |
j3 | 3:e1770675eca4 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 3:e1770675eca4 | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 3:e1770675eca4 | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 3:e1770675eca4 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 3:e1770675eca4 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 3:e1770675eca4 | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 3:e1770675eca4 | 10 | * |
j3 | 3:e1770675eca4 | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 3:e1770675eca4 | 12 | * in all copies or substantial portions of the Software. |
j3 | 3:e1770675eca4 | 13 | * |
j3 | 3:e1770675eca4 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 3:e1770675eca4 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 3:e1770675eca4 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 3:e1770675eca4 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 3:e1770675eca4 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 3:e1770675eca4 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 3:e1770675eca4 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 3:e1770675eca4 | 21 | * |
j3 | 3:e1770675eca4 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 3:e1770675eca4 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 3:e1770675eca4 | 24 | * Products, Inc. Branding Policy. |
j3 | 3:e1770675eca4 | 25 | * |
j3 | 3:e1770675eca4 | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 3:e1770675eca4 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 3:e1770675eca4 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 3:e1770675eca4 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 3:e1770675eca4 | 30 | * ownership rights. |
j3 | 3:e1770675eca4 | 31 | **********************************************************************/ |
j3 | 3:e1770675eca4 | 32 | |
j3 | 3:e1770675eca4 | 33 | |
j3 | 3:e1770675eca4 | 34 | #include "bmi160.h" |
j3 | 3:e1770675eca4 | 35 | |
j3 | 3:e1770675eca4 | 36 | |
j3 | 16:12782f5d4aa4 | 37 | const struct BMI160::AccConfig BMI160::DEFAULT_ACC_CONFIG = {SENS_2G, |
j3 | 16:12782f5d4aa4 | 38 | ACC_US_OFF, |
j3 | 16:12782f5d4aa4 | 39 | ACC_BWP_2, |
j3 | 16:12782f5d4aa4 | 40 | ACC_ODR_8}; |
j3 | 16:12782f5d4aa4 | 41 | |
j3 | 16:12782f5d4aa4 | 42 | const struct BMI160::GyroConfig BMI160::DEFAULT_GYRO_CONFIG = {DPS_2000, |
j3 | 16:12782f5d4aa4 | 43 | GYRO_BWP_2, |
j3 | 16:12782f5d4aa4 | 44 | GYRO_ODR_8}; |
j3 | 9:ca6b5fecdd63 | 45 | |
j3 | 9:ca6b5fecdd63 | 46 | |
j3 | 3:e1770675eca4 | 47 | //***************************************************************************** |
j3 | 5:35e032c8d8aa | 48 | int32_t BMI160::setSensorPowerMode(Sensors sensor, PowerModes pwrMode) |
j3 | 3:e1770675eca4 | 49 | { |
j3 | 3:e1770675eca4 | 50 | int32_t rtnVal = -1; |
j3 | 3:e1770675eca4 | 51 | |
j3 | 5:35e032c8d8aa | 52 | switch(sensor) |
j3 | 5:35e032c8d8aa | 53 | { |
j3 | 5:35e032c8d8aa | 54 | case MAG: |
j3 | 5:35e032c8d8aa | 55 | rtnVal = writeRegister(CMD, (MAG_SET_PMU_MODE | pwrMode)); |
j3 | 5:35e032c8d8aa | 56 | break; |
j3 | 5:35e032c8d8aa | 57 | |
j3 | 5:35e032c8d8aa | 58 | case GYRO: |
j3 | 5:35e032c8d8aa | 59 | rtnVal = writeRegister(CMD, (GYR_SET_PMU_MODE | pwrMode)); |
j3 | 5:35e032c8d8aa | 60 | break; |
j3 | 5:35e032c8d8aa | 61 | |
j3 | 5:35e032c8d8aa | 62 | case ACC: |
j3 | 5:35e032c8d8aa | 63 | rtnVal = writeRegister(CMD, (ACC_SET_PMU_MODE | pwrMode)); |
j3 | 5:35e032c8d8aa | 64 | break; |
j3 | 5:35e032c8d8aa | 65 | |
j3 | 5:35e032c8d8aa | 66 | default: |
j3 | 5:35e032c8d8aa | 67 | rtnVal = -1; |
j3 | 5:35e032c8d8aa | 68 | break; |
j3 | 5:35e032c8d8aa | 69 | } |
j3 | 5:35e032c8d8aa | 70 | |
j3 | 3:e1770675eca4 | 71 | return rtnVal; |
j3 | 3:e1770675eca4 | 72 | } |
j3 | 5:35e032c8d8aa | 73 | |
j3 | 5:35e032c8d8aa | 74 | |
j3 | 5:35e032c8d8aa | 75 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 76 | int32_t BMI160::setSensorConfig(const AccConfig &config) |
j3 | 5:35e032c8d8aa | 77 | { |
j3 | 5:35e032c8d8aa | 78 | uint8_t data[2]; |
j3 | 5:35e032c8d8aa | 79 | |
j3 | 14:646eb94fa2eb | 80 | data[0] = ((config.us << ACC_US_POS) | (config.bwp << ACC_BWP_POS) | |
j3 | 14:646eb94fa2eb | 81 | (config.odr << ACC_ODR_POS)); |
j3 | 14:646eb94fa2eb | 82 | data[1] = config.range; |
j3 | 12:64931a80340d | 83 | |
j3 | 14:646eb94fa2eb | 84 | return writeBlock(ACC_CONF, ACC_RANGE, data); |
j3 | 14:646eb94fa2eb | 85 | } |
j3 | 14:646eb94fa2eb | 86 | |
j3 | 14:646eb94fa2eb | 87 | |
j3 | 14:646eb94fa2eb | 88 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 89 | int32_t BMI160::setSensorConfig(const GyroConfig &config) |
j3 | 16:12782f5d4aa4 | 90 | { |
j3 | 16:12782f5d4aa4 | 91 | uint8_t data[2]; |
j3 | 16:12782f5d4aa4 | 92 | |
j3 | 16:12782f5d4aa4 | 93 | data[0] = ((config.bwp << GYRO_BWP_POS) | (config.odr << GYRO_ODR_POS)); |
j3 | 16:12782f5d4aa4 | 94 | data[1] = config.range; |
j3 | 16:12782f5d4aa4 | 95 | |
j3 | 16:12782f5d4aa4 | 96 | return writeBlock(GYR_CONF, GYR_RANGE, data); |
j3 | 16:12782f5d4aa4 | 97 | } |
j3 | 16:12782f5d4aa4 | 98 | |
j3 | 16:12782f5d4aa4 | 99 | |
j3 | 16:12782f5d4aa4 | 100 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 101 | int32_t BMI160::getSensorConfig(AccConfig &config) |
j3 | 14:646eb94fa2eb | 102 | { |
j3 | 14:646eb94fa2eb | 103 | uint8_t data[2]; |
j3 | 14:646eb94fa2eb | 104 | int32_t rtnVal = readBlock(ACC_CONF, ACC_RANGE, data); |
j3 | 14:646eb94fa2eb | 105 | |
j3 | 14:646eb94fa2eb | 106 | if(rtnVal == RTN_NO_ERROR) |
j3 | 14:646eb94fa2eb | 107 | { |
j3 | 14:646eb94fa2eb | 108 | config.range = static_cast<BMI160::AccRange>( |
j3 | 14:646eb94fa2eb | 109 | (data[1] & ACC_RANGE_MASK)); |
j3 | 14:646eb94fa2eb | 110 | config.us = static_cast<BMI160::AccUnderSampling>( |
j3 | 14:646eb94fa2eb | 111 | ((data[0] & ACC_US_MASK) >> ACC_US_POS)); |
j3 | 14:646eb94fa2eb | 112 | config.bwp = static_cast<BMI160::AccBandWidthParam>( |
j3 | 14:646eb94fa2eb | 113 | ((data[0] & ACC_BWP_MASK) >> ACC_BWP_POS)); |
j3 | 16:12782f5d4aa4 | 114 | config.odr = static_cast<BMI160::AccOutputDataRate>( |
j3 | 14:646eb94fa2eb | 115 | ((data[0] & ACC_ODR_MASK) >> ACC_ODR_POS)); |
j3 | 14:646eb94fa2eb | 116 | } |
j3 | 5:35e032c8d8aa | 117 | |
j3 | 5:35e032c8d8aa | 118 | return rtnVal; |
j3 | 5:35e032c8d8aa | 119 | } |
j3 | 8:a89b529b1d96 | 120 | |
j3 | 8:a89b529b1d96 | 121 | |
j3 | 8:a89b529b1d96 | 122 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 123 | int32_t BMI160::getSensorConfig(GyroConfig &config) |
j3 | 16:12782f5d4aa4 | 124 | { |
j3 | 16:12782f5d4aa4 | 125 | uint8_t data[2]; |
j3 | 16:12782f5d4aa4 | 126 | int32_t rtnVal = readBlock(GYR_CONF, GYR_RANGE, data); |
j3 | 16:12782f5d4aa4 | 127 | |
j3 | 16:12782f5d4aa4 | 128 | if(rtnVal == RTN_NO_ERROR) |
j3 | 16:12782f5d4aa4 | 129 | { |
j3 | 16:12782f5d4aa4 | 130 | config.range = static_cast<BMI160::GyroRange>( |
j3 | 16:12782f5d4aa4 | 131 | (data[1] & GYRO_RANGE_MASK)); |
j3 | 16:12782f5d4aa4 | 132 | config.bwp = static_cast<BMI160::GyroBandWidthParam>( |
j3 | 16:12782f5d4aa4 | 133 | ((data[0] & GYRO_BWP_MASK) >> GYRO_BWP_POS)); |
j3 | 16:12782f5d4aa4 | 134 | config.odr = static_cast<BMI160::GyroOutputDataRate>( |
j3 | 16:12782f5d4aa4 | 135 | ((data[0] & GYRO_ODR_MASK) >> GYRO_ODR_POS)); |
j3 | 16:12782f5d4aa4 | 136 | } |
j3 | 16:12782f5d4aa4 | 137 | |
j3 | 16:12782f5d4aa4 | 138 | return rtnVal; |
j3 | 16:12782f5d4aa4 | 139 | } |
j3 | 16:12782f5d4aa4 | 140 | |
j3 | 16:12782f5d4aa4 | 141 | |
j3 | 16:12782f5d4aa4 | 142 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 143 | int32_t BMI160::getSensorAxis(SensorAxis axis, AxisData &data, AccRange range) |
j3 | 8:a89b529b1d96 | 144 | { |
j3 | 8:a89b529b1d96 | 145 | uint8_t localData[2]; |
j3 | 8:a89b529b1d96 | 146 | int32_t rtnVal; |
j3 | 8:a89b529b1d96 | 147 | |
j3 | 8:a89b529b1d96 | 148 | switch(axis) |
j3 | 8:a89b529b1d96 | 149 | { |
j3 | 8:a89b529b1d96 | 150 | case X_AXIS: |
j3 | 8:a89b529b1d96 | 151 | rtnVal = readBlock(DATA_14, DATA_15, localData); |
j3 | 8:a89b529b1d96 | 152 | break; |
j3 | 8:a89b529b1d96 | 153 | |
j3 | 8:a89b529b1d96 | 154 | case Y_AXIS: |
j3 | 8:a89b529b1d96 | 155 | rtnVal = readBlock(DATA_16, DATA_17, localData); |
j3 | 8:a89b529b1d96 | 156 | break; |
j3 | 8:a89b529b1d96 | 157 | |
j3 | 8:a89b529b1d96 | 158 | case Z_AXIS: |
j3 | 8:a89b529b1d96 | 159 | rtnVal = readBlock(DATA_18, DATA_19, localData); |
j3 | 8:a89b529b1d96 | 160 | break; |
j3 | 8:a89b529b1d96 | 161 | |
j3 | 8:a89b529b1d96 | 162 | default: |
j3 | 8:a89b529b1d96 | 163 | rtnVal = -1; |
j3 | 8:a89b529b1d96 | 164 | break; |
j3 | 8:a89b529b1d96 | 165 | } |
j3 | 8:a89b529b1d96 | 166 | |
j3 | 8:a89b529b1d96 | 167 | if(rtnVal == RTN_NO_ERROR) |
j3 | 8:a89b529b1d96 | 168 | { |
j3 | 8:a89b529b1d96 | 169 | data.raw = ((localData[1] << 8) | localData[0]); |
j3 | 12:64931a80340d | 170 | switch(range) |
j3 | 9:ca6b5fecdd63 | 171 | { |
j3 | 9:ca6b5fecdd63 | 172 | case SENS_2G: |
j3 | 15:dc35ccc0b08e | 173 | data.scaled = (data.raw/SENS_2G_LSB_PER_G); |
j3 | 9:ca6b5fecdd63 | 174 | break; |
j3 | 9:ca6b5fecdd63 | 175 | |
j3 | 9:ca6b5fecdd63 | 176 | case SENS_4G: |
j3 | 15:dc35ccc0b08e | 177 | data.scaled = (data.raw/SENS_4G_LSB_PER_G); |
j3 | 9:ca6b5fecdd63 | 178 | break; |
j3 | 9:ca6b5fecdd63 | 179 | |
j3 | 9:ca6b5fecdd63 | 180 | case SENS_8G: |
j3 | 15:dc35ccc0b08e | 181 | data.scaled = (data.raw/SENS_8G_LSB_PER_G); |
j3 | 9:ca6b5fecdd63 | 182 | break; |
j3 | 9:ca6b5fecdd63 | 183 | |
j3 | 9:ca6b5fecdd63 | 184 | case SENS_16G: |
j3 | 15:dc35ccc0b08e | 185 | data.scaled = (data.raw/SENS_16G_LSB_PER_G); |
j3 | 9:ca6b5fecdd63 | 186 | break; |
j3 | 9:ca6b5fecdd63 | 187 | } |
j3 | 8:a89b529b1d96 | 188 | } |
j3 | 8:a89b529b1d96 | 189 | |
j3 | 8:a89b529b1d96 | 190 | return rtnVal; |
j3 | 8:a89b529b1d96 | 191 | } |
j3 | 16:12782f5d4aa4 | 192 | |
j3 | 16:12782f5d4aa4 | 193 | |
j3 | 16:12782f5d4aa4 | 194 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 195 | int32_t BMI160::getSensorAxis(SensorAxis axis, AxisData &data, GyroRange range) |
j3 | 16:12782f5d4aa4 | 196 | { |
j3 | 16:12782f5d4aa4 | 197 | uint8_t localData[2]; |
j3 | 16:12782f5d4aa4 | 198 | int32_t rtnVal; |
j3 | 16:12782f5d4aa4 | 199 | |
j3 | 16:12782f5d4aa4 | 200 | switch(axis) |
j3 | 16:12782f5d4aa4 | 201 | { |
j3 | 16:12782f5d4aa4 | 202 | case X_AXIS: |
j3 | 16:12782f5d4aa4 | 203 | rtnVal = readBlock(DATA_8, DATA_9, localData); |
j3 | 16:12782f5d4aa4 | 204 | break; |
j3 | 16:12782f5d4aa4 | 205 | |
j3 | 16:12782f5d4aa4 | 206 | case Y_AXIS: |
j3 | 16:12782f5d4aa4 | 207 | rtnVal = readBlock(DATA_10, DATA_11, localData); |
j3 | 16:12782f5d4aa4 | 208 | break; |
j3 | 16:12782f5d4aa4 | 209 | |
j3 | 16:12782f5d4aa4 | 210 | case Z_AXIS: |
j3 | 16:12782f5d4aa4 | 211 | rtnVal = readBlock(DATA_12, DATA_13, localData); |
j3 | 16:12782f5d4aa4 | 212 | break; |
j3 | 16:12782f5d4aa4 | 213 | |
j3 | 16:12782f5d4aa4 | 214 | default: |
j3 | 16:12782f5d4aa4 | 215 | rtnVal = -1; |
j3 | 16:12782f5d4aa4 | 216 | break; |
j3 | 16:12782f5d4aa4 | 217 | } |
j3 | 16:12782f5d4aa4 | 218 | |
j3 | 16:12782f5d4aa4 | 219 | if(rtnVal == RTN_NO_ERROR) |
j3 | 16:12782f5d4aa4 | 220 | { |
j3 | 16:12782f5d4aa4 | 221 | data.raw = ((localData[1] << 8) | localData[0]); |
j3 | 16:12782f5d4aa4 | 222 | switch(range) |
j3 | 16:12782f5d4aa4 | 223 | { |
j3 | 16:12782f5d4aa4 | 224 | case DPS_2000: |
j3 | 16:12782f5d4aa4 | 225 | data.scaled = (data.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 226 | break; |
j3 | 16:12782f5d4aa4 | 227 | |
j3 | 16:12782f5d4aa4 | 228 | case DPS_1000: |
j3 | 16:12782f5d4aa4 | 229 | data.scaled = (data.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 230 | break; |
j3 | 16:12782f5d4aa4 | 231 | |
j3 | 16:12782f5d4aa4 | 232 | case DPS_500: |
j3 | 16:12782f5d4aa4 | 233 | data.scaled = (data.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 234 | break; |
j3 | 16:12782f5d4aa4 | 235 | |
j3 | 16:12782f5d4aa4 | 236 | case DPS_250: |
j3 | 16:12782f5d4aa4 | 237 | data.scaled = (data.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 238 | break; |
j3 | 16:12782f5d4aa4 | 239 | |
j3 | 16:12782f5d4aa4 | 240 | case DPS_125: |
j3 | 16:12782f5d4aa4 | 241 | data.scaled = (data.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 242 | break; |
j3 | 16:12782f5d4aa4 | 243 | } |
j3 | 16:12782f5d4aa4 | 244 | } |
j3 | 16:12782f5d4aa4 | 245 | |
j3 | 16:12782f5d4aa4 | 246 | return rtnVal; |
j3 | 16:12782f5d4aa4 | 247 | } |
j3 | 8:a89b529b1d96 | 248 | |
j3 | 8:a89b529b1d96 | 249 | |
j3 | 8:a89b529b1d96 | 250 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 251 | int32_t BMI160::getSensorXYZ(SensorData &data, AccRange range) |
j3 | 8:a89b529b1d96 | 252 | { |
j3 | 8:a89b529b1d96 | 253 | uint8_t localData[6]; |
j3 | 8:a89b529b1d96 | 254 | int32_t rtnVal = readBlock(DATA_14, DATA_19, localData); |
j3 | 8:a89b529b1d96 | 255 | |
j3 | 8:a89b529b1d96 | 256 | if(rtnVal == RTN_NO_ERROR) |
j3 | 8:a89b529b1d96 | 257 | { |
j3 | 8:a89b529b1d96 | 258 | data.xAxis.raw = ((localData[1] << 8) | localData[0]); |
j3 | 8:a89b529b1d96 | 259 | data.yAxis.raw = ((localData[3] << 8) | localData[2]); |
j3 | 8:a89b529b1d96 | 260 | data.zAxis.raw = ((localData[5] << 8) | localData[4]); |
j3 | 8:a89b529b1d96 | 261 | |
j3 | 12:64931a80340d | 262 | switch(range) |
j3 | 9:ca6b5fecdd63 | 263 | { |
j3 | 9:ca6b5fecdd63 | 264 | case SENS_2G: |
j3 | 15:dc35ccc0b08e | 265 | data.xAxis.scaled = (data.xAxis.raw/SENS_2G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 266 | data.yAxis.scaled = (data.yAxis.raw/SENS_2G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 267 | data.zAxis.scaled = (data.zAxis.raw/SENS_2G_LSB_PER_G); |
j3 | 9:ca6b5fecdd63 | 268 | break; |
j3 | 9:ca6b5fecdd63 | 269 | |
j3 | 9:ca6b5fecdd63 | 270 | case SENS_4G: |
j3 | 15:dc35ccc0b08e | 271 | data.xAxis.scaled = (data.xAxis.raw/SENS_4G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 272 | data.yAxis.scaled = (data.yAxis.raw/SENS_4G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 273 | data.zAxis.scaled = (data.zAxis.raw/SENS_4G_LSB_PER_G); |
j3 | 9:ca6b5fecdd63 | 274 | break; |
j3 | 9:ca6b5fecdd63 | 275 | |
j3 | 9:ca6b5fecdd63 | 276 | case SENS_8G: |
j3 | 15:dc35ccc0b08e | 277 | data.xAxis.scaled = (data.xAxis.raw/SENS_8G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 278 | data.yAxis.scaled = (data.yAxis.raw/SENS_8G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 279 | data.zAxis.scaled = (data.zAxis.raw/SENS_8G_LSB_PER_G); |
j3 | 9:ca6b5fecdd63 | 280 | break; |
j3 | 9:ca6b5fecdd63 | 281 | |
j3 | 9:ca6b5fecdd63 | 282 | case SENS_16G: |
j3 | 15:dc35ccc0b08e | 283 | data.xAxis.scaled = (data.xAxis.raw/SENS_16G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 284 | data.yAxis.scaled = (data.yAxis.raw/SENS_16G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 285 | data.zAxis.scaled = (data.zAxis.raw/SENS_16G_LSB_PER_G); |
j3 | 9:ca6b5fecdd63 | 286 | break; |
j3 | 9:ca6b5fecdd63 | 287 | } |
j3 | 8:a89b529b1d96 | 288 | } |
j3 | 8:a89b529b1d96 | 289 | |
j3 | 8:a89b529b1d96 | 290 | return rtnVal; |
j3 | 8:a89b529b1d96 | 291 | } |
j3 | 10:9e219f2f1fb3 | 292 | |
j3 | 10:9e219f2f1fb3 | 293 | |
j3 | 16:12782f5d4aa4 | 294 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 295 | int32_t BMI160::getSensorXYZ(SensorData &data, GyroRange range) |
j3 | 16:12782f5d4aa4 | 296 | { |
j3 | 16:12782f5d4aa4 | 297 | uint8_t localData[6]; |
j3 | 16:12782f5d4aa4 | 298 | int32_t rtnVal = readBlock(DATA_8, DATA_13, localData); |
j3 | 16:12782f5d4aa4 | 299 | |
j3 | 16:12782f5d4aa4 | 300 | if(rtnVal == RTN_NO_ERROR) |
j3 | 16:12782f5d4aa4 | 301 | { |
j3 | 16:12782f5d4aa4 | 302 | data.xAxis.raw = ((localData[1] << 8) | localData[0]); |
j3 | 16:12782f5d4aa4 | 303 | data.yAxis.raw = ((localData[3] << 8) | localData[2]); |
j3 | 16:12782f5d4aa4 | 304 | data.zAxis.raw = ((localData[5] << 8) | localData[4]); |
j3 | 16:12782f5d4aa4 | 305 | |
j3 | 16:12782f5d4aa4 | 306 | switch(range) |
j3 | 16:12782f5d4aa4 | 307 | { |
j3 | 16:12782f5d4aa4 | 308 | case DPS_2000: |
j3 | 16:12782f5d4aa4 | 309 | data.xAxis.scaled = (data.xAxis.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 310 | data.yAxis.scaled = (data.yAxis.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 311 | data.zAxis.scaled = (data.zAxis.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 312 | break; |
j3 | 16:12782f5d4aa4 | 313 | |
j3 | 16:12782f5d4aa4 | 314 | case DPS_1000: |
j3 | 16:12782f5d4aa4 | 315 | data.xAxis.scaled = (data.xAxis.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 316 | data.yAxis.scaled = (data.yAxis.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 317 | data.zAxis.scaled = (data.zAxis.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 318 | break; |
j3 | 16:12782f5d4aa4 | 319 | |
j3 | 16:12782f5d4aa4 | 320 | case DPS_500: |
j3 | 16:12782f5d4aa4 | 321 | data.xAxis.scaled = (data.xAxis.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 322 | data.yAxis.scaled = (data.yAxis.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 323 | data.zAxis.scaled = (data.zAxis.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 324 | break; |
j3 | 16:12782f5d4aa4 | 325 | |
j3 | 16:12782f5d4aa4 | 326 | case DPS_250: |
j3 | 16:12782f5d4aa4 | 327 | data.xAxis.scaled = (data.xAxis.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 328 | data.yAxis.scaled = (data.yAxis.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 329 | data.zAxis.scaled = (data.zAxis.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 330 | break; |
j3 | 16:12782f5d4aa4 | 331 | |
j3 | 16:12782f5d4aa4 | 332 | case DPS_125: |
j3 | 16:12782f5d4aa4 | 333 | data.xAxis.scaled = (data.xAxis.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 334 | data.yAxis.scaled = (data.yAxis.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 335 | data.zAxis.scaled = (data.zAxis.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 336 | break; |
j3 | 16:12782f5d4aa4 | 337 | } |
j3 | 16:12782f5d4aa4 | 338 | } |
j3 | 16:12782f5d4aa4 | 339 | |
j3 | 16:12782f5d4aa4 | 340 | return rtnVal; |
j3 | 16:12782f5d4aa4 | 341 | } |
j3 | 16:12782f5d4aa4 | 342 | |
j3 | 16:12782f5d4aa4 | 343 | |
j3 | 10:9e219f2f1fb3 | 344 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 345 | int32_t BMI160::getSensorXYZandSensorTime(SensorData &data, |
j3 | 16:12782f5d4aa4 | 346 | SensorTime &sensorTime, |
j3 | 16:12782f5d4aa4 | 347 | AccRange range) |
j3 | 15:dc35ccc0b08e | 348 | { |
j3 | 15:dc35ccc0b08e | 349 | uint8_t localData[9]; |
j3 | 15:dc35ccc0b08e | 350 | int32_t rtnVal = readBlock(DATA_14, SENSORTIME_2, localData); |
j3 | 15:dc35ccc0b08e | 351 | if(rtnVal == RTN_NO_ERROR) |
j3 | 15:dc35ccc0b08e | 352 | { |
j3 | 15:dc35ccc0b08e | 353 | data.xAxis.raw = ((localData[1] << 8) | localData[0]); |
j3 | 15:dc35ccc0b08e | 354 | data.yAxis.raw = ((localData[3] << 8) | localData[2]); |
j3 | 15:dc35ccc0b08e | 355 | data.zAxis.raw = ((localData[5] << 8) | localData[4]); |
j3 | 15:dc35ccc0b08e | 356 | |
j3 | 15:dc35ccc0b08e | 357 | switch(range) |
j3 | 15:dc35ccc0b08e | 358 | { |
j3 | 15:dc35ccc0b08e | 359 | case SENS_2G: |
j3 | 15:dc35ccc0b08e | 360 | data.xAxis.scaled = (data.xAxis.raw/SENS_2G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 361 | data.yAxis.scaled = (data.yAxis.raw/SENS_2G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 362 | data.zAxis.scaled = (data.zAxis.raw/SENS_2G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 363 | break; |
j3 | 15:dc35ccc0b08e | 364 | |
j3 | 15:dc35ccc0b08e | 365 | case SENS_4G: |
j3 | 15:dc35ccc0b08e | 366 | data.xAxis.scaled = (data.xAxis.raw/SENS_4G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 367 | data.yAxis.scaled = (data.yAxis.raw/SENS_4G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 368 | data.zAxis.scaled = (data.zAxis.raw/SENS_4G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 369 | break; |
j3 | 15:dc35ccc0b08e | 370 | |
j3 | 15:dc35ccc0b08e | 371 | case SENS_8G: |
j3 | 15:dc35ccc0b08e | 372 | data.xAxis.scaled = (data.xAxis.raw/SENS_8G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 373 | data.yAxis.scaled = (data.yAxis.raw/SENS_8G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 374 | data.zAxis.scaled = (data.zAxis.raw/SENS_8G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 375 | break; |
j3 | 15:dc35ccc0b08e | 376 | |
j3 | 15:dc35ccc0b08e | 377 | case SENS_16G: |
j3 | 15:dc35ccc0b08e | 378 | data.xAxis.scaled = (data.xAxis.raw/SENS_16G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 379 | data.yAxis.scaled = (data.yAxis.raw/SENS_16G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 380 | data.zAxis.scaled = (data.zAxis.raw/SENS_16G_LSB_PER_G); |
j3 | 15:dc35ccc0b08e | 381 | break; |
j3 | 15:dc35ccc0b08e | 382 | } |
j3 | 15:dc35ccc0b08e | 383 | |
j3 | 15:dc35ccc0b08e | 384 | sensorTime.raw = ((localData[8] << 16) | (localData[7] << 8) | |
j3 | 15:dc35ccc0b08e | 385 | localData[6]); |
j3 | 15:dc35ccc0b08e | 386 | sensorTime.seconds = (sensorTime.raw * SENSOR_TIME_LSB); |
j3 | 15:dc35ccc0b08e | 387 | } |
j3 | 15:dc35ccc0b08e | 388 | |
j3 | 15:dc35ccc0b08e | 389 | return rtnVal; |
j3 | 15:dc35ccc0b08e | 390 | } |
j3 | 15:dc35ccc0b08e | 391 | |
j3 | 15:dc35ccc0b08e | 392 | |
j3 | 15:dc35ccc0b08e | 393 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 394 | int32_t BMI160::getSensorXYZandSensorTime(SensorData &data, |
j3 | 16:12782f5d4aa4 | 395 | SensorTime &sensorTime, |
j3 | 16:12782f5d4aa4 | 396 | GyroRange range) |
j3 | 16:12782f5d4aa4 | 397 | { |
j3 | 16:12782f5d4aa4 | 398 | uint8_t localData[16]; |
j3 | 16:12782f5d4aa4 | 399 | int32_t rtnVal = readBlock(DATA_8, SENSORTIME_2, localData); |
j3 | 16:12782f5d4aa4 | 400 | if(rtnVal == RTN_NO_ERROR) |
j3 | 16:12782f5d4aa4 | 401 | { |
j3 | 16:12782f5d4aa4 | 402 | data.xAxis.raw = ((localData[1] << 8) | localData[0]); |
j3 | 16:12782f5d4aa4 | 403 | data.yAxis.raw = ((localData[3] << 8) | localData[2]); |
j3 | 16:12782f5d4aa4 | 404 | data.zAxis.raw = ((localData[5] << 8) | localData[4]); |
j3 | 16:12782f5d4aa4 | 405 | |
j3 | 16:12782f5d4aa4 | 406 | switch(range) |
j3 | 16:12782f5d4aa4 | 407 | { |
j3 | 16:12782f5d4aa4 | 408 | case DPS_2000: |
j3 | 16:12782f5d4aa4 | 409 | data.xAxis.scaled = (data.xAxis.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 410 | data.yAxis.scaled = (data.yAxis.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 411 | data.zAxis.scaled = (data.zAxis.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 412 | break; |
j3 | 16:12782f5d4aa4 | 413 | |
j3 | 16:12782f5d4aa4 | 414 | case DPS_1000: |
j3 | 16:12782f5d4aa4 | 415 | data.xAxis.scaled = (data.xAxis.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 416 | data.yAxis.scaled = (data.yAxis.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 417 | data.zAxis.scaled = (data.zAxis.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 418 | break; |
j3 | 16:12782f5d4aa4 | 419 | |
j3 | 16:12782f5d4aa4 | 420 | case DPS_500: |
j3 | 16:12782f5d4aa4 | 421 | data.xAxis.scaled = (data.xAxis.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 422 | data.yAxis.scaled = (data.yAxis.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 423 | data.zAxis.scaled = (data.zAxis.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 424 | break; |
j3 | 16:12782f5d4aa4 | 425 | |
j3 | 16:12782f5d4aa4 | 426 | case DPS_250: |
j3 | 16:12782f5d4aa4 | 427 | data.xAxis.scaled = (data.xAxis.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 428 | data.yAxis.scaled = (data.yAxis.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 429 | data.zAxis.scaled = (data.zAxis.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 430 | break; |
j3 | 16:12782f5d4aa4 | 431 | |
j3 | 16:12782f5d4aa4 | 432 | case DPS_125: |
j3 | 16:12782f5d4aa4 | 433 | data.xAxis.scaled = (data.xAxis.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 434 | data.yAxis.scaled = (data.yAxis.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 435 | data.zAxis.scaled = (data.zAxis.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 436 | break; |
j3 | 16:12782f5d4aa4 | 437 | } |
j3 | 16:12782f5d4aa4 | 438 | |
j3 | 16:12782f5d4aa4 | 439 | sensorTime.raw = ((localData[14] << 16) | (localData[13] << 8) | |
j3 | 16:12782f5d4aa4 | 440 | localData[12]); |
j3 | 16:12782f5d4aa4 | 441 | sensorTime.seconds = (sensorTime.raw * SENSOR_TIME_LSB); |
j3 | 16:12782f5d4aa4 | 442 | } |
j3 | 16:12782f5d4aa4 | 443 | |
j3 | 16:12782f5d4aa4 | 444 | return rtnVal; |
j3 | 16:12782f5d4aa4 | 445 | } |
j3 | 16:12782f5d4aa4 | 446 | |
j3 | 16:12782f5d4aa4 | 447 | |
j3 | 16:12782f5d4aa4 | 448 | //***************************************************************************** |
j3 | 16:12782f5d4aa4 | 449 | int32_t BMI160::getGyroAccXYZandSensorTime(SensorData &accData, |
j3 | 16:12782f5d4aa4 | 450 | SensorData &gyroData, |
j3 | 16:12782f5d4aa4 | 451 | SensorTime &sensorTime, |
j3 | 16:12782f5d4aa4 | 452 | AccRange accRange, |
j3 | 16:12782f5d4aa4 | 453 | GyroRange gyroRange) |
j3 | 16:12782f5d4aa4 | 454 | { |
j3 | 16:12782f5d4aa4 | 455 | uint8_t localData[16]; |
j3 | 16:12782f5d4aa4 | 456 | int32_t rtnVal = readBlock(DATA_8, SENSORTIME_2, localData); |
j3 | 16:12782f5d4aa4 | 457 | if(rtnVal == RTN_NO_ERROR) |
j3 | 16:12782f5d4aa4 | 458 | { |
j3 | 16:12782f5d4aa4 | 459 | gyroData.xAxis.raw = ((localData[1] << 8) | localData[0]); |
j3 | 16:12782f5d4aa4 | 460 | gyroData.yAxis.raw = ((localData[3] << 8) | localData[2]); |
j3 | 16:12782f5d4aa4 | 461 | gyroData.zAxis.raw = ((localData[5] << 8) | localData[4]); |
j3 | 16:12782f5d4aa4 | 462 | |
j3 | 16:12782f5d4aa4 | 463 | accData.xAxis.raw = ((localData[7] << 8) | localData[6]); |
j3 | 16:12782f5d4aa4 | 464 | accData.yAxis.raw = ((localData[9] << 8) | localData[8]); |
j3 | 16:12782f5d4aa4 | 465 | accData.zAxis.raw = ((localData[11] << 8) | localData[10]); |
j3 | 16:12782f5d4aa4 | 466 | |
j3 | 16:12782f5d4aa4 | 467 | switch(gyroRange) |
j3 | 16:12782f5d4aa4 | 468 | { |
j3 | 16:12782f5d4aa4 | 469 | case DPS_2000: |
j3 | 16:12782f5d4aa4 | 470 | gyroData.xAxis.scaled = (gyroData.xAxis.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 471 | gyroData.yAxis.scaled = (gyroData.yAxis.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 472 | gyroData.zAxis.scaled = (gyroData.zAxis.raw/SENS_2000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 473 | break; |
j3 | 16:12782f5d4aa4 | 474 | |
j3 | 16:12782f5d4aa4 | 475 | case DPS_1000: |
j3 | 16:12782f5d4aa4 | 476 | gyroData.xAxis.scaled = (gyroData.xAxis.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 477 | gyroData.yAxis.scaled = (gyroData.yAxis.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 478 | gyroData.zAxis.scaled = (gyroData.zAxis.raw/SENS_1000_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 479 | break; |
j3 | 16:12782f5d4aa4 | 480 | |
j3 | 16:12782f5d4aa4 | 481 | case DPS_500: |
j3 | 16:12782f5d4aa4 | 482 | gyroData.xAxis.scaled = (gyroData.xAxis.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 483 | gyroData.yAxis.scaled = (gyroData.yAxis.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 484 | gyroData.zAxis.scaled = (gyroData.zAxis.raw/SENS_500_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 485 | break; |
j3 | 16:12782f5d4aa4 | 486 | |
j3 | 16:12782f5d4aa4 | 487 | case DPS_250: |
j3 | 16:12782f5d4aa4 | 488 | gyroData.xAxis.scaled = (gyroData.xAxis.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 489 | gyroData.yAxis.scaled = (gyroData.yAxis.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 490 | gyroData.zAxis.scaled = (gyroData.zAxis.raw/SENS_250_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 491 | break; |
j3 | 16:12782f5d4aa4 | 492 | |
j3 | 16:12782f5d4aa4 | 493 | case DPS_125: |
j3 | 16:12782f5d4aa4 | 494 | gyroData.xAxis.scaled = (gyroData.xAxis.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 495 | gyroData.yAxis.scaled = (gyroData.yAxis.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 496 | gyroData.zAxis.scaled = (gyroData.zAxis.raw/SENS_125_DPS_LSB_PER_DPS); |
j3 | 16:12782f5d4aa4 | 497 | break; |
j3 | 16:12782f5d4aa4 | 498 | } |
j3 | 16:12782f5d4aa4 | 499 | |
j3 | 16:12782f5d4aa4 | 500 | switch(accRange) |
j3 | 16:12782f5d4aa4 | 501 | { |
j3 | 16:12782f5d4aa4 | 502 | case SENS_2G: |
j3 | 16:12782f5d4aa4 | 503 | accData.xAxis.scaled = (accData.xAxis.raw/SENS_2G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 504 | accData.yAxis.scaled = (accData.yAxis.raw/SENS_2G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 505 | accData.zAxis.scaled = (accData.zAxis.raw/SENS_2G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 506 | break; |
j3 | 16:12782f5d4aa4 | 507 | |
j3 | 16:12782f5d4aa4 | 508 | case SENS_4G: |
j3 | 16:12782f5d4aa4 | 509 | accData.xAxis.scaled = (accData.xAxis.raw/SENS_4G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 510 | accData.yAxis.scaled = (accData.yAxis.raw/SENS_4G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 511 | accData.zAxis.scaled = (accData.zAxis.raw/SENS_4G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 512 | break; |
j3 | 16:12782f5d4aa4 | 513 | |
j3 | 16:12782f5d4aa4 | 514 | case SENS_8G: |
j3 | 16:12782f5d4aa4 | 515 | accData.xAxis.scaled = (accData.xAxis.raw/SENS_8G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 516 | accData.yAxis.scaled = (accData.yAxis.raw/SENS_8G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 517 | accData.zAxis.scaled = (accData.zAxis.raw/SENS_8G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 518 | break; |
j3 | 16:12782f5d4aa4 | 519 | |
j3 | 16:12782f5d4aa4 | 520 | case SENS_16G: |
j3 | 16:12782f5d4aa4 | 521 | accData.xAxis.scaled = (accData.xAxis.raw/SENS_16G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 522 | accData.yAxis.scaled = (accData.yAxis.raw/SENS_16G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 523 | accData.zAxis.scaled = (accData.zAxis.raw/SENS_16G_LSB_PER_G); |
j3 | 16:12782f5d4aa4 | 524 | break; |
j3 | 16:12782f5d4aa4 | 525 | } |
j3 | 16:12782f5d4aa4 | 526 | |
j3 | 16:12782f5d4aa4 | 527 | sensorTime.raw = ((localData[14] << 16) | (localData[13] << 8) | |
j3 | 16:12782f5d4aa4 | 528 | localData[12]); |
j3 | 16:12782f5d4aa4 | 529 | sensorTime.seconds = (sensorTime.raw * SENSOR_TIME_LSB); |
j3 | 16:12782f5d4aa4 | 530 | } |
j3 | 16:12782f5d4aa4 | 531 | |
j3 | 16:12782f5d4aa4 | 532 | return rtnVal; |
j3 | 16:12782f5d4aa4 | 533 | } |
j3 | 16:12782f5d4aa4 | 534 | |
j3 | 16:12782f5d4aa4 | 535 | |
j3 | 16:12782f5d4aa4 | 536 | //***************************************************************************** |
j3 | 15:dc35ccc0b08e | 537 | int32_t BMI160::getSensorTime(SensorTime &sensorTime) |
j3 | 10:9e219f2f1fb3 | 538 | { |
j3 | 10:9e219f2f1fb3 | 539 | uint8_t localData[3]; |
j3 | 10:9e219f2f1fb3 | 540 | int32_t rtnVal = readBlock(SENSORTIME_0, SENSORTIME_2, localData); |
j3 | 10:9e219f2f1fb3 | 541 | |
j3 | 10:9e219f2f1fb3 | 542 | if(rtnVal == RTN_NO_ERROR) |
j3 | 10:9e219f2f1fb3 | 543 | { |
j3 | 15:dc35ccc0b08e | 544 | sensorTime.raw = ((localData[2] << 16) | (localData[1] << 8) | |
j3 | 15:dc35ccc0b08e | 545 | localData[0]); |
j3 | 15:dc35ccc0b08e | 546 | sensorTime.seconds = (sensorTime.raw * SENSOR_TIME_LSB); |
j3 | 10:9e219f2f1fb3 | 547 | } |
j3 | 10:9e219f2f1fb3 | 548 | |
j3 | 10:9e219f2f1fb3 | 549 | return rtnVal; |
j3 | 10:9e219f2f1fb3 | 550 | } |
j3 | 10:9e219f2f1fb3 | 551 | |
j3 | 12:64931a80340d | 552 | |
j3 | 12:64931a80340d | 553 | //***************************************************************************** |
j3 | 12:64931a80340d | 554 | int32_t BMI160::getTemperature(float *temp) |
j3 | 12:64931a80340d | 555 | { |
j3 | 12:64931a80340d | 556 | uint8_t data[2]; |
j3 | 12:64931a80340d | 557 | uint16_t rawTemp; |
j3 | 12:64931a80340d | 558 | |
j3 | 12:64931a80340d | 559 | int32_t rtnVal = readBlock(TEMPERATURE_0, TEMPERATURE_1, data); |
j3 | 12:64931a80340d | 560 | if(rtnVal == RTN_NO_ERROR) |
j3 | 12:64931a80340d | 561 | { |
j3 | 12:64931a80340d | 562 | rawTemp = ((data[1] << 8) | data[0]); |
j3 | 12:64931a80340d | 563 | if(rawTemp & 0x8000) |
j3 | 12:64931a80340d | 564 | { |
j3 | 12:64931a80340d | 565 | *temp = (23.0F - ((0x10000 - rawTemp)/512.0F)); |
j3 | 12:64931a80340d | 566 | } |
j3 | 12:64931a80340d | 567 | else |
j3 | 12:64931a80340d | 568 | { |
j3 | 12:64931a80340d | 569 | *temp = ((rawTemp/512.0F) + 23.0F); |
j3 | 12:64931a80340d | 570 | } |
j3 | 12:64931a80340d | 571 | } |
j3 | 12:64931a80340d | 572 | |
j3 | 12:64931a80340d | 573 | return rtnVal; |
j3 | 12:64931a80340d | 574 | } |