Skip to content

Commit 898348d

Browse files
authored
Merge pull request #1092 from pimoroni/patch-picographics-generic
PicoGraphics: Add a GENERIC display type.
2 parents d7d7754 + 04c88c3 commit 898348d

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

micropython/modules/picographics/picographics.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ static const mp_map_elem_t picographics_globals_table[] = {
174174
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_EXPLORER), MP_ROM_INT(DISPLAY_EXPLORER) },
175175
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PRESTO), MP_ROM_INT(DISPLAY_PRESTO) },
176176
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_PRESTO_FULL_RES), MP_ROM_INT(DISPLAY_PRESTO_FULL_RES) },
177+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY_GENERIC), MP_ROM_INT(DISPLAY_GENERIC) },
178+
177179

178180
{ MP_ROM_QSTR(MP_QSTR_PEN_1BIT), MP_ROM_INT(PEN_1BIT) },
179181
{ MP_ROM_QSTR(MP_QSTR_PEN_P4), MP_ROM_INT(PEN_P4) },

micropython/modules/picographics/picographics.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ bool get_display_settings(PicoGraphicsDisplay display, int &width, int &height,
271271
rotate = (int)Rotation::ROTATE_0;
272272
if(pen_type == -1) pen_type = PEN_RGB565;
273273
break;
274+
case DISPLAY_GENERIC:
275+
if(width == 0) width = 320;
276+
if(height == 0) height = 240;
277+
bus_type = BUS_PIO;
278+
if(rotate == -1) rotate = (int)Rotation::ROTATE_0;
279+
if(pen_type == -1) pen_type = PEN_RGB565;
280+
break;
274281
default:
275282
return false;
276283
}
@@ -303,16 +310,18 @@ size_t get_required_buffer_size(PicoGraphicsPenType pen_type, uint width, uint h
303310
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) {
304311
ModPicoGraphics_obj_t *self = nullptr;
305312

306-
enum { ARG_display, ARG_rotate, ARG_bus, ARG_buffer, ARG_pen_type, ARG_extra_pins, ARG_i2c_address, ARG_layers };
313+
enum { ARG_display, ARG_rotate, ARG_bus, ARG_buffer, ARG_pen_type, ARG_extra_pins, ARG_i2c_address, ARG_layers, ARG_width, ARG_height };
307314
static const mp_arg_t allowed_args[] = {
308-
{ MP_QSTR_display, MP_ARG_INT | MP_ARG_REQUIRED },
315+
{ MP_QSTR_display, MP_ARG_INT, { .u_int = DISPLAY_GENERIC } },
309316
{ MP_QSTR_rotate, MP_ARG_INT, { .u_int = -1 } },
310317
{ MP_QSTR_bus, MP_ARG_OBJ, { .u_obj = mp_const_none } },
311318
{ MP_QSTR_buffer, MP_ARG_OBJ, { .u_obj = mp_const_none } },
312319
{ MP_QSTR_pen_type, MP_ARG_INT, { .u_int = -1 } },
313320
{ MP_QSTR_extra_pins, MP_ARG_OBJ, { .u_obj = mp_const_none } },
314321
{ MP_QSTR_i2c_address, MP_ARG_INT, { .u_int = -1 } },
315322
{ MP_QSTR_layers, MP_ARG_INT, { .u_int = 1 } },
323+
{ MP_QSTR_width, MP_ARG_INT, { .u_int = 0 } },
324+
{ MP_QSTR_height, MP_ARG_INT, { .u_int = 0 } },
316325
};
317326

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

326335
bool round = display == DISPLAY_ROUND_LCD_240X240;
327-
int width = 0;
328-
int height = 0;
336+
int width = args[ARG_width].u_int;
337+
int height = args[ARG_height].u_int;;
329338
int pen_type = args[ARG_pen_type].u_int;
330339
int rotate = args[ARG_rotate].u_int;
331340
int layers = args[ARG_layers].u_int;
@@ -413,7 +422,8 @@ mp_obj_t ModPicoGraphics_make_new(const mp_obj_type_t *type, size_t n_args, size
413422
|| display == DISPLAY_UNICORN_PACK
414423
|| display == DISPLAY_SCROLL_PACK
415424
|| display == DISPLAY_PRESTO
416-
|| display == DISPLAY_PRESTO_FULL_RES) {
425+
|| display == DISPLAY_PRESTO_FULL_RES
426+
|| display == DISPLAY_GENERIC) {
417427
// Create a dummy display driver
418428
self->display = m_new_class(DisplayDriver, width, height, (Rotation)rotate);
419429

micropython/modules/picographics/picographics.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ enum PicoGraphicsDisplay {
3434
DISPLAY_PICO_W_EXPLORER,
3535
DISPLAY_EXPLORER,
3636
DISPLAY_PRESTO,
37-
DISPLAY_PRESTO_FULL_RES
37+
DISPLAY_PRESTO_FULL_RES,
38+
DISPLAY_GENERIC
3839
};
3940

4041
enum PicoGraphicsPenType {

0 commit comments

Comments
 (0)