mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-21 00:27:19 +08:00
[spi]fix some bug for rt_spi_sendrecv16 (#6360)
修复 rt_spi_sendrecv16 api 对最高有效位(MSB or LSB)的处理不当造成的一些问题。 https://github.com/stm32duino/Arduino_Core_STM32/blob/main/libraries/SPI/src/SPI.cpp#L273
This commit is contained in:
parent
9bbe2097db
commit
6ac09a6db0
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@ -7,6 +7,7 @@
|
||||
* Date Author Notes
|
||||
* 2012-11-23 Bernard Add extern "C"
|
||||
* 2020-06-13 armink fix the 3 wires issue
|
||||
* 2022-09-01 liYony fix api rt_spi_sendrecv16 about MSB and LSB bug
|
||||
*/
|
||||
|
||||
#ifndef __SPI_H__
|
||||
@ -227,6 +228,9 @@ rt_err_t rt_spi_send_then_send(struct rt_spi_device *device,
|
||||
const void *send_buf2,
|
||||
rt_size_t send_length2);
|
||||
|
||||
rt_uint16_t rt_spi_sendrecv16(struct rt_spi_device *device,
|
||||
rt_uint16_t data);
|
||||
|
||||
/**
|
||||
* This function transmits data to SPI device.
|
||||
*
|
||||
@ -278,16 +282,6 @@ rt_inline rt_uint8_t rt_spi_sendrecv8(struct rt_spi_device *device,
|
||||
return value;
|
||||
}
|
||||
|
||||
rt_inline rt_uint16_t rt_spi_sendrecv16(struct rt_spi_device *device,
|
||||
rt_uint16_t data)
|
||||
{
|
||||
rt_uint16_t value = 0;
|
||||
|
||||
rt_spi_send_then_recv(device, &data, 2, &value, 2);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function appends a message to the SPI message list.
|
||||
*
|
||||
|
@ -309,6 +309,29 @@ __exit:
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_uint16_t rt_spi_sendrecv16(struct rt_spi_device *device,
|
||||
rt_uint16_t data)
|
||||
{
|
||||
rt_uint16_t value = 0;
|
||||
rt_uint16_t tmp;
|
||||
|
||||
if (device->config.mode & RT_SPI_MSB)
|
||||
{
|
||||
tmp = ((data & 0xff00) >> 8) | ((data & 0x00ff) << 8);
|
||||
data = tmp;
|
||||
}
|
||||
|
||||
rt_spi_send_then_recv(device, &data, 2, &value, 2);
|
||||
|
||||
if (device->config.mode & RT_SPI_MSB)
|
||||
{
|
||||
tmp = ((value & 0xff00) >> 8) | ((value & 0x00ff) << 8);
|
||||
value = tmp;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
struct rt_spi_message *rt_spi_transfer_message(struct rt_spi_device *device,
|
||||
struct rt_spi_message *message)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user