only test purpose not official

Committer:
5hel2l2y
Date:
Wed Jun 22 22:11:37 2016 +0000
Revision:
4:7ffcb378cfd4
Parent:
3:f96b287c0bf7
Child:
6:28c4b3c8b43d
Modified interrupt initialization.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
beanmachine44 0:622e8874902e 1 // Most of the Credit goes to jimblom
beanmachine44 0:622e8874902e 2 // Modifications by Allen Wild
beanmachine44 0:622e8874902e 3 #ifndef _LSM9DS1_H__
beanmachine44 0:622e8874902e 4 #define _LSM9DS1_H__
beanmachine44 0:622e8874902e 5
beanmachine44 0:622e8874902e 6 #include "mbed.h"
beanmachine44 0:622e8874902e 7
beanmachine44 0:622e8874902e 8 /////////////////////////////////////////
beanmachine44 0:622e8874902e 9 // LSM9DS1 Accel/Gyro (XL/G) Registers //
beanmachine44 0:622e8874902e 10 /////////////////////////////////////////
beanmachine44 0:622e8874902e 11 #define ACT_THS 0x04
beanmachine44 0:622e8874902e 12 #define ACT_DUR 0x05
beanmachine44 0:622e8874902e 13 #define INT_GEN_CFG_XL 0x06
beanmachine44 0:622e8874902e 14 #define INT_GEN_THS_X_XL 0x07
beanmachine44 0:622e8874902e 15 #define INT_GEN_THS_Y_XL 0x08
beanmachine44 0:622e8874902e 16 #define INT_GEN_THS_Z_XL 0x09
beanmachine44 0:622e8874902e 17 #define INT_GEN_DUR_XL 0x0A
beanmachine44 0:622e8874902e 18 #define REFERENCE_G 0x0B
beanmachine44 0:622e8874902e 19 #define INT1_CTRL 0x0C
beanmachine44 0:622e8874902e 20 #define INT2_CTRL 0x0D
beanmachine44 0:622e8874902e 21 #define WHO_AM_I_XG 0x0F
beanmachine44 0:622e8874902e 22 #define CTRL_REG1_G 0x10
beanmachine44 0:622e8874902e 23 #define CTRL_REG2_G 0x11
beanmachine44 0:622e8874902e 24 #define CTRL_REG3_G 0x12
beanmachine44 0:622e8874902e 25 #define ORIENT_CFG_G 0x13
beanmachine44 0:622e8874902e 26 #define INT_GEN_SRC_G 0x14
beanmachine44 0:622e8874902e 27 #define OUT_TEMP_L 0x15
beanmachine44 0:622e8874902e 28 #define OUT_TEMP_H 0x16
beanmachine44 0:622e8874902e 29 #define STATUS_REG_0 0x17
beanmachine44 0:622e8874902e 30 #define OUT_X_L_G 0x18
beanmachine44 0:622e8874902e 31 #define OUT_X_H_G 0x19
beanmachine44 0:622e8874902e 32 #define OUT_Y_L_G 0x1A
beanmachine44 0:622e8874902e 33 #define OUT_Y_H_G 0x1B
beanmachine44 0:622e8874902e 34 #define OUT_Z_L_G 0x1C
beanmachine44 0:622e8874902e 35 #define OUT_Z_H_G 0x1D
beanmachine44 0:622e8874902e 36 #define CTRL_REG4 0x1E
beanmachine44 0:622e8874902e 37 #define CTRL_REG5_XL 0x1F
beanmachine44 0:622e8874902e 38 #define CTRL_REG6_XL 0x20
beanmachine44 0:622e8874902e 39 #define CTRL_REG7_XL 0x21
beanmachine44 0:622e8874902e 40 #define CTRL_REG8 0x22
beanmachine44 0:622e8874902e 41 #define CTRL_REG9 0x23
beanmachine44 0:622e8874902e 42 #define CTRL_REG10 0x24
beanmachine44 0:622e8874902e 43 #define INT_GEN_SRC_XL 0x26
beanmachine44 0:622e8874902e 44 #define STATUS_REG_1 0x27
beanmachine44 0:622e8874902e 45 #define OUT_X_L_XL 0x28
beanmachine44 0:622e8874902e 46 #define OUT_X_H_XL 0x29
beanmachine44 0:622e8874902e 47 #define OUT_Y_L_XL 0x2A
beanmachine44 0:622e8874902e 48 #define OUT_Y_H_XL 0x2B
beanmachine44 0:622e8874902e 49 #define OUT_Z_L_XL 0x2C
beanmachine44 0:622e8874902e 50 #define OUT_Z_H_XL 0x2D
beanmachine44 0:622e8874902e 51 #define FIFO_CTRL 0x2E
beanmachine44 0:622e8874902e 52 #define FIFO_SRC 0x2F
beanmachine44 0:622e8874902e 53 #define INT_GEN_CFG_G 0x30
beanmachine44 0:622e8874902e 54 #define INT_GEN_THS_XH_G 0x31
beanmachine44 0:622e8874902e 55 #define INT_GEN_THS_XL_G 0x32
beanmachine44 0:622e8874902e 56 #define INT_GEN_THS_YH_G 0x33
beanmachine44 0:622e8874902e 57 #define INT_GEN_THS_YL_G 0x34
beanmachine44 0:622e8874902e 58 #define INT_GEN_THS_ZH_G 0x35
beanmachine44 0:622e8874902e 59 #define INT_GEN_THS_ZL_G 0x36
beanmachine44 0:622e8874902e 60 #define INT_GEN_DUR_G 0x37
beanmachine44 0:622e8874902e 61
beanmachine44 0:622e8874902e 62 ///////////////////////////////
beanmachine44 0:622e8874902e 63 // LSM9DS1 Magneto Registers //
beanmachine44 0:622e8874902e 64 ///////////////////////////////
beanmachine44 0:622e8874902e 65 #define OFFSET_X_REG_L_M 0x05
beanmachine44 0:622e8874902e 66 #define OFFSET_X_REG_H_M 0x06
beanmachine44 0:622e8874902e 67 #define OFFSET_Y_REG_L_M 0x07
beanmachine44 0:622e8874902e 68 #define OFFSET_Y_REG_H_M 0x08
beanmachine44 0:622e8874902e 69 #define OFFSET_Z_REG_L_M 0x09
beanmachine44 0:622e8874902e 70 #define OFFSET_Z_REG_H_M 0x0A
beanmachine44 0:622e8874902e 71 #define WHO_AM_I_M 0x0F
beanmachine44 0:622e8874902e 72 #define CTRL_REG1_M 0x20
beanmachine44 0:622e8874902e 73 #define CTRL_REG2_M 0x21
beanmachine44 0:622e8874902e 74 #define CTRL_REG3_M 0x22
beanmachine44 0:622e8874902e 75 #define CTRL_REG4_M 0x23
beanmachine44 0:622e8874902e 76 #define CTRL_REG5_M 0x24
beanmachine44 0:622e8874902e 77 #define STATUS_REG_M 0x27
beanmachine44 0:622e8874902e 78 #define OUT_X_L_M 0x28
beanmachine44 0:622e8874902e 79 #define OUT_X_H_M 0x29
beanmachine44 0:622e8874902e 80 #define OUT_Y_L_M 0x2A
beanmachine44 0:622e8874902e 81 #define OUT_Y_H_M 0x2B
beanmachine44 0:622e8874902e 82 #define OUT_Z_L_M 0x2C
beanmachine44 0:622e8874902e 83 #define OUT_Z_H_M 0x2D
beanmachine44 0:622e8874902e 84 #define INT_CFG_M 0x30
beanmachine44 0:622e8874902e 85 #define INT_SRC_M 0x30
beanmachine44 0:622e8874902e 86 #define INT_THS_L_M 0x32
beanmachine44 0:622e8874902e 87 #define INT_THS_H_M 0x33
beanmachine44 0:622e8874902e 88
beanmachine44 0:622e8874902e 89 ////////////////////////////////
beanmachine44 0:622e8874902e 90 // LSM9DS1 WHO_AM_I Responses //
beanmachine44 0:622e8874902e 91 ////////////////////////////////
beanmachine44 0:622e8874902e 92 #define WHO_AM_I_AG_RSP 0x68
beanmachine44 0:622e8874902e 93 #define WHO_AM_I_M_RSP 0x3D
beanmachine44 0:622e8874902e 94
beanmachine44 0:622e8874902e 95 // Possible I2C addresses for the accel/gyro and mag
beanmachine44 0:622e8874902e 96 #define LSM9DS1_AG_I2C_ADDR(sa0) ((sa0) ? 0xD6 : 0xD4)
beanmachine44 0:622e8874902e 97 #define LSM9DS1_M_I2C_ADDR(sa1) ((sa1) ? 0x3C : 0x38)
beanmachine44 0:622e8874902e 98
beanmachine44 0:622e8874902e 99 /**
beanmachine44 0:622e8874902e 100 * LSM9DS1 Class - driver for the 9 DoF IMU
beanmachine44 0:622e8874902e 101 */
beanmachine44 0:622e8874902e 102 class LSM9DS1
beanmachine44 0:622e8874902e 103 {
beanmachine44 0:622e8874902e 104 public:
beanmachine44 0:622e8874902e 105
beanmachine44 0:622e8874902e 106 /// gyro_scale defines the possible full-scale ranges of the gyroscope:
beanmachine44 0:622e8874902e 107 enum gyro_scale
beanmachine44 0:622e8874902e 108 {
beanmachine44 0:622e8874902e 109 G_SCALE_245DPS = 0x0 << 3, // 00 << 3: +/- 245 degrees per second
beanmachine44 0:622e8874902e 110 G_SCALE_500DPS = 0x1 << 3, // 01 << 3: +/- 500 dps
beanmachine44 0:622e8874902e 111 G_SCALE_2000DPS = 0x3 << 3 // 11 << 3: +/- 2000 dps
beanmachine44 0:622e8874902e 112 };
beanmachine44 0:622e8874902e 113
beanmachine44 0:622e8874902e 114 /// gyro_odr defines all possible data rate/bandwidth combos of the gyro:
beanmachine44 0:622e8874902e 115 enum gyro_odr
beanmachine44 0:622e8874902e 116 { // ODR (Hz) --- Cutoff
beanmachine44 0:622e8874902e 117 G_POWER_DOWN = 0x00, // 0 0
beanmachine44 0:622e8874902e 118 G_ODR_15_BW_0 = 0x20, // 14.9 0
beanmachine44 0:622e8874902e 119 G_ODR_60_BW_16 = 0x40, // 59.5 16
beanmachine44 0:622e8874902e 120 G_ODR_119_BW_14 = 0x60, // 119 14
beanmachine44 0:622e8874902e 121 G_ODR_119_BW_31 = 0x61, // 119 31
beanmachine44 0:622e8874902e 122 G_ODR_238_BW_14 = 0x80, // 238 14
beanmachine44 0:622e8874902e 123 G_ODR_238_BW_29 = 0x81, // 238 29
beanmachine44 0:622e8874902e 124 G_ODR_238_BW_63 = 0x82, // 238 63
beanmachine44 0:622e8874902e 125 G_ODR_238_BW_78 = 0x83, // 238 78
beanmachine44 0:622e8874902e 126 G_ODR_476_BW_21 = 0xA0, // 476 21
beanmachine44 0:622e8874902e 127 G_ODR_476_BW_28 = 0xA1, // 476 28
beanmachine44 0:622e8874902e 128 G_ODR_476_BW_57 = 0xA2, // 476 57
beanmachine44 0:622e8874902e 129 G_ODR_476_BW_100 = 0xA3, // 476 100
beanmachine44 0:622e8874902e 130 G_ODR_952_BW_33 = 0xC0, // 952 33
beanmachine44 0:622e8874902e 131 G_ODR_952_BW_40 = 0xC1, // 952 40
beanmachine44 0:622e8874902e 132 G_ODR_952_BW_58 = 0xC2, // 952 58
beanmachine44 0:622e8874902e 133 G_ODR_952_BW_100 = 0xC3 // 952 100
beanmachine44 0:622e8874902e 134 };
beanmachine44 0:622e8874902e 135
beanmachine44 0:622e8874902e 136 /// accel_scale defines all possible FSR's of the accelerometer:
beanmachine44 0:622e8874902e 137 enum accel_scale
beanmachine44 0:622e8874902e 138 {
beanmachine44 0:622e8874902e 139 A_SCALE_2G, // 00: +/- 2g
beanmachine44 0:622e8874902e 140 A_SCALE_16G,// 01: +/- 16g
beanmachine44 0:622e8874902e 141 A_SCALE_4G, // 10: +/- 4g
beanmachine44 0:622e8874902e 142 A_SCALE_8G // 11: +/- 8g
beanmachine44 0:622e8874902e 143 };
beanmachine44 0:622e8874902e 144
beanmachine44 0:622e8874902e 145 /// accel_oder defines all possible output data rates of the accelerometer:
beanmachine44 0:622e8874902e 146 enum accel_odr
beanmachine44 0:622e8874902e 147 {
beanmachine44 0:622e8874902e 148 A_POWER_DOWN, // Power-down mode (0x0)
beanmachine44 0:622e8874902e 149 A_ODR_10, // 10 Hz (0x1)
beanmachine44 0:622e8874902e 150 A_ODR_50, // 50 Hz (0x2)
beanmachine44 0:622e8874902e 151 A_ODR_119, // 119 Hz (0x3)
beanmachine44 0:622e8874902e 152 A_ODR_238, // 238 Hz (0x4)
beanmachine44 0:622e8874902e 153 A_ODR_476, // 476 Hz (0x5)
beanmachine44 0:622e8874902e 154 A_ODR_952 // 952 Hz (0x6)
beanmachine44 0:622e8874902e 155 };
beanmachine44 0:622e8874902e 156
beanmachine44 0:622e8874902e 157 // accel_bw defines all possible bandwiths for low-pass filter of the accelerometer:
beanmachine44 0:622e8874902e 158 enum accel_bw
beanmachine44 0:622e8874902e 159 {
beanmachine44 0:622e8874902e 160 A_BW_AUTO_SCALE = 0x0, // Automatic BW scaling (0x0)
beanmachine44 0:622e8874902e 161 A_BW_408 = 0x4, // 408 Hz (0x4)
beanmachine44 0:622e8874902e 162 A_BW_211 = 0x5, // 211 Hz (0x5)
beanmachine44 0:622e8874902e 163 A_BW_105 = 0x6, // 105 Hz (0x6)
beanmachine44 0:622e8874902e 164 A_BW_50 = 0x7 // 50 Hz (0x7)
beanmachine44 0:622e8874902e 165 };
beanmachine44 0:622e8874902e 166
beanmachine44 0:622e8874902e 167 /// mag_scale defines all possible FSR's of the magnetometer:
beanmachine44 0:622e8874902e 168 enum mag_scale
beanmachine44 0:622e8874902e 169 {
beanmachine44 0:622e8874902e 170 M_SCALE_4GS, // 00: +/- 4Gs
beanmachine44 0:622e8874902e 171 M_SCALE_8GS, // 01: +/- 8Gs
beanmachine44 0:622e8874902e 172 M_SCALE_12GS, // 10: +/- 12Gs
beanmachine44 0:622e8874902e 173 M_SCALE_16GS, // 11: +/- 16Gs
beanmachine44 0:622e8874902e 174 };
beanmachine44 0:622e8874902e 175
beanmachine44 0:622e8874902e 176 /// mag_odr defines all possible output data rates of the magnetometer:
beanmachine44 0:622e8874902e 177 enum mag_odr
beanmachine44 0:622e8874902e 178 {
beanmachine44 0:622e8874902e 179 M_ODR_0625, // 0.625 Hz (0x00)
beanmachine44 0:622e8874902e 180 M_ODR_125, // 1.25 Hz (0x01)
beanmachine44 0:622e8874902e 181 M_ODR_25, // 2.5 Hz (0x02)
beanmachine44 0:622e8874902e 182 M_ODR_5, // 5 Hz (0x03)
beanmachine44 0:622e8874902e 183 M_ODR_10, // 10 (0x04)
beanmachine44 0:622e8874902e 184 M_ODR_20, // 20 Hz (0x05)
beanmachine44 0:622e8874902e 185 M_ODR_40, // 40 Hz (0x06)
beanmachine44 0:622e8874902e 186 M_ODR_80 // 80 Hz (0x07)
beanmachine44 0:622e8874902e 187 };
beanmachine44 0:622e8874902e 188
beanmachine44 0:622e8874902e 189 // We'll store the gyro, accel, and magnetometer readings in a series of
beanmachine44 0:622e8874902e 190 // public class variables. Each sensor gets three variables -- one for each
beanmachine44 0:622e8874902e 191 // axis. Call readGyro(), readAccel(), and readMag() first, before using
beanmachine44 0:622e8874902e 192 // these variables!
beanmachine44 0:622e8874902e 193 // These values are the RAW signed 16-bit readings from the sensors.
beanmachine44 0:622e8874902e 194 int16_t gx_raw, gy_raw, gz_raw; // x, y, and z axis readings of the gyroscope
beanmachine44 0:622e8874902e 195 int16_t ax_raw, ay_raw, az_raw; // x, y, and z axis readings of the accelerometer
beanmachine44 0:622e8874902e 196 int16_t mx_raw, my_raw, mz_raw; // x, y, and z axis readings of the magnetometer
beanmachine44 0:622e8874902e 197 int16_t temperature_raw;
beanmachine44 0:622e8874902e 198
beanmachine44 0:622e8874902e 199 // floating-point values of scaled data in real-world units
beanmachine44 0:622e8874902e 200 float gx, gy, gz;
beanmachine44 0:622e8874902e 201 float ax, ay, az;
beanmachine44 0:622e8874902e 202 float mx, my, mz;
beanmachine44 0:622e8874902e 203 float temperature_c, temperature_f; // temperature in celcius and fahrenheit
5hel2l2y 3:f96b287c0bf7 204 float intr;
beanmachine44 0:622e8874902e 205
beanmachine44 0:622e8874902e 206
beanmachine44 0:622e8874902e 207 /** LSM9DS1 -- LSM9DS1 class constructor
beanmachine44 0:622e8874902e 208 * The constructor will set up a handful of private variables, and set the
beanmachine44 0:622e8874902e 209 * communication mode as well.
beanmachine44 0:622e8874902e 210 * Input:
beanmachine44 0:622e8874902e 211 * - interface = Either MODE_SPI or MODE_I2C, whichever you're using
beanmachine44 0:622e8874902e 212 * to talk to the IC.
beanmachine44 0:622e8874902e 213 * - xgAddr = If MODE_I2C, this is the I2C address of the accel/gyro.
beanmachine44 0:622e8874902e 214 * If MODE_SPI, this is the chip select pin of the accel/gyro (CS_A/G)
beanmachine44 0:622e8874902e 215 * - mAddr = If MODE_I2C, this is the I2C address of the mag.
beanmachine44 0:622e8874902e 216 * If MODE_SPI, this is the cs pin of the mag (CS_M)
beanmachine44 0:622e8874902e 217 */
beanmachine44 0:622e8874902e 218 LSM9DS1(PinName sda, PinName scl, uint8_t xgAddr = LSM9DS1_AG_I2C_ADDR(1), uint8_t mAddr = LSM9DS1_M_I2C_ADDR(1));
beanmachine44 0:622e8874902e 219
beanmachine44 0:622e8874902e 220 /** begin() -- Initialize the gyro, accelerometer, and magnetometer.
beanmachine44 0:622e8874902e 221 * This will set up the scale and output rate of each sensor. It'll also
beanmachine44 0:622e8874902e 222 * "turn on" every sensor and every axis of every sensor.
beanmachine44 0:622e8874902e 223 * Input:
beanmachine44 0:622e8874902e 224 * - gScl = The scale of the gyroscope. This should be a gyro_scale value.
beanmachine44 0:622e8874902e 225 * - aScl = The scale of the accelerometer. Should be a accel_scale value.
beanmachine44 0:622e8874902e 226 * - mScl = The scale of the magnetometer. Should be a mag_scale value.
beanmachine44 0:622e8874902e 227 * - gODR = Output data rate of the gyroscope. gyro_odr value.
beanmachine44 0:622e8874902e 228 * - aODR = Output data rate of the accelerometer. accel_odr value.
beanmachine44 0:622e8874902e 229 * - mODR = Output data rate of the magnetometer. mag_odr value.
beanmachine44 0:622e8874902e 230 * Output: The function will return an unsigned 16-bit value. The most-sig
beanmachine44 0:622e8874902e 231 * bytes of the output are the WHO_AM_I reading of the accel/gyro. The
beanmachine44 0:622e8874902e 232 * least significant two bytes are the WHO_AM_I reading of the mag.
beanmachine44 0:622e8874902e 233 * All parameters have a defaulted value, so you can call just "begin()".
beanmachine44 0:622e8874902e 234 * Default values are FSR's of: +/- 245DPS, 4g, 2Gs; ODRs of 119 Hz for
beanmachine44 0:622e8874902e 235 * gyro, 119 Hz for accelerometer, 80 Hz for magnetometer.
beanmachine44 0:622e8874902e 236 * Use the return value of this function to verify communication.
beanmachine44 0:622e8874902e 237 */
beanmachine44 0:622e8874902e 238 uint16_t begin(gyro_scale gScl = G_SCALE_245DPS,
beanmachine44 0:622e8874902e 239 accel_scale aScl = A_SCALE_2G, mag_scale mScl = M_SCALE_4GS,
beanmachine44 0:622e8874902e 240 gyro_odr gODR = G_ODR_119_BW_14, accel_odr aODR = A_ODR_119,
beanmachine44 0:622e8874902e 241 mag_odr mODR = M_ODR_80);
beanmachine44 0:622e8874902e 242
beanmachine44 0:622e8874902e 243 /** readGyro() -- Read the gyroscope output registers.
beanmachine44 0:622e8874902e 244 * This function will read all six gyroscope output registers.
beanmachine44 0:622e8874902e 245 * The readings are stored in the class' gx_raw, gy_raw, and gz_raw variables. Read
beanmachine44 0:622e8874902e 246 * those _after_ calling readGyro().
beanmachine44 0:622e8874902e 247 */
beanmachine44 0:622e8874902e 248 void readGyro();
beanmachine44 0:622e8874902e 249
beanmachine44 0:622e8874902e 250 /** readAccel() -- Read the accelerometer output registers.
beanmachine44 0:622e8874902e 251 * This function will read all six accelerometer output registers.
beanmachine44 0:622e8874902e 252 * The readings are stored in the class' ax_raw, ay_raw, and az_raw variables. Read
beanmachine44 0:622e8874902e 253 * those _after_ calling readAccel().
beanmachine44 0:622e8874902e 254 */
beanmachine44 0:622e8874902e 255 void readAccel();
beanmachine44 0:622e8874902e 256
beanmachine44 0:622e8874902e 257 /** readMag() -- Read the magnetometer output registers.
beanmachine44 0:622e8874902e 258 * This function will read all six magnetometer output registers.
beanmachine44 0:622e8874902e 259 * The readings are stored in the class' mx_raw, my_raw, and mz_raw variables. Read
beanmachine44 0:622e8874902e 260 * those _after_ calling readMag().
beanmachine44 0:622e8874902e 261 */
beanmachine44 0:622e8874902e 262 void readMag();
5hel2l2y 4:7ffcb378cfd4 263
5hel2l2y 4:7ffcb378cfd4 264 /** Read Interrupt **/
5hel2l2y 3:f96b287c0bf7 265 void readIntr();
beanmachine44 0:622e8874902e 266
beanmachine44 0:622e8874902e 267 /** readTemp() -- Read the temperature output register.
beanmachine44 0:622e8874902e 268 * This function will read two temperature output registers.
beanmachine44 0:622e8874902e 269 * The combined readings are stored in the class' temperature variables. Read
beanmachine44 0:622e8874902e 270 * those _after_ calling readTemp().
beanmachine44 0:622e8874902e 271 */
beanmachine44 0:622e8874902e 272 void readTemp();
beanmachine44 0:622e8874902e 273
beanmachine44 0:622e8874902e 274 /** setGyroScale() -- Set the full-scale range of the gyroscope.
beanmachine44 0:622e8874902e 275 * This function can be called to set the scale of the gyroscope to
beanmachine44 1:0e76f237c23d 276 * 245, 500, or 2000 degrees per second.
beanmachine44 0:622e8874902e 277 * Input:
beanmachine44 0:622e8874902e 278 * - gScl = The desired gyroscope scale. Must be one of three possible
beanmachine44 0:622e8874902e 279 * values from the gyro_scale enum.
beanmachine44 0:622e8874902e 280 */
beanmachine44 0:622e8874902e 281 void setGyroScale(gyro_scale gScl);
beanmachine44 0:622e8874902e 282
beanmachine44 0:622e8874902e 283 /** setAccelScale() -- Set the full-scale range of the accelerometer.
beanmachine44 0:622e8874902e 284 * This function can be called to set the scale of the accelerometer to
beanmachine44 1:0e76f237c23d 285 * 2, 4, 8, or 16 g's.
beanmachine44 0:622e8874902e 286 * Input:
beanmachine44 0:622e8874902e 287 * - aScl = The desired accelerometer scale. Must be one of five possible
beanmachine44 0:622e8874902e 288 * values from the accel_scale enum.
beanmachine44 0:622e8874902e 289 */
beanmachine44 0:622e8874902e 290 void setAccelScale(accel_scale aScl);
beanmachine44 0:622e8874902e 291
beanmachine44 0:622e8874902e 292 /** setMagScale() -- Set the full-scale range of the magnetometer.
beanmachine44 0:622e8874902e 293 * This function can be called to set the scale of the magnetometer to
beanmachine44 1:0e76f237c23d 294 * 4, 8, 12, or 16 Gs.
beanmachine44 0:622e8874902e 295 * Input:
beanmachine44 0:622e8874902e 296 * - mScl = The desired magnetometer scale. Must be one of four possible
beanmachine44 0:622e8874902e 297 * values from the mag_scale enum.
beanmachine44 0:622e8874902e 298 */
beanmachine44 0:622e8874902e 299 void setMagScale(mag_scale mScl);
beanmachine44 0:622e8874902e 300
beanmachine44 0:622e8874902e 301 /** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope
beanmachine44 0:622e8874902e 302 * Input:
beanmachine44 0:622e8874902e 303 * - gRate = The desired output rate and cutoff frequency of the gyro.
beanmachine44 1:0e76f237c23d 304 * Must be a value from the gyro_odr enum (check above).
beanmachine44 0:622e8874902e 305 */
beanmachine44 0:622e8874902e 306 void setGyroODR(gyro_odr gRate);
beanmachine44 0:622e8874902e 307
beanmachine44 0:622e8874902e 308 /** setAccelODR() -- Set the output data rate of the accelerometer
beanmachine44 0:622e8874902e 309 * Input:
beanmachine44 0:622e8874902e 310 * - aRate = The desired output rate of the accel.
beanmachine44 1:0e76f237c23d 311 * Must be a value from the accel_odr enum (check above).
beanmachine44 0:622e8874902e 312 */
beanmachine44 0:622e8874902e 313 void setAccelODR(accel_odr aRate);
beanmachine44 0:622e8874902e 314
beanmachine44 0:622e8874902e 315 /** setMagODR() -- Set the output data rate of the magnetometer
beanmachine44 0:622e8874902e 316 * Input:
beanmachine44 0:622e8874902e 317 * - mRate = The desired output rate of the mag.
beanmachine44 1:0e76f237c23d 318 * Must be a value from the mag_odr enum (check above).
beanmachine44 0:622e8874902e 319 */
beanmachine44 0:622e8874902e 320 void setMagODR(mag_odr mRate);
beanmachine44 0:622e8874902e 321
beanmachine44 0:622e8874902e 322
beanmachine44 0:622e8874902e 323 private:
beanmachine44 0:622e8874902e 324 /** xgAddress and mAddress store the I2C address
beanmachine44 0:622e8874902e 325 * for each sensor.
beanmachine44 0:622e8874902e 326 */
beanmachine44 0:622e8874902e 327 uint8_t xgAddress, mAddress;
beanmachine44 0:622e8874902e 328
beanmachine44 0:622e8874902e 329 // I2C bus
beanmachine44 0:622e8874902e 330 I2C i2c;
beanmachine44 0:622e8874902e 331
beanmachine44 0:622e8874902e 332 /** gScale, aScale, and mScale store the current scale range for each
beanmachine44 0:622e8874902e 333 * sensor. Should be updated whenever that value changes.
beanmachine44 0:622e8874902e 334 */
beanmachine44 0:622e8874902e 335 gyro_scale gScale;
beanmachine44 0:622e8874902e 336 accel_scale aScale;
beanmachine44 0:622e8874902e 337 mag_scale mScale;
beanmachine44 0:622e8874902e 338
beanmachine44 0:622e8874902e 339 /** gRes, aRes, and mRes store the current resolution for each sensor.
beanmachine44 0:622e8874902e 340 * Units of these values would be DPS (or g's or Gs's) per ADC tick.
beanmachine44 0:622e8874902e 341 * This value is calculated as (sensor scale) / (2^15).
beanmachine44 0:622e8874902e 342 */
beanmachine44 0:622e8874902e 343 float gRes, aRes, mRes;
beanmachine44 0:622e8874902e 344
beanmachine44 0:622e8874902e 345 /** initGyro() -- Sets up the gyroscope to begin reading.
beanmachine44 1:0e76f237c23d 346 * This function steps through all three gyroscope control registers.
beanmachine44 0:622e8874902e 347 */
beanmachine44 0:622e8874902e 348 void initGyro();
beanmachine44 0:622e8874902e 349
beanmachine44 0:622e8874902e 350 /** initAccel() -- Sets up the accelerometer to begin reading.
beanmachine44 0:622e8874902e 351 * This function steps through all accelerometer related control registers.
beanmachine44 0:622e8874902e 352 */
beanmachine44 0:622e8874902e 353 void initAccel();
beanmachine44 0:622e8874902e 354
5hel2l2y 4:7ffcb378cfd4 355 /** Initialize Interrupts **/
5hel2l2y 3:f96b287c0bf7 356 void initIntr();
5hel2l2y 3:f96b287c0bf7 357
beanmachine44 0:622e8874902e 358 /** initMag() -- Sets up the magnetometer to begin reading.
beanmachine44 0:622e8874902e 359 * This function steps through all magnetometer-related control registers.
beanmachine44 0:622e8874902e 360 */
beanmachine44 0:622e8874902e 361 void initMag();
beanmachine44 0:622e8874902e 362
beanmachine44 0:622e8874902e 363 /** calcgRes() -- Calculate the resolution of the gyroscope.
beanmachine44 0:622e8874902e 364 * This function will set the value of the gRes variable. gScale must
beanmachine44 0:622e8874902e 365 * be set prior to calling this function.
beanmachine44 0:622e8874902e 366 */
beanmachine44 0:622e8874902e 367 void calcgRes();
beanmachine44 0:622e8874902e 368
beanmachine44 0:622e8874902e 369 /** calcmRes() -- Calculate the resolution of the magnetometer.
beanmachine44 0:622e8874902e 370 * This function will set the value of the mRes variable. mScale must
beanmachine44 0:622e8874902e 371 * be set prior to calling this function.
beanmachine44 0:622e8874902e 372 */
beanmachine44 0:622e8874902e 373 void calcmRes();
beanmachine44 0:622e8874902e 374
beanmachine44 0:622e8874902e 375 /** calcaRes() -- Calculate the resolution of the accelerometer.
beanmachine44 0:622e8874902e 376 * This function will set the value of the aRes variable. aScale must
beanmachine44 0:622e8874902e 377 * be set prior to calling this function.
beanmachine44 0:622e8874902e 378 */
beanmachine44 0:622e8874902e 379 void calcaRes();
beanmachine44 0:622e8874902e 380 };
beanmachine44 0:622e8874902e 381
beanmachine44 0:622e8874902e 382 #endif // _LSM9DS1_H //