[device][spi] 修复 rt_spi_sendrecv8/16 收发不同时的问题

rt_spi_send_then_recv是先发再等待一个独立的消息接收
rt_spi_transfer是收发同时进行
rt_spi_sendrecv8/16应使用rt_spi_transfer而不是rt_spi_send_then_recv
This commit is contained in:
Meco Man 2023-05-21 21:49:27 -04:00 committed by Man, Jianting (Meco)
parent d8a42139bf
commit 93968942c2
2 changed files with 31 additions and 22 deletions

View File

@ -237,10 +237,6 @@ rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
const void *send_buf2, const void *send_buf2,
rt_size_t send_length2); 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. * 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, void *recv_buf,
rt_size_t length); 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. * 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); 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. * This function appends a message to the SPI message list.
* *

View File

@ -343,11 +343,26 @@ __exit:
return result; return result;
} }
rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device, rt_err_t rt_spi_sendrecv8(struct rt_spi_device *device,
rt_uint16_t senddata, rt_uint8_t senddata,
rt_uint16_t *recvdata) 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; rt_uint16_t tmp;
if (device->config.mode & RT_SPI_MSB) if (device->config.mode & RT_SPI_MSB)
@ -356,10 +371,10 @@ rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device,
senddata = tmp; senddata = tmp;
} }
result = rt_spi_send_then_recv(device, &senddata, 2, recvdata, 2); len = rt_spi_transfer(device, &senddata, recvdata, 2);
if(result != RT_EOK) if(len < 0)
{ {
return result; return (rt_err_t)len;
} }
if (device->config.mode & RT_SPI_MSB) if (device->config.mode & RT_SPI_MSB)
@ -368,7 +383,7 @@ rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device,
*recvdata = tmp; *recvdata = tmp;
} }
return result; return RT_EOK;
} }
struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device, struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device,