File tree 2 files changed +7
-1
lines changed
ports/espressif/common-hal/busio
2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
129
129
130
130
// Wait for any other users of this to finish.
131
131
while (!common_hal_busio_spi_try_lock (self )) {
132
+ RUN_BACKGROUND_TASKS ;
132
133
}
133
134
134
135
// Mark us as deinit early in case we are used in an interrupt.
@@ -139,7 +140,10 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) {
139
140
spi_bus_remove_device (spi_handle [self -> host_id ]);
140
141
spi_bus_free (self -> host_id );
141
142
143
+ // Release the mutex before we delete it. Otherwise FreeRTOS gets unhappy.
144
+ xSemaphoreGive (self -> mutex );
142
145
vSemaphoreDelete (self -> mutex );
146
+ self -> mutex = NULL ;
143
147
144
148
common_hal_reset_pin (self -> MOSI );
145
149
common_hal_reset_pin (self -> MISO );
@@ -166,7 +170,7 @@ bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) {
166
170
}
167
171
168
172
bool common_hal_busio_spi_has_lock (busio_spi_obj_t * self ) {
169
- return xSemaphoreGetMutexHolder (self -> mutex ) == xTaskGetCurrentTaskHandle ();
173
+ return self -> mutex != NULL && xSemaphoreGetMutexHolder (self -> mutex ) == xTaskGetCurrentTaskHandle ();
170
174
}
171
175
172
176
void common_hal_busio_spi_unlock (busio_spi_obj_t * self ) {
Original file line number Diff line number Diff line change @@ -196,8 +196,10 @@ void status_led_deinit() {
196
196
197
197
#elif defined(MICROPY_HW_APA102_MOSI ) && defined(MICROPY_HW_APA102_SCK )
198
198
#if CIRCUITPY_BITBANG_APA102
199
+ shared_module_bitbangio_spi_unlock (& status_apa102 );
199
200
shared_module_bitbangio_spi_deinit (& status_apa102 );
200
201
#else
202
+ common_hal_busio_spi_unlock (& status_apa102 );
201
203
common_hal_busio_spi_deinit (& status_apa102 );
202
204
#endif
203
205
You can’t perform that action at this time.
0 commit comments