ESP LV FS

[English]

esp_lv_fs 允许 LVGL 使用文件系统来访问资源。该组件依赖 esp_mmap_assets,以高效管理文件操作,并支持多个分区。

功能

  • 基于 esp_mmap_assets 用于文件系统创建。

  • 支持标准文件操作:fopen, fclose, fread, ftell, fseek。

  • 使用 esp_partition_read API 实现高效文件访问。

  • 支持多个分区。

依赖

依赖组件 esp_mmap_assets 。 它提供文件偏移索引关系。

应用示例

注册文件系统

在 LVGL 启动后注册文件系统。

#include "esp_lv_fs.h"
#include "esp_mmap_assets.h"

esp_lv_fs_handle_t fs_drive_a_handle;
mmap_assets_handle_t mmap_drive_a_handle;

const mmap_assets_config_t asset_cfg = {
   .partition_label = "assets_A",
   .max_files = MMAP_DRIVE_A_FILES,
   .checksum = MMAP_DRIVE_A_CHECKSUM,
   .flags = {
      .mmap_enable = true,
   }
};
mmap_assets_new(&asset_cfg, &mmap_drive_a_handle);

const fs_cfg_t fs_drive_a_cfg = {
   .fs_letter = 'A',
   .fs_assets = mmap_drive_a_handle,
   .fs_nums = MMAP_DRIVE_A_FILES
};
esp_lv_fs_desc_init(&fs_drive_a_cfg, &fs_drive_a_handle);

API 参考

Header File

Functions

esp_err_t esp_lv_fs_desc_init(const fs_cfg_t *cfg, esp_lv_fs_handle_t *ret_handle)

Initialize file descriptors for the filesystem.

This function sets up the filesystem by initializing file descriptors based on the provided configuration. It allocates necessary memory and populates the file descriptors with information about the assets.

参数
  • cfg[in] Pointer to the filesystem configuration structure.

  • ret_handle[out] Pointer to the handle that will hold the initialized filesystem instance.

返回

  • ESP_OK: Success

  • ESP_ERR_INVALID_ARG: Invalid argument

  • ESP_ERR_NO_MEM: Memory allocation failed

esp_err_t esp_lv_fs_desc_deinit(esp_lv_fs_handle_t handle)

Deinitialize the filesystem and clean up resources.

This function cleans up the filesystem by freeing allocated memory for file descriptors and other resources associated with the provided handle.

参数

handle[in] Handle to the filesystem instance to be deinitialized.

返回

  • ESP_OK: Success

  • ESP_ERR_INVALID_ARG: Invalid argument

Structures

struct fs_cfg_t

Configuration structure for the filesystem.

Public Members

char fs_letter

Filesystem letter identifier

int fs_nums

Number of filesystem instances

mmap_assets_handle_t fs_assets

Handle to memory-mapped assets

Type Definitions

typedef void *esp_lv_fs_handle_t

Filesystem handle type definition.