lib imu

Dependents:   LoRaWan_GPS

Committer:
RoddyRod
Date:
Fri Dec 27 16:01:32 2019 +0000
Revision:
0:4b0b0a4b20e3
imu

Who changed what in which revision?

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