Rdzleo c24a9bc162 feat: 集成 dzbj LVGL 显示模块 + 配网模式内存优化
阶段1: 将 dzbj 项目的 LVGL 8.3.11 LCD 显示集成到 AI小智 主项目,
开机显示 ScreenHome 界面,同时优化配网模式下的内存使用,
确保 WiFi+BLE+LVGL 三者共存运行。

## 新增功能

### dzbj 显示模块集成
- 新增 main/dzbj/ 目录,移植 LCD 驱动(ST77916 QSPI)、触摸驱动(CST816S)、
  LVGL 初始化和 SquareLine Studio UI 界面
- I2C 总线共享:dzbj 触摸控制器复用主项目的 I2C_NUM_1 总线
- GPIO 冲突解决:LED(GPIO21)、Touch1(GPIO1)、Touch4(GPIO7) 改为 NC,
  电池 ADC 从 GPIO6 改为 GPIO3
- 添加 LVGL、esp_lcd_st77916、esp_lcd_touch_cst816s 等组件依赖
- managed_components 纳入版本管理

### 配网模式轻量化启动
- BoxAudioCodec: 新增 output_only 模式,仅创建 I2S TX 通道(省 ~13KB DMA)
  跳过 ES7210 ADC 初始化(省 ~2-4KB)
- AudioCodec: 新增 StartOutputOnly() 方法,仅启用扬声器输出
- Application: 配网模式跳过 Opus 编码器、输入重采样器、协议初始化、
  天气位置检测等网络业务
- 板级构造函数: 配网模式跳过电池检测、IMU传感器、PowerSaveTimer

### WifiBoard 配网流程修复
- NeedsProvisioning() 静态方法: 读取 NVS force_ap 和 SSID 列表,
  用于提前判断配网模式
- force_ap 竞态修复: 构造函数不再清零 force_ap,改在 StartNetwork() 清零,
  确保 NeedsProvisioning() 能正确读到 force_ap=1
- Application 缓存 provisioning_mode_ 成员变量,避免重复读 NVS

### BLE 配网重启修复
- 配网成功后用 esp_timer 延迟重启替代 xTaskCreate,
  避免内存紧张时任务创建失败导致设备不重启
- 注释掉 WiFi 连接成功后的 MAC 地址发送步骤

### sdkconfig 内存优化
- BT_ALLOCATION_FROM_SPIRAM_FIRST=y (BLE 动态分配优先 PSRAM)
- SPIRAM_MALLOC_RESERVE_INTERNAL=32768
- NVS_ALLOCATE_CACHE_IN_SPIRAM=y
- WiFi 静态缓冲区数量优化 (RX=10, TX=8)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-27 17:07:51 +08:00

2.5 KiB

Messaging

Messaging (lv_msg) is a classic []publisher subscriber](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern) implementation for LVGL.

IDs

Both the publishers and the subscribers needs to know the message identifiers. In lv_msg these are simple uint32_t integers. For example:

#define MSG_DOOR_OPENED             1
#define MSG_DOOR_CLOSED             2
#define MSG_USER_NAME_CHANGED       100
#define MSG_USER_AVATAR_CHANGED     101

You can orgnaize the message IDs as you wish.

Both parties also need to know about the format of teh payload. E.g. in the above example MSG_DOOR_OPENED and MSG_DOOR_CLOSED has no payload but MSG_USER_NAME_CHANGED can have a const char * payload containing the user name, and MSG_USER_AVATAR_CHANGED a const void * image source with the new avatar image.

Send message

Messages can be sent with lv_msg_send(msg_id, payload). E.g.

lv_msg_send(MSG_USER_DOOR_OPENED, NULL);
lv_msg_send(MSG_USER_NAME_CHANGED, "John Smith");

Subscribe to a message

lv_msg_subscribe(msg_id, callback, user_data) can be used to subscribe to message.

The callback should look like this:


static void user_name_subscriber_cb(void * s, lv_msg_t * m)
{
    /*s: a subscriber obeject, can be used to unscubscribe*/
    /*m: a message object with the msg_id, payload, and user_data (set durung subscription)*/

    ...do something...
}

From lv_msg_t the followings can be used to get some data:

  • lv_msg_get_id(m)
  • lv_msg_get_payload(m)
  • lv_msg_get_user_data(m)

Subscribe with an lv_obj

It's quite typical that an LVGL widget is interested in some messages. To make it simpler lv_msg_subsribe_obj(msg_id, obj, user_data) can be used. If a new message is published with msg_id an LV_EVENT_MSG_RECEIVED event will be sent to the object.

For example:

lv_obj_add_event_cb(user_name_label, user_name_label_event_cb, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(MSG_USER_NAME_CHANGED, user_name_label, NULL);

...

void user_name_label_event_cb(lv_event_t * e)
{
    lv_obj_t * label = lv_event_get_target(e);
    lv_msg_t * m = lv_event_get_msg(e);
    lv_label_set_text(label, lv_msg_get_payload(m));
}

Unsubscribe

lv_msg_subscribe returns a pointer which can be used to unsubscribe:

void * s1;
s1 = lv_msg_subscribe(MSG_USER_DOOR_OPENED, some_callback, NULL);

...

lv_msg_unsubscribe(s1);

Example


.. include:: ../../examples/others/msg/index.rst

API


.. doxygenfile:: lv_msg.h
  :project: lvgl