Skip to content

PicoGraphics: Add a GENERIC display type. #1092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions micropython/modules/picographics/picographics.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ static const mp_map_elem_t picographics_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_EXPLORER), MP_ROM_INT(DISPLAY_EXPLORER) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PRESTO), MP_ROM_INT(DISPLAY_PRESTO) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PRESTO_FULL_RES), MP_ROM_INT(DISPLAY_PRESTO_FULL_RES) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_GENERIC), MP_ROM_INT(DISPLAY_GENERIC) },


{ MP_ROM_QSTR(MP_QSTR_PEN_1BIT), MP_ROM_INT(PEN_1BIT) },
{ MP_ROM_QSTR(MP_QSTR_PEN_P4), MP_ROM_INT(PEN_P4) },
Expand Down
20 changes: 15 additions & 5 deletions micropython/modules/picographics/picographics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ bool get_display_settings(PicoGraphicsDisplay display, int &width, int &height,
rotate = (int)Rotation::ROTATE_0;
if(pen_type == -1) pen_type = PEN_RGB565;
break;
case DISPLAY_GENERIC:
if(width == 0) width = 320;
if(height == 0) height = 240;
bus_type = BUS_PIO;
if(rotate == -1) rotate = (int)Rotation::ROTATE_0;
if(pen_type == -1) pen_type = PEN_RGB565;
break;
default:
return false;
}
Expand Down Expand Up @@ -303,16 +310,18 @@ size_t get_required_buffer_size(PicoGraphicsPenType pen_type, uint width, uint h
mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
ModPicoGraphics_obj_t *self = nullptr;

enum { ARG_display, ARG_rotate, ARG_bus, ARG_buffer, ARG_pen_type, ARG_extra_pins, ARG_i2c_address, ARG_layers };
enum { ARG_display, ARG_rotate, ARG_bus, ARG_buffer, ARG_pen_type, ARG_extra_pins, ARG_i2c_address, ARG_layers, ARG_width, ARG_height };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_display, MP_ARG_INT | MP_ARG_REQUIRED },
{ MP_QSTR_display, MP_ARG_INT, { .u_int = DISPLAY_GENERIC } },
{ MP_QSTR_rotate, MP_ARG_INT, { .u_int = -1 } },
{ MP_QSTR_bus, MP_ARG_OBJ, { .u_obj = mp_const_none } },
{ MP_QSTR_buffer, MP_ARG_OBJ, { .u_obj = mp_const_none } },
{ MP_QSTR_pen_type, MP_ARG_INT, { .u_int = -1 } },
{ MP_QSTR_extra_pins, MP_ARG_OBJ, { .u_obj = mp_const_none } },
{ MP_QSTR_i2c_address, MP_ARG_INT, { .u_int = -1 } },
{ MP_QSTR_layers, MP_ARG_INT, { .u_int = 1 } },
{ MP_QSTR_width, MP_ARG_INT, { .u_int = 0 } },
{ MP_QSTR_height, MP_ARG_INT, { .u_int = 0 } },
};

// Parse args.
Expand All @@ -324,8 +333,8 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size
PicoGraphicsDisplay display = (PicoGraphicsDisplay)args[ARG_display].u_int;

bool round = display == DISPLAY_ROUND_LCD_240X240;
int width = 0;
int height = 0;
int width = args[ARG_width].u_int;
int height = args[ARG_height].u_int;;
int pen_type = args[ARG_pen_type].u_int;
int rotate = args[ARG_rotate].u_int;
int layers = args[ARG_layers].u_int;
Expand Down Expand Up @@ -413,7 +422,8 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size
|| display == DISPLAY_UNICORN_PACK
|| display == DISPLAY_SCROLL_PACK
|| display == DISPLAY_PRESTO
|| display == DISPLAY_PRESTO_FULL_RES) {
|| display == DISPLAY_PRESTO_FULL_RES
|| display == DISPLAY_GENERIC) {
// Create a dummy display driver
self->display = m_new_class(DisplayDriver, width, height, (Rotation)rotate);

Expand Down
3 changes: 2 additions & 1 deletion micropython/modules/picographics/picographics.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ enum PicoGraphicsDisplay {
DISPLAY_PICO_W_EXPLORER,
DISPLAY_EXPLORER,
DISPLAY_PRESTO,
DISPLAY_PRESTO_FULL_RES
DISPLAY_PRESTO_FULL_RES,
DISPLAY_GENERIC
};

enum PicoGraphicsPenType {
Expand Down