@@ -55,9 +55,8 @@ mp_obj_t common_hal_board_get_i2c(void) {
55
55
}
56
56
57
57
mp_obj_t common_hal_board_create_i2c (void ) {
58
- if (i2c_singleton != NULL ) {
59
- return i2c_singleton ;
60
- }
58
+ // All callers have either already verified this or come so early that it can't be otherwise.
59
+ assert (i2c_singleton == NULL || common_hal_busio_i2c_deinited (i2c_singleton ));
61
60
busio_i2c_obj_t * self = & i2c_obj ;
62
61
self -> base .type = & busio_i2c_type ;
63
62
@@ -79,9 +78,8 @@ mp_obj_t common_hal_board_get_spi(void) {
79
78
}
80
79
81
80
mp_obj_t common_hal_board_create_spi (void ) {
82
- if (spi_singleton != NULL ) {
83
- return spi_singleton ;
84
- }
81
+ // All callers have either already verified this or come so early that it can't be otherwise.
82
+ assert (spi_singleton == NULL || common_hal_busio_spi_deinited (spi_singleton ));
85
83
busio_spi_obj_t * self = & spi_obj ;
86
84
self -> base .type = & busio_spi_type ;
87
85
@@ -139,14 +137,17 @@ void reset_board_busses(void) {
139
137
bool display_using_i2c = false;
140
138
#if CIRCUITPY_DISPLAYIO
141
139
for (uint8_t i = 0 ; i < CIRCUITPY_DISPLAY_LIMIT ; i ++ ) {
142
- if (displays [i ].i2cdisplay_bus .bus == i2c_singleton ) {
140
+ if (displays [i ].bus_base . type == & displayio_i2cdisplay_type && displays [ i ]. i2cdisplay_bus .bus == i2c_singleton ) {
143
141
display_using_i2c = true;
144
142
break ;
145
143
}
146
144
}
147
145
#endif
148
- if (!display_using_i2c ) {
149
- i2c_singleton = NULL ;
146
+ if (i2c_singleton != NULL ) {
147
+ if (!display_using_i2c ) {
148
+ common_hal_busio_i2c_deinit (i2c_singleton );
149
+ i2c_singleton = NULL ;
150
+ }
150
151
}
151
152
#endif
152
153
#if BOARD_SPI
@@ -169,9 +170,10 @@ void reset_board_busses(void) {
169
170
// make sure SPI lock is not held over a soft reset
170
171
if (spi_singleton != NULL ) {
171
172
common_hal_busio_spi_unlock (spi_singleton );
172
- }
173
- if (!display_using_spi ) {
174
- spi_singleton = NULL ;
173
+ if (!display_using_spi ) {
174
+ common_hal_busio_spi_deinit (spi_singleton );
175
+ spi_singleton = NULL ;
176
+ }
175
177
}
176
178
#endif
177
179
#if BOARD_UART
0 commit comments