搭建LVGL仿真环境
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(lvgl_sim C)
|
||||
|
||||
#=============================================================================
|
||||
# 路径配置(相对于 simulator/ 目录)
|
||||
#=============================================================================
|
||||
set(PROJECT_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||
set(LVGL_DIR "${PROJECT_ROOT}/Lib/lvgl")
|
||||
set(UI_DIR "${PROJECT_ROOT}/Drivers/BSP/UI")
|
||||
set(SDL2_DIR "${CMAKE_CURRENT_SOURCE_DIR}/SDL2/SDL2-2.32.10")
|
||||
|
||||
#=============================================================================
|
||||
# 编译标准
|
||||
#=============================================================================
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
# Windows 控制台输出(显示 printf)
|
||||
if(WIN32)
|
||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
# MSVC:源码为 UTF-8 编码(含中文注释),强制按 UTF-8 解析消除 C4819 警告
|
||||
if(MSVC)
|
||||
add_compile_options(/utf-8)
|
||||
endif()
|
||||
|
||||
#=============================================================================
|
||||
# SDL2 头文件路径(需先于 add_subdirectory 定义,供 LVGL SDL 驱动使用)
|
||||
#=============================================================================
|
||||
# LVGL SDL 驱动内部 #include "SDL2/SDL.h",include 目录下已有 SDL2/ 子目录
|
||||
set(SDL2_INCLUDE_DIR "${SDL2_DIR}/include" CACHE PATH "SDL2 include directory for LVGL")
|
||||
|
||||
#=============================================================================
|
||||
# LVGL 子目录(引用项目自带的 LVGL v9.3.0 源码)
|
||||
#=============================================================================
|
||||
# LVGL 内部会自动检测 lv_conf.h(通过 LV_CONF_INCLUDE_SIMPLE 宏)
|
||||
# 需要将 simulator 目录加入 LVGL 的包含路径,使其能找到 lv_conf.h
|
||||
set(LV_CONF_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "Directory containing lv_conf.h for LVGL")
|
||||
add_subdirectory("${LVGL_DIR}" lvgl_build)
|
||||
|
||||
#=============================================================================
|
||||
# 包含路径
|
||||
#=============================================================================
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR} # sim_port.h, lvgl conf.h (LVGL 找 lv_conf.h), dbg_cfg.h
|
||||
${LVGL_DIR} # lvgl.h
|
||||
${LVGL_DIR}/src # lvgl 内部头文件
|
||||
${UI_DIR} # ui_menu.h, ui_font_cn_12.h
|
||||
${PROJECT_ROOT}/Drivers/BSP # dbg_log.h(使用 simulator 的 dbg_cfg.h 配置)
|
||||
${SDL2_DIR}/include # SDL2 头文件
|
||||
)
|
||||
|
||||
#=============================================================================
|
||||
# SDL2 库(使用本地预编译版本)
|
||||
#=============================================================================
|
||||
set(SDL2_INCLUDE_PARENT "${SDL2_DIR}/include")
|
||||
set(SDL2_LIB_X64 "${SDL2_DIR}/lib/x64")
|
||||
|
||||
#=============================================================================
|
||||
# 源文件
|
||||
#=============================================================================
|
||||
set(SIM_SOURCES
|
||||
main.c
|
||||
sim_port.c
|
||||
)
|
||||
|
||||
# UI 源文件(与 MCU 端共用,直接编译)
|
||||
set(UI_SOURCES
|
||||
${UI_DIR}/ui_menu.c
|
||||
${UI_DIR}/ui_font_cn_12.c
|
||||
)
|
||||
|
||||
#=============================================================================
|
||||
# 构建可执行文件
|
||||
#=============================================================================
|
||||
add_executable(lvgl_sim WIN32 ${SIM_SOURCES} ${UI_SOURCES})
|
||||
|
||||
target_compile_definitions(lvgl_sim PRIVATE
|
||||
LV_CONF_INCLUDE_SIMPLE # 让 lvgl.h 找到 lv_conf.h
|
||||
LV_LVGL_H_INCLUDE_SIMPLE # ui_font_cn_12.c 内部 include 简化
|
||||
)
|
||||
|
||||
target_include_directories(lvgl_sim PRIVATE
|
||||
${SDL2_INCLUDE_PARENT} # SDL2/SDL.h 路径
|
||||
)
|
||||
|
||||
target_link_directories(lvgl_sim PRIVATE
|
||||
${SDL2_LIB_X64}
|
||||
)
|
||||
|
||||
target_link_libraries(lvgl_sim
|
||||
lvgl
|
||||
SDL2
|
||||
SDL2main
|
||||
)
|
||||
|
||||
# 数学库(非 MSVC)
|
||||
if(NOT MSVC)
|
||||
target_link_libraries(lvgl_sim m pthread)
|
||||
endif()
|
||||
|
||||
# Windows 子系统:控制台(显示 printf 输出)
|
||||
if(WIN32)
|
||||
if(MSVC)
|
||||
target_link_options(lvgl_sim PRIVATE "/SUBSYSTEM:CONSOLE")
|
||||
else()
|
||||
target_link_options(lvgl_sim PRIVATE "-mconsole")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# 复制 SDL2.dll 到输出目录
|
||||
add_custom_command(TARGET lvgl_sim POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||
"${SDL2_LIB_X64}/SDL2.dll"
|
||||
"$<TARGET_FILE_DIR:lvgl_sim>/SDL2.dll"
|
||||
COMMENT "Copying SDL2.dll to output directory"
|
||||
)
|
||||
|
||||
#=============================================================================
|
||||
# 自定义目标:运行模拟器
|
||||
#=============================================================================
|
||||
add_custom_target(run COMMAND ${CMAKE_BINARY_DIR}/lvgl_sim DEPENDS lvgl_sim)
|
||||
|
||||
#=============================================================================
|
||||
# 调试模式额外警告
|
||||
#=============================================================================
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
message(STATUS "Debug mode enabled for simulator")
|
||||
if(MSVC)
|
||||
target_compile_options(lvgl_sim PRIVATE /W4)
|
||||
else()
|
||||
target_compile_options(lvgl_sim PRIVATE -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message(STATUS "=== LVGL Simulator ===")
|
||||
message(STATUS "Screen: 160x160, 1bpp monochrome")
|
||||
message(STATUS "LVGL dir: ${LVGL_DIR}")
|
||||
message(STATUS "UI dir: ${UI_DIR}")
|
||||
message(STATUS "SDL2: ${SDL2_DIR}")
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* dbg_log.h — 模拟器专用调试日志 stub(覆盖 MCU 工程的 Drivers/BSP/dbg_log.h)
|
||||
*
|
||||
* 模拟器不使用 sys_clock.h / RTC,因此把 DBG_* 宏直接映射到 printf,
|
||||
* 使 ui_menu.c 等共享代码的日志在 PC 控制台可见。
|
||||
* DBG_TAG 仍需各 .c 文件在 include 前定义,这里保留该约定。
|
||||
*/
|
||||
|
||||
#ifndef __DBG_LOG_H
|
||||
#define __DBG_LOG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef DBG_TAG
|
||||
#define DBG_TAG ""
|
||||
#endif
|
||||
|
||||
#define DBG_ERROR(fmt, ...) do { \
|
||||
printf("[ERR]" DBG_TAG " " fmt "\n", ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define DBG_INFO(fmt, ...) do { \
|
||||
printf(DBG_TAG " " fmt "\n", ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define DBG_DEBUG(fmt, ...) do { \
|
||||
printf(DBG_TAG "(%s:%d) " fmt "\n", __func__, __LINE__, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DBG_LOG_H */
|
||||
@@ -0,0 +1,308 @@
|
||||
/**
|
||||
* @file lv_conf.h
|
||||
* @brief LVGL v9.3.0 配置 — Windows SDL2 模拟器(160x160 1bpp 单色)
|
||||
* @note 基于项目 Lib/lv_conf.h 适配,用于 PC 模拟器 UI 开发
|
||||
*/
|
||||
#ifndef LV_CONF_H
|
||||
#define LV_CONF_H
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
/*============================================================================
|
||||
* MEMORY AND STANDARD LIBRARY
|
||||
*============================================================================*/
|
||||
#define LV_USE_STDLIB_MALLOC LV_STDLIB_BUILTIN
|
||||
#define LV_USE_STDLIB_STRING LV_STDLIB_BUILTIN
|
||||
#define LV_USE_STDLIB_SPRINTF LV_STDLIB_BUILTIN
|
||||
|
||||
#define LV_STDINT_INCLUDE <stdint.h>
|
||||
#define LV_STDDEF_INCLUDE <stddef.h>
|
||||
#define LV_STDBOOL_INCLUDE <stdbool.h>
|
||||
#define LV_INTTYPES_INCLUDE <inttypes.h>
|
||||
#define LV_LIMITS_INCLUDE <limits.h>
|
||||
#define LV_STDARG_INCLUDE <stdarg.h>
|
||||
|
||||
#if LV_USE_STDLIB_MALLOC == LV_STDLIB_BUILTIN
|
||||
#define LV_MEM_SIZE (40 * 1024U)
|
||||
#define LV_MEM_ADR 0
|
||||
#endif
|
||||
|
||||
/*============================================================================
|
||||
* OS
|
||||
*============================================================================*/
|
||||
#define LV_USE_OS LV_OS_NONE
|
||||
|
||||
/*============================================================================
|
||||
* RENDERING
|
||||
*============================================================================*/
|
||||
/** 1bpp 单色 */
|
||||
#define LV_COLOR_DEPTH 1
|
||||
#define LV_COLOR_MIX_ROUND_OFS 0
|
||||
|
||||
/** 刷新周期(ms) */
|
||||
#define LV_DEF_REFR_PERIOD 20
|
||||
|
||||
/** DPI */
|
||||
#define LV_DPI_DEF 130
|
||||
|
||||
/** 绘制缓冲对齐 */
|
||||
#define LV_DRAW_BUF_STRIDE_ALIGN 1
|
||||
#define LV_DRAW_BUF_ALIGN 4
|
||||
|
||||
/** 关闭复杂绘制,省代码 */
|
||||
#define LV_DRAW_SW_COMPLEX 0
|
||||
#define LV_DRAW_SW_COMPLEX_GRADIENTS 0
|
||||
#define LV_DRAW_SW_SHADOW_CACHE_SIZE 0
|
||||
#define LV_DRAW_SW_CIRCLE_CACHE_SIZE 0
|
||||
#define LV_DRAW_LAYER_SIMPLE_BUF_SIZE 0
|
||||
#define LV_DRAW_LAYER_MAX_MEMORY 0
|
||||
|
||||
/** SW 渲染器:启用 I1 支持 */
|
||||
#define LV_USE_DRAW_SW 1
|
||||
#define LV_DRAW_SW_SUPPORT_RGB565 0
|
||||
#define LV_DRAW_SW_SUPPORT_RGB565_SWAPPED 0
|
||||
#define LV_DRAW_SW_SUPPORT_RGB565A8 0
|
||||
#define LV_DRAW_SW_SUPPORT_RGB888 0
|
||||
#define LV_DRAW_SW_SUPPORT_XRGB8888 0
|
||||
#define LV_DRAW_SW_SUPPORT_ARGB8888 0
|
||||
#define LV_DRAW_SW_SUPPORT_ARGB8888_PREMULTIPLIED 0
|
||||
#define LV_DRAW_SW_SUPPORT_L8 0
|
||||
#define LV_DRAW_SW_SUPPORT_AL88 0
|
||||
#define LV_DRAW_SW_SUPPORT_A8 0
|
||||
#define LV_DRAW_SW_SUPPORT_I1 1
|
||||
#define LV_DRAW_SW_I1_LUM_THRESHOLD 127
|
||||
|
||||
/** 关闭 GPU/矢量绘制 */
|
||||
#define LV_USE_DRAW_VG_LITE 0
|
||||
#define LV_USE_DRAW_DAVE2D 0
|
||||
#define LV_USE_DRAW_NEMA_GFX 0
|
||||
#define LV_USE_DRAW_PXP 0
|
||||
#define LV_USE_DRAW_PPA 0
|
||||
#define LV_USE_DRAW_DMA2D 0
|
||||
#define LV_USE_DRAW_EVE 0
|
||||
#define LV_USE_DRAW_G2D 0
|
||||
#define LV_USE_DRAW_NANOVG 0
|
||||
#define LV_USE_DRAW_OPENGLES 0
|
||||
#define LV_USE_DRAW_SDL 0
|
||||
#define LV_USE_THORVG 0
|
||||
#define LV_USE_VECTOR_GRAPHIC 0
|
||||
#define LV_USE_MATRIX 0
|
||||
#define LV_USE_SNAPSHOT 0
|
||||
|
||||
/*============================================================================
|
||||
* INPUT DEVICES
|
||||
*============================================================================*/
|
||||
#define LV_USE_GRIDNAV 0
|
||||
#define LV_USE_GESTURE_RECOGNITION 0
|
||||
|
||||
/*============================================================================
|
||||
* CORE
|
||||
*============================================================================*/
|
||||
#define LV_OBJ_STYLE_CACHE 1
|
||||
#define LV_USE_OBJ_NAME 1
|
||||
#define LV_USE_OBJ_ID 1
|
||||
#define LV_OBJ_ID_AUTO_ASSIGN 1
|
||||
#define LV_USE_OBJ_ID_BUILTIN 1
|
||||
#define LV_USE_OBJ_PROPERTY 0
|
||||
#define LV_USE_EXT_DATA 0
|
||||
#define LV_USE_FLOAT 0
|
||||
#define LV_USE_OBSERVER 0
|
||||
#define LV_USE_TRANSLATION 0
|
||||
#define LV_USE_COLOR_FILTER 0
|
||||
|
||||
/*============================================================================
|
||||
* LOGGING
|
||||
*============================================================================*/
|
||||
#define LV_USE_LOG 0
|
||||
|
||||
/*============================================================================
|
||||
* THEMES
|
||||
*============================================================================*/
|
||||
#define LV_USE_THEME_DEFAULT 0
|
||||
#define LV_USE_THEME_SIMPLE 0
|
||||
#define LV_USE_THEME_MONO 1
|
||||
|
||||
/*============================================================================
|
||||
* LAYOUTS
|
||||
*============================================================================*/
|
||||
#define LV_USE_FLEX 1
|
||||
#define LV_USE_GRID 0
|
||||
|
||||
/*============================================================================
|
||||
* IMAGE SETTINGS
|
||||
*============================================================================*/
|
||||
#define LV_CACHE_DEF_SIZE 0
|
||||
#define LV_IMAGE_HEADER_CACHE_DEF_CNT 0
|
||||
#define LV_USE_RLE 0
|
||||
#define LV_USE_LZ4 0
|
||||
#define LV_BIN_DECODER_RAM_LOAD 0
|
||||
#define LV_USE_LODEPNG 0
|
||||
#define LV_USE_LIBPNG 0
|
||||
#define LV_USE_BMP 0
|
||||
#define LV_USE_TJPGD 0
|
||||
#define LV_USE_LIBJPEG_TURBO 0
|
||||
#define LV_USE_LIBWEBP 0
|
||||
#define LV_USE_SVG 0
|
||||
|
||||
/*============================================================================
|
||||
* TEXT & FONT
|
||||
*============================================================================*/
|
||||
#define LV_TXT_ENC LV_TXT_ENC_UTF8
|
||||
#define LV_TXT_BREAK_CHARS " ,.;:-_)]}"
|
||||
#define LV_TXT_LINE_BREAK_LONG_LEN 0
|
||||
#define LV_TXT_COLOR_CMD "#"
|
||||
#define LV_USE_BIDI 0
|
||||
#define LV_USE_ARABIC_PERSIAN_CHARS 0
|
||||
|
||||
/** 内置字体:仅启用 Montserrat 12 作为基础 */
|
||||
#define LV_FONT_MONTSERRAT_8 0
|
||||
#define LV_FONT_MONTSERRAT_10 0
|
||||
#define LV_FONT_MONTSERRAT_12 1
|
||||
#define LV_FONT_MONTSERRAT_14 0
|
||||
#define LV_FONT_MONTSERRAT_16 0
|
||||
#define LV_FONT_MONTSERRAT_18 0
|
||||
#define LV_FONT_MONTSERRAT_20 0
|
||||
#define LV_FONT_MONTSERRAT_22 0
|
||||
#define LV_FONT_MONTSERRAT_24 0
|
||||
#define LV_FONT_MONTSERRAT_26 0
|
||||
#define LV_FONT_MONTSERRAT_28 0
|
||||
#define LV_FONT_MONTSERRAT_30 0
|
||||
#define LV_FONT_MONTSERRAT_32 0
|
||||
#define LV_FONT_MONTSERRAT_34 0
|
||||
#define LV_FONT_MONTSERRAT_36 0
|
||||
#define LV_FONT_MONTSERRAT_38 0
|
||||
#define LV_FONT_MONTSERRAT_40 0
|
||||
#define LV_FONT_MONTSERRAT_42 0
|
||||
#define LV_FONT_MONTSERRAT_44 0
|
||||
#define LV_FONT_MONTSERRAT_46 0
|
||||
#define LV_FONT_MONTSERRAT_48 0
|
||||
#define LV_FONT_MONTSERRAT_28_COMPRESSED 0
|
||||
#define LV_FONT_DEJAVU_16_PERSIAN_HEBREW 0
|
||||
#define LV_FONT_SOURCE_HAN_SANS_SC_14_CJK 0
|
||||
#define LV_FONT_SOURCE_HAN_SANS_SC_16_CJK 0
|
||||
#define LV_FONT_UNSCII_8 0
|
||||
#define LV_FONT_UNSCII_16 0
|
||||
|
||||
/** 自定义字体:中文 12px 1bpp */
|
||||
#define LV_FONT_USE_CUSTOM_INCLUDE 1
|
||||
#define LV_FONT_CUSTOM_INCLUDE "ui_font_cn_12.h"
|
||||
#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(ui_font_cn_12)
|
||||
#define LV_FONT_DEFAULT &ui_font_cn_12
|
||||
|
||||
#define LV_USE_CUSTOM_FONT_DEFAULT 0
|
||||
#define LV_FONT_FMT_TXT_LARGE 0
|
||||
#define LV_USE_FONT_COMPRESSED 0
|
||||
#define LV_USE_FONT_PLACEHOLDER 1
|
||||
#define LV_USE_FONT_MANAGER 0
|
||||
#define LV_USE_IMGFONT 0
|
||||
#define LV_USE_FREETYPE 0
|
||||
#define LV_USE_TINY_TTF 0
|
||||
|
||||
/*============================================================================
|
||||
* WIDGETS
|
||||
*============================================================================*/
|
||||
#define LV_WIDGETS_HAS_DEFAULT_VALUE 0
|
||||
|
||||
#define LV_USE_3DTEXTURE 0
|
||||
#define LV_USE_ANIMIMG 0
|
||||
#define LV_USE_ARC 0
|
||||
#define LV_USE_ARCLABEL 0
|
||||
#define LV_USE_BAR 0
|
||||
#define LV_USE_BARCODE 0
|
||||
#define LV_USE_BUTTON 1
|
||||
#define LV_USE_BUTTONMATRIX 1
|
||||
#define LV_USE_CALENDAR 0
|
||||
#define LV_USE_CANVAS 0
|
||||
#define LV_USE_CHART 0
|
||||
#define LV_USE_CHECKBOX 0
|
||||
#define LV_USE_DROPDOWN 0
|
||||
#define LV_USE_FFMPEG 0
|
||||
#define LV_USE_GIF 0
|
||||
#define LV_USE_GLTF 0
|
||||
#define LV_USE_GSTREAMER 0
|
||||
#define LV_USE_IMAGE 1
|
||||
#define LV_USE_IMAGEBUTTON 0
|
||||
#define LV_USE_IME_PINYIN 0
|
||||
#define LV_USE_KEYBOARD 1
|
||||
#define LV_USE_LABEL 1
|
||||
#define LV_LABEL_TEXT_SELECTION 0
|
||||
#define LV_LABEL_LONG_TXT_HINT 0
|
||||
#define LV_LABEL_WAIT_CHAR_COUNT 0
|
||||
#define LV_USE_LED 0
|
||||
#define LV_USE_LINE 0
|
||||
#define LV_USE_LIST 0
|
||||
#define LV_USE_LOTTIE 0
|
||||
#define LV_USE_MENU 1
|
||||
#define LV_USE_MSGBOX 0
|
||||
#define LV_USE_QRCODE 0
|
||||
#define LV_USE_RLOTTIE 0
|
||||
#define LV_USE_ROLLER 0
|
||||
#define LV_USE_SCALE 0
|
||||
#define LV_USE_SLIDER 0
|
||||
#define LV_USE_SPAN 0
|
||||
#define LV_USE_SPINBOX 0
|
||||
#define LV_USE_SPINNER 0
|
||||
#define LV_USE_SWITCH 0
|
||||
#define LV_USE_TEXTAREA 1
|
||||
#define LV_USE_TABLE 0
|
||||
#define LV_USE_TABVIEW 0
|
||||
#define LV_USE_TILEVIEW 0
|
||||
#define LV_USE_WIN 0
|
||||
|
||||
/*============================================================================
|
||||
* DRIVERS — SDL2 (模拟器专用)
|
||||
*============================================================================*/
|
||||
#define LV_USE_LINUX_DRM 0
|
||||
#define LV_USE_LINUX_FBDEV 0
|
||||
#define LV_USE_FT81X 0
|
||||
#define LV_USE_LOVYAN_GFX 0
|
||||
#define LV_USE_GENERIC_MIPI 0
|
||||
#define LV_USE_EVDEV 0
|
||||
#define LV_USE_LIBINPUT 0
|
||||
#define LV_USE_NUTTX 0
|
||||
#define LV_USE_OPENGLES 0
|
||||
#define LV_USE_GLFW 0
|
||||
#define LV_USE_QNX 0
|
||||
#define LV_USE_UEFI 0
|
||||
#define LV_USE_WAYLAND 0
|
||||
|
||||
/** SDL2 驱动:启用 */
|
||||
#define LV_USE_SDL 1
|
||||
|
||||
#if LV_USE_SDL
|
||||
#define LV_SDL_INCLUDE_PATH "SDL2/SDL.h"
|
||||
#define LV_SDL_AUTO_BACKEND 1
|
||||
#define LV_SDL_BACKEND LV_SDL_BACKEND_SW
|
||||
|
||||
/** 1bpp 必须使用 PARTIAL 模式 */
|
||||
#define LV_SDL_RENDER_MODE LV_DISPLAY_RENDER_MODE_PARTIAL
|
||||
|
||||
#define LV_SDL_BUF_COUNT 1
|
||||
#define LV_SDL_ACCELERATED 0
|
||||
#define LV_SDL_FULLSCREEN 0
|
||||
#define LV_SDL_DIRECT_EXIT 1
|
||||
#define LV_SDL_MOUSEWHEEL_MODE LV_SDL_MOUSEWHEEL_MODE_ENCODER
|
||||
#endif
|
||||
|
||||
#define LV_USE_WINDOWS 0
|
||||
|
||||
/*============================================================================
|
||||
* THEMES (补充)
|
||||
*============================================================================*/
|
||||
#define LV_USE_THEME_DEFAULT 0
|
||||
#define LV_THEME_DEFAULT_DARK 0
|
||||
#define LV_THEME_DEFAULT_GROW 0
|
||||
#define LV_THEME_DEFAULT_TRANSITION_TIME 0
|
||||
#define LV_USE_THEME_SIMPLE 0
|
||||
|
||||
/*============================================================================
|
||||
* EXPORTS
|
||||
*============================================================================*/
|
||||
#define LV_USE_DEMO_NONE 1
|
||||
#define LV_USE_DEMO_WIDGETS 0
|
||||
#define LV_USE_DEMO_MUSIC 0
|
||||
#define LV_USE_DEMO_BENCHMARK 0
|
||||
#define LV_USE_DEMO_STRESS 0
|
||||
#define LV_USE_DEMO_KEYPAD_AND_ENCODER 0
|
||||
|
||||
#endif /* LV_CONF_H */
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @file main.c
|
||||
* @brief LVGL 模拟器入口 — 160x160 1bpp 单色菜单 UI
|
||||
* @note 基于 lv_port_pc_vscode 适配,用于 PC 上 UI 开发与调试
|
||||
*
|
||||
* 键盘映射:
|
||||
* ↑/↓/←/→ → 方向键导航
|
||||
* Enter → 确认/进入
|
||||
* Escape → 返回
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <SDL.h>
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "sim_port.h"
|
||||
#include "ui_menu.h"
|
||||
|
||||
/* 屏幕尺寸(与 MCU 端一致) */
|
||||
#define SIM_SCREEN_W 160
|
||||
#define SIM_SCREEN_H 160
|
||||
|
||||
/**
|
||||
* @brief 程序入口
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
/* 初始化 SDL2(仅 timer + events,视频由 lv_sdl_window 内部初始化) */
|
||||
if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_EVENTS) != 0) {
|
||||
fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 初始化 LVGL */
|
||||
lv_init();
|
||||
|
||||
/* 初始化模拟器端口:创建 SDL 窗口 + 键盘输入 */
|
||||
if (sim_port_init(SIM_SCREEN_W, SIM_SCREEN_H) != 0) {
|
||||
fprintf(stderr, "sim_port_init failed\n");
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 设置 SDL 窗口标题 */
|
||||
lv_display_t *disp = lv_display_get_default();
|
||||
if (disp != NULL) {
|
||||
lv_sdl_window_set_title(disp, "STM32F4-Base UI Simulator (160x160 1bpp)");
|
||||
}
|
||||
|
||||
/* 构建菜单 UI(与 MCU 端共用 ui_menu.c) */
|
||||
if (ui_menu_init() != 0) {
|
||||
fprintf(stderr, "ui_menu_init failed\n");
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("=== LVGL Simulator Started ===\n");
|
||||
printf("Screen: %dx%d 1bpp\n", SIM_SCREEN_W, SIM_SCREEN_H);
|
||||
printf("Keyboard: ↑↓←→ navigate, Enter confirm, Escape back\n");
|
||||
printf("Press Ctrl+C or close window to exit\n\n");
|
||||
|
||||
/* 主循环:处理 SDL 事件 + 驱动 LVGL 刷新 */
|
||||
while (1) {
|
||||
/* 处理 SDL 事件(窗口关闭等) */
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
printf("SDL_QUIT received, exiting...\n");
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) {
|
||||
/* Escape 键:如果在子页面则返回上一级 */
|
||||
/* LVGL keyboard 驱动已自动处理 LV_KEY_ESC */
|
||||
}
|
||||
}
|
||||
|
||||
/* 驱动 LVGL 定时器与刷新 */
|
||||
uint32_t sleep_ms = lv_timer_handler();
|
||||
if (sleep_ms == LV_NO_TIMER_READY) {
|
||||
sleep_ms = LV_DEF_REFR_PERIOD;
|
||||
}
|
||||
|
||||
/* 强制整屏刷新(1bpp SDL PARTIAL 模式下保证首帧输出) */
|
||||
lv_refr_now(NULL);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
Sleep(sleep_ms);
|
||||
#else
|
||||
usleep(sleep_ms * 1000);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 模块名称:Simulator Display Port (SDL2 模拟器端口)
|
||||
* 模块功能:为 PC 模拟器提供 LVGL SDL2 显示与键盘输入端口
|
||||
* 适用平台:Windows / Linux / macOS (SDL2)
|
||||
* 说明:替代 MCU 端的 ui_port.c,用于 PC 上 UI 开发与调试
|
||||
*/
|
||||
#include "sim_port.h"
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
/* SDL 驱动头文件(由 lv_conf.h 中 LV_SDL_INCLUDE_PATH 指定) */
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <SDL.h>
|
||||
|
||||
/* 键盘输入设备句柄(全局,供 main.c SDL 事件循环读取) */
|
||||
static lv_indev_t *g_kbd_indev = NULL;
|
||||
|
||||
/*
|
||||
* 函数功能:初始化 SDL2 显示窗口与键盘输入设备
|
||||
* 入口参数:hor_res - 水平分辨率 int32_t
|
||||
* ver_res - 垂直分辨率 int32_t
|
||||
* 返回值:0 - 成功,-1 - 失败
|
||||
* 限定条件:lv_init() 已调用
|
||||
* 函数说明:1. 创建 SDL 窗口显示设备
|
||||
* 2. 创建键盘输入设备及默认输入组
|
||||
* 3. 不创建鼠标/触摸设备(模拟器仅用键盘导航)
|
||||
*/
|
||||
int sim_port_init(int32_t hor_res, int32_t ver_res)
|
||||
{
|
||||
/* 创建默认输入组 */
|
||||
lv_group_t *g = lv_group_create();
|
||||
if (g == NULL) {
|
||||
return -1;
|
||||
}
|
||||
lv_group_set_default(g);
|
||||
|
||||
/* 创建 SDL 窗口显示设备 */
|
||||
lv_display_t *disp = lv_sdl_window_create(hor_res, ver_res);
|
||||
if (disp == NULL) {
|
||||
return -1;
|
||||
}
|
||||
lv_display_set_default(disp);
|
||||
|
||||
/* 初始化 mono 主题(1bpp 单色屏:白字黑底),并应用默认字体 */
|
||||
#if LV_USE_THEME_MONO
|
||||
lv_theme_t *th = lv_theme_mono_init(disp, true, LV_FONT_DEFAULT);
|
||||
if (th != NULL) {
|
||||
lv_display_set_theme(disp, th);
|
||||
}
|
||||
#endif
|
||||
/* 创建键盘输入设备(方向键/确认/返回 → LVGL keypad) */
|
||||
g_kbd_indev = lv_sdl_keyboard_create();
|
||||
if (g_kbd_indev == NULL) {
|
||||
return -1;
|
||||
}
|
||||
lv_indev_set_group(g_kbd_indev, lv_group_get_default());
|
||||
lv_indev_set_display(g_kbd_indev, disp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 函数功能:获取 SDL 显示设备句柄
|
||||
* 入口参数:无
|
||||
* 返回值:显示设备指针 lv_display_t * 可能为 NULL
|
||||
* 限定条件:sim_port_init() 已成功调用
|
||||
*/
|
||||
void *sim_port_get_display(void)
|
||||
{
|
||||
return (void *)lv_display_get_default();
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 模块名称:Simulator Display Port (SDL2 模拟器端口)
|
||||
* 模块功能:为 PC 模拟器提供 LVGL SDL2 显示与键盘输入端口
|
||||
* 适用平台:Windows / Linux / macOS (SDL2)
|
||||
* 说明:替代 MCU 端的 ui_port.c,用于 PC 上 UI 开发与调试
|
||||
*/
|
||||
#ifndef __SIM_PORT_H
|
||||
#define __SIM_PORT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* 函数功能:初始化 SDL2 显示窗口与键盘输入设备
|
||||
* 入口参数:hor_res - 水平分辨率 int32_t
|
||||
* ver_res - 垂直分辨率 int32_t
|
||||
* 返回值:0 - 成功,-1 - 失败
|
||||
* 限定条件:lv_init() 已调用
|
||||
* 函数说明:创建 SDL 窗口、键盘输入设备及默认输入组
|
||||
*/
|
||||
int sim_port_init(int32_t hor_res, int32_t ver_res);
|
||||
|
||||
/*
|
||||
* 函数功能:获取 SDL 显示设备句柄
|
||||
* 入口参数:无
|
||||
* 返回值:显示设备指针 lv_display_t * 可能为 NULL
|
||||
* 限定条件:sim_port_init() 已成功调用
|
||||
*/
|
||||
void *sim_port_get_display(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __SIM_PORT_H */
|
||||
Reference in New Issue
Block a user