diff --git a/docs/development/experience-notes.md b/docs/development/experience-notes.md index 77c1b6a..dea8942 100644 --- a/docs/development/experience-notes.md +++ b/docs/development/experience-notes.md @@ -52,3 +52,5 @@ stored entries. The index below lists each entry once it is added. - **Display Refresh and Deep-sleep on ESP32-C3 (No PSRAM)** (Shinku-Chen) — direct panel refresh of a single image rect, RTC-GPIO deep-sleep wakeup, and the LVGL object-type misuse crash signature. See [`../experiences/shinku-chen/display-refresh-and-deep-sleep.md`](../experiences/shinku-chen/display-refresh-and-deep-sleep.md). - **Network Audio Streaming and Memory Budgeting on AI Passport** (PhoenixZHC) — bounded HTTP audio streaming, ES8311/I2S ownership, and joint memory budgeting for decoding, JSON, DMA, and LVGL. See [`../experiences/phoenixzhc/network-audio-streaming-and-memory.md`](../experiences/phoenixzhc/network-audio-streaming-and-memory.md). - **SoftAP Provisioning and Resource Budgets on AI Passport** (PhoenixZHC) — DHCP state, captive-portal compatibility, bounded forms and uploads, and no-PSRAM resource planning. See [`../experiences/phoenixzhc/softap-provisioning-and-resource-budget.md`](../experiences/phoenixzhc/softap-provisioning-and-resource-budget.md). +- **Implementing the FAP_SCREENSHOT_V1 Serial Screenshot Protocol** (Y2Lin) — install the USB-serial-JTAG driver first, substring-match the command, snapshot into a statically reserved full-screen buffer, chunk payload writes to the tx ring buffer, and mute logs during the binary window. See [`../experiences/y2lin/serial-screenshot-protocol.md`](../experiences/y2lin/serial-screenshot-protocol.md). +- **Sound-Meter UI: Smoothing, Anchors, and Stray Blocks** (Y2Lin) — an asymmetric EMA for live readouts, creation-time anchors for mascot animations, the usual suspects behind stray screen blocks, and LVGL pool exhaustion as a white-screen cause. See [`../experiences/y2lin/meter-ui-smoothing-and-layout.md`](../experiences/y2lin/meter-ui-smoothing-and-layout.md). diff --git a/docs/development/experience-notes.zh_CN.md b/docs/development/experience-notes.zh_CN.md index c3eba0b..fde4800 100644 --- a/docs/development/experience-notes.zh_CN.md +++ b/docs/development/experience-notes.zh_CN.md @@ -40,3 +40,5 @@ fork 上自行创建或变更的 `docs/` 文档。每条经验一个 `.md` 及 - **ESP32-C3(无 PSRAM)上的显示刷新与深睡**(Shinku-Chen)— 直接刷新单个图片矩形、RTC GPIO 深睡唤醒,以及 LVGL 对象类型误用的崩溃特征。见 [`../experiences/shinku-chen/display-refresh-and-deep-sleep.zh_CN.md`](../experiences/shinku-chen/display-refresh-and-deep-sleep.zh_CN.md)。 - **AI Passport 网络音频流与内存预算经验**(PhoenixZHC)— 有边界的 HTTP 音频流、ES8311/I2S 资源归属,以及解码、JSON、DMA 与 LVGL 的统一内存预算。见 [`../experiences/phoenixzhc/network-audio-streaming-and-memory.zh_CN.md`](../experiences/phoenixzhc/network-audio-streaming-and-memory.zh_CN.md)。 - **AI Passport SoftAP 配网与资源预算经验**(PhoenixZHC)— DHCP 状态、弹窗认证兼容、表单与上传边界,以及无 PSRAM 条件下的资源规划。见 [`../experiences/phoenixzhc/softap-provisioning-and-resource-budget.zh_CN.md`](../experiences/phoenixzhc/softap-provisioning-and-resource-budget.zh_CN.md)。 +- **实现 FAP_SCREENSHOT_V1 串口截屏协议**(Y2Lin)— 先装 USB-Serial-JTAG 驱动、按子串匹配命令、快照渲染进静态整屏缓冲、按发送环形缓冲分块流载荷、二进制窗口内静默日志。见 [`../experiences/y2lin/serial-screenshot-protocol.zh_CN.md`](../experiences/y2lin/serial-screenshot-protocol.zh_CN.md)。 +- **音量计 UI:读数平滑、动画锚定与杂色块**(Y2Lin)— 非对称 EMA 平滑实时读数、吉祥物动画锚定到创建位置、屏上杂色块的常见根因,以及 LVGL 池耗尽导致开机白屏。见 [`../experiences/y2lin/meter-ui-smoothing-and-layout.zh_CN.md`](../experiences/y2lin/meter-ui-smoothing-and-layout.zh_CN.md)。 diff --git a/docs/experiences/INDEX.md b/docs/experiences/INDEX.md index 8f22951..6f6defa 100644 --- a/docs/experiences/INDEX.md +++ b/docs/experiences/INDEX.md @@ -30,3 +30,8 @@ rather than merged into an existing one. - [Network Audio Streaming and Memory Budgeting on AI Passport](phoenixzhc/network-audio-streaming-and-memory.md) — bounded HTTP audio streaming, ES8311/I2S ownership, and joint memory budgeting for decoding, JSON, DMA, and LVGL. - [SoftAP Provisioning and Resource Budgets on AI Passport](phoenixzhc/softap-provisioning-and-resource-budget.md) — DHCP state, captive-portal compatibility, bounded forms and uploads, and no-PSRAM resource planning. + +### Y2Lin + +- [Implementing the FAP_SCREENSHOT_V1 Serial Screenshot Protocol](y2lin/serial-screenshot-protocol.md) — install the USB-serial-JTAG driver first, substring-match the command, snapshot into a statically reserved full-screen buffer, chunk payload writes to the tx ring buffer, and mute logs during the binary window. +- [Sound-Meter UI: Smoothing, Anchors, and Stray Blocks](y2lin/meter-ui-smoothing-and-layout.md) — an asymmetric EMA for live readouts, creation-time anchors for mascot animations, the usual suspects behind stray screen blocks, and LVGL pool exhaustion as a white-screen cause. diff --git a/docs/experiences/INDEX.zh_CN.md b/docs/experiences/INDEX.zh_CN.md index 0041cbf..0436164 100644 --- a/docs/experiences/INDEX.zh_CN.md +++ b/docs/experiences/INDEX.zh_CN.md @@ -24,3 +24,8 @@ - [AI Passport 网络音频流与内存预算经验](phoenixzhc/network-audio-streaming-and-memory.zh_CN.md) — 有边界的 HTTP 音频流、ES8311/I2S 资源归属,以及解码、JSON、DMA 与 LVGL 的统一内存预算。 - [AI Passport SoftAP 配网与资源预算经验](phoenixzhc/softap-provisioning-and-resource-budget.zh_CN.md) — DHCP 状态、弹窗认证兼容、表单与上传边界,以及无 PSRAM 条件下的资源规划。 + +### Y2Lin + +- [实现 FAP_SCREENSHOT_V1 串口截屏协议](y2lin/serial-screenshot-protocol.zh_CN.md) — 先装 USB-Serial-JTAG 驱动、按子串匹配命令、快照渲染进静态整屏缓冲、按发送环形缓冲分块流载荷、二进制窗口内静默日志。 +- [音量计 UI:读数平滑、动画锚定与杂色块](y2lin/meter-ui-smoothing-and-layout.zh_CN.md) — 非对称 EMA 平滑实时读数、吉祥物动画锚定到创建位置、屏上杂色块的常见根因,以及 LVGL 池耗尽导致开机白屏。 diff --git a/docs/experiences/y2lin/meter-ui-smoothing-and-layout.md b/docs/experiences/y2lin/meter-ui-smoothing-and-layout.md new file mode 100644 index 0000000..5dd6b26 --- /dev/null +++ b/docs/experiences/y2lin/meter-ui-smoothing-and-layout.md @@ -0,0 +1,89 @@ +

