framebufferio: Add getters for remaining displayio_display_core_construct arguments
.. and introduce a convenience macro that helps many of them be required (if their values match defaults or are inapplicable)
This commit is contained in:
parent
1ee2062c1b
commit
5e4ed93415
@ -40,6 +40,11 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define fb_getter_default(method, default_value) \
|
||||||
|
(self->framebuffer_protocol->method \
|
||||||
|
? self->framebuffer_protocol->method(self->framebuffer) \
|
||||||
|
: (default_value))
|
||||||
|
|
||||||
void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t* self,
|
void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebufferdisplay_obj_t* self,
|
||||||
mp_obj_t framebuffer,
|
mp_obj_t framebuffer,
|
||||||
uint16_t rotation,
|
uint16_t rotation,
|
||||||
@ -51,7 +56,7 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
|
|||||||
|
|
||||||
uint16_t ram_width = 0x100;
|
uint16_t ram_width = 0x100;
|
||||||
uint16_t ram_height = 0x100;
|
uint16_t ram_height = 0x100;
|
||||||
uint16_t depth = self->framebuffer_protocol->get_color_depth(self->framebuffer);
|
uint16_t depth = fb_getter_default(get_color_depth, 16);
|
||||||
displayio_display_core_construct(
|
displayio_display_core_construct(
|
||||||
&self->core,
|
&self->core,
|
||||||
NULL,
|
NULL,
|
||||||
@ -63,19 +68,15 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
|
|||||||
0,
|
0,
|
||||||
rotation,
|
rotation,
|
||||||
depth,
|
depth,
|
||||||
(depth < 12), // grayscale
|
fb_getter_default(get_grayscale, (depth < 8)),
|
||||||
true, // pixels_in_byte_share_row
|
fb_getter_default(get_pixels_in_byte_share_row, false),
|
||||||
self->framebuffer_protocol->get_bytes_per_cell(self->framebuffer),
|
fb_getter_default(get_bytes_per_cell, 2),
|
||||||
true, // reverse_pixels_in_byte
|
fb_getter_default(get_reverse_pixels_in_byte, false),
|
||||||
false // reverse_bytes_in_word
|
fb_getter_default(get_reverse_pixels_in_word, false)
|
||||||
);
|
);
|
||||||
|
|
||||||
self->first_pixel_offset = self->framebuffer_protocol->get_first_pixel_offset
|
self->first_pixel_offset = fb_getter_default(get_first_pixel_offset, 0);
|
||||||
? self->framebuffer_protocol->get_first_pixel_offset(self->framebuffer)
|
self->row_stride = fb_getter_default(get_row_stride, 0);
|
||||||
: 0;
|
|
||||||
self->row_stride = self->framebuffer_protocol->get_row_stride
|
|
||||||
? self->framebuffer_protocol->get_row_stride(self->framebuffer)
|
|
||||||
: 0;
|
|
||||||
if (self->row_stride == 0) {
|
if (self->row_stride == 0) {
|
||||||
self->row_stride = self->core.width * self->core.colorspace.depth/8;
|
self->row_stride = self->core.width * self->core.colorspace.depth/8;
|
||||||
}
|
}
|
||||||
@ -88,7 +89,7 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu
|
|||||||
|
|
||||||
self->first_manual_refresh = !auto_refresh;
|
self->first_manual_refresh = !auto_refresh;
|
||||||
|
|
||||||
self->native_frames_per_second = self->framebuffer_protocol->get_native_frames_per_second(self->framebuffer);
|
self->native_frames_per_second = fb_getter_default(get_native_frames_per_second, 60);
|
||||||
self->native_ms_per_frame = 1000 / self->native_frames_per_second;
|
self->native_ms_per_frame = 1000 / self->native_frames_per_second;
|
||||||
|
|
||||||
supervisor_start_terminal(self->core.width, self->core.height);
|
supervisor_start_terminal(self->core.width, self->core.height);
|
||||||
|
@ -62,35 +62,51 @@ void framebufferio_framebufferdisplay_collect_ptrs(framebufferio_framebufferdisp
|
|||||||
|
|
||||||
mp_obj_t common_hal_framebufferio_framebufferdisplay_get_framebuffer(framebufferio_framebufferdisplay_obj_t* self);
|
mp_obj_t common_hal_framebufferio_framebufferdisplay_get_framebuffer(framebufferio_framebufferdisplay_obj_t* self);
|
||||||
|
|
||||||
|
typedef bool (*framebuffer_get_auto_brightness_fun)(mp_obj_t);
|
||||||
|
typedef bool (*framebuffer_get_reverse_pixels_in_byte_fun)(mp_obj_t);
|
||||||
|
typedef bool (*framebuffer_get_reverse_pixels_in_word_fun)(mp_obj_t);
|
||||||
|
typedef bool (*framebuffer_set_auto_brightness_fun)(mp_obj_t, bool);
|
||||||
|
typedef bool (*framebuffer_set_brightness_fun)(mp_obj_t, mp_float_t);
|
||||||
|
typedef int (*framebuffer_get_bytes_per_cell_fun)(mp_obj_t);
|
||||||
|
typedef int (*framebuffer_get_color_depth_fun)(mp_obj_t);
|
||||||
|
typedef int (*framebuffer_get_first_pixel_offset_fun)(mp_obj_t);
|
||||||
|
typedef int (*framebuffer_get_grayscale_fun)(mp_obj_t);
|
||||||
|
typedef int (*framebuffer_get_height_fun)(mp_obj_t);
|
||||||
|
typedef int (*framebuffer_get_native_frames_per_second_fun)(mp_obj_t);
|
||||||
|
typedef int (*framebuffer_get_pixels_in_byte_share_row_fun)(mp_obj_t);
|
||||||
|
typedef int (*framebuffer_get_row_stride_fun)(mp_obj_t);
|
||||||
|
typedef int (*framebuffer_get_width_fun)(mp_obj_t);
|
||||||
|
typedef mp_float_t (*framebuffer_get_brightness_fun)(mp_obj_t);
|
||||||
|
typedef void (*framebuffer_deinit_fun)(mp_obj_t);
|
||||||
typedef void (*framebuffer_get_bufinfo_fun)(mp_obj_t, mp_buffer_info_t *bufinfo);
|
typedef void (*framebuffer_get_bufinfo_fun)(mp_obj_t, mp_buffer_info_t *bufinfo);
|
||||||
typedef void (*framebuffer_swapbuffers_fun)(mp_obj_t);
|
typedef void (*framebuffer_swapbuffers_fun)(mp_obj_t);
|
||||||
typedef void (*framebuffer_deinit_fun)(mp_obj_t);
|
|
||||||
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_row_stride_fun)(mp_obj_t);
|
|
||||||
typedef int (*framebuffer_get_first_pixel_offset_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 {
|
typedef struct _framebuffer_p_t {
|
||||||
MP_PROTOCOL_HEAD // MP_QSTR_protocol_framebuffer
|
MP_PROTOCOL_HEAD // MP_QSTR_protocol_framebuffer
|
||||||
|
|
||||||
|
// Mandatory
|
||||||
framebuffer_get_bufinfo_fun get_bufinfo;
|
framebuffer_get_bufinfo_fun get_bufinfo;
|
||||||
framebuffer_swapbuffers_fun swapbuffers;
|
framebuffer_swapbuffers_fun swapbuffers;
|
||||||
framebuffer_deinit_fun deinit;
|
framebuffer_deinit_fun deinit;
|
||||||
framebuffer_get_width_fun get_width;
|
framebuffer_get_width_fun get_width;
|
||||||
framebuffer_get_height_fun get_height;
|
framebuffer_get_height_fun get_height;
|
||||||
framebuffer_get_color_depth_fun get_color_depth;
|
|
||||||
framebuffer_get_bytes_per_cell_fun get_bytes_per_cell;
|
// Optional getters
|
||||||
framebuffer_get_native_frames_per_second_fun get_native_frames_per_second;
|
framebuffer_get_bytes_per_cell_fun get_bytes_per_cell; // default: 2
|
||||||
|
framebuffer_get_color_depth_fun get_color_depth; // default: 16
|
||||||
|
framebuffer_get_first_pixel_offset_fun get_first_pixel_offset; // default: 0
|
||||||
|
framebuffer_get_grayscale_fun get_grayscale; // default: grayscale if depth < 8
|
||||||
|
framebuffer_get_native_frames_per_second_fun get_native_frames_per_second; // default: 60
|
||||||
|
framebuffer_get_pixels_in_byte_share_row_fun get_pixels_in_byte_share_row; // default: false
|
||||||
|
framebuffer_get_reverse_pixels_in_byte_fun get_reverse_pixels_in_byte; // default: false
|
||||||
|
framebuffer_get_reverse_pixels_in_word_fun get_reverse_pixels_in_word; // default: false
|
||||||
|
framebuffer_get_row_stride_fun get_row_stride; // default: 0 (no extra row padding)
|
||||||
|
|
||||||
|
// Optional -- default is no brightness control
|
||||||
framebuffer_get_brightness_fun get_brightness;
|
framebuffer_get_brightness_fun get_brightness;
|
||||||
framebuffer_set_brightness_fun set_brightness;
|
framebuffer_set_brightness_fun set_brightness;
|
||||||
framebuffer_get_row_stride_fun get_row_stride;
|
|
||||||
framebuffer_get_first_pixel_offset_fun get_first_pixel_offset;
|
// Optional -- default is no automatic brightness control
|
||||||
framebuffer_get_auto_brightness_fun get_auto_brightness;
|
framebuffer_get_auto_brightness_fun get_auto_brightness;
|
||||||
framebuffer_set_auto_brightness_fun set_auto_brightness;
|
framebuffer_set_auto_brightness_fun set_auto_brightness;
|
||||||
} framebuffer_p_t;
|
} framebuffer_p_t;
|
||||||
|
Loading…
Reference in New Issue
Block a user