LSM6DS3 Library by sj

Fork of LSM6DS3 by Sherry Yang

Committer:
oreo329
Date:
Tue May 02 17:30:18 2017 +0000
Revision:
3:5f90ed3ba2e2
fixed accelerometer & gyro begin errors(both odr, scale); ; now its working at diff odrs &scales;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
oreo329 3:5f90ed3ba2e2 1 // Based on Eugene Gonzalez's version of LSM9DS1_Demo
oreo329 3:5f90ed3ba2e2 2 // Modified by Sherry Yang for LSM6DS3 sensor
oreo329 3:5f90ed3ba2e2 3 #ifndef _LSM6DS3_H__
oreo329 3:5f90ed3ba2e2 4 #define _LSM6DS3_H__
oreo329 3:5f90ed3ba2e2 5
oreo329 3:5f90ed3ba2e2 6 #include "mbed.h"
oreo329 3:5f90ed3ba2e2 7
oreo329 3:5f90ed3ba2e2 8 /////////////////////////////////////////
oreo329 3:5f90ed3ba2e2 9 // LSM6DS3 Accel/Gyro (XL/G) Registers //
oreo329 3:5f90ed3ba2e2 10 /////////////////////////////////////////
oreo329 3:5f90ed3ba2e2 11 #define RAM_ACCESS 0x01
oreo329 3:5f90ed3ba2e2 12 #define SENSOR_SYNC_TIME 0x04
oreo329 3:5f90ed3ba2e2 13 #define SENSOR_SYNC_EN 0x05
oreo329 3:5f90ed3ba2e2 14 #define FIFO_CTRL1 0x06
oreo329 3:5f90ed3ba2e2 15 #define FIFO_CTRL2 0x07
oreo329 3:5f90ed3ba2e2 16 #define FIFO_CTRL3 0x08
oreo329 3:5f90ed3ba2e2 17 #define FIFO_CTRL4 0x09
oreo329 3:5f90ed3ba2e2 18 #define FIFO_CTRL5 0x0A
oreo329 3:5f90ed3ba2e2 19 #define ORIENT_CFG_G 0x0B
oreo329 3:5f90ed3ba2e2 20 #define REFERENCE_G 0x0C
oreo329 3:5f90ed3ba2e2 21 #define INT1_CTRL 0x0D
oreo329 3:5f90ed3ba2e2 22 #define INT2_CTRL 0x0E
oreo329 3:5f90ed3ba2e2 23 #define WHO_AM_I_REG 0X0F
oreo329 3:5f90ed3ba2e2 24 #define CTRL1_XL 0x10
oreo329 3:5f90ed3ba2e2 25 #define CTRL2_G 0x11
oreo329 3:5f90ed3ba2e2 26 #define CTRL3_C 0x12
oreo329 3:5f90ed3ba2e2 27 #define CTRL4_C 0x13
oreo329 3:5f90ed3ba2e2 28 #define CTRL5_C 0x14
oreo329 3:5f90ed3ba2e2 29 #define CTRL6_C 0x15
oreo329 3:5f90ed3ba2e2 30 #define CTRL7_G 0x16
oreo329 3:5f90ed3ba2e2 31 #define CTRL8_XL 0x17
oreo329 3:5f90ed3ba2e2 32 #define CTRL9_XL 0x18
oreo329 3:5f90ed3ba2e2 33 #define CTRL10_C 0x19
oreo329 3:5f90ed3ba2e2 34 #define MASTER_CONFIG 0x1A
oreo329 3:5f90ed3ba2e2 35 #define WAKE_UP_SRC 0x1B
oreo329 3:5f90ed3ba2e2 36 #define TAP_SRC 0x1C
oreo329 3:5f90ed3ba2e2 37 #define D6D_SRC 0x1D
oreo329 3:5f90ed3ba2e2 38 #define STATUS_REG 0x1E
oreo329 3:5f90ed3ba2e2 39 #define OUT_TEMP_L 0x20
oreo329 3:5f90ed3ba2e2 40 #define OUT_TEMP_H 0x21
oreo329 3:5f90ed3ba2e2 41 #define OUTX_L_G 0x22
oreo329 3:5f90ed3ba2e2 42 #define OUTX_H_G 0x23
oreo329 3:5f90ed3ba2e2 43 #define OUTY_L_G 0x24
oreo329 3:5f90ed3ba2e2 44 #define OUTY_H_G 0x25
oreo329 3:5f90ed3ba2e2 45 #define OUTZ_L_G 0x26
oreo329 3:5f90ed3ba2e2 46 #define OUTZ_H_G 0x27
oreo329 3:5f90ed3ba2e2 47 #define OUTX_L_XL 0x28
oreo329 3:5f90ed3ba2e2 48 #define OUTX_H_XL 0x29
oreo329 3:5f90ed3ba2e2 49 #define OUTY_L_XL 0x2A
oreo329 3:5f90ed3ba2e2 50 #define OUTY_H_XL 0x2B
oreo329 3:5f90ed3ba2e2 51 #define OUTZ_L_XL 0x2C
oreo329 3:5f90ed3ba2e2 52 #define OUTZ_H_XL 0x2D
oreo329 3:5f90ed3ba2e2 53 #define SENSORHUB1_REG 0x2E
oreo329 3:5f90ed3ba2e2 54 #define SENSORHUB2_REG 0x2F
oreo329 3:5f90ed3ba2e2 55 #define SENSORHUB3_REG 0x30
oreo329 3:5f90ed3ba2e2 56 #define SENSORHUB4_REG 0x31
oreo329 3:5f90ed3ba2e2 57 #define SENSORHUB5_REG 0x32
oreo329 3:5f90ed3ba2e2 58 #define SENSORHUB6_REG 0x33
oreo329 3:5f90ed3ba2e2 59 #define SENSORHUB7_REG 0x34
oreo329 3:5f90ed3ba2e2 60 #define SENSORHUB8_REG 0x35
oreo329 3:5f90ed3ba2e2 61 #define SENSORHUB9_REG 0x36
oreo329 3:5f90ed3ba2e2 62 #define SENSORHUB10_REG 0x37
oreo329 3:5f90ed3ba2e2 63 #define SENSORHUB11_REG 0x38
oreo329 3:5f90ed3ba2e2 64 #define SENSORHUB12_REG 0x39
oreo329 3:5f90ed3ba2e2 65 #define FIFO_STATUS1 0x3A
oreo329 3:5f90ed3ba2e2 66 #define FIFO_STATUS2 0x3B
oreo329 3:5f90ed3ba2e2 67 #define FIFO_STATUS3 0x3C
oreo329 3:5f90ed3ba2e2 68 #define FIFO_STATUS4 0x3D
oreo329 3:5f90ed3ba2e2 69 #define FIFO_DATA_OUT_L 0x3E
oreo329 3:5f90ed3ba2e2 70 #define FIFO_DATA_OUT_H 0x3F
oreo329 3:5f90ed3ba2e2 71 #define TIMESTAMP0_REG 0x40
oreo329 3:5f90ed3ba2e2 72 #define TIMESTAMP1_REG 0x41
oreo329 3:5f90ed3ba2e2 73 #define TIMESTAMP2_REG 0x42
oreo329 3:5f90ed3ba2e2 74 #define STEP_COUNTER_L 0x4B
oreo329 3:5f90ed3ba2e2 75 #define STEP_COUNTER_H 0x4C
oreo329 3:5f90ed3ba2e2 76 #define FUNC_SR 0x53
oreo329 3:5f90ed3ba2e2 77 #define TAP_CFG 0x58
oreo329 3:5f90ed3ba2e2 78 #define TAP_THS_6D 0x59
oreo329 3:5f90ed3ba2e2 79 #define INT_DUR2 0x5A
oreo329 3:5f90ed3ba2e2 80 #define WAKE_UP_THS 0x5B
oreo329 3:5f90ed3ba2e2 81 #define WAKE_UP_DUR 0x5C
oreo329 3:5f90ed3ba2e2 82 #define FREE_FALL 0x5D
oreo329 3:5f90ed3ba2e2 83 #define MD1_CFG 0x5E
oreo329 3:5f90ed3ba2e2 84 #define MD2_CFG 0x5F
oreo329 3:5f90ed3ba2e2 85
oreo329 3:5f90ed3ba2e2 86 // Possible I2C addresses for the accel/gyro
oreo329 3:5f90ed3ba2e2 87 #define LSM6DS3_AG_I2C_ADDR(sa0) ((sa0) ? 0xD6 : 0xD4)
oreo329 3:5f90ed3ba2e2 88
oreo329 3:5f90ed3ba2e2 89 /**
oreo329 3:5f90ed3ba2e2 90 * LSM6DS3 Class - driver for the 9 DoF IMU
oreo329 3:5f90ed3ba2e2 91 */
oreo329 3:5f90ed3ba2e2 92 class LSM6DS3
oreo329 3:5f90ed3ba2e2 93 {
oreo329 3:5f90ed3ba2e2 94 public:
oreo329 3:5f90ed3ba2e2 95
oreo329 3:5f90ed3ba2e2 96 /// gyro_scale defines the possible full-scale ranges of the gyroscope:
oreo329 3:5f90ed3ba2e2 97 enum gyro_scale
oreo329 3:5f90ed3ba2e2 98 {
oreo329 3:5f90ed3ba2e2 99 G_SCALE_245DPS = 0x0 << 2, // 00 << 3: +/- 245 degrees per second
oreo329 3:5f90ed3ba2e2 100 G_SCALE_500DPS = 0x1 << 2, // 01 << 3: +/- 500 dps
oreo329 3:5f90ed3ba2e2 101 G_SCALE_1000DPS = 0x2 << 2, // 10 << 3: +/- 1000 dps
oreo329 3:5f90ed3ba2e2 102 G_SCALE_2000DPS = 0x3 << 2 // 11 << 3: +/- 2000 dps
oreo329 3:5f90ed3ba2e2 103 };
oreo329 3:5f90ed3ba2e2 104
oreo329 3:5f90ed3ba2e2 105 /// gyro_odr defines all possible data rate/bandwidth combos of the gyro:
oreo329 3:5f90ed3ba2e2 106 enum gyro_odr
oreo329 3:5f90ed3ba2e2 107 { // ODR (Hz) --- Cutoff
oreo329 3:5f90ed3ba2e2 108 G_POWER_DOWN = 0x00, // 0 0
oreo329 3:5f90ed3ba2e2 109 G_ODR_13_BW_0 = 0x10, // 12.5 0.0081 low power
oreo329 3:5f90ed3ba2e2 110 G_ODR_26_BW_2 = 0x20, // 26 2.07 low power
oreo329 3:5f90ed3ba2e2 111 G_ODR_52_BW_16 = 0x30, // 52 16.32 low power
oreo329 3:5f90ed3ba2e2 112 G_ODR_104 = 0x40, // 104
oreo329 3:5f90ed3ba2e2 113 G_ODR_208 = 0x50, // 208
oreo329 3:5f90ed3ba2e2 114 G_ODR_416 = 0x60, // 416
oreo329 3:5f90ed3ba2e2 115 G_ODR_833 = 0x70, // 833
oreo329 3:5f90ed3ba2e2 116 G_ODR_1660 = 0x80 // 1660
oreo329 3:5f90ed3ba2e2 117 };
oreo329 3:5f90ed3ba2e2 118
oreo329 3:5f90ed3ba2e2 119 /// accel_scale defines all possible FSR's of the accelerometer:
oreo329 3:5f90ed3ba2e2 120 enum accel_scale
oreo329 3:5f90ed3ba2e2 121 {
oreo329 3:5f90ed3ba2e2 122 A_SCALE_2G = 0x00, // 00: +/- 2g
oreo329 3:5f90ed3ba2e2 123 A_SCALE_16G = 0x04,// 01: +/- 16g
oreo329 3:5f90ed3ba2e2 124 A_SCALE_4G = 0x08, // 10: +/- 4g
oreo329 3:5f90ed3ba2e2 125 A_SCALE_8G = 0x0C // 11: +/- 8g
oreo329 3:5f90ed3ba2e2 126 };
oreo329 3:5f90ed3ba2e2 127
oreo329 3:5f90ed3ba2e2 128 /// accel_oder defines all possible output data rates of the accelerometer:
oreo329 3:5f90ed3ba2e2 129 enum accel_odr
oreo329 3:5f90ed3ba2e2 130 {
oreo329 3:5f90ed3ba2e2 131 A_POWER_DOWN=0x00, // Power-down mode (0x0)
oreo329 3:5f90ed3ba2e2 132 A_ODR_13=0x10, // 12.5 Hz (0x1) low power
oreo329 3:5f90ed3ba2e2 133 A_ODR_26=0x20, // 26 Hz (0x2) low power
oreo329 3:5f90ed3ba2e2 134 A_ODR_52=0x30, // 52 Hz (0x3) low power
oreo329 3:5f90ed3ba2e2 135 A_ODR_104=0x40, // 104 Hz (0x4) normal mode
oreo329 3:5f90ed3ba2e2 136 A_ODR_208=0x50, // 208 Hz (0x5) normal mode
oreo329 3:5f90ed3ba2e2 137 A_ODR_416=0x60, // 416 Hz (0x6) high performance
oreo329 3:5f90ed3ba2e2 138 A_ODR_833=0x70, // 833 Hz (0x7) high performance
oreo329 3:5f90ed3ba2e2 139 A_ODR_1660=0x80, // 1.66 kHz (0x8) high performance
oreo329 3:5f90ed3ba2e2 140 A_ODR_3330=0x90, // 3.33 kHz (0x9) high performance
oreo329 3:5f90ed3ba2e2 141 A_ODR_6660=0xA0, // 6.66 kHz (0xA) high performance
oreo329 3:5f90ed3ba2e2 142 };
oreo329 3:5f90ed3ba2e2 143
oreo329 3:5f90ed3ba2e2 144 // accel_bw defines all possible bandwiths for low-pass filter of the accelerometer:
oreo329 3:5f90ed3ba2e2 145 enum accel_bw
oreo329 3:5f90ed3ba2e2 146 {
oreo329 3:5f90ed3ba2e2 147 A_BW_AUTO_SCALE = 0x0, // Automatic BW scaling (0x0)
oreo329 3:5f90ed3ba2e2 148 A_BW_400 = 0x0, // 408 Hz (0x0)
oreo329 3:5f90ed3ba2e2 149 A_BW_200 = 0x1, // 211 Hz (0x1)
oreo329 3:5f90ed3ba2e2 150 A_BW_100 = 0x2, // 105 Hz (0x2)
oreo329 3:5f90ed3ba2e2 151 A_BW_50 = 0x3 // 50 Hz (0x3)
oreo329 3:5f90ed3ba2e2 152 };
oreo329 3:5f90ed3ba2e2 153
oreo329 3:5f90ed3ba2e2 154
oreo329 3:5f90ed3ba2e2 155
oreo329 3:5f90ed3ba2e2 156 // We'll store the gyro, and accel, readings in a series of
oreo329 3:5f90ed3ba2e2 157 // public class variables. Each sensor gets three variables -- one for each
oreo329 3:5f90ed3ba2e2 158 // axis. Call readGyro(), and readAccel() first, before using
oreo329 3:5f90ed3ba2e2 159 // these variables!
oreo329 3:5f90ed3ba2e2 160 // These values are the RAW signed 16-bit readings from the sensors.
oreo329 3:5f90ed3ba2e2 161 int16_t gx_raw, gy_raw, gz_raw; // x, y, and z axis readings of the gyroscope
oreo329 3:5f90ed3ba2e2 162 int16_t ax_raw, ay_raw, az_raw; // x, y, and z axis readings of the accelerometer
oreo329 3:5f90ed3ba2e2 163 int16_t temperature_raw;
oreo329 3:5f90ed3ba2e2 164
oreo329 3:5f90ed3ba2e2 165 // floating-point values of scaled data in real-world units
oreo329 3:5f90ed3ba2e2 166 float gx, gy, gz;
oreo329 3:5f90ed3ba2e2 167 float ax, ay, az;
oreo329 3:5f90ed3ba2e2 168 float temperature_c, temperature_f; // temperature in celcius and fahrenheit
oreo329 3:5f90ed3ba2e2 169 float intr;
oreo329 3:5f90ed3ba2e2 170
oreo329 3:5f90ed3ba2e2 171
oreo329 3:5f90ed3ba2e2 172 /** LSM6DS3 -- LSM6DS3 class constructor
oreo329 3:5f90ed3ba2e2 173 * The constructor will set up a handful of private variables, and set the
oreo329 3:5f90ed3ba2e2 174 * communication mode as well.
oreo329 3:5f90ed3ba2e2 175 * Input:
oreo329 3:5f90ed3ba2e2 176 * - interface = Either MODE_SPI or MODE_I2C, whichever you're using
oreo329 3:5f90ed3ba2e2 177 * to talk to the IC.
oreo329 3:5f90ed3ba2e2 178 * - xgAddr = If MODE_I2C, this is the I2C address of the accel/gyro.
oreo329 3:5f90ed3ba2e2 179 * If MODE_SPI, this is the chip select pin of the accel/gyro (CS_A/G)
oreo329 3:5f90ed3ba2e2 180 */
oreo329 3:5f90ed3ba2e2 181 LSM6DS3(PinName sda, PinName scl, uint8_t xgAddr = LSM6DS3_AG_I2C_ADDR(1));
oreo329 3:5f90ed3ba2e2 182
oreo329 3:5f90ed3ba2e2 183 /** begin() -- Initialize the gyro, and accelerometer.
oreo329 3:5f90ed3ba2e2 184 * This will set up the scale and output rate of each sensor. It'll also
oreo329 3:5f90ed3ba2e2 185 * "turn on" every sensor and every axis of every sensor.
oreo329 3:5f90ed3ba2e2 186 * Input:
oreo329 3:5f90ed3ba2e2 187 * - gScl = The scale of the gyroscope. This should be a gyro_scale value.
oreo329 3:5f90ed3ba2e2 188 * - aScl = The scale of the accelerometer. Should be a accel_scale value.
oreo329 3:5f90ed3ba2e2 189 * - gODR = Output data rate of the gyroscope. gyro_odr value.
oreo329 3:5f90ed3ba2e2 190 * - aODR = Output data rate of the accelerometer. accel_odr value.
oreo329 3:5f90ed3ba2e2 191 * Output: The function will return an unsigned 16-bit value. The most-sig
oreo329 3:5f90ed3ba2e2 192 * bytes of the output are the WHO_AM_I reading of the accel/gyro.
oreo329 3:5f90ed3ba2e2 193 * All parameters have a defaulted value, so you can call just "begin()".
oreo329 3:5f90ed3ba2e2 194 * Default values are FSR's of: +/- 245DPS, 4g, 2Gs; ODRs of 119 Hz for
oreo329 3:5f90ed3ba2e2 195 * gyro, 119 Hz for accelerometer.
oreo329 3:5f90ed3ba2e2 196 * Use the return value of this function to verify communication.
oreo329 3:5f90ed3ba2e2 197 */
oreo329 3:5f90ed3ba2e2 198 uint16_t begin(gyro_scale gScl = G_SCALE_245DPS,
oreo329 3:5f90ed3ba2e2 199 accel_scale aScl = A_SCALE_2G, gyro_odr gODR = G_ODR_104,
oreo329 3:5f90ed3ba2e2 200 accel_odr aODR = A_ODR_104);
oreo329 3:5f90ed3ba2e2 201
oreo329 3:5f90ed3ba2e2 202 /** readGyro() -- Read the gyroscope output registers.
oreo329 3:5f90ed3ba2e2 203 * This function will read all six gyroscope output registers.
oreo329 3:5f90ed3ba2e2 204 * The readings are stored in the class' gx_raw, gy_raw, and gz_raw variables. Read
oreo329 3:5f90ed3ba2e2 205 * those _after_ calling readGyro().
oreo329 3:5f90ed3ba2e2 206 */
oreo329 3:5f90ed3ba2e2 207 void readGyro();
oreo329 3:5f90ed3ba2e2 208
oreo329 3:5f90ed3ba2e2 209 /** readAccel() -- Read the accelerometer output registers.
oreo329 3:5f90ed3ba2e2 210 * This function will read all six accelerometer output registers.
oreo329 3:5f90ed3ba2e2 211 * The readings are stored in the class' ax_raw, ay_raw, and az_raw variables. Read
oreo329 3:5f90ed3ba2e2 212 * those _after_ calling readAccel().
oreo329 3:5f90ed3ba2e2 213 */
oreo329 3:5f90ed3ba2e2 214 void readAccel();
oreo329 3:5f90ed3ba2e2 215
oreo329 3:5f90ed3ba2e2 216 /** readTemp() -- Read the temperature output register.
oreo329 3:5f90ed3ba2e2 217 * This function will read two temperature output registers.
oreo329 3:5f90ed3ba2e2 218 * The combined readings are stored in the class' temperature variables. Read
oreo329 3:5f90ed3ba2e2 219 * those _after_ calling readTemp().
oreo329 3:5f90ed3ba2e2 220 */
oreo329 3:5f90ed3ba2e2 221 void readTemp();
oreo329 3:5f90ed3ba2e2 222
oreo329 3:5f90ed3ba2e2 223 /** Read Interrupt **/
oreo329 3:5f90ed3ba2e2 224 void readIntr();
oreo329 3:5f90ed3ba2e2 225
oreo329 3:5f90ed3ba2e2 226 /** setGyroScale() -- Set the full-scale range of the gyroscope.
oreo329 3:5f90ed3ba2e2 227 * This function can be called to set the scale of the gyroscope to
oreo329 3:5f90ed3ba2e2 228 * 245, 500, or 2000 degrees per second.
oreo329 3:5f90ed3ba2e2 229 * Input:
oreo329 3:5f90ed3ba2e2 230 * - gScl = The desired gyroscope scale. Must be one of three possible
oreo329 3:5f90ed3ba2e2 231 * values from the gyro_scale enum.
oreo329 3:5f90ed3ba2e2 232 */
oreo329 3:5f90ed3ba2e2 233 void setGyroScale(gyro_scale gScl);
oreo329 3:5f90ed3ba2e2 234
oreo329 3:5f90ed3ba2e2 235 /** setAccelScale() -- Set the full-scale range of the accelerometer.
oreo329 3:5f90ed3ba2e2 236 * This function can be called to set the scale of the accelerometer to
oreo329 3:5f90ed3ba2e2 237 * 2, 4, 8, or 16 g's.
oreo329 3:5f90ed3ba2e2 238 * Input:
oreo329 3:5f90ed3ba2e2 239 * - aScl = The desired accelerometer scale. Must be one of five possible
oreo329 3:5f90ed3ba2e2 240 * values from the accel_scale enum.
oreo329 3:5f90ed3ba2e2 241 */
oreo329 3:5f90ed3ba2e2 242 void setAccelScale(accel_scale aScl);
oreo329 3:5f90ed3ba2e2 243
oreo329 3:5f90ed3ba2e2 244 /** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope
oreo329 3:5f90ed3ba2e2 245 * Input:
oreo329 3:5f90ed3ba2e2 246 * - gRate = The desired output rate and cutoff frequency of the gyro.
oreo329 3:5f90ed3ba2e2 247 * Must be a value from the gyro_odr enum (check above).
oreo329 3:5f90ed3ba2e2 248 */
oreo329 3:5f90ed3ba2e2 249 void setGyroODR(gyro_odr gRate);
oreo329 3:5f90ed3ba2e2 250
oreo329 3:5f90ed3ba2e2 251 /** setAccelODR() -- Set the output data rate of the accelerometer
oreo329 3:5f90ed3ba2e2 252 * Input:
oreo329 3:5f90ed3ba2e2 253 * - aRate = The desired output rate of the accel.
oreo329 3:5f90ed3ba2e2 254 * Must be a value from the accel_odr enum (check above).
oreo329 3:5f90ed3ba2e2 255 */
oreo329 3:5f90ed3ba2e2 256 void setAccelODR(accel_odr aRate);
oreo329 3:5f90ed3ba2e2 257 //void setAccelODR_NoBW(accel_odr aRate);
oreo329 3:5f90ed3ba2e2 258
oreo329 3:5f90ed3ba2e2 259
oreo329 3:5f90ed3ba2e2 260 private:
oreo329 3:5f90ed3ba2e2 261 /** xgAddress store the I2C address
oreo329 3:5f90ed3ba2e2 262 * for each sensor.
oreo329 3:5f90ed3ba2e2 263 */
oreo329 3:5f90ed3ba2e2 264 uint8_t xgAddress;
oreo329 3:5f90ed3ba2e2 265
oreo329 3:5f90ed3ba2e2 266 // I2C bus
oreo329 3:5f90ed3ba2e2 267 I2C i2c;
oreo329 3:5f90ed3ba2e2 268
oreo329 3:5f90ed3ba2e2 269 /** gScale, and aScale store the current scale range for each
oreo329 3:5f90ed3ba2e2 270 * sensor. Should be updated whenever that value changes.
oreo329 3:5f90ed3ba2e2 271 */
oreo329 3:5f90ed3ba2e2 272 gyro_scale gScale;
oreo329 3:5f90ed3ba2e2 273 accel_scale aScale;
oreo329 3:5f90ed3ba2e2 274
oreo329 3:5f90ed3ba2e2 275 /** gRes, and aRes store the current resolution for each sensor.
oreo329 3:5f90ed3ba2e2 276 * Units of these values would be DPS (or g's or Gs's) per ADC tick.
oreo329 3:5f90ed3ba2e2 277 * This value is calculated as (sensor scale) / (2^15).
oreo329 3:5f90ed3ba2e2 278 */
oreo329 3:5f90ed3ba2e2 279 float gRes, aRes;
oreo329 3:5f90ed3ba2e2 280
oreo329 3:5f90ed3ba2e2 281 /** initGyro() -- Sets up the gyroscope to begin reading.
oreo329 3:5f90ed3ba2e2 282 * This function steps through all three gyroscope control registers.
oreo329 3:5f90ed3ba2e2 283 */
oreo329 3:5f90ed3ba2e2 284 void initGyro();
oreo329 3:5f90ed3ba2e2 285
oreo329 3:5f90ed3ba2e2 286 /** initAccel() -- Sets up the accelerometer to begin reading.
oreo329 3:5f90ed3ba2e2 287 * This function steps through all accelerometer related control registers.
oreo329 3:5f90ed3ba2e2 288 */
oreo329 3:5f90ed3ba2e2 289 void initAccel();
oreo329 3:5f90ed3ba2e2 290
oreo329 3:5f90ed3ba2e2 291 /** Setup Interrupt **/
oreo329 3:5f90ed3ba2e2 292 void initIntr();
oreo329 3:5f90ed3ba2e2 293
oreo329 3:5f90ed3ba2e2 294 /** calcgRes() -- Calculate the resolution of the gyroscope.
oreo329 3:5f90ed3ba2e2 295 * This function will set the value of the gRes variable. gScale must
oreo329 3:5f90ed3ba2e2 296 * be set prior to calling this function.
oreo329 3:5f90ed3ba2e2 297 */
oreo329 3:5f90ed3ba2e2 298 void calcgRes();
oreo329 3:5f90ed3ba2e2 299
oreo329 3:5f90ed3ba2e2 300 /** calcaRes() -- Calculate the resolution of the accelerometer.
oreo329 3:5f90ed3ba2e2 301 * This function will set the value of the aRes variable. aScale must
oreo329 3:5f90ed3ba2e2 302 * be set prior to calling this function.
oreo329 3:5f90ed3ba2e2 303 */
oreo329 3:5f90ed3ba2e2 304 void calcaRes();
oreo329 3:5f90ed3ba2e2 305 };
oreo329 3:5f90ed3ba2e2 306
oreo329 3:5f90ed3ba2e2 307 #endif // _LSM6DS3_H //