+ 简体中文 · English +

+ +# Sound-Meter UI: Smoothing, Anchors, and Stray Blocks + +Captured after the **Sound Sentry** meter page went through a full UI review +and a community release (commits `8abb233` and `517c7c8` through `dec556e`). +These lessons apply to any AI Passport app that shows a continuously-updating +measurement or a mascot-style character. + +## Smooth a live readout with an asymmetric EMA + +A raw pseudo-SPL value sampled every 80 ms makes the on-screen number, bar, +and zone color jump constantly and read as noise. Smooth them in the model +layer with an asymmetric EMA — fast attack (~130 ms) so real increases show +immediately, slow release (~0.5 s) so the readout settles instead of twitching +down — implemented in Q8 fixed-point with first-frame passthrough. Keep raw +values wherever accuracy matters: peak/mean statistics and the alarm state +machine must not lag behind reality. Preserve the smoother across session +resets, or the readout flashes to zero on every OK-key reset. Attack, release, +and convergence behavior lives in the host-testable model — test it there, +not on device. + +## Give big numbers a fixed-width box + +A 28 pt reading left to its natural width collides with the dB unit and the +status badge the moment the value crosses 100 dB and gains a third digit. +Right-align the number inside a fixed-width box and align scale ticks to the +panel edge, so digit-count changes never move neighboring elements. + +## Anchor animations at creation, never at the current position + +The mascot bobbed and jumped higher until it eventually left the screen: the +bob/jump animations used the *current* y as their start position, so +rebuilding the animation while the mascot was mid-swing (volume hovering on a +zone boundary) shifted the whole swing window upward on every rebuild. Start +such animations from a base y captured at creation time; the swing window then +stays constant no matter how often it is rebuilt. + +## A stray block on screen has several usual suspects + +The same user-visible symptom — an unexpected colored block — had four +different root causes in this one page. Enumerate the suspects instead of +guessing: + +- **An orphaned shadow.** `ui_pixel_panel_create()` builds two sibling + objects, the ink drop shadow and the paper body; hiding only the body left + the shadow on screen forever. Popups must show and hide both as a pair — + `ui_pixel_panel_create_ex()` returns the shadow for exactly this. +- **A dark slot at low fill.** A dark slate bar track (0x2E3A44) reads as a + stray black block while the indicator is short; a light paper-gray track + (0xE2E2D6) keeps the slot visually part of the page. +- **Pure decoration.** A bottom grass strip read as an unexpected block until + removed; the same goes for any oversized decoration added for flavor. +- **An object covering another.** The mascot overlapped the stats panel and + visually buried a statistic value underneath it. + +## A white screen at boot can be LVGL pool exhaustion + +The meter page (about 90 objects, roughly 35 KB LVGL allocation peak) +exhausted the template's 24 KB built-in LVGL pool mid-build: +`lv_obj_create()` returned NULL, the following style call dereferenced it, +and with the backlight already on no frame ever rendered — a white screen, +not a crash report. Switch LVGL to the C-library allocator +(`CONFIG_LV_USE_CLIB_MALLOC=y`) to fold the static pool into the general +heap, and raise the stack of the tasks that build pages and run key +callbacks — the 3584-byte default starved both `app_main` and the esp_timer +task; 8192 is comfortable. Log post-build free heap when entering a page so +field diagnosis is possible. + +## Generalization for the next app + +- Smooth what humans read; keep raw values for everything machines decide. +- Fixed-width containers for any numeric label that can change digit count. +- One creation-time anchor per animated object; never rebase on the current + position. +- When a stray block appears, enumerate shadows, slots, decorations, and + overlaps before touching code. +- On a white screen, suspect a NULL-object crash with the backlight on before + suspecting the display driver; check the LVGL allocator budget. + +## Related documents + +- `docs/CHANGELOG.md` — the Unreleased entries for the meter UI and the + sound-meter application. +- `main/demo_sound_meter.c` and `main/sound_meter_model.c` — the page and + its host-testable model. +- `main/ui_pixel.c` — the panel/shadow pair helpers. diff --git a/docs/experiences/y2lin/meter-ui-smoothing-and-layout.zh_CN.md b/docs/experiences/y2lin/meter-ui-smoothing-and-layout.zh_CN.md new file mode 100644 index 0000000..5ac232a --- /dev/null +++ b/docs/experiences/y2lin/meter-ui-smoothing-and-layout.zh_CN.md @@ -0,0 +1,72 @@ +

