feat(display): 添加显示模块功能支持电池状态和模式切换

- 配置文件中启用USB CDC ACM类、UART相关配置和LVGL显示库
- 添加对bat_state_event、hid_led_event和mode_switch_event事件的订阅
- 实现UI模型结构体ui_main_model用于管理显示状态
- 添加refresh_ui函数用于刷新UI界面
- 集成电池电量显示、充电状态指示和模式切换状态更新

fix(ui): 重构主UI界面添加动态数据更新功能

- 重写ui_main.c实现完整的UI组件创建和刷新逻辑
- 添加状态栏芯片显示USB、BLE、NumLock、CapsLock状态
- 实现电池图标、电量百分比和充电状态的动态更新
- 添加日期时间显示区域和整体UI刷新功能
- 创建ui_main_model数据结构管理UI状态数据

chore(config): 更新项目配置启用串口和显示相关功能

- 启用串口和UART中断驱动配置
- 添加USB CDC ACM类和HID支持
- 增加LVGL工作队列栈大小到16KB
- 添加蒙特赛拉特32号字体支持
This commit is contained in:
2026-04-11 16:40:54 +08:00
parent 2f6126da96
commit c40fc709d5
4 changed files with 356 additions and 18 deletions

View File

@@ -13,6 +13,9 @@
#include <zephyr/drivers/led.h>
#include <zephyr/logging/log.h>
#include "bat_state_event.h"
#include "hid_led_event.h"
#include "mode_switch_event.h"
#include "ui/ui_main.h"
LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF);
@@ -26,6 +29,11 @@ static const struct device *const display_dev =
static const struct device *const backlight_dev =
DEVICE_DT_GET(DT_PARENT(DT_ALIAS(backlight)));
static const uint32_t backlight_idx = DT_NODE_CHILD_IDX(DT_ALIAS(backlight));
static struct ui_main_model ui_model = {
.theme_color = LV_COLOR_MAKE(0x4C, 0x9E, 0xF5),
.inactive_border_color = LV_COLOR_MAKE(0x3A, 0x44, 0x52),
.mode = MODE_SWITCH_BLE,
};
static bool initialized;
static bool running;
static bool lvgl_initialized;
@@ -82,7 +90,7 @@ static int module_start(void)
lvgl_initialized = true;
lvgl_lock();
ui_main_init();
ui_main_init(&ui_model, "WH Mini", "Hello World");
lvgl_unlock();
}
@@ -117,8 +125,45 @@ static void module_pause(void)
LOG_INF("LVGL display paused");
}
static void refresh_ui(void)
{
if (!lvgl_initialized) {
return;
}
lvgl_lock();
ui_main_refresh_all(&ui_model, "WH Mini", "Hello World");
lvgl_unlock();
}
static bool app_event_handler(const struct app_event_header *aeh)
{
if (is_bat_state_event(aeh)) {
const struct bat_state_event *event = cast_bat_state_event(aeh);
ui_model.battery_level = event->soc;
ui_model.charging = event->charging;
ui_model.full = event->full;
refresh_ui();
return false;
}
if (is_mode_switch_event(aeh)) {
const struct mode_switch_event *event = cast_mode_switch_event(aeh);
ui_model.mode = event->mode;
refresh_ui();
return false;
}
if (is_hid_led_event(aeh)) {
const struct hid_led_event *event = cast_hid_led_event(aeh);
ui_model.led_mask = event->led_bm;
refresh_ui();
return false;
}
if (is_module_state_event(aeh)) {
const struct module_state_event *event = cast_module_state_event(aeh);
int err;
@@ -172,6 +217,9 @@ static bool app_event_handler(const struct app_event_header *aeh)
}
APP_EVENT_LISTENER(MODULE, app_event_handler);
APP_EVENT_SUBSCRIBE(MODULE, bat_state_event);
APP_EVENT_SUBSCRIBE(MODULE, hid_led_event);
APP_EVENT_SUBSCRIBE(MODULE, module_state_event);
APP_EVENT_SUBSCRIBE(MODULE, mode_switch_event);
APP_EVENT_SUBSCRIBE_EARLY(MODULE, power_down_event);
APP_EVENT_SUBSCRIBE(MODULE, wake_up_event);