a

Files at this revision

API Documentation at this revision

Comitter:
nanjo
Date:
Mon May 06 04:21:43 2019 +0000
Parent:
0:3aa973ebe3e5
Commit message:
a

Changed in this revision

I2Cdev.cpp Show annotated file Show diff for this revision Revisions of this file
I2Cdev.h Show annotated file Show diff for this revision Revisions of this file
diff -r 3aa973ebe3e5 -r 0631d7e009fa I2Cdev.cpp
--- a/I2Cdev.cpp	Sun Jan 31 13:52:23 2016 +0000
+++ b/I2Cdev.cpp	Mon May 06 04:21:43 2019 +0000
@@ -8,11 +8,14 @@
 
 #include "I2Cdev.h"
 
-I2C I2Cdev::i2c(I2C_SDA,I2C_SCL);
+I2Cdev::I2Cdev(): i2c(I2C_SDA,I2C_SCL)
+{
 
-/** Default constructor.
- */
-I2Cdev::I2Cdev() {
+}
+
+I2Cdev::I2Cdev(PinName i2cSda, PinName i2cScl): i2c(i2cSda,i2cScl)
+{
+
 }
 
 /** Read a single bit from an 8-bit device register.
diff -r 3aa973ebe3e5 -r 0631d7e009fa I2Cdev.h
--- a/I2Cdev.h	Sun Jan 31 13:52:23 2016 +0000
+++ b/I2Cdev.h	Mon May 06 04:21:43 2019 +0000
@@ -11,34 +11,36 @@
 
 #include "mbed.h"
 
-#define I2C_SDA p28
-#define I2C_SCL p27
+#define I2C_SDA PB_9
+#define I2C_SCL PB_8
 
-class I2Cdev {
-    private:
-        static I2C i2c;
-    public:
-        I2Cdev();
+class I2Cdev
+{
+private:
 
-        static int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout());
-        static int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout());
-        static int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout());
-        static int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout());
-        static int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout());
-        static int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout());
-        static int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout());
-        static int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout());
+    I2C i2c;
+public:
+    I2Cdev();
+    I2Cdev(PinName i2cSda, PinName i2cScl);
+    int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout());
+    int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout());
+    int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout());
+    int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout());
+    int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout());
+    int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout());
+    int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout());
+    int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout());
 
-        static bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data);
-        static bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data);
-        static bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data);
-        static bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
-        static bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data);
-        static bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
-        static bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data);
-        static bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data);
+    bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data);
+    bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data);
+    bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data);
+    bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data);
+    bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data);
+    bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data);
+    bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data);
+    bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data);
 
-        static uint16_t readTimeout(void);
+    static uint16_t readTimeout(void);
 };
 
 #endif
\ No newline at end of file