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