Skip to content

Commit 083960c

Browse files
committed
Fix SAMD51 builds and Prox Trinkey
Adds CIRCUITPY_BUSIO_UART to disable UART by raising ValueError that no pins work.
1 parent b56455f commit 083960c

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MICROPY_HW_MCU_NAME "samd21e18"
33

44
#define MICROPY_HW_NEOPIXEL (&pin_PA15)
5+
#define MICROPY_HW_NEOPIXEL_COUNT (2)
56

67
#define IGNORE_PIN_PA01 1
78
#define IGNORE_PIN_PA02 1

ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CIRCUITPY_FULL_BUILD = 0
1414
CIRCUITPY_ANALOGIO = 0
1515
CIRCUITPY_AUDIOCORE = 0
1616
CIRCUITPY_BUSIO_SPI = 0
17+
CIRCUITPY_BUSIO_UART = 0
1718
CIRCUITPY_PULSEIO = 0
1819
CIRCUITPY_PWMIO = 0
1920
CIRCUITPY_ROTARYIO = 0

ports/atmel-samd/supervisor/port.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,12 @@ void port_interrupt_after_ticks(uint32_t ticks) {
594594
#endif
595595

596596
uint32_t target = current_ticks + (ticks << 4);
597+
#ifdef SAMD21
597598
// Try and avoid a bus stall when writing COMP by checking for an obvious
598599
// existing sync.
599600
while (RTC->MODE0.STATUS.bit.SYNCBUSY == 1) {
600601
}
602+
#endif
601603
// Writing the COMP register can take up to 180us to synchronize. During
602604
// this time, the bus will stall and no interrupts will be serviced.
603605
RTC->MODE0.COMP[0].reg = target;

py/circuitpy_mpconfig.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,15 @@ CFLAGS += -DCIRCUITPY_BUILTINS_POW3=$(CIRCUITPY_BUILTINS_POW3)
121121
CIRCUITPY_BUSIO ?= 1
122122
CFLAGS += -DCIRCUITPY_BUSIO=$(CIRCUITPY_BUSIO)
123123

124+
# These two flags pretend to implement their class but raise a ValueError due to
125+
# unsupported pins. This should be used sparingly on boards that don't break out
126+
# generic IO but need parts of busio.
124127
CIRCUITPY_BUSIO_SPI ?= 1
125128
CFLAGS += -DCIRCUITPY_BUSIO_SPI=$(CIRCUITPY_BUSIO_SPI)
126129

130+
CIRCUITPY_BUSIO_UART ?= 1
131+
CFLAGS += -DCIRCUITPY_BUSIO_UART=$(CIRCUITPY_BUSIO_UART)
132+
127133
CIRCUITPY_CAMERA ?= 0
128134
CFLAGS += -DCIRCUITPY_CAMERA=$(CIRCUITPY_CAMERA)
129135

shared-bindings/busio/SPI.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, con
104104
common_hal_busio_spi_construct(self, clock, mosi, miso);
105105
return MP_OBJ_FROM_PTR(self);
106106
#else
107-
mp_raise_NotImplementedError(NULL);
107+
mp_raise_ValueError(translate("Invalid pins"));
108108
#endif // CIRCUITPY_BUSIO_SPI
109109
}
110110

shared-bindings/busio/UART.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,16 @@ typedef struct {
7272
extern const busio_uart_parity_obj_t busio_uart_parity_even_obj;
7373
extern const busio_uart_parity_obj_t busio_uart_parity_odd_obj;
7474

75+
#if CIRCUITPY_BUSIO_UART
7576
STATIC void validate_timeout(mp_float_t timeout) {
7677
if (timeout < (mp_float_t)0.0f || timeout > (mp_float_t)100.0f) {
7778
mp_raise_ValueError(translate("timeout must be 0.0-100.0 seconds"));
7879
}
7980
}
81+
#endif // CIRCUITPY_BUSIO_UART
8082

8183
STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
84+
#if CIRCUITPY_BUSIO_UART
8285
// Always initially allocate the UART object within the long-lived heap.
8386
// This is needed to avoid crashes with certain UART implementations which
8487
// cannot accomodate being moved after creation. (See
@@ -141,8 +144,12 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co
141144
args[ARG_baudrate].u_int, bits, parity, stop, timeout,
142145
args[ARG_receiver_buffer_size].u_int, NULL, false);
143146
return (mp_obj_t)self;
147+
#else
148+
mp_raise_ValueError(translate("Invalid pins"));
149+
#endif // CIRCUITPY_BUSIO_UART
144150
}
145151

152+
#if CIRCUITPY_BUSIO_UART
146153

147154
// Helper to ensure we have the native super class instead of a subclass.
148155
busio_uart_obj_t *native_uart(mp_obj_t uart_obj) {
@@ -358,6 +365,7 @@ STATIC mp_obj_t busio_uart_obj_reset_input_buffer(mp_obj_t self_in) {
358365
return mp_const_none;
359366
}
360367
STATIC MP_DEFINE_CONST_FUN_OBJ_1(busio_uart_reset_input_buffer_obj, busio_uart_obj_reset_input_buffer);
368+
#endif // CIRCUITPY_BUSIO_UART
361369

362370
//| class Parity:
363371
//| """Enum-like class to define the parity used to verify correct data transfer."""
@@ -400,6 +408,7 @@ const mp_obj_type_t busio_uart_parity_type = {
400408
};
401409

402410
STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = {
411+
#if CIRCUITPY_BUSIO_UART
403412
{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&busio_uart_deinit_obj) },
404413
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&busio_uart_deinit_obj) },
405414
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
@@ -417,12 +426,14 @@ STATIC const mp_rom_map_elem_t busio_uart_locals_dict_table[] = {
417426
{ MP_ROM_QSTR(MP_QSTR_baudrate), MP_ROM_PTR(&busio_uart_baudrate_obj) },
418427
{ MP_ROM_QSTR(MP_QSTR_in_waiting), MP_ROM_PTR(&busio_uart_in_waiting_obj) },
419428
{ MP_ROM_QSTR(MP_QSTR_timeout), MP_ROM_PTR(&busio_uart_timeout_obj) },
429+
#endif // CIRCUITPY_BUSIO_UART
420430

421431
// Nested Enum-like Classes.
422432
{ MP_ROM_QSTR(MP_QSTR_Parity), MP_ROM_PTR(&busio_uart_parity_type) },
423433
};
424434
STATIC MP_DEFINE_CONST_DICT(busio_uart_locals_dict, busio_uart_locals_dict_table);
425435

436+
#if CIRCUITPY_BUSIO_UART
426437
STATIC const mp_stream_p_t uart_stream_p = {
427438
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_stream)
428439
.read = busio_uart_read,
@@ -445,3 +456,11 @@ const mp_obj_type_t busio_uart_type = {
445456
.protocol = &uart_stream_p,
446457
),
447458
};
459+
#else
460+
const mp_obj_type_t busio_uart_type = {
461+
{ &mp_type_type },
462+
.name = MP_QSTR_UART,
463+
.make_new = busio_uart_make_new,
464+
.locals_dict = (mp_obj_dict_t *)&busio_uart_locals_dict,
465+
};
466+
#endif // CIRCUITPY_BUSIO_UART

0 commit comments

Comments
 (0)