Skip to content

Commit f4df5db

Browse files
committed
Improve declaration of root pointers.
Remove need for global -include "lvgl/lvgl.h" Fixes rp2 build.
1 parent 449c4ff commit f4df5db

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

Diff for: bindings.cmake

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ include(${LVGL_DIR}/CMakeLists.txt)
88
# lvgl bindings target (the mpy module)
99
add_library(usermod_lv_bindings INTERFACE)
1010
target_sources(usermod_lv_bindings INTERFACE ${LV_SRC})
11-
target_include_directories(usermod_lv_bindings INTERFACE ${LV_INCLUDE})
11+
target_include_directories(usermod_lv_bindings INTERFACE
12+
${CMAKE_CURRENT_LIST_DIR}/include
13+
${LV_INCLUDE}
14+
)
1215

1316
target_link_libraries(usermod_lv_bindings INTERFACE lvgl_interface)
1417

Diff for: gen/gen_mpy.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -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):
27512751
for 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

Diff for: include/lv_mp_root_pointers.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __LV_MP_ROOT_POINTERS_H
2+
#define __LV_MP_ROOT_POINTERS_H
3+
4+
#include <py/mpstate.h>
5+
#include "lvgl/lvgl.h"
6+
7+
typedef struct lvgl_root_pointers_t {
8+
LV_ROOTS
9+
void *mp_lv_user_data;
10+
} lvgl_root_pointers_t;
11+
12+
#endif //__LV_MP_ROOT_POINTERS_H

Diff for: lv_conf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@
281281
*Used if lvgl is bound to higher level language and the memory is managed by that language*/
282282
#define LV_ENABLE_GC 1
283283
#if LV_ENABLE_GC != 0
284-
#define LV_GC_INCLUDE "py/mpstate.h" /*Include Garbage Collector related things*/
285-
#define LV_GC_ROOT(x) MP_STATE_VM(x)
284+
#define LV_GC_INCLUDE "lv_mp_root_pointers.h" /*Include Garbage Collector related things*/
285+
#define LV_GC_ROOT(x) MP_STATE_VM(lvgl->x)
286286
#endif /*LV_ENABLE_GC*/
287287

288288
/*Default image cache size. Image caching keeps some images opened.

Diff for: micropython.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LVGL_PP = $(BUILD)/lvgl/lvgl.pp.c
1111
LVGL_MPY = $(BUILD)/lvgl/lv_mpy.c
1212
LVGL_MPY_METADATA = $(BUILD)/lvgl/lv_mpy.json
1313
QSTR_GLOBAL_DEPENDENCIES += $(LVGL_MPY)
14-
CFLAGS_USERMOD += $(LV_CFLAGS) $(INC) -include "lvgl/lvgl.h"
14+
CFLAGS_USERMOD += $(LV_CFLAGS) $(INC)
1515

1616

1717
ifneq ($(MICROPY_FLOAT_IMPL),double)

0 commit comments

Comments
 (0)