8000 framebufferio: get width, etc., from protocol, not object property · domdfcoding/circuitpython@57ce2d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 57ce2d1

Browse files
committed
framebufferio: get width, etc., from protocol, not object property
1 parent 3d6258f commit 57ce2d1

File tree

5 files changed

+62
-29
lines changed

5 files changed

+62
-29
lines changed

shared-bindings/framebufferio/FramebufferDisplay.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
#include "shared-module/displayio/__init__.h"
4040
#include "supervisor/shared/translate.h"
4141

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-
4642
//| .. currentmodule:: framebufferio
4743
//|
4844
//| :class:`FramebufferDisplay` -- Manage updating a display with framebuffer in RAM
@@ -79,25 +75,14 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *t
7975
mp_raise_ValueError(translate("Display rotation must be in 90 degree increments"));
8076
}
8177

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-
8878
primary_display_t *disp = allocate_display_or_raise();
8979
framebufferio_framebufferdisplay_obj_t *self = &disp->framebuffer_display;
9080
self->base.type = &framebufferio_framebufferdisplay_type;
9181
common_hal_framebufferio_framebufferdisplay_construct(
9282
self,
9383
framebuffer,
94-
width,
95-
height,
9684
rotation,
97-
color_depth,
98-
bytes_per_cell,
99-
args[ARG_auto_refresh].u_bool,
100-
native_frames_per_second
85+
args[ARG_auto_refresh].u_bool
10186
);
10287

10388
return self;

shared-bindings/framebufferio/FramebufferDisplay.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ extern const mp_obj_type_t framebufferio_framebufferdisplay_type;
3939
#define NO_BRIGHTNESS_COMMAND 0x100
4040

4141
void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t* self,
42-
mp_obj_t framebuffer, uint16_t width, uint16_t height,
43-
uint16_t rotation, uint16_t color_depth,
44-
uint8_t bytes_per_cell,
45-
bool auto_refresh, uint16_t native_frames_per_second);
42+
mp_obj_t framebuffer,
43+
uint16_t rotation,
44+
bool auto_refresh);
4645

4746
bool common_hal_framebufferio_framebufferdisplay_show(framebufferio_framebufferdisplay_obj_t* self,
4847
displayio_group_t* root_group);

shared-bindings/rgbmatrix/RGBMatrix.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,37 @@ STATIC bool protomatter_protomatter_set_brightness_proto(mp_obj_t self_in, mp_fl
443443
return true;
444444
}
445445

446+
STATIC int protomatter_protomatter_get_width_proto(mp_obj_t self_in) {
447+
return common_hal_protomatter_protomatter_get_width(self_in);
448+
}
449+
450+
STATIC int protomatter_protomatter_get_height_proto(mp_obj_t self_in) {
451+
return common_hal_protomatter_protomatter_get_height(self_in);
452+
}
453+
454+
STATIC int protomatter_protomatter_get_color_depth_proto(mp_obj_t self_in) {
455+
return 16;
456+
}
457+
458+
STATIC int protomatter_protomatter_get_bytes_per_cell_proto(mp_obj_t self_in) {
459+
return 1;
460+
}
461+
462+
STATIC int protomatter_protomatter_get_native_frames_per_second_proto(mp_obj_t self_in) {
463+
return 250;
464+
}
465+
466+
446467
STATIC const framebuffer_p_t protomatter_protomatter_proto = {
447468
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuffer)
448469
.get_bufinfo = protomatter_protomatter_get_bufinfo,
449470
.set_brightness = protomatter_protomatter_set_brightness_proto,
450471
.get_brightness = protomatter_protomatter_get_brightness_proto,
472+
.get_width = protomatter_protomatter_get_width_proto,
473+
.get_height = protomatter_protomatter_get_height_proto,
474+
.get_color_depth = protomatter_protomatter_get_color_depth_proto,
475+
.get_bytes_per_cell = protomatter_protomatter_get_bytes_per_cell_proto,
476+
.get_native_frames_per_second = protomatter_protomatter_get_native_frames_per_second_proto,
451477
.swapbuffers = protomatter_protomatter_swapbuffers,
452478
.deinit = protomatter_protomatter_deinit_proto,
453479
};

