add simulator with modules

This commit is contained in:
01trisha 2026-02-20 06:58:17 +07:00
parent 6e89d428c7
commit 4e0b3c02fb
11 changed files with 1953 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

209
CMakeLists.txt Normal file
View File

@ -0,0 +1,209 @@
cmake_minimum_required(VERSION 3.12.4)
project(lvgl C CXX)
# Set the correct FreeRTOS port for your system (e.g., Posix for WSL)
set(FREERTOS_PORT GCC_POSIX CACHE STRING "Port for FreeRTOS on Posix environment")
unset(USE_FREERTOS CACHE)
option(USE_FREERTOS "Enable FreeRTOS" OFF) # Turn this on to enable FreeRTOS
if(USE_FREERTOS)
message(STATUS "FreeRTOS is enabled")
# FreeRTOS integration when USE_FREERTOS is enabled
add_library(freertos_config INTERFACE)
target_include_directories(freertos_config SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/config)
target_compile_definitions(freertos_config INTERFACE projCOVERAGE_TEST=0)
# Add FreeRTOS as a subdirectory
add_subdirectory(FreeRTOS)
# FreeRTOS-specific include directories
include_directories(${PROJECT_SOURCE_DIR}/FreeRTOS/include)
include_directories(${PROJECT_SOURCE_DIR}/FreeRTOS/portable/ThirdParty/GCC/Posix)
include_directories(${PROJECT_SOURCE_DIR}/config)
# Add FreeRTOS sources
file(GLOB FREERTOS_SOURCES
"${PROJECT_SOURCE_DIR}/FreeRTOS/*.c"
"${PROJECT_SOURCE_DIR}/FreeRTOS/portable/MemMang/heap_4.c"
"${PROJECT_SOURCE_DIR}/FreeRTOS/portable/ThirdParty/GCC/Posix/*.c"
)
else()
message(STATUS "FreeRTOS is disabled")
set(FREERTOS_SOURCES "") # No FreeRTOS sources if FreeRTOS is disabled
endif()
# Main include files of the project
include_directories(${PROJECT_SOURCE_DIR}/main/inc)
# Define options for LVGL with default values (OFF)
option(LV_USE_DRAW_SDL "Use SDL draw unit" OFF)
option(LV_USE_LIBPNG "Use libpng to decode PNG" OFF)
option(LV_USE_LIBJPEG_TURBO "Use libjpeg turbo to decode JPEG" OFF)
option(LV_USE_FFMPEG "Use libffmpeg to display video using lv_ffmpeg" OFF)
option(LV_USE_FREETYPE "Use freetype library" OFF)
# Set C and C++ standards
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Set the output path for the executable
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
# Find and include SDL2 library
find_package(SDL2 REQUIRED)
# Add compile definitions based on the selected options
add_compile_definitions($<$<BOOL:${LV_USE_DRAW_SDL}>:LV_USE_DRAW_SDL=1>)
add_compile_definitions($<$<BOOL:${LV_USE_LIBPNG}>:LV_USE_LIBPNG=1>)
add_compile_definitions($<$<BOOL:${LV_USE_LIBJPEG_TURBO}>:LV_USE_LIBJPEG_TURBO=1>)
add_compile_definitions($<$<BOOL:${LV_USE_FFMPEG}>:LV_USE_FFMPEG=1>)
# Add LVGL subdirectory
add_subdirectory(lvgl)
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR} ${SDL2_INCLUDE_DIRS})
# Create the main executable, depending on the FreeRTOS option
if(USE_FREERTOS)
add_executable(main
${PROJECT_SOURCE_DIR}/main/src/main.c
${PROJECT_SOURCE_DIR}/main/src/freertos_main.cpp
${PROJECT_SOURCE_DIR}/main/src/mouse_cursor_icon.c
${PROJECT_SOURCE_DIR}/main/src/FreeRTOS_Posix_Port.c
${FREERTOS_SOURCES} # Add only if USE_FREERTOS is enabled
)
# Link FreeRTOS libraries
target_link_libraries(main freertos_config FreeRTOS)
else()
add_executable(main
${PROJECT_SOURCE_DIR}/main/src/main.c
${PROJECT_SOURCE_DIR}/main/src/mouse_cursor_icon.c
)
endif()
# Add sources for custom application
target_sources(main PRIVATE
${PROJECT_SOURCE_DIR}/rec-ui/main.c
${PROJECT_SOURCE_DIR}/rec-ui/utility_objects.c
${PROJECT_SOURCE_DIR}/rec-ui/utility_functions.c
${PROJECT_SOURCE_DIR}/rec-ui/montserrat_16_ru_en.c
${PROJECT_SOURCE_DIR}/rec-ui/montserrat_20_ru_en.c
${PROJECT_SOURCE_DIR}/rec-ui/montserrat_24_ru_en.c
${PROJECT_SOURCE_DIR}/rec-ui/montserrat_28_ru_en.c
${PROJECT_SOURCE_DIR}/rec-ui/montserrat_32_ru_en.c
${PROJECT_SOURCE_DIR}/rec-ui/montserrat_semibold_20_ru_en.c
${PROJECT_SOURCE_DIR}/rec-ui/montserrat_semibold_24_ru_en.c
${PROJECT_SOURCE_DIR}/rec-ui/montserrat_semibold_28_ru_en.c
${PROJECT_SOURCE_DIR}/rec-ui/montserrat_semibold_32_ru_en.c
${PROJECT_SOURCE_DIR}/rec-ui/arrow.c
${PROJECT_SOURCE_DIR}/rec-ui/moon_purple.c
${PROJECT_SOURCE_DIR}/rec-ui/sun_yellow.c
)
# Define LVGL configuration as a simple include
target_compile_definitions(main PRIVATE LV_CONF_INCLUDE_SIMPLE)
if(MSVC)
target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES})
else()
target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} m pthread)
endif()
# Only link freertos_config if the FreeRTOS directory exists
if(USE_FREERTOS)
target_link_libraries(main freertos_config)
endif()
# Custom target to run the executable
add_custom_target(run COMMAND ${EXECUTABLE_OUTPUT_PATH}/main DEPENDS main)
# Conditionally include and link SDL2_image if LV_USE_DRAW_SDL is enabled
if(LV_USE_DRAW_SDL)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
find_package(SDL2_image REQUIRED)
target_include_directories(lvgl PUBLIC ${SDL2_IMAGE_INCLUDE_DIRS})
target_link_libraries(main ${SDL2_IMAGE_LIBRARIES})
endif()
# Conditionally include and link libpng if LV_USE_LIBPNG is enabled
if(LV_USE_LIBPNG)
find_package(PNG REQUIRED)
target_include_directories(lvgl PUBLIC ${PNG_INCLUDE_DIRS})
target_link_libraries(main ${PNG_LIBRARIES})
endif()
# Conditionally include and link libjpeg-turbo if LV_USE_LIBJPEG_TURBO is enabled
if(LV_USE_LIBJPEG_TURBO)
find_package(JPEG REQUIRED)
target_include_directories(lvgl PUBLIC ${JPEG_INCLUDE_DIRS})
target_link_libraries(main ${JPEG_LIBRARIES})
endif()
# Conditionally include and link FFmpeg libraries if LV_USE_FFMPEG is enabled
if(LV_USE_FFMPEG)
target_link_libraries(main avformat avcodec avutil swscale z)
endif()
# Conditionally include and link FreeType if LV_USE_FREETYPE is enabled
if(LV_USE_FREETYPE)
find_package(Freetype REQUIRED)
target_include_directories(lvgl PUBLIC ${FREETYPE_INCLUDE_DIRS})
target_link_libraries(main ${FREETYPE_LIBRARIES})
endif()
# On Windows, GUI applications do not show a console by default,
# which hides log output. This ensures a console is available for logging.
if (WIN32)
if (MSVC)
target_link_options(main PRIVATE "/SUBSYSTEM:CONSOLE")
else()
target_link_options(main PRIVATE "-mconsole")
endif()
endif()
# Apply additional compile options if the build type is Debug
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Debug mode enabled")
target_compile_options(lvgl PRIVATE
-pedantic-errors
-Wall
-Wclobbered
-Wdeprecated
-Wdouble-promotion
-Wempty-body
-Wextra
-Wformat-security
-Wmaybe-uninitialized
# -Wmissing-prototypes
-Wpointer-arith
-Wmultichar
-Wno-pedantic # ignored for now, we convert functions to pointers for properties table.
-Wreturn-type
-Wshadow
-Wshift-negative-value
-Wsizeof-pointer-memaccess
-Wtype-limits
-Wundef
-Wuninitialized
-Wunreachable-code
-Wfloat-conversion
-Wstrict-aliasing
)
if (ASAN)
message(STATUS "AddressSanitizer enabled")
# Add AddressSanitizer flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
else()
message(STATUS "AddressSanitizer disabled")
endif()
endif()

