Porting LittlevGL for a monochrome display
Leveraging LvGL’s capabilities on a low resource project
My line of work brings me close to small embedded systems with minimal UI: a few LEDs or some digits displays. From time to time however I end up working with small monochrome screens, sparking the need for a working albeit simple GUI library.
In this field, the available resources are barren to say the least. Most results found online refer either to proprietary libraries distributed by LCD vendors with nonexistent support or to dubious code generators that fail to deliver anything beyond a few supported drivers, if at all. My same company’s previous solution was a cracked and modified API whose reference manual was long lost in time. The only reliable alternative to baking your own GUI is LittlevGL.
LittlevGL (or LvGL) is an open source graphic library for embedded systems. It is mainly focused on color TFT displays, but can in principle work for monochrome LCDs as well. My first approach was discouraged by its main purpose being color and the size of the compiled result (about 250 KB of binary for PIC architecture). After a little fiddling however I can say I’m very satisfied, and I wish to make a little tutorial on how to use it.
For reference, my project uses a PIC24 microcontroller managing a 240x128 monochrome resistive touch LCD; in principle however all of the code is abstracted from the actual hardware and most of the explanations are valid in general. Everything written here is based on the extensive LittlevGL documentation.
LittlevGL is written entirely in C and uses a macro system to configure its settings and features. There is a template configuration on the root of the repository that needs to be copied into a file named
lv_conf.h and to be included by all other sources. There are a lot of options, but for the sake of simplicity we can focus on just a few of them:
/* Maximal horizontal and vertical resolution to support by the library.*/
#define LV_HOR_RES_MAX (240)