Skip to content

Commit

Permalink
Support building as micropython USER_C_MODULE.
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-anl committed Nov 11, 2024
1 parent 465ef19 commit 1fb4224
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 1 deletion.
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
22 changes: 22 additions & 0 deletions manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys

include("$(MPY_DIR)/extmod/asyncio")

freeze("lib", (
"display_driver.py",
"display_driver_utils.py",
"fs_driver.py",
"lv_colors.py",
"lv_utils.py",
"tpcal.py",
"utils.py",
), opt=0)

require("aiorepl")

if sys.platform in ("linux"):
freeze("driver/linux", (
"evdev.py",
"lv_timer.py",
), opt=1)

8 changes: 8 additions & 0 deletions micropython.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# For detauils see: https://docs.micropython.org/en/latest/develop/cmodules.html

set(LVGL_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})

include(${CMAKE_CURRENT_LIST_DIR}/env_support/cmake/micropython.cmake)

# Link our INTERFACE library to the usermod target.
target_link_libraries(usermod INTERFACE lvgl_interface)
103 changes: 103 additions & 0 deletions micropython.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
################################################################################
# LVGL build rules for ports based on Makefile

# For details see: https://docs.micropython.org/en/latest/develop/cmodules.html

LVGL_BINDING_DIR := $(USERMOD_DIR)

LVGL_DIR = $(LVGL_BINDING_DIR)/lvgl
LVGL_GENERIC_DRV_DIR = $(LVGL_BINDING_DIR)/driver/generic

ifeq ($(wildcard $(LVGL_DIR)/.),,)
$(info lvgl submodule not init)
else
# This listing of all lvgl src files is used by make to track when the bindings need to be regenerated
ALL_LVGL_SRC = $(shell find $(LVGL_DIR) -type f -name '*.h') $(LVGL_BINDING_DIR)/lv_conf.h
endif

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)
INC += -I$(LVGL_BINDING_DIR) -I$(LVGL_BINDING_DIR)/include -I$(LVGL_DIR)/src
CFLAGS_USERMOD += $(INC) $(LV_CFLAGS)

ifneq ($(MICROPY_FLOAT_IMPL),double)
# Tiny TTF library needs a number of math.h double functions
CFLAGS_USERMOD += -DLV_USE_TINY_TTF=0
endif

# chain lvgl submodule check off the micropython submodules rule.
LVGL_SUBMODULES = lvgl pycparser
submodules: lvgl_submodule
lvgl_submodule:
$(ECHO) "Updating submodules: $(LVGL_SUBMODULES)"
$(Q)cd $(LVGL_BINDING_DIR) && git submodule sync $(LVGL_SUBMODULES)
$(Q)cd $(LVGL_BINDING_DIR) && git submodule update --init $(LVGL_SUBMODULES)
.PHONY: lvgl_submodule

# Generate the main micropython bindings library
$(LVGL_MPY): $(ALL_LVGL_SRC) $(LVGL_BINDING_DIR)/gen/gen_mpy.py
$(ECHO) "LVGL-GEN $@"
$(Q)mkdir -p $(dir $@)
$(Q)$(CPP) $(CFLAGS_USERMOD) -DPYCPARSER -x c -I $(LVGL_BINDING_DIR)/pycparser/utils/fake_libc_include $(INC) $(LVGL_DIR)/lvgl.h > $(LVGL_PP)
$(Q)$(PYTHON) $(LVGL_BINDING_DIR)/gen/gen_mpy.py -M lvgl -MP lv -MD $(LVGL_MPY_METADATA) -E $(LVGL_PP) $(LVGL_DIR)/lvgl.h > $@

# Add all lvgl source files to the module.
SRC_USERMOD += $(shell find $(LVGL_DIR)/src $(LVGL_DIR)/examples $(LVGL_GENERIC_DRV_DIR) -type f -name "*.c")
SRC_USERMOD += $(LVGL_MPY)

CFLAGS_USERMOD += -Wno-unused-function

FROZEN_MANIFEST += $(LVGL_BINDING_DIR)/manifest.py

################################################################################
# Per-port Support

MICROPY_PORT = $(notdir $(CURDIR))

ifeq ($(MICROPY_PORT),unix)
# This section only included when building the micropython unix port
UNAME_S := $(shell uname -s)

ifneq ($(UNAME_S),Darwin)
# On macos enable framebuffer support
CFLAGS_USERMOD += -DMICROPY_FB=1
endif

ifneq (,$(shell which pkg-config))
# Linux Support: if pkg-config is installed use it to
# check for and use optional libraries

SDL_CFLAGS_USERMOD := $(shell pkg-config --silence-errors --cflags sdl2)
SDL_LDFLAGS_USERMOD := $(shell pkg-config --silence-errors --libs sdl2)
ifneq ($(SDL_LDFLAGS_USERMOD),)
CFLAGS_USERMOD += $(SDL_CFLAGS_USERMOD) -DMICROPY_SDL=1
LDFLAGS_USERMOD += $(SDL_LDFLAGS_USERMOD)
endif

RLOTTIE_CFLAGS_USERMOD := $(shell pkg-config --silence-errors --cflags rlottie)
RLOTTIE_LDFLAGS_USERMOD := $(shell pkg-config --silence-errors --libs rlottie)
ifneq ($(RLOTTIE_LDFLAGS_USERMOD),)
CFLAGS_USERMOD += $(RLOTTIE_CFLAGS_USERMOD) -DMICROPY_RLOTTIE=1
LDFLAGS_USERMOD += $(RLOTTIE_LDFLAGS_USERMOD)
endif

FREETYPE_CFLAGS_USERMOD := $(shell pkg-config --silence-errors --cflags freetype2)
FREETYPE_LDFLAGS_USERMOD := $(shell pkg-config --silence-errors --libs freetype2)
ifneq ($(FREETYPE_LDFLAGS_USERMOD),)
CFLAGS_USERMOD += $(FREETYPE_CFLAGS_USERMOD) -DMICROPY_FREETYPE=1
LDFLAGS_USERMOD += $(FREETYPE_LDFLAGS_USERMOD)
endif

FFMPEG_LIBS := libavformat libavcodec libswscale libavutil
FFMPEG_CFLAGS_USERMOD := $(shell pkg-config --silence-errors --cflags $(FFMPEG_LIBS))
FFMPEG_LDFLAGS_USERMOD := $(shell pkg-config --silence-errors --libs $(FFMPEG_LIBS))
ifneq ($(FFMPEG_LDFLAGS_USERMOD),)
CFLAGS_USERMOD += $(FFMPEG_CFLAGS_USERMOD) -DMICROPY_FFMPEG=1
LDFLAGS_USERMOD += $(FFMPEG_LDFLAGS_USERMOD)
endif

endif # Linux

endif # unix port

0 comments on commit 1fb4224

Please sign in to comment.