LVGL + Swift experiment

Hey there,

I’m a big fan of both LVGL and the Swift programming language, so I thought it would be interesting to see if I could launch an LVGL-based GUI from a Swift SPM application.

After very little work, I managed to do a basic demo, which launches a window on macOS with SDL and animates some text, with all of the widget related functions being called directly from Swift. I had to keep the setup of the display buffers etc inside a C function for obvious reasons, as Swift is not well suited to this kind of real-time deterministic programming.

I posted the demo on Github, called LVGLSwiftDemo All submodules are on Github too, including a fork of lv_drivers which abstracts away a couple of header paths that don’t line up with the structure within the SPM (Swift Package Manager) module. If LVGL were available via Homebrew / apt / yum etc in future, the SPM interface to those package managers could be used which would further simplify things.

Most of the LVGL data types don’t import well into Swift due to LVGL’s heavy reliance on pointers in function arguments, so in future it might be fun to write a nice easy-to-use wrapper around the wrapper to present a more swifty API.

My hope was to be able to build a Swift GUI app for Raspberry Pi (running Raspbian) using LVGL, however the barrier at this point is that there is no build of Swift 5.3 for RPi at the moment (the newest is for Swift 5.1.3). I haven’t yet looked into Swift 5.3 on Ubuntu, which may well be possible. I’ve no doubt it will be easy to achieve on an x86 build of Ubuntu, however for my purposes I’m only interested in ARM SBCs.

Anyway, just a bit of fun and thought I’d post here in case anyone else has tried it and wants to share thoughts.




That’s awesome, thank you for sharing!

I’m amazed by in which “non-trivial” ways people use LVGL. :slight_smile:

1 Like