diff options
| author | Jeff Epler <jepler@gmail.com> | 2020-04-15 09:13:02 -0500 |
|---|---|---|
| committer | Jeff Epler <jepler@gmail.com> | 2020-04-17 18:43:57 -0500 |
| commit | d1ff23e0046a6462d4939b4b8c79f10182fabf9d (patch) | |
| tree | a75f345a90e01927d32e10041334513c06f7c698 /shared-bindings/framebufferio/FramebufferDisplay.c | |
| parent | d2aac7a754b748c48250c4d53de2d5601bd761ab (diff) | |
framebufferio: get width, height from framebuffer properties
Diffstat (limited to 'shared-bindings/framebufferio/FramebufferDisplay.c')
| -rw-r--r-- | shared-bindings/framebufferio/FramebufferDisplay.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index aa8fc1a63..cccbc423c 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -39,6 +39,10 @@ #include "shared-module/displayio/__init__.h" #include "supervisor/shared/translate.h" +STATIC int get_int_property(mp_obj_t obj, qstr attr) { + return mp_obj_get_int(mp_load_attr(obj, attr)); +} + //| .. currentmodule:: framebufferio //| //| :class:`FramebufferDisplay` -- Manage updating a display with framebuffer in RAM @@ -70,8 +74,8 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *t enum { ARG_framebuffer, ARG_width, ARG_height, ARG_rotation, ARG_color_depth, ARG_bytes_per_cell, ARG_auto_refresh, ARG_native_frames_per_second, NUM_ARGS }; static const mp_arg_t allowed_args[] = { { MP_QSTR_framebuffer, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, }, - { MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED, }, + { MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, + { MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_rotation, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, { MP_QSTR_color_depth, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} }, { MP_QSTR_bytes_per_cell, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} }, @@ -84,6 +88,14 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *t mp_obj_t framebuffer = args[ARG_framebuffer].u_obj; + if (args[ARG_width].u_int == 0) { + args[ARG_width].u_int = get_int_property(framebuffer, MP_QSTR_width); + } + + if (args[ARG_height].u_int == 0) { + args[ARG_height].u_int = get_int_property(framebuffer, MP_QSTR_height); + } + mp_int_t rotation = args[ARG_rotation].u_int; if (rotation % 90 != 0) { mp_raise_ValueError(translate("Display rotation must be in 90 degree increments")); |
