1
1
/*
2
- * Copyright (c) 2006-2023, RT-Thread Development Team
2
+ * Copyright (c) 2006-2024 RT-Thread Development Team
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*
@@ -98,6 +98,18 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
98
98
{
99
99
if (device -> bus -> owner == device )
100
100
{
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
+ }
101
113
/* current device is using, re-configure SPI bus */
102
114
result = device -> bus -> ops -> configure (device , & device -> config );
103
115
if (result != RT_EOK )
@@ -108,8 +120,8 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
108
120
}
109
121
else
110
122
{
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
113
125
*/
114
126
return - RT_EBUSY ;
115
127
}
@@ -132,15 +144,6 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
132
144
RT_ASSERT (device != RT_NULL );
133
145
RT_ASSERT (cfg != RT_NULL );
134
146
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
-
144
147
/* If the configurations are the same, we don't need to set again. */
145
148
if (device -> config .data_width == cfg -> data_width &&
146
149
device -> config .mode == (cfg -> mode & RT_SPI_MODE_MASK ) &&
0 commit comments