Description
What MCU/Processor/Board and compiler are you using?
esp32s3 with arduino
What LVGL version are you using?
v8.3
What do you want to achieve?
Show a jpg or sjpg img saved on sd card
What have you tried so far?
I have tired the code below to check lvgl can read the file inside my sd card, result is output “Open OK”
void lv_fs_test(void)
{
lv_fs_file_t f;
lv_fs_res_t res;
res = lv_fs_open(&f, "S:readme.txt", LV_FS_MODE_RD);
if(res != LV_FS_RES_OK)
{
Serial.println("Open fail");
}
else
{
Serial.println("Open OK");
}
}
In lv_conf.h:
/* JPG + split JPG decoder library.
* Split JPG is a custom format optimized for embedded systems. */
#define LV_USE_SJPG 1
/*API for FATFS (needs to be added separately). Uses f_open, f_read, etc*/
#define LV_USE_FS_FATFS 1
#if LV_USE_FS_FATFS
#define LV_FS_FATFS_LETTER 'S' /*Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
#define LV_FS_FATFS_CACHE_SIZE 0 /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
Code to reproduce
void lvglSetup(){
// Init Display
gfx->begin();
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
gfx->fillScreen(RED);
delay(100);
gfx->fillScreen(GREEN);
delay(100);
gfx->fillScreen(BLUE);
delay(100);
gfx->fillScreen(BLACK);
delay(50);
lv_init();
delay(10);
screenWidth = gfx->width();
screenHeight = gfx->height();
disp_draw_buf1 = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * screenWidth * screenHeight / 8, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
disp_draw_buf2 = (lv_color_t *)heap_caps_malloc(sizeof(lv_color_t) * screenWidth * screenHeight / 8, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
lv_disp_draw_buf_init(&draw_buf, disp_draw_buf1, disp_draw_buf2, screenWidth * screenHeight / 8);
/* Initialize the display */
lv_disp_drv_init(&disp_drv);
/* Change the following line to your display resolution */
disp_drv.hor_res = screenWidth;
disp_drv.ver_res = screenHeight;
disp_drv.flush_cb = my_disp_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x000000),LV_STATE_DEFAULT );
lv_obj_set_style_bg_opa(lv_scr_act(), 255, LV_STATE_DEFAULT);
Serial.println("Setup done");
}
After the initialization of display, lvgl works cause the CPU usage and FPS count are shown.
In setup (SD card initialization omitted due to insignificance.):
void setup() {
lvglSetup();
lv_fs_fatfs_init();
lv_fs_test();
lv_obj_t *img= lv_img_create(lv_scr_act());
lv_split_jpeg_init();
lv_img_set_src(img, "S:icons/bilibili.sjpg");
lv_obj_set_style_bg_opa(img, 255, LV_STATE_DEFAULT);
lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
Serial.println("Icon showed");
}
Result till now
CPU usage and FPS count are shown → lvgl runs success
lv_fs_test() fuction give positive result → lvgl can read file inside my sd card
I don’t know what to do next? No idea where i missed, cause LV_SYMBOL can be shown
lv_img_set_src(img, LV_SYMBOL_OK);