1
FreeRTOS Submodule

@ -0,0 +1 @@
Subproject commit 6cd736cfeb90ad31223c3c74eb17be6c454863f8

61
config/FreeRTOSConfig.h Normal file
View File

@ -0,0 +1,61 @@
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#include <stdint.h>
extern uint32_t SystemCoreClock;
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*----------------------------------------------------------*/
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES ( 5 )
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 256 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 512 * 1024 * 1024 ) ) // 512 MB Heap
#define configMAX_TASK_NAME_LEN ( 10 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TASK_NOTIFICATIONS 0
#define configUSE_STREAM_BUFFERS 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 2 )
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#endif /* FREERTOS_CONFIG_H */

8
licence.txt Normal file
View File

@ -0,0 +1,8 @@
MIT licence
Copyright (c) 2016 Gábor Kiss-Vámosi
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

65
lv_conf.defaults Normal file
View File

@ -0,0 +1,65 @@
LV_COLOR_DEPTH 32
LV_MEM_SIZE (1024 * 1024)
LV_USE_MATRIX 1
LV_USE_FLOAT 1
LV_USE_LOTTIE 1
LV_USE_DRAW_SW_COMPLEX_GRADIENTS 1
LV_OBJ_STYLE_CACHE 1
LV_USE_LOG 1
LV_LOG_PRINTF 1
LV_USE_ASSERT_MEM_INTEGRITY 1
LV_USE_ASSERT_OBJ 1
LV_USE_ASSERT_STYLE 1
LV_FONT_MONTSERRAT_12 1
LV_FONT_MONTSERRAT_14 1
LV_FONT_MONTSERRAT_16 1
LV_FONT_MONTSERRAT_18 1
LV_FONT_MONTSERRAT_20 1
LV_FONT_MONTSERRAT_22 1
LV_FONT_MONTSERRAT_24 1
LV_FONT_MONTSERRAT_26 1
LV_FONT_MONTSERRAT_28 1
LV_FONT_MONTSERRAT_30 1
LV_FONT_MONTSERRAT_32 1
LV_FONT_MONTSERRAT_34 1
LV_FONT_MONTSERRAT_36 1
LV_FONT_MONTSERRAT_38 1
LV_FONT_MONTSERRAT_40 1
LV_FONT_MONTSERRAT_42 1
LV_FONT_MONTSERRAT_44 1
LV_FONT_MONTSERRAT_46 1
LV_FONT_MONTSERRAT_48 1
LV_FONT_MONTSERRAT_28_COMPRESSED 1
LV_FONT_DEJAVU_16_PERSIAN_HEBREW 1
LV_FONT_SIMSUN_16_CJK 1
LV_FONT_UNSCII_8 1
LV_USE_SYSMON 1
LV_USE_IMGFONT 1
LV_USE_FS_STDIO 1
LV_FS_STDIO_LETTER 'A'
LV_USE_THORVG_INTERNAL 1
LV_USE_LZ4_INTERNAL 1
LV_USE_VECTOR_GRAPHIC 1
LV_USE_TINY_TTF 1
LV_USE_BARCODE 1
LV_USE_QRCODE 1
LV_USE_RLE 1
LV_BIN_DECODER_RAM_LOAD 1
LV_USE_TJPGD 1
LV_USE_BMP 1
LV_USE_LODEPNG 1
LV_USE_SDL 1
LV_USE_DEMO_WIDGETS 1
LV_USE_DEMO_KEYPAD_AND_ENCODER 1
LV_USE_DEMO_BENCHMARK 1
LV_USE_DEMO_RENDER 1
LV_USE_DEMO_STRESS 1
LV_USE_DEMO_MUSIC 1
LV_USE_DEMO_FLEX_LAYOUT 1
LV_USE_DEMO_MULTILANG 1
LV_USE_DEMO_TRANSFORM 1
LV_USE_DEMO_SCROLL 1

