Description
I have been able ta create a filesystem based on the stdio one and load a .bin image into the system. Previously i have been doing it with .c converted files including them into the program but I had to add more images recently and the program upload times and increased a lot.
That’s why I made a partition to upload images with a SPIFFS filesystem and I´m able to load them into the screen but the time to complete draw the image into the display has increased a lot. I think that the solution is in using _lv_img_cache_open but I didn’t find any example of how to do it.
What MCU/Processor/Board and compiler are you using?
ESP32-S3 with ESP-IDF4.4.3
What LVGL version are you using?
LVGL 8.2
What do you want to achieve?
Faster upload to display or caching the image before showing them.
What have you tried so far?
use of _lv_img_cache_open but to no avail.
Code to reproduce
Display image:
void showLogo(void)
{
Logo_page = lv_obj_create(NULL);
AdvanticsysLogo_img = lv_img_create(Logo_page); // this is where we create the container to hold the image
//lv_color_t color = lv_color_make(255, 255, 255);
//_lv_img_cache_open("F:images/HelloWorld.bin",color, 1);
lv_img_set_src(AdvanticsysLogo_img, "F:images/HelloWorld.bin"); // this is where we give the source of the image to the container
lv_scr_load(Logo_page);
}
Filesystem
static void * fs_open(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
{
LV_UNUSED(drv);
const char * flags = "";
if(mode == LV_FS_MODE_WR) flags = "wb";
else if(mode == LV_FS_MODE_RD) flags = "rb";
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = "rb+";
/*Make the path relative to the current directory (the projects root folder)*/
char buf[256];
char complete_path[strlen(path) + 1];
complete_path[0] = '/';
complete_path[1] = '\0';
strcat(complete_path, path);
return fopen(complete_path, flags);
}
static lv_fs_res_t fs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
{
LV_UNUSED(drv);
*br = fread(buf, 1, btr, file_p);
return (int32_t)(*br) < 0 ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
}
static lv_fs_res_t fs_close(lv_fs_drv_t * drv, void * file_p)
{
LV_UNUSED(drv);
fclose(file_p);
return LV_FS_RES_OK;
}
static lv_fs_res_t fs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence)
{
LV_UNUSED(drv);
fseek(file_p, pos, whence);
return LV_FS_RES_OK;
}
static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
{
LV_UNUSED(drv);
*pos_p = ftell(file_p);
return LV_FS_RES_OK;
}
esp_err_t spiffs_driver_init(void)
{
esp_vfs_spiffs_conf_t conf1 = {
.base_path = "/images",
.partition_label = "images",
.max_files = 100,
.format_if_mount_failed = true
};
ESP_LOGW(TAG, "MOUNTING FILESYSTEM IN IMAGE");
esp_err_t ret = esp_vfs_spiffs_register(&conf1);
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(conf1.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, "MOUNT IMAGE OK: Partition size: total: %d, used: %d", total, used);
}
static lv_fs_drv_t drv; /*A driver descriptor*/
lv_fs_drv_init(&drv);
drv.letter = 'F';
drv.open_cb = fs_open;
drv.read_cb = fs_read;
drv.close_cb = fs_close;
drv.seek_cb = fs_seek;
drv.tell_cb = fs_tell;
drv.dir_open_cb = NULL;
drv.dir_read_cb = NULL;
drv.dir_close_cb = NULL;
lv_fs_drv_register(&drv);
ESP_LOGW(TAG, "FINISHING MOUNTING IMAGE FILESYSTEM ");
return ESP_OK;
}```