Private
Public Access
2
0

spi: make mraa_spi_write_buf call mraa_transfer_buf

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2014-10-18 18:47:44 +01:00
committed by Brendan Le Foll
parent 2a11e31052
commit d734a661fd
3 changed files with 15 additions and 23 deletions

View File

@@ -96,7 +96,7 @@ mraa_result_t mraa_spi_frequency(mraa_spi_context dev, int hz);
uint8_t mraa_spi_write(mraa_spi_context dev, uint8_t data);
/** Write Buffer of bytes to the SPI device. The pointer return has to be
* free'd by the caller.
* free'd by the caller. It will return a NULL pointer in cases of error.
*
* @param dev The Spi context
* @param data to send

View File

@@ -85,7 +85,8 @@ class Spi {
}
/**
* Write buffer of bytes to SPI device The pointer return has to be
* free'd by the caller.
* free'd by the caller. It will return a NULL pointer in cases of
* error
*
* @param data buffer to send
* @param length size of buffer to send

View File

@@ -172,27 +172,6 @@ mraa_spi_write(mraa_spi_context dev, uint8_t data)
return recv;
}
uint8_t*
mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
{
struct spi_ioc_transfer msg;
memset(&msg, 0, sizeof(msg));
uint8_t* recv = malloc(sizeof(uint8_t) * length);
msg.tx_buf = (unsigned long) data;
msg.rx_buf = (unsigned long) recv;
msg.speed_hz = dev->clock;
msg.bits_per_word = dev->bpw;
msg.delay_usecs = 0;
msg.len = length;
if (ioctl(dev->devfd, SPI_IOC_MESSAGE(1), &msg) < 0) {
syslog(LOG_ERR, "Failed to perform dev transfer");
return NULL;
}
return recv;
}
mraa_result_t
mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length)
{
@@ -212,6 +191,18 @@ mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int l
return MRAA_SUCCESS;
}
uint8_t*
mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
{
uint8_t* recv = malloc(sizeof(uint8_t) * length);
if (mraa_spi_transfer_buf(dev, data, recv, length) != MRAA_SUCCESS) {
free(recv);
return NULL;
}
return recv;
}
mraa_result_t
mraa_spi_stop(mraa_spi_context dev)
{