Skip to content

Commit

Permalink
i2c: Make i2c advance function match new prototypes
Browse files Browse the repository at this point in the history
Signed-off-by: Brendan Le Foll <[email protected]>
  • Loading branch information
arfoll committed Apr 22, 2016
1 parent 1e4516d commit c1465bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
6 changes: 3 additions & 3 deletions include/mraa_adv_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ typedef struct {
mraa_result_t (*i2c_set_frequency_replace) (mraa_i2c_context dev, mraa_i2c_mode_t mode);
mraa_result_t (*i2c_address_replace) (mraa_i2c_context dev, uint8_t addr);
int (*i2c_read_replace) (mraa_i2c_context dev, uint8_t* data, int length);
uint8_t (*i2c_read_byte_replace) (mraa_i2c_context dev);
uint8_t (*i2c_read_byte_data_replace) (mraa_i2c_context dev, const uint8_t command);
uint16_t (*i2c_read_word_data_replace) (mraa_i2c_context dev, const uint8_t command);
int (*i2c_read_byte_replace) (mraa_i2c_context dev);
int (*i2c_read_byte_data_replace) (mraa_i2c_context dev, const uint8_t command);
int (*i2c_read_word_data_replace) (mraa_i2c_context dev, const uint8_t command);
int (*i2c_read_bytes_data_replace) (mraa_i2c_context dev, uint8_t command, uint8_t* data, int length);
mraa_result_t (*i2c_write_replace) (mraa_i2c_context dev, const uint8_t* data, int length);
mraa_result_t (*i2c_write_byte_replace) (mraa_i2c_context dev, uint8_t data);
Expand Down
18 changes: 9 additions & 9 deletions src/firmata/firmata_mraa.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@ mraa_firmata_i2c_wait(int addr, int reg)
return MRAA_SUCCESS;
}

static uint8_t
static int
mraa_firmata_i2c_read_byte(mraa_i2c_context dev)
{
if (mraa_firmata_send_i2c_read_req(dev, 1) == MRAA_SUCCESS) {
if (mraa_firmata_i2c_wait(dev->addr, 0) == MRAA_SUCCESS) {
return firmata_dev->i2cmsg[dev->addr][0];
}
}
return 0;
return -1;
}

static uint16_t
static int
mraa_firmata_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{
if (mraa_firmata_send_i2c_read_reg_req(dev, command, 2) == MRAA_SUCCESS) {
Expand All @@ -215,10 +215,10 @@ mraa_firmata_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
data = (data << 8) & 0xFF00;
data |= high;

return data;
}
return (int) data;
}
}
return 0;
return -1;
}

static int
Expand Down Expand Up @@ -249,16 +249,16 @@ mraa_firmata_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
return 0;
}

static uint8_t
static int
mraa_firmata_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
{
if (mraa_firmata_send_i2c_read_reg_req(dev, command, 1) == MRAA_SUCCESS) {
if (mraa_firmata_i2c_wait(dev->addr, command) == MRAA_SUCCESS) {
return firmata_dev->i2cmsg[dev->addr][command];
return (int) firmata_dev->i2cmsg[dev->addr][command];
}
}

return 0;
return -1;
}

static mraa_result_t
Expand Down
21 changes: 12 additions & 9 deletions src/usb/ftdi_ft4222.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,17 @@ mraa_ftdi_ft4222_i2c_read(mraa_i2c_context dev, uint8_t* data, int length)
return bytes_read;
}

static uint8_t
static int
mraa_ftdi_ft4222_i2c_read_byte(mraa_i2c_context dev)
{
uint8_t data;
pthread_mutex_lock(&ft4222_lock);
int bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, &data, 1);
pthread_mutex_unlock(&ft4222_lock);
return bytes_read == 1 ? data : 0;
return bytes_read == 1 ? data : -1;
}

static uint8_t
static int
mraa_ftdi_ft4222_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
{
uint8_t data;
Expand All @@ -570,10 +570,13 @@ mraa_ftdi_ft4222_i2c_read_byte_data(mraa_i2c_context dev, uint8_t command)
if (bytesWritten == 1)
bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, &data, 1);
pthread_mutex_unlock(&ft4222_lock);
return (bytes_read == 1) ? data : 0;
if (bytes_read == 1) {
return (int) data;
}
return -1;
}

static uint16_t
static int
mraa_ftdi_ft4222_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
{
uint8_t buf[2];
Expand All @@ -584,8 +587,10 @@ mraa_ftdi_ft4222_i2c_read_word_data(mraa_i2c_context dev, uint8_t command)
if (bytes_written == 1)
bytes_read = mraa_ftdi_ft4222_i2c_context_read(dev, buf, 2);
pthread_mutex_unlock(&ft4222_lock);
data = (bytes_read == 2) ? *(uint16_t*)buf : 0;
return data;
if (bytes_read == 2) {
return (int) data;
}
return -1;
}

static int
Expand All @@ -600,7 +605,6 @@ mraa_ftdi_ft4222_i2c_read_bytes_data(mraa_i2c_context dev, uint8_t command, uint
return bytes_read;
}


static mraa_result_t
mraa_ftdi_ft4222_i2c_write(mraa_i2c_context dev, const uint8_t* data, int bytesToWrite)
{
Expand All @@ -618,7 +622,6 @@ mraa_ftdi_ft4222_i2c_write_byte(mraa_i2c_context dev, uint8_t data)
return status;
}


static mraa_result_t
mraa_ftdi_ft4222_i2c_write_byte_data(mraa_i2c_context dev, const uint8_t data, const uint8_t command)
{
Expand Down

0 comments on commit c1465bd

Please sign in to comment.