diff --git a/MikuPi.cpp b/MikuPi.cpp index 538bf2f..036f3e2 100755 --- a/MikuPi.cpp +++ b/MikuPi.cpp @@ -19,6 +19,15 @@ #include "MikuPi.h" +char *i2cDevice; + +const char *i2cDevices[3] = +{ + "/dev/i2c-0", + "/dev/i2c-1", + "/dev/i2c-2" +} ; + const char *piModelNames [7] = { "Unknown", @@ -180,8 +189,8 @@ void sayHello() else { printf ("BananaPi Details:\n") ; - printf (" Type: %s, Memory: %dMB\n", - piModelNames [model], mem) ; + printf (" Type: %s, Memory: %dMB\n", piModelNames [model], mem) ; + //printf (" I2C Device: %s\n",i2cDevice) ; } } @@ -202,14 +211,15 @@ void mikuPiSetup (void) printf (" i@mikuq.com\n") ; piBoardRevOops ("with a copy of your /proc/cpuinfo if possible") ; } - if (model == PI_MODEL_M2p) - { - wPinToGpio=wPinToGpioM2p; - } - if (model == PI_MODEL_M3) - { - wPinToGpio=wPinToGpioM3; - } + + if (model == PI_MODEL_M2p) { + wPinToGpio=wPinToGpioM2p; + i2cDevice=(char *)i2cDevices[0]; + } + if (model == PI_MODEL_M3) { + wPinToGpio=wPinToGpioM3; + i2cDevice=(char *)i2cDevices[3]; + } fd = open("/dev/mem", O_RDWR); diff --git a/MikuPi.h b/MikuPi.h index 3086001..efa060c 100755 --- a/MikuPi.h +++ b/MikuPi.h @@ -27,9 +27,10 @@ #define PI_MODEL_M3 5 #define PI_MODEL_M2p 6 +extern char *i2cDevice; extern const int bPinTowPin[41]; -#define VERSION "0.21" +#define VERSION "0.25" extern const char *piModelNames [7] ; @@ -43,7 +44,7 @@ void mikuPiSetup (void); void pinMode(int pin, int mode); void digitalWrite(int pin,int value); -#define SW_PORTC_IO_BASE 0x01c20800 +#define SW_PORTC_IO_BASE 0x01c20800 #define SW_PORTL_IO_BASE 0x01f02c00 extern unsigned int SUNXI_PIO_BASE; diff --git a/README.md b/README.md index dd338f0..23e930b 100755 --- a/README.md +++ b/README.md @@ -41,10 +41,12 @@ sudo ./blink +-----+-----+---------+------+---+- BPI-M3 -+---+------+---------+-----+-----+ -1.(2016-05-30) start & sayhello -2.(2016-06-02) gpio for M2+,M3 & blink -3.(2016-06-04) update to C++ & add Relay -4.(2016-06-05) add Wire & SHT2x + 1.(2016-05-30) start & sayhello + 2.(2016-06-02) gpio for M2+,M3 & blink + 3.(2016-06-04) update to C++ & add Relay + 4.(2016-06-05) add Wire & SHT2x + +upload git add . git commit -a -m "md" diff --git a/Wire.cpp b/Wire.cpp index e729209..2e25a93 100755 --- a/Wire.cpp +++ b/Wire.cpp @@ -14,6 +14,7 @@ * */ +#include "MikuPi.h" #include "Wire.h" uint8 TwoWire::rxBuffer[BUFFER_LENGTH]; @@ -27,7 +28,7 @@ TwoWire::TwoWire() void TwoWire::requestFrom(int address, int quantity) { I2cError = 0; - if ((I2cDevHandle = open("/dev/i2c-0", O_RDWR)) < 0) I2cError |= ERROR_I2C_OPEN; + if ((I2cDevHandle = open(i2cDevice, O_RDWR)) < 0) I2cError |= ERROR_I2C_OPEN; else { if (ioctl(I2cDevHandle, I2C_SLAVE,address) < 0) I2cError |= ERROR_I2C_SETUP; @@ -47,7 +48,7 @@ void TwoWire::requestFrom(int address, int quantity) void TwoWire::beginTransmission(int address) { I2cError = 0; - if ((I2cDevHandle = open("/dev/i2c-0", O_RDWR)) < 0) I2cError |= ERROR_I2C_OPEN; + if ((I2cDevHandle = open(i2cDevice, O_RDWR)) < 0) I2cError |= ERROR_I2C_OPEN; else { if (ioctl(I2cDevHandle, I2C_SLAVE,address) < 0) I2cError |= ERROR_I2C_SETUP; diff --git a/Wire.h b/Wire.h index b5bfd70..c365493 100755 --- a/Wire.h +++ b/Wire.h @@ -25,7 +25,7 @@ class TwoWire void requestFrom(int, int); int available(void); int read(void); - void write(uint8); + void write(uint8); }; extern TwoWire Wire;