From 93968942c29c730f2c88adb188265124a3aa464f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 21 May 2023 21:49:27 -0400 Subject: [PATCH] =?UTF-8?q?[device][spi]=20=E4=BF=AE=E5=A4=8D=20rt=5Fspi?= =?UTF-8?q?=5Fsendrecv8/16=20=E6=94=B6=E5=8F=91=E4=B8=8D=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20rt=5Fspi=5Fsend=5Fthen=5Frecv?= =?UTF-8?q?=E6=98=AF=E5=85=88=E5=8F=91=E5=86=8D=E7=AD=89=E5=BE=85=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=8B=AC=E7=AB=8B=E7=9A=84=E6=B6=88=E6=81=AF=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=20rt=5Fspi=5Ftransfer=E6=98=AF=E6=94=B6=E5=8F=91?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E8=BF=9B=E8=A1=8C=20rt=5Fspi=5Fsendrecv8/16?= =?UTF-8?q?=E5=BA=94=E4=BD=BF=E7=94=A8rt=5Fspi=5Ftransfer=E8=80=8C?= =?UTF-8?q?=E4=B8=8D=E6=98=AFrt=5Fspi=5Fsend=5Fthen=5Frecv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/include/drivers/spi.h | 22 ++++++----------- components/drivers/spi/spi_core.c | 31 ++++++++++++++++++------ 2 files changed, 31 insertions(+), 22 deletions(-) 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,