Skip to content

Commit e42691b

Browse files
committed
[components][SPI][spi-bit-ops]xfer返回值优化
1 parent d8a1219 commit e42691b

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

components/drivers/spi/spi-bit-ops.c

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ rt_ssize_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *mes
423423
struct rt_spi_bit_ops *ops = obj->ops;
424424
struct rt_spi_configuration *config = &obj->config;
425425
rt_base_t cs_pin = device->cs_pin;
426+
rt_ssize_t length = 0;
426427

427428
RT_ASSERT(device != NULL);
428429
RT_ASSERT(message != NULL);
@@ -468,38 +469,22 @@ rt_ssize_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *mes
468469
{
469470
if (config->data_width <= 8)
470471
{
471-
spi_xfer_3line_data8(ops,
472-
config,
473-
message->send_buf,
474-
message->recv_buf,
475-
message->length);
472+
length = spi_xfer_3line_data8(ops, config, message->send_buf, message->recv_buf, message->length);
476473
}
477474
else if (config->data_width <= 16)
478475
{
479-
spi_xfer_3line_data16(ops,
480-
config,
481-
message->send_buf,
482-
message->recv_buf,
483-
message->length);
476+
length = spi_xfer_3line_data16(ops, config, message->send_buf, message->recv_buf, message->length);
484477
}
485478
}
486479
else
487480
{
488481
if (config->data_width <= 8)
489482
{
490-
spi_xfer_4line_data8(ops,
491-
config,
492-
message->send_buf,
493-
message->recv_buf,
494-
message->length);
483+
length = spi_xfer_4line_data8(ops, config, message->send_buf, message->recv_buf, message->length);
495484
}
496485
else if (config->data_width <= 16)
497486
{
498-
spi_xfer_4line_data16(ops,
499-
config,
500-
message->send_buf,
501-
message->recv_buf,
502-
message->length);
487+
length = spi_xfer_4line_data16(ops, config, message->send_buf, message->recv_buf, message->length);
503488
}
504489
}
505490

@@ -518,7 +503,7 @@ rt_ssize_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *mes
518503
LOG_I("spi release cs\n");
519504
}
520505

521-
return message->length;
506+
return length;
522507
}
523508

524509
static const struct rt_spi_ops spi_bit_bus_ops =

0 commit comments

Comments
 (0)