1424
lv_conf.h Normal file

File diff suppressed because it is too large Load Diff

1
lv_drivers Submodule

@ -0,0 +1 @@
Subproject commit ea2e4cc00d02064173d56241f16ad492692138e4

1
lvgl Submodule

@ -0,0 +1 @@
Subproject commit 9be768db427c6af5b33b0fb4d22c6b84a5acd83f

72
manifest.json Normal file
View File

@ -0,0 +1,72 @@
{
"name": "Simulator project for LVGL embedded GUI Library",
"maintainer": "LVGL",
"hostOperatingsystem": [
"Linux",
"Windows",
"MacOS"
],
"environment": [
"VSCode",
"SDL"
],
"description": "LVGL is written mainly for microcontrollers and embedded systems, however you can run the library on your PC as well without any embedded hardware. The code written on PC can be simply copied when you are using an embedded system. The project can use SDL but it can be easily replaced by any other built-in LVGL drivers.",
"shortDescription": "VSCode-based project to run LVGL on PC.",
"urlToClone": "https://github.com/lvgl/lv_port_pc_vscode",
"logos": [
"https://raw.githubusercontent.com/lvgl/project-creator/master/meta/images/vscode/logo.svg"
],
"image": "https://raw.githubusercontent.com/lvgl/project-creator/master/meta/images/vscode/logo.svg",
"branches": [
"release/v9.2"
],
"settings": [
{
"type": "dropdown",
"label": "Color Depth",
"options": [
{
"name": "16 (RGB565)",
"value": "16"
},
{
"name": "24 (RGB565)",
"value": "24"
},
{
"name": "32 (RGB565)",
"value": "32"
}
],
"actions": [
{
"toReplace": "#define LV_COLOR_DEPTH \\d+",
"newContent": "#define LV_COLOR_DEPTH {value}",
"filePath": "lv_conf.h"
}
]
},
{
"type": "dropdown",
"label": "Show performance monitor",
"options": [
{
"name": "Yes",
"value": "1",
"default": "true"
},
{
"name": "No",
"value": "0"
}
],
"actions": [
{
"toReplace": "#define LV_USE_PERF_MONITOR .*",
"newContent": "#define LV_USE_PERF_MONITOR {value}",
"filePath": "lv_conf.h"
}
]
}
]
}

