i2c device
This commit is contained in:
parent
d9f184c1f1
commit
2d9103b806
22
MikuPi.cpp
22
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,13 +211,14 @@ void mikuPiSetup (void)
|
||||
printf (" i@mikuq.com\n") ;
|
||||
piBoardRevOops ("with a copy of your /proc/cpuinfo if possible") ;
|
||||
}
|
||||
if (model == PI_MODEL_M2p)
|
||||
{
|
||||
|
||||
if (model == PI_MODEL_M2p) {
|
||||
wPinToGpio=wPinToGpioM2p;
|
||||
i2cDevice=(char *)i2cDevices[0];
|
||||
}
|
||||
if (model == PI_MODEL_M3)
|
||||
{
|
||||
if (model == PI_MODEL_M3) {
|
||||
wPinToGpio=wPinToGpioM3;
|
||||
i2cDevice=(char *)i2cDevices[3];
|
||||
}
|
||||
|
||||
fd = open("/dev/mem", O_RDWR);
|
||||
|
||||
3
MikuPi.h
3
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] ;
|
||||
|
||||
|
||||
@ -46,6 +46,8 @@ sudo ./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"
|
||||
git push origin master
|
||||
|
||||
5
Wire.cpp
5
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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user