Skip to content

Commit 54e18ea

Browse files
committed
Fix lost board.SPI and board.I2C after being used by display.
Fixes #3581. Pins were marked as never_reset by common_hal_displayio_fourwire_construct() and common_hal_sharpdisplay_framebuffer_construct(), but these marks were never removed, so at the end of a session after displayio.release_displays(), {spi|i2c}_singleton would be set to NULL but the pins would not be reset. In the next session, board.SPI() and board.I2C() were unable to reconstruct the object because the pins were still in use. For symmetry with creation of the singleton, add deinitialization before setting it to NULL in reset_board_busses(). This makes the pins resettable, so that reset_port(), moved behind it, then resets them.
1 parent 600dc69 commit 54e18ea

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,12 @@ void cleanup_after_vm(supervisor_allocation* heap) {
234234
common_hal_canio_reset();
235235
#endif
236236

237-
reset_port();
237+
// reset_board_busses() first because it may release pins from the never_reset state, so that
238+
// reset_port() can reset them.
238239
#if CIRCUITPY_BOARD
239240
reset_board_busses();
240241
#endif
242+
reset_port();
241243
reset_board();
242244
reset_status_led();
243245
}

shared-module/board/__init__.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,11 @@ void reset_board_busses(void) {
145145
}
146146
}
147147
#endif
148-
if (!display_using_i2c) {
149-
i2c_singleton = NULL;
148+
if (i2c_singleton != NULL) {
149+
if (!display_using_i2c) {
150+
common_hal_busio_i2c_deinit(i2c_singleton);
151+
i2c_singleton = NULL;
152+
}
150153
}
151154
#endif
152155
#if BOARD_SPI
@@ -169,9 +172,10 @@ void reset_board_busses(void) {
169172
// make sure SPI lock is not held over a soft reset
170173
if (spi_singleton != NULL) {
171174
common_hal_busio_spi_unlock(spi_singleton);
172-
}
173-
if (!display_using_spi) {
174-
spi_singleton = NULL;
175+
if (!display_using_spi) {
176+
common_hal_busio_spi_deinit(spi_singleton);
177+
spi_singleton = NULL;
178+
}
175179
}
176180
#endif
177181
#if BOARD_UART

0 commit comments

Comments
 (0)