i2c device

This commit is contained in:
MikuQ.com 2016-06-05 19:30:36 +08:00
parent d9f184c1f1
commit 2d9103b806
5 changed files with 33 additions and 19 deletions

View File

@ -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);

View File

@ -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;

View File

@ -41,10 +41,12 @@ sudo ./blink
+-----+-----+---------+------+---+- BPI-M3 -+---+------+---------+-----+-----+
</code></pre>
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"

View File

@ -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;

2
Wire.h
View File

@ -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;