spi: transfer the tx/rx data with the same structure variable 11/148011/1 accepted/tizen/unified/20170907.190204 submit/tizen/20170907.084231
authorkibak.yoon <kibak.yoon@samsung.com>
Wed, 6 Sep 2017 08:12:02 +0000 (17:12 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Wed, 6 Sep 2017 08:12:02 +0000 (17:12 +0900)
- Tested with ADC(MCP3008)
- The name of spi_read_write() function will be changed to "spi_transfer()".

Change-Id: I6db7383854de46c5e45721fb9ec9da6ce4a51c8f
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/interface/spi.c

index cd20e97..b926405 100644 (file)
@@ -296,19 +296,18 @@ int spi_write(int fd, unsigned char *txbuf, int length)
 int spi_read_write(int fd, unsigned char *txbuf, unsigned char *rxbuf, int length)
 {
        int status;
-       struct spi_ioc_transfer xfer[2];
+       struct spi_ioc_transfer xfer;
 
        RETVM_IF(fd < 0, -EINVAL, "Invalid fd : %d", fd);
 
        if (!txbuf || !rxbuf || length < 0) return -EINVAL;
 
-       memset(xfer, 0, sizeof(xfer));
-       xfer[0].tx_buf = (unsigned long)txbuf;
-       xfer[0].len = length;
-       xfer[1].rx_buf = (unsigned long)rxbuf;
-       xfer[1].len = length;
+       memset(&xfer, 0, sizeof(xfer));
+       xfer.tx_buf = (unsigned long)txbuf;
+       xfer.rx_buf = (unsigned long)rxbuf;
+       xfer.len = length;
 
-       status = ioctl(fd, SPI_IOC_MESSAGE(2), xfer);
+       status = ioctl(fd, SPI_IOC_MESSAGE(1), xfer);
        if (status < 0) {
                char errmsg[MAX_ERR_LEN];
                strerror_r(errno, errmsg, MAX_ERR_LEN);