Skip to content

Commit

Permalink
Merge pull request #363 from espressif/fix/lvgl_local_component
Browse files Browse the repository at this point in the history
fix(esp_lvgl_port): Fix esp_lvgl_port with local LVGL component
  • Loading branch information
tore-espressif authored Aug 12, 2024
2 parents f4f51f4 + c5d1193 commit bf20d6c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 32 deletions.
4 changes: 4 additions & 0 deletions components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.3.1
- Fixed LVGL version resolution if LVGL is not a managed component
- Fixed link error with LVGL v9.2

## 2.3.0
- Fixed LVGL port for using with LVGL9 OS FreeRTOS enabled
- Fixed bad handled touch due to synchronization timer task
Expand Down
65 changes: 44 additions & 21 deletions components/esp_lvgl_port/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
include($ENV{IDF_PATH}/tools/cmake/version.cmake) # $ENV{IDF_VERSION} was added after v4.3...

if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_LESS "4.4")
return()
return()
endif()

#Get LVGL version
idf_component_get_property(lvgl_ver lvgl__lvgl COMPONENT_VERSION)
if(lvgl_ver EQUAL "")
idf_component_get_property(lvgl_ver lvgl COMPONENT_VERSION)
# This component uses a CMake workaround, so we can compile esp_lvgl_port for both LVGL8.x and LVGL9.x
# At the time of idf_component_register() we don't know which LVGL version is used, so we only register an INTERFACE component (with no sources)
# Later, when we know the LVGL version, we create another CMake library called 'lvgl_port_lib' and link it to the 'esp_lvgl_port' INTERFACE component
idf_component_register(
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES "esp_lcd")

# Get LVGL version
idf_build_get_property(build_components BUILD_COMPONENTS)
if(lvgl IN_LIST build_components)
set(lvgl_name lvgl) # Local component
set(lvgl_ver $ENV{LVGL_VERSION}) # Get the version from env variable (set from LVGL v9.2)
else()
set(lvgl_name lvgl__lvgl) # Managed component
idf_component_get_property(lvgl_ver ${lvgl_name} COMPONENT_VERSION) # Get the version from esp-idf build system
endif()

if("${lvgl_ver}" STREQUAL "")
message("Could not determine LVGL version, assuming v9.x")
set(lvgl_ver "9.0.0")
endif()
message(STATUS "LVGL version: ${lvgl_ver}")

#Select folder by LVGL version
# Select folder by LVGL version
message(STATUS "LVGL version: ${lvgl_ver}")
if(lvgl_ver VERSION_LESS "9.0.0")
message(VERBOSE "Compiling esp_lvgl_port for LVGL8")
set(PORT_FOLDER "lvgl8")
Expand All @@ -20,15 +37,8 @@ else()
set(PORT_FOLDER "lvgl9")
endif()

# Add LVGL port extensions
set(PORT_PATH "src/${PORT_FOLDER}")

idf_component_register(
SRCS "${PORT_PATH}/esp_lvgl_port.c" "${PORT_PATH}/esp_lvgl_port_disp.c"
INCLUDE_DIRS "include"
PRIV_INCLUDE_DIRS "priv_include"
REQUIRES "esp_lcd"
PRIV_REQUIRES "esp_timer")

set(ADD_SRCS "")
set(ADD_LIBS "")

Expand Down Expand Up @@ -66,9 +76,22 @@ if("usb_host_hid" IN_LIST build_components)
list(APPEND ADD_LIBS idf::usb_host_hid)
endif()

