How to tell SLS to load images from file in generated code?

What do you want to achieve?

We want SLS to add calls like:

lv_img_set_src(icon, “S:my_icon.bin”)

to make LVGL load bitmaps from an external file system.
We have lots of them, won’t fit in flash code area so compiling .C sources containing all the bitmaps is not an option.

Avoid linking the .C bitmap files is trivial; but we dont find a way to tell SLS to keep bitmaps on file adding the necessary lv_img_set_src() calls.

What have you tried so far?

Can manually add the necessary calls, but is very cumbersome, specially tracking each bitmap addition, and i’m not able to find a way that does’nt need re-editing after each export.

Screenshot or video

Others

SquareLine Studio version: 1.3.2

  • Operating system: Windows 10
  • Target hardware: custom STM32 board

On startup screen add event ONLOADSTART call function and here place all

and how mutch is

On startup screen add event ONLOADSTART call function and here place all

Thanks for the suggestion! im a newbie with SLS, learning now…

and how much is “we have lots”

At end of project will be 200 unique bitmaps x 4 different product brandings x 3 different display sizes and resolutions, so roughly 2400 bitmaps in sizes varying from 48x48 to 240x240, true color.

Much better storing those on external very fast NAND (eMMC 100 Mhz x 8 bit), so we can “reskin” a brand without pushing out a new code release.

I’d like to store them in raw binary (to avoid decode time), and give LVGL some image caching.

Answering to myself for others that could end here searching for the same thing…

To select between loading an image from filesystem vs. a compiled constant array is simple:

  1. add a .c file listing all the images identifier declared like this:

#define IMG_PATH “R:/images” // or whatever

const char ui_img_btn_exit_n_94x80_png[] = IMG_PATH “btn_exit_n_94x80.png”;
// const char ui_img_btn_help_n_94x80_png[] = IMG_PATH “btn_help_n_94x80.png”;

( can be made with “dir /B *.png >images.c” or similar)

  1. disable compiling the ui_img_btn_exit_n_94x80_png.c source (depends on the IDE used)
    Keep compiling those you want to put in code (small images or frequently used, whatever)

In the example above, the “exit” image will be loaded from disk, while the “help” one will be compiled in the binary.

Hi - you might be helping me fix a big issue I’ve got like this (running out of RAM quickly on my Arduino GIga R1). Do you have to also populate the LVGL file system placeholder functions for this to work?

For reading from files on an MCU you need the matching filesystem functions compiled to handle the filesystem (posix-stdio/FAT32/etc.) your images are residing on. The drivers must be registered by the drive-letter given in lv_conf.h, so you can use the paths containing ‘S:’/‘A:’/etc. SquareLine Studio will likely support loading images from binary files in the exported code soon, so you won’t have to do manual tweaking to achieve that…

Hi - that’s what I’m working on right now. With microcontrollers like the Arduino Giga R1 with the big screen, a 128x128 px image button consumes 5% of RAM. When I was working with arduino RP2040 Connects, they had so much RAM it didn’t matter. I’ve tried loading the bin into SDRAM and assigning the pointer over so LVGL looks at the pointer to the bin in SDRAM, but I’m getting nowhere.

If this can become native in SLS as soon as possible, that’ll remove a huge amount of grief for me (and others adopting this and other families like it).