111
simulator.code-workspace Normal file
View File

@ -0,0 +1,111 @@
{
// https://code.visualstudio.com/docs/editor/workspaces
// https://code.visualstudio.com/docs/editor/multi-root-workspaces
// https://code.visualstudio.com/docs/editor/variables-reference
"folders": [
{
"path": "."
},
],
// extensions.json section
"extensions": {
"recommendations": [
"ms-vscode.cpptools", // common C/C++ support
"ms-vscode.cpptools-themes", // general C/C++ theme
"ms-vscode.cmake-tools" // cmake support
],
"unwantedRecommendations": [
]
},
// settings.json section
"settings": {
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"cmake.configureOnOpen": true,
"files.associations": {
"glob.h": "c",
"lvgl.h": "c",
"utility_functions.h": "c"
},
"commentTranslate.browse.mode": "contrast",
},
// tasks.json section
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"command": "cmake",
"args": [
"--build", "${command:cmake.buildDirectory}"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
{
"label": "Build and Run",
"type": "shell",
"command": "${workspaceFolder}/bin/main",
"group": {
"kind": "test",
"isDefault": true
},
"dependsOn": "Build"
}
],
},
// launch.json section
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Debug LVGL demo with gdb",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/main",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "Build",
"stopAtEntry": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe"
}
},
{
"name": "Debug LVGL demo with LLVM",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/main",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "Build",
"stopAtEntry": false,
"MIMode": "lldb"
},
],
},
}