+ 简体中文 · English +

+ +# 音量计 UI:读数平滑、动画锚定与杂色块 + +**音量小哨兵** 计量页经历完整 UI 评审并发布社区后沉淀(对应提交 `8abb233` +及 `517c7c8` 至 `dec556e`)。这些经验适用于任何显示持续刷新读数或吉祥物式 +角色的 AI Passport 应用。 + +## 用非对称 EMA 平滑实时读数 + +每 80 ms 采样一次的原始伪 SPL 值会让屏上的数字、进度条和分区色不停跳变, +读起来像噪声。在模型层用非对称 EMA 平滑——快攻(约 130 ms)让真实升高 +立刻可见,慢放(约 0.5 s)让读数回落后趋于稳定而不是抖下去——Q8 定点实现, +首帧直通。凡是精度要紧的地方保留原始值:峰值/均值统计和告警状态机绝不能 +滞后于现实。会话重置要保留平滑器,否则每次 OK 键重置读数都会闪一下零。 +攻击/释放/收敛行为放在可主机测试的模型里——在那里测,别上设备测。 + +## 大数字要给固定宽度的盒子 + +28 pt 的读数若按自然宽度排布,一旦数值过 100 dB 多出第三位数字,就会撞上 +dB 单位和状态徽章。把数字放进固定宽度盒子右对齐,刻度对齐面板边缘,位数 +变化就永远不会挤动相邻元素。 + +## 动画锚定在创建位置,绝不锚定在当前位置 + +吉祥物一路越跳越高、最后冲出屏幕:浮动/跳跃动画用*当前* y 作为起始位置, +于是音量悬在分区边界附近时(动画不断重建),每次重建都把整个摆动窗口整体 +上移。这类动画要从创建时记录的基础 y 出发;这样无论重建多频繁,摆动窗口 +都恒定不变。 + +## 屏上杂色块有多个惯犯 + +同一个用户可见症状——一块意料之外的颜色块——在这一页上先后有四种不同根因。 +逐一排查惯犯,不要猜: + +- **被遗落的阴影。** `ui_pixel_panel_create()` 会创建两个兄弟对象:墨色投影 + 和纸面本体;弹窗只隐藏本体,阴影就永远留在屏上。弹窗必须成对显隐—— + `ui_pixel_panel_create_ex()` 专门为此返回阴影。 +- **低填充时的深色槽位。** 深石板色的进度条槽(0x2E3A44)在指示条很短时 + 读起来就像一块游离的黑块;换成浅纸灰(0xE2E2D6)后,槽位在视觉上归回 + 页面。 +- **纯装饰。** 底部一条草地装饰在被移除前一直被当成意外色块;任何为了 + 氛围加的超尺寸装饰都同理。 +- **对象互相遮挡。** 吉祥物与统计面板重叠,把面板上一项统计值整个盖住。 + +## 开机白屏可能是 LVGL 池耗尽 + +计量页(约 90 个对象、LVGL 分配峰值约 35 KB)在构建到一半时耗尽了模板内置 +的 24 KB LVGL 池:`lv_obj_create()` 返回 NULL,紧随其后的样式调用解引用了它, +而背光已经点亮、一帧都没渲染出来——表现为白屏,而不是崩溃报告。把 LVGL +切到 C 库分配器(`CONFIG_LV_USE_CLIB_MALLOC=y`),把静态池并入通用堆;同时 +抬高构建页面和跑按键回调的任务栈——3584 字节默认值让 `app_main` 和 +esp_timer 任务双双吃紧,8192 很宽裕。进入页面时记录构建后空闲堆,让现场 +诊断成为可能。 + +## 对下一个应用的泛化 + +- 给人看的要平滑;给机器判定的一律用原始值。 +- 任何位数可能变化的数字标签都用固定宽度容器。 +- 每个动画对象一个创建时锚点;永远不要以当前位置为基准。 +- 出现杂色块时,先枚举阴影、槽位、装饰和遮挡,再动代码。 +- 白屏先怀疑“背光已亮的 NULL 对象崩溃”,再怀疑显示驱动;查 LVGL 分配器 + 预算。 + +## 相关文档 + +- `docs/CHANGELOG.zh_CN.md` — 计量页 UI 与噪音计应用的 Unreleased 条目。 +- `main/demo_sound_meter.c` 与 `main/sound_meter_model.c` — 页面及其可 + 主机测试的模型。 +- `main/ui_pixel.c` — 面板/阴影成对辅助函数。 diff --git a/docs/experiences/y2lin/serial-screenshot-protocol.md b/docs/experiences/y2lin/serial-screenshot-protocol.md new file mode 100644 index 0000000..c376492 --- /dev/null +++ b/docs/experiences/y2lin/serial-screenshot-protocol.md @@ -0,0 +1,114 @@ +

