LittleFS example for loading a binary file from the converter into an lvgl image

Description

I want to use a binary image file from the converter and display it using lvgl from a littlefs mount.

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

Zephyr, nRF5340, nRF Connect for VSC

What LVGL version are you using?

8.3

What have you tried so far?

I have read this documentation on File System and LittleFS and tried with lv_fs_littlefs_set_driver(LV_FS_LITTLEFS_LETTER, my_lfs) but these calls are not recognized.

I’ve searched the forum and seen a few references but no answers.

Code to reproduce

The code block(s) should be formatted like:

/*From file*/
lv_img_set_src(screen_icon, "/lfs/my_icon.bin");

Here is the error I’m getting:

[00:00:00.299,957] <wrn> lvgl: (0.299, +299)     _lv_img_cache_open: Image draw cannot open the image resource  (in lv_img_cache.c line #125)
[00:00:00.300,140] <wrn> lvgl: (0.299, +0)       lv_draw_img: Image draw error  (in lv_draw_img.c line #83)
[00:00:00.312,225] <wrn> lvgl: (0.312, +13)      _lv_img_cache_open: Image draw cannot open the image resource  (in lv_img_cache.c line #125)
[00:00:00.312,377] <wrn> lvgl: (0.312, +0)       lv_draw_img: Image draw error  (in lv_draw_img.c line #83)
[00:00:00.324,676] <wrn> lvgl: (0.324, +12)      _lv_img_cache_open: Image draw cannot open the image resource  (in lv_img_cache.c line #125)
[00:00:00.324,829] <wrn> lvgl: (0.324, +0)       lv_draw_img: Image draw error  (in lv_draw_img.c line #83)
[00:00:00.336,547] <wrn> lvgl: (0.336, +12)      _lv_img_cache_open: Image draw cannot open the image resource  (in lv_img_cache.c line #125)
[00:00:00.336,700] <wrn> lvgl: (0.336, +0)       lv_draw_img: Image draw error  (in lv_draw_img.c line #83)
[00:00:00.348,419] <wrn> lvgl: (0.348, +12)      _lv_img_cache_open: Image draw cannot open the image resource  (in lv_img_cache.c line #125)
[00:00:00.348,602] <wrn> lvgl: (0.348, +0)       lv_draw_img: Image draw error  (in lv_draw_img.c line #83)
[00:00:00.360,321] <wrn> lvgl: (0.360, +12)      _lv_img_cache_open: Image draw cannot open the image resource  (in lv_img_cache.c line #125)
[00:00:00.360,473] <wrn> lvgl: (0.360, +0)       lv_draw_img: Image draw error  (in lv_draw_img.c line #83)

I’ve tried these two calls but they are not recognized and neither is the LV_FS_LITTLEFS_LETTER:

lv_fs_littlefs_set_driver(LV_FS_LITTLEFS_LETTER, mp); // Attach 'my_lfs' to driver letter 'S'
lv_fs_littlefs_set_driver('S', mp); // Attach 'my_lfs' to driver letter 'S'

When I try with this:

lv_img_set_src(screen_token_icon, "S:/lfs/my_icon.bin");

I get this error:

<wrn> lvgl: (0.255, +255)     lv_fs_open: Can't open file (S:/lfs/my_icon.bin): unknown driver letter        (in lv_fs.c line #68)

When debugging it this call:

lv_img_set_src(screen_icon, "/lfs/my_icon.bin");

Does it find the file in fs and if so, does it accept the header when read from flash?

I am getting this errror

[00:01:05.635,284] <wrn> lvgl: (65.635, +65298)  _lv_img_cache_open: Image draw cannot open the image resource  (in lv_img_cache.c line #125)

I am getting to here:

I’m running into this:

Getting called from here:

I’m just looking at the same problem on esp32.

I used the joltwallet LittleFS and get the same issue - I’m attempting to decode an sjpg file from a spiffs data partition (which is what the littlefs uses as storage).

The littlefs filesystem is initialised using esp_vfs_littlefs_register() - and then files can be read or written using fopen, fread etc - this seems to work AOK

What I can’t find is how to ‘attach’ a drive letter to the littlefs drive. So In the config of littlefs - I set base_path as ‘lfs’.(Setting it as ‘A:/lfs’ causes bad things to happen.

As an alternative - is it possible to use LV_USE_FS_STDIO and expect lvgl to just use standard C file operations (and assume that if using littlefs it’s expecting lvgl to initialise and handle everything - though I haven’t found anything to suggest this is the case) . However - a drive letter is still expected here?
I haven’t managed to find an example demonstrating the use of this anywhere - so maybe not so simple?

Martin

One step forward…

After multiple crashes using the USE_LittleFS setting (lv_driver_init etc)_ - I tried using the LV_USE_FS_STDIO setting - and initialised LittleFS as usual (it should work with regular fopen, fread etc calls)
Changing the filename to A:/lfs/file.sjpg (to suit - but I set the drive letter to ‘A’) and it can now open the file.
I now get ‘failed to get image info’ - but definitely a step in the right direction?

Martin

It does work with a regular jpeg file (albeit a small one) - I had to increase the program stack size - but once that error was out of the way - a small jpeg in the middle of the screen :slight_smile:

And it will decompress a full screen jog (240 x 320 in my case).

I had to tweak the delay settings to invert the colours (though initially I did this in the SendColors function).

Still no joy with an sjpg though “failed to get image info:” (I used the conversion code in the lvgl release)

Martin

It’s good you have it working. I should be able to hone in on the problem. I’m using an Indexed 1 bit image from the converter.

Yes - it took some time working through the code.
Set the drive letter in the conf file and the add to the file name when you want to access the file. LVGL seems to initialise the driver using this letter correctly. (You don’t need to do anything - it is handled automatically - spent a long time trying to work out how to attach the littlefs drive to a letter :frowning: )
The error you were getting was that it couldn’t open the file?
As mentioned try using the STDIO interface (which should work fine with littlefs) - and check that you can open the file (using fopen() I just printed success if the return was not 0)

I’m still not sure how to get the ‘actual’ littlefs interface to work (it uses lfs.h - which all looks good) or how to read sjpg files.