spi: transfer the tx/rx data with the same structure variable 22/148022/1 accepted/tizen/4.0/unified/20170907.200140 submit/tizen_4.0/20170907.084141
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 09:50:50 +0000 (09:50 +0000)
- 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>
(cherry picked from commit 2c2412ce0706788c57fc1ffc3c2bd8834fc17a71)

src/interface/spi.c

index 601be5c8749f783ce538add7a7acec6092bad8be..50f43653a79278a2729611620e7bf15c186b1b9d 100644 (file)
@@ -300,19 +300,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;
 
        if (fd < 0) return -EINVAL;
 
        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);