diff --git a/components/drivers/include/drivers/spi.h b/components/drivers/include/drivers/spi.h index 7f7c2cedcc..8ba269f94b 100644 --- a/components/drivers/include/drivers/spi.h +++ b/components/drivers/include/drivers/spi.h @@ -237,10 +237,6 @@ rt_err_t rt_spi_send_then_send(struct rt_spi_device *device, const void *send_buf2, rt_size_t send_length2); -rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device, - rt_uint16_t senddata, - rt_uint16_t *recvdata); - /** * This function transmits data to SPI device. * @@ -256,6 +252,14 @@ rt_ssize_t rt_spi_transfer(struct rt_spi_device *device, void *recv_buf, rt_size_t length); +rt_err_t rt_spi_sendrecv8(struct rt_spi_device *device, + rt_uint8_t senddata, + rt_uint8_t *recvdata); + +rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device, + rt_uint16_t senddata, + rt_uint16_t *recvdata); + /** * This function transfers a message list to the SPI device. * @@ -282,16 +286,6 @@ rt_inline rt_size_t rt_spi_send(struct rt_spi_device *device, return rt_spi_transfer(device, send_buf, RT_NULL, length); } -rt_inline rt_uint8_t rt_spi_sendrecv8(struct rt_spi_device *device, - rt_uint8_t data) -{ - rt_uint8_t value = 0; - - rt_spi_send_then_recv(device, &data, 1, &value, 1); - - return value; -} - /** * This function appends a message to the SPI message list. * diff --git a/components/drivers/spi/spi_core.c b/components/drivers/spi/spi_core.c index 9cff697b32..994faa4bf4 100644 --- a/components/drivers/spi/spi_core.c +++ b/components/drivers/spi/spi_core.c @@ -343,11 +343,26 @@ __exit: return result; } -rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device, - rt_uint16_t senddata, - rt_uint16_t *recvdata) +rt_err_t rt_spi_sendrecv8(struct rt_spi_device *device, + rt_uint8_t senddata, + rt_uint8_t *recvdata) { - rt_err_t result; + rt_ssize_t len = rt_spi_transfer(device, &senddata, recvdata, 1); + if (len < 0) + { + return (rt_err_t)len; + } + else + { + return RT_EOK; + } +} + +rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device, + rt_uint16_t senddata, + rt_uint16_t *recvdata) +{ + rt_ssize_t len; rt_uint16_t tmp; if (device->config.mode & RT_SPI_MSB) @@ -356,10 +371,10 @@ rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device, senddata = tmp; } - result = rt_spi_send_then_recv(device, &senddata, 2, recvdata, 2); - if(result != RT_EOK) + len = rt_spi_transfer(device, &senddata, recvdata, 2); + if(len < 0) { - return result; + return (rt_err_t)len; } if (device->config.mode & RT_SPI_MSB) @@ -368,7 +383,7 @@ rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device, *recvdata = tmp; } - return result; + return RT_EOK; } struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device,