Baji_Rtc_Toy/main/dzbj/dzbj_init.c
Rdzleo 31982ba7b9 feat(ui): Phase 10 - 数字人模式 LVGL → esp_emote_gfx 完整切换
 验证完成:
- 音频卡顿明显改善(用户实测)
- 数字人 hiyori 动画正常显示
- nm 验证:固件中 0 个 lv_*/lvgl_* 函数符号
- kapi.bin: 4.7MB → 2.75MB(-42%)

关键改动:
- main/dzbj/ai_chat_ui_eaf.c (404 行新增):
  完全替代 LVGL 版 ai_chat_ui.c,提供同名 C API(ai_chat_screen_init
  / set_status / set_emotion / set_chat_message / resume_animation)。
  AiChatDisplay C++ 桥接层无需改动。
  内部用 gfx_emote_init + gfx_disp_add + gfx_anim + mmap_assets。
- main/CMakeLists.txt:双轨编译
  CONFIG_BAJI_BADGE_MODE=y → ai_chat_ui.c (LVGL) + bg_gif_demo.c
  CONFIG_BAJI_BADGE_MODE=n → ai_chat_ui_eaf.c (esp_emote_gfx)
- main/dzbj/dzbj_init.c:EAF 模式跳过 lvgl_lcd_init() 调用
- main/dzbj/lcd.c/h:暴露 lcd_io_handle 给 EAF 注册 IO 完成回调

踩坑修复(commit message 留档供后续参考):
1. esp_mmap_assets v2.0.0 在 use_fs=true 模式下 mmap_assets_get_mem()
   返回的是文件内偏移量而非 RAM 指针(fseek bug + offset 没加
   data_section_start),导致 LoadProhibited panic。
   解决:完全绕过 mmap_assets,自己 fopen + 解析 MMAP bin 头
   (layout: 头 16B + 每 entry 28B + data 段每文件 2B magic + 数据)。
2. esp_emote_gfx 期望 esp_lcd_touch v2.x 新 API,项目用 v1.1.2 旧 API。
   在 managed_components 内 gfx_touch.c 加 shim 桥接(local patch,
   reconfigure 后需 reapply)。
3. EAF format magic 是 0x89 'EAF'(gfx_eaf_dec.h),不是 0x5A5A
   (那是 esp_mmap_assets 内部文件分隔符)。
4. SPIFFS 需要在 ai_chat_screen_init 入口自动挂载(不能依赖
   bg_gif_demo 的惰性挂载,那个已被 CONFIG 排除)。

依赖增量:
- espressif2022/esp_emote_gfx: ~3.0.5
- espressif/esp_mmap_assets: * (仅用于声明依赖,运行时被绕过)

数字人模式核心 UI 范围:
- 显示数字人动画  (hiyori_m06/m07, 居中循环)
- 情绪 → GIF 映射  (23 情绪 → 2 EAF,sad/angry 暂用 m07,m03 待补)
- 字幕/状态文字: stub (字体接驳留待后续,需打包 .bin 字体到资源)
- 触摸: 不支持(PoC 阶段不需要)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 15:53:21 +08:00

65 lines
1.9 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "sdkconfig.h"
#include "dzbj_init.h"
#include "dzbj_gpio.h"
#include "lcd.h"
#include "pages_pwm.h"
#ifdef CONFIG_BAJI_BADGE_MODE
#include "ui/ui.h"
#endif
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#define TAG "DZBJ"
// 仅硬件+LVGL 初始化(不加载 SquareLine UI不点亮背光
//
// Phase 10: 数字人 EAF 模式CONFIG_BAJI_BADGE_MODE=n下跳过 LVGL 初始化
// 让 esp_emote_gfx 接管 panel_handle避免双框架冲突
void dzbj_hw_display_init(i2c_master_bus_handle_t i2c_bus) {
ESP_LOGI(TAG, "开始初始化显示硬件...");
// 1. LCD 硬件初始化QSPI ST77916—— 共享
lcd_init();
ESP_LOGI(TAG, "LCD 硬件初始化完成");
#if DZBJ_ENABLE_TOUCH
// 2. 传入 I2C 总线句柄(与音频编解码器共享)
lcd_set_i2c_bus(i2c_bus);
// 3. 触摸控制器初始化CST816S
touch_init();
#else
(void)i2c_bus;
ESP_LOGI(TAG, "屏幕触摸已禁用 (DZBJ_ENABLE_TOUCH=0)");
#endif
#ifdef CONFIG_BAJI_BADGE_MODE
// 4. LVGL 初始化(仅吧唧模式)
lvgl_lcd_init();
ESP_LOGI(TAG, "LVGL 初始化完成");
#else
// Phase 10: 数字人 EAF 模式下不初始化 LVGL
// esp_emote_gfx 会在 ai_chat_screen_init 中接管 panel_handle
ESP_LOGI(TAG, "数字人 EAF 模式: 跳过 LVGL 初始化,等待 esp_emote_gfx 接管");
#endif
}
#ifdef CONFIG_BAJI_BADGE_MODE
// 完整初始化(硬件+LVGL + SquareLine UI + 背光)—— 仅吧唧模式
void dzbj_display_init(i2c_master_bus_handle_t i2c_bus) {
dzbj_hw_display_init(i2c_bus);
// SquareLine UI 初始化
ui_init();
ESP_LOGI(TAG, "UI 初始化完成");
// 等待首帧渲染完成
vTaskDelay(pdMS_TO_TICKS(100));
// 点亮背光
pwm_init();
ESP_LOGI(TAG, "背光已点亮dzbj 显示模块初始化完成");
}
#endif // CONFIG_BAJI_BADGE_MODE