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

6.4 KiB

Input devices

An input device usually means:

  • Pointer-like input device like touchpad or mouse
  • Keypads like a normal keyboard or simple numeric keypad
  • Encoders with left/right turn and push options
  • External hardware buttons which are assigned to specific points on the screen

Pointers

Cursor

Pointer input devices (like a mouse) can have a cursor.

...
lv_indev_t * mouse_indev = lv_indev_drv_register(&indev_drv);

LV_IMG_DECLARE(mouse_cursor_icon);                          /*Declare the image source.*/
lv_obj_t * cursor_obj = lv_img_create(lv_scr_act());       /*Create an image object for the cursor */
lv_img_set_src(cursor_obj, &mouse_cursor_icon);             /*Set the image source*/
lv_indev_set_cursor(mouse_indev, cursor_obj);               /*Connect the image  object to the driver*/

Note that the cursor object should have lv_obj_clear_flag(cursor_obj, LV_OBJ_FLAG_CLICKABLE). For images, clicking is disabled by default.

Gestures

Pointer input devices can detect basic gestures. By default, most of the widgets send the gestures to its parent, so finally the gestures can be detected on the screen object in a form of an LV_EVENT_GESTURE event. For example:

void my_event(lv_event_t * e)
{
  lv_obj_t * screen = lv_event_get_current_target(e);
  lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_act());
  switch(dir) {
    case LV_DIR_LEFT:
      ...
      break;
    case LV_DIR_RIGHT:
      ...
      break;
    case LV_DIR_TOP:
      ...
      break;
    case LV_DIR_BOTTOM:
      ...
      break;
  }
}

...

lv_obj_add_event_cb(screen1, my_event, LV_EVENT_GESTURE, NULL);

To prevent passing the gesture event to the parent from an object use lv_obj_clear_flag(obj, LV_OBJ_FLAG_GESTURE_BUBBLE).

Note that, gestures are not triggered if an object is being scrolled.

If you did some action on a gesture you can call lv_indev_wait_release(lv_indev_get_act()) in the event handler to prevent LVGL sending further input device related events.

Keypad and encoder

You can fully control the user interface without a touchpad or mouse by using a keypad or encoder(s). It works similar to the TAB key on the PC to select an element in an application or a web page.

Groups

Objects you want to control with a keypad or encoder need to be added to a Group. In every group there is exactly one focused object which receives the pressed keys or the encoder actions. For example, if a Text area is focused and you press some letter on a keyboard, the keys will be sent and inserted into the text area. Similarly, if a Slider is focused and you press the left or right arrows, the slider's value will be changed.

You need to associate an input device with a group. An input device can send key events to only one group but a group can receive data from more than one input device.

To create a group use lv_group_t * g = lv_group_create() and to add an object to the group use lv_group_add_obj(g, obj).

To associate a group with an input device use lv_indev_set_group(indev, g), where indev is the return value of lv_indev_drv_register()

Keys

There are some predefined keys which have special meaning:

  • LV_KEY_NEXT Focus on the next object
  • LV_KEY_PREV Focus on the previous object
  • LV_KEY_ENTER Triggers LV_EVENT_PRESSED/CLICKED/LONG_PRESSED etc. events
  • LV_KEY_UP Increase value or move upwards
  • LV_KEY_DOWN Decrease value or move downwards
  • LV_KEY_RIGHT Increase value or move to the right
  • LV_KEY_LEFT Decrease value or move to the left
  • LV_KEY_ESC Close or exit (E.g. close a Drop down list)
  • LV_KEY_DEL Delete (E.g. a character on the right in a Text area)
  • LV_KEY_BACKSPACE Delete a character on the left (E.g. in a Text area)
  • LV_KEY_HOME Go to the beginning/top (E.g. in a Text area)
  • LV_KEY_END Go to the end (E.g. in a Text area)

The most important special keys are LV_KEY_NEXT/PREV, LV_KEY_ENTER and LV_KEY_UP/DOWN/LEFT/RIGHT. In your read_cb function, you should translate some of your keys to these special keys to support navigation in a group and interact with selected objects.

Usually, it's enough to use only LV_KEY_LEFT/RIGHT because most objects can be fully controlled with them.

With an encoder you should use only LV_KEY_LEFT, LV_KEY_RIGHT, and LV_KEY_ENTER.

Edit and navigate mode

Since a keypad has plenty of keys, it's easy to navigate between objects and edit them using the keypad. But encoders have a limited number of "keys" and hence it is difficult to navigate using the default options. Navigate and Edit modes are used to avoid this problem with encoders.

In Navigate mode, an encoder's LV_KEY_LEFT/RIGHT is translated to LV_KEY_NEXT/PREV. Therefore, the next or previous object will be selected by turning the encoder. Pressing LV_KEY_ENTER will change to Edit mode.

In Edit mode, LV_KEY_NEXT/PREV is usually used to modify an object. Depending on the object's type, a short or long press of LV_KEY_ENTER changes back to Navigate mode. Usually, an object which cannot be pressed (like a Slider) leaves Edit mode upon a short click. But with objects where a short click has meaning (e.g. Button), a long press is required.

Default group

Interactive widgets - such as buttons, checkboxes, sliders, etc. - can be automatically added to a default group. Just create a group with lv_group_t * g = lv_group_create(); and set the default group with lv_group_set_default(g);

Don't forget to assign one or more input devices to the default group with lv_indev_set_group(my_indev, g);.

Styling

If an object is focused either by clicking it via touchpad or focused via an encoder or keypad it goes to the LV_STATE_FOCUSED state. Hence, focused styles will be applied to it.

If an object switches to edit mode it enters the LV_STATE_FOCUSED | LV_STATE_EDITED states so these style properties will be shown.

For a more detailed description read the Style section.

API

Input device


.. doxygenfile:: lv_indev.h
  :project: lvgl

Groups


.. doxygenfile:: lv_group.h
  :project: lvgl