Skip to content

Commit 6867c01

Browse files
committed
(fix) lvgl deinit on soft-reset
Include `lv_conf.h` in `mpconfigboard.h` so lvgl deinit is called on soft-reset, so calling `lvgl.deinit()` is no longer necessary. This closes #343
1 parent 44f70b1 commit 6867c01

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

gen/gen_mpy.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,11 +1357,23 @@ def register_int_ptr_type(convertor, *types):
13571357
void mp_lv_deinit_gc()
13581358
{
13591359
1360-
// mp_printf(&mp_plat_print, "[ DEINIT GC ]");
1361-
mp_lv_roots = MP_STATE_VM(mp_lv_roots) = NULL;
1362-
mp_lv_user_data = MP_STATE_VM(mp_lv_user_data) = NULL;
1363-
mp_lv_roots_initialized = MP_STATE_VM(mp_lv_roots_initialized) = 0;
1364-
lvgl_mod_initialized = MP_STATE_VM(lvgl_mod_initialized) = 0;
1360+
1361+
if (MP_STATE_VM(lvgl_mod_initialized)) {
1362+
// mp_printf(&mp_plat_print, "[ DEINIT GC ]");
1363+
mp_lv_roots = MP_STATE_VM(mp_lv_roots) = NULL;
1364+
mp_lv_user_data = MP_STATE_VM(mp_lv_user_data) = NULL;
1365+
mp_lv_roots_initialized = MP_STATE_VM(mp_lv_roots_initialized) = 0;
1366+
lvgl_mod_initialized = MP_STATE_VM(lvgl_mod_initialized) = 0;
1367+
}
1368+
1369+
}
1370+
1371+
void mp_deinit_lvgl_mod()
1372+
{
1373+
1374+
if (MP_STATE_VM(lvgl_mod_initialized)) {
1375+
mp_lv_deinit_gc();
1376+
}
13651377
13661378
}
13671379

lv_conf.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ extern void mp_lv_deinit_gc();
306306
#define LV_GC_INIT() mp_lv_init_gc()
307307
#define LV_GC_DEINIT() mp_lv_deinit_gc()
308308

309+
// include lv_conf.h in "mpconfigboard.h" for this to take effect.
310+
extern void mp_deinit_lvgl_mod();
311+
#define MICROPY_PORT_DEINIT_FUNC mp_deinit_lvgl_mod()
312+
309313
#define LV_ENABLE_GLOBAL_CUSTOM 1
310314
#if LV_ENABLE_GLOBAL_CUSTOM
311315
extern void *mp_lv_roots;

0 commit comments

Comments
 (0)