@@ -2223,7 +2223,7 @@ def gen_callback_func(func, func_name = None, user_data_argument = False):
22232223 if not func_name : func_name = get_arg_name (func .type )
22242224 # print('/* --> callback: func_name = %s */' % func_name)
22252225 if is_global_callback (func ):
2226- full_user_data = 'MP_STATE_PORT (mp_lv_user_data)'
2226+ full_user_data = 'LV_GC_ROOT (mp_lv_user_data)'
22272227 else :
22282228 user_data = get_user_data (func , func_name )
22292229
@@ -2312,7 +2312,7 @@ def build_mp_func_arg(arg, index, func, obj_name):
23122312 callback_name = '%s_%s' % (struct_name , callback_name )
23132313 user_data = get_user_data (arg_type , callback_name )
23142314 if is_global_callback (arg_type ):
2315- full_user_data = '&MP_STATE_PORT (mp_lv_user_data)'
2315+ full_user_data = '&LV_GC_ROOT (mp_lv_user_data)'
23162316 else :
23172317 full_user_data = '&%s->%s' % (first_arg .name , user_data ) if user_data else None
23182318 if index == 0 :
@@ -2751,6 +2751,9 @@ def generate_struct_functions(struct_list):
27512751for module_func in module_funcs [:]: # clone list because we are changing it in the loop.
27522752 if module_func .name in generated_funcs :
27532753 continue # generated_funcs could change inside the loop so need to recheck.
2754+ if module_func .name == "lv_init" :
2755+ func_metadata [module_func .name ] = {'type' : 'function' , 'args' :[]}
2756+ continue # special case handled separately
27542757 try :
27552758 gen_mp_func (module_func , None )
27562759 # A new function can create new struct with new function structs
@@ -2806,10 +2809,22 @@ def generate_struct_functions(struct_list):
28062809 * lvgl root pointers.
28072810 */
28082811
2809- #define LV_REGISTER_ROOT(root_type, root_name) MP_REGISTER_ROOT_POINTER(root_type root_name);
2810- LV_ITERATE_ROOTS(LV_REGISTER_ROOT);
2812+ MP_REGISTER_ROOT_POINTER(struct lvgl_root_pointers_t * lvgl);
28112813
2812- MP_REGISTER_ROOT_POINTER(void *mp_lv_user_data);
2814+ STATIC mp_obj_t mp_lv_init(void)
2815+ {
2816+ if (lv_is_initialized()) {
2817+ return mp_const_none;
2818+ }
2819+
2820+ // Create object to hold all the lvgl global objects.
2821+ MP_STATE_VM(lvgl) = m_new0(lvgl_root_pointers_t, 1);
2822+
2823+ lv_init();
2824+ return mp_const_none;
2825+ }
2826+
2827+ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_lv_init_mpobj, mp_lv_init);
28132828
28142829""" )
28152830
0 commit comments