Allows for reading accelerometer, gyroscope, and magnetometer data from an LSM9DS0 IMU device
Dependents: uVGA_4180 uLCD_4180_mini ECE4781_Project
I2Cdev.h@0:1b975a6ae539, 2014-10-21 (annotated)
- Committer:
- randrews33
- Date:
- Tue Oct 21 18:11:45 2014 +0000
- Revision:
- 0:1b975a6ae539
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
randrews33 | 0:1b975a6ae539 | 1 | //ported from arduino library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 |
randrews33 | 0:1b975a6ae539 | 2 | //written by szymon gaertig (email: szymon@gaertig.com.pl) |
randrews33 | 0:1b975a6ae539 | 3 | // |
randrews33 | 0:1b975a6ae539 | 4 | //Changelog: |
randrews33 | 0:1b975a6ae539 | 5 | //2013-01-08 - first beta release |
randrews33 | 0:1b975a6ae539 | 6 | |
randrews33 | 0:1b975a6ae539 | 7 | #ifndef I2Cdev_h |
randrews33 | 0:1b975a6ae539 | 8 | #define I2Cdev_h |
randrews33 | 0:1b975a6ae539 | 9 | |
randrews33 | 0:1b975a6ae539 | 10 | #include "mbed.h" |
randrews33 | 0:1b975a6ae539 | 11 | |
randrews33 | 0:1b975a6ae539 | 12 | #define I2C_SDA p9 |
randrews33 | 0:1b975a6ae539 | 13 | #define I2C_SCL p10 |
randrews33 | 0:1b975a6ae539 | 14 | |
randrews33 | 0:1b975a6ae539 | 15 | class I2Cdev { |
randrews33 | 0:1b975a6ae539 | 16 | private: |
randrews33 | 0:1b975a6ae539 | 17 | I2C i2c; |
randrews33 | 0:1b975a6ae539 | 18 | Serial debugSerial; |
randrews33 | 0:1b975a6ae539 | 19 | public: |
randrews33 | 0:1b975a6ae539 | 20 | I2Cdev(); |
randrews33 | 0:1b975a6ae539 | 21 | I2Cdev(PinName i2cSda, PinName i2cScl); |
randrews33 | 0:1b975a6ae539 | 22 | |
randrews33 | 0:1b975a6ae539 | 23 | int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
randrews33 | 0:1b975a6ae539 | 24 | int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
randrews33 | 0:1b975a6ae539 | 25 | int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
randrews33 | 0:1b975a6ae539 | 26 | int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
randrews33 | 0:1b975a6ae539 | 27 | int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
randrews33 | 0:1b975a6ae539 | 28 | int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
randrews33 | 0:1b975a6ae539 | 29 | int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
randrews33 | 0:1b975a6ae539 | 30 | int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
randrews33 | 0:1b975a6ae539 | 31 | |
randrews33 | 0:1b975a6ae539 | 32 | bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data); |
randrews33 | 0:1b975a6ae539 | 33 | bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data); |
randrews33 | 0:1b975a6ae539 | 34 | bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data); |
randrews33 | 0:1b975a6ae539 | 35 | bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data); |
randrews33 | 0:1b975a6ae539 | 36 | bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data); |
randrews33 | 0:1b975a6ae539 | 37 | bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data); |
randrews33 | 0:1b975a6ae539 | 38 | bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data); |
randrews33 | 0:1b975a6ae539 | 39 | bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data); |
randrews33 | 0:1b975a6ae539 | 40 | |
randrews33 | 0:1b975a6ae539 | 41 | static uint16_t readTimeout(void); |
randrews33 | 0:1b975a6ae539 | 42 | }; |
randrews33 | 0:1b975a6ae539 | 43 | |
randrews33 | 0:1b975a6ae539 | 44 | #endif |