Remoção de funções não utilizadas

Fork of LSM6DS3 by Sherry Yang

Committer:
joaomazza
Date:
Sat Sep 29 20:14:06 2018 +0000
Revision:
3:a8a6b2456e93
Parent:
2:ed14e6196255
Tirei o que era in?til;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
5hel2l2y 0:46630122dec9 1 #include "LSM6DS3.h"
5hel2l2y 0:46630122dec9 2
5hel2l2y 0:46630122dec9 3 LSM6DS3::LSM6DS3(PinName sda, PinName scl, uint8_t xgAddr) : i2c(sda, scl)
5hel2l2y 0:46630122dec9 4 {
5hel2l2y 0:46630122dec9 5 // xgAddress will store the 7-bit I2C address, if using I2C.
5hel2l2y 0:46630122dec9 6 xgAddress = xgAddr;
5hel2l2y 0:46630122dec9 7 }
5hel2l2y 0:46630122dec9 8
5hel2l2y 0:46630122dec9 9 uint16_t LSM6DS3::begin(gyro_scale gScl, accel_scale aScl,
5hel2l2y 0:46630122dec9 10 gyro_odr gODR, accel_odr aODR)
5hel2l2y 0:46630122dec9 11 {
5hel2l2y 0:46630122dec9 12 // Store the given scales in class variables. These scale variables
5hel2l2y 0:46630122dec9 13 // are used throughout to calculate the actual g's, DPS,and Gs's.
5hel2l2y 0:46630122dec9 14 gScale = gScl;
5hel2l2y 0:46630122dec9 15 aScale = aScl;
5hel2l2y 0:46630122dec9 16
5hel2l2y 0:46630122dec9 17 // Once we have the scale values, we can calculate the resolution
5hel2l2y 0:46630122dec9 18 // of each sensor. That's what these functions are for. One for each sensor
5hel2l2y 0:46630122dec9 19 calcgRes(); // Calculate DPS / ADC tick, stored in gRes variable
5hel2l2y 0:46630122dec9 20 calcaRes(); // Calculate g / ADC tick, stored in aRes variable
5hel2l2y 0:46630122dec9 21
5hel2l2y 0:46630122dec9 22
5hel2l2y 0:46630122dec9 23 // To verify communication, we can read from the WHO_AM_I register of
5hel2l2y 0:46630122dec9 24 // each device. Store those in a variable so we can return them.
5hel2l2y 0:46630122dec9 25 // The start of the addresses we want to read from
5hel2l2y 0:46630122dec9 26 char cmd[2] = {
5hel2l2y 0:46630122dec9 27 WHO_AM_I_REG,
5hel2l2y 0:46630122dec9 28 0
5hel2l2y 0:46630122dec9 29 };
5hel2l2y 0:46630122dec9 30
5hel2l2y 0:46630122dec9 31 // Write the address we are going to read from and don't end the transaction
5hel2l2y 0:46630122dec9 32 i2c.write(xgAddress, cmd, 1, true);
5hel2l2y 0:46630122dec9 33 // Read in all the 8 bits of data
5hel2l2y 0:46630122dec9 34 i2c.read(xgAddress, cmd+1, 1);
5hel2l2y 0:46630122dec9 35 uint8_t xgTest = cmd[1]; // Read the accel/gyro WHO_AM_I
5hel2l2y 0:46630122dec9 36
5hel2l2y 0:46630122dec9 37 // Gyro initialization stuff:
5hel2l2y 0:46630122dec9 38 initGyro(); // This will "turn on" the gyro. Setting up interrupts, etc.
5hel2l2y 0:46630122dec9 39 setGyroODR(gODR); // Set the gyro output data rate and bandwidth.
5hel2l2y 0:46630122dec9 40 setGyroScale(gScale); // Set the gyro range
5hel2l2y 0:46630122dec9 41
5hel2l2y 0:46630122dec9 42 // Accelerometer initialization stuff:
5hel2l2y 0:46630122dec9 43 initAccel(); // "Turn on" all axes of the accel. Set up interrupts, etc.
5hel2l2y 0:46630122dec9 44 setAccelODR(aODR); // Set the accel data rate.
5hel2l2y 0:46630122dec9 45 setAccelScale(aScale); // Set the accel range.
5hel2l2y 0:46630122dec9 46
5hel2l2y 2:ed14e6196255 47 // Interrupt initialization stuff;
5hel2l2y 2:ed14e6196255 48 initIntr();
5hel2l2y 2:ed14e6196255 49
5hel2l2y 0:46630122dec9 50 // Once everything is initialized, return the WHO_AM_I registers we read:
5hel2l2y 0:46630122dec9 51 return xgTest;
5hel2l2y 0:46630122dec9 52 }
5hel2l2y 0:46630122dec9 53
5hel2l2y 0:46630122dec9 54 void LSM6DS3::initGyro()
5hel2l2y 0:46630122dec9 55 {
5hel2l2y 0:46630122dec9 56 char cmd[4] = {
5hel2l2y 0:46630122dec9 57 CTRL2_G,
5hel2l2y 1:924c7dea286e 58 gScale | G_ODR_104,
5hel2l2y 0:46630122dec9 59 0, // Default data out and int out
5hel2l2y 0:46630122dec9 60 0 // Default power mode and high pass settings
5hel2l2y 0:46630122dec9 61 };
5hel2l2y 0:46630122dec9 62
5hel2l2y 0:46630122dec9 63 // Write the data to the gyro control registers
5hel2l2y 0:46630122dec9 64 i2c.write(xgAddress, cmd, 4);
5hel2l2y 0:46630122dec9 65 }
5hel2l2y 0:46630122dec9 66
5hel2l2y 0:46630122dec9 67 void LSM6DS3::initAccel()
5hel2l2y 0:46630122dec9 68 {
5hel2l2y 0:46630122dec9 69 char cmd[4] = {
5hel2l2y 0:46630122dec9 70 CTRL1_XL,
5hel2l2y 0:46630122dec9 71 0x38, // Enable all axis and don't decimate data in out Registers
5hel2l2y 1:924c7dea286e 72 (A_ODR_104 << 5) | (aScale << 3) | (A_BW_AUTO_SCALE), // 119 Hz ODR, set scale, and auto BW
5hel2l2y 0:46630122dec9 73 0 // Default resolution mode and filtering settings
5hel2l2y 0:46630122dec9 74 };
5hel2l2y 0:46630122dec9 75
5hel2l2y 0:46630122dec9 76 // Write the data to the accel control registers
5hel2l2y 0:46630122dec9 77 i2c.write(xgAddress, cmd, 4);
5hel2l2y 0:46630122dec9 78 }
5hel2l2y 0:46630122dec9 79
5hel2l2y 2:ed14e6196255 80 void LSM6DS3::initIntr()
5hel2l2y 2:ed14e6196255 81 {
5hel2l2y 2:ed14e6196255 82 char cmd[2];
5hel2l2y 2:ed14e6196255 83
5hel2l2y 2:ed14e6196255 84 cmd[0] = TAP_CFG;
5hel2l2y 2:ed14e6196255 85 cmd[1] = 0x0E;
5hel2l2y 2:ed14e6196255 86 i2c.write(xgAddress, cmd, 2);
5hel2l2y 2:ed14e6196255 87 cmd[0] = TAP_THS_6D;
5hel2l2y 2:ed14e6196255 88 cmd[1] = 0x03;
5hel2l2y 2:ed14e6196255 89 i2c.write(xgAddress, cmd, 2);
5hel2l2y 2:ed14e6196255 90 cmd[0] = INT_DUR2;
5hel2l2y 2:ed14e6196255 91 cmd[1] = 0x7F;
5hel2l2y 2:ed14e6196255 92 i2c.write(xgAddress, cmd, 2);
5hel2l2y 2:ed14e6196255 93 cmd[0] = WAKE_UP_THS;
5hel2l2y 2:ed14e6196255 94 cmd[1] = 0x80;
5hel2l2y 2:ed14e6196255 95 i2c.write(xgAddress, cmd, 2);
5hel2l2y 2:ed14e6196255 96 cmd[0] = MD1_CFG;
5hel2l2y 2:ed14e6196255 97 cmd[1] = 0x48;
5hel2l2y 2:ed14e6196255 98 i2c.write(xgAddress, cmd, 2);
5hel2l2y 2:ed14e6196255 99 }
5hel2l2y 2:ed14e6196255 100
5hel2l2y 0:46630122dec9 101 void LSM6DS3::readAccel()
5hel2l2y 0:46630122dec9 102 {
5hel2l2y 0:46630122dec9 103 // The data we are going to read from the accel
5hel2l2y 0:46630122dec9 104 char data[6];
5hel2l2y 0:46630122dec9 105
5hel2l2y 0:46630122dec9 106 // Set addresses
5hel2l2y 0:46630122dec9 107 char subAddressXL = OUTX_L_XL;
5hel2l2y 0:46630122dec9 108 char subAddressXH = OUTX_H_XL;
5hel2l2y 0:46630122dec9 109 char subAddressYL = OUTY_L_XL;
5hel2l2y 0:46630122dec9 110 char subAddressYH = OUTY_H_XL;
5hel2l2y 0:46630122dec9 111 char subAddressZL = OUTZ_L_XL;
5hel2l2y 0:46630122dec9 112 char subAddressZH = OUTZ_H_XL;
5hel2l2y 0:46630122dec9 113
5hel2l2y 0:46630122dec9 114 // Write the address we are going to read from and don't end the transaction
5hel2l2y 0:46630122dec9 115 i2c.write(xgAddress, &subAddressXL, 1, true);
5hel2l2y 0:46630122dec9 116 // Read in register containing the axes data and alocated to the correct index
5hel2l2y 0:46630122dec9 117 i2c.read(xgAddress, data, 1);
5hel2l2y 0:46630122dec9 118
5hel2l2y 0:46630122dec9 119 i2c.write(xgAddress, &subAddressXH, 1, true);
5hel2l2y 0:46630122dec9 120 i2c.read(xgAddress, (data + 1), 1);
5hel2l2y 0:46630122dec9 121 i2c.write(xgAddress, &subAddressYL, 1, true);
5hel2l2y 0:46630122dec9 122 i2c.read(xgAddress, (data + 2), 1);
5hel2l2y 0:46630122dec9 123 i2c.write(xgAddress, &subAddressYH, 1, true);
5hel2l2y 0:46630122dec9 124 i2c.read(xgAddress, (data + 3), 1);
5hel2l2y 0:46630122dec9 125 i2c.write(xgAddress, &subAddressZL, 1, true);
5hel2l2y 0:46630122dec9 126 i2c.read(xgAddress, (data + 4), 1);
5hel2l2y 0:46630122dec9 127 i2c.write(xgAddress, &subAddressZH, 1, true);
5hel2l2y 0:46630122dec9 128 i2c.read(xgAddress, (data + 5), 1);
5hel2l2y 0:46630122dec9 129
5hel2l2y 0:46630122dec9 130 // Reassemble the data and convert to g
5hel2l2y 0:46630122dec9 131 ax_raw = data[0] | (data[1] << 8);
5hel2l2y 0:46630122dec9 132 ay_raw = data[2] | (data[3] << 8);
5hel2l2y 0:46630122dec9 133 az_raw = data[4] | (data[5] << 8);
5hel2l2y 0:46630122dec9 134 ax = ax_raw * aRes;
5hel2l2y 0:46630122dec9 135 ay = ay_raw * aRes;
5hel2l2y 0:46630122dec9 136 az = az_raw * aRes;
5hel2l2y 0:46630122dec9 137 }
5hel2l2y 0:46630122dec9 138
5hel2l2y 2:ed14e6196255 139 void LSM6DS3::readIntr()
5hel2l2y 2:ed14e6196255 140 {
5hel2l2y 2:ed14e6196255 141 char data[1];
5hel2l2y 2:ed14e6196255 142 char subAddress = TAP_SRC;
5hel2l2y 2:ed14e6196255 143
5hel2l2y 2:ed14e6196255 144 i2c.write(xgAddress, &subAddress, 1, true);
5hel2l2y 2:ed14e6196255 145 i2c.read(xgAddress, data, 1);
5hel2l2y 2:ed14e6196255 146
5hel2l2y 2:ed14e6196255 147 intr = (float)data[0];
5hel2l2y 2:ed14e6196255 148 }
5hel2l2y 2:ed14e6196255 149
5hel2l2y 0:46630122dec9 150
5hel2l2y 0:46630122dec9 151 void LSM6DS3::readGyro()
5hel2l2y 0:46630122dec9 152 {
5hel2l2y 0:46630122dec9 153 // The data we are going to read from the gyro
5hel2l2y 0:46630122dec9 154 char data[6];
5hel2l2y 0:46630122dec9 155
5hel2l2y 0:46630122dec9 156 // Set addresses
5hel2l2y 0:46630122dec9 157 char subAddressXL = OUTX_L_G;
5hel2l2y 0:46630122dec9 158 char subAddressXH = OUTX_H_G;
5hel2l2y 0:46630122dec9 159 char subAddressYL = OUTY_L_G;
5hel2l2y 0:46630122dec9 160 char subAddressYH = OUTY_H_G;
5hel2l2y 0:46630122dec9 161 char subAddressZL = OUTZ_L_G;
5hel2l2y 0:46630122dec9 162 char subAddressZH = OUTZ_H_G;
5hel2l2y 0:46630122dec9 163
5hel2l2y 0:46630122dec9 164 // Write the address we are going to read from and don't end the transaction
5hel2l2y 0:46630122dec9 165 i2c.write(xgAddress, &subAddressXL, 1, true);
5hel2l2y 0:46630122dec9 166 // Read in register containing the axes data and alocated to the correct index
5hel2l2y 0:46630122dec9 167 i2c.read(xgAddress, data, 1);
5hel2l2y 0:46630122dec9 168
5hel2l2y 0:46630122dec9 169 i2c.write(xgAddress, &subAddressXH, 1, true);
5hel2l2y 0:46630122dec9 170 i2c.read(xgAddress, (data + 1), 1);
5hel2l2y 0:46630122dec9 171 i2c.write(xgAddress, &subAddressYL, 1, true);
5hel2l2y 0:46630122dec9 172 i2c.read(xgAddress, (data + 2), 1);
5hel2l2y 0:46630122dec9 173 i2c.write(xgAddress, &subAddressYH, 1, true);
5hel2l2y 0:46630122dec9 174 i2c.read(xgAddress, (data + 3), 1);
5hel2l2y 0:46630122dec9 175 i2c.write(xgAddress, &subAddressZL, 1, true);
5hel2l2y 0:46630122dec9 176 i2c.read(xgAddress, (data + 4), 1);
5hel2l2y 0:46630122dec9 177 i2c.write(xgAddress, &subAddressZH, 1, true);
5hel2l2y 0:46630122dec9 178 i2c.read(xgAddress, (data + 5), 1);
5hel2l2y 0:46630122dec9 179
5hel2l2y 0:46630122dec9 180 // Reassemble the data and convert to degrees/sec
5hel2l2y 0:46630122dec9 181 gx_raw = data[0] | (data[1] << 8);
5hel2l2y 0:46630122dec9 182 gy_raw = data[2] | (data[3] << 8);
5hel2l2y 0:46630122dec9 183 gz_raw = data[4] | (data[5] << 8);
5hel2l2y 0:46630122dec9 184 gx = gx_raw * gRes;
5hel2l2y 0:46630122dec9 185 gy = gy_raw * gRes;
5hel2l2y 0:46630122dec9 186 gz = gz_raw * gRes;
5hel2l2y 0:46630122dec9 187 }
5hel2l2y 0:46630122dec9 188
5hel2l2y 0:46630122dec9 189 void LSM6DS3::setGyroScale(gyro_scale gScl)
5hel2l2y 0:46630122dec9 190 {
5hel2l2y 0:46630122dec9 191 // The start of the addresses we want to read from
5hel2l2y 0:46630122dec9 192 char cmd[2] = {
5hel2l2y 0:46630122dec9 193 CTRL2_G,
5hel2l2y 0:46630122dec9 194 0
5hel2l2y 0:46630122dec9 195 };
5hel2l2y 0:46630122dec9 196
5hel2l2y 0:46630122dec9 197 // Write the address we are going to read from and don't end the transaction
5hel2l2y 0:46630122dec9 198 i2c.write(xgAddress, cmd, 1, true);
5hel2l2y 0:46630122dec9 199 // Read in all the 8 bits of data
5hel2l2y 0:46630122dec9 200 i2c.read(xgAddress, cmd+1, 1);
5hel2l2y 0:46630122dec9 201
5hel2l2y 0:46630122dec9 202 // Then mask out the gyro scale bits:
5hel2l2y 0:46630122dec9 203 cmd[1] &= 0xFF^(0x3 << 3);
5hel2l2y 0:46630122dec9 204 // Then shift in our new scale bits:
5hel2l2y 0:46630122dec9 205 cmd[1] |= gScl << 3;
5hel2l2y 0:46630122dec9 206
5hel2l2y 0:46630122dec9 207 // Write the gyroscale out to the gyro
5hel2l2y 0:46630122dec9 208 i2c.write(xgAddress, cmd, 2);
5hel2l2y 0:46630122dec9 209
5hel2l2y 0:46630122dec9 210 // We've updated the sensor, but we also need to update our class variables
5hel2l2y 0:46630122dec9 211 // First update gScale:
5hel2l2y 0:46630122dec9 212 gScale = gScl;
5hel2l2y 0:46630122dec9 213 // Then calculate a new gRes, which relies on gScale being set correctly:
5hel2l2y 0:46630122dec9 214 calcgRes();
5hel2l2y 0:46630122dec9 215 }
5hel2l2y 0:46630122dec9 216
5hel2l2y 0:46630122dec9 217 void LSM6DS3::setAccelScale(accel_scale aScl)
5hel2l2y 0:46630122dec9 218 {
5hel2l2y 0:46630122dec9 219 // The start of the addresses we want to read from
5hel2l2y 0:46630122dec9 220 char cmd[2] = {
5hel2l2y 0:46630122dec9 221 CTRL1_XL,
5hel2l2y 0:46630122dec9 222 0
5hel2l2y 0:46630122dec9 223 };
5hel2l2y 0:46630122dec9 224
5hel2l2y 0:46630122dec9 225 // Write the address we are going to read from and don't end the transaction
5hel2l2y 0:46630122dec9 226 i2c.write(xgAddress, cmd, 1, true);
5hel2l2y 0:46630122dec9 227 // Read in all the 8 bits of data
5hel2l2y 0:46630122dec9 228 i2c.read(xgAddress, cmd+1, 1);
5hel2l2y 0:46630122dec9 229
5hel2l2y 0:46630122dec9 230 // Then mask out the accel scale bits:
5hel2l2y 0:46630122dec9 231 cmd[1] &= 0xFF^(0x3 << 3);
5hel2l2y 0:46630122dec9 232 // Then shift in our new scale bits:
5hel2l2y 0:46630122dec9 233 cmd[1] |= aScl << 3;
5hel2l2y 0:46630122dec9 234
5hel2l2y 0:46630122dec9 235 // Write the accelscale out to the accel
5hel2l2y 0:46630122dec9 236 i2c.write(xgAddress, cmd, 2);
5hel2l2y 0:46630122dec9 237
5hel2l2y 0:46630122dec9 238 // We've updated the sensor, but we also need to update our class variables
5hel2l2y 0:46630122dec9 239 // First update aScale:
5hel2l2y 0:46630122dec9 240 aScale = aScl;
5hel2l2y 0:46630122dec9 241 // Then calculate a new aRes, which relies on aScale being set correctly:
5hel2l2y 0:46630122dec9 242 calcaRes();
5hel2l2y 0:46630122dec9 243 }
5hel2l2y 0:46630122dec9 244
5hel2l2y 0:46630122dec9 245 void LSM6DS3::setGyroODR(gyro_odr gRate)
5hel2l2y 0:46630122dec9 246 {
5hel2l2y 0:46630122dec9 247 // The start of the addresses we want to read from
5hel2l2y 0:46630122dec9 248 char cmd[2] = {
5hel2l2y 0:46630122dec9 249 CTRL2_G,
5hel2l2y 0:46630122dec9 250 0
5hel2l2y 0:46630122dec9 251 };
5hel2l2y 1:924c7dea286e 252
5hel2l2y 1:924c7dea286e 253 // Set low power based on ODR, else keep sensor on high performance
5hel2l2y 1:924c7dea286e 254 if(gRate == G_ODR_13_BW_0 | gRate == G_ODR_26_BW_2 | gRate == G_ODR_52_BW_16) {
5hel2l2y 1:924c7dea286e 255 char cmdLow[2] ={
5hel2l2y 1:924c7dea286e 256 CTRL7_G,
5hel2l2y 1:924c7dea286e 257 1
5hel2l2y 1:924c7dea286e 258 };
5hel2l2y 1:924c7dea286e 259
5hel2l2y 1:924c7dea286e 260 i2c.write(xgAddress, cmdLow, 2);
5hel2l2y 1:924c7dea286e 261 }
5hel2l2y 1:924c7dea286e 262 else {
5hel2l2y 1:924c7dea286e 263 char cmdLow[2] ={
5hel2l2y 1:924c7dea286e 264 CTRL7_G,
5hel2l2y 1:924c7dea286e 265 0
5hel2l2y 1:924c7dea286e 266 };
5hel2l2y 1:924c7dea286e 267
5hel2l2y 1:924c7dea286e 268 i2c.write(xgAddress, cmdLow, 2);
5hel2l2y 1:924c7dea286e 269 }
5hel2l2y 0:46630122dec9 270
5hel2l2y 0:46630122dec9 271 // Write the address we are going to read from and don't end the transaction
5hel2l2y 0:46630122dec9 272 i2c.write(xgAddress, cmd, 1, true);
5hel2l2y 0:46630122dec9 273 // Read in all the 8 bits of data
5hel2l2y 0:46630122dec9 274 i2c.read(xgAddress, cmd+1, 1);
5hel2l2y 0:46630122dec9 275
5hel2l2y 0:46630122dec9 276 // Then mask out the gyro odr bits:
5hel2l2y 0:46630122dec9 277 cmd[1] &= (0x3 << 3);
5hel2l2y 0:46630122dec9 278 // Then shift in our new odr bits:
5hel2l2y 0:46630122dec9 279 cmd[1] |= gRate;
5hel2l2y 0:46630122dec9 280
5hel2l2y 0:46630122dec9 281 // Write the gyroodr out to the gyro
5hel2l2y 0:46630122dec9 282 i2c.write(xgAddress, cmd, 2);
5hel2l2y 0:46630122dec9 283 }
5hel2l2y 0:46630122dec9 284
5hel2l2y 0:46630122dec9 285 void LSM6DS3::setAccelODR(accel_odr aRate)
5hel2l2y 0:46630122dec9 286 {
5hel2l2y 0:46630122dec9 287 // The start of the addresses we want to read from
5hel2l2y 0:46630122dec9 288 char cmd[2] = {
5hel2l2y 0:46630122dec9 289 CTRL1_XL,
5hel2l2y 0:46630122dec9 290 0
5hel2l2y 0:46630122dec9 291 };
5hel2l2y 1:924c7dea286e 292
5hel2l2y 1:924c7dea286e 293 // Set low power based on ODR, else keep sensor on high performance
5hel2l2y 1:924c7dea286e 294 if(aRate == A_ODR_13 | aRate == A_ODR_26 | aRate == A_ODR_52) {
5hel2l2y 1:924c7dea286e 295 char cmdLow[2] ={
5hel2l2y 1:924c7dea286e 296 CTRL6_C,
5hel2l2y 1:924c7dea286e 297 1
5hel2l2y 1:924c7dea286e 298 };
5hel2l2y 1:924c7dea286e 299
5hel2l2y 1:924c7dea286e 300 i2c.write(xgAddress, cmdLow, 2);
5hel2l2y 1:924c7dea286e 301 }
5hel2l2y 1:924c7dea286e 302 else {
5hel2l2y 1:924c7dea286e 303 char cmdLow[2] ={
5hel2l2y 1:924c7dea286e 304 CTRL6_C,
5hel2l2y 1:924c7dea286e 305 0
5hel2l2y 1:924c7dea286e 306 };
5hel2l2y 1:924c7dea286e 307
5hel2l2y 1:924c7dea286e 308 i2c.write(xgAddress, cmdLow, 2);
5hel2l2y 1:924c7dea286e 309 }
5hel2l2y 0:46630122dec9 310
5hel2l2y 0:46630122dec9 311 // Write the address we are going to read from and don't end the transaction
5hel2l2y 0:46630122dec9 312 i2c.write(xgAddress, cmd, 1, true);
5hel2l2y 0:46630122dec9 313 // Read in all the 8 bits of data
5hel2l2y 0:46630122dec9 314 i2c.read(xgAddress, cmd+1, 1);
5hel2l2y 0:46630122dec9 315
5hel2l2y 0:46630122dec9 316 // Then mask out the accel odr bits:
5hel2l2y 0:46630122dec9 317 cmd[1] &= 0xFF^(0x7 << 5);
5hel2l2y 0:46630122dec9 318 // Then shift in our new odr bits:
5hel2l2y 0:46630122dec9 319 cmd[1] |= aRate << 5;
5hel2l2y 0:46630122dec9 320
5hel2l2y 0:46630122dec9 321 // Write the accelodr out to the accel
5hel2l2y 0:46630122dec9 322 i2c.write(xgAddress, cmd, 2);
5hel2l2y 0:46630122dec9 323 }
5hel2l2y 0:46630122dec9 324
5hel2l2y 0:46630122dec9 325 void LSM6DS3::calcgRes()
5hel2l2y 0:46630122dec9 326 {
5hel2l2y 0:46630122dec9 327 // Possible gyro scales (and their register bit settings) are:
5hel2l2y 0:46630122dec9 328 // 245 DPS (00), 500 DPS (01), 2000 DPS (10).
5hel2l2y 0:46630122dec9 329 switch (gScale)
5hel2l2y 0:46630122dec9 330 {
5hel2l2y 0:46630122dec9 331 case G_SCALE_245DPS:
5hel2l2y 0:46630122dec9 332 gRes = 245.0 / 32768.0;
5hel2l2y 0:46630122dec9 333 break;
5hel2l2y 0:46630122dec9 334 case G_SCALE_500DPS:
5hel2l2y 0:46630122dec9 335 gRes = 500.0 / 32768.0;
5hel2l2y 0:46630122dec9 336 break;
5hel2l2y 0:46630122dec9 337 case G_SCALE_2000DPS:
5hel2l2y 0:46630122dec9 338 gRes = 2000.0 / 32768.0;
5hel2l2y 0:46630122dec9 339 break;
5hel2l2y 0:46630122dec9 340 }
5hel2l2y 0:46630122dec9 341 }
5hel2l2y 0:46630122dec9 342
5hel2l2y 0:46630122dec9 343 void LSM6DS3::calcaRes()
5hel2l2y 0:46630122dec9 344 {
5hel2l2y 0:46630122dec9 345 // Possible accelerometer scales (and their register bit settings) are:
5hel2l2y 0:46630122dec9 346 // 2 g (000), 4g (001), 6g (010) 8g (011), 16g (100).
5hel2l2y 0:46630122dec9 347 switch (aScale)
5hel2l2y 0:46630122dec9 348 {
5hel2l2y 0:46630122dec9 349 case A_SCALE_2G:
5hel2l2y 0:46630122dec9 350 aRes = 2.0 / 32768.0;
5hel2l2y 0:46630122dec9 351 break;
5hel2l2y 0:46630122dec9 352 case A_SCALE_4G:
5hel2l2y 0:46630122dec9 353 aRes = 4.0 / 32768.0;
5hel2l2y 0:46630122dec9 354 break;
5hel2l2y 0:46630122dec9 355 case A_SCALE_8G:
5hel2l2y 0:46630122dec9 356 aRes = 8.0 / 32768.0;
5hel2l2y 0:46630122dec9 357 break;
5hel2l2y 0:46630122dec9 358 case A_SCALE_16G:
5hel2l2y 0:46630122dec9 359 aRes = 16.0 / 32768.0;
5hel2l2y 0:46630122dec9 360 break;
5hel2l2y 0:46630122dec9 361 }
5hel2l2y 0:46630122dec9 362 }