AdvRobot_Team / Mbed 2 deprecated LSM9DS1_Library

Dependencies:   PinDetect mbed

Fork of LSM9DS1_Library by jim hamblen

Committer:
ChangYuHsuan
Date:
Tue Jun 13 03:51:56 2017 +0000
Revision:
3:9ed8bc1d0da3
Parent:
2:e8c2301f7523
F446RE test;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jmar7 0:e8167f37725c 1 /******************************************************************************
jmar7 0:e8167f37725c 2 SFE_LSM9DS1.h
jmar7 0:e8167f37725c 3 SFE_LSM9DS1 Library Header File
jmar7 0:e8167f37725c 4 Jim Lindblom @ SparkFun Electronics
jmar7 0:e8167f37725c 5 Original Creation Date: February 27, 2015
jmar7 0:e8167f37725c 6 https://github.com/sparkfun/LSM9DS1_Breakout
jmar7 0:e8167f37725c 7
jmar7 0:e8167f37725c 8 This file prototypes the LSM9DS1 class, implemented in SFE_LSM9DS1.cpp. In
jmar7 0:e8167f37725c 9 addition, it defines every register in the LSM9DS1 (both the Gyro and Accel/
jmar7 0:e8167f37725c 10 Magnetometer registers).
jmar7 0:e8167f37725c 11
jmar7 0:e8167f37725c 12 Development environment specifics:
jmar7 0:e8167f37725c 13 IDE: Arduino 1.6.0
jmar7 0:e8167f37725c 14 Hardware Platform: Arduino Uno
jmar7 0:e8167f37725c 15 LSM9DS1 Breakout Version: 1.0
jmar7 0:e8167f37725c 16
jmar7 0:e8167f37725c 17 This code is beerware; if you see me (or any other SparkFun employee) at the
jmar7 0:e8167f37725c 18 local, and you've found our code helpful, please buy us a round!
jmar7 0:e8167f37725c 19
jmar7 0:e8167f37725c 20 Distributed as-is; no warranty is given.
jmar7 0:e8167f37725c 21 ******************************************************************************/
jmar7 0:e8167f37725c 22 #ifndef __SparkFunLSM9DS1_H__
jmar7 0:e8167f37725c 23 #define __SparkFunLSM9DS1_H__
jmar7 0:e8167f37725c 24
jmar7 0:e8167f37725c 25 //#if defined(ARDUINO) && ARDUINO >= 100
jmar7 0:e8167f37725c 26 // #include "Arduino.h"
jmar7 0:e8167f37725c 27 //#else
jmar7 0:e8167f37725c 28 // #include "WProgram.h"
jmar7 0:e8167f37725c 29 // #include "pins_arduino.h"
jmar7 0:e8167f37725c 30 //#endif
jmar7 0:e8167f37725c 31
jmar7 0:e8167f37725c 32 #include "mbed.h"
jmar7 0:e8167f37725c 33 #include <stdint.h>
jmar7 0:e8167f37725c 34 #include "LSM9DS1_Registers.h"
jmar7 0:e8167f37725c 35 #include "LSM9DS1_Types.h"
ChangYuHsuan 3:9ed8bc1d0da3 36 #include <vector>
ChangYuHsuan 3:9ed8bc1d0da3 37 using std::vector;
ChangYuHsuan 3:9ed8bc1d0da3 38
ChangYuHsuan 3:9ed8bc1d0da3 39 #define PI 3.1415926
ChangYuHsuan 3:9ed8bc1d0da3 40 #define G 9.81
jmar7 0:e8167f37725c 41
jmar7 0:e8167f37725c 42 #define LSM9DS1_AG_ADDR(sa0) ((sa0) == 0 ? 0x6A : 0x6B)
jmar7 0:e8167f37725c 43 #define LSM9DS1_M_ADDR(sa1) ((sa1) == 0 ? 0x1C : 0x1E)
jmar7 0:e8167f37725c 44
jmar7 0:e8167f37725c 45 enum lsm9ds1_axis {
jmar7 0:e8167f37725c 46 X_AXIS,
jmar7 0:e8167f37725c 47 Y_AXIS,
jmar7 0:e8167f37725c 48 Z_AXIS,
jmar7 0:e8167f37725c 49 ALL_AXIS
jmar7 0:e8167f37725c 50 };
jmar7 0:e8167f37725c 51
jmar7 0:e8167f37725c 52 class LSM9DS1
jmar7 0:e8167f37725c 53 {
jmar7 0:e8167f37725c 54 public:
jmar7 0:e8167f37725c 55 IMUSettings settings;
jmar7 0:e8167f37725c 56
jmar7 0:e8167f37725c 57 // We'll store the gyro, accel, and magnetometer readings in a series of
jmar7 0:e8167f37725c 58 // public class variables. Each sensor gets three variables -- one for each
jmar7 0:e8167f37725c 59 // axis. Call readGyro(), readAccel(), and readMag() first, before using
jmar7 0:e8167f37725c 60 // these variables!
jmar7 0:e8167f37725c 61 // These values are the RAW signed 16-bit readings from the sensors.
jmar7 0:e8167f37725c 62 int16_t gx, gy, gz; // x, y, and z axis readings of the gyroscope
jmar7 0:e8167f37725c 63 int16_t ax, ay, az; // x, y, and z axis readings of the accelerometer
jmar7 0:e8167f37725c 64 int16_t mx, my, mz; // x, y, and z axis readings of the magnetometer
jmar7 0:e8167f37725c 65 int16_t temperature; // Chip temperature
jmar7 0:e8167f37725c 66 float gBias[3], aBias[3], mBias[3];
jmar7 0:e8167f37725c 67 int16_t gBiasRaw[3], aBiasRaw[3], mBiasRaw[3];
jmar7 0:e8167f37725c 68
ChangYuHsuan 3:9ed8bc1d0da3 69 // Unit transformation
ChangYuHsuan 3:9ed8bc1d0da3 70 float deg2rad; // = 3.1415926/180.0;
ChangYuHsuan 3:9ed8bc1d0da3 71 float rad2deg; // = 180.0/3.1415926;
ChangYuHsuan 3:9ed8bc1d0da3 72
jmar7 0:e8167f37725c 73 // LSM9DS1 -- LSM9DS1 class constructor
jmar7 0:e8167f37725c 74 // The constructor will set up a handful of private variables, and set the
jmar7 0:e8167f37725c 75 // communication mode as well.
jmar7 1:87d535bf8c53 76 /**Input:
jmar7 1:87d535bf8c53 77 * - interface = Either IMU_MODE_SPI or IMU_MODE_I2C, whichever you're using
jmar7 1:87d535bf8c53 78 * to talk to the IC.
jmar7 1:87d535bf8c53 79 * - xgAddr = If IMU_MODE_I2C, this is the I2C address of the accel/gyroscope.
jmar7 1:87d535bf8c53 80 * If IMU_MODE_SPI, this is the chip select pin of the gyro (CS_AG)
jmar7 1:87d535bf8c53 81 * - mAddr = If IMU_MODE_I2C, this is the I2C address of the magnetometer.
jmar7 1:87d535bf8c53 82 * If IMU_MODE_SPI, this is the cs pin of the magnetometer (CS_M)
jmar7 1:87d535bf8c53 83
jmar7 1:87d535bf8c53 84 */
jmar7 0:e8167f37725c 85 LSM9DS1(PinName sda, PinName scl, uint8_t xgAddr, uint8_t mAddr);
jmar7 1:87d535bf8c53 86 //LSM9DS1(interface_mode interface, uint8_t xgAddr, uint8_t mAddr);
jmar7 1:87d535bf8c53 87 //LSM9DS1();
jmar7 1:87d535bf8c53 88
jmar7 1:87d535bf8c53 89
jmar7 1:87d535bf8c53 90 /** begin() -- Initialize the gyro, accelerometer, and magnetometer.
jmar7 1:87d535bf8c53 91 *This will set up the scale and output rate of each sensor. The values set
jmar7 1:87d535bf8c53 92 * in the IMUSettings struct will take effect after calling this function.
jmar7 1:87d535bf8c53 93 */
jmar7 0:e8167f37725c 94 uint16_t begin();
jmar7 0:e8167f37725c 95
jmar7 0:e8167f37725c 96 void calibrate(bool autoCalc = true);
jmar7 0:e8167f37725c 97 void calibrateMag(bool loadIn = true);
jmar7 0:e8167f37725c 98 void magOffset(uint8_t axis, int16_t offset);
jmar7 0:e8167f37725c 99
jmar7 1:87d535bf8c53 100 /** accelAvailable() -- Polls the accelerometer status register to check
jmar7 1:87d535bf8c53 101 * if new data is available.
jmar7 1:87d535bf8c53 102 * Output: 1 - New data available
jmar7 1:87d535bf8c53 103 * 0 - No new data available
jmar7 1:87d535bf8c53 104 */
jmar7 0:e8167f37725c 105 uint8_t accelAvailable();
jmar7 0:e8167f37725c 106
jmar7 1:87d535bf8c53 107 /** gyroAvailable() -- Polls the gyroscope status register to check
jmar7 1:87d535bf8c53 108 * if new data is available.
jmar7 1:87d535bf8c53 109 * Output: 1 - New data available
jmar7 1:87d535bf8c53 110 * 0 - No new data available
jmar7 1:87d535bf8c53 111 */
jmar7 0:e8167f37725c 112 uint8_t gyroAvailable();
jmar7 0:e8167f37725c 113
jmar7 1:87d535bf8c53 114 /** gyroAvailable() -- Polls the temperature status register to check
jmar7 1:87d535bf8c53 115 * if new data is available.
jmar7 1:87d535bf8c53 116 * Output: 1 - New data available
jmar7 1:87d535bf8c53 117 * 0 - No new data available
jmar7 1:87d535bf8c53 118 */
jmar7 0:e8167f37725c 119 uint8_t tempAvailable();
jmar7 0:e8167f37725c 120
jmar7 1:87d535bf8c53 121 /** magAvailable() -- Polls the accelerometer status register to check
jmar7 1:87d535bf8c53 122 * if new data is available.
jmar7 1:87d535bf8c53 123 * Input:
jmar7 1:87d535bf8c53 124 * - axis can be either X_AXIS, Y_AXIS, Z_AXIS, to check for new data
jmar7 1:87d535bf8c53 125 * on one specific axis. Or ALL_AXIS (default) to check for new data
jmar7 1:87d535bf8c53 126 * on all axes.
jmar7 1:87d535bf8c53 127 * Output: 1 - New data available
jmar7 1:87d535bf8c53 128 * 0 - No new data available
jmar7 1:87d535bf8c53 129 */
jmar7 0:e8167f37725c 130 uint8_t magAvailable(lsm9ds1_axis axis = ALL_AXIS);
jmar7 0:e8167f37725c 131
jmar7 1:87d535bf8c53 132 /** readGyro() -- Read the gyroscope output registers.
jmar7 1:87d535bf8c53 133 * This function will read all six gyroscope output registers.
jmar7 1:87d535bf8c53 134 * The readings are stored in the class' gx, gy, and gz variables. Read
jmar7 1:87d535bf8c53 135 * those _after_ calling readGyro().
jmar7 1:87d535bf8c53 136 */
jmar7 0:e8167f37725c 137 void readGyro();
jmar7 0:e8167f37725c 138
jmar7 1:87d535bf8c53 139 /** int16_t readGyro(axis) -- Read a specific axis of the gyroscope.
jmar7 1:87d535bf8c53 140 * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS.
jmar7 1:87d535bf8c53 141 * Input:
jmar7 1:87d535bf8c53 142 * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS.
jmar7 1:87d535bf8c53 143 * Output:
jmar7 1:87d535bf8c53 144 * A 16-bit signed integer with sensor data on requested axis.
jmar7 1:87d535bf8c53 145 */
jmar7 0:e8167f37725c 146 int16_t readGyro(lsm9ds1_axis axis);
jmar7 0:e8167f37725c 147
ChangYuHsuan 3:9ed8bc1d0da3 148 /** readGyroFloatVectorRad() -- Read the gyroscope output registers.
ChangYuHsuan 3:9ed8bc1d0da3 149 * This function will read all six gyroscope output registers and
ChangYuHsuan 3:9ed8bc1d0da3 150 * transform the data into rad/s^2 unit.
ChangYuHsuan 3:9ed8bc1d0da3 151 * The readings are stored in the class' gx, gy, and gz variables. Read
ChangYuHsuan 3:9ed8bc1d0da3 152 * those _after_ calling readGyro().
ChangYuHsuan 3:9ed8bc1d0da3 153 */
ChangYuHsuan 3:9ed8bc1d0da3 154 void readGyroFloatVectorRad(vector<float> &v_out);
ChangYuHsuan 3:9ed8bc1d0da3 155
ChangYuHsuan 3:9ed8bc1d0da3 156 /** readGyroFloatVectorDeg() -- Read the gyroscope output registers.
ChangYuHsuan 3:9ed8bc1d0da3 157 * This function will read all six gyroscope output registers and
ChangYuHsuan 3:9ed8bc1d0da3 158 * transform the data into rad/s^2 unit.
ChangYuHsuan 3:9ed8bc1d0da3 159 * The readings are stored in the class' gx, gy, and gz variables. Read
ChangYuHsuan 3:9ed8bc1d0da3 160 * those _after_ calling readGyro().
ChangYuHsuan 3:9ed8bc1d0da3 161 */
ChangYuHsuan 3:9ed8bc1d0da3 162 void readGyroFloatVectorDeg(vector<float> &v_out);
ChangYuHsuan 3:9ed8bc1d0da3 163
ChangYuHsuan 3:9ed8bc1d0da3 164 /** float readGyroFloatRad(axis) -- Read a specific axis of the gyroscope in rad/s^2 unit.
ChangYuHsuan 3:9ed8bc1d0da3 165 * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS.
ChangYuHsuan 3:9ed8bc1d0da3 166 * Input:
ChangYuHsuan 3:9ed8bc1d0da3 167 * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS.
ChangYuHsuan 3:9ed8bc1d0da3 168 * Output:
ChangYuHsuan 3:9ed8bc1d0da3 169 * A float with sensor data on requested axis.
ChangYuHsuan 3:9ed8bc1d0da3 170 */
ChangYuHsuan 3:9ed8bc1d0da3 171 float readGyroFloatRad(lsm9ds1_axis axis);
ChangYuHsuan 3:9ed8bc1d0da3 172
ChangYuHsuan 3:9ed8bc1d0da3 173 /** float readGyroFloatDeg(axis) -- Read a specific axis of the gyroscope in rad/s^2 unit.
ChangYuHsuan 3:9ed8bc1d0da3 174 * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS.
ChangYuHsuan 3:9ed8bc1d0da3 175 * Input:
ChangYuHsuan 3:9ed8bc1d0da3 176 * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS.
ChangYuHsuan 3:9ed8bc1d0da3 177 * Output:
ChangYuHsuan 3:9ed8bc1d0da3 178 * A float with sensor data on requested axis.
ChangYuHsuan 3:9ed8bc1d0da3 179 */
ChangYuHsuan 3:9ed8bc1d0da3 180 float readGyroFloatDeg(lsm9ds1_axis axis);
ChangYuHsuan 3:9ed8bc1d0da3 181
jmar7 1:87d535bf8c53 182 /** readAccel() -- Read the accelerometer output registers.
jmar7 1:87d535bf8c53 183 * This function will read all six accelerometer output registers.
jmar7 1:87d535bf8c53 184 * The readings are stored in the class' ax, ay, and az variables. Read
jmar7 1:87d535bf8c53 185 * those _after_ calling readAccel().
jmar7 1:87d535bf8c53 186 */
jmar7 0:e8167f37725c 187 void readAccel();
jmar7 0:e8167f37725c 188
jmar7 1:87d535bf8c53 189 /** int16_t readAccel(axis) -- Read a specific axis of the accelerometer.
jmar7 1:87d535bf8c53 190 * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS.
jmar7 1:87d535bf8c53 191 * Input:
jmar7 1:87d535bf8c53 192 * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS.
jmar7 1:87d535bf8c53 193 * Output:
jmar7 1:87d535bf8c53 194 * A 16-bit signed integer with sensor data on requested axis.
jmar7 1:87d535bf8c53 195 */
jmar7 0:e8167f37725c 196 int16_t readAccel(lsm9ds1_axis axis);
jmar7 0:e8167f37725c 197
ChangYuHsuan 3:9ed8bc1d0da3 198 /** readAccel() -- Read the accelerometer output registers.
ChangYuHsuan 3:9ed8bc1d0da3 199 * This function will read all six accelerometer output registers and
ChangYuHsuan 3:9ed8bc1d0da3 200 * transform the data into m/s^2 unit.
ChangYuHsuan 3:9ed8bc1d0da3 201 * The readings are stored in the class' ax, ay, and az variables. Read
ChangYuHsuan 3:9ed8bc1d0da3 202 * those _after_ calling readAccel().
ChangYuHsuan 3:9ed8bc1d0da3 203 */
ChangYuHsuan 3:9ed8bc1d0da3 204 void readAccelFloatVector(vector<float> &v_out);
ChangYuHsuan 3:9ed8bc1d0da3 205
ChangYuHsuan 3:9ed8bc1d0da3 206 /** float readAccelFloat(axis) -- Read a specific axis of the accelerometer.
ChangYuHsuan 3:9ed8bc1d0da3 207 * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS.
ChangYuHsuan 3:9ed8bc1d0da3 208 * Input:
ChangYuHsuan 3:9ed8bc1d0da3 209 * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS.
ChangYuHsuan 3:9ed8bc1d0da3 210 * Output:
ChangYuHsuan 3:9ed8bc1d0da3 211 * A float with sensor data on requested axis.
ChangYuHsuan 3:9ed8bc1d0da3 212 */
ChangYuHsuan 3:9ed8bc1d0da3 213 float readAccelFloat(lsm9ds1_axis axis);
ChangYuHsuan 3:9ed8bc1d0da3 214
ChangYuHsuan 3:9ed8bc1d0da3 215
jmar7 1:87d535bf8c53 216 /** readMag() -- Read the magnetometer output registers.
jmar7 1:87d535bf8c53 217 * This function will read all six magnetometer output registers.
jmar7 1:87d535bf8c53 218 * The readings are stored in the class' mx, my, and mz variables. Read
jmar7 1:87d535bf8c53 219 * those _after_ calling readMag().
jmar7 1:87d535bf8c53 220 */
jmar7 0:e8167f37725c 221 void readMag();
ChangYuHsuan 3:9ed8bc1d0da3 222
jmar7 1:87d535bf8c53 223 /** int16_t readMag(axis) -- Read a specific axis of the magnetometer.
jmar7 1:87d535bf8c53 224 * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS.
jmar7 1:87d535bf8c53 225 * Input:
jmar7 1:87d535bf8c53 226 * - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS.
jmar7 1:87d535bf8c53 227 * Output:
jmar7 1:87d535bf8c53 228 * A 16-bit signed integer with sensor data on requested axis.
jmar7 1:87d535bf8c53 229 */
jmar7 0:e8167f37725c 230 int16_t readMag(lsm9ds1_axis axis);
jmar7 0:e8167f37725c 231
jmar7 1:87d535bf8c53 232 /** readTemp() -- Read the temperature output register.
jmar7 1:87d535bf8c53 233 * This function will read two temperature output registers.
jmar7 1:87d535bf8c53 234 * The combined readings are stored in the class' temperature variables. Read
jmar7 1:87d535bf8c53 235 * those _after_ calling readTemp().
jmar7 1:87d535bf8c53 236 */
jmar7 0:e8167f37725c 237 void readTemp();
jmar7 0:e8167f37725c 238
jmar7 1:87d535bf8c53 239 /** calcGyro() -- Convert from RAW signed 16-bit value to degrees per second
jmar7 1:87d535bf8c53 240 * This function reads in a signed 16-bit value and returns the scaled
jmar7 1:87d535bf8c53 241 * DPS. This function relies on gScale and gRes being correct.
jmar7 1:87d535bf8c53 242 * Input:
jmar7 1:87d535bf8c53 243 * - gyro = A signed 16-bit raw reading from the gyroscope.
jmar7 1:87d535bf8c53 244 */
jmar7 0:e8167f37725c 245 float calcGyro(int16_t gyro);
jmar7 0:e8167f37725c 246
jmar7 1:87d535bf8c53 247 /** calcAccel() -- Convert from RAW signed 16-bit value to gravity (g's).
jmar7 1:87d535bf8c53 248 * This function reads in a signed 16-bit value and returns the scaled
jmar7 1:87d535bf8c53 249 * g's. This function relies on aScale and aRes being correct.
jmar7 1:87d535bf8c53 250 * Input:
jmar7 1:87d535bf8c53 251 * - accel = A signed 16-bit raw reading from the accelerometer.
jmar7 1:87d535bf8c53 252 */
jmar7 0:e8167f37725c 253 float calcAccel(int16_t accel);
jmar7 0:e8167f37725c 254
jmar7 1:87d535bf8c53 255 /** calcMag() -- Convert from RAW signed 16-bit value to Gauss (Gs)
jmar7 1:87d535bf8c53 256 * This function reads in a signed 16-bit value and returns the scaled
jmar7 1:87d535bf8c53 257 * Gs. This function relies on mScale and mRes being correct.
jmar7 1:87d535bf8c53 258 * Input:
jmar7 1:87d535bf8c53 259 * - mag = A signed 16-bit raw reading from the magnetometer.
jmar7 1:87d535bf8c53 260 */
jmar7 0:e8167f37725c 261 float calcMag(int16_t mag);
jmar7 0:e8167f37725c 262
jmar7 1:87d535bf8c53 263 /** setGyroScale() -- Set the full-scale range of the gyroscope.
jmar7 1:87d535bf8c53 264 * This function can be called to set the scale of the gyroscope to
jmar7 1:87d535bf8c53 265 * 245, 500, or 200 degrees per second.
jmar7 1:87d535bf8c53 266 * Input:
jmar7 1:87d535bf8c53 267 * - gScl = The desired gyroscope scale. Must be one of three possible
jmar7 1:87d535bf8c53 268 * values from the gyro_scale.
jmar7 1:87d535bf8c53 269 */
jmar7 0:e8167f37725c 270 void setGyroScale(uint16_t gScl);
jmar7 0:e8167f37725c 271
jmar7 1:87d535bf8c53 272 /** setAccelScale() -- Set the full-scale range of the accelerometer.
jmar7 1:87d535bf8c53 273 * This function can be called to set the scale of the accelerometer to
jmar7 1:87d535bf8c53 274 * 2, 4, 6, 8, or 16 g's.
jmar7 1:87d535bf8c53 275 * Input:
jmar7 1:87d535bf8c53 276 * - aScl = The desired accelerometer scale. Must be one of five possible
jmar7 1:87d535bf8c53 277 * values from the accel_scale.
jmar7 1:87d535bf8c53 278 */
jmar7 0:e8167f37725c 279 void setAccelScale(uint8_t aScl);
jmar7 0:e8167f37725c 280
jmar7 1:87d535bf8c53 281 /** setMagScale() -- Set the full-scale range of the magnetometer.
jmar7 1:87d535bf8c53 282 * This function can be called to set the scale of the magnetometer to
jmar7 1:87d535bf8c53 283 * 2, 4, 8, or 12 Gs.
jmar7 1:87d535bf8c53 284 * Input:
jmar7 1:87d535bf8c53 285 * - mScl = The desired magnetometer scale. Must be one of four possible
jmar7 1:87d535bf8c53 286 * values from the mag_scale.
jmar7 1:87d535bf8c53 287 */
jmar7 0:e8167f37725c 288 void setMagScale(uint8_t mScl);
jmar7 0:e8167f37725c 289
jmar7 1:87d535bf8c53 290 /** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope
jmar7 1:87d535bf8c53 291 * Input:
jmar7 1:87d535bf8c53 292 * - gRate = The desired output rate and cutoff frequency of the gyro.
jmar7 1:87d535bf8c53 293 */
jmar7 0:e8167f37725c 294 void setGyroODR(uint8_t gRate);
jmar7 0:e8167f37725c 295
jmar7 0:e8167f37725c 296 // setAccelODR() -- Set the output data rate of the accelerometer
jmar7 0:e8167f37725c 297 // Input:
jmar7 0:e8167f37725c 298 // - aRate = The desired output rate of the accel.
jmar7 0:e8167f37725c 299 void setAccelODR(uint8_t aRate);
jmar7 0:e8167f37725c 300
jmar7 0:e8167f37725c 301 // setMagODR() -- Set the output data rate of the magnetometer
jmar7 0:e8167f37725c 302 // Input:
jmar7 0:e8167f37725c 303 // - mRate = The desired output rate of the mag.
jmar7 0:e8167f37725c 304 void setMagODR(uint8_t mRate);
jmar7 0:e8167f37725c 305
jmar7 0:e8167f37725c 306 // configInactivity() -- Configure inactivity interrupt parameters
jmar7 0:e8167f37725c 307 // Input:
jmar7 0:e8167f37725c 308 // - duration = Inactivity duration - actual value depends on gyro ODR
jmar7 0:e8167f37725c 309 // - threshold = Activity Threshold
jmar7 0:e8167f37725c 310 // - sleepOn = Gyroscope operating mode during inactivity.
jmar7 0:e8167f37725c 311 // true: gyroscope in sleep mode
jmar7 0:e8167f37725c 312 // false: gyroscope in power-down
jmar7 0:e8167f37725c 313 void configInactivity(uint8_t duration, uint8_t threshold, bool sleepOn);
jmar7 0:e8167f37725c 314
jmar7 0:e8167f37725c 315 // configAccelInt() -- Configure Accelerometer Interrupt Generator
jmar7 0:e8167f37725c 316 // Input:
jmar7 0:e8167f37725c 317 // - generator = Interrupt axis/high-low events
jmar7 0:e8167f37725c 318 // Any OR'd combination of ZHIE_XL, ZLIE_XL, YHIE_XL, YLIE_XL, XHIE_XL, XLIE_XL
jmar7 0:e8167f37725c 319 // - andInterrupts = AND/OR combination of interrupt events
jmar7 0:e8167f37725c 320 // true: AND combination
jmar7 0:e8167f37725c 321 // false: OR combination
jmar7 0:e8167f37725c 322 void configAccelInt(uint8_t generator, bool andInterrupts = false);
jmar7 0:e8167f37725c 323
jmar7 0:e8167f37725c 324 // configAccelThs() -- Configure the threshold of an accelereomter axis
jmar7 0:e8167f37725c 325 // Input:
jmar7 0:e8167f37725c 326 // - threshold = Interrupt threshold. Possible values: 0-255.
jmar7 0:e8167f37725c 327 // Multiply by 128 to get the actual raw accel value.
jmar7 0:e8167f37725c 328 // - axis = Axis to be configured. Either X_AXIS, Y_AXIS, or Z_AXIS
jmar7 0:e8167f37725c 329 // - duration = Duration value must be above or below threshold to trigger interrupt
jmar7 0:e8167f37725c 330 // - wait = Wait function on duration counter
jmar7 0:e8167f37725c 331 // true: Wait for duration samples before exiting interrupt
jmar7 0:e8167f37725c 332 // false: Wait function off
jmar7 0:e8167f37725c 333 void configAccelThs(uint8_t threshold, lsm9ds1_axis axis, uint8_t duration = 0, bool wait = 0);
jmar7 0:e8167f37725c 334
jmar7 0:e8167f37725c 335 // configGyroInt() -- Configure Gyroscope Interrupt Generator
jmar7 0:e8167f37725c 336 // Input:
jmar7 0:e8167f37725c 337 // - generator = Interrupt axis/high-low events
jmar7 0:e8167f37725c 338 // Any OR'd combination of ZHIE_G, ZLIE_G, YHIE_G, YLIE_G, XHIE_G, XLIE_G
jmar7 0:e8167f37725c 339 // - aoi = AND/OR combination of interrupt events
jmar7 0:e8167f37725c 340 // true: AND combination
jmar7 0:e8167f37725c 341 // false: OR combination
jmar7 0:e8167f37725c 342 // - latch: latch gyroscope interrupt request.
jmar7 0:e8167f37725c 343 void configGyroInt(uint8_t generator, bool aoi, bool latch);
jmar7 0:e8167f37725c 344
jmar7 0:e8167f37725c 345 // configGyroThs() -- Configure the threshold of a gyroscope axis
jmar7 0:e8167f37725c 346 // Input:
jmar7 0:e8167f37725c 347 // - threshold = Interrupt threshold. Possible values: 0-0x7FF.
jmar7 0:e8167f37725c 348 // Value is equivalent to raw gyroscope value.
jmar7 0:e8167f37725c 349 // - axis = Axis to be configured. Either X_AXIS, Y_AXIS, or Z_AXIS
jmar7 0:e8167f37725c 350 // - duration = Duration value must be above or below threshold to trigger interrupt
jmar7 0:e8167f37725c 351 // - wait = Wait function on duration counter
jmar7 0:e8167f37725c 352 // true: Wait for duration samples before exiting interrupt
jmar7 0:e8167f37725c 353 // false: Wait function off
jmar7 0:e8167f37725c 354 void configGyroThs(int16_t threshold, lsm9ds1_axis axis, uint8_t duration, bool wait);
jmar7 0:e8167f37725c 355
jmar7 0:e8167f37725c 356 // configInt() -- Configure INT1 or INT2 (Gyro and Accel Interrupts only)
jmar7 0:e8167f37725c 357 // Input:
jmar7 0:e8167f37725c 358 // - interrupt = Select INT1 or INT2
jmar7 0:e8167f37725c 359 // Possible values: XG_INT1 or XG_INT2
jmar7 0:e8167f37725c 360 // - generator = Or'd combination of interrupt generators.
jmar7 0:e8167f37725c 361 // Possible values: INT_DRDY_XL, INT_DRDY_G, INT1_BOOT (INT1 only), INT2_DRDY_TEMP (INT2 only)
jmar7 0:e8167f37725c 362 // INT_FTH, INT_OVR, INT_FSS5, INT_IG_XL (INT1 only), INT1_IG_G (INT1 only), INT2_INACT (INT2 only)
jmar7 0:e8167f37725c 363 // - activeLow = Interrupt active configuration
jmar7 0:e8167f37725c 364 // Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW
jmar7 0:e8167f37725c 365 // - pushPull = Push-pull or open drain interrupt configuration
jmar7 0:e8167f37725c 366 // Can be either INT_PUSH_PULL or INT_OPEN_DRAIN
jmar7 0:e8167f37725c 367 void configInt(interrupt_select interupt, uint8_t generator,
jmar7 0:e8167f37725c 368 h_lactive activeLow = INT_ACTIVE_LOW, pp_od pushPull = INT_PUSH_PULL);
jmar7 0:e8167f37725c 369
jmar7 1:87d535bf8c53 370 /** configMagInt() -- Configure Magnetometer Interrupt Generator
jmar7 1:87d535bf8c53 371 * Input:
jmar7 1:87d535bf8c53 372 * - generator = Interrupt axis/high-low events
jmar7 1:87d535bf8c53 373 * Any OR'd combination of ZIEN, YIEN, XIEN
jmar7 1:87d535bf8c53 374 * - activeLow = Interrupt active configuration
jmar7 1:87d535bf8c53 375 * Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW
4180_1 2:e8c2301f7523 376 * - latch: latch gyroscope interrupt request.
4180_1 2:e8c2301f7523 377 */
jmar7 0:e8167f37725c 378 void configMagInt(uint8_t generator, h_lactive activeLow, bool latch = true);
jmar7 0:e8167f37725c 379
jmar7 1:87d535bf8c53 380 /** configMagThs() -- Configure the threshold of a gyroscope axis
jmar7 1:87d535bf8c53 381 * Input:
jmar7 1:87d535bf8c53 382 * - threshold = Interrupt threshold. Possible values: 0-0x7FF.
jmar7 1:87d535bf8c53 383 * Value is equivalent to raw magnetometer value.
jmar7 1:87d535bf8c53 384 */
jmar7 0:e8167f37725c 385 void configMagThs(uint16_t threshold);
jmar7 0:e8167f37725c 386
jmar7 1:87d535bf8c53 387 //! getGyroIntSrc() -- Get contents of Gyroscope interrupt source register
jmar7 0:e8167f37725c 388 uint8_t getGyroIntSrc();
jmar7 0:e8167f37725c 389
jmar7 1:87d535bf8c53 390 //! getGyroIntSrc() -- Get contents of accelerometer interrupt source register
jmar7 0:e8167f37725c 391 uint8_t getAccelIntSrc();
jmar7 0:e8167f37725c 392
jmar7 1:87d535bf8c53 393 //! getGyroIntSrc() -- Get contents of magnetometer interrupt source register
jmar7 0:e8167f37725c 394 uint8_t getMagIntSrc();
jmar7 0:e8167f37725c 395
jmar7 1:87d535bf8c53 396 //! getGyroIntSrc() -- Get status of inactivity interrupt
jmar7 0:e8167f37725c 397 uint8_t getInactivity();
jmar7 0:e8167f37725c 398
jmar7 1:87d535bf8c53 399 /** sleepGyro() -- Sleep or wake the gyroscope
jmar7 1:87d535bf8c53 400 * Input:
jmar7 1:87d535bf8c53 401 * - enable: True = sleep gyro. False = wake gyro.
jmar7 1:87d535bf8c53 402 */
jmar7 0:e8167f37725c 403 void sleepGyro(bool enable = true);
jmar7 0:e8167f37725c 404
jmar7 1:87d535bf8c53 405 /** enableFIFO() - Enable or disable the FIFO
jmar7 1:87d535bf8c53 406 * Input:
jmar7 1:87d535bf8c53 407 * - enable: true = enable, false = disable.
jmar7 1:87d535bf8c53 408 */
jmar7 0:e8167f37725c 409 void enableFIFO(bool enable = true);
jmar7 0:e8167f37725c 410
jmar7 1:87d535bf8c53 411 /** setFIFO() - Configure FIFO mode and Threshold
jmar7 1:87d535bf8c53 412 * Input:
jmar7 1:87d535bf8c53 413 * - fifoMode: Set FIFO mode to off, FIFO (stop when full), continuous, bypass
jmar7 1:87d535bf8c53 414 * Possible inputs: FIFO_OFF, FIFO_THS, FIFO_CONT_TRIGGER, FIFO_OFF_TRIGGER, FIFO_CONT
jmar7 1:87d535bf8c53 415 * - fifoThs: FIFO threshold level setting
jmar7 1:87d535bf8c53 416 * Any value from 0-0x1F is acceptable.
jmar7 1:87d535bf8c53 417 */
jmar7 0:e8167f37725c 418 void setFIFO(fifoMode_type fifoMode, uint8_t fifoThs);
jmar7 0:e8167f37725c 419
jmar7 1:87d535bf8c53 420 //! getFIFOSamples() - Get number of FIFO samples
jmar7 0:e8167f37725c 421 uint8_t getFIFOSamples();
jmar7 0:e8167f37725c 422
jmar7 0:e8167f37725c 423
jmar7 0:e8167f37725c 424 protected:
jmar7 0:e8167f37725c 425 // x_mAddress and gAddress store the I2C address or SPI chip select pin
jmar7 0:e8167f37725c 426 // for each sensor.
jmar7 0:e8167f37725c 427 uint8_t _mAddress, _xgAddress;
jmar7 0:e8167f37725c 428
jmar7 0:e8167f37725c 429 // gRes, aRes, and mRes store the current resolution for each sensor.
jmar7 0:e8167f37725c 430 // Units of these values would be DPS (or g's or Gs's) per ADC tick.
jmar7 0:e8167f37725c 431 // This value is calculated as (sensor scale) / (2^15).
jmar7 0:e8167f37725c 432 float gRes, aRes, mRes;
jmar7 0:e8167f37725c 433
jmar7 0:e8167f37725c 434 // _autoCalc keeps track of whether we're automatically subtracting off
jmar7 0:e8167f37725c 435 // accelerometer and gyroscope bias calculated in calibrate().
jmar7 0:e8167f37725c 436 bool _autoCalc;
jmar7 0:e8167f37725c 437
jmar7 0:e8167f37725c 438 // init() -- Sets up gyro, accel, and mag settings to default.
jmar7 0:e8167f37725c 439 // - interface - Sets the interface mode (IMU_MODE_I2C or IMU_MODE_SPI)
jmar7 0:e8167f37725c 440 // - xgAddr - Sets either the I2C address of the accel/gyro or SPI chip
jmar7 0:e8167f37725c 441 // select pin connected to the CS_XG pin.
jmar7 0:e8167f37725c 442 // - mAddr - Sets either the I2C address of the magnetometer or SPI chip
jmar7 0:e8167f37725c 443 // select pin connected to the CS_M pin.
jmar7 0:e8167f37725c 444 void init(interface_mode interface, uint8_t xgAddr, uint8_t mAddr);
jmar7 0:e8167f37725c 445
jmar7 0:e8167f37725c 446 // initGyro() -- Sets up the gyroscope to begin reading.
jmar7 0:e8167f37725c 447 // This function steps through all five gyroscope control registers.
jmar7 0:e8167f37725c 448 // Upon exit, the following parameters will be set:
jmar7 0:e8167f37725c 449 // - CTRL_REG1_G = 0x0F: Normal operation mode, all axes enabled.
jmar7 0:e8167f37725c 450 // 95 Hz ODR, 12.5 Hz cutoff frequency.
jmar7 0:e8167f37725c 451 // - CTRL_REG2_G = 0x00: HPF set to normal mode, cutoff frequency
jmar7 0:e8167f37725c 452 // set to 7.2 Hz (depends on ODR).
jmar7 0:e8167f37725c 453 // - CTRL_REG3_G = 0x88: Interrupt enabled on INT_G (set to push-pull and
jmar7 0:e8167f37725c 454 // active high). Data-ready output enabled on DRDY_G.
jmar7 0:e8167f37725c 455 // - CTRL_REG4_G = 0x00: Continuous update mode. Data LSB stored in lower
jmar7 0:e8167f37725c 456 // address. Scale set to 245 DPS. SPI mode set to 4-wire.
jmar7 0:e8167f37725c 457 // - CTRL_REG5_G = 0x00: FIFO disabled. HPF disabled.
jmar7 0:e8167f37725c 458 void initGyro();
jmar7 0:e8167f37725c 459
jmar7 0:e8167f37725c 460 // initAccel() -- Sets up the accelerometer to begin reading.
jmar7 0:e8167f37725c 461 // This function steps through all accelerometer related control registers.
jmar7 0:e8167f37725c 462 // Upon exit these registers will be set as:
jmar7 0:e8167f37725c 463 // - CTRL_REG0_XM = 0x00: FIFO disabled. HPF bypassed. Normal mode.
jmar7 0:e8167f37725c 464 // - CTRL_REG1_XM = 0x57: 100 Hz data rate. Continuous update.
jmar7 0:e8167f37725c 465 // all axes enabled.
jmar7 0:e8167f37725c 466 // - CTRL_REG2_XM = 0x00: 2g scale. 773 Hz anti-alias filter BW.
jmar7 0:e8167f37725c 467 // - CTRL_REG3_XM = 0x04: Accel data ready signal on INT1_XM pin.
jmar7 0:e8167f37725c 468 void initAccel();
jmar7 0:e8167f37725c 469
jmar7 0:e8167f37725c 470 // initMag() -- Sets up the magnetometer to begin reading.
jmar7 0:e8167f37725c 471 // This function steps through all magnetometer-related control registers.
jmar7 0:e8167f37725c 472 // Upon exit these registers will be set as:
jmar7 0:e8167f37725c 473 // - CTRL_REG4_XM = 0x04: Mag data ready signal on INT2_XM pin.
jmar7 0:e8167f37725c 474 // - CTRL_REG5_XM = 0x14: 100 Hz update rate. Low resolution. Interrupt
jmar7 0:e8167f37725c 475 // requests don't latch. Temperature sensor disabled.
jmar7 0:e8167f37725c 476 // - CTRL_REG6_XM = 0x00: 2 Gs scale.
jmar7 0:e8167f37725c 477 // - CTRL_REG7_XM = 0x00: Continuous conversion mode. Normal HPF mode.
jmar7 0:e8167f37725c 478 // - INT_CTRL_REG_M = 0x09: Interrupt active-high. Enable interrupts.
jmar7 0:e8167f37725c 479 void initMag();
jmar7 0:e8167f37725c 480
jmar7 0:e8167f37725c 481 // gReadByte() -- Reads a byte from a specified gyroscope register.
jmar7 0:e8167f37725c 482 // Input:
jmar7 0:e8167f37725c 483 // - subAddress = Register to be read from.
jmar7 0:e8167f37725c 484 // Output:
jmar7 0:e8167f37725c 485 // - An 8-bit value read from the requested address.
jmar7 0:e8167f37725c 486 uint8_t mReadByte(uint8_t subAddress);
jmar7 0:e8167f37725c 487
jmar7 0:e8167f37725c 488 // gReadBytes() -- Reads a number of bytes -- beginning at an address
jmar7 0:e8167f37725c 489 // and incrementing from there -- from the gyroscope.
jmar7 0:e8167f37725c 490 // Input:
jmar7 0:e8167f37725c 491 // - subAddress = Register to be read from.
jmar7 0:e8167f37725c 492 // - * dest = A pointer to an array of uint8_t's. Values read will be
jmar7 0:e8167f37725c 493 // stored in here on return.
jmar7 0:e8167f37725c 494 // - count = The number of bytes to be read.
jmar7 0:e8167f37725c 495 // Output: No value is returned, but the `dest` array will store
jmar7 0:e8167f37725c 496 // the data read upon exit.
jmar7 0:e8167f37725c 497 void mReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count);
jmar7 0:e8167f37725c 498
jmar7 0:e8167f37725c 499 // gWriteByte() -- Write a byte to a register in the gyroscope.
jmar7 0:e8167f37725c 500 // Input:
jmar7 0:e8167f37725c 501 // - subAddress = Register to be written to.
jmar7 0:e8167f37725c 502 // - data = data to be written to the register.
jmar7 0:e8167f37725c 503 void mWriteByte(uint8_t subAddress, uint8_t data);
jmar7 0:e8167f37725c 504
jmar7 0:e8167f37725c 505 // xmReadByte() -- Read a byte from a register in the accel/mag sensor
jmar7 0:e8167f37725c 506 // Input:
jmar7 0:e8167f37725c 507 // - subAddress = Register to be read from.
jmar7 0:e8167f37725c 508 // Output:
jmar7 0:e8167f37725c 509 // - An 8-bit value read from the requested register.
jmar7 0:e8167f37725c 510 uint8_t xgReadByte(uint8_t subAddress);
jmar7 0:e8167f37725c 511
jmar7 0:e8167f37725c 512 // xmReadBytes() -- Reads a number of bytes -- beginning at an address
jmar7 0:e8167f37725c 513 // and incrementing from there -- from the accelerometer/magnetometer.
jmar7 0:e8167f37725c 514 // Input:
jmar7 0:e8167f37725c 515 // - subAddress = Register to be read from.
jmar7 0:e8167f37725c 516 // - * dest = A pointer to an array of uint8_t's. Values read will be
jmar7 0:e8167f37725c 517 // stored in here on return.
jmar7 0:e8167f37725c 518 // - count = The number of bytes to be read.
jmar7 0:e8167f37725c 519 // Output: No value is returned, but the `dest` array will store
jmar7 0:e8167f37725c 520 // the data read upon exit.
jmar7 0:e8167f37725c 521 void xgReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count);
jmar7 0:e8167f37725c 522
jmar7 0:e8167f37725c 523 // xmWriteByte() -- Write a byte to a register in the accel/mag sensor.
jmar7 0:e8167f37725c 524 // Input:
jmar7 0:e8167f37725c 525 // - subAddress = Register to be written to.
jmar7 0:e8167f37725c 526 // - data = data to be written to the register.
jmar7 0:e8167f37725c 527 void xgWriteByte(uint8_t subAddress, uint8_t data);
jmar7 0:e8167f37725c 528
jmar7 0:e8167f37725c 529 // calcgRes() -- Calculate the resolution of the gyroscope.
jmar7 0:e8167f37725c 530 // This function will set the value of the gRes variable. gScale must
jmar7 0:e8167f37725c 531 // be set prior to calling this function.
jmar7 0:e8167f37725c 532 void calcgRes();
jmar7 0:e8167f37725c 533
jmar7 0:e8167f37725c 534 // calcmRes() -- Calculate the resolution of the magnetometer.
jmar7 0:e8167f37725c 535 // This function will set the value of the mRes variable. mScale must
jmar7 0:e8167f37725c 536 // be set prior to calling this function.
jmar7 0:e8167f37725c 537 void calcmRes();
jmar7 0:e8167f37725c 538
jmar7 0:e8167f37725c 539 // calcaRes() -- Calculate the resolution of the accelerometer.
jmar7 0:e8167f37725c 540 // This function will set the value of the aRes variable. aScale must
jmar7 0:e8167f37725c 541 // be set prior to calling this function.
jmar7 0:e8167f37725c 542 void calcaRes();
jmar7 0:e8167f37725c 543
jmar7 0:e8167f37725c 544 //////////////////////
jmar7 0:e8167f37725c 545 // Helper Functions //
jmar7 0:e8167f37725c 546 //////////////////////
jmar7 0:e8167f37725c 547 void constrainScales();
jmar7 0:e8167f37725c 548
jmar7 0:e8167f37725c 549 ///////////////////
jmar7 0:e8167f37725c 550 // SPI Functions //
jmar7 0:e8167f37725c 551 ///////////////////
jmar7 0:e8167f37725c 552 // initSPI() -- Initialize the SPI hardware.
jmar7 0:e8167f37725c 553 // This function will setup all SPI pins and related hardware.
jmar7 0:e8167f37725c 554 void initSPI();
jmar7 0:e8167f37725c 555
jmar7 0:e8167f37725c 556 // SPIwriteByte() -- Write a byte out of SPI to a register in the device
jmar7 0:e8167f37725c 557 // Input:
jmar7 0:e8167f37725c 558 // - csPin = The chip select pin of the slave device.
jmar7 0:e8167f37725c 559 // - subAddress = The register to be written to.
jmar7 0:e8167f37725c 560 // - data = Byte to be written to the register.
jmar7 0:e8167f37725c 561 void SPIwriteByte(uint8_t csPin, uint8_t subAddress, uint8_t data);
jmar7 0:e8167f37725c 562
jmar7 0:e8167f37725c 563 // SPIreadByte() -- Read a single byte from a register over SPI.
jmar7 0:e8167f37725c 564 // Input:
jmar7 0:e8167f37725c 565 // - csPin = The chip select pin of the slave device.
jmar7 0:e8167f37725c 566 // - subAddress = The register to be read from.
jmar7 0:e8167f37725c 567 // Output:
jmar7 0:e8167f37725c 568 // - The byte read from the requested address.
jmar7 0:e8167f37725c 569 uint8_t SPIreadByte(uint8_t csPin, uint8_t subAddress);
jmar7 0:e8167f37725c 570
jmar7 0:e8167f37725c 571 // SPIreadBytes() -- Read a series of bytes, starting at a register via SPI
jmar7 0:e8167f37725c 572 // Input:
jmar7 0:e8167f37725c 573 // - csPin = The chip select pin of a slave device.
jmar7 0:e8167f37725c 574 // - subAddress = The register to begin reading.
jmar7 0:e8167f37725c 575 // - * dest = Pointer to an array where we'll store the readings.
jmar7 0:e8167f37725c 576 // - count = Number of registers to be read.
jmar7 0:e8167f37725c 577 // Output: No value is returned by the function, but the registers read are
jmar7 0:e8167f37725c 578 // all stored in the *dest array given.
jmar7 0:e8167f37725c 579 void SPIreadBytes(uint8_t csPin, uint8_t subAddress,
jmar7 0:e8167f37725c 580 uint8_t * dest, uint8_t count);
jmar7 0:e8167f37725c 581
jmar7 0:e8167f37725c 582 ///////////////////
jmar7 0:e8167f37725c 583 // I2C Functions //
jmar7 0:e8167f37725c 584 ///////////////////
jmar7 0:e8167f37725c 585 // initI2C() -- Initialize the I2C hardware.
jmar7 0:e8167f37725c 586 // This function will setup all I2C pins and related hardware.
jmar7 0:e8167f37725c 587 void initI2C();
jmar7 0:e8167f37725c 588
jmar7 0:e8167f37725c 589 // I2CwriteByte() -- Write a byte out of I2C to a register in the device
jmar7 0:e8167f37725c 590 // Input:
jmar7 0:e8167f37725c 591 // - address = The 7-bit I2C address of the slave device.
jmar7 0:e8167f37725c 592 // - subAddress = The register to be written to.
jmar7 0:e8167f37725c 593 // - data = Byte to be written to the register.
jmar7 0:e8167f37725c 594 void I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data);
jmar7 0:e8167f37725c 595
jmar7 0:e8167f37725c 596 // I2CreadByte() -- Read a single byte from a register over I2C.
jmar7 0:e8167f37725c 597 // Input:
jmar7 0:e8167f37725c 598 // - address = The 7-bit I2C address of the slave device.
jmar7 0:e8167f37725c 599 // - subAddress = The register to be read from.
jmar7 0:e8167f37725c 600 // Output:
jmar7 0:e8167f37725c 601 // - The byte read from the requested address.
jmar7 0:e8167f37725c 602 uint8_t I2CreadByte(uint8_t address, uint8_t subAddress);
jmar7 0:e8167f37725c 603
jmar7 0:e8167f37725c 604 // I2CreadBytes() -- Read a series of bytes, starting at a register via SPI
jmar7 0:e8167f37725c 605 // Input:
jmar7 0:e8167f37725c 606 // - address = The 7-bit I2C address of the slave device.
jmar7 0:e8167f37725c 607 // - subAddress = The register to begin reading.
jmar7 0:e8167f37725c 608 // - * dest = Pointer to an array where we'll store the readings.
jmar7 0:e8167f37725c 609 // - count = Number of registers to be read.
jmar7 0:e8167f37725c 610 // Output: No value is returned by the function, but the registers read are
jmar7 0:e8167f37725c 611 // all stored in the *dest array given.
jmar7 0:e8167f37725c 612 uint8_t I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count);
jmar7 0:e8167f37725c 613
jmar7 0:e8167f37725c 614 private:
jmar7 0:e8167f37725c 615 I2C i2c;
jmar7 0:e8167f37725c 616 };
jmar7 0:e8167f37725c 617
jmar7 0:e8167f37725c 618 #endif // SFE_LSM9DS1_H //