Mangue Baja team's code to frontal ECU

Committer:
einsteingustavo
Date:
Wed Jul 24 20:03:52 2019 +0000
Revision:
0:12fb9cbcabcc
Mangue Baja team's code to frontal ECU

Who changed what in which revision?

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