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:
committed by
Brendan Le Foll
parent
54deb01796
commit
2a11e31052
@@ -105,6 +105,17 @@ uint8_t mraa_spi_write(mraa_spi_context dev, uint8_t data);
|
||||
*/
|
||||
uint8_t* mraa_spi_write_buf(mraa_spi_context dev, uint8_t* data, int length);
|
||||
|
||||
/** Transfer Buffer of bytes to the SPI device. Both send and recv buffers
|
||||
* are passed in
|
||||
*
|
||||
* @param dev The Spi context
|
||||
* @param data to send
|
||||
* @param rxbuf buffer to recv data back, may be NULL
|
||||
* @param length elements within buffer, Max 4096
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* data, uint8_t* rxbuf, int length);
|
||||
|
||||
/**
|
||||
* Change the SPI lsb mode
|
||||
*
|
||||
|
||||
@@ -84,7 +84,8 @@ class Spi {
|
||||
return (char) mraa_spi_write(m_spi, (uint8_t) data);
|
||||
}
|
||||
/**
|
||||
* Write buffer of bytes to SPI device
|
||||
* Write buffer of bytes to SPI device The pointer return has to be
|
||||
* free'd by the caller.
|
||||
*
|
||||
* @param data buffer to send
|
||||
* @param length size of buffer to send
|
||||
@@ -93,6 +94,18 @@ class Spi {
|
||||
char* write(char* data, size_t length) {
|
||||
return (char*) mraa_spi_write_buf(m_spi, (uint8_t *) data, (int) length);
|
||||
}
|
||||
/**
|
||||
* Transfer data to and from SPI device Receive pointer may be null if return
|
||||
* data is not needed.
|
||||
*
|
||||
* @param data buffer to send
|
||||
* @param rxBuf buffer to optionally receive data from spi device
|
||||
* @param length size of buffer to send
|
||||
* @return Result of operation
|
||||
*/
|
||||
mraa_result_t transfer(char* data, char* rxBuf, size_t length) {
|
||||
return mraa_spi_transfer_buf(m_spi, (uint8_t *) data, (uint8_t *)rxBuf, (int) length);
|
||||
}
|
||||
/**
|
||||
* Change the SPI lsb mode
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user