DESK-MX9-L-AN-0002: Using LVGL to create embedded GUI

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box


200px-Emblem-important.svg.png

This application note has been validated using the kit version in the History table.


History
Issue Date Notes
2024/01/10 DESK-MX9-L 5.1.0


Introduction[edit | edit source]

LVGL is a free and open-source graphics library providing everything you need to create an embedded GUI with easy-to-use graphical elements.

The main advantage of the LVGL graphics library is that:

The LVGL project (including all repositories) is licensed under the MIT license. This means you can use it even in commercial projects.

An i.MX93 Yocto porting can be found here.

In this Application Note, a simple and easy way to demonstrate the LVGL capabilities has been done by simply (cross) compiling and running the lv_bechmark LVGL demo on the AURA Evaluation Kit.

Building LVGL library and benchmark application[edit | edit source]

For running LVGL with DRM, the system must have libdrm installed. DESK-MX9-L Yocto build has already installed the libdrm library which can be easily checked in the target root file system:

root@desk-mx93-rev1:~# ls -la /usr/lib/libdrm.so
lrwxrwxrwx 1 root root 11 Mar  9  2018 /usr/lib/libdrm.so -> libdrm.so.2
root@desk-mx93-rev1:~#

An easy guide for building LVGL application and - in our case - the LVGL benchmark can be found the the LVGL documentation site.

Due to the ready-to-use cross compile toolchain available in the DESK-MX9-L virtual machine, the building process is very easy: it is enough to

  • clone the LVGL benchmark repository
  • enable the cross-toolchain
  • configure the project with cmake
  • build the application

The steps are the following ones:

  • clone the lv_benchmark.git git repository
