Skip to content

Commit 0c55b83

Browse files
committed
update reset_board_busses()
- rename it to `reset_board_buses()` - add deinited check before i2c and spi unlock
1 parent 6dda9cb commit 0c55b83

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ STATIC void cleanup_after_vm(supervisor_allocation *heap, mp_obj_t exception) {
288288
keypad_reset();
289289
#endif
290290

291-
// reset_board_busses() first because it may release pins from the never_reset state, so that
291+
// reset_board_buses() first because it may release pins from the never_reset state, so that
292292
// reset_port() can reset them.
293293
#if CIRCUITPY_BOARD
294-
reset_board_busses();
294+
reset_board_buses();
295295
#endif
296296
reset_port();
297297
reset_board();

shared-module/board/__init__.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ mp_obj_t common_hal_board_create_uart(const mp_int_t instance) {
168168
}
169169
#endif
170170

171-
void reset_board_busses(void) {
171+
void reset_board_buses(void) {
172172
#if CIRCUITPY_BOARD_I2C
173173
for (uint8_t instance = 0; instance < CIRCUITPY_BOARD_I2C; instance++) {
174174
bool display_using_i2c = false;
@@ -180,10 +180,12 @@ void reset_board_busses(void) {
180180
}
181181
}
182182
#endif
183-
// make sure I2C lock is not held over a soft reset
184-
common_hal_busio_i2c_unlock(&i2c_obj[instance]);
185-
if (!display_using_i2c) {
186-
common_hal_busio_i2c_deinit(&i2c_obj[instance]);
183+
if (!common_hal_busio_i2c_deinited(&i2c_obj[instance])) {
184+
// make sure I2C lock is not held over a soft reset
185+
common_hal_busio_i2c_unlock(&i2c_obj[instance]);
186+
if (!display_using_i2c) {
187+
common_hal_busio_i2c_deinit(&i2c_obj[instance]);
188+
}
187189
}
188190
}
189191
#endif
@@ -205,10 +207,12 @@ void reset_board_busses(void) {
205207
#endif
206208
}
207209
#endif
208-
// make sure SPI lock is not held over a soft reset
209-
common_hal_busio_spi_unlock(&spi_obj[instance]);
210-
if (!display_using_spi) {
211-
common_hal_busio_spi_deinit(&spi_obj[instance]);
210+
if (!common_hal_busio_spi_deinited(&spi_obj[instance])) {
211+
// make sure SPI lock is not held over a soft reset
212+
common_hal_busio_spi_unlock(&spi_obj[instance]);
213+
if (!display_using_spi) {
214+
common_hal_busio_spi_deinit(&spi_obj[instance]);
215+
}
212216
}
213217
}
214218
#endif

shared-module/board/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
#ifndef MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H
2828
#define MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H
2929

30-
void reset_board_busses(void);
30+
void reset_board_buses(void);
3131

3232
#endif // MICROPY_INCLUDED_SHARED_MODULE_BOARD__INIT__H

0 commit comments

Comments
 (0)