shared-module/framebufferio/FramebufferDisplay.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@
4242
#include "tick.h"
4343

4444
void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t* self,
45-
mp_obj_t framebuffer, uint16_t width, uint16_t height,
46-
uint16_t rotation, uint16_t color_depth,
47-
uint8_t bytes_per_cell,
48-
bool auto_refresh, uint16_t native_frames_per_second) {
45+
mp_obj_t framebuffer,
46+
uint16_t rotation,
47+
bool auto_refresh) {
4948
// Turn off auto-refresh as we init.
5049
self->auto_refresh = false;
5150
self->framebuffer = framebuffer;
@@ -54,15 +53,29 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
5453
uint16_t ram_width = 0x100;
5554
uint16_t ram_height = 0x100;
5655

57-
displayio_display_core_construct(&self->core, NULL, width, height, ram_width, ram_height, 0, 0, rotation,
58-
color_depth, false, false, bytes_per_cell, false, false);
56+
displayio_display_core_construct(
57+
&self->core,
58+
NULL,
59+
self->framebuffer_protocol->get_width(self->framebuffer),
60+
self->framebuffer_protocol->get_height(self->framebuffer),
61+
ram_width,
62+
ram_height,
63+
0,
64+
0,
65+
rotation,
66+
self->framebuffer_protocol->get_color_depth(self->framebuffer),
67+
false,
68+
false,
69+
self->framebuffer_protocol->get_bytes_per_cell(self->framebuffer),
70+
false,
71+
false);
5972

6073
self->first_manual_refresh = !auto_refresh;
6174

62-
self->native_frames_per_second = native_frames_per_second;
63-
self->native_ms_per_frame = 1000 / native_frames_per_second;
75+
self->native_frames_per_second = self->framebuffer_protocol->get_native_frames_per_second(self->framebuffer);
76+
self->native_ms_per_frame = 1000 / self->native_frames_per_second;
6477

65-
supervisor_start_terminal(width, height);
78+
supervisor_start_terminal(self->core.width, self->core.height);
6679

6780
// Set the group after initialization otherwise we may send pixels while we delay in
6881
// initialization.

shared-module/framebufferio/FramebufferDisplay.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,22 @@ typedef bool (*framebuffer_set_brightness_fun)(mp_obj_t, mp_float_t);
6666
typedef mp_float_t (*framebuffer_get_brightness_fun)(mp_obj_t);
6767
typedef bool (*framebuffer_set_auto_brightness_fun)(mp_obj_t, bool);
6868
typedef bool (*framebuffer_get_auto_brightness_fun)(mp_obj_t);
69+
typedef int (*framebuffer_get_width_fun)(mp_obj_t);
70+
typedef int (*framebuffer_get_height_fun)(mp_obj_t);
71+
typedef int (*framebuffer_get_color_depth_fun)(mp_obj_t);
72+
typedef int (*framebuffer_get_bytes_per_cell_fun)(mp_obj_t);
73+
typedef int (*framebuffer_get_native_frames_per_second_fun)(mp_obj_t);
6974

7075
typedef struct _framebuffer_p_t {
7176
MP_PROTOCOL_HEAD // MP_QSTR_protocol_framebuffer
7277
framebuffer_get_bufinfo_fun get_bufinfo;
7378
framebuffer_swapbuffers_fun swapbuffers;
7479
framebuffer_deinit_fun deinit;
80+
framebuffer_get_width_fun get_width;
81+
framebuffer_get_height_fun get_height;
82+
framebuffer_get_color_depth_fun get_color_depth;
83+
framebuffer_get_bytes_per_cell_fun get_bytes_per_cell;
84+
framebuffer_get_native_frames_per_second_fun get_native_frames_per_second;
7585
framebuffer_get_brightness_fun get_brightness;
7686
framebuffer_set_brightness_fun set_brightness;
7787
framebuffer_get_auto_brightness_fun get_auto_brightness;

0 commit comments

Comments
 (0)
0