feat(app): 添加显示模块支持ST7789V显示屏

- 新增display_module.c实现LVGL显示功能,包括标签创建和定时刷新
- 在CMakeLists.txt中添加display_module.c到应用源文件列表
- 在app.overlay中配置显示设备选择和SPI接口使能
- 增加DISPLAY、MIPI_DBI、ST7789V、LVGL等相关配置选项
- 调整pm_static.yml中的应用分区大小以适应新的固件尺寸
- 禁用MCUBOOT和MCUMGR相关配置以节省空间
This commit is contained in:
2026-03-20 17:25:57 +08:00
parent 7e0f224ec8
commit 6ca70d2580
6 changed files with 163 additions and 19 deletions

View File

@@ -0,0 +1,122 @@
#include <stdio.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/display.h>
#include <zephyr/kernel.h>
#include <app_event_manager.h>
#include <lvgl.h>
#include <lvgl_zephyr.h>
#define MODULE display
#include <caf/events/module_state_event.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF);
#define DISPLAY_UPDATE_PERIOD_MS 10
struct display_ctx {
const struct device *dev;
struct k_work_delayable refresh_work;
lv_obj_t *hello_label;
lv_obj_t *count_label;
uint32_t tick_count;
bool initialized;
};
static struct display_ctx disp = {
.dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display)),
};
static void display_refresh_work_fn(struct k_work *work)
{
char count_str[12];
uint32_t wait_ms;
ARG_UNUSED(work);
if (!disp.initialized) {
return;
}
lvgl_lock();
if ((disp.tick_count % 100U) == 0U) {
snprintk(count_str, sizeof(count_str), "%u", disp.tick_count / 100U);
lv_label_set_text(disp.count_label, count_str);
}
wait_ms = lv_timer_handler();
lvgl_unlock();
disp.tick_count++;
k_work_reschedule(&disp.refresh_work,
K_MSEC(MAX(wait_ms, DISPLAY_UPDATE_PERIOD_MS)));
}
static int display_demo_init(void)
{
int err;
if (!device_is_ready(disp.dev)) {
LOG_ERR("Display device not ready");
return -ENODEV;
}
disp.tick_count = 0U;
k_work_init_delayable(&disp.refresh_work, display_refresh_work_fn);
lvgl_lock();
lv_obj_clean(lv_screen_active());
disp.hello_label = lv_label_create(lv_screen_active());
lv_label_set_text(disp.hello_label, "LVGL demo running");
lv_obj_align(disp.hello_label, LV_ALIGN_CENTER, 0, -12);
disp.count_label = lv_label_create(lv_screen_active());
lv_label_set_text(disp.count_label, "0");
lv_obj_align(disp.count_label, LV_ALIGN_BOTTOM_MID, 0, -12);
lv_timer_handler();
lvgl_unlock();
err = display_blanking_off(disp.dev);
if (err) {
LOG_ERR("Display blanking off failed: %d", err);
return err;
}
disp.initialized = true;
k_work_reschedule(&disp.refresh_work, K_MSEC(DISPLAY_UPDATE_PERIOD_MS));
LOG_INF("LVGL display demo initialized");
return 0;
}
static bool app_event_handler(const struct app_event_header *aeh)
{
if (is_module_state_event(aeh)) {
const struct module_state_event *event = cast_module_state_event(aeh);
if (check_state(event, MODULE_ID(main), MODULE_STATE_READY)) {
int err = display_demo_init();
if (err) {
module_set_state(MODULE_STATE_ERROR);
} else {
module_set_state(MODULE_STATE_READY);
}
}
return false;
}
__ASSERT_NO_MSG(false);
return false;
}
APP_EVENT_LISTENER(MODULE, app_event_handler);
APP_EVENT_SUBSCRIBE(MODULE, module_state_event);