Skip to content

Commit

Permalink
Improve declaration of root pointers.
Browse files Browse the repository at this point in the history
Remove need for global -include "lvgl/lvgl.h"
Fixes rp2 build.
  • Loading branch information
pi-anl committed Nov 14, 2022
1 parent 3ad73cd commit b4f481b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
5 changes: 4 additions & 1 deletion bindings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ include(${LVGL_DIR}/CMakeLists.txt)
# lvgl bindings target (the mpy module)
add_library(usermod_lv_bindings INTERFACE)
target_sources(usermod_lv_bindings INTERFACE ${LV_SRC})
target_include_directories(usermod_lv_bindings INTERFACE ${LV_INCLUDE})
target_include_directories(usermod_lv_bindings INTERFACE
${CMAKE_CURRENT_LIST_DIR}/include
${LV_INCLUDE}
)

target_link_libraries(usermod_lv_bindings INTERFACE lvgl_interface)

Expand Down
25 changes: 20 additions & 5 deletions gen/gen_mpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2223,7 +2223,7 @@ def gen_callback_func(func, func_name = None, user_data_argument = False):
if not func_name: func_name = get_arg_name(func.type)
# print('/* --> callback: func_name = %s */' % func_name)
if is_global_callback(func):
full_user_data = 'MP_STATE_PORT(mp_lv_user_data)'
full_user_data = 'LV_GC_ROOT(mp_lv_user_data)'
else:
user_data = get_user_data(func, func_name)

Expand Down Expand Up @@ -2312,7 +2312,7 @@ def build_mp_func_arg(arg, index, func, obj_name):
callback_name = '%s_%s' % (struct_name, callback_name)
user_data = get_user_data(arg_type, callback_name)
if is_global_callback(arg_type):
full_user_data = '&MP_STATE_PORT(mp_lv_user_data)'
full_user_data = '&LV_GC_ROOT(mp_lv_user_data)'
else:
full_user_data = '&%s->%s' % (first_arg.name, user_data) if user_data else None
if index == 0:
Expand Down Expand Up @@ -2751,6 +2751,9 @@ def generate_struct_functions(struct_list):
for module_func in module_funcs[:]: # clone list because we are changing it in the loop.
if module_func.name in generated_funcs:
continue # generated_funcs could change inside the loop so need to recheck.
if module_func.name == "lv_init":
func_metadata[module_func.name] = {'type': 'function', 'args':[]}
continue # special case handled separately
try:
gen_mp_func(module_func, None)
# A new function can create new struct with new function structs
Expand Down Expand Up @@ -2806,10 +2809,22 @@ def generate_struct_functions(struct_list):
* lvgl root pointers.
*/
#define LV_REGISTER_ROOT(root_type, root_name) MP_REGISTER_ROOT_POINTER(root_type root_name);
LV_ITERATE_ROOTS(LV_REGISTER_ROOT);
MP_REGISTER_ROOT_POINTER(struct lvgl_root_pointers_t * lvgl);
MP_REGISTER_ROOT_POINTER(void *mp_lv_user_data);
STATIC mp_obj_t mp_lv_init(void)
{
if (lv_is_initialized()) {
return mp_const_none;
}
// Create object to hold all the lvgl global objects.
MP_STATE_VM(lvgl) = m_new0(lvgl_root_pointers_t, 1);
lv_init();
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_lv_init_mpobj, mp_lv_init);
""")

Expand Down
12 changes: 12 additions & 0 deletions include/lv_mp_root_pointers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __LV_MP_ROOT_POINTERS_H
#define __LV_MP_ROOT_POINTERS_H

#include <py/mpstate.h>
#include "lvgl/lvgl.h"

typedef struct lvgl_root_pointers_t {
LV_ROOTS
void *mp_lv_user_data;
} lvgl_root_pointers_t;

#endif //__LV_MP_ROOT_POINTERS_H
4 changes: 2 additions & 2 deletions lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@
*Used if lvgl is bound to higher level language and the memory is managed by that language*/
#define LV_ENABLE_GC 1
#if LV_ENABLE_GC != 0
#define LV_GC_INCLUDE "py/mpstate.h" /*Include Garbage Collector related things*/
#define LV_GC_ROOT(x) MP_STATE_VM(x)
#define LV_GC_INCLUDE "lv_mp_root_pointers.h" /*Include Garbage Collector related things*/
#define LV_GC_ROOT(x) MP_STATE_VM(lvgl->x)
#endif /*LV_ENABLE_GC*/

/*Default image cache size. Image caching keeps some images opened.
Expand Down
2 changes: 1 addition & 1 deletion micropython.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LVGL_PP = $(BUILD)/lvgl/lvgl.pp.c
LVGL_MPY = $(BUILD)/lvgl/lv_mpy.c
LVGL_MPY_METADATA = $(BUILD)/lvgl/lv_mpy.json
QSTR_GLOBAL_DEPENDENCIES += $(LVGL_MPY)
CFLAGS_USERMOD += $(LV_CFLAGS) $(INC) -include "lvgl/lvgl.h"
CFLAGS_USERMOD += $(LV_CFLAGS) $(INC)


ifneq ($(MICROPY_FLOAT_IMPL),double)
Expand Down

0 comments on commit b4f481b

Please sign in to comment.