From ac131e1e178ddcc7e3cc1544b5d12ed953699593 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Tue, 22 Apr 2014 15:30:34 +0100 Subject: [PATCH] i2cslave: basic working implimentation Signed-off-by: Brendan Le Foll --- src/i2c/i2cslave.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/i2c/i2cslave.cxx b/src/i2c/i2cslave.cxx index f5b9022..3f700fd 100644 --- a/src/i2c/i2cslave.cxx +++ b/src/i2c/i2cslave.cxx @@ -28,9 +28,9 @@ using namespace maa; I2CSlave::I2CSlave(unsigned int sda, unsigned int scl) { - // Galileo only has one I2CSlave device which is always /dev/i2c-0 + // Galileo only has one I2C master which should be /dev/i2c-0 // reliability is a fickle friend! - if (i2c_handle = open("/dev/i2c-0", O_RDWR) < 1) { + if ((i2c_handle = open("/dev/i2c-0", O_RDWR)) < 1) { fprintf(stderr, "Failed to open requested i2c port"); } } @@ -50,7 +50,8 @@ I2CSlave::receive(void) int I2CSlave::read(char *data, int length) { - if (this->read(data, length) == length) { + // this is the read(3) syscall not I2CSlave::read() + if (::read(i2c_handle, data, length) == length) { return length; } return -1; @@ -69,7 +70,7 @@ I2CSlave::read(void) int I2CSlave::write(const char *data, int length) { - if (i2c_smbus_write_i2c_block_data(i2c_handle, data[0], length, (uint8_t*) data) < 0) { + if (i2c_smbus_write_i2c_block_data(i2c_handle, data[0], length-1, (uint8_t*) data+1) < 0) { fprintf(stderr, "Failed to write to I2CSlave slave\n"); return -1; }