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
@@ -49,6 +49,7 @@ int main ()
|
||||
spi = new mraa::Spi(0);
|
||||
|
||||
char data[] = {0x00, 100};
|
||||
char rxBuf[2];
|
||||
char *recv;
|
||||
while (running == 0) {
|
||||
int i;
|
||||
@@ -56,14 +57,18 @@ int main ()
|
||||
data[1] = i;
|
||||
recv = spi->write(data, 2);
|
||||
printf("Writing -%i",i);
|
||||
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
|
||||
if (recv) {
|
||||
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
|
||||
free(recv);
|
||||
}
|
||||
usleep(100000);
|
||||
}
|
||||
for (i = 130; i > 90; i--) {
|
||||
data[1] = i;
|
||||
recv = spi->write(data, 2);
|
||||
printf("Writing -%i",i);
|
||||
printf("RECIVED-%i-%i\n",recv[0],recv[1]);
|
||||
if (spi->transfer(data, rxBuf, 2) == MRAA_SUCCESS) {
|
||||
printf("Writing -%i",i);
|
||||
printf("RECIVED-%i-%i\n",rxBuf[0],rxBuf[1]);
|
||||
}
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user