@@ -2223,7 +2223,7 @@ def gen_callback_func(func, func_name = None, user_data_argument = False):
2223
2223
if not func_name : func_name = get_arg_name (func .type )
2224
2224
# print('/* --> callback: func_name = %s */' % func_name)
2225
2225
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)'
2227
2227
else :
2228
2228
user_data = get_user_data (func , func_name )
2229
2229
@@ -2312,7 +2312,7 @@ def build_mp_func_arg(arg, index, func, obj_name):
2312
2312
callback_name = '%s_%s' % (struct_name , callback_name )
2313
2313
user_data = get_user_data (arg_type , callback_name )
2314
2314
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)'
2316
2316
else :
2317
2317
full_user_data = '&%s->%s' % (first_arg .name , user_data ) if user_data else None
2318
2318
if index == 0 :
@@ -2751,6 +2751,9 @@ def generate_struct_functions(struct_list):
2751
2751
for module_func in module_funcs [:]: # clone list because we are changing it in the loop.
2752
2752
if module_func .name in generated_funcs :
2753
2753
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
2754
2757
try :
2755
2758
gen_mp_func (module_func , None )
2756
2759
# A new function can create new struct with new function structs
@@ -2806,10 +2809,22 @@ def generate_struct_functions(struct_list):
2806
2809
* lvgl root pointers.
2807
2810
*/
2808
2811
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);
2811
2813
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);
2813
2828
2814
2829
""" )
2815
2830
0 commit comments