framebufferio: get width, etc., from protocol, not object property
This commit is contained in:
parent
3d6258f63d
commit
57ce2d1f41
|
@ -39,10 +39,6 @@
|
|||
#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
|
||||
|
@ -79,25 +75,14 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *t
|
|||
mp_raise_ValueError(translate("Display rotation must be in 90 degree increments"));
|
||||
}
|
||||
|
||||
int width = get_int_property(framebuffer, MP_QSTR_width);
|
||||
int height = get_int_property(framebuffer, MP_QSTR_height);
|
||||
int color_depth = get_int_property(framebuffer, MP_QSTR_color_depth);
|
||||
int bytes_per_cell = get_int_property(framebuffer, MP_QSTR_bytes_per_cell);
|
||||
int native_frames_per_second = get_int_property(framebuffer, MP_QSTR_native_frames_per_second);
|
||||
|
||||
primary_display_t *disp = allocate_display_or_raise();
|
||||
framebufferio_framebufferdisplay_obj_t *self = &disp->framebuffer_display;
|
||||
self->base.type = &framebufferio_framebufferdisplay_type;
|
||||
common_hal_framebufferio_framebufferdisplay_construct(
|
||||
self,
|
||||
framebuffer,
|
||||
width,
|
||||
height,
|
||||
rotation,
|
||||
color_depth,
|
||||
bytes_per_cell,
|
||||
args[ARG_auto_refresh].u_bool,
|
||||
native_frames_per_second
|
||||
args[ARG_auto_refresh].u_bool
|
||||
);
|
||||
|
||||
return self;
|
||||
|
|
|
@ -39,10 +39,9 @@ extern const mp_obj_type_t framebufferio_framebufferdisplay_type;
|
|||
#define NO_BRIGHTNESS_COMMAND 0x100
|
||||
|
||||
void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t* self,
|
||||
mp_obj_t framebuffer, uint16_t width, uint16_t height,
|
||||
uint16_t rotation, uint16_t color_depth,
|
||||
uint8_t bytes_per_cell,
|
||||
bool auto_refresh, uint16_t native_frames_per_second);
|
||||
mp_obj_t framebuffer,
|
||||
uint16_t rotation,
|
||||
bool auto_refresh);
|
||||
|
||||
bool common_hal_framebufferio_framebufferdisplay_show(framebufferio_framebufferdisplay_obj_t* self,
|
||||
displayio_group_t* root_group);
|
||||
|
|
|
@ -443,11 +443,37 @@ STATIC bool protomatter_protomatter_set_brightness_proto(mp_obj_t self_in, mp_fl
|
|||
return true;
|
||||
}
|
||||
|
||||
STATIC int protomatter_protomatter_get_width_proto(mp_obj_t self_in) {
|
||||
return common_hal_protomatter_protomatter_get_width(self_in);
|
||||
}
|
||||
|
||||
STATIC int protomatter_protomatter_get_height_proto(mp_obj_t self_in) {
|
||||
return common_hal_protomatter_protomatter_get_height(self_in);
|
||||
}
|
||||
|
||||
STATIC int protomatter_protomatter_get_color_depth_proto(mp_obj_t self_in) {
|
||||
return 16;
|
||||
}
|
||||
|
||||
STATIC int protomatter_protomatter_get_bytes_per_cell_proto(mp_obj_t self_in) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
STATIC int protomatter_protomatter_get_native_frames_per_second_proto(mp_obj_t self_in) {
|
||||
return 250;
|
||||
}
|
||||
|
||||
|
||||
STATIC const framebuffer_p_t protomatter_protomatter_proto = {
|
||||
MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuffer)
|
||||
.get_bufinfo = protomatter_protomatter_get_bufinfo,
|
||||
.set_brightness = protomatter_protomatter_set_brightness_proto,
|
||||
.get_brightness = protomatter_protomatter_get_brightness_proto,
|
||||
.get_width = protomatter_protomatter_get_width_proto,
|
||||
.get_height = protomatter_protomatter_get_height_proto,
|
||||
.get_color_depth = protomatter_protomatter_get_color_depth_proto,
|
||||
.get_bytes_per_cell = protomatter_protomatter_get_bytes_per_cell_proto,
|
||||
.get_native_frames_per_second = protomatter_protomatter_get_native_frames_per_second_proto,
|
||||
.swapbuffers = protomatter_protomatter_swapbuffers,
|
||||
.deinit = protomatter_protomatter_deinit_proto,
|
||||
};
|
||||
|
|
|
@ -42,10 +42,9 @@
|
|||
#include "tick.h"
|
||||
|
||||
void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t* self,
|
||||
mp_obj_t framebuffer, uint16_t width, uint16_t height,
|
||||
uint16_t rotation, uint16_t color_depth,
|
||||
uint8_t bytes_per_cell,
|
||||
bool auto_refresh, uint16_t native_frames_per_second) {
|
||||
mp_obj_t framebuffer,
|
||||
uint16_t rotation,
|
||||
bool auto_refresh) {
|
||||
// Turn off auto-refresh as we init.
|
||||
self->auto_refresh = false;
|
||||
self->framebuffer = framebuffer;
|
||||
|
@ -54,15 +53,29 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
|
|||
uint16_t ram_width = 0x100;
|
||||
uint16_t ram_height = 0x100;
|
||||
|
||||
displayio_display_core_construct(&self->core, NULL, width, height, ram_width, ram_height, 0, 0, rotation,
|
||||
color_depth, false, false, bytes_per_cell, false, false);
|
||||
displayio_display_core_construct(
|
||||
&self->core,
|
||||
NULL,
|
||||
self->framebuffer_protocol->get_width(self->framebuffer),
|
||||
self->framebuffer_protocol->get_height(self->framebuffer),
|
||||
ram_width,
|
||||
ram_height,
|
||||
0,
|
||||
0,
|
||||
rotation,
|
||||
self->framebuffer_protocol->get_color_depth(self->framebuffer),
|
||||
false,
|
||||
false,
|
||||
self->framebuffer_protocol->get_bytes_per_cell(self->framebuffer),
|
||||
false,
|
||||
false);
|
||||
|
||||
self->first_manual_refresh = !auto_refresh;
|
||||
|
||||
self->native_frames_per_second = native_frames_per_second;
|
||||
self->native_ms_per_frame = 1000 / native_frames_per_second;
|
||||
self->native_frames_per_second = self->framebuffer_protocol->get_native_frames_per_second(self->framebuffer);
|
||||
self->native_ms_per_frame = 1000 / self->native_frames_per_second;
|
||||
|
||||
supervisor_start_terminal(width, height);
|
||||
supervisor_start_terminal(self->core.width, self->core.height);
|
||||
|
||||
// Set the group after initialization otherwise we may send pixels while we delay in
|
||||
// initialization.
|
||||
|
|
|
@ -66,12 +66,22 @@ typedef bool (*framebuffer_set_brightness_fun)(mp_obj_t, mp_float_t);
|
|||
typedef mp_float_t (*framebuffer_get_brightness_fun)(mp_obj_t);
|
||||
typedef bool (*framebuffer_set_auto_brightness_fun)(mp_obj_t, bool);
|
||||
typedef bool (*framebuffer_get_auto_brightness_fun)(mp_obj_t);
|
||||
typedef int (*framebuffer_get_width_fun)(mp_obj_t);
|
||||
typedef int (*framebuffer_get_height_fun)(mp_obj_t);
|
||||
typedef int (*framebuffer_get_color_depth_fun)(mp_obj_t);
|
||||
typedef int (*framebuffer_get_bytes_per_cell_fun)(mp_obj_t);
|
||||
typedef int (*framebuffer_get_native_frames_per_second_fun)(mp_obj_t);
|
||||
|
||||
typedef struct _framebuffer_p_t {
|
||||
MP_PROTOCOL_HEAD // MP_QSTR_protocol_framebuffer
|
||||
framebuffer_get_bufinfo_fun get_bufinfo;
|
||||
framebuffer_swapbuffers_fun swapbuffers;
|
||||
framebuffer_deinit_fun deinit;
|
||||
framebuffer_get_width_fun get_width;
|
||||
framebuffer_get_height_fun get_height;
|
||||
framebuffer_get_color_depth_fun get_color_depth;
|
||||
framebuffer_get_bytes_per_cell_fun get_bytes_per_cell;
|
||||
framebuffer_get_native_frames_per_second_fun get_native_frames_per_second;
|
||||
framebuffer_get_brightness_fun get_brightness;
|
||||
framebuffer_set_brightness_fun set_brightness;
|
||||
framebuffer_get_auto_brightness_fun get_auto_brightness;
|
||||
|
|
Loading…
Reference in New Issue