Private
Public Access
2
0

spi: Add SPI transfer function that pass in RX/TX

When using SPI, I prefer to not have to do malloc/free functions for each
transfer, so why not have a transfer function that you can pass in both
buffers.  With my ILI9341 TFT display code that gave some perf wins, also more
of a win, you can pass in NULL for recv buffer and the underlying device driver
does not have to copy the data.

Signed-off-by: Kurt Eckhardt <kurte@rockisland.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Kurt Eckhardt
2014-10-18 09:25:19 -07:00
committed by Brendan Le Foll
parent 54deb01796
commit 2a11e31052
4 changed files with 53 additions and 5 deletions

View File

@@ -193,6 +193,25 @@ mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length)
return recv;
}
mraa_result_t
mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length)
{
struct spi_ioc_transfer msg;
memset(&msg, 0, sizeof(msg));
msg.tx_buf = (unsigned long) data;
msg.rx_buf = (unsigned long) rxbuf;
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 MRAA_ERROR_INVALID_RESOURCE;
}
return MRAA_SUCCESS;
}
mraa_result_t
mraa_spi_stop(mraa_spi_context dev)
{