From: kibak.yoon Date: Wed, 6 Sep 2017 08:12:02 +0000 (+0900) Subject: spi: transfer the tx/rx data with the same structure variable X-Git-Tag: submit/tizen_4.0/20170907.084141^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=447f5ca43552c877acc3dc17eb70fab82f0725ea;p=platform%2Fcore%2Fsystem%2Fperipheral-bus.git spi: transfer the tx/rx data with the same structure variable - 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 (cherry picked from commit 2c2412ce0706788c57fc1ffc3c2bd8834fc17a71) --- diff --git a/src/interface/spi.c b/src/interface/spi.c index 601be5c..50f4365 100644 --- a/src/interface/spi.c +++ b/src/interface/spi.c @@ -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);