diff options
author | Damien George <damien.p.george@gmail.com> | 2016-12-01 15:51:16 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-12-01 16:43:25 +1100 |
commit | 81e171b7bb38cff377ca389cd6fb179aea325998 (patch) | |
tree | 60bed405a7fca9f866adfa4d2a3cdc32828aa72d | |
parent | eb09336e996a71fd58e0638035565946d74a1495 (diff) |
extmod/modframebuf: Add back legacy FrameBuffer1 "class".
For backwards compatibility. It simple creates a frame buffer with the
MVLSB format.
-rw-r--r-- | extmod/modframebuf.c | 23 | ||||
-rw-r--r-- | tests/extmod/framebuf1.py | 4 |
2 files changed, 27 insertions, 0 deletions
diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index 2ca5f2df3..e1bfe8310 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -310,9 +310,32 @@ STATIC const mp_obj_type_t mp_type_framebuf = { .locals_dict = (mp_obj_t)&framebuf_locals_dict, }; +// this factory function is provided for backwards compatibility with old FrameBuffer1 class +STATIC mp_obj_t legacy_framebuffer1(size_t n_args, const mp_obj_t *args) { + mp_obj_framebuf_t *o = m_new_obj(mp_obj_framebuf_t); + o->base.type = &mp_type_framebuf; + + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_WRITE); + o->buf = bufinfo.buf; + + o->width = mp_obj_get_int(args[1]); + o->height = mp_obj_get_int(args[2]); + o->format = FRAMEBUF_MVLSB; + if (n_args >= 4) { + o->stride = mp_obj_get_int(args[3]); + } else { + o->stride = o->width; + } + + return MP_OBJ_FROM_PTR(o); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(legacy_framebuffer1_obj, 3, 4, legacy_framebuffer1); + STATIC const mp_rom_map_elem_t framebuf_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_framebuf) }, { MP_ROM_QSTR(MP_QSTR_FrameBuffer), MP_ROM_PTR(&mp_type_framebuf) }, + { MP_ROM_QSTR(MP_QSTR_FrameBuffer1), MP_ROM_PTR(&legacy_framebuffer1_obj) }, { MP_ROM_QSTR(MP_QSTR_MVLSB), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_MVLSB) }, { MP_ROM_QSTR(MP_QSTR_RGB565), MP_OBJ_NEW_SMALL_INT(FRAMEBUF_RGB565) }, }; diff --git a/tests/extmod/framebuf1.py b/tests/extmod/framebuf1.py index 836b1a9de..7faad7181 100644 --- a/tests/extmod/framebuf1.py +++ b/tests/extmod/framebuf1.py @@ -54,3 +54,7 @@ print(buf) # char out of font range set to chr(127) fbuf.text(str(chr(31)), 0, 0) print(buf) + +# test legacy constructor +fbuf = framebuf.FrameBuffer1(buf, w, h) +fbuf = framebuf.FrameBuffer1(buf, w, h, w) |