From 48569b03a7dfde5ac2b76b2992124136a0f6c291 Mon Sep 17 00:00:00 2001 From: Jan Van Winkel Date: Fri, 30 Nov 2018 23:01:50 +0100 Subject: [PATCH 1/3] display: Added double buffer screen info to display API Extend display API screen info with double buffer enum entry. Signed-off-by: Jan Van Winkel --- drivers/display/ssd1673.c | 3 ++- include/display.h | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/display/ssd1673.c b/drivers/display/ssd1673.c index 9c8f276fa965bd..ea31e520c1b96e 100644 --- a/drivers/display/ssd1673.c +++ b/drivers/display/ssd1673.c @@ -334,7 +334,8 @@ static void ssd1673_get_capabilities(const struct device *dev, caps->current_pixel_format = PIXEL_FORMAT_MONO10; caps->screen_info = SCREEN_INFO_MONO_VTILED | SCREEN_INFO_MONO_MSB_FIRST | - SCREEN_INFO_EPD; + SCREEN_INFO_EPD | + SCREEN_INFO_DOUBLE_BUFFER; } static int ssd1673_set_orientation(const struct device *dev, diff --git a/include/display.h b/include/display.h index 4b79f37fda880d..dbd91bb7d0cf6f 100644 --- a/include/display.h +++ b/include/display.h @@ -49,6 +49,10 @@ enum display_screen_info { * Electrophoretic Display. */ SCREEN_INFO_EPD = BIT(2), + /** + * Screen has two alternating ram buffers + */ + SCREEN_INFO_DOUBLE_BUFFER = BIT(3), }; /** From 8a25ae6de4d95f8f2e4d941c61fc53a0014ec2b2 Mon Sep 17 00:00:00 2001 From: Jan Van Winkel Date: Sun, 25 Mar 2018 01:27:48 +0100 Subject: [PATCH 2/3] gui: Added glue logic for LittlevGL GUI library Added glue logic to interface Zephyr with LittlevGL GUI library This includes: * KConfig options for all lvgl options * Kernel & user space memory management * Zephyr to lvgl FS call mapping * Color space conversion function Signed-off-by: Jan Van Winkel --- lib/CMakeLists.txt | 1 + lib/Kconfig | 3 + lib/gui/CMakeLists.txt | 1 + lib/gui/Kconfig | 11 + lib/gui/lvgl/CMakeLists.txt | 175 +++++++++++++++ lib/gui/lvgl/Kconfig | 341 ++++++++++++++++++++++++++++++ lib/gui/lvgl/Kconfig.fonts | 189 +++++++++++++++++ lib/gui/lvgl/Kconfig.objects | 296 ++++++++++++++++++++++++++ lib/gui/lvgl/Kconfig.themes | 59 ++++++ lib/gui/lvgl/lv_conf.h | 374 +++++++++++++++++++++++++++++++++ lib/gui/lvgl/lvgl.c | 89 ++++++++ lib/gui/lvgl/lvgl_color.h | 26 +++ lib/gui/lvgl/lvgl_color_1.c | 100 +++++++++ lib/gui/lvgl/lvgl_color_16.c | 50 +++++ lib/gui/lvgl/lvgl_color_32.c | 87 ++++++++ lib/gui/lvgl/lvgl_color_8.c | 50 +++++ lib/gui/lvgl/lvgl_fs.c | 243 +++++++++++++++++++++ lib/gui/lvgl/lvgl_fs.h | 20 ++ lib/gui/lvgl/lvgl_mem.h | 24 +++ lib/gui/lvgl/lvgl_mem_kernel.c | 25 +++ lib/gui/lvgl/lvgl_mem_user.c | 37 ++++ 21 files changed, 2201 insertions(+) create mode 100644 lib/gui/CMakeLists.txt create mode 100644 lib/gui/Kconfig create mode 100644 lib/gui/lvgl/CMakeLists.txt create mode 100644 lib/gui/lvgl/Kconfig create mode 100644 lib/gui/lvgl/Kconfig.fonts create mode 100644 lib/gui/lvgl/Kconfig.objects create mode 100644 lib/gui/lvgl/Kconfig.themes create mode 100644 lib/gui/lvgl/lv_conf.h create mode 100644 lib/gui/lvgl/lvgl.c create mode 100644 lib/gui/lvgl/lvgl_color.h create mode 100644 lib/gui/lvgl/lvgl_color_1.c create mode 100644 lib/gui/lvgl/lvgl_color_16.c create mode 100644 lib/gui/lvgl/lvgl_color_32.c create mode 100644 lib/gui/lvgl/lvgl_color_8.c create mode 100644 lib/gui/lvgl/lvgl_fs.c create mode 100644 lib/gui/lvgl/lvgl_fs.h create mode 100644 lib/gui/lvgl/lvgl_mem.h create mode 100644 lib/gui/lvgl/lvgl_mem_kernel.c create mode 100644 lib/gui/lvgl/lvgl_mem_user.c diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index e0f44469ff8ee9..2e42a6323f78da 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -12,3 +12,4 @@ add_subdirectory_ifdef(CONFIG_POSIX_API posix) add_subdirectory_ifdef(CONFIG_CMSIS_RTOS_V1 cmsis_rtos_v1) add_subdirectory_ifdef(CONFIG_CMSIS_RTOS_V2 cmsis_rtos_v2) add_subdirectory(rbtree) +add_subdirectory(gui) diff --git a/lib/Kconfig b/lib/Kconfig index 01c885f8184f13..6861a2ccbd8bf0 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -30,4 +30,7 @@ source "lib/posix/Kconfig" source "lib/cmsis_rtos_v1/Kconfig" source "lib/cmsis_rtos_v2/Kconfig" + +source "lib/gui/Kconfig" + endmenu diff --git a/lib/gui/CMakeLists.txt b/lib/gui/CMakeLists.txt new file mode 100644 index 00000000000000..51eadedd1ab7bb --- /dev/null +++ b/lib/gui/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory_if_kconfig(lvgl) diff --git a/lib/gui/Kconfig b/lib/gui/Kconfig new file mode 100644 index 00000000000000..e1618529e16e9d --- /dev/null +++ b/lib/gui/Kconfig @@ -0,0 +1,11 @@ +# +# Copyright (c) 2018 Jan Van Winkel +# +# SPDX-License-Identifier: Apache-2.0 +# + +menu "Graphical user interface" + +rsource "lvgl/Kconfig" + +endmenu diff --git a/lib/gui/lvgl/CMakeLists.txt b/lib/gui/lvgl/CMakeLists.txt new file mode 100644 index 00000000000000..9c4f84c09b4a09 --- /dev/null +++ b/lib/gui/lvgl/CMakeLists.txt @@ -0,0 +1,175 @@ +include(FetchContent) + +set(lv_name lvgl) + +set(ep_base ${PROJECT_BINARY_DIR}/ext_proj) +set_property(DIRECTORY PROPERTY "EP_BASE" ${ep_base}) + +set(lv_SOURCE_DIR ${ep_base}/Source/${lv_name}) +set(lv_SUBBUILD_DIR ${ep_base}/Subbuild/${lv_name}) + +FetchContent_Declare( + ${lv_name} + GIT_REPOSITORY https://github.com/littlevgl/lvgl.git + GIT_TAG v5.2 + SOURCE_DIR ${lv_SOURCE_DIR} + BINARY_DIR ${lv_SOURCE_DIR} + SUBBUILD_DIR ${lv_SUBBUILD_DIR} +) + +FetchContent_GetProperties(${lv_name}) +if(NOT ${lv_name}_POPULATED) + FetchContent_Populate(${lv_name}) +endif() + +zephyr_interface_library_named(lvgl) + +set(LVGL_SOURCE_DIR ${${lv_name}_SOURCE_DIR}) + +target_include_directories(lvgl INTERFACE ${LVGL_SOURCE_DIR}) +target_include_directories(lvgl INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) + +zephyr_compile_definitions(LV_CONF_INCLUDE_SIMPLE=1) + +zephyr_library() + +zephyr_library_sources( + + ${LVGL_SOURCE_DIR}/lv_core/lv_group.c + ${LVGL_SOURCE_DIR}/lv_core/lv_indev.c + ${LVGL_SOURCE_DIR}/lv_core/lv_obj.c + ${LVGL_SOURCE_DIR}/lv_core/lv_refr.c + ${LVGL_SOURCE_DIR}/lv_core/lv_style.c + ${LVGL_SOURCE_DIR}/lv_core/lv_vdb.c + + ${LVGL_SOURCE_DIR}/lv_draw/lv_draw.c + ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_arc.c + ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_img.c + ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_label.c + ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_line.c + ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_rbasic.c + ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_rect.c + ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_triangle.c + ${LVGL_SOURCE_DIR}/lv_draw/lv_draw_vbasic.c + + ${LVGL_SOURCE_DIR}/lv_hal/lv_hal_disp.c + ${LVGL_SOURCE_DIR}/lv_hal/lv_hal_indev.c + ${LVGL_SOURCE_DIR}/lv_hal/lv_hal_tick.c + + ${LVGL_SOURCE_DIR}/lv_misc/lv_anim.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_area.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_circ.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_color.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_font.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_fs.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_ll.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_log.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_math.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_mem.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_task.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_templ.c + ${LVGL_SOURCE_DIR}/lv_misc/lv_txt.c + + ${LVGL_SOURCE_DIR}/lv_objx/lv_arc.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_bar.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_btn.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_btnm.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_calendar.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_cb.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_chart.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_cont.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_ddlist.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_gauge.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_img.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_imgbtn.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_kb.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_label.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_led.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_line.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_list.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_lmeter.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_mbox.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_objx_templ.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_page.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_preload.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_roller.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_slider.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_sw.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_ta.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_tabview.c + ${LVGL_SOURCE_DIR}/lv_objx/lv_win.c + + ${LVGL_SOURCE_DIR}/lv_themes/lv_theme.c + ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_alien.c + ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_default.c + ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_material.c + ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_mono.c + ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_nemo.c + ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_night.c + ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_templ.c + ${LVGL_SOURCE_DIR}/lv_themes/lv_theme_zen.c + + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_builtin.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_BUILD_IN_FONT_10 + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_10.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_10_cyrillic.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_10_latin_sup.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_symbol_10.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_BUILD_IN_FONT_20 + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_20.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_20_cyrillic.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_20_latin_sup.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_symbol_20.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_BUILD_IN_FONT_30 + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_30.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_30_cyrillic.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_30_latin_sup.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_symbol_30.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_BUILD_IN_FONT_40 + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_40.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_40_cyrillic.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_dejavu_40_latin_sup.c + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_symbol_40.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_BUILD_IN_FONT_MONOSPACE + ${LVGL_SOURCE_DIR}/lv_fonts/lv_font_monospace_8.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_COLOR_DEPTH_32 + lvgl_color_32.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_COLOR_DEPTH_16 + lvgl_color_16.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_COLOR_DEPTH_8 + lvgl_color_8.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_COLOR_DEPTH_1 + lvgl_color_1.c +) + +zephyr_library_sources_ifdef( CONFIG_LVGL_FILESYSTEM + lvgl_fs.c +) + +zephyr_library_sources(lvgl.c) + +zephyr_library_sources_ifdef( CONFIG_LVGL_MEM_POOL_USER lvgl_mem_user.c) + +zephyr_library_sources_ifdef( CONFIG_LVGL_MEM_POOL_KERNEL lvgl_mem_kernel.c) + +zephyr_library_link_libraries(lvgl) + +target_link_libraries(lvgl INTERFACE zephyr_interface) diff --git a/lib/gui/lvgl/Kconfig b/lib/gui/lvgl/Kconfig new file mode 100644 index 00000000000000..b2146d2c1eacb7 --- /dev/null +++ b/lib/gui/lvgl/Kconfig @@ -0,0 +1,341 @@ +# +# Copyright (c) 2018 Jan Van Winkel +# +# SPDX-License-Identifier: Apache-2.0 +# + +config LVGL + bool "LittlevGL Support" + help + This option enables the LittlevGL GUI library. + +if LVGL + +module = LVGL +module-str = lvgl +source "subsys/logging/Kconfig.template.log_config" + +config LVGL_DISPLAY_DEV_NAME + string "Display device name" + default "DISPLAY" + help + Name of the display device to use for rendering. + +config LVGL_HOR_RES + int "Horizontal Screen Resolution" + default 320 + help + Horizontal screen resolution in pixels + +config LVGL_VER_RES + int "Vertical Screen Resolution" + default 240 + help + Vertical screen resolution in pixels + +config LVGL_DPI + int "DPI" + default 100 + help + Dots per inch (DPI) + +choice + prompt "Color Depth" + default LVGL_COLOR_DEPTH_32 + help + Color depth to be used by library + + config LVGL_COLOR_DEPTH_32 + bool "32-bit" + + config LVGL_COLOR_DEPTH_16 + bool "16-bit" + + config LVGL_COLOR_DEPTH_8 + bool "8-bit" + + config LVGL_COLOR_DEPTH_1 + bool "1-bit" + +endchoice + +config LVGL_BITS_PER_PIXEL + int "Bits per pixel" + default 0 + help + Number of bits per pixel, in case the number of pixels should be derived + from the color depth set the number of pixels to zero. + +if LVGL_COLOR_DEPTH_16 + +config LVGL_COLOR_16_SWAP + bool "RGB565 byte swap" + help + Swap the 2 bytes of a RGB565 pixel. + +endif + +if LVGL_COLOR_DEPTH_32 + +config CONFIG_LVGL_COLOR_SCREEN_TRANSP + bool "Transparency support" + help + Enable screen transparency. Useful for OSD or other overlapping GUISs. + +endif + +choice + prompt "Chroma key color" + default LVGL_CHROMA_KEY_GREEN + help + Color to to use as chroma key + + config LVGL_CHROMA_KEY_RED + bool "Red" + + config LVGL_CHROMA_KEY_GREEN + bool "Green" + + config LVGL_CHROMA_KEY_BLUE + bool "Blue" + + config LVGL_CHROMA_KEY_CUSTOM + bool "Custom" + +endchoice + +if LVGL_CHROMA_KEY_CUSTOM + +config LVGL_CUSTOM_CHROMA_KEY_RED + hex "Chroma Key Red" + range 0x00 0xFF + default 0x00 + help + Value of the color red to be used in the chroma key + +config LVGL_CUSTOM_CHROMA_KEY_GREEN + hex "Chroma Key Green" + range 0x00 0xFF + default 0xFF + help + Value of the color green to be used in the chroma key + +config LVGL_CUSTOM_CHROMA_KEY_BLUE + hex "Chroma Key Blue" + range 0x00 0xFF + default 0x00 + help + Value of the color blue to be used in the chroma key + +endif + +choice + prompt "Memory pool" + default LVGL_MEM_POOL_HEAP_KERNEL + help + Memory pool to use for lvgl allocated objects + + config LVGL_MEM_POOL_HEAP_KERNEL + bool "Kernel Heap" + depends on HEAP_MEM_POOL_SIZE != 0 + help + Use k_malloc and k_free to allocate objects on the kernel heap + + config LVGL_MEM_POOL_HEAP_LIB_C + bool "C library Heap" + depends on NEWLIB_LIBC || (MINIMAL_LIBC_MALLOC_ARENA_SIZE != 0) + help + Use C library malloc and free to allocate objects on the C library heap + + config LVGL_MEM_POOL_KERNEL + bool "Kernel space lvgl pool" + help + Use a dedicated memory pool in kernel space to allocate lvgl objects + on + + config LVGL_MEM_POOL_USER + bool "User space lvgl pool" + help + Use a dedicated memory pool in user space to allocate lvgl objects on + +endchoice + +if LVGL_MEM_POOL_KERNEL || LVGL_MEM_POOL_USER + +config LVGL_MEM_POOL_MIN_SIZE + int "Minimum memory pool block size" + default 16 + help + Size of the smallest block in the memory pool in bytes + +config LVGL_MEM_POOL_MAX_SIZE + int "Maximum memory pool block size" + default 2048 + help + Size of the largest block in the memory pool in bytes + +config LVGL_MEM_POOL_NUMBER_BLOCKS + int "Number of max size blocks in memory pool" + default 1 + help + Number of maximum sized blocks in the memory pool. + +endif + +config LVGL_VDB_SIZE + int "Virtual Display Buffer Size" + default 10 + range 1 100 + help + Virtual Display Buffer (double buffering) size as a percentage of + total display size. + +config LVGL_VDB_STATIC + bool "Statically allocate virtual display buffer" + default y + help + Statically allocate virtual display buffer. If disabled pointer should be + passed via lv_vdb_set_adr(). + +config LVGL_DOUBLE_VDB + bool "Use 2 Virtual Display Buffers" + help + Use 2 virtual display buffers to render and flush data in parallel + +config LVGL_SCREEN_REFRESH_PERIOD + int "Screen refresh period" + default 50 + help + Screen refresh period in milliseconds + +config LVGL_INPUT_REFRESH_PERIOD + int "Input device refresh period" + default 50 + help + Refresh period for input devices in milliseconds + +config LVGL_INPUT_MARK_PRESSED_POINTS + bool "Mark pressed points" + depends on LVGL_DIRECT_DRAW + help + Mark the pressed points on the screen. + +config LVGL_INPUT_DRAG_THRESHOLD + int "Drag Threshold" + default 10 + help + Threshold in pixels before entering drag mode + +config LVGL_INPUT_DRAG_THROW_SLOW_DOWN + int "Drag throw slow-down" + default 20 + range 0 100 + help + Percentage of slow down of a throw following a drag. + Greater percentage means faster slow-down. + +config LVGL_INPUT_LONG_PRESS_TIME + int "Long press time" + default 400 + help + Period in milliseconds before a press is seen as a long press + +config LVGL_INPUT_LONG_RESS_REPEAT_TIME + int "Long press repeat time" + default 100 + help + Period in milliseconds after which a new trigger is generated + for a long press + +config LVGL_AVG_OBJ_COUNT + int "Average object counter" + default 32 + help + Average object counter on a screen + +config LVGL_UTF_8 + bool "Enable UTF-8 support" + default y + help + Enable UTF-8 support + +config LVGL_TEXT_BREAK_CHARACTERS + string "Text break characters" + default " ,.;:-_" + help + Characters on which a text break can take place + +config LVGL_ANTIALIAS + bool "Enable anti-aliasing" + default y + help + Enable anti-aliasing + +config LVGL_ANIMATION + bool "Enable animations" + default y + help + Enable animations + +config LVGL_SHADOW + bool "Enable shadows" + default y + help + Enable shadows + +config LVGL_GROUP + bool "Enable group support" + default y + help + Enable group support. + Used by keyboard and button input + +config LVGL_GPU + bool "Enable GPU support" + help + Enable GPU support + +config LVGL_DIRECT_DRAW + bool "Enable direct draw" + default y + help + Enable direct draw support. + Direct draw bypasses virtual display buffer and directly writes to + frame buffer + +config LVGL_FILESYSTEM + bool "Enable file system" + depends on FILE_SYSTEM + default y if FILE_SYSTEM + help + Enable LittlevGL file system + +config LVGL_VLA_SUPPORT + bool "Enable variable length array support" + default y + help + Enable variable length array support + +config LVGL_COMPILER_NON_CONST_INIT_SUPPORTED + bool "Enable non constant init" + default y + help + Indicate if initialization with non constant values is supported + +rsource "Kconfig.themes" + +rsource "Kconfig.fonts" + +rsource "Kconfig.objects" + +config APP_LINK_WITH_LVGL + bool "Link 'app' with LVGL" + default y + depends on LVGL + help + Add LVGL header files to the 'app' include path. It may be + disabled if the include paths for LVGL are causing aliasing + issues for 'app'. + +endif + diff --git a/lib/gui/lvgl/Kconfig.fonts b/lib/gui/lvgl/Kconfig.fonts new file mode 100644 index 00000000000000..b101c6bf46ddbf --- /dev/null +++ b/lib/gui/lvgl/Kconfig.fonts @@ -0,0 +1,189 @@ +# +# Copyright (c) 2018 Jan Van Winkel +# +# SPDX-License-Identifier: Apache-2.0 +# + +menu "Fonts" + +config LVGL_BUILD_IN_FONTS + bool "Enable build-in fonts" + default y + help + Enable build-in font support + +if LVGL_BUILD_IN_FONTS + +config LVGL_BUILD_IN_FONT_10 + bool "Enable build-in 10px fonts" + help + Enable build-in font support, size 10 pixels + +if LVGL_BUILD_IN_FONT_10 + +config LVGL_BUILD_IN_FONT_10_ASCII_BPP + int "ASCII character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_10_LATIN_SUP_BPP + int "Latin supplement character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_10_CYRILLIC_BPP + int "Cyrillic character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_10_SYMBOL_BPP + int "Symbol character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +endif + +config LVGL_BUILD_IN_FONT_20 + bool "Enable build-in 20px fonts" + default y + help + Enable build-in font support, size 20 pixels + +if LVGL_BUILD_IN_FONT_20 + +config LVGL_BUILD_IN_FONT_20_ASCII_BPP + int "ASCII character set BPP" + default 4 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_20_LATIN_SUP_BPP + int "Latin supplement character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_20_CYRILLIC_BPP + int "Cyrillic character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_20_SYMBOL_BPP + int "Symbol character set BPP" + default 4 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +endif + +config LVGL_BUILD_IN_FONT_30 + bool "Enable build-in 30px fonts" + help + Enable build-in font support, size 30 pixels + +if LVGL_BUILD_IN_FONT_30 + +config LVGL_BUILD_IN_FONT_30_ASCII_BPP + int "ASCII character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_30_LATIN_SUP_BPP + int "Latin supplement character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_30_CYRILLIC_BPP + int "Cyrillic character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_30_SYMBOL_BPP + int "Symbol character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +endif + +config LVGL_BUILD_IN_FONT_40 + bool "Enable build-in 40px fonts" + help + Enable build-in font support, size 40 pixels + +if LVGL_BUILD_IN_FONT_40 + +config LVGL_BUILD_IN_FONT_40_ASCII_BPP + int "ASCII character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_40_LATIN_SUP_BPP + int "Latin supplement character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_40_CYRILLIC_BPP + int "Cyrillic character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +config LVGL_BUILD_IN_FONT_40_SYMBOL_BPP + int "Symbol character set BPP" + default 0 + help + Bits per pixel (1,2,4,8) for font, 0 will disable font + +endif + +endif + +config LVGL_BUILD_IN_FONT_MONOSPACE + bool "Enable build-in monospace font" + help + Enable build-in monospace font support + +choice + prompt "Default LVGL font" + default LVGL_DEFAULT_FONT_BUILD_IN_20_ASCII + + config LVGL_DEFAULT_FONT_BUILD_IN_10_ASCII + bool "Build-in ASCII font 10" + depends on LVGL_BUILD_IN_FONT_10 && LVGL_BUILD_IN_FONT_10_ASCII_BPP != 0 + + config LVGL_DEFAULT_FONT_BUILD_IN_20_ASCII + bool "Build-in ASCII font 20" + depends on LVGL_BUILD_IN_FONT_20 && LVGL_BUILD_IN_FONT_20_ASCII_BPP != 0 + + config LVGL_DEFAULT_FONT_BUILD_IN_30_ASCII + bool "Build-in ASCII font 30" + depends on LVGL_BUILD_IN_FONT_30 && LVGL_BUILD_IN_FONT_30_ASCII_BPP != 0 + + config LVGL_DEFAULT_FONT_BUILD_IN_40_ASCII + bool "Build-in ASCII font 40" + depends on LVGL_BUILD_IN_FONT_40 && LVGL_BUILD_IN_FONT_40_ASCII_BPP != 0 + + config LVGL_DEFAULT_FONT_BUILD_IN_MONOSPACE + bool "Build-in monospace font" + depends on LVGL_BUILD_IN_FONT_MONOSPACE + + config LVGL_DEFAULT_FONT_CUSTOM + bool "Custom font" + help + Use a none build-in font as default font. A pointer named lv_default_font_custom_ptr + should exists as a global variable and pint yo a valid font structure + +endchoice + +endmenu diff --git a/lib/gui/lvgl/Kconfig.objects b/lib/gui/lvgl/Kconfig.objects new file mode 100644 index 00000000000000..cc65364f7d0c35 --- /dev/null +++ b/lib/gui/lvgl/Kconfig.objects @@ -0,0 +1,296 @@ +# +# Copyright (c) 2018 Jan Van Winkel +# +# SPDX-License-Identifier: Apache-2.0 +# + +menu "Objects" + +config LVGL_OBJ_LABEL + bool "Label Object" + default y + help + Enable label support + +if LVGL_OBJ_LABEL + +config LVGL_OBJ_LABEL_SCROLL_SPEED + int "Label scroll speed" + default 25 + help + Scroll speed in pixels per second if scroll mode is enabled for a label + +endif + +config LVGL_OBJ_IMAGE + bool "Image Object" + default y + depends on LVGL_OBJ_LABEL + help + Enable image object support + +if LVGL_OBJ_IMAGE + +config LVGL_IMG_CF_INDEXED + bool "Enable indexed image support" + default y + help + Enable support for indexed images + +config LVGL_IMG_CF_ALPHA + bool "Enable alpha indexed image support" + default y + help + Enable support for alpha indexed images + +endif + +config LVGL_OBJ_LINE + bool "Line Object" + default y + help + Enable line object support + +config LVGL_OBJ_ARC + bool "Arc Object" + default y + help + Enable arc object support + +config LVGL_OBJ_CONTAINER + bool "Container Object" + default y + help + Enable container object support + +config LVGL_OBJ_PAGE + bool "Page object" + default y + depends on LVGL_OBJ_CONTAINER + help + Enable page object support + +config LVGL_OBJ_WINDOW + bool "Window object" + default y + depends on LVGL_OBJ_CONTAINER && LVGL_OBJ_BUTTON && LVGL_OBJ_LABEL && LVGL_OBJ_IMAGE && LVGL_OBJ_PAGE + help + Enable window object support + +config LVGL_OBJ_TAB_VIEW + bool "Tab view object" + default y + depends on LVGL_OBJ_PAGE && LVGL_OBJ_BUTTON_MATRIX + help + Enable tab view object support + +if LVGL_OBJ_TAB_VIEW + +config LVGL_OBJ_TAB_VIEW_ANIMATION_TIME + int "Tab view animation time" + default 300 + help + Tab view animation time in milliseconds + +endif + +config LVGL_OBJ_CALENDAR + bool "Calendar object" + default y + help + Enable calendar object support + +config LVGL_OBJ_PRELOAD + bool "Pre-load object" + default y + depends on LVGL_OBJ_ARC + help + Enabled pre-load object support + +if LVGL_OBJ_PRELOAD + +config LVGL_OBJ_PRELOAD_DEF_ARC_LENGTH + int "Default arc length" + range 1 360 + default 60 + help + Default arc length for pre-load in degrees + +config LVGL_OBJ_PRELOAD_DEF_SPIN_TIME + int "Default spin time" + default 1000 + help + Default spin time for pre-load in ms + +endif + +config LVGL_OBJ_BAR + bool "Bar object" + default y + help + Enable bar object support + +config LVGL_OBJ_LINE_METER + bool "Line meter object" + default y + help + Enable line meter object support + +config LVGL_OBJ_GAUGE + bool "Gauge object" + default y + depends on LVGL_OBJ_BAR && LVGL_OBJ_LINE_METER + help + Enable gauge object support + +config LVGL_OBJ_CHART + bool "Chart object" + default y + help + Enable chart object support + +config LVGL_OBJ_LED + bool "LED object" + default y + help + Enable LED object support + +config LVGL_OBJ_MSG_BOX + bool "Message box object" + default y + depends on LVGL_OBJ_BUTTON_MATRIX && LVGL_OBJ_LABEL + help + Enable message box object support + +config LVGL_OBJ_TEXT_AREA + bool "Text area object" + default y + depends on LVGL_OBJ_LABEL && LVGL_OBJ_PAGE + help + Enable text area object support + +if LVGL_OBJ_TEXT_AREA + +config LVGL_OBJ_TEXT_AREA_CURSOR_BLINK_TIME + int "Cursor Blink Time" + default 400 + help + Text area cursor blink time in milliseconds + +config LVGL_OBJ_TEXT_AREA_PWD_SHOW_TIME + int "Label scroll speed" + default 1500 + help + Password character show time in milliseconds + +endif + +config LVGL_OBJ_BUTTON + bool "Button object" + default y + depends on LVGL_OBJ_CONTAINER + help + Enable button object support + +if LVGL_OBJ_BUTTON + +config LVGL_OBJ_BUTTON_INK_EFFECT + bool "Enable ink effect" + default y + help + Enable ink, press, effect for buttons + +config LVGL_OBJ_IMG_BUTTON + bool "Image Button" + default y + help + Enable image button object support + +endif + +config LVGL_OBJ_BUTTON_MATRIX + bool "Button Matrix object" + default y + help + Enable button matrix object support + +config LVGL_OBJ_KEYBOARD + bool "Keyboard object" + default y + depends on LVGL_OBJ_BUTTON_MATRIX + help + Enable keyboard object support + +config LVGL_OBJ_CHECK_BOX + bool "Check box object" + default y + depends on LVGL_OBJ_BUTTON && LVGL_OBJ_LABEL + help + Enable check box object support + +config LVGL_OBJ_LIST + bool "List object" + default y + depends on LVGL_OBJ_BUTTON && LVGL_OBJ_LABEL && LVGL_OBJ_PAGE + help + Enable list object support + +if LVGL_OBJ_LIST + +config LVGL_OBJ_LIST_FOCUS_TIME + int "List focus time" + default 100 + help + List focus animation time in milliseconds + +endif + +config LVGL_OBJ_DROP_DOWN_LIST + bool "Drop Down List object" + default y + depends on LVGL_OBJ_LABEL && LVGL_OBJ_PAGE + help + Enable drop down list object support + +if LVGL_OBJ_DROP_DOWN_LIST + +config LVGL_OBJ_DROP_DOWN_LIST_ANIM_TIME + int "Drop Down list animation time" + default 200 + help + Drop down list animation time in milliseconds + +endif + +config LVGL_OBJ_ROLLER + bool "Roller object" + default y + depends on LVGL_OBJ_DROP_DOWN_LIST + help + Enable roller object support + +if LVGL_OBJ_ROLLER + +config LVGL_OBJ_ROLLER_ANIM_TIME + int "Roller animation time" + default 200 + help + Roller animation time in milliseconds + +endif + +config LVGL_OBJ_SLIDER + bool "Slider object" + default y + depends on LVGL_OBJ_BAR + help + Enable slider object support + +config LVGL_OBJ_SWITCH + bool "Switch object" + default y + depends on LVGL_OBJ_SLIDER + help + Enable switch object support + +endmenu diff --git a/lib/gui/lvgl/Kconfig.themes b/lib/gui/lvgl/Kconfig.themes new file mode 100644 index 00000000000000..160e89a14e03f2 --- /dev/null +++ b/lib/gui/lvgl/Kconfig.themes @@ -0,0 +1,59 @@ +# +# Copyright (c) 2018 Jan Van Winkel +# +# SPDX-License-Identifier: Apache-2.0 +# + +menu "Themes" + +config LVGL_THEMES + bool "Enable build-in themes" + help + Enable build-in themes + +if LVGL_THEMES + +config LVGL_THEME_LIVE_UPDATE + bool "Enable runtime theme switching" + help + Enable runtime theme switching, this will consume 8 to 10kB of RAM. + +config LVGL_THEME_DEFAULT + bool "Enable default theme support" + help + Enable default theme support. + Low RAM footprint theme. + +config LVGL_THEME_ALIEN + bool "Enable alien theme support" + help + Enable alien theme, dark futuristic, support + +config LVGL_THEME_NIGHT + bool "Enable night theme support" + help + Enable night theme, dark elegant, support + +config LVGL_THEME_MONO + bool "Enable mono theme support" + help + Enable mono theme, monochrome, support + +config LVGL_THEME_MATERIAL + bool "Enable material theme support" + help + Enable material theme, flat theme with bold colors and light shadow, support + +config LVGL_THEME_ZEN + bool "Enable zen theme support" + help + Enable zen theme, peaceful light theme, support + +config LVGL_THEME_NEMO + bool "Enable nemo theme support" + help + Enable water-like theme based on the movie "Finding Nemo" + +endif + +endmenu diff --git a/lib/gui/lvgl/lv_conf.h b/lib/gui/lvgl/lv_conf.h new file mode 100644 index 00000000000000..dcfe0a9ad2cf17 --- /dev/null +++ b/lib/gui/lvgl/lv_conf.h @@ -0,0 +1,374 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_GUI_LVGL_LV_CONF_H_ +#define ZEPHYR_LIB_GUI_LVGL_LV_CONF_H_ + +/* Dynamic memory */ + +#define LV_MEM_CUSTOM 1 + +#ifdef CONFIG_LVGL_MEM_POOL_HEAP_KERNEL + +#define LV_MEM_CUSTOM_INCLUDE "kernel.h" +#define LV_MEM_CUSTOM_ALLOC k_malloc +#define LV_MEM_CUSTOM_FREE k_free + +#elif defined(CONFIG_LVGL_MEM_POOL_HEAP_LIB_C) + +#define LV_MEM_CUSTOM_INCLUDE "stdlib.h" +#define LV_MEM_CUSTOM_ALLOC malloc +#define LV_MEM_CUSTOM_FREE free + +#else + +#define LV_MEM_CUSTOM_INCLUDE "lvgl_mem.h" +#define LV_MEM_CUSTOM_ALLOC lvgl_malloc +#define LV_MEM_CUSTOM_FREE lvgl_free + +#endif + +/* Graphics settings */ + +#define LV_HOR_RES CONFIG_LVGL_HOR_RES +#define LV_VER_RES CONFIG_LVGL_VER_RES +#define LV_DPI CONFIG_LVGL_DPI + +#define LV_VDB_SIZE (CONFIG_LVGL_VDB_SIZE * CONFIG_LVGL_HOR_RES \ + * CONFIG_LVGL_VER_RES / 100) + +#if CONFIG_LVGL_BITS_PER_PIXEL == 0 +#define LV_VDB_PX_BPP LV_COLOR_SIZE +#else +#define LV_VDB_PX_BPP CONFIG_LVGL_BITS_PER_PIXEL +#endif + +#ifdef CONFIG_LVGL_VDB_STATIC +#define LV_VDB_ADR 0 +#else +#define LV_VDB_ADR LV_VDB_ADR_INV +#endif + + +#define LV_VDB_DOUBLE CONFIG_LVGL_DOUBLE_VDB +#ifdef CONFIG_LVGL_VDB_STATIC +#define LV_VDB2_ADR 0 +#else +#define LV_VDB2_ADR LV_VDB_ADR_INV +#endif + +#ifdef CONFIG_LVGL_ANTIALIAS +#define LV_ANTIALIAS CONFIG_LVGL_ANTIALIAS +#else +#define LV_ANTIALIAS 0 +#endif + +#define LV_REFR_PERIOD CONFIG_LVGL_SCREEN_REFRESH_PERIOD +#define LV_INV_FIFO_SIZE CONFIG_LVGL_AVG_OBJ_COUNT + +/* Miscellaneous setting */ + +#define LV_INDEV_READ_PERIOD CONFIG_LVGL_INPUT_REFRESH_PERIOD +#define LV_INDEV_POINT_MARKER CONFIG_LVGL_INPUT_MARK_PRESSED_POINTS +#define LV_INDEV_DRAG_LIMIT CONFIG_LVGL_INPUT_DRAG_THRESHOLD +#define LV_INDEV_DRAG_THROW CONFIG_LVGL_INPUT_DRAG_THROW_SLOW_DOWN +#define LV_INDEV_LONG_PRESS_TIME CONFIG_LVGL_INPUT_LONG_PRESS_TIME +#define LV_INDEV_LONG_PRESS_REP_TIME CONFIG_LVGL_INPUT_LONG_RESS_REPEAT_TIME + +#ifdef CONFIG_LVGL_COLOR_DEPTH_32 +#define LV_COLOR_DEPTH 32 +#elif defined(CONFIG_LVGL_COLOR_DEPTH_16) +#define LV_COLOR_DEPTH 16 +#elif defined(CONFIG_LVGL_COLOR_DEPTH_8) +#define LV_COLOR_DEPTH 8 +#elif defined(CONFIG_LVGL_COLOR_DEPTH_1) +#define LV_COLOR_DEPTH 1 +#else +#error No color depth defined +#endif + +#define LV_COLOR_16_SWAP CONFIG_LVGL_COLOR_16_SWAP +#define LV_COLOR_SCREEN_TRANSP CONFIG_LVGL_COLOR_SCREEN_TRANSP + +#ifdef CONFIG_LVGL_CHROMA_KEY_RED +#define LV_COLOR_TRANSP LV_COLOR_RED +#elif defined(CONFIG_LVGL_CHROMA_KEY_GREEN) +#define LV_COLOR_TRANSP LV_COLOR_LIME +#elif defined(CONFIG_LVGL_CHROMA_KEY_BLUE) +#define LV_COLOR_TRANSP LV_COLOR_BLUE +#elif defined(CONFIG_LVGL_CHROMA_KEY_CUSTOM) +#define LV_COLOR_TRANSP LV_COLOR_MAKE(CONFIG_LVGL_CUSTOM_CHROMA_KEY_RED, \ + CONFIG_LVGL_CUSTOM_CHROMA_KEY_GREEN, \ + CONFIG_LVGL_CUSTOM_CHROMA_KEY_BLUE) +#else +#error No chroma key defined +#endif + +#define LV_TXT_UTF8 CONFIG_LVGL_UTF_8 +#define LV_TXT_BREAK_CHARS CONFIG_LVGL_TEXT_BREAK_CHARACTERS + +#define USE_LV_ANIMATION CONFIG_LVGL_ANIMATION +#define USE_LV_SHADOW CONFIG_LVGL_SHADOW +#define USE_LV_GROUP CONFIG_LVGL_GROUP +#define USE_LV_GPU CONFIG_LVGL_GPU +#define USE_LV_REAL_DRAW CONFIG_LVGL_DIRECT_DRAW +#define USE_LV_FILESYSTEM CONFIG_LVGL_FILESYSTEM + +#define LV_ATTRIBUTE_TICK_INC +#define LV_ATTRIBUTE_TASK_HANDLER +#define LV_COMPILER_VLA_SUPPORTED CONFIG_LVGL_VLA_SUPPORT +#define LV_COMPILER_NON_CONST_INIT_SUPPORTED \ + CONFIG_LVGL_COMPILER_NON_CONST_INIT_SUPPORTED + +#define LV_TICK_CUSTOM 1 +#define LV_TICK_CUSTOM_INCLUDE "kernel.h" +#define LV_TICK_CUSTOM_SYS_TIME_EXPR (k_uptime_get_32()) + +#if CONFIG_LVGL_LOG_LEVEL == 0 +#define USE_LV_LOG 0 +#else +#define USE_LV_LOG 1 + +#if CONFIG_LVGL_LOG_LEVEL == 1 +#define LV_LOG_LEVEL LV_LOG_LEVEL_ERROR +#elif CONFIG_LVGL_LOG_LEVEL == 2 +#define LV_LOG_LEVEL LV_LOG_LEVEL_WARN +#elif CONFIG_LVGL_LOG_LEVEL == 3 +#define LV_LOG_LEVEL LV_LOG_LEVEL_INFO +#elif CONFIG_LVGL_LOG_LEVEL == 4 +#define LV_LOG_LEVEL LV_LOG_LEVEL_TRACE +#else +#error Invalid log level defined +#endif + +#define LV_LOG_PRINTF 0 +#endif + +/* Theme support */ + +#ifdef CONFIG_LVGL_THEMES + +#define LV_THEME_LIVE_UPDATE CONFIG_LVGL_THEME_LIVE_UPDATE + +#define USE_LV_THEME_TEMPL 0 +#define USE_LV_THEME_DEFAULT CONFIG_LVGL_THEME_DEFAULT +#define USE_LV_THEME_ALIEN CONFIG_LVGL_THEME_ALIEN +#define USE_LV_THEME_NIGHT CONFIG_LVGL_THEME_NIGHT +#define USE_LV_THEME_MONO CONFIG_LVGL_THEME_MONO +#define USE_LV_THEME_MATERIAL CONFIG_LVGL_THEME_MATERIAL +#define USE_LV_THEME_ZEN CONFIG_LVGL_THEME_ZEN +#define USE_LV_THEME_NEMO CONFIG_LVGL_THEME_NEMO + +#else + +#define LV_THEME_LIVE_UPDATE 0 + +#define USE_LV_THEME_TEMPL 0 +#define USE_LV_THEME_DEFAULT 0 +#define USE_LV_THEME_ALIEN 0 +#define USE_LV_THEME_NIGHT 0 +#define USE_LV_THEME_MONO 0 +#define USE_LV_THEME_MATERIAL 0 +#define USE_LV_THEME_ZEN 0 +#define USE_LV_THEME_NEMO 0 + +#endif + +/* Font support */ + +#ifdef CONFIG_LVGL_DEFAULT_FONT_BUILD_IN_10_ASCII +#define LV_FONT_DEFAULT (&lv_font_dejavu_10) +#elif defined(CONFIG_LVGL_DEFAULT_FONT_BUILD_IN_20_ASCII) +#define LV_FONT_DEFAULT (&lv_font_dejavu_20) +#elif defined(CONFIG_LVGL_DEFAULT_FONT_BUILD_IN_30_ASCII) +#define LV_FONT_DEFAULT (&lv_font_dejavu_30) +#elif defined(CONFIG_LVGL_DEFAULT_FONT_BUILD_IN_40_ASCII) +#define LV_FONT_DEFAULT (&lv_font_dejavu_40) +#elif defined(CONFIG_LVGL_DEFAULT_FONT_BUILD_IN_MONOSPACE) +#define LV_FONT_DEFAULT (&lv_font_monospace_8) +#elif defined(CONFIG_LVGL_DEFAULT_FONT_CUSTOM) +extern void *lv_default_font_custom_ptr; +#define LV_FONT_DEFAULT ((lv_font_t *) lv_default_font_custom_ptr) +#else +#error No defulat font defined +#endif + +#ifdef CONFIG_LVGL_BUILD_IN_FONT_10 + +#define USE_LV_FONT_DEJAVU_10 \ + CONFIG_LVGL_BUILD_IN_FONT_10_ASCII_BPP +#define USE_LV_FONT_DEJAVU_10_LATIN_SUP \ + CONFIG_LVGL_BUILD_IN_FONT_10_LATIN_SUP_BPP +#define USE_LV_FONT_DEJAVU_10_CYRILLIC \ + CONFIG_LVGL_BUILD_IN_FONT_10_CYRILLIC_BPP +#define USE_LV_FONT_SYMBOL_10 \ + CONFIG_LVGL_BUILD_IN_FONT_10_SYMBOL_BPP + +#else + +#define USE_LV_FONT_DEJAVU_10 0 +#define USE_LV_FONT_DEJAVU_10_LATIN_SUP 0 +#define USE_LV_FONT_DEJAVU_10_CYRILLIC 0 +#define USE_LV_FONT_SYMBOL_10 0 + +#endif + +#if CONFIG_LVGL_BUILD_IN_FONT_20 + +#define USE_LV_FONT_DEJAVU_20 \ + CONFIG_LVGL_BUILD_IN_FONT_20_ASCII_BPP +#define USE_LV_FONT_DEJAVU_20_LATIN_SUP \ + CONFIG_LVGL_BUILD_IN_FONT_20_LATIN_SUP_BPP +#define USE_LV_FONT_DEJAVU_20_CYRILLIC \ + CONFIG_LVGL_BUILD_IN_FONT_20_CYRILLIC_BPP +#define USE_LV_FONT_SYMBOL_20 \ + CONFIG_LVGL_BUILD_IN_FONT_20_SYMBOL_BPP + +#else + +#define USE_LV_FONT_DEJAVU_20 0 +#define USE_LV_FONT_DEJAVU_20_LATIN_SUP 0 +#define USE_LV_FONT_DEJAVU_20_CYRILLIC 0 +#define USE_LV_FONT_SYMBOL_20 0 + +#endif + +#if CONFIG_LVGL_BUILD_IN_FONT_30 + +#define USE_LV_FONT_DEJAVU_30 \ + CONFIG_LVGL_BUILD_IN_FONT_30_ASCII_BPP +#define USE_LV_FONT_DEJAVU_30_LATIN_SUP \ + CONFIG_LVGL_BUILD_IN_FONT_30_LATIN_SUP_BPP +#define USE_LV_FONT_DEJAVU_30_CYRILLIC \ + CONFIG_LVGL_BUILD_IN_FONT_30_CYRILLIC_BPP +#define USE_LV_FONT_SYMBOL_30 \ + CONFIG_LVGL_BUILD_IN_FONT_30_SYMBOL_BPP + +#else + +#define USE_LV_FONT_DEJAVU_30 0 +#define USE_LV_FONT_DEJAVU_30_LATIN_SUP 0 +#define USE_LV_FONT_DEJAVU_30_CYRILLIC 0 +#define USE_LV_FONT_SYMBOL_30 0 + +#endif + +#if CONFIG_LVGL_BUILD_IN_FONT_40 + +#define USE_LV_FONT_DEJAVU_40 \ + CONFIG_LVGL_BUILD_IN_FONT_40_ASCII_BPP +#define USE_LV_FONT_DEJAVU_40_LATIN_SUP \ + CONFIG_LVGL_BUILD_IN_FONT_40_LATIN_SUP_BPP +#define USE_LV_FONT_DEJAVU_40_CYRILLIC \ + CONFIG_LVGL_BUILD_IN_FONT_40_CYRILLIC_BPP +#define USE_LV_FONT_SYMBOL_40 \ + CONFIG_LVGL_BUILD_IN_FONT_40_SYMBOL_BPP + +#else + +#define USE_LV_FONT_DEJAVU_40 0 +#define USE_LV_FONT_DEJAVU_40_LATIN_SUP 0 +#define USE_LV_FONT_DEJAVU_40_CYRILLIC 0 +#define USE_LV_FONT_SYMBOL_40 0 + +#endif + +#define USE_LV_FONT_MONOSPACE_8 CONFIG_LVGL_BUILD_IN_FONT_MONOSPACE + +#define LV_FONT_CUSTOM_DECLARE + +/* Objects */ +#define LV_OBJ_FREE_NUM_TYPE uint32_t +#define LV_OBJ_FREE_PTR 1 + +#define USE_LV_LABEL CONFIG_LVGL_OBJ_LABEL +#if USE_LV_LABEL != 0 +#define LV_LABEL_SCROLL_SPEED CONFIG_LVGL_OBJ_LABEL_SCROLL_SPEED +#endif + +#define USE_LV_IMG CONFIG_LVGL_OBJ_IMAGE +#if USE_LV_IMG != 0 +#define LV_IMG_CF_INDEXED CONFIG_LVGL_IMG_CF_INDEXED +#define LV_IMG_CF_ALPHA CONFIG_LVGL_IMG_CF_ALPHA +#endif + +#define USE_LV_LINE CONFIG_LVGL_OBJ_LINE + +#define USE_LV_ARC CONFIG_LVGL_OBJ_ARC + +#define USE_LV_CONT CONFIG_LVGL_OBJ_CONTAINER + +#define USE_LV_PAGE CONFIG_LVGL_OBJ_PAGE + +#define USE_LV_WIN CONFIG_LVGL_OBJ_WINDOW + +#define USE_LV_TABVIEW CONFIG_LVGL_OBJ_TAB_VIEW +#if USE_LV_TABVIEW != 0 +#define LV_TABVIEW_ANIM_TIME CONFIG_LVGL_OBJ_TAB_VIEW_ANIMATION_TIME +#endif + +#define USE_LV_CALENDAR CONFIG_LVGL_OBJ_CALENDAR + +#define USE_LV_PRELOAD CONFIG_LVGL_OBJ_PRELOAD +#if USE_LV_PRELOAD != 0 +#define LV_PRELOAD_DEF_ARC_LENGTH CONFIG_LVGL_OBJ_PRELOAD_DEF_ARC_LENGTH +#define LV_PRELOAD_DEF_SPIN_TIME CONFIG_LVGL_OBJ_PRELOAD_DEF_SPIN_TIME +#endif + +#define USE_LV_BAR CONFIG_LVGL_OBJ_BAR + +#define USE_LV_LMETER CONFIG_LVGL_OBJ_LINE_METER + +#define USE_LV_GAUGE CONFIG_LVGL_OBJ_GAUGE + +#define USE_LV_CHART CONFIG_LVGL_OBJ_CHART + +#define USE_LV_LED CONFIG_LVGL_OBJ_LED + +#define USE_LV_MBOX CONFIG_LVGL_OBJ_MSG_BOX + +#define USE_LV_TA CONFIG_LVGL_OBJ_TEXT_AREA +#if USE_LV_TA != 0 +#define LV_TA_CURSOR_BLINK_TIME \ + CONFIG_LVGL_OBJ_TEXT_AREA_CURSOR_BLINK_TIME +#define LV_TA_PWD_SHOW_TIME \ + CONFIG_LVGL_OBJ_TEXT_AREA_PWD_SHOW_TIME +#endif + +#define USE_LV_BTN CONFIG_LVGL_OBJ_BUTTON + +#if USE_LV_BTN != 0 +#define LV_BTN_INK_EFFECT CONFIG_LVGL_OBJ_BUTTON_INK_EFFECT +#endif + +#define USE_LV_IMGBTN CONFIG_LVGL_OBJ_IMG_BUTTON + +#define USE_LV_BTNM CONFIG_LVGL_OBJ_BUTTON_MATRIX + +#define USE_LV_KB CONFIG_LVGL_OBJ_KEYBOARD + +#define USE_LV_CB CONFIG_LVGL_OBJ_CHECK_BOX + +#define USE_LV_LIST CONFIG_LVGL_OBJ_LIST +#if USE_LV_LIST != 0 +#define LV_LIST_FOCUS_TIME CONFIG_LVGL_OBJ_LIST_FOCUS_TIME +#endif + +#define USE_LV_DDLIST CONFIG_LVGL_OBJ_DROP_DOWN_LIST +#if USE_LV_DDLIST != 0 +#define LV_DDLIST_ANIM_TIME CONFIG_LVGL_OBJ_DROP_DOWN_LIST_ANIM_TIME +#endif + +#define USE_LV_ROLLER CONFIG_LVGL_OBJ_ROLLER +#if USE_LV_ROLLER != 0 +#define LV_ROLLER_ANIM_TIME CONFIG_LVGL_OBJ_ROLLER_ANIM_TIME +#endif + +#define USE_LV_SLIDER CONFIG_LVGL_OBJ_SLIDER + +#define USE_LV_SW CONFIG_LVGL_OBJ_SWITCH + +#endif /* ZEPHYR_LIB_GUI_LVGL_LV_CONF_H_ */ diff --git a/lib/gui/lvgl/lvgl.c b/lib/gui/lvgl/lvgl.c new file mode 100644 index 00000000000000..43693741f04220 --- /dev/null +++ b/lib/gui/lvgl/lvgl.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include "lvgl_color.h" +#include "lvgl_fs.h" + +#define LOG_LEVEL CONFIG_LVGL_LOG_LEVEL +#include +LOG_MODULE_REGISTER(lvgl); + +struct device *lvgl_display_dev; + +#if CONFIG_LVGL_LOG_LEVEL != 0 +static void lvgl_log(lv_log_level_t level, const char *file, uint32_t line, + const char *dsc) +{ + /* Convert LVGL log level to Zephyr log lvel + * + * LVGL log level mapping: + * * LV_LOG_LEVEL_TRACE 0 + * * LV_LOG_LEVEL_INFO 1 + * * LV_LOG_LEVEL_WARN 2 + * * LV_LOG_LEVEL_ERROR 3 + * * LV_LOG_LEVEL_NUM 4 + * + * Zephyr log level mapping: + * * LOG_LEVEL_NONE 0 + * * LOG_LEVEL_ERR 1 + * * LOG_LEVEL_WRN 2 + * * LOG_LEVEL_INF 3 + * * LOG_LEVEL_DBG 4 + */ + u8_t zephyr_level = LOG_LEVEL_DBG - level; + + ARG_UNUSED(file); + ARG_UNUSED(line); + + _LOG(zephyr_level, "%s", dsc); +} +#endif + + +static int lvgl_init(struct device *dev) +{ + lv_disp_drv_t disp_drv; + + ARG_UNUSED(dev); + + lvgl_display_dev = device_get_binding(CONFIG_LVGL_DISPLAY_DEV_NAME); + + if (lvgl_display_dev == NULL) { + LOG_ERR("Display device not found."); + return -ENODEV; + } + +#if CONFIG_LVGL_LOG_LEVEL != 0 + lv_log_register_print(lvgl_log); +#endif + + lv_init(); + +#ifdef CONFIG_LVGL_FILESYSTEM + lvgl_fs_init(); +#endif + + lv_refr_set_round_cb(get_round_func()); + + lv_disp_drv_init(&disp_drv); + disp_drv.disp_flush = get_disp_flush(); + +#if CONFIG_LVGL_VDB_SIZE != 0 + disp_drv.vdb_wr = get_vdb_write(); +#endif + if (lv_disp_drv_register(&disp_drv) == NULL) { + LOG_ERR("Failed to register display device."); + return -EPERM; + } + + return 0; +} + +SYS_INIT(lvgl_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/lib/gui/lvgl/lvgl_color.h b/lib/gui/lvgl/lvgl_color.h new file mode 100644 index 00000000000000..22b47492ae03ab --- /dev/null +++ b/lib/gui/lvgl/lvgl_color.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_GUI_LVGL_LVGL_COLOR_H_ +#define ZEPHYR_LIB_GUI_LVGL_LVGL_COLOR_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct device *lvgl_display_dev; + +void *get_disp_flush(void); +void *get_vdb_write(void); +void *get_round_func(void); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_LIB_GUI_LVGL_LVGL_COLOR_H */ diff --git a/lib/gui/lvgl/lvgl_color_1.c b/lib/gui/lvgl/lvgl_color_1.c new file mode 100644 index 00000000000000..52e7d597e6b0c3 --- /dev/null +++ b/lib/gui/lvgl/lvgl_color_1.c @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "lvgl_color.h" + +#if CONFIG_LVGL_BITS_PER_PIXEL == 1 + +static void zephyr_disp_flush(s32_t x1, s32_t y1, s32_t x2, s32_t y2, + const lv_color_t *color_p) +{ + u16_t w = x2 - x1 + 1; + u16_t h = y2 - y1 + 1; + struct display_capabilities cap; + struct display_buffer_descriptor desc; + + display_get_capabilities(lvgl_display_dev, &cap); + + desc.buf_size = (w * h)/8; + desc.width = w; + desc.pitch = w; + desc.height = h; + display_write(lvgl_display_dev, x1, y1, &desc, (void *) color_p); + if (cap.screen_info & SCREEN_INFO_DOUBLE_BUFFER) { + display_write(lvgl_display_dev, x1, y1, &desc, + (void *) color_p); + } + + lv_flush_ready(); +} + +void zephyr_vdb_write(u8_t *buf, lv_coord_t buf_w, lv_coord_t x, + lv_coord_t y, lv_color_t color, lv_opa_t opa) +{ + u8_t *buf_xy = buf + x + y/8 * buf_w; + u8_t bit; + struct display_capabilities cap; + + display_get_capabilities(lvgl_display_dev, &cap); + + if (cap.screen_info & SCREEN_INFO_MONO_MSB_FIRST) { + bit = 7 - y%8; + } else { + bit = y%8; + } + + if (cap.current_pixel_format == PIXEL_FORMAT_MONO10) { + if (color.full == 0) { + *buf_xy &= ~BIT(bit); + } else { + *buf_xy |= BIT(bit); + } + } else { + if (color.full == 0) { + *buf_xy |= BIT(bit); + } else { + *buf_xy &= ~BIT(bit); + } + } +} + +void zephyr_round_area(lv_area_t *a) +{ + struct display_capabilities cap; + + display_get_capabilities(lvgl_display_dev, &cap); + + if (cap.screen_info & SCREEN_INFO_MONO_VTILED) { + a->y1 &= ~0x7; + a->y2 |= 0x7; + } else { + a->x1 &= ~0x7; + a->x2 |= 0x7; + } +} + +#else + +#error "Unsupported pixel format conversion" + +#endif /* CONFIG_LVGL_BITS_PER_PIXEL */ + +void *get_disp_flush(void) +{ + return zephyr_disp_flush; +} + +void *get_vdb_write(void) +{ + return zephyr_vdb_write; +} + +void *get_round_func(void) +{ + return zephyr_round_area; +} diff --git a/lib/gui/lvgl/lvgl_color_16.c b/lib/gui/lvgl/lvgl_color_16.c new file mode 100644 index 00000000000000..8b34a0fc527899 --- /dev/null +++ b/lib/gui/lvgl/lvgl_color_16.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "lvgl_color.h" + +#if CONFIG_LVGL_BITS_PER_PIXEL == 0 + +static void zephyr_disp_flush(s32_t x1, s32_t y1, s32_t x2, s32_t y2, + const lv_color_t *color_p) +{ + u16_t w = x2 - x1 + 1; + u16_t h = y2 - y1 + 1; + struct display_buffer_descriptor desc; + + desc.buf_size = 2 * w * h; + desc.width = w; + desc.pitch = w; + desc.height = h; + display_write(lvgl_display_dev, x1, y1, &desc, (void *) color_p); + + lv_flush_ready(); +} + +#define zephyr_vdb_write NULL + +#else + +#error "Unsupported pixel format conversion" + +#endif /* CONFIG_LVGL_BITS_PER_PIXEL */ + +void *get_disp_flush(void) +{ + return zephyr_disp_flush; +} + +void *get_vdb_write(void) +{ + return zephyr_vdb_write; +} + +void *get_round_func(void) +{ + return NULL; +} diff --git a/lib/gui/lvgl/lvgl_color_32.c b/lib/gui/lvgl/lvgl_color_32.c new file mode 100644 index 00000000000000..497b10dc22b38d --- /dev/null +++ b/lib/gui/lvgl/lvgl_color_32.c @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "lvgl_color.h" + +#if CONFIG_LVGL_BITS_PER_PIXEL == 0 + +static void zephyr_disp_flush(s32_t x1, s32_t y1, s32_t x2, s32_t y2, + const lv_color_t *color_p) +{ + u16_t w = x2 - x1 + 1; + u16_t h = y2 - y1 + 1; + struct display_buffer_descriptor desc; + + desc.buf_size = 4 * w * h; + desc.width = w; + desc.pitch = w; + desc.height = h; + display_write(lvgl_display_dev, x1, y1, &desc, (void *) color_p); + + lv_flush_ready(); +} + +#define zephyr_vdb_write NULL + +#elif CONFIG_LVGL_BITS_PER_PIXEL == 24 + +static void zephyr_disp_flush(s32_t x1, s32_t y1, s32_t x2, s32_t y2, + const lv_color_t *color_p) +{ + u16_t w = x2 - x1 + 1; + u16_t h = y2 - y1 + 1; + struct display_buffer_descriptor desc; + + desc.buf_size = 3 * w * h; + desc.width = w; + desc.pitch = w; + desc.height = h; + display_write(lvgl_display_dev, x1, y1, &desc, (void *) color_p); + + lv_flush_ready(); +} + +static void zephyr_vdb_write(u8_t *buf, lv_coord_t buf_w, lv_coord_t x, + lv_coord_t y, lv_color_t color, lv_opa_t opa) +{ + u8_t *buf_xy = buf + x + y * buf_w; + + if (opa != LV_OPA_COVER) { + lv_color_t mix_color; + + mix_color.red = *buf_xy; + mix_color.green = *(buf_xy+1); + mix_color.blue = *(buf_xy+2); + color = lv_color_mix(color, mix_color, opa); + } + + *buf_xy = color.red; + *(buf_xy + 1) = color.green; + *(buf_xy + 2) = color.blue; +} + +#else + +#error "Unsupported pixel format conversion" + +#endif /* CONFIG_LVGL_BITS_PER_PIXEL */ + +void *get_disp_flush(void) +{ + return zephyr_disp_flush; +} + +void *get_vdb_write(void) +{ + return zephyr_vdb_write; +} + +void *get_round_func(void) +{ + return NULL; +} diff --git a/lib/gui/lvgl/lvgl_color_8.c b/lib/gui/lvgl/lvgl_color_8.c new file mode 100644 index 00000000000000..170b788e111c24 --- /dev/null +++ b/lib/gui/lvgl/lvgl_color_8.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include "lvgl_color.h" + +#if CONFIG_LVGL_BITS_PER_PIXEL == 0 + +static void zephyr_disp_flush(s32_t x1, s32_t y1, s32_t x2, s32_t y2, + const lv_color_t *color_p) +{ + u16_t w = x2 - x1 + 1; + u16_t h = y2 - y1 + 1; + struct display_buffer_descriptor desc; + + desc.buf_size = w * h; + desc.width = w; + desc.pitch = w; + desc.height = h; + display_write(lvgl_display_dev, x1, y1, &desc, (void *) color_p); + + lv_flush_ready(); +} + +#define zephyr_vdb_write NULL + +#else + +#error "Unsupported pixel format conversion" + +#endif /* CONFIG_LVGL_BITS_PER_PIXEL */ + +void *get_disp_flush(void) +{ + return zephyr_disp_flush; +} + +void *get_vdb_write(void) +{ + return zephyr_vdb_write; +} + +void *get_round_func(void) +{ + return NULL; +} diff --git a/lib/gui/lvgl/lvgl_fs.c b/lib/gui/lvgl/lvgl_fs.c new file mode 100644 index 00000000000000..a4edb9728951a1 --- /dev/null +++ b/lib/gui/lvgl/lvgl_fs.c @@ -0,0 +1,243 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +/* Stub for LVGL ufs (ram based FS) init function + * as we use Zephyr FS API instead + */ +void lv_ufs_init(void) +{ +} + +bool lvgl_fs_ready(void) +{ + return true; +} + +static lv_fs_res_t errno_to_lv_fs_res(int err) +{ + switch (err) { + case 0: + return LV_FS_RES_OK; + case -EIO: + /*Low level hardware error*/ + return LV_FS_RES_HW_ERR; + case -EBADF: + /*Error in the file system structure */ + return LV_FS_RES_FS_ERR; + case -ENOENT: + /*Driver, file or directory is not exists*/ + return LV_FS_RES_NOT_EX; + case -EFBIG: + /*Disk full*/ + return LV_FS_RES_FULL; + case -EACCES: + /*Access denied. Check 'fs_open' modes and write protect*/ + return LV_FS_RES_DENIED; + case -EBUSY: + /*The file system now can't handle it, try later*/ + return LV_FS_RES_BUSY; + case -ENOMEM: + /*Not enough memory for an internal operation*/ + return LV_FS_RES_OUT_OF_MEM; + case -EINVAL: + /*Invalid parameter among arguments*/ + return LV_FS_RES_INV_PARAM; + default: + return LV_FS_RES_UNKNOWN; + } +} + +static lv_fs_res_t lvgl_fs_open(void *file, const char *path, + lv_fs_mode_t mode) +{ + int err; + + err = fs_open((struct fs_file_t *)file, path); + return errno_to_lv_fs_res(err); +} + +static lv_fs_res_t lvgl_fs_close(void *file) +{ + int err; + + err = fs_close((struct fs_file_t *)file); + return LV_FS_RES_NOT_IMP; +} + +static lv_fs_res_t lvgl_fs_remove(const char *path) +{ + int err; + + err = fs_unlink(path); + return errno_to_lv_fs_res(err); +} + +static lv_fs_res_t lvgl_fs_read(void *file, void *buf, u32_t btr, + u32_t *br) +{ + int err; + + err = fs_read((struct fs_file_t *)file, buf, btr); + if (err > 0) { + if (br != NULL) { + *br = err; + } + err = 0; + } else if (br != NULL) { + *br = 0; + } + return errno_to_lv_fs_res(err); +} + +static lv_fs_res_t lvgl_fs_write(void *file, const void *buf, u32_t btw, + u32_t *bw) +{ + int err; + + err = fs_write((struct fs_file_t *)file, buf, btw); + if (err == btw) { + if (bw != NULL) { + *bw = btw; + } + err = 0; + } else if (err < 0) { + if (bw != NULL) { + *bw = 0; + } + } else { + if (bw != NULL) { + *bw = err; + } + err = -EFBIG; + } + return errno_to_lv_fs_res(err); +} + +static lv_fs_res_t lvgl_fs_seek(void *file, u32_t pos) +{ + int err; + + err = fs_seek((struct fs_file_t *)file, pos, FS_SEEK_SET); + return errno_to_lv_fs_res(err); +} + +static lv_fs_res_t lvgl_fs_tell(void *file, u32_t *pos_p) +{ + *pos_p = fs_tell((struct fs_file_t *)file); + return LV_FS_RES_OK; +} + +static lv_fs_res_t lvgl_fs_trunc(void *file) +{ + int err; + off_t length; + + length = fs_tell((struct fs_file_t *) file); + ++length; + err = fs_truncate((struct fs_file_t *)file, length); + return errno_to_lv_fs_res(err); +} + +static lv_fs_res_t lvgl_fs_size(void *file, u32_t *fsize) +{ + int err; + off_t org_pos; + + /* LVGL does not provided path but pointer to file struct as such + * we can not use fs_stat, instead use a combination of fs_tell and + * fs_seek to get the files size. + */ + + org_pos = fs_tell((struct fs_file_t *) file); + + err = fs_seek((struct fs_file_t *) file, 0, FS_SEEK_END); + if (err != 0) { + *fsize = 0; + return errno_to_lv_fs_res(err); + } + + *fsize = fs_tell((struct fs_file_t *) file) + 1; + + err = fs_seek((struct fs_file_t *) file, org_pos, FS_SEEK_SET); + + return errno_to_lv_fs_res(err); +} + +static lv_fs_res_t lvgl_fs_rename(const char *from, const char *to) +{ + int err; + + err = fs_rename(from, to); + return errno_to_lv_fs_res(err); +} + +static lv_fs_res_t lvgl_fs_free(u32_t *total_p, u32_t *free_p) +{ + /* We have no easy way of telling the total file system size. + * Zephyr can only return this information per mount point. + */ + return LV_FS_RES_NOT_IMP; +} + +static lv_fs_res_t lvgl_fs_dir_open(void *dir, const char *path) +{ + int err; + + err = fs_opendir((struct fs_dir_t *)dir, path); + return errno_to_lv_fs_res(err); +} + +static lv_fs_res_t lvgl_fs_dir_read(void *dir, char *fn) +{ + /* LVGL expects a string as return parameter but the format of the + * string is not documented. + */ + return LV_FS_RES_NOT_IMP; +} + +static lv_fs_res_t lvgl_fs_dir_close(void *dir) +{ + int err; + + err = fs_closedir((struct fs_dir_t *)dir); + return errno_to_lv_fs_res(err); +} + + +void lvgl_fs_init(void) +{ + lv_fs_drv_t fs_drv; + + memset(&fs_drv, 0, sizeof(lv_fs_drv_t)); + + fs_drv.file_size = sizeof(struct fs_file_t); + fs_drv.rddir_size = sizeof(struct fs_dir_t); + fs_drv.letter = '/'; + fs_drv.ready = lvgl_fs_ready; + + fs_drv.open = lvgl_fs_open; + fs_drv.close = lvgl_fs_close; + fs_drv.remove = lvgl_fs_remove; + fs_drv.read = lvgl_fs_read; + fs_drv.write = lvgl_fs_write; + fs_drv.seek = lvgl_fs_seek; + fs_drv.tell = lvgl_fs_tell; + fs_drv.trunc = lvgl_fs_trunc; + fs_drv.size = lvgl_fs_size; + fs_drv.rename = lvgl_fs_rename; + fs_drv.free = lvgl_fs_free; + + fs_drv.dir_open = lvgl_fs_dir_open; + fs_drv.dir_read = lvgl_fs_dir_read; + fs_drv.dir_close = lvgl_fs_dir_close; + + lv_fs_add_drv(&fs_drv); +} + diff --git a/lib/gui/lvgl/lvgl_fs.h b/lib/gui/lvgl/lvgl_fs.h new file mode 100644 index 00000000000000..02a3732c90f66e --- /dev/null +++ b/lib/gui/lvgl/lvgl_fs.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_GUI_LVGL_LVGL_FS_H_ +#define ZEPHYR_LIB_GUI_LVGL_LVGL_FS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +void lvgl_fs_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_LIB_GUI_LVGL_LVGL_FS_H */ diff --git a/lib/gui/lvgl/lvgl_mem.h b/lib/gui/lvgl/lvgl_mem.h new file mode 100644 index 00000000000000..9b6c552a83b8a4 --- /dev/null +++ b/lib/gui/lvgl/lvgl_mem.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_GUI_LVGL_MEM_H_ +#define ZEPHYR_LIB_GUI_LVGL_MEM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void *lvgl_malloc(size_t size); + +void lvgl_free(void *ptr); + +#ifdef __cplusplus +} +#endif + +#endif /* ZEPHYR_LIB_GUI_LVGL_MEM_H_i */ diff --git a/lib/gui/lvgl/lvgl_mem_kernel.c b/lib/gui/lvgl/lvgl_mem_kernel.c new file mode 100644 index 00000000000000..52030f94e68d6c --- /dev/null +++ b/lib/gui/lvgl/lvgl_mem_kernel.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "lvgl_mem.h" +#include +#include +#include + +K_MEM_POOL_DEFINE(lvgl_mem_pool, + CONFIG_LVGL_MEM_POOL_MIN_SIZE, + CONFIG_LVGL_MEM_POOL_MAX_SIZE, + CONFIG_LVGL_MEM_POOL_NUMBER_BLOCKS, 4); + +void *lvgl_malloc(size_t size) +{ + return k_mem_pool_malloc(&lvgl_mem_pool, size); +} + +void lvgl_free(void *ptr) +{ + k_free(ptr); +} diff --git a/lib/gui/lvgl/lvgl_mem_user.c b/lib/gui/lvgl/lvgl_mem_user.c new file mode 100644 index 00000000000000..8464abac3eceef --- /dev/null +++ b/lib/gui/lvgl/lvgl_mem_user.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "lvgl_mem.h" +#include +#include +#include + +K_MUTEX_DEFINE(lvgl_mem_pool_mutex); +SYS_MEM_POOL_DEFINE(lvgl_mem_pool, &lvgl_mem_pool_mutex, + CONFIG_LVGL_MEM_POOL_MIN_SIZE, + CONFIG_LVGL_MEM_POOL_MAX_SIZE, + CONFIG_LVGL_MEM_POOL_NUMBER_BLOCKS, 4, .data); + +void *lvgl_malloc(size_t size) +{ + return sys_mem_pool_alloc(&lvgl_mem_pool, size); +} + +void lvgl_free(void *ptr) +{ + sys_mem_pool_free(ptr); +} + +static int lvgl_mem_pool_init(struct device *unused) +{ +#ifdef CONFIG_USERSPACE + k_object_access_all_grant(&lvgl_mem_pool_mutex); +#endif + sys_mem_pool_init(&lvgl_mem_pool); + return 0; +} + +SYS_INIT(lvgl_mem_pool_init, APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); From 2a694ed3f0e06adb33db756947a91f990c5e5556 Mon Sep 17 00:00:00 2001 From: Jan Van Winkel Date: Tue, 27 Mar 2018 19:25:06 +0200 Subject: [PATCH 3/3] sample: gui: Added basic sample for lvgl library Added a basic sample showing how to use the LittlevGL library in an application. Signed-off-by: Jan Van Winkel --- samples/gui/gui.rst | 10 +++ samples/gui/lvgl/CMakeLists.txt | 17 +++++ samples/gui/lvgl/README.rst | 75 +++++++++++++++++++ samples/gui/lvgl/boards/native_posix.conf | 5 ++ .../gui/lvgl/boards/nrf52840_pca10056.conf | 7 ++ samples/gui/lvgl/boards/reel_board.conf | 9 +++ samples/gui/lvgl/dts_fixup.h | 40 ++++++++++ samples/gui/lvgl/nrf52840_pca10056.overlay | 19 +++++ samples/gui/lvgl/prj.conf | 8 ++ samples/gui/lvgl/reel_board.overlay | 11 +++ samples/gui/lvgl/sample.yaml | 8 ++ samples/gui/lvgl/src/main.c | 51 +++++++++++++ samples/samples.rst | 1 + 13 files changed, 261 insertions(+) create mode 100644 samples/gui/gui.rst create mode 100644 samples/gui/lvgl/CMakeLists.txt create mode 100644 samples/gui/lvgl/README.rst create mode 100644 samples/gui/lvgl/boards/native_posix.conf create mode 100644 samples/gui/lvgl/boards/nrf52840_pca10056.conf create mode 100644 samples/gui/lvgl/boards/reel_board.conf create mode 100644 samples/gui/lvgl/dts_fixup.h create mode 100644 samples/gui/lvgl/nrf52840_pca10056.overlay create mode 100644 samples/gui/lvgl/prj.conf create mode 100644 samples/gui/lvgl/reel_board.overlay create mode 100644 samples/gui/lvgl/sample.yaml create mode 100644 samples/gui/lvgl/src/main.c diff --git a/samples/gui/gui.rst b/samples/gui/gui.rst new file mode 100644 index 00000000000000..43e5c92c9b096c --- /dev/null +++ b/samples/gui/gui.rst @@ -0,0 +1,10 @@ +.. _gui-samples: + +GUI Samples +########### + +.. toctree:: + :maxdepth: 1 + :glob: + + **/* diff --git a/samples/gui/lvgl/CMakeLists.txt b/samples/gui/lvgl/CMakeLists.txt new file mode 100644 index 00000000000000..e8a2e4ff6f4ed5 --- /dev/null +++ b/samples/gui/lvgl/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.8.2) +macro(set_conf_file) + if(EXISTS ${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf) + set(CONF_FILE "${APPLICATION_SOURCE_DIR}/prj_${BOARD}.conf") + elseif(EXISTS ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf) + set(CONF_FILE + "prj.conf ${APPLICATION_SOURCE_DIR}/boards/${BOARD}.conf") + else() + set(CONF_FILE "prj.conf") + endif() +endmacro() + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(lvgl) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/samples/gui/lvgl/README.rst b/samples/gui/lvgl/README.rst new file mode 100644 index 00000000000000..343231f9546fe8 --- /dev/null +++ b/samples/gui/lvgl/README.rst @@ -0,0 +1,75 @@ +.. _lvgl-sample: + +LittlevGL Basic Sample +###################### + +Overview +******** + +This sample application displays "Hello World" in the center of the screen +and a counter at the bottom which increments every second. + +Requirements +************ + +- `nRF52840 Preview development kit`_ +- `Adafruit 2.2 inch TFT Display`_ + +or a simulated display environment in a native Posix application: + +- :ref:`native_posix` +- `SDL2`_ + +Wiring +****** + +The nrf52840 Preview development kit should be connected as follows to the +Adafruit TFT display. + ++-------------+----------------+ +| | nrf52840 | | Adafruit TFT | +| | Pin | | Pin | ++=============+================+ +| P0.27 | SCK | ++-------------+----------------+ +| P0.31 | D/C | ++-------------+----------------+ +| P0.30 | RST | ++-------------+----------------+ +| P0.26 | MOSI | ++-------------+----------------+ +| P0.29 | MISO | ++-------------+----------------+ +| P0.4 | NSS | ++-------------+----------------+ + +Building and Running +******************** + +Build this sample using the following commands: + +.. zephyr-app-commands:: + :zephyr-app: samples/gui/lvgl + :board: nrf52840_pca10056 + :goals: build + :compact: + +See :ref:`nrf52840_pca10056` on how to flash the build. + +or + +.. zephyr-app-commands:: + :zephyr-app: samples/gui/lvgl + :board: native_posix + :goals: build + :compact: + +References +********** + +.. target-notes:: + +.. _LittlevGL Web Page: https://littlevgl.com/ +.. _Adafruit 2.2 inch TFT Display: https://www.adafruit.com/product/1480 +.. _nRF52840 Preview development kit: http://www.nordicsemi.com/eng/Products/nRF52840-Preview-DK +.. _SDL2: https://www.libsdl.org diff --git a/samples/gui/lvgl/boards/native_posix.conf b/samples/gui/lvgl/boards/native_posix.conf new file mode 100644 index 00000000000000..77136ee89c4e00 --- /dev/null +++ b/samples/gui/lvgl/boards/native_posix.conf @@ -0,0 +1,5 @@ +CONFIG_SDL_DISPLAY=y +CONFIG_SDL_DISPLAY_DEV_NAME="DISPLAY" +CONFIG_SDL_DISPLAY_X_RES=320 +CONFIG_SDL_DISPLAY_Y_RES=240 + diff --git a/samples/gui/lvgl/boards/nrf52840_pca10056.conf b/samples/gui/lvgl/boards/nrf52840_pca10056.conf new file mode 100644 index 00000000000000..43a2c343d61053 --- /dev/null +++ b/samples/gui/lvgl/boards/nrf52840_pca10056.conf @@ -0,0 +1,7 @@ +CONFIG_SPI=y +CONFIG_SPI_1=y +CONFIG_SPI_NRFX=y + +CONFIG_ILI9340=y + +CONFIG_LVGL_BITS_PER_PIXEL=24 diff --git a/samples/gui/lvgl/boards/reel_board.conf b/samples/gui/lvgl/boards/reel_board.conf new file mode 100644 index 00000000000000..52918090e66359 --- /dev/null +++ b/samples/gui/lvgl/boards/reel_board.conf @@ -0,0 +1,9 @@ +CONFIG_SPI=y +CONFIG_SSD1673=y + +CONFIG_LVGL_COLOR_DEPTH_1=y +CONFIG_LVGL_BITS_PER_PIXEL=1 +CONFIG_LVGL_HOR_RES=250 +CONFIG_LVGL_VER_RES=120 +CONFIG_LVGL_DPI=130 +CONFIG_LVGL_VDB_SIZE=16 diff --git a/samples/gui/lvgl/dts_fixup.h b/samples/gui/lvgl/dts_fixup.h new file mode 100644 index 00000000000000..fddf43c7eb322a --- /dev/null +++ b/samples/gui/lvgl/dts_fixup.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#if defined(CONFIG_SPI_NRFX) && defined(CONFIG_ILI9340) + +#define DT_ILI9340_SPI_DEV_NAME \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_BUS_NAME + +#define DT_ILI9340_SPI_SLAVE_NUMBER \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_BASE_ADDRESS + +#define DT_ILI9340_CMD_DATA_GPIO_PORT_NAME \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_CMD_DATA_GPIOS_CONTROLLER + +#define DT_ILI9340_CMD_DATA_PIN \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_CMD_DATA_GPIOS_PIN + +#define DT_ILI9340_DEV_NAME \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_LABEL + +#define DT_ILI9340_RESET_GPIO_PORT_NAME \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_RESET_GPIOS_CONTROLLER + +#define DT_ILI9340_RESET_PIN \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_RESET_GPIOS_PIN + +#define DT_ILI9340_SPI_FREQ \ + DT_NORDIC_NRF_SPI_40004000_ILITEK_ILI9340_0_SPI_MAX_FREQUENCY + +#define DT_ILI9340_CS_GPIO_PORT_NAME \ + DT_NORDIC_NRF_SPI_40004000_CS_GPIOS_CONTROLLER + +#define DT_ILI9340_CS_GPIO_PIN \ + DT_NORDIC_NRF_SPI_40004000_CS_GPIOS_PIN + +#endif + diff --git a/samples/gui/lvgl/nrf52840_pca10056.overlay b/samples/gui/lvgl/nrf52840_pca10056.overlay new file mode 100644 index 00000000000000..c3aa02aeca7635 --- /dev/null +++ b/samples/gui/lvgl/nrf52840_pca10056.overlay @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&spi1 { + status = "ok"; + cs-gpios = <&gpio0 4 0>; + + ili9340@0 { + compatible = "ilitek,ili9340"; + label = "DISPLAY"; + spi-max-frequency = <15151515>; + reg = <0>; + reset-gpios = <&gpio0 30 0>; + cmd-data-gpios = <&gpio0 31 0>; + }; +}; diff --git a/samples/gui/lvgl/prj.conf b/samples/gui/lvgl/prj.conf new file mode 100644 index 00000000000000..49efbe377af951 --- /dev/null +++ b/samples/gui/lvgl/prj.conf @@ -0,0 +1,8 @@ +CONFIG_HEAP_MEM_POOL_SIZE=16384 + +CONFIG_DISPLAY=y +CONFIG_DISPLAY_LOG_LEVEL_ERR=y + +CONFIG_LOG=y + +CONFIG_LVGL=y diff --git a/samples/gui/lvgl/reel_board.overlay b/samples/gui/lvgl/reel_board.overlay new file mode 100644 index 00000000000000..a785c0723462ad --- /dev/null +++ b/samples/gui/lvgl/reel_board.overlay @@ -0,0 +1,11 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&spi3 { + ssd1673fb@0 { + label = "DISPLAY"; + }; +}; diff --git a/samples/gui/lvgl/sample.yaml b/samples/gui/lvgl/sample.yaml new file mode 100644 index 00000000000000..24393837917d00 --- /dev/null +++ b/samples/gui/lvgl/sample.yaml @@ -0,0 +1,8 @@ +sample: + description: LVGL sample application + name: lvgl +tests: + test: + harness: display + platform_whitelist: nrf52840_pca10056 reel_board + tags: samples display gui diff --git a/samples/gui/lvgl/src/main.c b/samples/gui/lvgl/src/main.c new file mode 100644 index 00000000000000..3932976b8f1cc2 --- /dev/null +++ b/samples/gui/lvgl/src/main.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018 Jan Van Winkel + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#include +LOG_MODULE_REGISTER(app); + +void main(void) +{ + u32_t count = 0; + char count_str[11] = {0}; + struct device *display_dev; + lv_obj_t *hello_world_label; + lv_obj_t *count_label; + + display_dev = device_get_binding("DISPLAY"); + + if (display_dev == NULL) { + LOG_ERR("device not found. Aborting test."); + return; + } + + hello_world_label = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(hello_world_label, "Hello world!"); + lv_obj_align(hello_world_label, NULL, LV_ALIGN_CENTER, 0, 0); + + count_label = lv_label_create(lv_scr_act(), NULL); + lv_obj_align(count_label, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); + + display_blanking_off(display_dev); + + while (1) { + if ((count % 100) == 0) { + sprintf(count_str, "%d", count/100); + lv_label_set_text(count_label, count_str); + } + lv_task_handler(); + k_sleep(10); + ++count; + } +} diff --git a/samples/samples.rst b/samples/samples.rst index 504e35935068a6..3a2e824cef0a8d 100644 --- a/samples/samples.rst +++ b/samples/samples.rst @@ -22,6 +22,7 @@ Samples and Demos display/* shields/* portability/* + gui/* To add a new sample document, please use the template available under :file:`doc/templates/sample.tmpl`