@@ -1337,18 +1337,54 @@ def register_int_ptr_type(convertor, *types):
1337
1337
// Register LVGL root pointers
1338
1338
MP_REGISTER_ROOT_POINTER(void *mp_lv_roots);
1339
1339
MP_REGISTER_ROOT_POINTER(void *mp_lv_user_data);
1340
+ MP_REGISTER_ROOT_POINTER(int mp_lv_roots_initialized);
1341
+ MP_REGISTER_ROOT_POINTER(int lvgl_mod_initialized);
1340
1342
1341
1343
void *mp_lv_roots;
1344
+ void *mp_lv_user_data;
1345
+ int mp_lv_roots_initialized = 0;
1346
+ int lvgl_mod_initialized = 0;
1342
1347
1343
1348
void mp_lv_init_gc()
1344
1349
{
1345
- static bool mp_lv_roots_initialized = false;
1346
- if (!mp_lv_roots_initialized) {
1350
+ if (!MP_STATE_VM( mp_lv_roots_initialized)) {
1351
+ // mp_printf(&mp_plat_print, "[ INIT GC ]");
1347
1352
mp_lv_roots = MP_STATE_VM(mp_lv_roots) = m_new0(lv_global_t, 1);
1348
- mp_lv_roots_initialized = true ;
1353
+ mp_lv_roots_initialized = MP_STATE_VM(mp_lv_roots_initialized) = 1 ;
1349
1354
}
1350
1355
}
1351
1356
1357
+ void mp_lv_deinit_gc()
1358
+ {
1359
+
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;
1365
+
1366
+ }
1367
+
1368
+ static mp_obj_t lvgl_mod___init__(void) {
1369
+ if (!MP_STATE_VM(lvgl_mod_initialized)) {
1370
+ // __init__ for builtins is called each time the module is imported,
1371
+ // so ensure that initialisation only happens once.
1372
+ MP_STATE_VM(lvgl_mod_initialized) = true;
1373
+ lv_init();
1374
+ }
1375
+ return mp_const_none;
1376
+ }
1377
+ static MP_DEFINE_CONST_FUN_OBJ_0(lvgl_mod___init___obj, lvgl_mod___init__);
1378
+
1379
+
1380
+ static mp_obj_t lvgl_mod___del__(void) {
1381
+ if (MP_STATE_VM(lvgl_mod_initialized)) {
1382
+ lv_deinit();
1383
+ }
1384
+ return mp_const_none;
1385
+ }
1386
+ static MP_DEFINE_CONST_FUN_OBJ_0(lvgl_mod___del___obj, lvgl_mod___del__);
1387
+
1352
1388
#else // LV_OBJ_T
1353
1389
1354
1390
typedef struct mp_lv_obj_type_t {
@@ -3621,6 +3657,8 @@ def generate_struct_functions(struct_list):
3621
3657
3622
3658
static const mp_rom_map_elem_t {module_name}_globals_table[] = {{
3623
3659
{{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_{module_name}) }},
3660
+ {{ MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&lvgl_mod___init___obj) }},
3661
+ {{ MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&lvgl_mod___del___obj) }},
3624
3662
{objects}
3625
3663
{functions}
3626
3664
{enums}
0 commit comments