+ 简体中文 · English +

+ +# Implementing the FAP_SCREENSHOT_V1 Serial Screenshot Protocol + +Captured after publishing the **Sound Sentry** ambient sound meter to the AI +Passport community market. The publisher workflow requires a fresh device +screenshot captured over the `FAP_SCREENSHOT_V1` serial protocol, and this +entry records the pitfalls hit while implementing that protocol on ESP32-C3 +with LVGL 9.5 (commits `6acfd9d` through `cc1d72f`). + +The protocol itself is small: the host sends the ASCII line +`FAP_SCREENSHOT_V1\n` over USB-CDC, and the device replies with the header +`FAP_SCREENSHOT_V1 RGB565LE \n` followed by exactly +`` little-endian RGB565 pixels. Every trap below is in the device-side +plumbing, not in the protocol. + +## Install the USB-serial-JTAG driver before reading anything + +A single-app firmware that boots straight into its UI starts no REPL, and +console logging goes through the register-level VFS path, so nothing in the +system ever installs the USB-serial-JTAG driver. Calling +`usb_serial_jtag_read_bytes()` then dereferences a NULL driver object — on +this board it crashed in a loop, and because the backlight was already on, the +visible symptom was "the screen keeps flickering", not a serial error. Install +the driver explicitly (modest buffers suffice: 256-byte rx, 1024-byte tx), +call `usb_serial_jtag_vfs_use_driver()` to move the console onto the driver +path, and have the reader task poll `usb_serial_jtag_is_driver_installed()` +at a low frequency instead of assuming readiness. + +## Never busy-loop a serial reader task + +A persistent error return from `usb_serial_jtag_read_bytes()` spins a tight +read loop, starves the idle task, and trips the task watchdog — the device +reboots in a loop and again *looks* like a flickering screen. Back off (200 ms) +on errors, drop the task below the LVGL priority (LVGL runs at 4; a serial +helper at 3), and give every nothing-to-do path a `vTaskDelay()`. On this +board the flicker had two independent causes (the NULL driver and the +busy-loop); fix both classes, not just one. + +## Match the command as a substring, not a terminated line + +Windows terminal tools can swallow the trailing newline, so a strict +newline-terminated line match never fires and the device stays silent while +the host times out. Match a sliding window of the last command-length bytes +against the ASCII command, reset the window on any line terminator, and clear +it after a match so residual bytes cannot re-trigger the capture. + +## Render the snapshot into a statically reserved buffer + +Two LVGL 9.5 facts come first: the snapshot helpers stay disabled unless +`CONFIG_LV_USE_SNAPSHOT=y` is set (an implicit-declaration build error is the +first symptom), and `lv_snapshot_take()` returns an `lv_draw_buf_t*` — the +`lv_image_dsc_t*` pattern from older examples no longer compiles. + +The heap is the real trap. With roughly 220 KB free, the runtime heap still +could not produce one contiguous 153,600-byte block (240x320x2) once LVGL, +the codec stack, and DMA had been running; the dynamic allocation failed on +every request while the free-heap log looked healthy. Reserve the full-screen +RGB565 buffer at compile time (64-byte aligned), initialize it with +`lv_draw_buf_init()`, and render with `lv_snapshot_take_to_draw_buf()` — the +official external-buffer pattern that never touches the LVGL heap. Hold the +LVGL lock only for the render instant (`bsp_lvgl_lock()` / +`bsp_lvgl_unlock()`), so the UI keeps animating during the transfer, and give +the task stack headroom: full-screen software rendering was comfortable with +8192 bytes. + +## Stream the payload in chunks sized to the tx ring buffer + +`usb_serial_jtag_write_bytes()` bottoms out in `xRingbufferSend()`, which +rejects any item larger than the ring buffer capacity outright ("data will +never ever fit"). Submitting the 153,600-byte payload in a single call sends +nothing at all, and the host reports that the data ended before the declared +length. Stream the payload in 512-byte chunks (well under the 1024-byte tx +buffer), blocking per chunk with a generous timeout, and abandon the transfer +— but not the task — when a chunk fails because the host unplugged. + +## Mute logs during the binary window + +ESP-IDF log lines share the same USB-CDC stream as the reply, and the host +reads exactly the declared byte count, so a single interleaved log byte shifts +the whole image. Set `esp_log_level_set("*", ESP_LOG_NONE)` immediately before +the first header byte, restore the default level after the last pixel byte, +and keep any post-transfer logging strictly outside that window. + +## Keep the command read-only and fail silently + +The publisher's contract is observational: the command never reboots, flashes, +or changes settings. On any failure (lock timeout, snapshot mismatch, driver +gone), log the reason and send nothing — the host surfaces a clean timeout +error instead of a corrupted stream. Defensively verify that the snapshot is +a tight-packed full-screen RGB565 image before answering at all. + +## Generalization for the next app + +- Anything that reads the USB-serial console must first make sure the driver + is installed; booting without a REPL leaves that job to the app. +- Debug the pipe with a raw serial terminal (local echo on) before debugging + the protocol — it distinguishes "command never arrived" from "device did + not answer". +- Size serial payload writes to the tx ring buffer, not to the payload. +- Reserve full-screen frame buffers statically; runtime fragmentation makes + contiguous 150 KB allocations unreliable on a no-PSRAM part. +- Keep binary replies and log output mutually exclusive in time. +- Treat a flickering screen as a crash-loop symptom and read the serial log + before touching display code. + +## Related documents + +- `docs/development/publish-to-community.md` — the publishing workflow that needs this screenshot. +- `docs/experiences/shinku-chen/post-release-follow-up.md` — the release-side view of the same flow. +- `main/fap_screenshot.c` — the implementation the commits above landed. +- `docs/CHANGELOG.md` — the Unreleased entry describing the shipped protocol. diff --git a/docs/experiences/y2lin/serial-screenshot-protocol.zh_CN.md b/docs/experiences/y2lin/serial-screenshot-protocol.zh_CN.md new file mode 100644 index 0000000..f4d839c --- /dev/null +++ b/docs/experiences/y2lin/serial-screenshot-protocol.zh_CN.md @@ -0,0 +1,91 @@ +

