From 8a84465710da3a5bdcbd191a18993c54a0e37211 Mon Sep 17 00:00:00 2001 From: xuxin Date: Fri, 1 Nov 2024 19:26:12 +0800 Subject: [PATCH] feat: Update image loading method --- .../build-examples-gh-pages-on-push.yml | 3 +- examples/display/CMakeLists.txt | 2 +- examples/display/main/CMakeLists.txt | 15 +++++-- examples/display/main/display_main.c | 41 ++++++++++++++++++- examples/display/main/idf_component.yml | 6 ++- examples/display/main/lvgl_demo_ui.c | 5 ++- examples/display/main/mmap_generate_images.h | 22 ++++++++++ examples/display/partitions.csv | 6 +++ 8 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 examples/display/main/mmap_generate_images.h create mode 100644 examples/display/partitions.csv diff --git a/.github/workflows/build-examples-gh-pages-on-push.yml b/.github/workflows/build-examples-gh-pages-on-push.yml index 340804d3..fd5b4bf3 100644 --- a/.github/workflows/build-examples-gh-pages-on-push.yml +++ b/.github/workflows/build-examples-gh-pages-on-push.yml @@ -3,7 +3,8 @@ name: "ESP-IDF build examples to github pages (push)" on: push: branches: - - master + # - master + - feat/update_image_convert jobs: diff --git a/examples/display/CMakeLists.txt b/examples/display/CMakeLists.txt index db3ca766..535c5dde 100644 --- a/examples/display/CMakeLists.txt +++ b/examples/display/CMakeLists.txt @@ -4,6 +4,6 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) -set(COMPONENTS main) # "Trim" the build. Include the minimal set of components; main and anything it depends on. +# set(COMPONENTS main) # "Trim" the build. Include the minimal set of components; main and anything it depends on. include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(display) diff --git a/examples/display/main/CMakeLists.txt b/examples/display/main/CMakeLists.txt index 838a18b1..12a3f1ce 100644 --- a/examples/display/main/CMakeLists.txt +++ b/examples/display/main/CMakeLists.txt @@ -1,6 +1,15 @@ idf_component_register(SRCS "display_main.c" "lvgl_demo_ui.c" INCLUDE_DIRS ".") -lvgl_port_create_c_image("images/esp_logo.png" "images/gen/" "ARGB8888" "NONE") -lvgl_port_create_c_image("images/esp_text.png" "images/gen/" "ARGB8888" "NONE") -lvgl_port_add_images(${COMPONENT_LIB} "images/gen/") +spiffs_create_partition_assets( + storage + "./images" + FLASH_IN_PROJECT + MMAP_FILE_SUPPORT_FORMAT ".png" + MMAP_SUPPORT_RAW + MMAP_RAW_COLOR_FORMAT "ARGB8888" +) + +idf_component_get_property(lib espressif__esp_lv_fs COMPONENT_LIB) +target_compile_options(${lib} PRIVATE -Wno-incompatible-pointer-types -Wno-implicit-function-declaration) + diff --git a/examples/display/main/display_main.c b/examples/display/main/display_main.c index a7115d6b..a5fe8791 100644 --- a/examples/display/main/display_main.c +++ b/examples/display/main/display_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -9,11 +9,50 @@ #include "lvgl.h" #include "esp_log.h" +#include "esp_lv_fs.h" +#include "mmap_generate_images.h" + extern void example_lvgl_demo_ui(lv_obj_t *scr); +static const char *TAG = "display"; + +static mmap_assets_handle_t mmap_drive_handle; +static esp_lv_fs_handle_t fs_drive_handle; + +esp_err_t mount_mmap_filesystem(void) +{ + esp_err_t ret; + + const mmap_assets_config_t asset_cfg = { + .partition_label = "storage", + .max_files = MMAP_IMAGES_FILES, + .checksum = MMAP_IMAGES_CHECKSUM, + .flags = {.mmap_enable = true} + }; + ret = mmap_assets_new(&asset_cfg, &mmap_drive_handle); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to initialize %s", "storage"); + return ret; + } + + fs_cfg_t fs_cfg; + + fs_cfg.fs_letter = 'A'; + fs_cfg.fs_assets = mmap_drive_handle; + fs_cfg.fs_nums = MMAP_IMAGES_FILES; + + ret = esp_lv_fs_desc_init(&fs_cfg, &fs_drive_handle); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to initialize FS for %s", "storage"); + return ret; + } + + return ESP_OK; +} void app_main(void) { bsp_display_start(); + mount_mmap_filesystem(); ESP_LOGI("example", "Display LVGL animation"); bsp_display_lock(0); diff --git a/examples/display/main/idf_component.yml b/examples/display/main/idf_component.yml index 772f667d..61b6cfd0 100644 --- a/examples/display/main/idf_component.yml +++ b/examples/display/main/idf_component.yml @@ -1,6 +1,8 @@ description: BSP Display example dependencies: - esp_wrover_kit: + esp-box: version: "*" - override_path: "../../../bsp/esp_wrover_kit" + override_path: "../../../bsp/esp-box" + esp_mmap_assets: "1.*" + esp_lv_fs: "0.1.*" diff --git a/examples/display/main/lvgl_demo_ui.c b/examples/display/main/lvgl_demo_ui.c index 9eb6da10..83746295 100644 --- a/examples/display/main/lvgl_demo_ui.c +++ b/examples/display/main/lvgl_demo_ui.c @@ -54,7 +54,8 @@ static void anim_timer_cb(lv_timer_t *timer) // Create new image and make it transparent img_text = lv_img_create(scr); - lv_img_set_src(img_text, &esp_text); + lv_img_set_src(img_text, "A:esp_text.bin"); + lv_obj_set_style_img_opa(img_text, 0, 0); } @@ -78,7 +79,7 @@ void example_lvgl_demo_ui(lv_obj_t *scr) { // Create image img_logo = lv_img_create(scr); - lv_img_set_src(img_logo, &esp_logo); + lv_img_set_src(img_logo, "A:esp_logo.bin"); lv_obj_center(img_logo); // Create arcs diff --git a/examples/display/main/mmap_generate_images.h b/examples/display/main/mmap_generate_images.h new file mode 100644 index 00000000..c3be86aa --- /dev/null +++ b/examples/display/main/mmap_generate_images.h @@ -0,0 +1,22 @@ +/* + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @file + * @brief This file was generated by esp_mmap_assets, don't modify it + */ + +#pragma once + +#include "esp_mmap_assets.h" + +#define MMAP_IMAGES_FILES 2 +#define MMAP_IMAGES_CHECKSUM 0xC382 + +enum MMAP_IMAGES_LISTS { + MMAP_IMAGES_ESP_LOGO_BIN = 0, /*!< esp_logo.bin */ + MMAP_IMAGES_ESP_TEXT_BIN = 1, /*!< esp_text.bin */ +}; diff --git a/examples/display/partitions.csv b/examples/display/partitions.csv new file mode 100644 index 00000000..b895d62e --- /dev/null +++ b/examples/display/partitions.csv @@ -0,0 +1,6 @@ +# Name, Type, SubType, Offset, Size, Flags +# Note: if you change the phy_init or app partition offset, make sure to change the offset in Kconfig.projbuild +nvs, data, nvs, 0x9000, 0x6000, +phy_init, data, phy, 0xf000, 0x1000, +factory, app, factory, 0x10000, 1M, +storage, data, spiffs, 0x110000,0x2f0000,