diff --git a/locale/ID.po b/locale/ID.po index 2e01bfe9a767..949eddc4bf9b 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -2575,7 +2575,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index e38aa77279d2..3416ef0f3141 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -2528,7 +2528,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/locale/de_DE.po b/locale/de_DE.po index ae76bc76c871..8bb5ce370b6a 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -2584,8 +2584,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "Nicht unterstützter Bitmap-Typ" +msgid "unsupported %q type" +msgstr "Nicht unterstützter %q-Typ" #: py/objstr.c #, c-format diff --git a/locale/en_US.po b/locale/en_US.po index fb62ea2b03dd..79f4ab06deee 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -2528,7 +2528,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 24af776c0332..db068589bd58 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -2532,7 +2532,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/locale/es.po b/locale/es.po index 661c591d31b6..0592af24223b 100644 --- a/locale/es.po +++ b/locale/es.po @@ -2614,8 +2614,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "instrucción Xtensa '%s' con %d argumentos no soportada" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "tipo de bitmap no soportado" +msgid "unsupported %q type" +msgstr "tipo de %q no soportado" #: py/objstr.c #, c-format diff --git a/locale/fil.po b/locale/fil.po index 7873ec6853f8..b34e7bb1b282 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -2616,8 +2616,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "hindi sinusuportahan ang instruction ng Xtensa '%s' sa %d argumento" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "Hindi supportadong tipo ng bitmap" +msgid "unsupported %q type" +msgstr "Hindi supportadong tipo ng %q" #: py/objstr.c #, c-format diff --git a/locale/fr.po b/locale/fr.po index 9c723333d64a..df3af424e6d0 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -2638,8 +2638,8 @@ msgstr "instruction Xtensa '%s' non supportée avec %d arguments" #: shared-bindings/displayio/TileGrid.c #, fuzzy -msgid "unsupported bitmap type" -msgstr "type de bitmap non supporté" +msgid "unsupported %q type" +msgstr "type de %q non supporté" #: py/objstr.c #, c-format diff --git a/locale/it_IT.po b/locale/it_IT.po index c14b3698badb..7714530f643d 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -2614,8 +2614,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "istruzione '%s' Xtensa non supportata con %d argomenti" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "tipo di bitmap non supportato" +msgid "unsupported %q type" +msgstr "tipo di %q non supportato" #: py/objstr.c #, c-format diff --git a/locale/pl.po b/locale/pl.po index 1b861fff0fab..888103fd3eb9 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -2561,8 +2561,8 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "niewspierana instrukcja Xtensa '%s' z %d argumentami" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" -msgstr "niewspierany typ bitmapy" +msgid "unsupported %q type" +msgstr "niewspierany typ %q" #: py/objstr.c #, c-format diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 4685e9c82a6e..047b654b48af 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -2565,7 +2565,7 @@ msgid "unsupported Xtensa instruction '%s' with %d arguments" msgstr "" #: shared-bindings/displayio/TileGrid.c -msgid "unsupported bitmap type" +msgid "unsupported %q type" msgstr "" #: py/objstr.c diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index f234db8caf65..ba18a28966de 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -71,7 +71,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB12, NULL); + common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL); common_hal_busio_spi_never_reset(spi); displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; diff --git a/ports/atmel-samd/boards/pybadge/mpconfigboard.mk b/ports/atmel-samd/boards/pybadge/mpconfigboard.mk index 8ab759865607..8828c17b270a 100644 --- a/ports/atmel-samd/boards/pybadge/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pybadge/mpconfigboard.mk @@ -6,7 +6,7 @@ USB_MANUFACTURER = "Adafruit Industries LLC" QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICE_COUNT = 1 -EXTERNAL_FLASH_DEVICES = GD25Q64C +EXTERNAL_FLASH_DEVICES = GD25Q16C LONGINT_IMPL = MPZ # No I2S on SAMD51G diff --git a/py/objtype.c b/py/objtype.c index f205c224e65c..4dec478e9601 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -964,6 +964,18 @@ STATIC bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) { #endif return false; } + +STATIC bool map_has_special_accessors(const mp_map_t *map) { + for (size_t i = 0; i < map->alloc; i++) { + if (MP_MAP_SLOT_IS_FILLED(map, i)) { + const mp_map_elem_t *elem = &map->table[i]; + if (check_for_special_accessors(elem->key, elem->value)) { + return true; + } + } + } + return false; +} #endif STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { @@ -1158,20 +1170,6 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) o->locals_dict = make_dict_long_lived(locals_dict, 10); - #if ENABLE_SPECIAL_ACCESSORS - // Check if the class has any special accessor methods - if (!(o->flags & TYPE_FLAG_HAS_SPECIAL_ACCESSORS)) { - for (size_t i = 0; i < o->locals_dict->map.alloc; i++) { - if (MP_MAP_SLOT_IS_FILLED(&o->locals_dict->map, i)) { - const mp_map_elem_t *elem = &o->locals_dict->map.table[i]; - if (check_for_special_accessors(elem->key, elem->value)) { - o->flags |= TYPE_FLAG_HAS_SPECIAL_ACCESSORS; - break; - } - } - } - } - #endif const mp_obj_type_t *native_base; size_t num_native_bases = instance_count_native_bases(o, &native_base); @@ -1180,6 +1178,16 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) } mp_map_t *locals_map = &o->locals_dict->map; + #if ENABLE_SPECIAL_ACCESSORS + // Check if the class has any special accessor methods + if (!(o->flags & TYPE_FLAG_HAS_SPECIAL_ACCESSORS) && + (map_has_special_accessors(locals_map) || + (num_native_bases == 1 && + map_has_special_accessors(&native_base->locals_dict->map)))) { + o->flags |= TYPE_FLAG_HAS_SPECIAL_ACCESSORS; + } + #endif + mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(MP_QSTR___new__), MP_MAP_LOOKUP); if (elem != NULL) { // __new__ slot exists; check if it is a function diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index c4f65704f700..17f275bc0736 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -157,13 +157,19 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a return self; } +// Helper to ensure we have the native super class instead of a subclass. +static displayio_display_obj_t* native_display(mp_obj_t display_obj) { + mp_obj_t native_display = mp_instance_cast_to_native_base(display_obj, &displayio_display_type); + return MP_OBJ_TO_PTR(native_display); +} + //| .. method:: show(group) //| //| Switches to displaying the given group of layers. When group is None, the default //| CircuitPython terminal will be shown. //| STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); displayio_group_t* group = NULL; if (group_in != mp_const_none) { mp_obj_t native_layer = mp_instance_cast_to_native_base(group_in, &displayio_group_type); @@ -183,7 +189,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show //| Queues up a display refresh that happens in the background. //| STATIC mp_obj_t displayio_display_obj_refresh_soon(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); common_hal_displayio_display_refresh_soon(self); return mp_const_none; } @@ -195,7 +201,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_refresh_soon_obj, displayio_display_ //| behind the rendered frames. In that case, this will return immediately with the wait count. //| STATIC mp_obj_t displayio_display_obj_wait_for_frame(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_wait_for_frame(self)); } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_wait_for_frame_obj, displayio_display_obj_wait_for_frame); @@ -207,7 +213,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_wait_for_frame_obj, displayio_displa //| effect. To control the brightness, auto_brightness must be false. //| STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); mp_float_t brightness = common_hal_displayio_display_get_brightness(self); if (brightness < 0) { mp_raise_RuntimeError(translate("Brightness not adjustable")); @@ -217,7 +223,7 @@ STATIC mp_obj_t displayio_display_obj_get_brightness(mp_obj_t self_in) { MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_brightness_obj, displayio_display_obj_get_brightness); STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t brightness) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); bool ok = common_hal_displayio_display_set_brightness(self, mp_obj_get_float(brightness)); if (!ok) { mp_raise_RuntimeError(translate("Brightness not adjustable")); @@ -238,13 +244,13 @@ const mp_obj_property_t displayio_display_brightness_obj = { //| True when the display brightness is auto adjusted. //| STATIC mp_obj_t displayio_display_obj_get_auto_brightness(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return mp_obj_new_bool(common_hal_displayio_display_get_auto_brightness(self)); } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_auto_brightness_obj, displayio_display_obj_get_auto_brightness); STATIC mp_obj_t displayio_display_obj_set_auto_brightness(mp_obj_t self_in, mp_obj_t auto_brightness) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); common_hal_displayio_display_set_auto_brightness(self, mp_obj_is_true(auto_brightness)); @@ -265,7 +271,7 @@ const mp_obj_property_t displayio_display_auto_brightness_obj = { //| //| STATIC mp_obj_t displayio_display_obj_get_width(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_width(self)); } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_width_obj, displayio_display_obj_get_width); @@ -283,7 +289,7 @@ const mp_obj_property_t displayio_display_width_obj = { //| //| STATIC mp_obj_t displayio_display_obj_get_height(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_height(self)); } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_height_obj, displayio_display_obj_get_height); @@ -301,7 +307,7 @@ const mp_obj_property_t displayio_display_height_obj = { //| //| STATIC mp_obj_t displayio_display_obj_get_bus(mp_obj_t self_in) { - displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in); + displayio_display_obj_t *self = native_display(self_in); return self->bus; } MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_get_bus_obj, displayio_display_obj_get_bus); diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 7c2c0d4ccc9d..2b41eb8fd5e9 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -103,7 +103,12 @@ STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_ bitmap_width = bmp->width; bitmap_height = bmp->height; } else { - mp_raise_TypeError(translate("unsupported bitmap type")); + mp_raise_TypeError_varg(translate("unsupported %q type"), MP_QSTR_bitmap); + } + mp_obj_t pixel_shader = args[ARG_pixel_shader].u_obj; + if (!MP_OBJ_IS_TYPE(pixel_shader, &displayio_colorconverter_type) && + !MP_OBJ_IS_TYPE(pixel_shader, &displayio_palette_type)) { + mp_raise_TypeError_varg(translate("unsupported %q type"), MP_QSTR_pixel_shader); } uint16_t tile_width = args[ARG_tile_width].u_int; if (tile_width == 0) { @@ -126,7 +131,7 @@ STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_ displayio_tilegrid_t *self = m_new_obj(displayio_tilegrid_t); self->base.type = &displayio_tilegrid_type; common_hal_displayio_tilegrid_construct(self, native, bitmap_width / tile_width, - args[ARG_pixel_shader].u_obj, args[ARG_width].u_int, args[ARG_height].u_int, + pixel_shader, args[ARG_width].u_int, args[ARG_height].u_int, tile_width, tile_height, x, y, args[ARG_default_tile].u_int); return MP_OBJ_FROM_PTR(self); }