Skip to content

Commit

Permalink
Tweak pybadge and fix display bugs
Browse files Browse the repository at this point in the history
* Update pybadge pins and flash for rev D
* TileGrid now validates the type of the pixel_shader.
* Display actually handles incoming subclass objects.
* MicroPython will inspect native parents to see if special
  accessors are used.
  • Loading branch information
tannewt committed Apr 10, 2019
1 parent 9026f13 commit 5028f87
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 45 deletions.
2 changes: 1 addition & 1 deletion locale/ID.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions locale/de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion locale/en_US.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion locale/en_x_pirate.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions locale/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions locale/fil.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions locale/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions locale/it_IT.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions locale/pl.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion locale/pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/pybadge/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/pybadge/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 22 additions & 14 deletions py/objtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
26 changes: 16 additions & 10 deletions shared-bindings/displayio/Display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -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));

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions shared-bindings/displayio/TileGrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down

0 comments on commit 5028f87

Please sign in to comment.