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