Skip to content

Commit

Permalink
feat: Update image loading method
Browse files Browse the repository at this point in the history
  • Loading branch information
espressif2022 committed Nov 1, 2024
1 parent c90025b commit 8a84465
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-examples-gh-pages-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name: "ESP-IDF build examples to github pages (push)"
on:
push:
branches:
- master
# - master
- feat/update_image_convert

jobs:

Expand Down
2 changes: 1 addition & 1 deletion examples/display/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
15 changes: 12 additions & 3 deletions examples/display/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

41 changes: 40 additions & 1 deletion examples/display/main/display_main.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions examples/display/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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.*"
5 changes: 3 additions & 2 deletions examples/display/main/lvgl_demo_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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
Expand Down
22 changes: 22 additions & 0 deletions examples/display/main/mmap_generate_images.h
Original file line number Diff line number Diff line change
@@ -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 */
};
6 changes: 6 additions & 0 deletions examples/display/partitions.csv
Original file line number Diff line number Diff line change
@@ -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,

0 comments on commit 8a84465

Please sign in to comment.