diff --git a/include/mraa_adv_func.h b/include/mraa_adv_func.h index a8eb8045a..e237ef9df 100644 --- a/include/mraa_adv_func.h +++ b/include/mraa_adv_func.h @@ -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); diff --git a/src/firmata/firmata_mraa.c b/src/firmata/firmata_mraa.c index 9e173b9af..25dd9f584 100644 --- a/src/firmata/firmata_mraa.c +++ b/src/firmata/firmata_mraa.c @@ -191,7 +191,7 @@ 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) { @@ -199,10 +199,10 @@ mraa_firmata_i2c_read_byte(mraa_i2c_context dev) 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) { @@ -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 @@ -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 diff --git a/src/usb/ftdi_ft4222.c b/src/usb/ftdi_ft4222.c index 5c6167e10..cb903e681 100644 --- a/src/usb/ftdi_ft4222.c +++ b/src/usb/ftdi_ft4222.c @@ -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; @@ -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]; @@ -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 @@ -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) { @@ -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) {