From 59dc675722f8537e544301e50ef066f0fcba34a1 Mon Sep 17 00:00:00 2001 From: Liu Zhongwei Date: Thu, 19 Sep 2024 11:06:21 +0800 Subject: [PATCH 1/3] feat(repo): rename from 'esp-ui' to 'esp-brookesia' --- .gitmodules | 22 +--- Makefile | 20 +-- README.md | 26 ++-- README_CN.md | 28 ++-- components/esp-brookesia | 1 + .../.gitkeep | 0 components/esp-brookesia-stylesheet/.gitkeep | 0 components/esp-ui | 1 - .../esp-ui-phone_1024_600_stylesheet | 1 - .../esp-ui-phone_320_240_stylesheet | 1 - .../esp-ui-phone_480_480_stylesheet | 1 - .../esp-ui-phone_800_480_stylesheet | 1 - components/esp_brookesia_conf.h | 120 ++++++++++++++++++ components/esp_ui_conf.h | 120 ------------------ ...-brookesia-simulator_vscode.code-workspace | 9 +- main/main.cpp | 67 +++++----- 16 files changed, 202 insertions(+), 216 deletions(-) create mode 160000 components/esp-brookesia rename components/{esp-ui-app => esp-brookesia-app}/.gitkeep (100%) create mode 100644 components/esp-brookesia-stylesheet/.gitkeep delete mode 160000 components/esp-ui delete mode 160000 components/esp-ui-stylesheet/esp-ui-phone_1024_600_stylesheet delete mode 160000 components/esp-ui-stylesheet/esp-ui-phone_320_240_stylesheet delete mode 160000 components/esp-ui-stylesheet/esp-ui-phone_480_480_stylesheet delete mode 160000 components/esp-ui-stylesheet/esp-ui-phone_800_480_stylesheet create mode 100644 components/esp_brookesia_conf.h delete mode 100644 components/esp_ui_conf.h rename esp-ui-simulator_vscode.code-workspace => esp-brookesia-simulator_vscode.code-workspace (90%) diff --git a/.gitmodules b/.gitmodules index 5df29f5..dafbdbd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,23 +4,7 @@ [submodule "components/lv_drivers"] path = components/lv_drivers url = https://github.com/lvgl/lv_drivers -[submodule "components/esp-ui"] - path = components/esp-ui - url = https://github.com/espressif/esp-ui.git - branch = master -[submodule "components/esp-ui-stylesheet/esp-ui-phone_480_480_stylesheet"] - path = components/esp-ui-stylesheet/esp-ui-phone_480_480_stylesheet - url = https://github.com/esp-arduino-libs/esp-ui-phone_480_480_stylesheet.git - branch = master -[submodule "components/esp-ui-stylesheet/esp-ui-phone_800_480_stylesheet"] - path = components/esp-ui-stylesheet/esp-ui-phone_800_480_stylesheet - url = https://github.com/esp-arduino-libs/esp-ui-phone_800_480_stylesheet.git - branch = master -[submodule "components/esp-ui-stylesheet/esp-ui-phone_1024_600_stylesheet"] - path = components/esp-ui-stylesheet/esp-ui-phone_1024_600_stylesheet - url = https://github.com/esp-arduino-libs/esp-ui-phone_1024_600_stylesheet.git - branch = master -[submodule "components/esp-ui-stylesheet/esp-ui-phone_320_240_stylesheet"] - path = components/esp-ui-stylesheet/esp-ui-phone_320_240_stylesheet - url = https://github.com/esp-arduino-libs/esp-ui-phone_320_240_stylesheet.git +[submodule "components/esp-brookesia"] + path = components/esp-brookesia + url = https://github.com/espressif/esp-brookesia branch = master diff --git a/Makefile b/Makefile index e4a8b8f..7108ec9 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ UNAME_S := $(shell uname -s) # LV_DRIVER := X11 LV_DRIVER := SDL2 -PROJECT ?= esp-ui-simulator_vscode +PROJECT ?= esp-brookesia-simulator_vscode C_SRC_EXT := c CXX_SRC_EXT := cpp C_OBJ_EXT := o @@ -34,11 +34,11 @@ MAIN_DIR := ./main COMPONENTS_DIR := ./components LVGL_DIR := ${COMPONENTS_DIR}/lvgl LVGL_DRIVER_DIR := ${COMPONENTS_DIR}/lv_drivers -ESP_UI_DIR := ${COMPONENTS_DIR}/esp-ui -ESP_UI_APP_DIR := ${COMPONENTS_DIR}/esp-ui-app -ESP_UI_DATA_DIR := ${COMPONENTS_DIR}/esp-ui-stylesheet +ESP_BROOKESIA_DIR := ${COMPONENTS_DIR}/esp-brookesia +ESP_BROOKESIA_STYLESHEET_DIR := ${COMPONENTS_DIR}/esp-brookesia-stylesheet +ESP_BROOKESIA_APP_DIR := ${COMPONENTS_DIR}/esp-brookesia-app -SRC_INCLUDE_DIRS := ${MAIN_DIR} ${LVGL_DIR} ${LVGL_DRIVER_DIR} ${ESP_UI_DIR}/src ${ESP_UI_DATA_DIR} ${ESP_UI_APP_DIR} +SRC_INCLUDE_DIRS := ${MAIN_DIR} ${LVGL_DIR} ${LVGL_DRIVER_DIR} ${ESP_BROOKESIA_DIR}/src ${ESP_BROOKESIA_APP_DIR} SRC_EXCLUDE_DIRS := ${LVGL_DIR}/tests ${LVGL_DIR}/demos ${LVGL_DIR}/examples ${LVGL_DIR}/env_support INC_DIRS := ${SRC_INCLUDE_DIRS} ${COMPONENTS_DIR} @@ -93,7 +93,7 @@ LV_DRIVER_USE := USE_$(LV_DRIVER) endif # Add simulator defines to allow modification of source -DEFINES := -D SIMULATOR=1 -D LV_BUILD_TEST=0 -D $(LV_DRIVER_USE) -D ESP_UI_KCONFIG_IGNORE +DEFINES := -D SIMULATOR=1 -D LV_BUILD_TEST=0 -D $(LV_DRIVER_USE) -D ESP_BROOKESIA_KCONFIG_IGNORE # Include simulator inc folder first so lv_conf.h from custom UI can be used instead INC := $(patsubst %,-I%,$(INC_DIRS)) #-I/usr/include/freetype2 -L/usr/local/lib @@ -121,13 +121,13 @@ $(BUILD_DIR)/%.${CXX_OBJ_EXT}: %.${CXX_SRC_EXT} ${EXTRA_FILES} @mkdir -p $(dir $@) @$(CXX_COMPILE) -c -o $@ $< -$(BUILD_DIR)/%.${C_OBJ_EXT}: ${ESP_UI_DIR}/%.${C_SRC_EXT} ${EXTRA_FILES} - @echo 'Building esp-ui file: $<' +$(BUILD_DIR)/%.${C_OBJ_EXT}: ${ESP_BROOKESIA_DIR}/%.${C_SRC_EXT} ${EXTRA_FILES} + @echo 'Building esp-brookesia file: $<' @mkdir -p $(dir $@) @$(C_COMPILE) -c -o $@ $< -$(BUILD_DIR)/%.${CXX_OBJ_EXT}: ${ESP_UI_DIR}/%.${CXX_SRC_EXT} ${EXTRA_FILES} - @echo 'Building esp-ui file: $<' +$(BUILD_DIR)/%.${CXX_OBJ_EXT}: ${ESP_BROOKESIA_DIR}/%.${CXX_SRC_EXT} ${EXTRA_FILES} + @echo 'Building esp-brookesia file: $<' @mkdir -p $(dir $@) @$(CXX_COMPILE) -c -o $@ $< diff --git a/README.md b/README.md index daf047e..1c9257d 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,23 @@ -# ESP-UI PC Simulator with VSCode +# ESP-Brookesia PC Simulator with VSCode * [中文版本](./README_CN.md) -esp-ui-simulator_vscode is a [VSCode](https://code.visualstudio.com) project that enables running [LVGL](https://github.com/lvgl/lvgl) and [esp-ui](https://github.com/espressif/esp-ui) on a PC. It is used to simulate the esp-ui system UI, making it convenient for users to debug stylesheets and apps. +esp-brookesia-simulator_vscode is a [VSCode](https://code.visualstudio.com) project that enables running [LVGL](https://github.com/lvgl/lvgl) and [ESP-Brookesia](https://github.com/espressif/esp-brookesia) on a PC. It is used to simulate the esp-brookesia system UI, making it convenient for users to debug stylesheets and apps. -esp-ui-simulator_vscode is a port and modification based on [lv_port_pc_vscode](https://github.com/lvgl/lv_port_pc_vscode), designed to support the compilation of C++ files. +esp-brookesia-simulator_vscode is a port and modification based on [lv_port_pc_vscode](https://github.com/lvgl/lv_port_pc_vscode), designed to support the compilation of C++ files. > [!WARNING] -> * esp-ui-simulator_vscode has been tested only on `Linux` and `MacOS`, but may also work on `Windows WSL`. +> * esp-brookesia-simulator_vscode has been tested only on `Linux`, `MacOS` and `Windows WSL`. ## Dependencies ### Build Tools -Ensure that `GCC`, `GDB`, `bear`, and `make` are installed on your system. All requirements are pre-configured in the [.workspace](./esp-ui-simulator_vscode.code-workspace) file (simply double-click this file to open the project). +On Linux, you can install `GCC`, `GDB`, `bear` and `make` via terminal: + +```bash +sudo apt-get update && sudo apt-get install -y gcc gdb bear make +``` ### Graphics Drivers @@ -42,17 +46,17 @@ sudo apt-get update && sudo apt-get install -y libx11-dev 1. Clone the project and related submodules: ```bash -git clone --recursive https://github.com/esp-arduino-libs/esp-ui-simulator_vscode +git clone --recursive https://github.com/esp-arduino-libs/esp-brookesia-simulator_vscode ``` -2. Double-clicking the VSCode workspace file [esp-ui-simulator_vscode.code-workspace](./esp-ui-simulator_vscode.code-workspace) to open the project. - -3. Place your apps in the [components/esp-ui-app](./components/esp-ui-app) directory and create and install them in the `main()` function in [main/main.cpp](./main/main.cpp). +2. Double-clicking the VSCode workspace file [esp-brookesia-simulator_vscode.code-workspace](./esp-brookesia-simulator_vscode.code-workspace) to open the project. -4. Press F5 to build and debug. The system UI of esp-ui should appear in a new window, and you can access all debugging features of VSCode through GDB. +3. Press F5 to build and debug. The system UI of ESP-Brookesia should appear in a new window, and you can access all debugging features of VSCode through GDB. > [!NOTE] > * To allow temporary modifications between the simulator and device code, a global definition `SIMULATOR=1` has been added to the Makefile. +> * The project will by default compile the `.c` 和 `.cpp` files located in the [components/esp-brookesia-app](./components/esp-brookesia-app) directory and include this directory as a header file directory. Users can place their custom apps in this directory. +> * The project will by default compile the `.c` 和 `.cpp` files located in the [components/esp-brookesia-stylesheet](./components/esp-brookesia-stylesheet) directory and include this directory as a header file directory. Users can place their custom stylesheets in this directory. > [!WARNING] -> * Please use the workspace file [esp-ui-simulator_vscode.code-workspace](./esp-ui-simulator_vscode.code-workspace) to open the project, as it contains all the configurations for building and debugging. Otherwise, you won't be able to directly use the `F5` key to build and debug. +> * Please use the workspace file [esp-brookesia-simulator_vscode.code-workspace](./esp-brookesia-simulator_vscode.code-workspace) to open the project, as it contains all the configurations for building and debugging. Otherwise, you won't be able to directly use the `F5` key to build and debug. diff --git a/README_CN.md b/README_CN.md index edc786a..5d856d4 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,19 +1,23 @@ -# ESP-UI PC Simulator with VSCode +# ESP-Brookesia PC Simulator with VSCode * [English Version](./README.md) -esp-ui-simulator_vscode 是一个能够在 PC 上运行 [LVGL](https://github.com/lvgl/lvgl) 和 [esp-ui](https://github.com/espressif/esp-ui) 的 [VSCode](https://code.visualstudio.com) 工程,用于模拟运行 esp-ui 的系统 UI,方便用户调试样式表以及 app。 +esp-brookesia-simulator_vscode 是一个能够在 PC 上运行 [LVGL](https://github.com/lvgl/lvgl) 和 [ESP-Brookesia](https://github.com/espressif/esp-brookesia) 的 [VSCode](https://code.visualstudio.com) 工程,用于模拟运行 ESP-Brookesia 的系统 UI,方便用户调试样式表以及 app。 -esp-ui-simulator_vscode 是参考 [lv_port_pc_vscode](https://github.com/lvgl/lv_port_pc_vscode) 进行的移植和修改,从而支持编译 C++ 文件。 +esp-brookesia-simulator_vscode 是参考 [lv_port_pc_vscode](https://github.com/lvgl/lv_port_pc_vscode) 进行的移植和修改,从而支持编译 C++ 文件。 > [!WARNING] -> * esp-ui-simulator_vscode 仅在 `Linux` 和 `MacOS` 上进行了测试,但也可能在 `Windows WSL` 上工作。 +> * esp-brookesia-simulator_vscode 仅在 `Linux`、`MacOS` 和 `Windows WSL` 上进行了测试。 ## 依赖项 -### 编译工具 +### 编译和调试工具 -请确保系统中已安装 `GCC` `GDB` `bear` 和 `make`,所有的需求都已在 [.workspace](./esp-ui-simulator_vscode.code-workspace) 文件中预配置好(只需双击此文件打开工程)。 +在 Linux 上,用户可以通过终端安装 `GCC`、`GDB`、`bear` 和 `make`: + +```bash +sudo apt-get update && sudo apt-get install -y gcc gdb bear make +``` ### 图形驱动 @@ -42,17 +46,17 @@ sudo apt-get update && sudo apt-get install -y libx11-dev 1. 克隆工程及相关子模块: ```bash -git clone --recursive https://github.com/esp-arduino-libs/esp-ui-simulator_vscode +git clone --recursive https://github.com/esp-arduino-libs/esp-brookesia-simulator_vscode ``` -2. 双击打开 VSCode 工作区文件 [esp-ui-simulator_vscode.code-workspace](./esp-ui-simulator_vscode.code-workspace) 打开工程。 - -3. 在 [components/esp-ui-app](./components/esp-ui-app) 目录下存放 apps,并在 [main/main.cpp](./main/main.cpp) 的 `main()` 函数中进行创建和安装。 +2. 双击打开 VSCode 工作区文件 [esp-brookesia-simulator_vscode.code-workspace](./esp-brookesia-simulator_vscode.code-workspace) 打开工程。 -4. 按 F5 构建和调试,此时 esp-ui 的系统 UI 应该会显示在一个新窗口中。同时,用户可以通过 GDB 访问 VSCode 的所有调试功能。 +3. 按 F5 构建和调试,此时 ESP-Brookesia 的系统 UI 应该会显示在一个新窗口中。同时,用户可以通过 GDB 访问 VSCode 的所有调试功能。 > [!NOTE] > * 为了在模拟器和设备代码之间进行临时修改,Makefile 中已添加了 `SIMULATOR=1` 全局定义。 +> * 工程默认会编译 [components/esp-brookesia-app](./components/esp-brookesia-app) 目录下的 `.c` 和 `.cpp` 文件,并包含此目录作为头文件目录,用户可以将自定义 apps 放置在此目录下。 +> * 工程默认会编译 [components/esp-brookesia-stylesheet](./components/esp-brookesia-stylesheet) 目录下的 `.c` 和 `.cpp` 文件,并包含此目录作为头文件目录,用户可以将自定义样式表放置在此目录下。 > [!WARNING] -> * 请使用工作区文件 [esp-ui-simulator_vscode.code-workspace](./esp-ui-simulator_vscode.code-workspace) 打开工程,因为它包含了所有编译和调试的配置。否则,你将无法直接使用 `F5` 键进行编译和调试。 +> * 请使用工作区文件 [esp-brookesia-simulator_vscode.code-workspace](./esp-brookesia-simulator_vscode.code-workspace) 打开工程,因为它包含了所有编译和调试的配置。否则,你将无法直接使用 `F5` 键进行编译和调试。 diff --git a/components/esp-brookesia b/components/esp-brookesia new file mode 160000 index 0000000..2b0d70f --- /dev/null +++ b/components/esp-brookesia @@ -0,0 +1 @@ +Subproject commit 2b0d70ffe8692c3579e73d754f124154dfae5741 diff --git a/components/esp-ui-app/.gitkeep b/components/esp-brookesia-app/.gitkeep similarity index 100% rename from components/esp-ui-app/.gitkeep rename to components/esp-brookesia-app/.gitkeep diff --git a/components/esp-brookesia-stylesheet/.gitkeep b/components/esp-brookesia-stylesheet/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/components/esp-ui b/components/esp-ui deleted file mode 160000 index b7a1d13..0000000 --- a/components/esp-ui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b7a1d13d7cc84935f81aeb14803c50867cc83bdc diff --git a/components/esp-ui-stylesheet/esp-ui-phone_1024_600_stylesheet b/components/esp-ui-stylesheet/esp-ui-phone_1024_600_stylesheet deleted file mode 160000 index ec5dd88..0000000 --- a/components/esp-ui-stylesheet/esp-ui-phone_1024_600_stylesheet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ec5dd889e2d02e20cc2a5edd7220e8e369783a3b diff --git a/components/esp-ui-stylesheet/esp-ui-phone_320_240_stylesheet b/components/esp-ui-stylesheet/esp-ui-phone_320_240_stylesheet deleted file mode 160000 index 2f903f8..0000000 --- a/components/esp-ui-stylesheet/esp-ui-phone_320_240_stylesheet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2f903f8eda45246337e5c3cc1ec442e94ff17398 diff --git a/components/esp-ui-stylesheet/esp-ui-phone_480_480_stylesheet b/components/esp-ui-stylesheet/esp-ui-phone_480_480_stylesheet deleted file mode 160000 index 760a36c..0000000 --- a/components/esp-ui-stylesheet/esp-ui-phone_480_480_stylesheet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 760a36c43425c0be1d3c264a43477608c60479af diff --git a/components/esp-ui-stylesheet/esp-ui-phone_800_480_stylesheet b/components/esp-ui-stylesheet/esp-ui-phone_800_480_stylesheet deleted file mode 160000 index 6cec799..0000000 --- a/components/esp-ui-stylesheet/esp-ui-phone_800_480_stylesheet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6cec7994587415a39fc824592d1690d776b8b8ad diff --git a/components/esp_brookesia_conf.h b/components/esp_brookesia_conf.h new file mode 100644 index 0000000..9d1283e --- /dev/null +++ b/components/esp_brookesia_conf.h @@ -0,0 +1,120 @@ +/* + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// Debug ///////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/* Assert when check result failed. 0: disable, 1: enable */ +#define ESP_BROOKESIA_CHECK_RESULT_ASSERT (0) + +/** + * Log style. choose one of the following: + * - ESP_BROOKESIA_LOG_STYLE_STD: Use printf to output log + * - ESP_BROOKESIA_LOG_STYLE_ESP: Use ESP_LOGx to output log + * - ESP_BROOKESIA_LOG_STYLE_LVGL: Use LV_LOG_x to output log + * + */ +#define ESP_BROOKESIA_LOG_STYLE (ESP_BROOKESIA_LOG_STYLE_STD) + +/** + * Log level. Higher levels produce less log output. choose one of the following: + * - ESP_BROOKESIA_LOG_LEVEL_DEBUG: Output all logs (most verbose) + * - ESP_BROOKESIA_LOG_LEVEL_INFO: Output info, warnings, and errors + * - ESP_BROOKESIA_LOG_LEVEL_WARN: Output warnings and errors + * - ESP_BROOKESIA_LOG_LEVEL_ERROR: Output only errors + * - ESP_BROOKESIA_LOG_LEVEL_NONE: No log output (least verbose) + * + */ +#define ESP_BROOKESIA_LOG_LEVEL (ESP_BROOKESIA_LOG_LEVEL_INFO) + +/* Enable debug logs for modules */ +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_CORE (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_WIDGETS (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_PHONE (1) +// Core +#if ESP_BROOKESIA_LOG_ENABLE_DEBUG_CORE +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_CORE_APP (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_CORE_HOME (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_CORE_MANAGER (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_CORE_CORE (1) +#endif +// Widgets +#if ESP_BROOKESIA_LOG_ENABLE_DEBUG_WIDGETS +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_WIDGETS_APP_LAUNCHER (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_WIDGETS_RECENTS_SCREEN (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_WIDGETS_GESTURE (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_WIDGETS_NAVIGATION (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_WIDGETS_STATUS_BAR (1) +#endif +// Phone +#if ESP_BROOKESIA_LOG_ENABLE_DEBUG_PHONE +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_PHONE_APP (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_PHONE_HOME (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_PHONE_MANAGER (1) +#define ESP_BROOKESIA_LOG_ENABLE_DEBUG_PHONE_PHONE (1) +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////// Memory ///////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +#define ESP_BROOKESIA_MEMORY_USE_CUSTOM (0) +#if ESP_BROOKESIA_MEMORY_USE_CUSTOM == 0 +#define ESP_BROOKESIA_MEMORY_INCLUDE +#define ESP_BROOKESIA_MEMORY_MALLOC malloc +#define ESP_BROOKESIA_MEMORY_FREE free +#else +#define ESP_BROOKESIA_MEMORY_INCLUDE "esp_heap_caps.h" +#define ESP_BROOKESIA_MEMORY_MALLOC(x) heap_caps_aligned_alloc(1, x, MALLOC_CAP_SPIRAM) +#define ESP_BROOKESIA_MEMORY_FREE free +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////// Squareline //////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/** + * Use the internal "ui_helpers.c" and "ui_helpers.h" instead of the ones exported from Squareline Studio. 1: enable, + * 0: disable + * + * This configuration is to avoid function redefinition errors caused by multiple UIs exported from Squareline Studio + * that include duplicate "ui_helpers.c" and "ui_helpers.h". + * + */ +#define ESP_BROOKESIA_SQUARELINE_USE_INTERNAL_UI_HELPERS (1) +#if ESP_BROOKESIA_SQUARELINE_USE_INTERNAL_UI_HELPERS +/** + * Please uncomment one of the options below based on the version of Squareline Studio you are using and the corresponding + * configured version of LVGL. (If multiple options are uncommented, a compilation error will occur) + * + */ +// | Squareline | LVGL | +// #define ESP_BROOKESIA_SQ1_3_4_LV8_3_3 // | 1.3.4 | 8.3.3 | +// #define ESP_BROOKESIA_SQ1_3_4_LV8_3_4 // | 1.3.4 | 8.3.4 | +// #define ESP_BROOKESIA_SQ1_3_4_LV8_3_6 // | 1.3.4 | 8.3.6 | +// #define ESP_BROOKESIA_SQ1_4_0_LV8_3_6 // | 1.4.0 | 8.3.6 | +// #define ESP_BROOKESIA_SQ1_4_0_LV8_3_11 // | 1.4.0 | 8.3.11 | +// #define ESP_BROOKESIA_SQ1_4_1_LV8_3_6 // | 1.4.1 | 8.3.6 | +#define ESP_BROOKESIA_SQ1_4_1_LV8_3_11 // | 1.4.1 | 8.3.11 | +#endif /* ESP_BROOKESIA_SQUARELINE_USE_INTERNAL_UI_HELPERS */ + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////// File Version /////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/** + * Do not change the following versions, they are used to check if the configurations in this file are compatible with + * the current version of `esp_brookesia_conf.h` in the library. The detailed rules are as follows: + * + * 1. If the major version is not consistent, then the configurations in this file are incompatible with the library + * and must be replaced with the file from the library. + * 2. If the minor version is not consistent, this file might be missing some new configurations, which will be set to + * default values. It is recommended to replace it with the file from the library. + * 3. Even if the patch version is not consistent, it will not affect normal functionality. + * + */ +#define ESP_BROOKESIA_CONF_FILE_VER_MAJOR 0 +#define ESP_BROOKESIA_CONF_FILE_VER_MINOR 1 +#define ESP_BROOKESIA_CONF_FILE_VER_PATCH 0 diff --git a/components/esp_ui_conf.h b/components/esp_ui_conf.h deleted file mode 100644 index fbea7bc..0000000 --- a/components/esp_ui_conf.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////// Debug ///////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/* Assert when check result failed. 0: disable, 1: enable */ -#define ESP_UI_CHECK_RESULT_ASSERT (0) - -/** - * Log style. choose one of the following: - * - ESP_UI_LOG_STYLE_STD: Use printf to output log - * - ESP_UI_LOG_STYLE_ESP: Use ESP_LOGx to output log - * - ESP_UI_LOG_STYLE_LVGL: Use LV_LOG_x to output log - * - */ -#define ESP_UI_LOG_STYLE (ESP_UI_LOG_STYLE_STD) - -/** - * Log level. Higher levels produce less log output. choose one of the following: - * - ESP_UI_LOG_LEVEL_DEBUG: Output all logs (most verbose) - * - ESP_UI_LOG_LEVEL_INFO: Output info, warnings, and errors - * - ESP_UI_LOG_LEVEL_WARN: Output warnings and errors - * - ESP_UI_LOG_LEVEL_ERROR: Output only errors - * - ESP_UI_LOG_LEVEL_NONE: No log output (least verbose) - * - */ -#define ESP_UI_LOG_LEVEL (ESP_UI_LOG_LEVEL_DEBUG) - -/* Enable debug logs for modules */ -#define ESP_UI_LOG_ENABLE_DEBUG_CORE (1) -#define ESP_UI_LOG_ENABLE_DEBUG_WIDGETS (1) -#define ESP_UI_LOG_ENABLE_DEBUG_PHONE (1) -// Core -#if ESP_UI_LOG_ENABLE_DEBUG_CORE -#define ESP_UI_LOG_ENABLE_DEBUG_CORE_APP (1) -#define ESP_UI_LOG_ENABLE_DEBUG_CORE_HOME (1) -#define ESP_UI_LOG_ENABLE_DEBUG_CORE_MANAGER (1) -#define ESP_UI_LOG_ENABLE_DEBUG_CORE_CORE (1) -#endif -// Widgets -#if ESP_UI_LOG_ENABLE_DEBUG_WIDGETS -#define ESP_UI_LOG_ENABLE_DEBUG_WIDGETS_APP_LAUNCHER (1) -#define ESP_UI_LOG_ENABLE_DEBUG_WIDGETS_RECENTS_SCREEN (1) -#define ESP_UI_LOG_ENABLE_DEBUG_WIDGETS_GESTURE (0) -#define ESP_UI_LOG_ENABLE_DEBUG_WIDGETS_NAVIGATION (1) -#define ESP_UI_LOG_ENABLE_DEBUG_WIDGETS_STATUS_BAR (1) -#endif -// Phone -#if ESP_UI_LOG_ENABLE_DEBUG_PHONE -#define ESP_UI_LOG_ENABLE_DEBUG_PHONE_APP (1) -#define ESP_UI_LOG_ENABLE_DEBUG_PHONE_HOME (1) -#define ESP_UI_LOG_ENABLE_DEBUG_PHONE_MANAGER (1) -#define ESP_UI_LOG_ENABLE_DEBUG_PHONE_PHONE (1) -#endif - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////// Memory ///////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#define ESP_UI_MEMORY_USE_CUSTOM (0) -#if ESP_UI_MEMORY_USE_CUSTOM == 0 -#define ESP_UI_MEMORY_INCLUDE -#define ESP_UI_MEMORY_MALLOC malloc -#define ESP_UI_MEMORY_FREE free -#else -#define ESP_UI_MEMORY_INCLUDE "esp_heap_caps.h" -#define ESP_UI_MEMORY_MALLOC(x) heap_caps_aligned_alloc(1, x, MALLOC_CAP_SPIRAM) -#define ESP_UI_MEMORY_FREE free -#endif - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////// Squareline //////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/** - * Use the internal "ui_helpers.c" and "ui_helpers.h" instead of the ones exported from Squareline Studio. 1: enable, - * 0: disable - * - * This configuration is to avoid function redefinition errors caused by multiple UIs exported from Squareline Studio - * that include duplicate "ui_helpers.c" and "ui_helpers.h". - * - */ -#define ESP_UI_SQUARELINE_USE_INTERNAL_UI_HELPERS (1) -#if ESP_UI_SQUARELINE_USE_INTERNAL_UI_HELPERS -/** - * Please uncomment one of the options below based on the version of Squareline Studio you are using and the corresponding - * configured version of LVGL. (If multiple options are uncommented, a compilation error will occur) - * - */ -// | Squareline | LVGL | -// #define ESP_UI_SQ1_3_4_LV8_3_3 // | 1.3.4 | 8.3.3 | -// #define ESP_UI_SQ1_3_4_LV8_3_4 // | 1.3.4 | 8.3.4 | -// #define ESP_UI_SQ1_3_4_LV8_3_6 // | 1.3.4 | 8.3.6 | -// #define ESP_UI_SQ1_4_0_LV8_3_6 // | 1.4.0 | 8.3.6 | -// #define ESP_UI_SQ1_4_0_LV8_3_11 // | 1.4.0 | 8.3.11 | -// #define ESP_UI_SQ1_4_1_LV8_3_6 // | 1.4.1 | 8.3.6 | -#define ESP_UI_SQ1_4_1_LV8_3_11 // | 1.4.1 | 8.3.11 | -#endif /* ESP_UI_SQUARELINE_USE_INTERNAL_UI_HELPERS */ - -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////// File Version /////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -/** - * Do not change the following versions, they are used to check if the configurations in this file are compatible with - * the current version of `esp_ui_conf.h` in the library. The detailed rules are as follows: - * - * 1. If the major version is not consistent, then the configurations in this file are incompatible with the library - * and must be replaced with the file from the library. - * 2. If the minor version is not consistent, this file might be missing some new configurations, which will be set to - * default values. It is recommended to replace it with the file from the library. - * 3. Even if the patch version is not consistent, it will not affect normal functionality. - * - */ -#define ESP_UI_CONF_FILE_VER_MAJOR 0 -#define ESP_UI_CONF_FILE_VER_MINOR 1 -#define ESP_UI_CONF_FILE_VER_PATCH 0 diff --git a/esp-ui-simulator_vscode.code-workspace b/esp-brookesia-simulator_vscode.code-workspace similarity index 90% rename from esp-ui-simulator_vscode.code-workspace rename to esp-brookesia-simulator_vscode.code-workspace index 6a49fac..95e089a 100644 --- a/esp-ui-simulator_vscode.code-workspace +++ b/esp-brookesia-simulator_vscode.code-workspace @@ -31,7 +31,12 @@ "array": "cpp", "string": "cpp", "string_view": "cpp", - "unordered_map": "cpp" + "unordered_map": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "initializer_list": "cpp" }, }, // tasks.json section @@ -74,7 +79,7 @@ "name": "g++ build and debug active file", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/build/bin/esp-ui-simulator_vscode", + "program": "${workspaceFolder}/build/bin/esp-brookesia-simulator_vscode", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", diff --git a/main/main.cpp b/main/main.cpp index 7a4a0b0..86d8296 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -23,8 +23,8 @@ #include "lv_drivers/x11/x11.h" #endif #include -#include "esp_ui.hpp" -/* These are built-in app examples in `esp-ui` library */ +#include "esp_brookesia.hpp" +/* These are built-in app examples in `esp-brookesia` library */ #include "app_examples/phone/simple_conf/src/phone_app_simple_conf.hpp" #include "app_examples/phone/complex_conf/src/phone_app_complex_conf.hpp" #include "app_examples/phone/squareline/src/phone_app_squareline.hpp" @@ -32,21 +32,14 @@ /********************* * DEFINES *********************/ -#define EXAMPLE_USE_EXTERNAL_STYLESHEET (1) -#if EXAMPLE_USE_EXTERNAL_STYLESHEET - #if (DISP_HOR_RES == 1024) && (DISP_VER_RES == 600) - #include "esp-ui-phone_1024_600_stylesheet/src/esp_ui_phone_1024_600_stylesheet.h" - #define EXAMPLE_ESP_UI_PHONE_DARK_STYLESHEET() ESP_UI_PHONE_1024_600_DARK_STYLESHEET() - #elif (DISP_HOR_RES == 800) && (DISP_VER_RES == 480) - #include "esp-ui-phone_800_480_stylesheet/src/esp_ui_phone_800_480_stylesheet.h" - #define EXAMPLE_ESP_UI_PHONE_DARK_STYLESHEET() ESP_UI_PHONE_800_480_DARK_STYLESHEET() - #elif (DISP_HOR_RES == 480) && (DISP_VER_RES == 480) - #include "esp-ui-phone_480_480_stylesheet/src/esp_ui_phone_480_480_stylesheet.h" - #define EXAMPLE_ESP_UI_PHONE_DARK_STYLESHEET() ESP_UI_PHONE_480_480_DARK_STYLESHEET() - #elif (DISP_HOR_RES == 320) && (DISP_VER_RES == 240) - #include "esp-ui-phone_320_240_stylesheet/src/esp_ui_phone_320_240_stylesheet.h" - #define EXAMPLE_ESP_UI_PHONE_DARK_STYLESHEET() ESP_UI_PHONE_320_240_DARK_STYLESHEET() - #endif +#if (DISP_HOR_RES == 1024) && (DISP_VER_RES == 600) + #define EXAMPLE_ESP_BROOKESIA_PHONE_DARK_STYLESHEET() ESP_BROOKESIA_PHONE_1024_600_DARK_STYLESHEET() +#elif (DISP_HOR_RES == 800) && (DISP_VER_RES == 480) + #define EXAMPLE_ESP_BROOKESIA_PHONE_DARK_STYLESHEET() ESP_BROOKESIA_PHONE_800_480_DARK_STYLESHEET() +#elif (DISP_HOR_RES == 480) && (DISP_VER_RES == 480) + #define EXAMPLE_ESP_BROOKESIA_PHONE_DARK_STYLESHEET() ESP_BROOKESIA_PHONE_480_480_DARK_STYLESHEET() +#elif (DISP_HOR_RES == 320) && (DISP_VER_RES == 240) + #define EXAMPLE_ESP_BROOKESIA_PHONE_DARK_STYLESHEET() ESP_BROOKESIA_PHONE_320_240_DARK_STYLESHEET() #endif /********************** @@ -111,36 +104,36 @@ int main(int argc, char **argv) hal_init(); /* Create a phone object */ - ESP_UI_Phone *phone = new ESP_UI_Phone(disp); - ESP_UI_CHECK_NULL_RETURN(phone, 1, "Create phone failed"); + ESP_Brookesia_Phone *phone = new ESP_Brookesia_Phone(disp); + ESP_BROOKESIA_CHECK_NULL_RETURN(phone, 1, "Create phone failed"); -#ifdef EXAMPLE_ESP_UI_PHONE_DARK_STYLESHEET +#ifdef EXAMPLE_ESP_BROOKESIA_PHONE_DARK_STYLESHEET /* Add external stylesheet and activate it */ - ESP_UI_PhoneStylesheet_t *phone_stylesheet = new ESP_UI_PhoneStylesheet_t EXAMPLE_ESP_UI_PHONE_DARK_STYLESHEET(); - ESP_UI_CHECK_NULL_RETURN(phone_stylesheet, 1, "Create phone stylesheet failed"); - ESP_UI_CHECK_FALSE_RETURN(phone->addStylesheet(phone_stylesheet), 1, "Add phone stylesheet failed"); - ESP_UI_CHECK_FALSE_RETURN(phone->activateStylesheet(phone_stylesheet), 1, "Activate phone stylesheet failed"); + ESP_Brookesia_PhoneStylesheet_t *phone_stylesheet = new ESP_Brookesia_PhoneStylesheet_t EXAMPLE_ESP_BROOKESIA_PHONE_DARK_STYLESHEET(); + ESP_BROOKESIA_CHECK_NULL_RETURN(phone_stylesheet, 1, "Create phone stylesheet failed"); + ESP_BROOKESIA_CHECK_FALSE_RETURN(phone->addStylesheet(phone_stylesheet), 1, "Add phone stylesheet failed"); + ESP_BROOKESIA_CHECK_FALSE_RETURN(phone->activateStylesheet(phone_stylesheet), 1, "Activate phone stylesheet failed"); delete phone_stylesheet; #endif /* Configure and begin the phone */ - ESP_UI_CHECK_FALSE_RETURN(phone->setTouchDevice(mouse_indev), 1, "Set touch device failed"); - ESP_UI_CHECK_FALSE_RETURN(phone->begin(), 1, "Begin failed"); - // ESP_UI_CHECK_FALSE_RETURN(phone->getCoreHome().showContainerBorder(), 1, "Show container border failed"); + ESP_BROOKESIA_CHECK_FALSE_RETURN(phone->setTouchDevice(mouse_indev), 1, "Set touch device failed"); + ESP_BROOKESIA_CHECK_FALSE_RETURN(phone->begin(), 1, "Begin failed"); + // ESP_BROOKESIA_CHECK_FALSE_RETURN(phone->getCoreHome().showContainerBorder(), 1, "Show container border failed"); /* Install apps */ PhoneAppSimpleConf *phone_app_simple_conf = new PhoneAppSimpleConf(true, true); - ESP_UI_CHECK_NULL_RETURN(phone_app_simple_conf, 1, "Create phone app simple conf failed"); - ESP_UI_CHECK_FALSE_RETURN((phone->installApp(phone_app_simple_conf) >= 0), 1, "Install phone app simple conf failed"); + ESP_BROOKESIA_CHECK_NULL_RETURN(phone_app_simple_conf, 1, "Create phone app simple conf failed"); + ESP_BROOKESIA_CHECK_FALSE_RETURN((phone->installApp(phone_app_simple_conf) >= 0), 1, "Install phone app simple conf failed"); PhoneAppComplexConf *phone_app_complex_conf = new PhoneAppComplexConf(true, true); - ESP_UI_CHECK_NULL_RETURN(phone_app_complex_conf, 1, "Create phone app complex conf failed"); - ESP_UI_CHECK_FALSE_RETURN((phone->installApp(phone_app_complex_conf) >= 0), 1, "Install phone app complex conf failed"); + ESP_BROOKESIA_CHECK_NULL_RETURN(phone_app_complex_conf, 1, "Create phone app complex conf failed"); + ESP_BROOKESIA_CHECK_FALSE_RETURN((phone->installApp(phone_app_complex_conf) >= 0), 1, "Install phone app complex conf failed"); PhoneAppSquareline *phone_app_squareline = new PhoneAppSquareline(true, true); - ESP_UI_CHECK_NULL_RETURN(phone_app_squareline, 1, "Create phone app squareline failed"); - ESP_UI_CHECK_FALSE_RETURN((phone->installApp(phone_app_squareline) >= 0), 1, "Install phone app squareline failed"); + ESP_BROOKESIA_CHECK_NULL_RETURN(phone_app_squareline, 1, "Create phone app squareline failed"); + ESP_BROOKESIA_CHECK_FALSE_RETURN((phone->installApp(phone_app_squareline) >= 0), 1, "Install phone app squareline failed"); /* Create a timer to update the clock */ - ESP_UI_CHECK_NULL_RETURN(lv_timer_create(on_clock_update_timer_cb, 1000, phone), 1, "Create clock update timer failed"); + ESP_BROOKESIA_CHECK_NULL_RETURN(lv_timer_create(on_clock_update_timer_cb, 1000, phone), 1, "Create clock update timer failed"); while(1) { /* Periodically call the lv_task handler. @@ -161,19 +154,19 @@ static void on_clock_update_timer_cb(struct _lv_timer_t *t) time_t now; struct tm timeinfo; bool is_time_pm = false; - ESP_UI_Phone *phone = (ESP_UI_Phone *)t->user_data; + ESP_Brookesia_Phone *phone = (ESP_Brookesia_Phone *)t->user_data; time(&now); localtime_r(&now, &timeinfo); is_time_pm = (timeinfo.tm_hour >= 12); - ESP_UI_CHECK_FALSE_EXIT(phone->getHome().getStatusBar()->setClock(timeinfo.tm_hour, timeinfo.tm_min, is_time_pm), + ESP_BROOKESIA_CHECK_FALSE_EXIT(phone->getHome().getStatusBar()->setClock(timeinfo.tm_hour, timeinfo.tm_min, is_time_pm), "Refresh status bar failed"); lv_mem_monitor_t mon; lv_mem_monitor(&mon); uint32_t free_kb = mon.free_size / 1024; uint32_t total_kb = mon.total_size / 1024; - ESP_UI_CHECK_FALSE_EXIT(phone->getHome().getRecentsScreen()->setMemoryLabel(free_kb, total_kb, 0, 0), + ESP_BROOKESIA_CHECK_FALSE_EXIT(phone->getHome().getRecentsScreen()->setMemoryLabel(free_kb, total_kb, 0, 0), "Refresh memory label failed"); } From 7e15a2d9222179d6ab452bc3fc3d24f70642140c Mon Sep 17 00:00:00 2001 From: Kevincoooool <33611679+Kevincoooool@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:11:12 +0800 Subject: [PATCH 2/3] feat(repo): use cmake as build tool Closes https://github.com/esp-arduino-libs/esp-brookesia-simulator_vscode/pull/3 --- .gitignore | 9 +- CMakeLists.txt | 111 ++++++++++++++ Makefile | 144 ------------------ README.md | 71 +++++---- README_CN.md | 69 +++++---- components/esp-brookesia | 2 +- components/lv_drv_conf.h | 4 + esp-brookesia-simulator_vscode.code-workspace | 105 ------------- main/main.cpp | 18 ++- simulator.code-workspace | 112 ++++++++++++++ 10 files changed, 330 insertions(+), 315 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile delete mode 100644 esp-brookesia-simulator_vscode.code-workspace create mode 100644 simulator.code-workspace diff --git a/.gitignore b/.gitignore index 389603c..e41365f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# Ignore build folder -build/ - # Ignore all dot folders, with below exceptions .*/ @@ -10,6 +7,6 @@ build/ # MacOS .DS_Store -# Ignore files generated by bear -compile_commands.events.json -compile_commands.json +# Ignore files generated by CMake +build/ +bin/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2554689 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,111 @@ +cmake_minimum_required(VERSION 3.10) + +project(esp_brookesia_simulator_vscode LANGUAGES C CXX) + +# Set definitions +set(SIMULATOR_DEF "-DSIMULATOR=1") # Flag for simulator +set(DISP_DEF "-DDISP_HOR_RES=1024 -DDISP_VER_RES=600") # Resolution of the display +set(LVGL_DEF "-DLV_CONF_INCLUDE_SIMPLE") # Used for LVGL related codes +set(LV_DRIVERS_DEF "-DUSE_SDL") # Used for lv_drivers related codes +set(ESP_BROOKESIA_DEF "-DESP_BROOKESIA_KCONFIG_IGNORE") # Used for ESP-Brookesia related codes +# Set C/CXX toolchain +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(CMAKE_C_COMPILER /usr/bin/gcc) + set(CMAKE_CXX_COMPILER /usr/bin/g++) + message(STATUS "Detected system: Linux") + message(STATUS "Using toolchain C: ${CMAKE_C_COMPILER}") + message(STATUS "Using toolchain CXX: ${CMAKE_CXX_COMPILER}") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(CMAKE_C_COMPILER gcc.exe) + set(CMAKE_CXX_COMPILER g++.exe) + message(STATUS "Detected system: Windows") + message(STATUS "Using toolchain C: ${CMAKE_C_COMPILER}") + message(STATUS "Using toolchain CXX: ${CMAKE_CXX_COMPILER}") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(CMAKE_C_COMPILER /usr/bin/clang) + set(CMAKE_CXX_COMPILER /usr/bin/clang++) + message(STATUS "Detected system: MacOS") + message(STATUS "Using toolchain C: ${CMAKE_C_COMPILER}") + message(STATUS "Using toolchain CXX: ${CMAKE_CXX_COMPILER}") +endif() +# Set C/C++ standards +set(CMAKE_C_STANDARD 11) # C11 +set(CMAKE_CXX_STANDARD 17) # C17 +set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Set compiler flags +set(CMAKE_C_FLAGS "-O0 -g -Wall -Wextra -Wshadow -Wundef -Wno-unused-function") +set(CMAKE_CXX_FLAGS "-O0 -g -Wall -Wextra -Wshadow -Wundef -Wno-unused-function -Wno-unused-parameter \ + -Wno-missing-field-initializers") +# Set cmake options +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) +# Set componets directory +set(MAIN_DIR ${CMAKE_SOURCE_DIR}/main) +set(COMPONENTS_DIR ${CMAKE_SOURCE_DIR}/components) +set(LVGL_DIR ${COMPONENTS_DIR}/lvgl) +set(LV_DRIVERS_DIR ${COMPONENTS_DIR}/lv_drivers) +set(ESP_BROOKESIA_DIR ${COMPONENTS_DIR}/esp-brookesia/src) +set(ESP_BROOKESIA_APP_DIR ${COMPONENTS_DIR}/esp-brookesia-app) +set(ESP_BROOKESIA_STYLESHEET_DIR ${COMPONENTS_DIR}/esp-brookesia-stylesheet) + +# Include componets directories +include_directories( + ${SDL2_INCLUDE_DIRS} + ${COMPONENTS_DIR} + ${LVGL_DIR} + ${LV_DRIVERS_DIR} + ${ESP_BROOKESIA_DIR} + ${ESP_BROOKESIA_APP_DIR} + ${ESP_BROOKESIA_STYLESHEET_DIR} +) + +# Search C/CXX sources +file(GLOB_RECURSE MAIN_SRCS "${MAIN_DIR}/*.c" "${MAIN_DIR}/*.cpp") # Main sources +file(GLOB_RECURSE LVGL_SRCS "${LVGL_DIR}/src/*.c") # LVGL sources +file(GLOB_RECURSE LV_DRIVER_SRCS "${LV_DRIVERS_DIR}/*.c") # lv_drivers sources +file(GLOB_RECURSE ESP_BROOKESIA_SRCS "${ESP_BROOKESIA_DIR}/*.c" "${ESP_BROOKESIA_DIR}/*.cpp") + # ESP-Brookesia sources +file(GLOB_RECURSE ESP_BROOKESIA_APP_SRCS "${ESP_BROOKESIA_APP_DIR}/*.c" "${ESP_BROOKESIA_APP_DIR}/*.cpp") + # ESP-Brookesia apps sources +file(GLOB_RECURSE ESP_BROOKESIA_STYLESHEET_SRCS # ESP-Brookesia stylesheets sources + "${ESP_BROOKESIA_STYLESHEET_DIR}/*.c" + "${ESP_BROOKESIA_STYLESHEET_DIR}/*.cpp" +) +# Set definitions for sources +set_source_files_properties(${MAIN_SRCS} # Main definitions + PROPERTIES COMPILE_FLAGS "${SIMULATOR_DEF} ${DISP_DEF} ${LVGL_DEF} ${LV_DRIVERS_DEF} ${ESP_BROOKESIA_DEF}" +) +set_source_files_properties(${LVGL_SRCS} PROPERTIES COMPILE_FLAGS "${LVGL_DEF}") + # LVGL definitions +set_source_files_properties(${LV_DRIVER_SRCS} PROPERTIES COMPILE_FLAGS "${LV_DRIVERS_DEF} ${DISP_DEF}") + # lv_drivers definitions +set_source_files_properties(${ESP_BROOKESIA_SRCS} PROPERTIES COMPILE_FLAGS "${ESP_BROOKESIA_DEF}") + # ESP-Brookesia definitions +set_source_files_properties(${ESP_BROOKESIA_APP_SRCS} PROPERTIES COMPILE_FLAGS "${SIMULATOR_DEF} ${ESP_BROOKESIA_DEF}") + # ESP-Brookesia apps definitions +set_source_files_properties(${ESP_BROOKESIA_STYLESHEET_SRCS} # ESP-Brookesia stylesheets definitions + PROPERTIES COMPILE_FLAGS "${SIMULATOR_DEF} ${ESP_BROOKESIA_DEF}" +) +# Add C/CXX sources +add_executable(esp_brookesia_simulator_vscode + ${MAIN_SRCS} + ${LVGL_SRCS} + ${LV_DRIVER_SRCS} + ${ESP_BROOKESIA_SRCS} + ${ESP_BROOKESIA_APP_SRCS} + ${ESP_BROOKESIA_STYLESHEET_SRCS} +) + +# Link SDL2 library +find_package(SDL2 REQUIRED) +target_link_libraries(esp_brookesia_simulator_vscode SDL2main) +target_link_libraries(esp_brookesia_simulator_vscode SDL2) + +# Add target: clean_build (command: make clean_build) +add_custom_target(clean_build + COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR} +) +# Add target: run (command: make run) +add_custom_target (run + COMMAND ${EXECUTABLE_OUTPUT_PATH}/esp_brookesia_simulator_vscode +) diff --git a/Makefile b/Makefile deleted file mode 100644 index 7108ec9..0000000 --- a/Makefile +++ /dev/null @@ -1,144 +0,0 @@ -# -# Makefile -# WARNING: relies on invocation setting current working directory to Makefile location -# This is done in .vscode/task.json -# - -# Detect the operating system -UNAME_S := $(shell uname -s) - -# select underlaying LCGL display driver (SDL2 || X11) -# LV_DRIVER := X11 -LV_DRIVER := SDL2 - -PROJECT ?= esp-brookesia-simulator_vscode -C_SRC_EXT := c -CXX_SRC_EXT := cpp -C_OBJ_EXT := o -CXX_OBJ_EXT := opp -ifeq ($(UNAME_S), Darwin) # macOS - MAKEFLAGS := -j $(shell sysctl -n hw.ncpu) - CC := arch -x86_64 gcc - CXX := arch -x86_64 g++ -else ifeq ($(UNAME_S), Linux) # Linux - MAKEFLAGS := -j $(shell nproc) - CC := gcc - CXX := g++ -endif - -WORKING_DIR := ./build -BUILD_DIR := $(WORKING_DIR)/obj -BIN_DIR := $(WORKING_DIR)/bin - -MAIN_DIR := ./main -COMPONENTS_DIR := ./components -LVGL_DIR := ${COMPONENTS_DIR}/lvgl -LVGL_DRIVER_DIR := ${COMPONENTS_DIR}/lv_drivers -ESP_BROOKESIA_DIR := ${COMPONENTS_DIR}/esp-brookesia -ESP_BROOKESIA_STYLESHEET_DIR := ${COMPONENTS_DIR}/esp-brookesia-stylesheet -ESP_BROOKESIA_APP_DIR := ${COMPONENTS_DIR}/esp-brookesia-app - -SRC_INCLUDE_DIRS := ${MAIN_DIR} ${LVGL_DIR} ${LVGL_DRIVER_DIR} ${ESP_BROOKESIA_DIR}/src ${ESP_BROOKESIA_APP_DIR} -SRC_EXCLUDE_DIRS := ${LVGL_DIR}/tests ${LVGL_DIR}/demos ${LVGL_DIR}/examples ${LVGL_DIR}/env_support -INC_DIRS := ${SRC_INCLUDE_DIRS} ${COMPONENTS_DIR} - -ifeq ($(UNAME_S), Darwin) # macOS -C_WARNINGS := -Wall -Wextra \ - -Wshadow -Wundef -Wmissing-prototypes \ - -Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing \ - -Wno-error=cpp -Wuninitialized -Wno-unused-parameter -Wno-missing-field-initializers \ - -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default \ - -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic \ - -Wno-sign-compare -Wno-error=missing-prototypes -Wdeprecated \ - -Wempty-body -Wshift-negative-value \ - -Wtype-limits -Wsizeof-pointer-memaccess -Wpointer-arith -CXX_WARNINGS := -Wall -Wextra \ - -Wshadow -Wundef \ - -Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing \ - -Wno-error=cpp -Wuninitialized -Wno-unused-parameter -Wno-missing-field-initializers \ - -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default \ - -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic \ - -Wno-sign-compare -Wno-error=missing-prototypes -Wdeprecated \ - -Wempty-body -Wshift-negative-value \ - -Wtype-limits -Wsizeof-pointer-memaccess -Wpointer-arith -else ifeq ($(UNAME_S), Linux) # Linux -C_WARNINGS := -Wall -Wextra \ - -Wshadow -Wundef -Wmaybe-uninitialized -Wmissing-prototypes -Wno-discarded-qualifiers \ - -Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing \ - -Wno-error=cpp -Wuninitialized -Wno-unused-parameter -Wno-missing-field-initializers \ - -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default \ - -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic \ - -Wno-sign-compare -Wno-error=missing-prototypes -Wclobbered -Wdeprecated \ - -Wempty-body -Wshift-negative-value -Wstack-usage=2048 \ - -Wtype-limits -Wsizeof-pointer-memaccess -Wpointer-arith -CXX_WARNINGS := -Wall -Wextra \ - -Wshadow -Wundef -Wmaybe-uninitialized \ - -Wno-unused-function -Wno-error=strict-prototypes -Wpointer-arith -fno-strict-aliasing \ - -Wno-error=cpp -Wuninitialized -Wno-unused-parameter -Wno-missing-field-initializers \ - -Wno-format-nonliteral -Wno-cast-qual -Wunreachable-code -Wno-switch-default \ - -Wreturn-type -Wmultichar -Wformat-security -Wno-ignored-qualifiers -Wno-error=pedantic \ - -Wno-sign-compare -Wno-error=missing-prototypes -Wclobbered -Wdeprecated \ - -Wempty-body -Wshift-negative-value -Wstack-usage=2048 \ - -Wtype-limits -Wsizeof-pointer-memaccess -Wpointer-arith -endif - -CFLAGS := -O0 -g -std=c11 $(C_WARNINGS) -CXX_FLAGS := -O0 -g -std=c++14 $(CXX_WARNINGS) - -# simulator library define -ifeq "$(LV_DRIVER)" "SDL2" -LV_DRIVER_USE := USE_SDL -else -LV_DRIVER_USE := USE_$(LV_DRIVER) -endif - -# Add simulator defines to allow modification of source -DEFINES := -D SIMULATOR=1 -D LV_BUILD_TEST=0 -D $(LV_DRIVER_USE) -D ESP_BROOKESIA_KCONFIG_IGNORE - -# Include simulator inc folder first so lv_conf.h from custom UI can be used instead -INC := $(patsubst %,-I%,$(INC_DIRS)) #-I/usr/include/freetype2 -L/usr/local/lib -LDLIBS := -l$(LV_DRIVER) -lpthread -lm #-lfreetype -lavformat -lavcodec -lavutil -lswscale -lm -lz -BIN := $(BIN_DIR)/${PROJECT} - -C_COMPILE = $(CC) $(CFLAGS) $(INC) $(DEFINES) -CXX_COMPILE = $(CXX) $(CXX_FLAGS) $(INC) $(DEFINES) - -# Automatically include all source files -SRCS := $(shell find $(SRC_INCLUDE_DIRS) -type f \( -name '*.${C_SRC_EXT}' -o -name '*.${CXX_SRC_EXT}' \) \ - $(foreach dir,$(SRC_EXCLUDE_DIRS),-not -path '$(dir)/*')) -OBJECTS := $(patsubst %.${C_SRC_EXT},$(BUILD_DIR)/%.${C_OBJ_EXT},$(filter %.${C_SRC_EXT},$(SRCS))) \ - $(patsubst %.${CXX_SRC_EXT},$(BUILD_DIR)/%.${CXX_OBJ_EXT},$(filter %.${CXX_SRC_EXT},$(SRCS))) - -EXTRA_FILES := Makefile $(shell find $(INC_DIRS) -type f \( -name "*.h" -o -name "*.hpp" \)) - -$(BUILD_DIR)/%.${C_OBJ_EXT}: %.${C_SRC_EXT} ${EXTRA_FILES} - @echo 'Building project file: $<' - @mkdir -p $(dir $@) - @$(C_COMPILE) -c -o $@ $< - -$(BUILD_DIR)/%.${CXX_OBJ_EXT}: %.${CXX_SRC_EXT} ${EXTRA_FILES} - @echo 'Building project file: $<' - @mkdir -p $(dir $@) - @$(CXX_COMPILE) -c -o $@ $< - -$(BUILD_DIR)/%.${C_OBJ_EXT}: ${ESP_BROOKESIA_DIR}/%.${C_SRC_EXT} ${EXTRA_FILES} - @echo 'Building esp-brookesia file: $<' - @mkdir -p $(dir $@) - @$(C_COMPILE) -c -o $@ $< - -$(BUILD_DIR)/%.${CXX_OBJ_EXT}: ${ESP_BROOKESIA_DIR}/%.${CXX_SRC_EXT} ${EXTRA_FILES} - @echo 'Building esp-brookesia file: $<' - @mkdir -p $(dir $@) - @$(CXX_COMPILE) -c -o $@ $< - -$(BIN): $(OBJECTS) - @echo 'Linking bin: $@' - @mkdir -p $(BIN_DIR) - @$(CXX) -o $@ $^ $(LD_FLAGS) ${LDLIBS} - -clean: - rm -rf $(WORKING_DIR) - -install: ${BIN} - install -d ${DESTDIR}/usr/lib/${PROJECT}/bin - install $< ${DESTDIR}/usr/lib/${PROJECT}/bin/ diff --git a/README.md b/README.md index 1c9257d..8767b46 100644 --- a/README.md +++ b/README.md @@ -1,44 +1,49 @@ -# ESP-Brookesia PC Simulator with VSCode +# ESP-Brookesia PC VSCode Simulator * [中文版本](./README_CN.md) -esp-brookesia-simulator_vscode is a [VSCode](https://code.visualstudio.com) project that enables running [LVGL](https://github.com/lvgl/lvgl) and [ESP-Brookesia](https://github.com/espressif/esp-brookesia) on a PC. It is used to simulate the esp-brookesia system UI, making it convenient for users to debug stylesheets and apps. +## Table of Contents -esp-brookesia-simulator_vscode is a port and modification based on [lv_port_pc_vscode](https://github.com/lvgl/lv_port_pc_vscode), designed to support the compilation of C++ files. +- [ESP-Brookesia PC VSCode Simulator](#esp-brookesia-pc-vscode-simulator) + - [Table of Contents](#table-of-contents) + - [Overview](#overview) + - [Installing Dependencies](#installing-dependencies) + - [Windows](#windows) + - [Linux](#linux) + - [Usage](#usage) -> [!WARNING] -> * esp-brookesia-simulator_vscode has been tested only on `Linux`, `MacOS` and `Windows WSL`. +## Overview -## Dependencies +The `esp-brookesia-simulator_vscode` is a VSCode project that can run [LVGL](https://github.com/lvgl/lvgl) and [ESP-Brookesia](https://github.com/espressif/esp-brookesia) on a PC, simulating the system UI of ESP-Brookesia, which facilitates users in debugging styles and apps. -### Build Tools +The `esp-brookesia-simulator_vscode` is a port and modification based on [lv_port_pc_vscode](https://github.com/lvgl/lv_port_pc_vscode) to support compiling C++ files. -On Linux, you can install `GCC`, `GDB`, `bear` and `make` via terminal: +> [!NOTE] +> It has been tested that `esp-brookesia-simulator_vscode` can run on `Linux`, `MacOS`, `Windows`, and `Windows WSL` platforms. -```bash -sudo apt-get update && sudo apt-get install -y gcc gdb bear make -``` +## Installing Dependencies -### Graphics Drivers +### Windows -This project supports using **SDL** or **X11** as the LVGL display driver for low-level graphics/mouse/keyboard support. This can be configured in the [Makefile](./Makefile). +It is recommended that users install `gcc`, `gdb`, `cmake`, `make`, and `sdl2` through [MSYS2](https://www.msys2.org/). Below are the installation steps for a 64-bit Windows system: -#### Install SDL +1. Download ([Official Link](https://www.msys2.org/) / [Mirror Link](https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/)) and install MSYS2. -On Linux, you can install `SDL` via terminal: +2. Open the `MSYS2 MINGW64` terminal and execute the following commands: ```bash -sudo apt-get update && sudo apt-get install -y build-essential libsdl2-dev +pacman -Syu +pacman -S --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-SDL2 mingw-w64-x86_64-cmake ``` -SDL can also be downloaded from https://www.libsdl.org/. +3. Add the path *C:\\\msys64\mingw64\bin* to the system environment variable `PATH` (where `` is the installation path of the software). -#### Install X11 +### Linux -On Linux, you can install `X11` via terminal: +Users can directly install `gcc`, `gdb`, `cmake`, `make`, and `sdl2` through the terminal: ```bash -sudo apt-get update && sudo apt-get install -y libx11-dev +sudo apt-get update && sudo apt-get install -y gcc gdb cmake make build-essential libsdl2-dev ``` ## Usage @@ -49,14 +54,26 @@ sudo apt-get update && sudo apt-get install -y libx11-dev git clone --recursive https://github.com/esp-arduino-libs/esp-brookesia-simulator_vscode ``` -2. Double-clicking the VSCode workspace file [esp-brookesia-simulator_vscode.code-workspace](./esp-brookesia-simulator_vscode.code-workspace) to open the project. +2. Double-click to open the VSCode workspace file *[simulator.code-workspace](./simulator.code-workspace)* to open the project. + +> [!WARNING] +> Please use the workspace file to open the project, as it contains all the configurations for compiling and debugging. Otherwise, you will not be able to compile and debug directly using the `F5` key. + +3. Press F5 to build and debug, at which point the system UI of ESP-Brookesia should appear in a new window. Meanwhile, users can access all debugging features of VSCode through GDB. + +4. Adjust project configuration -3. Press F5 to build and debug. The system UI of ESP-Brookesia should appear in a new window, and you can access all debugging features of VSCode through GDB. + - Modify the definition in the *[CMakeLists.txt](./CMakeLists.txt#L7)* file to adjust the display window resolution: + ```cmake + set(DISP_DEF "-DDISP_HOR_RES=1024 -DDISP_VER_RES=600") # Resolution of the display + ``` + - Adjust the LVGL configuration by modifying definitions in the *[components/lv_conf.h](./components/lv_conf.h)* file. + - Adjust the ESP-Brookesia configuration by modifying definitions in the *[components/esp_brookesia_conf.h](./components/esp_brookesia_conf.h)* file. > [!NOTE] -> * To allow temporary modifications between the simulator and device code, a global definition `SIMULATOR=1` has been added to the Makefile. -> * The project will by default compile the `.c` 和 `.cpp` files located in the [components/esp-brookesia-app](./components/esp-brookesia-app) directory and include this directory as a header file directory. Users can place their custom apps in this directory. -> * The project will by default compile the `.c` 和 `.cpp` files located in the [components/esp-brookesia-stylesheet](./components/esp-brookesia-stylesheet) directory and include this directory as a header file directory. Users can place their custom stylesheets in this directory. +> A global definition `SIMULATOR=1` has been added to *[CMakeLists.txt](./CMakeLists.txt)* for temporary modifications between the simulator and device code. -> [!WARNING] -> * Please use the workspace file [esp-brookesia-simulator_vscode.code-workspace](./esp-brookesia-simulator_vscode.code-workspace) to open the project, as it contains all the configurations for building and debugging. Otherwise, you won't be able to directly use the `F5` key to build and debug. +5. Add custom stylesheets and apps + + - By default, the project will compile `.c` and `.cpp` files under the *[components/esp-brookesia-app](./components/esp-brookesia-app)* directory and include this directory as a header file directory. Users can place custom apps in this directory. + - By default, the project will compile `.c` and `.cpp` files under the *[components/esp-brookesia-stylesheet](./components/esp-brookesia-stylesheet)* directory and include this directory as a header file directory. Users can place custom stylesheets in this directory. diff --git a/README_CN.md b/README_CN.md index 5d856d4..75f809a 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,44 +1,49 @@ -# ESP-Brookesia PC Simulator with VSCode +# ESP-Brookesia PC VSCode 模拟器 * [English Version](./README.md) -esp-brookesia-simulator_vscode 是一个能够在 PC 上运行 [LVGL](https://github.com/lvgl/lvgl) 和 [ESP-Brookesia](https://github.com/espressif/esp-brookesia) 的 [VSCode](https://code.visualstudio.com) 工程,用于模拟运行 ESP-Brookesia 的系统 UI,方便用户调试样式表以及 app。 +## 目录 -esp-brookesia-simulator_vscode 是参考 [lv_port_pc_vscode](https://github.com/lvgl/lv_port_pc_vscode) 进行的移植和修改,从而支持编译 C++ 文件。 +- [ESP-Brookesia PC VSCode 模拟器](#esp-brookesia-pc-vscode-模拟器) + - [目录](#目录) + - [概述](#概述) + - [安装依赖项](#安装依赖项) + - [Windows](#windows) + - [Linux](#linux) + - [使用方法](#使用方法) -> [!WARNING] -> * esp-brookesia-simulator_vscode 仅在 `Linux`、`MacOS` 和 `Windows WSL` 上进行了测试。 +## 概述 -## 依赖项 +esp-brookesia-simulator_vscode 是一个能够在 PC 上运行 [LVGL](https://github.com/lvgl/lvgl) 和 [ESP-Brookesia](https://github.com/espressif/esp-brookesia) 的 [VSCode](https://code.visualstudio.com) 工程,用于模拟运行 ESP-Brookesia 的系统 UI,方便用户调试样式表以及 app。 -### 编译和调试工具 +esp-brookesia-simulator_vscode 是参考 [lv_port_pc_vscode](https://github.com/lvgl/lv_port_pc_vscode) 进行的移植和修改,从而支持编译 C++ 文件。 -在 Linux 上,用户可以通过终端安装 `GCC`、`GDB`、`bear` 和 `make`: +> [!NOTE] +> 经测试,esp-brookesia-simulator_vscode 可以运行在 `Linux`、`MacOS`、`Windows` 和 `Windows WSL` 平台。 -```bash -sudo apt-get update && sudo apt-get install -y gcc gdb bear make -``` +## 安装依赖项 -### 图形驱动 +### Windows -该工程支持使用 **SDL** 或 **X11** 作为 LVGL 的显示驱动程序,用于底层图形/鼠标/键盘支持,可以在 Makefile 中修改定义。 +推荐用户通过 [MSYS2](https://www.msys2.org/) 安装 `MinGW` 的 `gcc`、`gdb`、`cmake` 、`make` 和 `sdl2`。下面以 64 位 Windows 系统为例,安装步骤如下: -#### 安装 SDL +1. 下载([官方链接](https://www.msys2.org/) / [镜像链接](https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/x86_64/))并安装 MSYS2。 -在 Linux 上,用户可以通过终端安装: +2. 打开 MSYS2 的 `MSYS2 MINGW64` 终端,执行以下命令: ```bash -sudo apt-get update && sudo apt-get install -y build-essential libsdl2-dev +pacman -Syu +pacman -S --needed mingw-w64-x86_64-toolchain mingw-w64-x86_64-SDL2 mingw-w64-x86_64-cmake ``` -用户可以从 https://www.libsdl.org/ 下载 SDL。 +3. 在系统环境变量 `PATH` 中添加路径 *C:\\\msys64\mingw64\bin* (其中,`` 是软件的安装路径)。 -#### 安装 X11 +### Linux -在 Linux 上,用户可以通过终端安装: +用户可以直接通过终端安装 `gcc`、`gdb`、`cmake`、`make` 和 `sdl2`: ```bash -sudo apt-get update && sudo apt-get install -y libx11-dev +sudo apt-get update && sudo apt-get install -y gcc gdb cmake make build-essential libsdl2-dev ``` ## 使用方法 @@ -49,14 +54,26 @@ sudo apt-get update && sudo apt-get install -y libx11-dev git clone --recursive https://github.com/esp-arduino-libs/esp-brookesia-simulator_vscode ``` -2. 双击打开 VSCode 工作区文件 [esp-brookesia-simulator_vscode.code-workspace](./esp-brookesia-simulator_vscode.code-workspace) 打开工程。 +2. 双击打开 VSCode 工作区文件 *[simulator.code-workspace](./simulator.code-workspace)* 打开工程。 + +> [!WARNING] +> 请使用工作区文件打开工程,因为它包含了所有编译和调试的配置。否则,你将无法直接使用 `F5` 键进行编译和调试。 3. 按 F5 构建和调试,此时 ESP-Brookesia 的系统 UI 应该会显示在一个新窗口中。同时,用户可以通过 GDB 访问 VSCode 的所有调试功能。 +4. (可选)调整工程的配置 + + - 通过修改 *[CMakeLists.txt](./CMakeLists.txt#L7)* 文件中如下的定义来调整显示窗口的分辨率: + ```cmake + set(DISP_DEF "-DDISP_HOR_RES=1024 -DDISP_VER_RES=600") # Resolution of the display + ``` + - 通过修改 *[components/lv_conf.h](./components/lv_conf.h)* 文件中的定义来调整 LVGL 的配置。 + - 通过修改 *[components/esp_brookesia_conf.h](./components/esp_brookesia_conf.h)* 文件中的定义来调整 ESP-Brookesia 的配置。 + > [!NOTE] -> * 为了在模拟器和设备代码之间进行临时修改,Makefile 中已添加了 `SIMULATOR=1` 全局定义。 -> * 工程默认会编译 [components/esp-brookesia-app](./components/esp-brookesia-app) 目录下的 `.c` 和 `.cpp` 文件,并包含此目录作为头文件目录,用户可以将自定义 apps 放置在此目录下。 -> * 工程默认会编译 [components/esp-brookesia-stylesheet](./components/esp-brookesia-stylesheet) 目录下的 `.c` 和 `.cpp` 文件,并包含此目录作为头文件目录,用户可以将自定义样式表放置在此目录下。 +> 为了在模拟器和设备代码之间进行临时修改,*[CMakeLists.txt](./CMakeLists.txt)* 中已添加了 `SIMULATOR=1` 全局定义。 -> [!WARNING] -> * 请使用工作区文件 [esp-brookesia-simulator_vscode.code-workspace](./esp-brookesia-simulator_vscode.code-workspace) 打开工程,因为它包含了所有编译和调试的配置。否则,你将无法直接使用 `F5` 键进行编译和调试。 +5. (可选)添加自定义样式表和 app + + - 工程默认会编译 *[components/esp-brookesia-app](./components/esp-brookesia-app)* 目录下的 `.c` 和 `.cpp` 文件,并包含此目录作为头文件目录,用户可以将自定义 apps 放置在此目录下。 + - 工程默认会编译 *[components/esp-brookesia-stylesheet](./components/esp-brookesia-stylesheet)* 目录下的 `.c` 和 `.cpp` 文件,并包含此目录作为头文件目录,用户可以将自定义样式表放置在此目录下。 diff --git a/components/esp-brookesia b/components/esp-brookesia index 2b0d70f..5a31a27 160000 --- a/components/esp-brookesia +++ b/components/esp-brookesia @@ -1 +1 @@ -Subproject commit 2b0d70ffe8692c3579e73d754f124154dfae5741 +Subproject commit 5a31a2757fc32e3088ec15ba69a667f84166381f diff --git a/components/lv_drv_conf.h b/components/lv_drv_conf.h index 6adbcb1..f7d1620 100644 --- a/components/lv_drv_conf.h +++ b/components/lv_drv_conf.h @@ -15,8 +15,12 @@ #include "lv_conf.h" +#ifndef DISP_HOR_RES #define DISP_HOR_RES (1024) +#endif +#ifndef DISP_VER_RES #define DISP_VER_RES (600) +#endif /********************* * DELAY INTERFACE diff --git a/esp-brookesia-simulator_vscode.code-workspace b/esp-brookesia-simulator_vscode.code-workspace deleted file mode 100644 index 95e089a..0000000 --- a/esp-brookesia-simulator_vscode.code-workspace +++ /dev/null @@ -1,105 +0,0 @@ -{ - // 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 - ], - "unwantedRecommendations": [ - ] - }, - // settings.json section - "settings": { - "files.trimTrailingWhitespace": true, - "files.insertFinalNewline": true, - "files.trimFinalNewlines": true, - "cmake.configureOnOpen": false, - "files.associations": { - "*.h": "c", - "*.hpp": "cpp", - "*.c": "c", - "*.cpp": "cpp", - "array": "cpp", - "string": "cpp", - "string_view": "cpp", - "unordered_map": "cpp", - "deque": "cpp", - "list": "cpp", - "unordered_set": "cpp", - "vector": "cpp", - "initializer_list": "cpp" - }, - }, - // tasks.json section - "tasks": { - "version": "2.0.0", - "tasks": [ - { - "type": "shell", - "label": "Build", - "linux": { - "command": "bear -- make", - }, - "osx": { - "command": "arch -x86_64 bear -- make", - }, - "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 - } - } - }, - ], - }, - // launch.json section - "launch": { - "version": "0.2.0", - "configurations": [ - { - "name": "g++ build and debug active file", - "type": "cppdbg", - "request": "launch", - "program": "${workspaceFolder}/build/bin/esp-brookesia-simulator_vscode", - "args": [], - "stopAtEntry": false, - "cwd": "${workspaceFolder}", - "environment": [], - "externalConsole": false, - "linux": { - "MIMode": "gdb", - }, - "osx": { - "MIMode": "lldb" - }, - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ], - "preLaunchTask": "Build" - } - ] - }, -} diff --git a/main/main.cpp b/main/main.cpp index 86d8296..ad8ec8e 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -15,13 +15,9 @@ #include "lv_drv_conf.h" #include "lvgl/lvgl.h" #include "lvgl/examples/lv_examples.h" -#if USE_SDL #define SDL_MAIN_HANDLED /*To fix SDL's "undefined reference to WinMain" issue*/ #include #include "lv_drivers/sdl/sdl.h" -#elif USE_X11 -#include "lv_drivers/x11/x11.h" -#endif #include #include "esp_brookesia.hpp" /* These are built-in app examples in `esp-brookesia` library */ @@ -66,7 +62,15 @@ static bool end_tick = false; /* flag to terminate thread */ /********************** * GLOBAL FUNCTIONS **********************/ - +void get_local_time(struct tm *timeinfo, time_t *rawtime) { +#ifdef _WIN32 + // For Windows systems + localtime_s(timeinfo, rawtime); +#else + // For POSIX systems + localtime_r(rawtime, timeinfo); +#endif +} /********************* * DEFINES *********************/ @@ -103,6 +107,8 @@ int main(int argc, char **argv) /* Initialize the HAL (display, input devices, tick) for LVGL */ hal_init(); + ESP_BROOKESIA_LOGI("Using display resolution: %dx%d", DISP_HOR_RES, DISP_VER_RES); + /* Create a phone object */ ESP_Brookesia_Phone *phone = new ESP_Brookesia_Phone(disp); ESP_BROOKESIA_CHECK_NULL_RETURN(phone, 1, "Create phone failed"); @@ -157,7 +163,7 @@ static void on_clock_update_timer_cb(struct _lv_timer_t *t) ESP_Brookesia_Phone *phone = (ESP_Brookesia_Phone *)t->user_data; time(&now); - localtime_r(&now, &timeinfo); + get_local_time(&timeinfo, &now); is_time_pm = (timeinfo.tm_hour >= 12); ESP_BROOKESIA_CHECK_FALSE_EXIT(phone->getHome().getStatusBar()->setClock(timeinfo.tm_hour, timeinfo.tm_min, is_time_pm), "Refresh status bar failed"); diff --git a/simulator.code-workspace b/simulator.code-workspace new file mode 100644 index 0000000..12147ed --- /dev/null +++ b/simulator.code-workspace @@ -0,0 +1,112 @@ +{ + // 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 + ], + "unwantedRecommendations": [ + ] + }, + // settings.json section + "settings": { + "files.trimTrailingWhitespace": true, + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "cmake.configureOnOpen": false, + "files.associations": { + "*.h": "c", + "*.hpp": "cpp", + "*.c": "c", + "*.cpp": "cpp", + "array": "cpp", + "string": "cpp", + "string_view": "cpp", + "unordered_map": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "initializer_list": "cpp" + }, + "C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json", + }, + // tasks.json section + "tasks": { + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "label": "Build", + "windows": { + "command": "cmake.exe -G 'MinGW Makefiles' -B ./build; mingw32-make.exe -C ./build", + }, + "linux": { + "command": "cmake -B ./build & make -C ./build", + }, + "osx": { + "command": "cmake -B ./build & arch -x86_64 make -C ./build", + }, + "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 + } + } + }, + ], + }, + // launch.json section + "launch": { + "version": "0.2.0", + "configurations": [ + { + "name": "Debug With GDB", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/bin/esp_brookesia_simulator_vscode", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "windows": { + "MIMode": "gdb" + }, + "linux": { + "MIMode": "gdb", + }, + "osx": { + "MIMode": "lldb" + }, + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ], + "preLaunchTask": "Build" + } + ] + }, +} From a6711803419e357a08afcbb05800a5bda8b5a73c Mon Sep 17 00:00:00 2001 From: Liu Zhongwei Date: Wed, 25 Sep 2024 20:28:18 +0800 Subject: [PATCH 3/3] feat(action): add build test action --- .github/workflows/build_test.yml | 39 ++++++++++++++++++++++++++++++++ .gitignore | 1 + README.md | 2 ++ README_CN.md | 2 ++ simulator.code-workspace | 4 ++-- 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build_test.yml diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml new file mode 100644 index 0000000..129adf7 --- /dev/null +++ b/.github/workflows/build_test.yml @@ -0,0 +1,39 @@ +name: Build Test Application + +on: + workflow_dispatch: + pull_request: + types: [opened, reopened, synchronize] + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-22.04 + name: Build Test Application + + container: + image: ubuntu:22.04 + options: --user root + + steps: + - name: Update apt and install Git 2.18+ + run: | + apt-get update && apt-get upgrade -y + apt-get install -y git + + - name: Checkout repository + uses: actions/checkout@v3 + with: + submodules: 'recursive' + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + run: | + apt-get install -y gcc gdb cmake make build-essential libsdl2-dev + + - name: Build Application + working-directory: ./ + run: | + cmake -B ./build && make -C ./build diff --git a/.gitignore b/.gitignore index e41365f..a8a7536 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Ignore all dot folders, with below exceptions .*/ +!.github # VSCode .vscode/ diff --git a/README.md b/README.md index 8767b46..cb8792a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # ESP-Brookesia PC VSCode Simulator +[![Build Test Application](https://github.com/esp-arduino-libs/esp-brookesia-simulator_vscode/actions/workflows/build_test.yml/badge.svg)](https://github.com/esp-arduino-libs/esp-brookesia-simulator_vscode/actions/workflows/build_test.yml) + * [中文版本](./README_CN.md) ## Table of Contents diff --git a/README_CN.md b/README_CN.md index 75f809a..db9e05f 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,5 +1,7 @@ # ESP-Brookesia PC VSCode 模拟器 +[![Build Test Application](https://github.com/esp-arduino-libs/esp-brookesia-simulator_vscode/actions/workflows/build_test.yml/badge.svg)](https://github.com/esp-arduino-libs/esp-brookesia-simulator_vscode/actions/workflows/build_test.yml) + * [English Version](./README.md) ## 目录 diff --git a/simulator.code-workspace b/simulator.code-workspace index 12147ed..14957e8 100644 --- a/simulator.code-workspace +++ b/simulator.code-workspace @@ -51,10 +51,10 @@ "command": "cmake.exe -G 'MinGW Makefiles' -B ./build; mingw32-make.exe -C ./build", }, "linux": { - "command": "cmake -B ./build & make -C ./build", + "command": "cmake -B ./build && make -C ./build", }, "osx": { - "command": "cmake -B ./build & arch -x86_64 make -C ./build", + "command": "cmake -B ./build && arch -x86_64 make -C ./build", }, "group": { "kind": "build",