Skip to content

Commit 144eb13

Browse files
authored
Merge pull request #3627 from adafruit/6.0.x
Merge 6.0.x bugfixes to main
2 parents 0938d4e + bbed1b0 commit 144eb13

File tree

7 files changed

+30
-24
lines changed

7 files changed

+30
-24
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
}

ports/atmel-samd/boards/matrixportal_m4/pins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
1616
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_BUSY), MP_ROM_PTR(&pin_PA22) },
1717
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_RESET), MP_ROM_PTR(&pin_PA21) },
1818
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_RTS), MP_ROM_PTR(&pin_PA18) },
19-
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_TX), MP_ROM_PTR(&pin_PA12) },
20-
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_RX), MP_ROM_PTR(&pin_PA13) },
19+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_TX), MP_ROM_PTR(&pin_PA13) },
20+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ESP_RX), MP_ROM_PTR(&pin_PA12) },
2121

2222
{ MP_OBJ_NEW_QSTR(MP_QSTR_SCL),MP_ROM_PTR(&pin_PB30) },
2323
{ MP_OBJ_NEW_QSTR(MP_QSTR_SDA),MP_ROM_PTR(&pin_PB31) },

shared-bindings/board/__init__.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
#include "py/runtime.h"
2929

3030
#include "shared-bindings/board/__init__.h"
31+
#if BOARD_I2C
32+
#include "shared-bindings/busio/I2C.h"
33+
#endif
34+
#if BOARD_SPI
35+
#include "shared-bindings/busio/SPI.h"
36+
#endif
3137

3238
//| """Board specific pin names
3339
//|
@@ -45,7 +51,7 @@
4551
#if BOARD_I2C
4652
mp_obj_t board_i2c(void) {
4753
mp_obj_t singleton = common_hal_board_get_i2c();
48-
if (singleton != NULL) {
54+
if (singleton != NULL && !common_hal_busio_i2c_deinited(singleton)) {
4955
return singleton;
5056
}
5157
assert_pin_free(DEFAULT_I2C_BUS_SDA);
@@ -69,7 +75,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
6975
#if BOARD_SPI
7076
mp_obj_t board_spi(void) {
7177
mp_obj_t singleton = common_hal_board_get_spi();
72-
if (singleton != NULL) {
78+
if (singleton != NULL && !common_hal_busio_spi_deinited(singleton)) {
7379
return singleton;
7480
}
7581
assert_pin_free(DEFAULT_SPI_BUS_SCK);

shared-module/board/__init__.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ mp_obj_t common_hal_board_get_i2c(void) {
5555
}
5656

5757
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));
6160
busio_i2c_obj_t *self = &i2c_obj;
6261
self->base.type = &busio_i2c_type;
6362

@@ -79,9 +78,8 @@ mp_obj_t common_hal_board_get_spi(void) {
7978
}
8079

8180
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));
8583
busio_spi_obj_t *self = &spi_obj;
8684
self->base.type = &busio_spi_type;
8785

@@ -139,14 +137,17 @@ void reset_board_busses(void) {
139137
bool display_using_i2c = false;
140138
#if CIRCUITPY_DISPLAYIO
141139
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) {
143141
display_using_i2c = true;
144142
break;
145143
}
146144
}
147145
#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+
}
150151
}
151152
#endif
152153
#if BOARD_SPI
@@ -169,9 +170,10 @@ void reset_board_busses(void) {
169170
// make sure SPI lock is not held over a soft reset
170171
if (spi_singleton != NULL) {
171172
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+
}
175177
}
176178
#endif
177179
#if BOARD_UART

supervisor/serial.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,4 @@ char serial_read(void);
4747
bool serial_bytes_available(void);
4848
bool serial_connected(void);
4949

50-
extern volatile bool _serial_connected;
5150
#endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H

supervisor/shared/serial.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ busio_uart_obj_t debug_uart;
4747
byte buf_array[64];
4848
#endif
4949

50-
volatile bool _serial_connected;
51-
5250
void serial_early_init(void) {
5351
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
5452
debug_uart.base.type = &busio_uart_type;
@@ -71,7 +69,9 @@ bool serial_connected(void) {
7169
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
7270
return true;
7371
#else
74-
return _serial_connected;
72+
// True if DTR is asserted, and the USB connection is up.
73+
// tud_cdc_get_line_state(): bit 0 is DTR, bit 1 is RTS
74+
return (tud_cdc_get_line_state() & 1) && tud_ready();
7575
#endif
7676
}
7777

supervisor/shared/usb/usb.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ void tud_umount_cb(void) {
116116
// remote_wakeup_en : if host allows us to perform remote wakeup
117117
// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus
118118
void tud_suspend_cb(bool remote_wakeup_en) {
119-
_serial_connected = false;
120119
}
121120

122121
// Invoked when usb bus is resumed
@@ -128,8 +127,6 @@ void tud_resume_cb(void) {
128127
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
129128
(void) itf; // interface ID, not used
130129

131-
_serial_connected = dtr;
132-
133130
// DTR = false is counted as disconnected
134131
if ( !dtr )
135132
{

0 commit comments

Comments
 (0)