Skip to content

samples/modules: Add LVGL demo sample #62904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions samples/modules/lvgl/demos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright (c) 2023 Fabian Blatz <[email protected]>
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(lvgl_sample)

set(LVGL_DIR ${ZEPHYR_LVGL_MODULE_DIR})

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

target_include_directories(app PRIVATE
${LVGL_DIR}/demos/
)

target_sources_ifdef(CONFIG_LV_USE_DEMO_MUSIC app PRIVATE
${LVGL_DIR}/demos/music/lv_demo_music_list.c
${LVGL_DIR}/demos/music/lv_demo_music.c
${LVGL_DIR}/demos/music/lv_demo_music_main.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_next.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_wave_top_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_4_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_4.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_corner_right.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_1.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_slider_knob_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_3.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_pause.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_pause_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_wave_bottom_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_2_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_list_play_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_wave_top.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_play_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_1_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_wave_bottom.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_corner_left_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_play.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_list_border.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_2.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_next_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_list_play.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_list_border_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_rnd.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_3.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_prev_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_loop.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_1.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_slider_knob.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_corner_right_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_corner_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_corner_left.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_2_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_3_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_icon_1_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_2.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_prev.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_rnd_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_list_pause_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_cover_3_large.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_list_pause.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_logo.c
${LVGL_DIR}/demos/music/assets/img_lv_demo_music_btn_loop_large.c
)

target_sources_ifdef(CONFIG_LV_USE_DEMO_BENCHMARK app PRIVATE
${LVGL_DIR}/demos/benchmark/lv_demo_benchmark.c
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_indexed16.c
${LVGL_DIR}/demos/benchmark/assets/lv_font_bechmark_montserrat_28_compr_az.c.c
${LVGL_DIR}/demos/benchmark/assets/lv_font_bechmark_montserrat_16_compr_az.c.c
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_argb.c
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_alpha16.c
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_rgb.c
${LVGL_DIR}/demos/benchmark/assets/lv_font_bechmark_montserrat_12_compr_az.c.c
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_chroma_keyed.c
${LVGL_DIR}/demos/benchmark/assets/img_benchmark_cogwheel_rgb565a8.c
)

target_sources_ifdef(CONFIG_LV_USE_DEMO_STRESS app PRIVATE
${LVGL_DIR}/demos/stress/lv_demo_stress.c
)
30 changes: 30 additions & 0 deletions samples/modules/lvgl/demos/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2023 Fabian Blatz <[email protected]>
# SPDX-License-Identifier: Apache-2.0

choice LV_Z_DEMO
prompt "LVGL demo to build"
default LV_Z_DEMO_MUSIC
help
Demo application to build.

config LV_Z_DEMO_MUSIC
bool "LVGL music demo"
select LV_USE_DEMO_MUSIC
help
Build music player demo application.

config LV_Z_DEMO_BENCHMARK
bool "LVGL benchmark demo"
select LV_USE_DEMO_BENCHMARK
help
Build benchmarking demo application.

config LV_Z_DEMO_STRESS
bool "LVGL stress demo"
select LV_USE_DEMO_STRESS
help
Build stress testing demo application.

endchoice

source "Kconfig.zephyr"
51 changes: 51 additions & 0 deletions samples/modules/lvgl/demos/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.. zephyr:code-sample:: lvgl-demos
:name: LVGL demos
:relevant-api: display_interface

Run LVGL built-in demos.

Overview
********

A sample showcasing upstream LVGL demos.

* Music
The music player demo shows what kind of modern, smartphone-like user interfaces can be created on LVGL.
* Benchmark
The benchmark demo tests the performance in various cases. For example rectangle, border, shadow, text, image blending, image transformation, blending modes, etc.
* Stress
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.
Comment on lines +12 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should these be wrapping on 80 columns or something? @kartben @gmarull not sure if it's a rule or guideline or just not a thing for doc files but usually everything in the repo is bounded it seems


Requirements
************

* A board with display, ideally with 480x272 resolution or higher.

Building and Running
********************

These demos can be built as follows:

.. zephyr-app-commands::
:zephyr-app: samples/modules/lvgl/demos
:host-os: unix
:board: native_posix
:gen-args: -DCONFIG_LV_Z_DEMO_MUSIC=y
:goals: run
:compact:

.. zephyr-app-commands::
:zephyr-app: samples/modules/lvgl/demos
:host-os: unix
:board: native_posix
:gen-args: -DCONFIG_LV_Z_DEMO_BENCHMARK=y
:goals: run
:compact:

.. zephyr-app-commands::
:zephyr-app: samples/modules/lvgl/demos
:host-os: unix
:board: native_posix
:gen-args: -DCONFIG_LV_Z_DEMO_STRESS=y
:goals: run
:compact:
4 changes: 4 additions & 0 deletions samples/modules/lvgl/demos/boards/m5stack_core2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 Fabian Blatz <[email protected]>
# SPDX-License-Identifier: Apache-2.0

CONFIG_MAIN_STACK_SIZE=4096
8 changes: 8 additions & 0 deletions samples/modules/lvgl/demos/boards/mimxrt1060_evk.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2023 Fabian Blatz <[email protected]>
# SPDX-License-Identifier: Apache-2.0

