Frederick Lemuel Ravibabu / Mbed 2 deprecated LSM9DS1_Library_cal

Dependencies:   PinDetect mbed

Fork of LSM9DS1_Library_cal by jim hamblen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LSM9DS1.h Source File

LSM9DS1.h

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