- ...
- SDK
- Yocto
- ...
- ...
- your first application
- tools
- ...
Getting started with LVGL#
If you want to create a SimpleSwitch™ application using LVGL, please follow this guide to get you easily started.
Example Project#
Here is a very small LVGL project, with a single C source file, main.c
:
//SPDX-FileCopyrightText: (C) 2025 Avnet Embedded GmbH
//SPDX-License-Identifier: LicenseRef-Avnet-OSS-1.0
#include "lvgl.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
int main(void)
{
int width = 400, height = 400;
lv_init();
lv_display_t * disp = lv_wayland_window_create(width, height, "LVGL Wayland helloworld", NULL);
lv_indev_t *touch = lv_evdev_create(LV_INDEV_TYPE_POINTER, "/dev/input/event1");
lv_indev_set_display(touch, disp);
/*Change the active screen's background color*/
lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0x003a57), LV_PART_MAIN);
/*Create a white label, set its text and align it to the center*/
lv_obj_t * label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "Hello world");
lv_obj_set_style_text_color(lv_screen_active(), lv_color_hex(0xffffff), LV_PART_MAIN);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
uint32_t idle_time;
/*Handle LVGL tasks*/
while(1) {
idle_time = lv_wayland_timer_handler();
if(idle_time != 0) {
usleep(idle_time * 1000);
}
/* Run until the last window closes */
if (!lv_wayland_window_is_open(NULL)) {
break;
}
}
return 0;
}
And a Makefile:
# SPDX-FileCopyrightText: (C) 2025 Avnet Embedded GmbH
# SPDX-License-Identifier: LicenseRef-Avnet-OSS-1.0
BIN = lvgl_test_prog
OBJS = main.o
BINDIR ?= /usr/bin
SDKTARGETSYSROOT_LVGL = $(OECORE_NATIVE_SYSROOT_LVGL)/../$(notdir $(SDKTARGETSYSROOT))
LIBDIR = $(SDKTARGETSYSROOT_LVGL)/usr/lib
CFLAGS += -I${SDKTARGETSYSROOT_LVGL}/usr/include/lvgl -I${SDKTARGETSYSROOT_LVGL}/usr/include/lvgl/drivers/wayland -D_DEFAULT_SOURCE -D_REENTRANT -Wall -Werror -pedantic -std=c99
LIBS += --sysroot=${SDKTARGETSYSROOT_LVGL}/ -L$(LIBDIR) -llvgl -lpthread -lwayland-client -lwayland-cursor -lxkbcommon
all: $(BIN)
$(BIN): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
rm -f $(BIN) $(OBJS)
install: $(BIN)
install -m 0755 -d "$(PREFIX)/$(BINDIR)/"
install -m 0755 $(BIN) "$(PREFIX)/$(BINDIR)/"
.PHONY: clean install
One can build this project for the host system by putting both file in the same
directory and running make
make
./lvgl_test_prog
Build the project using a Makefile#
With a makefile aware of cross-compilation, building the binary is as simple as
sourcing the SDK (see Source the SDK) and running make
, e.g.
make
If the makefile has an install
target using the PREFIX
variable as
installation path, it can be used directly with the --makefile-dir
option of
the Generate a SimpleSwitch™ package script
simpleswitch-generate-package --name simpleswitch-example --makefile-dir . \
--template lvgl --startup-command /usr/bin/lvgl_test_prog
Or if you want to be able to debug your application:
simpleswitch-generate-package --name simpleswitch-example --makefile-dir . \
--template lvgl --startup-command "while true; do gdbserver :2159 /usr/bin/lvgl_test_prog ; done"
If your makefile lack of a compatible install
target, see below.
Deploy to the target#
Now it is time to deploy the generated SimpleSwitch™ container to the device. For this please see Deploy a SimpleSwitch™ package
Remote debugging a LVGL application#
To remote debugging a LVGL application, you can see Remote debug a SimpleSwitch™ package
Further reading#
See also