diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index b4c54062f6..07546abf5c 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -108,7 +108,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/hallowing_m4_express/board.c b/ports/atmel-samd/boards/hallowing_m4_express/board.c index 6bb2a591f0..6822368d72 100644 --- a/ports/atmel-samd/boards/hallowing_m4_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m4_express/board.c @@ -88,7 +88,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/monster_m4sk/board.c b/ports/atmel-samd/boards/monster_m4sk/board.c index 2377f4a9da..eeafdb4b80 100644 --- a/ports/atmel-samd/boards/monster_m4sk/board.c +++ b/ports/atmel-samd/boards/monster_m4sk/board.c @@ -89,7 +89,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pewpew_m4/board.c b/ports/atmel-samd/boards/pewpew_m4/board.c index 5f5a01e48e..ef259e27a6 100644 --- a/ports/atmel-samd/boards/pewpew_m4/board.c +++ b/ports/atmel-samd/boards/pewpew_m4/board.c @@ -139,7 +139,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands false, // auto_refresh - 20); // native_frames_per_second + 20, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index bead06f3c6..1209c027ee 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -111,7 +111,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pybadge_airlift/board.c b/ports/atmel-samd/boards/pybadge_airlift/board.c index 061f3d7772..dfbf7023fa 100644 --- a/ports/atmel-samd/boards/pybadge_airlift/board.c +++ b/ports/atmel-samd/boards/pybadge_airlift/board.c @@ -89,7 +89,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index 70d4a05dcd..6df485fa9e 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -111,7 +111,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pygamer_advance/board.c b/ports/atmel-samd/boards/pygamer_advance/board.c index ff2da34a26..ad5abd3f6c 100644 --- a/ports/atmel-samd/boards/pygamer_advance/board.c +++ b/ports/atmel-samd/boards/pygamer_advance/board.c @@ -89,7 +89,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index 2a72897784..a86f0ee48a 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -100,7 +100,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pyportal_titano/board.c b/ports/atmel-samd/boards/pyportal_titano/board.c index 828ceebc4e..a9ded1760d 100644 --- a/ports/atmel-samd/boards/pyportal_titano/board.c +++ b/ports/atmel-samd/boards/pyportal_titano/board.c @@ -117,7 +117,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index ce389a2b1c..96f2361fd6 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -108,7 +108,8 @@ void board_init(void) { false, // single_byte_bounds false, // data as commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk index b1f916ec20..166eaad3f7 100644 --- a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk +++ b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk @@ -12,8 +12,8 @@ CHIP_VARIANT = SAMD51J20A CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 -EXTERNAL_FLASH_DEVICE_COUNT = 1 -EXTERNAL_FLASH_DEVICES = W25Q32JV_IQ +EXTERNAL_FLASH_DEVICE_COUNT = 2 +EXTERNAL_FLASH_DEVICES = "GD25Q64C, W25Q32JV_IQ" LONGINT_IMPL = MPZ # Disable modules that are unusable on this special-purpose board. diff --git a/ports/mimxrt10xx/common-hal/busio/UART.c b/ports/mimxrt10xx/common-hal/busio/UART.c index b34b948b29..4633507d8b 100644 --- a/ports/mimxrt10xx/common-hal/busio/UART.c +++ b/ports/mimxrt10xx/common-hal/busio/UART.c @@ -270,9 +270,14 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t LPUART_TransferAbortReceive(self->uart, &self->handle); } + // No data left, we got it all + if (self->handle.rxData == NULL) { + return len; + } + // The only place we can reliably tell how many bytes have been received is from the current // wp in the handle (because the abort nukes rxDataSize, and reading it before abort is a race.) - return self->handle.rxData-data; + return self->handle.rxData - data; } // Write characters. diff --git a/ports/nrf/boards/clue_nrf52840_express/board.c b/ports/nrf/boards/clue_nrf52840_express/board.c index e342c6d939..03b212f9e0 100644 --- a/ports/nrf/boards/clue_nrf52840_express/board.c +++ b/ports/nrf/boards/clue_nrf52840_express/board.c @@ -88,7 +88,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/nrf/boards/ohs2020_badge/board.c b/ports/nrf/boards/ohs2020_badge/board.c index 9e881d7639..106bbd6e16 100644 --- a/ports/nrf/boards/ohs2020_badge/board.c +++ b/ports/nrf/boards/ohs2020_badge/board.c @@ -81,14 +81,15 @@ void board_init(void) { 0x37, // set vertical scroll command display_init_sequence, sizeof(display_init_sequence), - NULL, // backlight pin + &pin_P0_02, // backlight pin NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) true, // auto_brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + false); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/ports/stm/boards/meowbit_v121/board.c b/ports/stm/boards/meowbit_v121/board.c index a0ae988249..da87f00ec2 100644 --- a/ports/stm/boards/meowbit_v121/board.c +++ b/ports/stm/boards/meowbit_v121/board.c @@ -109,7 +109,8 @@ void board_init(void) { false, // single_byte_bounds false, // data_as_commands true, // auto_refresh - 60); // native_frames_per_second + 60, // native_frames_per_second + true); // backlight_on_high } bool board_requests_safe_mode(void) { diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 991c828be8..3ef7e74e9e 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -104,9 +104,10 @@ //| :param bool data_as_commands: Treat all init and boundary data as SPI commands. Certain displays require this. //| :param bool auto_refresh: Automatically refresh the screen //| :param int native_frames_per_second: Number of display refreshes per second that occur with the given init_sequence. +//| :param bool backlight_on_high: If True, pulling the backlight pin high turns the backlight on. //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second }; + enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command, ARG_set_vertical_scroll, ARG_backlight_pin, ARG_brightness_command, ARG_brightness, ARG_auto_brightness, ARG_single_byte_bounds, ARG_data_as_commands, ARG_auto_refresh, ARG_native_frames_per_second, ARG_backlight_on_high }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -132,6 +133,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_data_as_commands, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, { MP_QSTR_native_frames_per_second, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60} }, + { MP_QSTR_backlight_on_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -178,7 +180,8 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a args[ARG_single_byte_bounds].u_bool, args[ARG_data_as_commands].u_bool, args[ARG_auto_refresh].u_bool, - args[ARG_native_frames_per_second].u_int + args[ARG_native_frames_per_second].u_int, + args[ARG_backlight_on_high].u_bool ); return self; diff --git a/shared-bindings/displayio/Display.h b/shared-bindings/displayio/Display.h index b82a68ebe9..8c2e20262b 100644 --- a/shared-bindings/displayio/Display.h +++ b/shared-bindings/displayio/Display.h @@ -45,7 +45,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command, mp_float_t brightness, bool auto_brightness, - bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second); + bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high); bool common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group); diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 299c8ad359..820fbcce62 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -50,7 +50,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, uint8_t set_row_command, uint8_t write_ram_command, uint8_t set_vertical_scroll, uint8_t* init_sequence, uint16_t init_sequence_len, const mcu_pin_obj_t* backlight_pin, uint16_t brightness_command, mp_float_t brightness, bool auto_brightness, - bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second) { + bool single_byte_bounds, bool data_as_commands, bool auto_refresh, uint16_t native_frames_per_second, bool backlight_on_high) { // Turn off auto-refresh as we init. self->auto_refresh = false; uint16_t ram_width = 0x100; @@ -159,6 +159,9 @@ mp_float_t common_hal_displayio_display_get_brightness(displayio_display_obj_t* bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, mp_float_t brightness) { self->updating_backlight = true; + if (!self->backlight_on_high){ + brightness = 1.0-brightness; + } bool ok = false; if (self->backlight_pwm.base.type == &pulseio_pwmout_type) { common_hal_pulseio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t) (0xffff * brightness)); diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index e5fe0a7088..8adaf597f9 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -55,6 +55,7 @@ typedef struct { bool data_as_commands; bool auto_brightness; bool updating_backlight; + bool backlight_on_high; } displayio_display_obj_t; void displayio_display_background(displayio_display_obj_t* self);