I use LittlevGL as Arduino and use FileSystem with SD Card. i think i found bug after upload sketch, LittlevGL call drv.open_cb and then drv.read_cb and then drv.close_cb and then drv.open_cb and then drv.read_cb and then drv.close_cb (plz see Screenshots)
To Reproduce
#include <IOXGD.h>
#include <SPI.h>
#include <SD.h>
File f;
static lv_fs_res_t lv_sd_open(lv_fs_drv_t * drv, void * file_p, const char * fn, lv_fs_mode_t mode)
{
(void) drv; /*Unused*/
if (f) {
return LV_FS_RES_OK;
}
if (!SD.exists(fn)) {
Serial.print("File ");
Serial.print(fn);
Serial.println(" doesn't exist.");
return LV_FS_RES_UNKNOWN;
}
f = SD.open(fn, mode == LV_FS_MODE_WR ? FILE_WRITE : FILE_READ);
if (!f) {
Serial.println("Open " + String(fn) + " fail");
return LV_FS_RES_UNKNOWN;
} else {
Serial.println("Open " + String(fn) + " OK !");
f.seek(0);
/* 'file_p' is pointer to a file descriptor and
we need to store our file descriptor here*/
File *fp = (File*)file_p; /*Just avoid the confusing casings*/
*fp = f;
}
return LV_FS_RES_OK;
}
static lv_fs_res_t lv_sd_close(lv_fs_drv_t * drv, void * file_p)
{
(void) drv; /*Unused*/
Serial.println("File close");
//File* fp = (File*)file_p; /*Just avoid the confusing casings*/
f.close();
return LV_FS_RES_OK;
}
static lv_fs_res_t lv_sd_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
{
(void) drv; /*Unused*/
Serial.println("File read");
// File* fp = (File*)file_p; /*Just avoid the confusing casings*/
Serial.println("Read " + String(btr) + " bytes");
*br = f.read(buf, btr);
Serial.println("Return " + String(*br) + " bytes");
return LV_FS_RES_OK;
}
static lv_fs_res_t lv_sd_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos)
{
(void) drv; /*Unused*/
Serial.println("File seek");
// File* fp = (File*)file_p; /*Just avoid the confusing casings*/
f.seek(pos);
return LV_FS_RES_OK;
}
static lv_fs_res_t lv_sd_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
{
(void) drv; /*Unused*/
Serial.println("File tell");
// File* fp = (File*)file_p; /*Just avoid the confusing casings*/
*pos_p = f.position();
return LV_FS_RES_OK;
}
static lv_fs_res_t lv_sd_size(lv_fs_drv_t *drv, void *file_p, uint32_t *size_p) {
(void) drv; /*Unused*/
Serial.println("File size");
// File* fp = (File*)file_p; /*Just avoid the confusing casings*/
*size_p = f.size();
return LV_FS_RES_OK;
}
void setup() {
Serial.begin(115200);
gd.begin();
Serial.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!SD.begin(29)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
while (1);
} else {
Serial.println("Wiring is correct and a card is present.");
}
lv_fs_drv_t drv;
memset(&drv, 0, sizeof(lv_fs_drv_t)); /*Initialization*/
drv.letter = 'S'; /*An uppercase letter to identify the drive */
drv.file_size = sizeof(File); /*Size required to store a file object*/
drv.open_cb = lv_sd_open; /*Callback to open a file */
drv.close_cb = lv_sd_close; /*Callback to close a file */
drv.read_cb = lv_sd_read; /*Callback to read a file */
drv.seek_cb = lv_sd_seek; /*Callback to seek in a file (Move cursor) */
drv.tell_cb = lv_sd_tell; /*Callback to tell the cursor position */
drv.size_cb = lv_sd_size; /*Callback to tell a file's size */
lv_fs_drv_register(&drv); /*Finally register the drive*/
lv_obj_t * img_bin = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img_bin, "S:/EN.3-4/img/8.bin");
lv_obj_align(img_bin, NULL, LV_ALIGN_CENTER, 0, 0);
}
void loop() {
lv_task_handler();
delay(5);
}
note: gd.begin(); setup touch screen input and LCD and call lv_init();
Expected behavior
Now, picture not show on screen and after you help me. my screen will show correct picture.
So the problem is you think LittlevGL open-read-close too often?
If yes is it happen infinitely?
A few calls are normal because LittlevGL reads the header of the image (width, height etc)
/* Maximal horizontal and vertical resolution to support by the library.*/
#define LV_HOR_RES_MAX (800)
#define LV_VER_RES_MAX (480)
lv_conf.h(2)
/* Default image cache size. Image caching keeps the images opened.
* If only the built-in image formats are used there is no real advantage of caching.
* (I.e. no new image decoder is added)
* With complex image decoders (e.g. PNG or JPG) caching can save the continuous open/decode of images.
* However the opened images might consume additional RAM.
* LV_IMG_CACHE_DEF_SIZE must be >= 1 */
#define LV_IMG_CACHE_DEF_SIZE 1
WARNING: File: C:\Users\Max\AppData\Local\Arduino15\packages\Maixduino\hardware\k210\0.3.10\libraries\lv_maixduino\src\src\lv_draw\lv_img_cache.c#118: Image draw cannot open the image resource
So LittlevGL can’t open the image. Be sure your driver is working.
Take a look at this topic. It seems @Ulric_Denis was using the same library:
Please update it and send a Pull request. We can’t test it and it’s be add a tested version.
@embeddedt and I take care of core lvgl but we can not deal with all the projects. Therefore contribution is even more required and important in the hardware specific projects.