8000 framebufferio: get more properties direct from underlying framebuffer · domdfcoding/circuitpython@1a91a75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1a91a75

Browse files
committed
framebufferio: get more properties direct from underlying framebuffer
1 parent a323377 commit 1a91a75

File tree

2 files changed

+72
-29
lines changed

2 files changed

+72
-29
lines changed

shared-bindings/framebufferio/FramebufferDisplay.c

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,67 +52,52 @@ STATIC int get_int_property(mp_obj_t obj, qstr attr) {
5252
//| objects in CircuitPython, Display objects live until `displayio.release_displays()`
5353
//| is called. This is done so that CircuitPython can use the display itself.
5454
//|
55-
//| .. class:: FramebufferDisplay(framebuffer, *, width, height, colstart=0, rowstart=0, rotation=0, color_depth=16, grayscale=False, pixels_in_byte_share_row=True, bytes_per_cell=1, reverse_pixels_in_byte=False, backlight_pin=None, brightness=1.0, auto_brightness=False, auto_refresh=True, native_frames_per_second=60)
55+
//| .. class:: FramebufferDisplay(framebuffer, *, rotation=0, auto_refresh=True)
5656
//|
5757
//| Create a Display object with the given framebuffer (a buffer, array, ulab.array, etc)
5858
//|
5959
//| :param framebuffer: The framebuffer that the display is connected to
6060
//| :type framebuffer: any core object implementing the framebuffer protocol
61-
//| :param int width: Width in pixels
62-
//| :param int height: Height in pixels
63-
//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)
64-
//| :param int color_depth: The number of bits of color per pixel transmitted. (Some displays
65-
//| support 18 bit but 16 is easier to transmit. The last bit is extrapolated.)
66-
//| :param int bytes_per_cell: Number of bytes per addressable memory location when color_depth < 8. When greater than one, bytes share a row or column according to pixels_in_byte_share_row.
67-
//| :param microcontroller.Pin backlight_pin: Pin connected to the display's backlight
68-
//| :param bool brightness: Initial display brightness. This value is ignored if auto_brightness is True.
69-
//| :param bool auto_brightness: If True, brightness is controlled via an ambient light sensor or other mechanism.
7061
//| :param bool auto_refresh: Automatically refresh the screen
71-
//| :param int native_frames_per_second: Number of display refreshes per second
62+
//| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)
7263
//|
7364
STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
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 };
65+
enum { ARG_framebuffer, ARG_rotation, ARG_auto_refresh, NUM_ARGS };
7566
static const mp_arg_t allowed_args[] = {
7667
{ MP_QSTR_framebuffer, MP_ARG_REQUIRED | MP_ARG_OBJ },
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} },
7968
{ MP_QSTR_rotation, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
80-
{ MP_QSTR_color_depth, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} },
81-
{ MP_QSTR_bytes_per_cell, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} },
8269
{ MP_QSTR_auto_refresh, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = true} },
83-
{ MP_QSTR_native_frames_per_second, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 60} },
8470
};
8571
MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS );
8672
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
8773
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
8874

8975
mp_obj_t framebuffer = args[ARG_framebuffer].u_obj;
9076

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-
9977
mp_int_t rotation = args[ARG_rotation].u_int;
10078
if (rotation % 90 != 0) {
10179
mp_raise_ValueError(translate("Display rotation must be in 90 degree increments"));
10280
}
10381

82+
int width = get_int_property(framebuffer, MP_QSTR_width);
83+
int height = get_int_property(framebuffer, MP_QSTR_height);
84+
int color_depth = get_int_property(framebuffer, MP_QSTR_color_depth);
85+
int bytes_per_cell = get_int_property(framebuffer, MP_QSTR_bytes_per_cell);
86+
int native_frames_per_second = get_int_property(framebuffer, MP_QSTR_native_frames_per_second);
87+
10488
primary_display_t *disp = allocate_display_or_raise();
10589
framebufferio_framebufferdisplay_obj_t *self = &disp->framebuffer_display;
10690
self->base.type = &framebufferio_framebufferdisplay_type;
10791
common_hal_framebufferio_framebufferdisplay_construct(
10892
self,
10993
framebuffer,
110-
args[ARG_width].u_int, args[ARG_height].u_int,
94+
width,
95+
height,
11196
rotation,
112-
args[ARG_color_depth].u_int,
113-
args[ARG_bytes_per_cell].u_int,
97+
color_depth,
98+
bytes_per_cell,
11499
args[ARG_auto_refresh].u_bool,
115-
args[ARG_native_frames_per_second].u_int
100+
native_frames_per_second
116101
);
117102

