Michael Ernst Peter / LSM9DS1

Dependents:   PM2_Libary PM2_Libary

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LSM9DS1_i2c.h Source File

LSM9DS1_i2c.h

00001 /******************************************************************************
00002 SFE_LSM9DS1.h
00003 SFE_LSM9DS1 Library Header File
00004 Jim Lindblom @ SparkFun Electronics
00005 Original Creation Date: February 27, 2015
00006 https://github.com/sparkfun/LSM9DS1_Breakout
00007 
00008 This file prototypes the LSM9DS1 class, implemented in SFE_LSM9DS1.cpp. In
00009 addition, it defines every register in the LSM9DS1 (both the Gyro and Accel/
00010 Magnetometer registers).
00011 
00012 Development environment specifics:
00013     IDE: Arduino 1.6.0
00014     Hardware Platform: Arduino Uno
00015     LSM9DS1 Breakout Version: 1.0
00016 
00017 This code is beerware; if you see me (or any other SparkFun employee) at the
00018 local, and you've found our code helpful, please buy us a round!
00019 
00020 Distributed as-is; no warranty is given.
00021 ******************************************************************************/
00022 #ifndef __SparkFunLSM9DS1_H__
00023 #define __SparkFunLSM9DS1_H__
00024 
00025 //#if defined(ARDUINO) && ARDUINO >= 100
00026 //  #include "Arduino.h"
00027 //#else
00028 //  #include "WProgram.h"
00029 //  #include "pins_arduino.h"
00030 //#endif
00031 
00032 #include "mbed.h"
00033 #include <stdint.h>
00034 #include "LSM9DS1_Registers.h"
00035 #include "LSM9DS1_Types.h"
00036 
00037 #define LSM9DS1_AG_ADDR(sa0)    ((sa0) == 0 ? 0x6A : 0x6B)
00038 #define LSM9DS1_M_ADDR(sa1)     ((sa1) == 0 ? 0x1C : 0x1E)
00039 
00040 enum lsm9ds1_axis {
00041     X_AXIS,
00042     Y_AXIS,
00043     Z_AXIS,
00044     ALL_AXIS
00045 };
00046 
00047 class LSM9DS1
00048 {
00049 public:
00050     IMUSettings settings;
00051     
00052     // We'll store the gyro, accel, and magnetometer readings in a series of
00053     // public class variables. Each sensor gets three variables -- one for each
00054     // axis. Call updateGyro(), updateAcc(), and updateMag() first, before using
00055     // these variables!
00056     // These values are the RAW signed 16-bit readings from the sensors.
00057     int16_t gx, gy, gz; // x, y, and z axis readings of the gyroscope
00058     int16_t ax, ay, az; // x, y, and z axis readings of the accelerometer
00059     int16_t mx, my, mz; // x, y, and z axis readings of the magnetometer
00060     int16_t temperature; // Chip temperature
00061     float gBias[3], aBias[3], mBias[3];
00062     int16_t gBiasRaw[3], aBiasRaw[3], mBiasRaw[3];
00063     
00064     /*
00065     float gyroX, gyroY, gyroZ; // x, y, and z axis readings of the gyroscope (float value)
00066     float accX, accY, accZ; // x, y, and z axis readings of the accelerometer (float value)
00067     float magX, magY, magZ; // x, y, and z axis readings of the magnetometer (float value)
00068     */
00069     
00070     // LSM9DS1 -- LSM9DS1 class constructor
00071     // The constructor will set up a handful of private variables, and set the
00072     // communication mode as well.
00073     /**Input:
00074     *  - interface = Either IMU_MODE_SPI or IMU_MODE_I2C, whichever you're using
00075     *              to talk to the IC.
00076     *  - xgAddr = If IMU_MODE_I2C, this is the I2C address of the accel/gyroscope.
00077     *              If IMU_MODE_SPI, this is the chip select pin of the gyro (CS_AG)
00078     *  - mAddr = If IMU_MODE_I2C, this is the I2C address of the magnetometer.
00079     *              If IMU_MODE_SPI, this is the cs pin of the magnetometer (CS_M)
00080     
00081     */
00082     LSM9DS1(PinName sda, PinName scl, uint8_t xgAddr, uint8_t mAddr);
00083     LSM9DS1(PinName sda, PinName scl);
00084     //LSM9DS1(interface_mode interface, uint8_t xgAddr, uint8_t mAddr);
00085     //LSM9DS1();
00086        
00087     
00088     /** begin() -- Initialize the gyro, accelerometer, and magnetometer.
00089     *This will set up the scale and output rate of each sensor. The values set
00090     * in the IMUSettings struct will take effect after calling this function.
00091     */
00092     uint16_t begin();
00093     
00094     float readGyroX();
00095     float readGyroY();
00096     float readGyroZ();
00097     float readAccX();
00098     float readAccY();
00099     float readAccZ();
00100     float readMagX();
00101     float readMagY();
00102     float readMagZ();
00103     
00104     void calibrate(bool autoCalc = true);
00105     void calibrateMag(bool loadIn = true);
00106     void magOffset(uint8_t axis, int16_t offset);
00107     
00108     /** accelAvailable() -- Polls the accelerometer status register to check
00109     * if new data is available.
00110     * Output:  1 - New data available
00111     *          0 - No new data available
00112     */
00113     uint8_t accelAvailable();
00114     
00115     /** gyroAvailable() -- Polls the gyroscope status register to check
00116     * if new data is available.
00117     * Output:  1 - New data available
00118     *          0 - No new data available
00119     */
00120     uint8_t gyroAvailable();
00121     
00122     /** gyroAvailable() -- Polls the temperature status register to check
00123     * if new data is available.
00124     * Output:  1 - New data available
00125     *          0 - No new data available
00126     */
00127     uint8_t tempAvailable();
00128     
00129     /** magAvailable() -- Polls the accelerometer status register to check
00130     * if new data is available.
00131     * Input:
00132     *  - axis can be either X_AXIS, Y_AXIS, Z_AXIS, to check for new data
00133     *    on one specific axis. Or ALL_AXIS (default) to check for new data
00134     *    on all axes.
00135     * Output:  1 - New data available
00136     *          0 - No new data available
00137     */
00138     uint8_t magAvailable(lsm9ds1_axis axis = ALL_AXIS);
00139     
00140     /** updateGyro() -- Read the gyroscope output registers.
00141     * This function will read all six gyroscope output registers.
00142     * The readings are stored in the class' gx, gy, and gz variables. Read
00143     * those _after_ calling updateGyro().
00144     */
00145     void updateGyro();
00146     
00147     /** int16_t updateGyro(axis) -- Read a specific axis of the gyroscope.
00148     * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS.
00149     * Input:
00150     *  - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS.
00151     * Output:
00152     *  A 16-bit signed integer with sensor data on requested axis.
00153     */
00154     int16_t updateGyro(lsm9ds1_axis axis);
00155     
00156     /** updateAcc() -- Read the accelerometer output registers.
00157     * This function will read all six accelerometer output registers.
00158     * The readings are stored in the class' ax, ay, and az variables. Read
00159     * those _after_ calling updateAcc().
00160     */
00161     void updateAcc();
00162     
00163     /** int16_t updateAcc(axis) -- Read a specific axis of the accelerometer.
00164     * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS.
00165     * Input:
00166     *  - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS.
00167     * Output:
00168     *  A 16-bit signed integer with sensor data on requested axis.
00169     */
00170     int16_t updateAcc(lsm9ds1_axis axis);
00171     
00172     /** updateMag() -- Read the magnetometer output registers.
00173     * This function will read all six magnetometer output registers.
00174     * The readings are stored in the class' mx, my, and mz variables. Read
00175     * those _after_ calling updateMag().
00176     */
00177     void updateMag();
00178     
00179     /** int16_t updateMag(axis) -- Read a specific axis of the magnetometer.
00180     * [axis] can be any of X_AXIS, Y_AXIS, or Z_AXIS.
00181     * Input:
00182     *  - axis: can be either X_AXIS, Y_AXIS, or Z_AXIS.
00183     * Output:
00184     *  A 16-bit signed integer with sensor data on requested axis.
00185     */
00186     int16_t updateMag(lsm9ds1_axis axis);
00187 
00188     /** readTemp() -- Read the temperature output register.
00189     * This function will read two temperature output registers.
00190     * The combined readings are stored in the class' temperature variables. Read
00191     * those _after_ calling readTemp().
00192     */
00193     void readTemp();
00194     
00195     /** calcGyro() -- Convert from RAW signed 16-bit value to degrees per second
00196     * This function reads in a signed 16-bit value and returns the scaled
00197     * DPS. This function relies on gScale and gRes being correct.
00198     * Input:
00199     *  - gyro = A signed 16-bit raw reading from the gyroscope.
00200     */
00201     float calcGyro(int16_t gyro);
00202     
00203     /** calcAccel() -- Convert from RAW signed 16-bit value to gravity (g's).
00204     * This function reads in a signed 16-bit value and returns the scaled
00205     * g's. This function relies on aScale and aRes being correct.
00206     * Input:
00207     *  - accel = A signed 16-bit raw reading from the accelerometer.
00208     */
00209     float calcAccel(int16_t accel);
00210     
00211     /** calcMag() -- Convert from RAW signed 16-bit value to Gauss (Gs)
00212     * This function reads in a signed 16-bit value and returns the scaled
00213     * Gs. This function relies on mScale and mRes being correct.
00214     * Input:
00215     *  - mag = A signed 16-bit raw reading from the magnetometer.
00216     */
00217     float calcMag(int16_t mag);
00218     
00219     /** setGyroScale() -- Set the full-scale range of the gyroscope.
00220     * This function can be called to set the scale of the gyroscope to 
00221     * 245, 500, or 200 degrees per second.
00222     * Input:
00223     *  - gScl = The desired gyroscope scale. Must be one of three possible
00224     *      values from the gyro_scale.
00225     */
00226     void setGyroScale(uint16_t gScl);
00227     
00228     /** setAccelScale() -- Set the full-scale range of the accelerometer.
00229     * This function can be called to set the scale of the accelerometer to
00230     * 2, 4, 6, 8, or 16 g's.
00231     * Input:
00232     *  - aScl = The desired accelerometer scale. Must be one of five possible
00233     *      values from the accel_scale.
00234     */
00235     void setAccelScale(uint8_t aScl);
00236     
00237     /** setMagScale() -- Set the full-scale range of the magnetometer.
00238     * This function can be called to set the scale of the magnetometer to
00239     * 2, 4, 8, or 12 Gs.
00240     * Input:
00241     *  - mScl = The desired magnetometer scale. Must be one of four possible
00242     *      values from the mag_scale.
00243     */
00244     void setMagScale(uint8_t mScl);
00245     
00246     /** setGyroODR() -- Set the output data rate and bandwidth of the gyroscope
00247     * Input:
00248     *  - gRate = The desired output rate and cutoff frequency of the gyro.
00249     */
00250     void setGyroODR(uint8_t gRate);
00251     
00252     // setAccelODR() -- Set the output data rate of the accelerometer
00253     // Input:
00254     //  - aRate = The desired output rate of the accel.
00255     void setAccelODR(uint8_t aRate);    
00256     
00257     // setMagODR() -- Set the output data rate of the magnetometer
00258     // Input:
00259     //  - mRate = The desired output rate of the mag.
00260     void setMagODR(uint8_t mRate);
00261     
00262     // configInactivity() -- Configure inactivity interrupt parameters
00263     // Input:
00264     //  - duration = Inactivity duration - actual value depends on gyro ODR
00265     //  - threshold = Activity Threshold
00266     //  - sleepOn = Gyroscope operating mode during inactivity.
00267     //    true: gyroscope in sleep mode
00268     //    false: gyroscope in power-down
00269     void configInactivity(uint8_t duration, uint8_t threshold, bool sleepOn);
00270     
00271     // configAccelInt() -- Configure Accelerometer Interrupt Generator
00272     // Input:
00273     //  - generator = Interrupt axis/high-low events
00274     //    Any OR'd combination of ZHIE_XL, ZLIE_XL, YHIE_XL, YLIE_XL, XHIE_XL, XLIE_XL
00275     //  - andInterrupts = AND/OR combination of interrupt events
00276     //    true: AND combination
00277     //    false: OR combination
00278     void configAccelInt(uint8_t generator, bool andInterrupts = false);
00279     
00280     // configAccelThs() -- Configure the threshold of an accelereomter axis
00281     // Input:
00282     //  - threshold = Interrupt threshold. Possible values: 0-255.
00283     //    Multiply by 128 to get the actual raw accel value.
00284     //  - axis = Axis to be configured. Either X_AXIS, Y_AXIS, or Z_AXIS
00285     //  - duration = Duration value must be above or below threshold to trigger interrupt
00286     //  - wait = Wait function on duration counter
00287     //    true: Wait for duration samples before exiting interrupt
00288     //    false: Wait function off
00289     void configAccelThs(uint8_t threshold, lsm9ds1_axis axis, uint8_t duration = 0, bool wait = 0);
00290     
00291     // configGyroInt() -- Configure Gyroscope Interrupt Generator
00292     // Input:
00293     //  - generator = Interrupt axis/high-low events
00294     //    Any OR'd combination of ZHIE_G, ZLIE_G, YHIE_G, YLIE_G, XHIE_G, XLIE_G
00295     //  - aoi = AND/OR combination of interrupt events
00296     //    true: AND combination
00297     //    false: OR combination
00298     //  - latch: latch gyroscope interrupt request.
00299     void configGyroInt(uint8_t generator, bool aoi, bool latch);
00300     
00301     // configGyroThs() -- Configure the threshold of a gyroscope axis
00302     // Input:
00303     //  - threshold = Interrupt threshold. Possible values: 0-0x7FF.
00304     //    Value is equivalent to raw gyroscope value.
00305     //  - axis = Axis to be configured. Either X_AXIS, Y_AXIS, or Z_AXIS
00306     //  - duration = Duration value must be above or below threshold to trigger interrupt
00307     //  - wait = Wait function on duration counter
00308     //    true: Wait for duration samples before exiting interrupt
00309     //    false: Wait function off
00310     void configGyroThs(int16_t threshold, lsm9ds1_axis axis, uint8_t duration, bool wait);
00311     
00312     // configInt() -- Configure INT1 or INT2 (Gyro and Accel Interrupts only)
00313     // Input:
00314     //  - interrupt = Select INT1 or INT2
00315     //    Possible values: XG_INT1 or XG_INT2
00316     //  - generator = Or'd combination of interrupt generators.
00317     //    Possible values: INT_DRDY_XL, INT_DRDY_G, INT1_BOOT (INT1 only), INT2_DRDY_TEMP (INT2 only)
00318     //    INT_FTH, INT_OVR, INT_FSS5, INT_IG_XL (INT1 only), INT1_IG_G (INT1 only), INT2_INACT (INT2 only)
00319     //  - activeLow = Interrupt active configuration
00320     //    Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW
00321     //  - pushPull =  Push-pull or open drain interrupt configuration
00322     //    Can be either INT_PUSH_PULL or INT_OPEN_DRAIN
00323     void configInt(interrupt_select interupt, uint8_t generator,
00324                    h_lactive activeLow = INT_ACTIVE_LOW, pp_od pushPull = INT_PUSH_PULL);
00325                    
00326     /** configMagInt() -- Configure Magnetometer Interrupt Generator
00327     * Input:
00328     *  - generator = Interrupt axis/high-low events
00329     *    Any OR'd combination of ZIEN, YIEN, XIEN
00330     *  - activeLow = Interrupt active configuration
00331     *    Can be either INT_ACTIVE_HIGH or INT_ACTIVE_LOW
00332     *  - latch: latch gyroscope interrupt request.
00333     */  
00334     void configMagInt(uint8_t generator, h_lactive activeLow, bool latch = true);
00335     
00336     /** configMagThs() -- Configure the threshold of a gyroscope axis
00337     * Input:
00338     *  - threshold = Interrupt threshold. Possible values: 0-0x7FF.
00339     *    Value is equivalent to raw magnetometer value.
00340     */
00341     void configMagThs(uint16_t threshold);
00342     
00343     //! getGyroIntSrc() -- Get contents of Gyroscope interrupt source register
00344     uint8_t getGyroIntSrc();
00345     
00346     //! getGyroIntSrc() -- Get contents of accelerometer interrupt source register
00347     uint8_t getAccelIntSrc();
00348     
00349     //! getGyroIntSrc() -- Get contents of magnetometer interrupt source register
00350     uint8_t getMagIntSrc();
00351     
00352     //! getGyroIntSrc() -- Get status of inactivity interrupt
00353     uint8_t getInactivity();
00354     
00355     /** sleepGyro() -- Sleep or wake the gyroscope
00356     * Input:
00357     *  - enable: True = sleep gyro. False = wake gyro.
00358     */
00359     void sleepGyro(bool enable = true);
00360     
00361     /** enableFIFO() - Enable or disable the FIFO
00362     * Input:
00363     *  - enable: true = enable, false = disable.
00364     */
00365     void enableFIFO(bool enable = true);
00366     
00367     /** setFIFO() - Configure FIFO mode and Threshold
00368     * Input:
00369     *  - fifoMode: Set FIFO mode to off, FIFO (stop when full), continuous, bypass
00370     *    Possible inputs: FIFO_OFF, FIFO_THS, FIFO_CONT_TRIGGER, FIFO_OFF_TRIGGER, FIFO_CONT
00371     *  - fifoThs: FIFO threshold level setting
00372     *    Any value from 0-0x1F is acceptable.
00373     */
00374     void setFIFO(fifoMode_type fifoMode, uint8_t fifoThs);
00375     
00376     //! getFIFOSamples() - Get number of FIFO samples
00377     uint8_t getFIFOSamples();
00378         
00379 
00380 protected:  
00381     // x_mAddress and gAddress store the I2C address or SPI chip select pin
00382     // for each sensor.
00383     uint8_t _mAddress, _xgAddress;
00384     
00385     // gRes, aRes, and mRes store the current resolution for each sensor. 
00386     // Units of these values would be DPS (or g's or Gs's) per ADC tick.
00387     // This value is calculated as (sensor scale) / (2^15).
00388     float gRes, aRes, mRes;
00389     
00390     // _autoCalc keeps track of whether we're automatically subtracting off
00391     // accelerometer and gyroscope bias calculated in calibrate().
00392     bool _autoCalc;
00393     
00394     // init() -- Sets up gyro, accel, and mag settings to default.
00395     // - interface - Sets the interface mode (IMU_MODE_I2C or IMU_MODE_SPI)
00396     // - xgAddr - Sets either the I2C address of the accel/gyro or SPI chip 
00397     //   select pin connected to the CS_XG pin.
00398     // - mAddr - Sets either the I2C address of the magnetometer or SPI chip 
00399     //   select pin connected to the CS_M pin.
00400     void init(interface_mode interface, uint8_t xgAddr, uint8_t mAddr);
00401     
00402     // initGyro() -- Sets up the gyroscope to begin reading.
00403     // This function steps through all five gyroscope control registers.
00404     // Upon exit, the following parameters will be set:
00405     //  - CTRL_REG1_G = 0x0F: Normal operation mode, all axes enabled. 
00406     //      95 Hz ODR, 12.5 Hz cutoff frequency.
00407     //  - CTRL_REG2_G = 0x00: HPF set to normal mode, cutoff frequency
00408     //      set to 7.2 Hz (depends on ODR).
00409     //  - CTRL_REG3_G = 0x88: Interrupt enabled on INT_G (set to push-pull and
00410     //      active high). Data-ready output enabled on DRDY_G.
00411     //  - CTRL_REG4_G = 0x00: Continuous update mode. Data LSB stored in lower
00412     //      address. Scale set to 245 DPS. SPI mode set to 4-wire.
00413     //  - CTRL_REG5_G = 0x00: FIFO disabled. HPF disabled.
00414     void initGyro();
00415     
00416     // initAccel() -- Sets up the accelerometer to begin reading.
00417     // This function steps through all accelerometer related control registers.
00418     // Upon exit these registers will be set as:
00419     //  - CTRL_REG0_XM = 0x00: FIFO disabled. HPF bypassed. Normal mode.
00420     //  - CTRL_REG1_XM = 0x57: 100 Hz data rate. Continuous update.
00421     //      all axes enabled.
00422     //  - CTRL_REG2_XM = 0x00:  2g scale. 773 Hz anti-alias filter BW.
00423     //  - CTRL_REG3_XM = 0x04: Accel data ready signal on INT1_XM pin.
00424     void initAccel();
00425     
00426     // initMag() -- Sets up the magnetometer to begin reading.
00427     // This function steps through all magnetometer-related control registers.
00428     // Upon exit these registers will be set as:
00429     //  - CTRL_REG4_XM = 0x04: Mag data ready signal on INT2_XM pin.
00430     //  - CTRL_REG5_XM = 0x14: 100 Hz update rate. Low resolution. Interrupt
00431     //      requests don't latch. Temperature sensor disabled.
00432     //  - CTRL_REG6_XM = 0x00:  2 Gs scale.
00433     //  - CTRL_REG7_XM = 0x00: Continuous conversion mode. Normal HPF mode.
00434     //  - INT_CTRL_REG_M = 0x09: Interrupt active-high. Enable interrupts.
00435     void initMag();
00436     
00437     // gReadByte() -- Reads a byte from a specified gyroscope register.
00438     // Input:
00439     //  - subAddress = Register to be read from.
00440     // Output:
00441     //  - An 8-bit value read from the requested address.
00442     uint8_t mReadByte(uint8_t subAddress);
00443     
00444     // gReadBytes() -- Reads a number of bytes -- beginning at an address
00445     // and incrementing from there -- from the gyroscope.
00446     // Input:
00447     //  - subAddress = Register to be read from.
00448     //  - * dest = A pointer to an array of uint8_t's. Values read will be
00449     //      stored in here on return.
00450     //  - count = The number of bytes to be read.
00451     // Output: No value is returned, but the `dest` array will store
00452     //  the data read upon exit.
00453     void mReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count);
00454     
00455     // gWriteByte() -- Write a byte to a register in the gyroscope.
00456     // Input:
00457     //  - subAddress = Register to be written to.
00458     //  - data = data to be written to the register.
00459     void mWriteByte(uint8_t subAddress, uint8_t data);
00460     
00461     // xmReadByte() -- Read a byte from a register in the accel/mag sensor
00462     // Input:
00463     //  - subAddress = Register to be read from.
00464     // Output:
00465     //  - An 8-bit value read from the requested register.
00466     uint8_t xgReadByte(uint8_t subAddress);
00467     
00468     // xmReadBytes() -- Reads a number of bytes -- beginning at an address
00469     // and incrementing from there -- from the accelerometer/magnetometer.
00470     // Input:
00471     //  - subAddress = Register to be read from.
00472     //  - * dest = A pointer to an array of uint8_t's. Values read will be
00473     //      stored in here on return.
00474     //  - count = The number of bytes to be read.
00475     // Output: No value is returned, but the `dest` array will store
00476     //  the data read upon exit.
00477     void xgReadBytes(uint8_t subAddress, uint8_t * dest, uint8_t count);
00478     
00479     // xmWriteByte() -- Write a byte to a register in the accel/mag sensor.
00480     // Input:
00481     //  - subAddress = Register to be written to.
00482     //  - data = data to be written to the register.
00483     void xgWriteByte(uint8_t subAddress, uint8_t data);
00484     
00485     // calcgRes() -- Calculate the resolution of the gyroscope.
00486     // This function will set the value of the gRes variable. gScale must
00487     // be set prior to calling this function.
00488     void calcgRes();
00489     
00490     // calcmRes() -- Calculate the resolution of the magnetometer.
00491     // This function will set the value of the mRes variable. mScale must
00492     // be set prior to calling this function.
00493     void calcmRes();
00494     
00495     // calcaRes() -- Calculate the resolution of the accelerometer.
00496     // This function will set the value of the aRes variable. aScale must
00497     // be set prior to calling this function.
00498     void calcaRes();
00499     
00500     //////////////////////
00501     // Helper Functions //
00502     //////////////////////
00503     void constrainScales();
00504     
00505     ///////////////////
00506     // SPI Functions //
00507     ///////////////////
00508     // initSPI() -- Initialize the SPI hardware.
00509     // This function will setup all SPI pins and related hardware.
00510     void initSPI();
00511     
00512     // SPIwriteByte() -- Write a byte out of SPI to a register in the device
00513     // Input:
00514     //  - csPin = The chip select pin of the slave device.
00515     //  - subAddress = The register to be written to.
00516     //  - data = Byte to be written to the register.
00517     void SPIwriteByte(uint8_t csPin, uint8_t subAddress, uint8_t data);
00518     
00519     // SPIreadByte() -- Read a single byte from a register over SPI.
00520     // Input:
00521     //  - csPin = The chip select pin of the slave device.
00522     //  - subAddress = The register to be read from.
00523     // Output:
00524     //  - The byte read from the requested address.
00525     uint8_t SPIreadByte(uint8_t csPin, uint8_t subAddress);
00526     
00527     // SPIreadBytes() -- Read a series of bytes, starting at a register via SPI
00528     // Input:
00529     //  - csPin = The chip select pin of a slave device.
00530     //  - subAddress = The register to begin reading.
00531     //  - * dest = Pointer to an array where we'll store the readings.
00532     //  - count = Number of registers to be read.
00533     // Output: No value is returned by the function, but the registers read are
00534     //      all stored in the *dest array given.
00535     void SPIreadBytes(uint8_t csPin, uint8_t subAddress, 
00536                             uint8_t * dest, uint8_t count);
00537     
00538     ///////////////////
00539     // I2C Functions //
00540     ///////////////////
00541     // initI2C() -- Initialize the I2C hardware.
00542     // This function will setup all I2C pins and related hardware.
00543     void initI2C();
00544     
00545     // I2CwriteByte() -- Write a byte out of I2C to a register in the device
00546     // Input:
00547     //  - address = The 7-bit I2C address of the slave device.
00548     //  - subAddress = The register to be written to.
00549     //  - data = Byte to be written to the register.
00550     void I2CwriteByte(uint8_t address, uint8_t subAddress, uint8_t data);
00551     
00552     // I2CreadByte() -- Read a single byte from a register over I2C.
00553     // Input:
00554     //  - address = The 7-bit I2C address of the slave device.
00555     //  - subAddress = The register to be read from.
00556     // Output:
00557     //  - The byte read from the requested address.
00558     uint8_t I2CreadByte(uint8_t address, uint8_t subAddress);
00559     
00560     // I2CreadBytes() -- Read a series of bytes, starting at a register via SPI
00561     // Input:
00562     //  - address = The 7-bit I2C address of the slave device.
00563     //  - subAddress = The register to begin reading.
00564     //  - * dest = Pointer to an array where we'll store the readings.
00565     //  - count = Number of registers to be read.
00566     // Output: No value is returned by the function, but the registers read are
00567     //      all stored in the *dest array given.
00568     uint8_t I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count);
00569     
00570 private:
00571     I2C i2c;
00572     float gyroX, gyroY, gyroZ; // x, y, and z axis readings of the gyroscope (float value)
00573     float accX, accY, accZ; // x, y, and z axis readings of the accelerometer (float value)
00574     float magX, magY, magZ; // x, y, and z axis readings of the magnetometer (float value)
00575 };
00576 
00577 #endif // SFE_LSM9DS1_H //
00578 
00579