adafruit / Adafruit_LvGL_Glue

“Glue” library between LittlevGL and Adafruit GFX (SPITFT)
Other
35 stars 14 forks source link

Support for SD card reader on 3.5” Featherwing #10

Closed photomoose closed 2 years ago

photomoose commented 3 years ago

Before I look at implementing LVGL's file system abstraction myself (to read images from an SD card), I thought I'd just check here whether this is something that has already been implemented (doesn't appear to be in this library), is currently under development or whether there are any known issues with doing so...

https://docs.lvgl.io/latest/en/html/overview/file-system.html

Thanks.

ladyada commented 3 years ago

ah! very good to ask first. we do have a very intense filesystem setup on adafruit boards. note that boards can have SD cards OR they may have internal SPI/QSPI flash memory. both can be exposed over USB. what hardware are you looking to adapt? we can give you example code to look at

photomoose commented 3 years ago

Hey @ladyada,

I have a HUZZAH ESP32 Feather paired with a 3.5" TFT Featherwing; I was planning on loading images from the SD card reader embedded on the TFT screen. I am aware of your existing Adafruit ImageReader library, but I'm not entirely sure this will play nicely with LVGL...

The LVGL documentation states that in order to use external image files, I first need to convert them to a binary format then load them using LVGL's file system (see https://docs.lvgl.io/latest/en/html/widgets/img.html):

To use external files, you also need to convert the image files using the online converter tool but now you should select the binary Output format. You also need to use LVGL's file system module and register a driver with some functions for the basic file operation. Go to the File system to learn more. To set an image sourced from a file, use lv_img_set_src(img, "S:folder1/my_img.bin").

It's also possible to use a pixel array generated by their online tool (which I guess can also be obtained from the Adafruit ImageReader library - maybe the loadBMP() function), however in order to use this within LVGL, it needs to be wrapped in a lv_img_dsc_t type, which is what the LV_IMG_DECLARE(var_name) macro does:

To generate a pixel array from a PNG, JPG or BMP image, use the Online image converter tool and set the converted image with its pointer: lv_img_set_src(img1, &converted_img_var); To make the variable visible in the C file, you need to declare it with LV_IMG_DECLARE(converted_img_var).

If you've got any thoughts on any existing functionality that will use images from an SD card for LVGL, then I'm all ears, otherwise I might take a look at implementing the file system abstraction for Glue. :-)

Thanks!

ladyada commented 3 years ago

ok it sounds like you really just need to use their file format, we recommend SDfat for the filesystem. since FS is separate from GFX, whatever they have now should def support SD card?

photomoose commented 3 years ago

Right, I've managed to implement LVGL's file system abstraction for 3.5" TFT Featherwing as part of Glue. The only additional dependency I've brought in is the Adafruit fork of SDFat - however I've made this option available via preprocessor directives, so as not to bring in unnecessary dependencies for users that do not require it. I'll knock up an example project of its usage and create a PR for review.

As it turns out, to load an image from SD and draw it on the TFT is rather slow - approximately 15-20 seconds for a full screen image...

Whilst working on the above, I noticed a bug with Glue's existing implementation for the lv_flush_callback function - see #11 .

ladyada commented 3 years ago

if you're talking about #defines, nobody in arduino can set them. instead, have dependancies and let the compiler/linker optimize them out.

photomoose commented 3 years ago

I've implemented the file system abstraction in #12 - this works well on an ESP32 Feather with a 3.5" TFT Featherwing.