Skip to content

Commit

Permalink
[components][SPI][spi-bit-ops]xfer返回值优化
Browse files Browse the repository at this point in the history
  • Loading branch information
wdfk-prog committed Jul 1, 2024
1 parent d8a1219 commit e42691b
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions components/drivers/spi/spi-bit-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ rt_ssize_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *mes
struct rt_spi_bit_ops *ops = obj->ops;
struct rt_spi_configuration *config = &obj->config;
rt_base_t cs_pin = device->cs_pin;
rt_ssize_t length = 0;

RT_ASSERT(device != NULL);
RT_ASSERT(message != NULL);
Expand Down Expand Up @@ -468,38 +469,22 @@ rt_ssize_t spi_bit_xfer(struct rt_spi_device *device, struct rt_spi_message *mes
{
if (config->data_width <= 8)
{
spi_xfer_3line_data8(ops,
config,
message->send_buf,
message->recv_buf,
message->length);
length = spi_xfer_3line_data8(ops, config, message->send_buf, message->recv_buf, message->length);
}
else if (config->data_width <= 16)
{
spi_xfer_3line_data16(ops,
config,
message->send_buf,
message->recv_buf,
message->length);
length = spi_xfer_3line_data16(ops, config, message->send_buf, message->recv_buf, message->length);
}
}
else
{
if (config->data_width <= 8)
{
spi_xfer_4line_data8(ops,
config,
message->send_buf,
message->recv_buf,
message->length);
length = spi_xfer_4line_data8(ops, config, message->send_buf, message->recv_buf, message->length);
}
else if (config->data_width <= 16)
{
spi_xfer_4line_data16(ops,
config,
message->send_buf,
message->recv_buf,
message->length);
length = spi_xfer_4line_data16(ops, config, message->send_buf, message->recv_buf, message->length);
}
}

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

return message->length;
return length;
}

static const struct rt_spi_ops spi_bit_bus_ops =
Expand Down

0 comments on commit e42691b

Please sign in to comment.