118103
return self;

shared-bindings/protomatter/Protomatter.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,71 @@ const mp_obj_property_t protomatter_protomatter_height_obj = {
350350
(mp_obj_t)&mp_const_none_obj},
351351
};
352352

353+
//| .. attribute:: bytes_per_cell
354+
//|
355+
//| The bytes_per_cell of the display, in pixels. Always equal to 1.
356+
//|
357+
STATIC mp_obj_t protomatter_protomatter_get_bytes_per_cell(mp_obj_t self_in) {
358+
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
359+
check_for_deinit(self);
360+
return MP_OBJ_NEW_SMALL_INT(1);
361+
}
362+
MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_get_bytes_per_cell_obj, protomatter_protomatter_get_bytes_per_cell);
363+
364+
const mp_obj_property_t protomatter_protomatter_bytes_per_cell_obj = {
365+
.base.type = &mp_type_property,
366+
.proxy = {(mp_obj_t)&protomatter_protomatter_get_bytes_per_cell_obj,
367+
(mp_obj_t)&mp_const_none_obj,
368+
(mp_obj_t)&mp_const_none_obj},
369+
};
370+
371+
//| .. attribute:: color_depth
372+
//|
373+
//| The color_depth of the framebuffer, in bits. Always equal to 16. This
374+
//| is different than the constructor's "bit_depth".
375+
//|
376+
STATIC mp_obj_t protomatter_protomatter_get_color_depth(mp_obj_t self_in) {
377+
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
378+
check_for_deinit(self);
379+
return MP_OBJ_NEW_SMALL_INT(16);
380+
}
381+
MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_get_color_depth_obj, protomatter_protomatter_get_color_depth);
382+
383+
const mp_obj_property_t protomatter_protomatter_color_depth_obj = {
384+
.base.type = &mp_type_property,
385+
.proxy = {(mp_obj_t)&protomatter_protomatter_get_color_depth_obj,
386+
(mp_obj_t)&mp_const_none_obj,
387+
(mp_obj_t)&mp_const_none_obj},
388+
};
389+
390+
//| .. attribute:: native_frames_per_second
391+
//|
392+
//| The native_frames_per_second of the display. Always equal to 250.
393+
//|
394+
STATIC mp_obj_t protomatter_protomatter_get_native_frames_per_second(mp_obj_t self_in) {
395+
protomatter_protomatter_obj_t *self = (protomatter_protomatter_obj_t*)self_in;
396+
check_for_deinit(self);
397+
return MP_OBJ_NEW_SMALL_INT(250);
398+
}
399+
MP_DEFINE_CONST_FUN_OBJ_1(protomatter_protomatter_get_native_frames_per_second_obj, protomatter_protomatter_get_native_frames_per_second);
400+
401+
const mp_obj_property_t protomatter_protomatter_native_frames_per_second_obj = {
402+
.base.type = &mp_type_property,
403+
.proxy = {(mp_obj_t)&protomatter_protomatter_get_native_frames_per_second_obj,
404+
(mp_obj_t)&mp_const_none_obj,
405+
(mp_obj_t)&mp_const_none_obj},
406+
};
407+
353408

354409
STATIC const mp_rom_map_elem_t protomatter_protomatter_locals_dict_table[] = {
355410
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&protomatter_protomatter_deinit_obj) },
356411
{ MP_ROM_QSTR(MP_QSTR_brightness), MP_ROM_PTR(&protomatter_protomatter_brightness_obj) },
357412
{ MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&protomatter_protomatter_refresh_obj) },
358413
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&protomatter_protomatter_width_obj) },
359414
{ MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&protomatter_protomatter_height_obj) },
415+
{ MP_ROM_QSTR(MP_QSTR_color_depth), MP_ROM_PTR(&protomatter_protomatter_color_depth_obj) },
416+
{ MP_ROM_QSTR(MP_QSTR_bytes_per_cell), MP_ROM_PTR(&protomatter_protomatter_bytes_per_cell_obj) },
417+
{ MP_ROM_QSTR(MP_QSTR_native_frames_per_second), MP_ROM_PTR(&protomatter_protomatter_native_frames_per_second_obj) },
360418
};
361419
STATIC MP_DEFINE_CONST_DICT(protomatter_protomatter_locals_dict, protomatter_protomatter_locals_dict_table);
362420

0 commit comments

Comments
 (0)
0