Skip to content

Commit 6fae7e7

Browse files
committed
esp32: Enable lv_binding_micropython as user C mod.
1 parent d7ffcf6 commit 6fae7e7

File tree

3 files changed

+205
-0
lines changed

3 files changed

+205
-0
lines changed

micropython.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
# This file is to be given as "make USER_C_MODULES=..." when building Micropython port
3+
4+
# Include LVGL component, ignore KCONFIG
5+
6+
idf_build_set_property(LV_MICROPYTHON 1)
7+
idf_build_component(${CMAKE_CURRENT_LIST_DIR}/lvgl)
8+
idf_build_set_property(COMPILE_DEFINITIONS "-DLV_KCONFIG_IGNORE" APPEND)
9+
separate_arguments(LV_CFLAGS_ENV UNIX_COMMAND $ENV{LV_CFLAGS})
10+
idf_build_set_property(COMPILE_DEFINITIONS "${LV_CFLAGS}" APPEND)
11+
idf_build_set_property(COMPILE_OPTIONS "-Wno-unused-function" APPEND)
12+
idf_build_set_property(SRCS "${LV_SRC}" APPEND)
13+
idf_build_set_property(INCLUDE_DIRS "${LV_INCLUDE}" APPEND)
14+
15+
include(${CMAKE_CURRENT_LIST_DIR}/mkrules_usermod.cmake)
16+
17+
# Add lv_bindings rules
18+
19+
all_lv_bindings()
20+
21+
22+
# # # make usermod (target declared by Micropython for all user compiled modules) link to bindings
23+
# # # this way the bindings (and transitively lvgl_interface) get proper compilation flags
24+
# target_link_libraries(usermod INTERFACE usermod_lvgl)
25+
26+
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_LIST_DIR}/lvgl/src/*.c)
27+
28+
add_library(lvgl_interface INTERFACE)
29+
30+
target_sources(lvgl_interface INTERFACE ${SOURCES})
31+
target_compile_options(lvgl_interface INTERFACE ${LV_CFLAGS})
32+
33+
# # lvgl bindings target (the mpy module)
34+
35+
add_library(usermod_lvgl INTERFACE)
36+
target_sources(usermod_lvgl INTERFACE ${LV_SRC})
37+
target_include_directories(usermod_lvgl INTERFACE ${LV_INCLUDE})
38+
39+
40+
file(WRITE ${LV_MP} "")
41+
42+
target_link_libraries(usermod_lvgl INTERFACE lvgl_interface)
43+
44+
# # # make usermod (target declared by Micropython for all user compiled modules) link to bindings
45+
# # # this way the bindings (and transitively lvgl_interface) get proper compilation flags
46+
target_link_libraries(usermod INTERFACE usermod_lvgl)
47+

mkrules_usermod.cmake

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
2+
3+
find_package(Python3 REQUIRED COMPONENTS Interpreter)
4+
find_program(AWK awk mawk gawk)
5+
6+
set(LV_BINDINGS_DIR ${CMAKE_CURRENT_LIST_DIR})
7+
8+
# Common function for creating LV bindings
9+
10+
function(lv_bindings)
11+
set(_options)
12+
set(_one_value_args OUTPUT)
13+
set(_multi_value_args INPUT DEPENDS COMPILE_OPTIONS PP_OPTIONS GEN_OPTIONS FILTER)
14+
cmake_parse_arguments(
15+
PARSE_ARGV 0 LV
16+
"${_options}"
17+
"${_one_value_args}"
18+
"${_multi_value_args}"
19+
)
20+
21+
set(LV_PP ${LV_OUTPUT}.pp)
22+
set(LV_MPY_METADATA ${LV_OUTPUT}.json)
23+
24+
add_custom_command(
25+
OUTPUT
26+
${LV_PP}
27+
COMMAND
28+
${CMAKE_C_COMPILER} -E -DPYCPARSER ${LV_COMPILE_OPTIONS} ${LV_PP_OPTIONS} "${LV_CFLAGS}" -I ${LV_BINDINGS_DIR}/pycparser/utils/fake_libc_include ${MICROPY_CPP_FLAGS} ${LV_INPUT} > ${LV_PP}
29+
DEPENDS
30+
${LV_INPUT}
31+
${LV_DEPENDS}
32+
${LV_BINDINGS_DIR}/pycparser/utils/fake_libc_include
33+
IMPLICIT_DEPENDS
34+
C ${LV_INPUT}
35+
VERBATIM
36+
COMMAND_EXPAND_LISTS
37+
)
38+
39+
# if(ESP_PLATFORM)
40+
# target_compile_options(${COMPONENT_LIB} PRIVATE ${LV_COMPILE_OPTIONS})
41+
# else()
42+
# target_compile_options(usermod_lv_bindings INTERFACE ${LV_COMPILE_OPTIONS})
43+
# endif()
44+
45+
if (DEFINED LV_FILTER)
46+
47+
set(LV_PP_FILTERED ${LV_PP}.filtered)
48+
set(LV_AWK_CONDITION)
49+
foreach(_f ${LV_FILTER})
50+
string(APPEND LV_AWK_CONDITION "\$3!~\"${_f}\" && ")
51+
endforeach()
52+
string(APPEND LV_AWK_COMMAND "\$1==\"#\"{p=(${LV_AWK_CONDITION} 1)} p{print}")
53+
54+
# message("AWK COMMAND: ${LV_AWK_COMMAND}")
55+
56+
add_custom_command(
57+
OUTPUT
58+
${LV_PP_FILTERED}
59+
COMMAND
60+
${AWK} ${LV_AWK_COMMAND} ${LV_PP} > ${LV_PP_FILTERED}
61+
DEPENDS
62+
${LV_PP}
63+
VERBATIM
64+
COMMAND_EXPAND_LISTS
65+
)
66+
else()
67+
set(LV_PP_FILTERED ${LV_PP})
68+
endif()
69+
70+
add_custom_command(
71+
OUTPUT
72+
${LV_OUTPUT}
73+
COMMAND
74+
${Python3_EXECUTABLE} ${LV_BINDINGS_DIR}/gen/gen_mpy.py ${LV_GEN_OPTIONS} -MD ${LV_MPY_METADATA} -E ${LV_PP_FILTERED} ${LV_INPUT} > ${LV_OUTPUT} || (rm -f ${LV_OUTPUT} && /bin/false)
75+
DEPENDS
76+
${LV_BINDINGS_DIR}/gen/gen_mpy.py
77+
${LV_PP_FILTERED}
78+
COMMAND_EXPAND_LISTS
79+
)
80+
81+
endfunction()
82+
83+
# Definitions for specific bindings
84+
85+
set(LVGL_DIR ${LV_BINDINGS_DIR}/lvgl)
86+
87+
set(LV_MP ${CMAKE_BINARY_DIR}/lv_mp.c)
88+
# if(ESP_PLATFORM)
89+
# set(LV_ESPIDF ${CMAKE_BINARY_DIR}/lv_espidf.c)
90+
# endif()
91+
92+
# Function for creating all specific bindings
93+
94+
function(all_lv_bindings)
95+
96+
# LVGL bindings
97+
98+
file(GLOB_RECURSE LVGL_HEADERS ${LVGL_DIR}/src/*.h ${LV_BINDINGS_DIR}/lv_conf.h)
99+
lv_bindings(
100+
OUTPUT
101+
${LV_MP}
102+
INPUT
103+
${LVGL_DIR}/lvgl.h
104+
DEPENDS
105+
${LVGL_HEADERS}
106+
GEN_OPTIONS
107+
-M lvgl -MP lv
108+
)
109+
110+
111+
# ESPIDF bindings
112+
113+
# if(ESP_PLATFORM)
114+
# file(GLOB_RECURSE LV_ESPIDF_HEADERS ${IDF_PATH}/components/*.h ${LV_BINDINGS_DIR}/driver/esp32/*.h)
115+
# lv_bindings(
116+
# OUTPUT
117+
# ${LV_ESPIDF}
118+
# INPUT
119+
# ${LV_BINDINGS_DIR}/driver/esp32/espidf.h
120+
# DEPENDS
121+
# ${LV_ESPIDF_HEADERS}
122+
# GEN_OPTIONS
123+
# -M espidf
124+
# FILTER
125+
# i2s_ll.h
126+
# i2s_hal.h
127+
# esp_intr_alloc.h
128+
# soc/spi_periph.h
129+
# rom/ets_sys.h
130+
# soc/sens_struct.h
131+
# soc/rtc.h
132+
# driver/periph_ctrl.h
133+
# )
134+
# endif(ESP_PLATFORM)
135+
136+
endfunction()
137+
138+
# Add includes to CMake component
139+
140+
set(LV_INCLUDE
141+
${LV_BINDINGS_DIR}
142+
)
143+
144+
# Add sources to CMake component
145+
146+
set(LV_SRC
147+
${LV_MP}
148+
)
149+
150+
# if(ESP_PLATFORM)
151+
# LIST(APPEND LV_SRC
152+
# ${LV_BINDINGS_DIR}/driver/esp32/espidf.c
153+
# ${LV_BINDINGS_DIR}/driver/esp32/modrtch.c
154+
# ${LV_BINDINGS_DIR}/driver/esp32/sh2lib.c
155+
# ${LV_ESPIDF}
156+
# )
157+
# endif(ESP_PLATFORM)

ports/esp32/manifest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module("lv_utils.py", base_path="../../lib")

0 commit comments

Comments
 (0)