39
39
#include "shared-module/displayio/__init__.h"
40
40
#include "supervisor/shared/translate.h"
41
41
42
+ STATIC int get_int_property (mp_obj_t obj , qstr attr ) {
43
+ return mp_obj_get_int (mp_load_attr (obj , attr ));
44
+ }
45
+
42
46
//| .. currentmodule:: framebufferio
43
47
//|
44
48
//| :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
70
74
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 };
71
75
static const mp_arg_t allowed_args [] = {
72
76
{ MP_QSTR_framebuffer , MP_ARG_REQUIRED | MP_ARG_OBJ },
73
- { MP_QSTR_width , MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED , },
74
- { MP_QSTR_height , MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED , },
77
+ { MP_QSTR_width , MP_ARG_INT | MP_ARG_KW_ONLY , {. u_int = 0 } },
78
+ { MP_QSTR_height , MP_ARG_INT | MP_ARG_KW_ONLY , {. u_int = 0 } },
75
79
{ MP_QSTR_rotation , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 0 } },
76
80
{ MP_QSTR_color_depth , MP_ARG_INT | MP_ARG_KW_ONLY , {.u_int = 16 } },
77
81
{ 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
84
88
85
89
mp_obj_t framebuffer = args [ARG_framebuffer ].u_obj ;
86
90
91
+ if (args [ARG_width ].u_int == 0 ) {
92
+ args [ARG_width ].u_int = get_int_property (framebuffer , MP_QSTR_width );
93
+ }
94
+
95
+ if (args [ARG_height ].u_int == 0 ) {
96
+ args [ARG_height ].u_int = get_int_property (framebuffer , MP_QSTR_height );
97
+ }
98
+
87
99
mp_int_t rotation = args [ARG_rotation ].u_int ;
88
100
if (rotation % 90 != 0 ) {
89
101
mp_raise_ValueError (translate ("Display rotation must be in 90 degree increments" ));
0 commit comments