MPU9250
Fork of MPU6050 by
I2Cdev.h@22:ec9725201195, 2018-04-18 (annotated)
- Committer:
- tyftyftyf
- Date:
- Wed Apr 18 20:24:13 2018 +0000
- Revision:
- 22:ec9725201195
- Parent:
- 15:09f072efa71e
change to I2C 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garfieldsg | 0:662207e34fba | 1 | //ported from arduino library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 |
pommzorz | 2:3cf70c42a784 | 2 | //written by szymon gaertig (email: szymon@gaertig.com.pl), small correction by Aloïs Wolff |
garfieldsg | 0:662207e34fba | 3 | // |
garfieldsg | 0:662207e34fba | 4 | //Changelog: |
garfieldsg | 0:662207e34fba | 5 | //2013-01-08 - first beta release |
pommzorz | 2:3cf70c42a784 | 6 | //2013-02-18 - fixed a malloc with no free in ::readBytes |
garfieldsg | 0:662207e34fba | 7 | |
garfieldsg | 0:662207e34fba | 8 | #ifndef I2Cdev_h |
garfieldsg | 0:662207e34fba | 9 | #define I2Cdev_h |
garfieldsg | 0:662207e34fba | 10 | |
tyftyftyf | 15:09f072efa71e | 11 | #include "mbed.h" |
tyftyftyf | 15:09f072efa71e | 12 | |
tyftyftyf | 9:d879deb55ae1 | 13 | #ifndef I2C_SDA |
tyftyftyf | 22:ec9725201195 | 14 | #define I2C_SDA p9 |
tyftyftyf | 22:ec9725201195 | 15 | #define I2C_SCL p10 |
tyftyftyf | 9:d879deb55ae1 | 16 | #endif |
garfieldsg | 0:662207e34fba | 17 | |
tyftyftyf | 9:d879deb55ae1 | 18 | #include "mbed.h" |
tyftyftyf | 9:d879deb55ae1 | 19 | #include "MODI2C.h" |
garfieldsg | 0:662207e34fba | 20 | |
garfieldsg | 0:662207e34fba | 21 | class I2Cdev { |
garfieldsg | 0:662207e34fba | 22 | private: |
tyftyftyf | 9:d879deb55ae1 | 23 | |
garfieldsg | 0:662207e34fba | 24 | Serial debugSerial; |
garfieldsg | 0:662207e34fba | 25 | public: |
garfieldsg | 0:662207e34fba | 26 | I2Cdev(); |
garfieldsg | 0:662207e34fba | 27 | I2Cdev(PinName i2cSda, PinName i2cScl); |
tyftyftyf | 9:d879deb55ae1 | 28 | I2Cdev(MODI2C i2c_); |
garfieldsg | 0:662207e34fba | 29 | |
garfieldsg | 0:662207e34fba | 30 | int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 31 | int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 32 | int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 33 | int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 34 | int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 35 | int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 36 | int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 37 | int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 38 | |
garfieldsg | 0:662207e34fba | 39 | bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data); |
garfieldsg | 0:662207e34fba | 40 | bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data); |
garfieldsg | 0:662207e34fba | 41 | bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data); |
garfieldsg | 0:662207e34fba | 42 | bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data); |
garfieldsg | 0:662207e34fba | 43 | bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data); |
garfieldsg | 0:662207e34fba | 44 | bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data); |
garfieldsg | 0:662207e34fba | 45 | bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data); |
garfieldsg | 0:662207e34fba | 46 | bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data); |
tyftyftyf | 9:d879deb55ae1 | 47 | |
tyftyftyf | 9:d879deb55ae1 | 48 | void readBytes_nb(uint8_t devAddr, char *command, uint8_t length, uint8_t *data, uint32_t (*function)(uint32_t), void* param); |
garfieldsg | 0:662207e34fba | 49 | |
garfieldsg | 0:662207e34fba | 50 | static uint16_t readTimeout(void); |
tyftyftyf | 9:d879deb55ae1 | 51 | |
tyftyftyf | 9:d879deb55ae1 | 52 | MODI2C i2c; |
tyftyftyf | 9:d879deb55ae1 | 53 | |
tyftyftyf | 9:d879deb55ae1 | 54 | char* allocbuffer(); |
tyftyftyf | 9:d879deb55ae1 | 55 | void freebuffer(); |
tyftyftyf | 9:d879deb55ae1 | 56 | |
tyftyftyf | 10:11cc1b413f49 | 57 | MemoryPool<char[14], 16> pool; |
tyftyftyf | 10:11cc1b413f49 | 58 | Queue<char, 16> queue; |
garfieldsg | 0:662207e34fba | 59 | }; |
garfieldsg | 0:662207e34fba | 60 | |
garfieldsg | 0:662207e34fba | 61 | #endif |