+ 简体中文 · English +

+ +# 实现 FAP_SCREENSHOT_V1 串口截屏协议 + +把 **音量小哨兵** 环境噪音计发布到 AI Passport 社区市场后沉淀。publisher +工作流要求通过 `FAP_SCREENSHOT_V1` 串口协议现场截取设备屏幕,本条记录在 +ESP32-C3 + LVGL 9.5 上实现该协议踩过的坑(对应提交 `6acfd9d` 至 `cc1d72f`)。 + +协议本身很小:主机经 USB-CDC 发送 ASCII 行 `FAP_SCREENSHOT_V1\n`,设备回 +`FAP_SCREENSHOT_V1 <宽> <高> RGB565LE <字节数>\n` 头行,再紧跟恰好 +`<字节数>` 字节的小端 RGB565 像素。下面的坑全部出在设备侧管线,而不是协议。 + +## 读取任何数据前,先安装 USB-Serial-JTAG 驱动 + +直接进入应用界面的单应用固件不启动 REPL,控制台日志又走 VFS 寄存器直写 +通道,于是整个系统没有任何人安装过 USB-Serial-JTAG 驱动。此时调用 +`usb_serial_jtag_read_bytes()` 会解引用空的驱动对象——在本板上表现为反复 +崩溃重启;由于背光已经点亮,用户看到的是“屏幕一直闪”,而不是串口报错。要 +显式安装驱动(缓冲不必大:rx 256 字节、tx 1024 字节足够),调用 +`usb_serial_jtag_vfs_use_driver()` 把控制台 VFS 切到驱动通道,并让读取任务 +低频轮询 `usb_serial_jtag_is_driver_installed()`,而不是假设驱动就绪。 + +## 串口读取任务绝不能忙等空转 + +`usb_serial_jtag_read_bytes()` 持续返回错误时,紧凑的读循环会打满任务、 +饿死空闲任务并触发任务看门狗——设备反复重启,表现同样是“屏幕在闪”。读错误 +要退避(200 ms),任务优先级要压到 LVGL 之下(LVGL 为 4,串口辅助任务取 3), +每条“无事可做”的路径都要有 `vTaskDelay()`。本板的闪屏有两个独立成因(空 +驱动指针和忙等空转),两类都要修,不能只修一个。 + +## 按子串匹配命令,不要依赖换行终结 + +Windows 终端工具可能吞掉行尾换行,严格的换行终结行匹配永远不会命中,设备 +毫无反应、主机只能超时。改用“最近命令长度字节”的滑动窗口去匹配 ASCII 命令, +遇到任何行终结符就重置窗口,命中后清空窗口,避免残留字节连续误触发截屏。 + +## 快照渲染写入静态预留的缓冲 + +先说两个 LVGL 9.5 的事实:不设 `CONFIG_LV_USE_SNAPSHOT=y` 时快照辅助函数 +整体不可用(隐式声明编译错误是第一症状);`lv_snapshot_take()` 返回的是 +`lv_draw_buf_t*`,旧示例里的 `lv_image_dsc_t*` 写法已经编译不过。 + +真正的坑在堆上:运行时堆明明还有约 220 KB 空闲,却在 LVGL、codec 栈和 DMA +跑起来之后拿不出一块连续的 153,600 字节(240x320x2);动态分配每次都失败, +而空闲堆日志看起来完全健康。要在编译期静态预留整屏 RGB565 缓冲(64 字节 +对齐),用 `lv_draw_buf_init()` 初始化描述符,再用 +`lv_snapshot_take_to_draw_buf()` 渲染——这是官方的外部缓冲模式,完全不经过 +LVGL 堆。LVGL 锁只覆盖渲染瞬间(`bsp_lvgl_lock()` / `bsp_lvgl_unlock()`), +回传期间 UI 照常动画;任务栈要留余量:整屏软件渲染配 8192 字节很宽裕。 + +## 载荷按发送环形缓冲的容量分块流式发送 + +`usb_serial_jtag_write_bytes()` 底层落在 `xRingbufferSend()` 上,而它对超过 +环形缓冲容量的整块写入会立即失败("data will never ever fit")。把 153,600 +字节载荷一次性提交等于一个字节都发不出去,主机报“数据在声明长度之前就结束”。 +按 512 字节分块(远小于 1024 字节的 tx 缓冲)流式发送,每块带充足超时阻塞; +某块失败(主机拔线)就放弃本次传输,但任务继续存活等下一条命令。 + +## 二进制窗口期间静默一切日志 + +ESP-IDF 的日志行与应答共用同一条 USB-CDC 流,而主机按声明的字节数精确读取, +混入任何一个日志字节都会让整幅图像错位。在发出第一个头行字节之前 +`esp_log_level_set("*", ESP_LOG_NONE)`,在最后一个像素字节之后恢复默认级别, +传输完成后的日志严格留在这个窗口之外。 + +## 命令保持只读语义,失败就静默 + +publisher 的契约是纯观察:命令不重启、不刷机、不改设置。任何失败(锁超时、 +快照不符、驱动消失)都只记日志、不应答——主机会得到一个干净的超时错误,而 +不是一条被破坏的流。应答前还要防御性核对快照确实是紧排整屏 RGB565。 + +## 对下一个应用的泛化 + +- 任何要读 USB 串口控制台的代码,都要先确认驱动已安装;不启动 REPL 的固件 + 只能靠应用自己装。 +- 先用裸串口终端(开本地回显)调试管道,再调试协议——这能区分“命令没到” + 和“设备没答”。 +- 串口载荷写入尺寸要对着发送环形缓冲规划,而不是对着载荷本身。 +- 整屏帧缓冲静态预留;无 PSRAM 的芯片上,运行时碎片让 150 KB 连续分配 + 不可依赖。 +- 二进制应答与日志输出在时间上互斥。 +- 看到“屏幕在闪”先按崩溃循环处理、读串口日志,再考虑动显示代码。 + +## 相关文档 + +- `docs/development/publish-to-community.md` — 需要这张截图的发布工作流。 +- `docs/experiences/shinku-chen/post-release-follow-up.zh_CN.md` — 同一发布流程的收尾侧视角。 +- `main/fap_screenshot.c` — 上述提交落地的实现。 +- `docs/CHANGELOG.zh_CN.md` — 描述已交付协议的 Unreleased 条目。