Skip to content

Commit

Permalink
feat(LVGL port): Generate C arrays for images during build process
Browse files Browse the repository at this point in the history
  • Loading branch information
espzav committed Apr 23, 2024
1 parent 9e882f3 commit d1ea532
Show file tree
Hide file tree
Showing 18 changed files with 340 additions and 635 deletions.
15 changes: 7 additions & 8 deletions components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Changelog

## 2.0.1
## 2.1.0

### Features
- Added unit test
- Allow to sleep main LVGL task
- Wake LVGL task from touch and display, when set big maximum sleep
- Allow to select display color mode (only with LVGL9)
- Added LVGL sleep feature: The esp_lvgl_port handling can sleep if the display and touch are inactive (only with LVGL9)
- Added support for different display color modes (only with LVGL9)
- Added script for generating C array images during build (depends on LVGL version)

### Fixes
- Apply display rotation from configuration
- Wait for stop task when deinit
- Added esp_idf_version.h
- Applied initial display rotation from configuration https://github.com/espressif/esp-bsp/pull/278
- Added blocking wait for LVGL task stop during esp_lvgl_port de-initialization https://github.com/espressif/esp-bsp/issues/277
- Added missing esp_idf_version.h include

## 2.0.0

Expand Down
24 changes: 24 additions & 0 deletions components/esp_lvgl_port/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,30 @@ If the SRAM is insufficient, you can use the PSRAM as a canvas and use a small t
}
```
### Generating images (C Array)
Images can be generated during build by adding these lines to end of the main CMakeLists.txt:
```
# Generate C array for each image
lvgl_port_create_c_image("images/logo.png" "images/" "ARGB8888" "NONE")
lvgl_port_create_c_image("images/image.png" "images/" "ARGB8888" "NONE")
# Add generated images to build
lvgl_port_add_images(${COMPONENT_LIB} "images/")
```
Usage of create C image function:
```
lvgl_port_create_c_image(input_image output_folder color_format compression)
```
Available color formats:
L8,I1,I2,I4,I8,A1,A2,A4,A8,ARGB8888,XRGB8888,RGB565,RGB565A8,RGB888,TRUECOLOR,TRUECOLOR_ALPHA,AUTO
Available compression:
NONE,RLE,LZ4
**Note:** Parameters `color_format` and `compression` are used only in LVGL 9.
## Power Saving
The LVGL port can be optimized for power saving mode. There are two main features.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
idf_component_register(SRCS "main.c"
INCLUDE_DIRS ".")

lvgl_port_create_c_image("images/esp_logo.png" "images/" "ARGB8888" "NONE")
lvgl_port_add_images(${COMPONENT_LIB} "images/")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.c
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion components/esp_lvgl_port/examples/touchscreen/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@

static const char *TAG = "EXAMPLE";

// LVGL image declare
LV_IMG_DECLARE(esp_logo)

/* LCD IO and panel */
static esp_lcd_panel_io_handle_t lcd_io = NULL;
static esp_lcd_panel_handle_t lcd_panel = NULL;
Expand Down Expand Up @@ -182,15 +185,19 @@ static esp_err_t app_lvgl_init(void)
.hres = EXAMPLE_LCD_H_RES,
.vres = EXAMPLE_LCD_V_RES,
.monochrome = false,
#if LVGL_VERSION_MAJOR >= 9
.color_format = LV_COLOR_FORMAT_RGB565,
#endif
.rotation = {
.swap_xy = false,
.mirror_x = true,
.mirror_y = true,
},
.flags = {
.buff_dma = true,
#if LVGL_VERSION_MAJOR >= 9
.swap_bytes = true,
#endif
}
};
lvgl_disp = lvgl_port_add_disp(&disp_cfg);
Expand Down Expand Up @@ -226,6 +233,11 @@ static void app_main_display(void)

/* Your LVGL objects code here .... */

/* Create image */
lv_obj_t *img_logo = lv_img_create(scr);
lv_img_set_src(img_logo, &esp_logo);
lv_obj_align(img_logo, LV_ALIGN_TOP_MID, 0, 20);

/* Label */
lv_obj_t *label = lv_label_create(scr);
lv_obj_set_width(label, EXAMPLE_LCD_H_RES);
Expand All @@ -236,7 +248,7 @@ static void app_main_display(void)
#else
lv_label_set_text(label, LV_SYMBOL_BELL" Hello world Espressif and LVGL "LV_SYMBOL_BELL"\n "LV_SYMBOL_WARNING" For simplier initialization, use BSP "LV_SYMBOL_WARNING);
#endif
lv_obj_align(label, LV_ALIGN_CENTER, 0, -30);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 20);

/* Button */
lv_obj_t *btn = lv_btn_create(scr);
Expand Down
2 changes: 1 addition & 1 deletion components/esp_lvgl_port/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2.0.0"
version: "2.1.0"
description: ESP LVGL port
url: https://github.com/espressif/esp-bsp/tree/master/components/esp_lvgl_port
dependencies:
Expand Down
66 changes: 66 additions & 0 deletions components/esp_lvgl_port/project_include.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# lvgl_port_create_c_image
#
# Create a C array of image for using with LVGL
function(lvgl_port_create_c_image image_path output_path color_format compression)

#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")
endif()

get_filename_component(image_full_path ${image_path} ABSOLUTE)
get_filename_component(output_full_path ${output_path} ABSOLUTE)
if(NOT EXISTS ${image_full_path})
message(FATAL_ERROR "Input image (${image_full_path}) not exists!")
endif()

message(STATUS "Generating C array image: ${image_path}")

#Create C array image by LVGL version
if(lvgl_ver VERSION_LESS "9.0.0")
if(${CONFIG_LV_COLOR_16_SWAP} STREQUAL "y")
set(color_format "RGB565SWAP")
else()
set(color_format "RGB565")
endif()

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 -r "${CMAKE_BINARY_DIR}/lvgl_image_converter/requirements.txt")
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)
get_filename_component(script_path ${lvgl_dir}/scripts/LVGLImage.py ABSOLUTE)
set(lvglimage_py ${PYTHON} ${script_path})

#Install dependencies
execute_process(COMMAND python -m pip3 install pypng)
execute_process(COMMAND python -m pip3 install lz4)

execute_process(COMMAND ${lvglimage_py}
--ofmt=C
--cf=${color_format}
--compress=${compression}
-o ${output_full_path}
${image_full_path})
endif()

endfunction()

# lvgl_port_add_images
#
# Add all images to build
function(lvgl_port_add_images component output_path)
#Add images to sources
file(GLOB_RECURSE IMAGE_SOURCES ${output_path}*.c)
target_sources(${component} PRIVATE ${IMAGE_SOURCES})
idf_build_set_property(COMPILE_OPTIONS "-DLV_LVGL_H_INCLUDE_SIMPLE=1" APPEND)
endfunction()
1 change: 1 addition & 0 deletions examples/display/main/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.c
12 changes: 11 additions & 1 deletion examples/display/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
idf_component_register(SRCS "display_main.c" "esp_logo.c" "esp_text.c" "lvgl_demo_ui.c"
idf_component_register(SRCS "display_main.c" "lvgl_demo_ui.c"
INCLUDE_DIRS ".")

if(COMMAND lvgl_port_create_c_image)
lvgl_port_create_c_image("images/esp_logo.png" "images/" "ARGB8888" "NONE")
lvgl_port_create_c_image("images/esp_text.png" "images/" "ARGB8888" "NONE")
lvgl_port_add_images(${COMPONENT_LIB} "images/")
else()
file(GLOB_RECURSE IMAGE_SOURCES images/*.c)
target_sources(${COMPONENT_LIB} PRIVATE ${IMAGE_SOURCES})
idf_build_set_property(COMPILE_OPTIONS "-DLV_LVGL_H_INCLUDE_SIMPLE=1" APPEND)
endif()
Loading

0 comments on commit d1ea532

Please sign in to comment.