Skip to content

Commit 61338b6

Browse files
committed
feat:[drivers][spi] reset the CS pin 调用位置更为合理
1 parent 4fcc03c commit 61338b6

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

components/drivers/include/drivers/dev_spi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2023, RT-Thread Development Team
2+
* Copyright (c) 2006-2024 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*

components/drivers/spi/dev_spi_core.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2023, RT-Thread Development Team
2+
* Copyright (c) 2006-2024 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -98,6 +98,18 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
9898
{
9999
if (device->bus->owner == device)
100100
{
101+
/* reset the CS pin */
102+
if (device->cs_pin != PIN_NONE)
103+
{
104+
if (device->config.mode & RT_SPI_CS_HIGH)
105+
{
106+
rt_pin_write(device->cs_pin, PIN_LOW);
107+
}
108+
else
109+
{
110+
rt_pin_write(device->cs_pin, PIN_HIGH);
111+
}
112+
}
101113
/* current device is using, re-configure SPI bus */
102114
result = device->bus->ops->configure(device, &device->config);
103115
if (result != RT_EOK)
@@ -108,8 +120,8 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
108120
}
109121
else
110122
{
111-
/* RT_EBUSY is not an error condition and
112-
* the configuration will take effect once the device has the bus
123+
/* RT_EBUSY is not an error condition and
124+
* the configuration will take effect once the device has the bus
113125
*/
114126
return -RT_EBUSY;
115127
}
@@ -132,15 +144,6 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
132144
RT_ASSERT(device != RT_NULL);
133145
RT_ASSERT(cfg != RT_NULL);
134146

135-
/* reset the CS pin */
136-
if (device->cs_pin != PIN_NONE)
137-
{
138-
if (cfg->mode & RT_SPI_CS_HIGH)
139-
rt_pin_write(device->cs_pin, PIN_LOW);
140-
else
141-
rt_pin_write(device->cs_pin, PIN_HIGH);
142-
}
143-
144147
/* If the configurations are the same, we don't need to set again. */
145148
if (device->config.data_width == cfg->data_width &&
146149
device->config.mode == (cfg->mode & RT_SPI_MODE_MASK) &&

0 commit comments

Comments
 (0)