Skip to content

Commit 8927f18

Browse files
committed
(fix) lvgl deinit on soft-reset
Include `<include/lv_mp_port_soft_reset.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 40eb341 commit 8927f18

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

.github/workflows/micropython_lvgl_ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ jobs:
8383
make -j $(nproc) -C ports/rp2 BOARD=RPI_PICO USER_C_MODULES=../../user_modules/lv_binding_micropython/micropython.cmake
8484
8585
# ESP32 port
86+
# USER_C_MODULES defined in esp32_common.cmake
8687
- name: Build esp32 port
8788
if: matrix.port == 'esp32'
8889
run: |
8990
source tools/ci.sh && ci_esp32_idf_setup
9091
source tools/ci.sh && ci_esp32_build_common
91-
make -C ports/esp32 BOARD=ESP32_GENERIC_S3 USER_C_MODULES=../../user_modules/lv_binding_micropython/micropython.cmake
92+
make -C ports/esp32 BOARD=ESP32_GENERIC_S3
93+
9294

9395
# Unix port
9496
- name: Build unix port

gen/gen_mpy.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,11 +1362,23 @@ def register_int_ptr_type(convertor, *types):
13621362
void mp_lv_deinit_gc()
13631363
{
13641364
1365-
// mp_printf(&mp_plat_print, "[ DEINIT GC ]");
1366-
mp_lv_roots = MP_STATE_VM(mp_lv_roots) = NULL;
1367-
mp_lv_user_data = MP_STATE_VM(mp_lv_user_data) = NULL;
1368-
mp_lv_roots_initialized = MP_STATE_VM(mp_lv_roots_initialized) = 0;
1369-
lvgl_mod_initialized = MP_STATE_VM(lvgl_mod_initialized) = 0;
1365+
1366+
if (MP_STATE_VM(lvgl_mod_initialized)) {
1367+
// mp_printf(&mp_plat_print, "[ DEINIT GC ]");
1368+
mp_lv_roots = MP_STATE_VM(mp_lv_roots) = NULL;
1369+
mp_lv_user_data = MP_STATE_VM(mp_lv_user_data) = NULL;
1370+
mp_lv_roots_initialized = MP_STATE_VM(mp_lv_roots_initialized) = 0;
1371+
lvgl_mod_initialized = MP_STATE_VM(lvgl_mod_initialized) = 0;
1372+
}
1373+
1374+
}
1375+
1376+
void mp_deinit_lvgl_mod()
1377+
{
1378+
1379+
if (MP_STATE_VM(lvgl_mod_initialized)) {
1380+
mp_lv_deinit_gc();
1381+
}
13701382
13711383
}
13721384

include/lv_mp_port_soft_reset.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
extern void mp_deinit_lvgl_mod();
4+
#define MICROPY_PORT_DEINIT_FUNC mp_deinit_lvgl_mod()
5+

lv_conf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ extern void mp_lv_deinit_gc();
434434
#define LV_GC_INIT() mp_lv_init_gc()
435435
#define LV_GC_DEINIT() mp_lv_deinit_gc()
436436

437+
// To enable deinit on soft-reset add in mpconfigboard.h
438+
// #include <include/lv_mp_port_soft_reset.h>
439+
437440
#define LV_ENABLE_GLOBAL_CUSTOM 1
438441
#if LV_ENABLE_GLOBAL_CUSTOM
439442
extern void *mp_lv_roots;

0 commit comments

Comments
 (0)