Skip to content

Commit b946416

Browse files
faxe1008carlescufi
authored andcommitted
samples/modules: Add LVGL demo sample
Adds a sample which allows to build the LVGL upstream demo applications (music, benchmark, stress). Resolves issue #62744. Signed-off-by: Fabian Blatz <[email protected]>
1 parent 2a8548b commit b946416

17 files changed

+311
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Copyright (c) 2023 Fabian Blatz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7+
project(lvgl_sample)
8+
9+
set(LVGL_DIR ${ZEPHYR_LVGL_MODULE_DIR})
10+
11+
FILE(GLOB app_sources src/*.c)
12+
target_sources(app PRIVATE ${app_sources})
13+
14+
target_include_directories(app PRIVATE
15+
${LVGL_DIR}/demos/
16+
)
17+
18+
target_sources_ifdef(CONFIG_LV_USE_DEMO_MUSIC app PRIVATE
19+
${LVGL_DIR}/demos/music/lv_demo_music_list.c
20+
${LVGL_DIR}/demos/music/lv_demo_music.c
21+
${LVGL_DIR}/demos/music/lv_demo_music_main.c
22+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_next.c
23+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_wave_top_large.c
24+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_4_large.c
25+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_4.c
26+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_corner_right.c
27+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_1.c
28+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_slider_knob_large.c
29+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_3.c
30+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_pause.c
31+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_pause_large.c
32+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_wave_bottom_large.c
33+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_2_large.c
34+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_list_play_large.c
35+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_wave_top.c
36+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_play_large.c
37+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_1_large.c
38+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_wave_bottom.c
39+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_corner_left_large.c
40+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_play.c
41+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_list_border.c
42+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_2.c
43+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_next_large.c
44+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_list_play.c
45+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_list_border_large.c
46+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_rnd.c
47+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_3.c
48+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_prev_large.c
49+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_loop.c
50+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_1.c
51+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_slider_knob.c
52+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_corner_right_large.c
53+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_corner_large.c
54+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_corner_left.c
55+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_2_large.c
56+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_3_large.c
57+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_1_large.c
58+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_2.c
59+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_prev.c
60+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_rnd_large.c
61+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_list_pause_large.c
62+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_3_large.c
63+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_list_pause.c
64+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_logo.c
65+
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_loop_large.c
66+
)
67+
68+
target_sources_ifdef(CONFIG_LV_USE_DEMO_BENCHMARK app PRIVATE
69+
${LVGL_DIR}/demos/benchmark/lv_demo_benchmark.c
70+
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_indexed16.c
71+
${LVGL_DIR}/demos/benchmark/assets/lv_font_bechmark_montserrat_28_compr_az.c.c
72+
${LVGL_DIR}/demos/benchmark/assets/lv_font_bechmark_montserrat_16_compr_az.c.c
73+
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_argb.c
74+
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_alpha16.c
75+
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_rgb.c
76+
${LVGL_DIR}/demos/benchmark/assets/lv_font_bechmark_montserrat_12_compr_az.c.c
77+
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_chroma_keyed.c
78+
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_rgb565a8.c
79+
)
80+
81+
target_sources_ifdef(CONFIG_LV_USE_DEMO_STRESS app PRIVATE
82+
${LVGL_DIR}/demos/stress/lv_demo_stress.c
83+
)

samples/modules/lvgl/demos/Kconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2023 Fabian Blatz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
choice LV_Z_DEMO
5+
prompt "LVGL demo to build"
6+
default LV_Z_DEMO_MUSIC
7+
help
8+
Demo application to build.
9+
10+
config LV_Z_DEMO_MUSIC
11+
bool "LVGL music demo"
12+
select LV_USE_DEMO_MUSIC
13+
help
14+
Build music player demo application.
15+
16+
config LV_Z_DEMO_BENCHMARK
17+
bool "LVGL benchmark demo"
18+
select LV_USE_DEMO_BENCHMARK
19+
help
20+
Build benchmarking demo application.
21+
22+
config LV_Z_DEMO_STRESS
23+
bool "LVGL stress demo"
24+
select LV_USE_DEMO_STRESS
25+
help
26+
Build stress testing demo application.
27+
28+
endchoice
29+
30+
source "Kconfig.zephyr"

samples/modules/lvgl/demos/README.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.. zephyr:code-sample:: lvgl-demos
2+
:name: LVGL demos
3+
:relevant-api: display_interface
4+
5+
Run LVGL built-in demos.
6+
7+
Overview
8+
********
9+
10+
A sample showcasing upstream LVGL demos.
11+
12+
* Music
13+
The music player demo shows what kind of modern, smartphone-like user interfaces can be created on LVGL.
14+
* Benchmark
15+
The benchmark demo tests the performance in various cases. For example rectangle, border, shadow, text, image blending, image transformation, blending modes, etc.
16+
* Stress
17+
A stress test for LVGL. It contains a lot of object creation, deletion, animations, styles usage, and so on. It can be used if there is any memory corruption during heavy usage or any memory leaks.
18+
19+
Requirements
20+
************
21+
22+
* A board with display, ideally with 480x272 resolution or higher.
23+
24+
Building and Running
25+
********************
26+
27+
These demos can be built as follows:
28+
29+
.. zephyr-app-commands::
30+
:zephyr-app: samples/modules/lvgl/demos
31+
:host-os: unix
32+
:board: native_posix
33+
:gen-args: -DCONFIG_LV_Z_DEMO_MUSIC=y
34+
:goals: run
35+
:compact:
36+
37+
.. zephyr-app-commands::
38+
:zephyr-app: samples/modules/lvgl/demos
39+
:host-os: unix
40+
:board: native_posix
41+
:gen-args: -DCONFIG_LV_Z_DEMO_BENCHMARK=y
42+
:goals: run
43+
:compact:
44+
45+
.. zephyr-app-commands::
46+
:zephyr-app: samples/modules/lvgl/demos
47+
:host-os: unix
48+
:board: native_posix
49+
:gen-args: -DCONFIG_LV_Z_DEMO_STRESS=y
50+
:goals: run
51+
:compact:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2023 Fabian Blatz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_MAIN_STACK_SIZE=4096
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2023 Fabian Blatz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Enable PXP DMA engine and set rotation angle to 0 degrees.
5+
# This allows us to verify the DMA driver functions without altering
6+
# the output image
7+
CONFIG_DMA=y
8+
CONFIG_MCUX_ELCDIF_PXP=y
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2023 Fabian Blatz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Enable PXP DMA engine and set rotation angle to 0 degrees.
5+
# This allows us to verify the DMA driver functions without altering
6+
# the output image
7+
CONFIG_DMA=y
8+
CONFIG_MCUX_ELCDIF_PXP=y
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2023 Fabian Blatz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_LV_COLOR_DEPTH_32=y
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) 2023, Fabian Blatz <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&sdl_dc {
8+
compatible = "zephyr,sdl-dc";
9+
height = <272>;
10+
width = <480>;
11+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2023 Fabian Blatz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_LV_COLOR_DEPTH_32=y
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (c) 2023, Fabian Blatz <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include "native_posix.overlay"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2023 Fabian Blatz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_LV_COLOR_DEPTH_32=y
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (c) 2023, Fabian Blatz <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include "native_posix.overlay"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2023 Fabian Blatz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_LV_COLOR_DEPTH_32=y
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (c) 2023, Fabian Blatz <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include "native_sim.overlay"

samples/modules/lvgl/demos/prj.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CONFIG_MAIN_STACK_SIZE=2048
2+
CONFIG_LOG=y
3+
CONFIG_SHELL=y
4+
5+
CONFIG_LVGL=y
6+
CONFIG_LV_Z_MEM_POOL_NUMBER_BLOCKS=8
7+
CONFIG_LV_Z_SHELL=y
8+
CONFIG_LV_USE_MONKEY=y
9+
10+
CONFIG_DISPLAY=y
11+
CONFIG_INPUT=y
12+
13+
CONFIG_LV_FONT_MONTSERRAT_12=y
14+
CONFIG_LV_FONT_MONTSERRAT_14=y
15+
CONFIG_LV_FONT_MONTSERRAT_16=y
16+
17+
# Benchmark Demo
18+
CONFIG_LV_USE_FONT_COMPRESSED=y
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sample:
2+
description: LVGL sample, containing all upstream demos
3+
name: LVGL demos
4+
common:
5+
modules:
6+
- lvgl
7+
harness: none
8+
filter: dt_chosen_enabled("zephyr,display")
9+
tags: samples lvgl display gui
10+
tests:
11+
sample.modules.lvgl.demo_music:
12+
extra_configs:
13+
- CONFIG_LV_Z_DEMO_MUSIC=y
14+
sample.modules.lvgl.demo_benchmark:
15+
extra_configs:
16+
- CONFIG_LV_Z_DEMO_BENCHMARK=y
17+
sample.modules.lvgl.demo_stress:
18+
extra_configs:
19+
- CONFIG_LV_Z_DEMO_STRESS=y

samples/modules/lvgl/demos/src/main.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2023 Fabian Blatz <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/drivers/display.h>
9+
#include <lvgl.h>
10+
#include <lv_demos.h>
11+
12+
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
13+
#include <zephyr/logging/log.h>
14+
LOG_MODULE_REGISTER(app);
15+
16+
int main(void)
17+
{
18+
const struct device *display_dev;
19+
20+
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
21+
if (!device_is_ready(display_dev)) {
22+
LOG_ERR("Device not ready, aborting test");
23+
return 0;
24+
}
25+
26+
#if defined(CONFIG_LV_USE_DEMO_MUSIC)
27+
lv_demo_music();
28+
#elif defined(CONFIG_LV_USE_DEMO_BENCHMARK)
29+
lv_demo_benchmark();
30+
#elif defined(CONFIG_LV_USE_DEMO_STRESS)
31+
lv_demo_stress();
32+
#else
33+
#error Enable one of the demos CONFIG_LV_USE_DEMO_MUSIC, CONFIG_LV_USE_DEMO_BENCHMARK \
34+
or CONFIG_LV_USE_DEMO_STRESS.
35+
#endif
36+
37+
lv_task_handler();
38+
display_blanking_off(display_dev);
39+
40+
while (1) {
41+
k_msleep(lv_task_handler());
42+
}
43+
44+
return 0;
45+
}

0 commit comments

Comments
 (0)