Skip to content

Commit b14468a

Browse files
committed
Fixup the QSPI transfer result check
The result could < 0 (with error number) now. Signed-off-by: GuEe-GUI <[email protected]>
1 parent 7735d13 commit b14468a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

components/drivers/include/drivers/dev_spi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ rt_err_t rt_qspi_bus_register(struct rt_spi_bus *bus, const char *name, const st
603603
*
604604
* @return the actual length of transmitted.
605605
*/
606-
rt_size_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message);
606+
rt_ssize_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message);
607607

608608
/**
609609
* @brief This function can send data then receive data from QSPI device
@@ -616,7 +616,7 @@ rt_size_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qsp
616616
*
617617
* @return the status of transmit.
618618
*/
619-
rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length,void *recv_buf, rt_size_t recv_length);
619+
rt_ssize_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length,void *recv_buf, rt_size_t recv_length);
620620

621621
/**
622622
* @brief This function can send data to QSPI device
@@ -627,7 +627,7 @@ rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_
627627
*
628628
* @return the status of transmit.
629629
*/
630-
rt_err_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_size_t length);
630+
rt_ssize_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_size_t length);
631631

632632
#ifdef __cplusplus
633633
}

components/drivers/spi/dev_qspi_core.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ rt_err_t rt_qspi_bus_register(struct rt_spi_bus *bus, const char *name, const st
7777
return spi_bus_register(bus, name, ops);
7878
}
7979

80-
rt_size_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message)
80+
rt_ssize_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qspi_message *message)
8181
{
82-
rt_err_t result;
82+
rt_ssize_t result;
8383

8484
RT_ASSERT(device != RT_NULL);
8585
RT_ASSERT(message != RT_NULL);
@@ -128,7 +128,7 @@ rt_size_t rt_qspi_transfer_message(struct rt_qspi_device *device, struct rt_qsp
128128
return result;
129129
}
130130

131-
rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length, void *recv_buf, rt_size_t recv_length)
131+
rt_ssize_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_buf, rt_size_t send_length, void *recv_buf, rt_size_t recv_length)
132132
{
133133
RT_ASSERT(send_buf);
134134
RT_ASSERT(recv_buf);
@@ -137,7 +137,7 @@ rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_
137137
struct rt_qspi_message message;
138138
unsigned char *ptr = (unsigned char *)send_buf;
139139
rt_size_t count = 0;
140-
rt_err_t result = 0;
140+
rt_ssize_t result = 0;
141141

142142
message.instruction.content = ptr[0];
143143
message.instruction.qspi_lines = 1;
@@ -206,23 +206,23 @@ rt_err_t rt_qspi_send_then_recv(struct rt_qspi_device *device, const void *send_
206206
{
207207
result = -RT_EIO;
208208
}
209-
else
209+
else if (result > 0)
210210
{
211211
result = recv_length;
212212
}
213213

214214
return result;
215215
}
216216

217-
rt_err_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_size_t length)
217+
rt_ssize_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_size_t length)
218218
{
219219
RT_ASSERT(send_buf);
220220
RT_ASSERT(length != 0);
221221

222222
struct rt_qspi_message message;
223223
unsigned char *ptr = (unsigned char *)send_buf;
224224
rt_size_t count = 0;
225-
rt_err_t result = 0;
225+
rt_ssize_t result = 0;
226226

227227
message.instruction.content = ptr[0];
228228
message.instruction.qspi_lines = 1;
@@ -292,7 +292,7 @@ rt_err_t rt_qspi_send(struct rt_qspi_device *device, const void *send_buf, rt_si
292292
{
293293
result = -RT_EIO;
294294
}
295-
else
295+
else if (result > 0)
296296
{
297297
result = length;
298298
}

0 commit comments

Comments
 (0)