Skip to content

(fix) lvgl deinit on soft-reset #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/micropython_lvgl_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ jobs:
make -j $(nproc) -C ports/rp2 BOARD=RPI_PICO USER_C_MODULES=../../user_modules/lv_binding_micropython/micropython.cmake

# ESP32 port
# USER_C_MODULES defined in esp32_common.cmake
- name: Build esp32 port
if: matrix.port == 'esp32'
run: |
source tools/ci.sh && ci_esp32_idf_setup
source tools/ci.sh && ci_esp32_build_common
make -C ports/esp32 BOARD=ESP32_GENERIC_S3 USER_C_MODULES=../../user_modules/lv_binding_micropython/micropython.cmake
make -C ports/esp32 BOARD=ESP32_GENERIC_S3


# Unix port
- name: Build unix port
Expand Down
22 changes: 17 additions & 5 deletions gen/gen_mpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,11 +1362,23 @@ def register_int_ptr_type(convertor, *types):
void mp_lv_deinit_gc()
{

// mp_printf(&mp_plat_print, "[ DEINIT GC ]");
mp_lv_roots = MP_STATE_VM(mp_lv_roots) = NULL;
mp_lv_user_data = MP_STATE_VM(mp_lv_user_data) = NULL;
mp_lv_roots_initialized = MP_STATE_VM(mp_lv_roots_initialized) = 0;
lvgl_mod_initialized = MP_STATE_VM(lvgl_mod_initialized) = 0;

if (MP_STATE_VM(lvgl_mod_initialized)) {
// mp_printf(&mp_plat_print, "[ DEINIT GC ]");
mp_lv_roots = MP_STATE_VM(mp_lv_roots) = NULL;
mp_lv_user_data = MP_STATE_VM(mp_lv_user_data) = NULL;
mp_lv_roots_initialized = MP_STATE_VM(mp_lv_roots_initialized) = 0;
lvgl_mod_initialized = MP_STATE_VM(lvgl_mod_initialized) = 0;
}

}

void mp_deinit_lvgl_mod()
{

if (MP_STATE_VM(lvgl_mod_initialized)) {
mp_lv_deinit_gc();
}

}

Expand Down
5 changes: 5 additions & 0 deletions include/lv_mp_port_soft_reset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


extern void mp_deinit_lvgl_mod();
#define MICROPY_PORT_DEINIT_FUNC mp_deinit_lvgl_mod()

3 changes: 3 additions & 0 deletions lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ extern void mp_lv_deinit_gc();
#define LV_GC_INIT() mp_lv_init_gc()
#define LV_GC_DEINIT() mp_lv_deinit_gc()

// To enable deinit on soft-reset add in mpconfigboard.h
Copy link
Collaborator

@PGNetHun PGNetHun Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you define deinit here with a new LV_ config?

Like:

#define LV_ENABLE_DEINIT_ON_SOFT_RESET 1
#ifdef LV_ENABLE_DEINIT_ON_SOFT_RESET
   extern void mp_deinit_lvgl_mod();
   #define MICROPY_PORT_DEINIT_FUNC mp_deinit_lvgl_mod()
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter where you define it, as long as you include MICROPY_PORT_DEINIT_FUNC macro definition in mpconfigboard.h, so this way you would need to include lv_conf.h as I did before ?

// #include <include/lv_mp_port_soft_reset.h>

#define LV_ENABLE_GLOBAL_CUSTOM 1
#if LV_ENABLE_GLOBAL_CUSTOM
extern void *mp_lv_roots;
Expand Down