if(ADD_SRCS)
target_sources(${COMPONENT_LIB} PRIVATE ${ADD_SRCS})
endif()
if(ADD_LIBS)
target_link_libraries(${COMPONENT_LIB} PRIVATE ${ADD_LIBS})
endif()
# Here we create the real lvgl_port_lib
add_library(lvgl_port_lib STATIC
${PORT_PATH}/esp_lvgl_port.c
${PORT_PATH}/esp_lvgl_port_disp.c
${ADD_SRCS}
)
target_include_directories(lvgl_port_lib PUBLIC "include")
target_include_directories(lvgl_port_lib PRIVATE "priv_include")
target_link_libraries(lvgl_port_lib PUBLIC
idf::esp_lcd
idf::${lvgl_name}
)
target_link_libraries(lvgl_port_lib PRIVATE
idf::esp_timer
${ADD_LIBS}
)

# Finally, link the lvgl_port_lib its esp-idf interface library
target_link_libraries(${COMPONENT_LIB} INTERFACE lvgl_port_lib)
32 changes: 21 additions & 11 deletions components/esp_lvgl_port/project_include.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
# Create a C array of image for using with LVGL
function(lvgl_port_create_c_image image_path output_path color_format compression)

#Get Python
idf_build_get_property(python PYTHON)

#Get LVGL version
idf_component_get_property(lvgl_ver lvgl__lvgl COMPONENT_VERSION)
set(LVGL_NAME "lvgl__lvgl")
if(lvgl_ver EQUAL "")
idf_component_get_property(lvgl_ver lvgl COMPONENT_VERSION)
set(LVGL_NAME "lvgl")
idf_build_get_property(build_components BUILD_COMPONENTS)
if(lvgl IN_LIST build_components)
set(lvgl_name lvgl) # Local component
set(lvgl_ver $ENV{LVGL_VERSION}) # Get the version from env variable (set from LVGL v9.2)
else()
set(lvgl_name lvgl__lvgl) # Managed component
idf_component_get_property(lvgl_ver ${lvgl_name} COMPONENT_VERSION) # Get the version from esp-idf build system
endif()

if("${lvgl_ver}" STREQUAL "")
message("Could not determine LVGL version, assuming v9.x")
set(lvgl_ver "9.0.0")
endif()

get_filename_component(image_full_path ${image_path} ABSOLUTE)
Expand All @@ -30,22 +40,22 @@ function(lvgl_port_create_c_image image_path output_path color_format compressio

execute_process(COMMAND git clone https://github.com/W-Mai/lvgl_image_converter.git "${CMAKE_BINARY_DIR}/lvgl_image_converter")
execute_process(COMMAND git checkout 9174634e9dcc1b21a63668969406897aad650f35 WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/lvgl_image_converter" OUTPUT_QUIET)
execute_process(COMMAND python -m pip install --upgrade pip)
execute_process(COMMAND python -m pip install pillow==10.3.0)
execute_process(COMMAND ${python} -m pip install --upgrade pip)
execute_process(COMMAND ${python} -m pip install pillow==10.3.0)
#execute_process(COMMAND python -m pip install -r "${CMAKE_BINARY_DIR}/lvgl_image_converter/requirements.txt")
execute_process(COMMAND ${PYTHON} "${CMAKE_BINARY_DIR}/lvgl_image_converter/lv_img_conv.py"
execute_process(COMMAND ${python} "${CMAKE_BINARY_DIR}/lvgl_image_converter/lv_img_conv.py"
-ff C
-f true_color_alpha
-cf ${color_format}
-o ${output_full_path}
${image_full_path})
else()
idf_component_get_property(lvgl_dir ${LVGL_NAME} COMPONENT_DIR)
idf_component_get_property(lvgl_dir ${lvgl_name} COMPONENT_DIR)
get_filename_component(script_path ${lvgl_dir}/scripts/LVGLImage.py ABSOLUTE)
set(lvglimage_py ${PYTHON} ${script_path})
set(lvglimage_py ${python} ${script_path})

#Install dependencies
execute_process(COMMAND python -m pip install pypng lz4)
execute_process(COMMAND ${python} -m pip install pypng lz4 OUTPUT_QUIET)

execute_process(COMMAND ${lvglimage_py}
--ofmt=C
Expand Down

0 comments on commit bf20d6c

Please sign in to comment.