spi: return int instead of uint8_t in mraa_spi_write
This stops the error code getting lost since -1 wraps around to 0xFF when cast to a uint8_t. This fixes #146 Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -102,9 +102,9 @@ mraa_result_t mraa_spi_frequency(mraa_spi_context dev, int hz);
|
||||
*
|
||||
* @param dev The Spi context
|
||||
* @param data Data to send
|
||||
* @return Data received on the miso line
|
||||
* @return Data received on the miso line or -1 in case of error
|
||||
*/
|
||||
uint8_t mraa_spi_write(mraa_spi_context dev, uint8_t data);
|
||||
int mraa_spi_write(mraa_spi_context dev, uint8_t data);
|
||||
|
||||
/**
|
||||
*Write Two Bytes to the SPI device.
|
||||
|
||||
@@ -93,9 +93,9 @@ class Spi {
|
||||
* Write single byte to the SPI device
|
||||
*
|
||||
* @param data the byte to send
|
||||
* @return data received on the miso line
|
||||
* @return data received on the miso line or -1 in case of error
|
||||
*/
|
||||
uint8_t writeByte(uint8_t data) {
|
||||
int writeByte(uint8_t data) {
|
||||
return mraa_spi_write(m_spi, (uint8_t) data);
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ mraa_spi_bit_per_word(mraa_spi_context dev, unsigned int bits)
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
int
|
||||
mraa_spi_write(mraa_spi_context dev, uint8_t data)
|
||||
{
|
||||
struct spi_ioc_transfer msg;
|
||||
@@ -242,7 +242,7 @@ mraa_spi_write(mraa_spi_context dev, uint8_t data)
|
||||
|
||||
uint16_t length = 1;
|
||||
|
||||
uint8_t recv = 0;
|
||||
unsigned long recv = 0;
|
||||
msg.tx_buf = (unsigned long) &data;
|
||||
msg.rx_buf = (unsigned long) &recv;
|
||||
msg.speed_hz = dev->clock;
|
||||
@@ -253,7 +253,7 @@ mraa_spi_write(mraa_spi_context dev, uint8_t data)
|
||||
syslog(LOG_ERR, "spi: Failed to perform dev transfer");
|
||||
return -1;
|
||||
}
|
||||
return recv;
|
||||
return (int) recv;
|
||||
}
|
||||
|
||||
uint16_t
|
||||
|
||||
Reference in New Issue
Block a user