# Enable PXP DMA engine and set rotation angle to 0 degrees.
# This allows us to verify the DMA driver functions without altering
# the output image
CONFIG_DMA=y
CONFIG_MCUX_ELCDIF_PXP=y
8 changes: 8 additions & 0 deletions samples/modules/lvgl/demos/boards/mimxrt1170_evk_cm7.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2023 Fabian Blatz <[email protected]>
# SPDX-License-Identifier: Apache-2.0

# Enable PXP DMA engine and set rotation angle to 0 degrees.
# This allows us to verify the DMA driver functions without altering
# the output image
CONFIG_DMA=y
CONFIG_MCUX_ELCDIF_PXP=y
4 changes: 4 additions & 0 deletions samples/modules/lvgl/demos/boards/native_posix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 Fabian Blatz <[email protected]>
# SPDX-License-Identifier: Apache-2.0

CONFIG_LV_COLOR_DEPTH_32=y
11 changes: 11 additions & 0 deletions samples/modules/lvgl/demos/boards/native_posix.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright (c) 2023, Fabian Blatz <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

&sdl_dc {
compatible = "zephyr,sdl-dc";
height = <272>;
width = <480>;
};
4 changes: 4 additions & 0 deletions samples/modules/lvgl/demos/boards/native_posix_64.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 Fabian Blatz <[email protected]>
# SPDX-License-Identifier: Apache-2.0

CONFIG_LV_COLOR_DEPTH_32=y
6 changes: 6 additions & 0 deletions samples/modules/lvgl/demos/boards/native_posix_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright (c) 2023, Fabian Blatz <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "native_posix.overlay"
4 changes: 4 additions & 0 deletions samples/modules/lvgl/demos/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 Fabian Blatz <[email protected]>
# SPDX-License-Identifier: Apache-2.0

CONFIG_LV_COLOR_DEPTH_32=y
6 changes: 6 additions & 0 deletions samples/modules/lvgl/demos/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright (c) 2023, Fabian Blatz <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "native_posix.overlay"
4 changes: 4 additions & 0 deletions samples/modules/lvgl/demos/boards/native_sim_64.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 Fabian Blatz <[email protected]>
# SPDX-License-Identifier: Apache-2.0

CONFIG_LV_COLOR_DEPTH_32=y
6 changes: 6 additions & 0 deletions samples/modules/lvgl/demos/boards/native_sim_64.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* Copyright (c) 2023, Fabian Blatz <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "native_sim.overlay"
18 changes: 18 additions & 0 deletions samples/modules/lvgl/demos/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_LOG=y
CONFIG_SHELL=y

CONFIG_LVGL=y
CONFIG_LV_Z_MEM_POOL_NUMBER_BLOCKS=8
CONFIG_LV_Z_SHELL=y
CONFIG_LV_USE_MONKEY=y

CONFIG_DISPLAY=y
CONFIG_INPUT=y

CONFIG_LV_FONT_MONTSERRAT_12=y
CONFIG_LV_FONT_MONTSERRAT_14=y
CONFIG_LV_FONT_MONTSERRAT_16=y

# Benchmark Demo
CONFIG_LV_USE_FONT_COMPRESSED=y
19 changes: 19 additions & 0 deletions samples/modules/lvgl/demos/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sample:
description: LVGL sample, containing all upstream demos
name: LVGL demos
common:
modules:
- lvgl
harness: none
filter: dt_chosen_enabled("zephyr,display")
tags: samples lvgl display gui
tests:
sample.modules.lvgl.demo_music:
extra_configs:
- CONFIG_LV_Z_DEMO_MUSIC=y
sample.modules.lvgl.demo_benchmark:
extra_configs:
- CONFIG_LV_Z_DEMO_BENCHMARK=y
sample.modules.lvgl.demo_stress:
extra_configs:
- CONFIG_LV_Z_DEMO_STRESS=y
45 changes: 45 additions & 0 deletions samples/modules/lvgl/demos/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2023 Fabian Blatz <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/drivers/display.h>
#include <lvgl.h>
#include <lv_demos.h>

#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(app);
Copy link
Member

@fabiobaltieri fabiobaltieri Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just do LOG_MODULE_REGISTER(app, CONFIG_LOG_DEFAULT_LEVEL); and drop the define above


int main(void)
{
const struct device *display_dev;

display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(display_dev)) {
LOG_ERR("Device not ready, aborting test");
return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes nothing in this case but it's odd to catch an error and return 0... -ENODEV?

}

#if defined(CONFIG_LV_USE_DEMO_MUSIC)
lv_demo_music();
#elif defined(CONFIG_LV_USE_DEMO_BENCHMARK)
lv_demo_benchmark();
#elif defined(CONFIG_LV_USE_DEMO_STRESS)
lv_demo_stress();
#else
#error Enable one of the demos CONFIG_LV_USE_DEMO_MUSIC, CONFIG_LV_USE_DEMO_BENCHMARK \
or CONFIG_LV_USE_DEMO_STRESS.
#endif

lv_task_handler();
display_blanking_off(display_dev);

while (1) {
k_msleep(lv_task_handler());
}

return 0;
}