dvdk@vagrant:~/desk-mx-l$ git clone --recurse-submodules https://github.com/EDGEMTech/lv_benchmark.git
Cloning into 'lv_benchmark'...
remote: Enumerating objects: 29, done.
remote: Counting objects: 100% (29/29), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 29 (delta 10), reused 26 (delta 7), pack-reused 0 (from 0)
Receiving objects: 100% (29/29), 34.15 KiB | 1.71 MiB/s, done.
Resolving deltas: 100% (10/10), done.
Submodule 'lvgl' (https://github.com/lvgl/lvgl.git) registered for path 'lvgl'
Cloning into '/home/dvdk/desk-mx-l/lv_benchmark/lvgl'...
remote: Enumerating objects: 114797, done.        
remote: Counting objects: 100% (4108/4108), done.        
remote: Compressing objects: 100% (386/386), done.        
remote: Total 114797 (delta 3878), reused 3725 (delta 3722), pack-reused 110689 (from 3)        
Receiving objects: 100% (114797/114797), 405.30 MiB | 9.81 MiB/s, done.
Resolving deltas: 100% (86546/86546), done.
Submodule path 'lvgl': checked out 'a853a1289ae40898122d83be1842d0b61c56b15d'
dvdk@vagrant:~/desk-mx-l$ 
  • enable the cross-toolchain
dvdk@vagrant:~/desk-mx-l$ source /home/dvdk/desk-mx-l/desk-mx9-l-5.0.0_env.sh 
  • configure the project with cmake
dvdk@vagrant:~/desk-mx-l$ cd lv_benchmark/
dvdk@vagrant:~/desk-mx-l/lv_benchmark$ cmake -B build -S . -DCMAKE_C_COMPILER=${CROSS_COMPILE}gcc -DCMAKE_CXX_COMPILER=${CROSS_COMPILE}g++ -DCMAKE_SYSROOT=${SDKTARGETSYSROOT} -DCMAKE_C_FLAGS="--sysroot=${SDKTARGETSYSROOT}" -DCMAKE_CXX_FLAGS="--sysroot=${SDKTARGETSYSROOT}"
-- Toolchain file defaulted to '/opt/yocto/sdk/desk-mx9-l/desk-mx9-l-5.0.0/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake'
-- The C compiler identification is GNU 12.3.0
-- The CXX compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/yocto/sdk/desk-mx9-l/desk-mx9-l-5.0.0/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/yocto/sdk/desk-mx9-l/desk-mx9-l-5.0.0/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: /opt/yocto/sdk/desk-mx9-l/desk-mx9-l-5.0.0/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dvdk/desk-mx-l/lv_benchmark/build
dvdk@vagrant:~/desk-mx-l/lv_benchmark$ 
  • build the application
dvdk@vagrant:~/desk-mx-l/lv_benchmark$ make -j $(nproc) -C build
-- Toolchain file defaulted to '/opt/yocto/sdk/desk-mx9-l/desk-mx9-l-5.0.0/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake'
-- The C compiler identification is GNU 12.3.0
-- The CXX compiler identification is GNU 12.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/yocto/sdk/desk-mx9-l/desk-mx9-l-5.0.0/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/yocto/sdk/desk-mx9-l/desk-mx9-l-5.0.0/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: /opt/yocto/sdk/desk-mx9-l/desk-mx9-l-5.0.0/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-gcc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dvdk/desk-mx-l/lv_benchmark/build
dvdk@vagrant:~/desk-mx-l/lv_benchmark$ make -j $(nproc) -C build
make: Entering directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
make[1]: Entering directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
make[2]: Entering directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
make[2]: Leaving directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
make[2]: Entering directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
[  0%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_group.c.o
[  0%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_draw.c.o
[  0%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_event.c.o
[  1%] Building C object lvgl/CMakeFiles/lvgl.dir/src/core/lv_obj_property.c.o
...
...
[ 99%] Built target lvgl_examples
make[2]: Entering directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
make[2]: Leaving directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
make[2]: Entering directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
[100%] Building C object CMakeFiles/lvgl-app.dir/main.c.o
[100%] Building C object CMakeFiles/lvgl-app.dir/demo_app.c.o
[100%] Building C object CMakeFiles/lvgl-app.dir/mouse_cursor_icon.c.o
[100%] Linking CXX executable /home/dvdk/desk-mx-l/lv_benchmark/bin/lvgl-app
make[2]: Leaving directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
[100%] Built target lvgl-app
make[1]: Leaving directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
make: Leaving directory '/home/dvdk/desk-mx-l/lv_benchmark/build'
dvdk@vagrant:~/desk-mx-l/lv_benchmark$ 
  • check the built application file
dvdk@vagrant:~/desk-mx-l/lv_benchmark$ file bin/lvgl-app 
bin/lvgl-app: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=f5f2c9da5deffdbbce0b69e94a3ebb3676735ee3, for GNU/Linux 3.14.0, with debug_info, not stripped
dvdk@vagrant:~/desk-mx-l/lv_benchmark$ 

Running the LVGL application in the target[edit | edit source]

The built application can be remotely copied in the target for the final test:

dvdk@vagrant:~/desk-mx-l/lv_benchmark$ scp bin/lvgl-app root@192.168.0.90:/home/root
lvgl-app                                                                                                                                                   100% 7992KB  21.6MB/s   00:00    
dvdk@vagrant:~/desk-mx-l/lv_benchmark$ 

and then can be started with the following CPU usage and FPS results:

root@desk-mx93-rev1:~# ./lvgl-app
Benchmark Summary (9.3.0 dev)
Name, Avg. CPU, Avg. FPS, Avg. time, render time, flush time
Empty screen, 3%, 23, 0, 0, 0
Moving wallpaper, 20%, 29, 7, 7, 0
Single rectangle, 2%, 27, 0, 0, 0
Multiple rectangles, 2%, 26, 0, 0, 0
Multiple RGB images, 11%, 28, 3, 3, 0
Multiple ARGB images, 11%, 28, 3, 3, 0
Rotated ARGB images, 31%, 27, 10, 10, 0
Multiple labels, 6%, 27, 1, 1, 0
Screen sized text, 21%, 29, 6, 6, 0
Multiple arcs, 9%, 28, 1, 1, 0
Containers, 6%, 28, 1, 1, 0
Containers with overlay, 25%, 28, 8, 8, 0
Containers with opa, 11%, 28, 3, 3, 0
Containers with opa_layer, 14%, 27, 4, 4, 0
Containers with scrolling, 14%, 27, 4, 4, 0
Widgets demo, 15%, 27, 3, 3, 0
All scenes avg.,12%, 27, 3, 3, 0

It is possible to see an average CPU usage of 12% and an average FPS of 27.


AURA LVGL benchmark demo application


AURA LVGL benchmark demo results

systemd LVGL demo service[edit | edit source]

A systemd service can be created for automatically start the LVGL demo on boot, for example:

/lib/systemd/system/lvgl-benchmark.service

and the service contains the initialization parameters:

[Unit]
Description=Start LVGL benchmark demo
DefaultDependencies=no
After=psplash-quit.service

[Service]
ExecStart=/home/root/lvgl/lvgl-app
RemainAfterExit=yes

[Install]
WantedBy=graphical.target

and then start/enable the service:

systemctl enable lvgl-benchmark.service

N.B.: the weston service should be disabled before enabling and running the LVGL service: this use directly the DRM backend for running the graphical application

systemctl disable weston.service