SPIFFS and ESP32 to display images

Description

i need to load a jpeg image and diplay it in TFT screen. the jpeg will stored in the spiffs in ESP32.
i already uploaded the images and can successfully read the image using SPIFFS api.

when using lvgl framework i registered a driver and try to read the same file through it. it always fails. ( can’t even open the file) it says file do not exist.

can someone help me to figure this out.

What MCU/Processor/Board and compiler are you using?

ESP32 WROOM32

What LVGL version are you using?

v7.7.0

What do you want to achieve?

Load image from SPIFFS and display it

What have you tried so far?

tried the lv_fs_if_pc.c and tried it with normal lv_fs.h api

Code to reproduce

esp_vfs_spiffs_conf_t conf = {
        .base_path = "/spiffs",
        .partition_label = NULL,
        .max_files = 5,
        .format_if_mount_failed = true
    };

    esp_err_t ret = esp_vfs_spiffs_register(&conf);

    if (ret != ESP_OK)
    {
        if (ret == ESP_FAIL)
        {
            ESP_LOGE(TAG, "Failed to mount or format filesystem");
        }
        else if (ret == ESP_ERR_NOT_FOUND)
        {
            ESP_LOGE(TAG, "Failed to find SPIFFS partition");
        }
        else
        {
            ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
        }
        return ESP_FAIL;
    }

    size_t total = 0, used = 0;
    ret = esp_spiffs_info(conf.partition_label, &total, &used);
    if (ret != ESP_OK)
    {
        ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
    }
    else
    {
        ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
    }

    lv_fs_drv_t drv;
    lv_fs_drv_init(&drv);

    drv.letter = 'F';
    drv.file_size = sizeof(file_t);
    drv.rddir_size = 0; //TODO: maybe not zero
    drv.open_cb = spiffs_driver_open;
    drv.read_cb = spiffs_driver_read;
    drv.close_cb = spiffs_driver_close;
    drv.seek_cb = spiffs_driver_seek;
    drv.tell_cb = spiffs_driver_tell;
    drv.ready_cb = NULL;
    drv.trunc_cb = NULL;
    drv.size_cb = NULL;
    drv.rename_cb = NULL;
    drv.write_cb = NULL;

    drv.dir_open_cb = NULL;
    drv.dir_read_cb = NULL;
    drv.dir_close_cb = NULL;
    drv.free_space_cb = NULL;


    lv_fs_drv_register(&drv);

    lv_fs_file_t f;
    lv_fs_res_t res;
    res = lv_fs_open(&f, "F:/spiffs/hello.txt", LV_FS_MODE_RD);
    if(res != LV_FS_RES_OK){
        ESP_LOGE(TAG,"file opened failed");
    }
    ESP_LOGE(TAG, "file opened %d",res);

    uint32_t read_num;
    uint8_t buf[8];
    res = lv_fs_read(&f, buf, 8, &read_num);
    ESP_LOGE(TAG, "file read %s",buf);
    

    lv_fs_close(&f);

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

How did you implement spiffs_driver_open?

Please add a lot of debug printfs in spiffs_driver_open to see the paths and flags and how they are different from the case when you use “bare” spiffs?

1 Like