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
*
@@ -108,8 +108,8 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device)
108
108
}
109
109
else
110
110
{
111
- /* RT_EBUSY is not an error condition and
112
- * the configuration will take effect once the device has the bus
111
+ /* RT_EBUSY is not an error condition and
112
+ * the configuration will take effect once the device has the bus
113
113
*/
114
114
return - RT_EBUSY ;
115
115
}
@@ -131,14 +131,24 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
131
131
{
132
132
RT_ASSERT (device != RT_NULL );
133
133
RT_ASSERT (cfg != RT_NULL );
134
+ rt_err_t result = - RT_ERROR ;
134
135
135
- /* reset the CS pin */
136
- if (device -> cs_pin != PIN_NONE )
136
+ result = rt_mutex_take ( & ( device -> bus -> lock ), RT_WAITING_FOREVER );
137
+ if (result == RT_EOK )
137
138
{
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 );
139
+ /* reset the CS pin */
140
+ if (device -> cs_pin != PIN_NONE )
141
+ {
142
+ if (cfg -> mode & RT_SPI_CS_HIGH )
143
+ rt_pin_write (device -> cs_pin , PIN_LOW );
144
+ else
145
+ rt_pin_write (device -> cs_pin , PIN_HIGH );
146
+ }
147
+ rt_mutex_release (& (device -> bus -> lock ));
148
+ }
149
+ else
150
+ {
151
+ return result ;
142
152
}
143
153
144
154
/* If the configurations are the same, we don't need to set again. */
0 commit comments