Skip to content

Commit 81e171b

Browse files
committed
extmod/modframebuf: Add back legacy FrameBuffer1 "class".
For backwards compatibility. It simple creates a frame buffer with the MVLSB format.
1 parent eb09336 commit 81e171b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

extmod/modframebuf.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,32 @@ STATIC const mp_obj_type_t mp_type_framebuf = {
310310
.locals_dict = (mp_obj_t)&framebuf_locals_dict,
311311
};
312312

313+
// this factory function is provided for backwards compatibility with old FrameBuffer1 class
314+
STATIC mp_obj_t legacy_framebuffer1(size_t n_args, const mp_obj_t *args) {
315+
mp_obj_framebuf_t *o = m_new_obj(mp_obj_framebuf_t);
316+
o->base.type = &mp_type_framebuf;
317+
318+
mp_buffer_info_t bufinfo;
319+
mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_WRITE);
320+
o->buf = bufinfo.buf;
321+
322+
o->width = mp_obj_get_int(args[1]);
323+
o->height = mp_obj_get_int(args[2]);
324+
o->format = FRAMEBUF_MVLSB;
325+
if (n_args >= 4) {
326+
o->stride = mp_obj_get_int(args[3]);
327+
} else {
328+
o->stride = o->width;
329+
}
330+
331+
return MP_OBJ_FROM_PTR(o);
332+
}
333+
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(legacy_framebuffer1_obj, 3, 4, legacy_framebuffer1);
334+
313335
STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = {
314336
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_framebuf) },
315337
{ MP_ROM_QSTR(MP_QSTR_FrameBuffer), MP_ROM_PTR(&mp_type_framebuf) },
338+
{ MP_ROM_QSTR(MP_QSTR_FrameBuffer1), MP_ROM_PTR(&legacy_framebuffer1_obj) },
316339
{ MP_ROM_QSTR(MP_QSTR_MVLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) },
317340
{ MP_ROM_QSTR(MP_QSTR_RGB565), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_RGB565) },
318341
};

tests/extmod/framebuf1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@
5454
# char out of font range set to chr(127)
5555
fbuf.text(str(chr(31)), 0, 0)
5656
print(buf)
57+
58+
# test legacy constructor
59+
fbuf = framebuf.FrameBuffer1(buf, w, h)
60+
fbuf = framebuf.FrameBuffer1(buf, w, h, w)

0 commit comments

Comments
 (0)