From 72992070c5137ce44969555828673ba7ccd69f08 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 9 Apr 2019 11:36:10 -0700 Subject: [PATCH] Fix boards with no shared busses. --- py/runtime.c | 8 ++++++++ py/runtime.h | 1 + shared-bindings/board/__init__.c | 1 + shared-module/board/__init__.c | 7 +++++++ shared-module/displayio/__init__.c | 14 ++++++++------ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/py/runtime.c b/py/runtime.c index 060748f1b88a..1e01003373ab 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1590,6 +1590,14 @@ NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg) { mp_raise_msg(&mp_type_NotImplementedError, msg); } +NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...) { + va_list argptr; + va_start(argptr,fmt); + mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_NotImplementedError, fmt, argptr); + va_end(argptr); + nlr_raise(exception); +} + #if MICROPY_STACK_CHECK || MICROPY_ENABLE_PYSTACK NORETURN void mp_raise_recursion_depth(void) { mp_raise_RuntimeError(translate("maximum recursion depth exceeded")); diff --git a/py/runtime.h b/py/runtime.h index e52d3232ee30..2577c9dd531f 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -162,6 +162,7 @@ NORETURN void mp_raise_OSError(int errno_); NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg); NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg); +NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, ...); NORETURN void mp_raise_recursion_depth(void); #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG diff --git a/shared-bindings/board/__init__.c b/shared-bindings/board/__init__.c index 1092d40a01c2..82a0cab6753d 100644 --- a/shared-bindings/board/__init__.c +++ b/shared-bindings/board/__init__.c @@ -25,6 +25,7 @@ */ #include "py/obj.h" +#include "py/runtime.h" #include "shared-bindings/board/__init__.h" diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index 3647e2654612..ac4de2fe5eda 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -37,6 +37,7 @@ #include "shared-module/displayio/__init__.h" #endif +#if BOARD_I2C mp_obj_t common_hal_board_get_i2c(void) { return MP_STATE_VM(shared_i2c_bus); } @@ -49,7 +50,10 @@ mp_obj_t common_hal_board_create_i2c(void) { MP_STATE_VM(shared_i2c_bus) = MP_OBJ_FROM_PTR(self); return MP_STATE_VM(shared_i2c_bus); } +#endif + +#if BOARD_SPI // Statically allocate the SPI object so it can live past the end of the heap and into the next VM. // That way it can be used by built-in FourWire displays and be accessible through board.SPI(). STATIC busio_spi_obj_t spi_obj; @@ -73,7 +77,9 @@ mp_obj_t common_hal_board_create_spi(void) { spi_singleton = (mp_obj_t)self; return spi_singleton; } +#endif +#if BOARD_UART mp_obj_t common_hal_board_get_uart(void) { return MP_STATE_VM(shared_uart_bus); } @@ -89,6 +95,7 @@ mp_obj_t common_hal_board_create_uart(void) { MP_STATE_VM(shared_uart_bus) = MP_OBJ_FROM_PTR(self); return MP_STATE_VM(shared_uart_bus); } +#endif void reset_board_busses(void) { #if BOARD_I2C diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index c1f5a68100fc..156640440eb4 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -191,12 +191,14 @@ void reset_displays(void) { if (((uint32_t) fourwire->bus) < ((uint32_t) &displays) || ((uint32_t) fourwire->bus) > ((uint32_t) &displays + CIRCUITPY_DISPLAY_LIMIT)) { busio_spi_obj_t* original_spi = fourwire->bus; - // We don't need to move original_spi if it is the board.SPI object because it is - // statically allocated already. (Doing so would also make it impossible to reference in - // a subsequent VM run.) - if (original_spi == common_hal_board_get_spi()) { - continue; - } + #if BOARD_SPI + // We don't need to move original_spi if it is the board.SPI object because it is + // statically allocated already. (Doing so would also make it impossible to reference in + // a subsequent VM run.) + if (original_spi == common_hal_board_get_spi()) { + continue; + } + #endif memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t)); fourwire->bus = &fourwire->inline_bus; // Check for other displays that use the same spi bus and swap them too.