Skip to content

Fix rev C partial update framing and render count reset - #1149

Open
f4ww4z wants to merge 2 commits into
mathoudebine:mainfrom
f4ww4z:fix-rev-c-partial-update-framing
Open

f4ww4z wants to merge 2 commits into
mathoudebine:mainfrom
f4ww4z:fix-rev-c-partial-update-framing

Conversation

@f4ww4z

@f4ww4z f4ww4z commented Dec 2, 2026 •

Copy link
Copy Markdown

Summary

Fixes rev C partial updates (UPDATE_BITMAP) that leave the display stuck: after one bad update, the screen keeps showing the last good image and ignores every later partial update.

The display reads 249 data bytes from each 250-byte packet and treats the last byte as a separator. The ef69 terminator belongs to that data stream. _generate_update_image chunked only the pixel records (and only when they were longer than 250 bytes), then appended ef69 after chunking. For some payload lengths the terminator therefore landed on or across a separator slot:

  • raw lengths ≡ 248 or 0 (mod 249): 248, 249, 497, 498, 746, 747, …
  • raw length 250, because of the old > 250 threshold

When that happens, the QUERY_STATUS reply is swallowed, or the display answers needReSend:1|renderCnt:0 to every later update. needReSend:1 is sticky and only a full frame clears it. With themes that update often, this eventually happens in normal use, which matches reports of a frozen screen.

Changes

  • library/lcd/lcd_comm_rev_c.py
    • Chunk the records and the terminator together: b"\x00".join(chunked(raw + b"\xef\x69", 249)). This is the same framing _generate_full_image already uses.
    • Output is byte-identical to before for every length that worked; it changes only for the broken lengths.
    • Reset Count.Start to 0 after each full frame (the display restarts its expected count there), and increment it inside update_queue_mutex.
  • tests/library/lcd/test_lcd_comm_rev_c_update_framing.py (new, unittest)
    • Runs the real _generate_update_image over many raw lengths, including every bad residue up to about 2 KB and a ~227 KB update. It covers the 2.1", 5" and 8" sub-revisions against a model of the display's packet parsing.
    • Checks that the count restarts after a full frame.
    • The tests fail without the fix (23 failures) and pass with it.

Testing

On a device: Turing 2.1" rev C, ROM 89, Linux.

  • Before the fix:
    • Streaming partial updates froze the screen within seconds.
    • Status replies showed an empty reply or needReSend:1 exactly when the length residue hit 248 or 0.
  • After the fix:
    • 300 partial updates of varying sizes through DisplayPILImage (including the bad lengths, with a full frame in the middle) all returned needReSend:0.
    • main.py with theme 26 ran normally.
  • The 5" and 8" behaviour follows from the shared code path and is covered by the unit tests, but I could not test it on those devices.

Note on existing tests

tests/library/lcd/test_lcd_comm_rev_c.py already errors on main, because MockedLcdCommRevC doesn't set sub_revision or rom_version. I left that harness and its goldens untouched. Once someone repairs it, the rev_c_display_pil_image_patch_* goldens will change only if their payload length falls in one of the broken classes above. The new test file has a working harness that could be reused.

The root cause was found while experimenting with the protocol details discussed in #348; credit to @gwendal-h for first spotting the ef69/needReSend symptom there.

The display reads 249 data bytes from each 250-byte packet and treats the
last byte as a separator; the "ef69" terminator belongs to that data stream.
_generate_update_image chunked only the raw pixel records (and only when
longer than 250 bytes) and appended the terminator afterwards, so updates
whose length fell on certain residues (raw lengths 248/249 mod 249, and
248-250 unchunked) lost the terminator: the status reply was swallowed or
the display answered needReSend:1 to every later update.

Chunk the records and the terminator together. Also restart the render count
at 0 after every full frame (the display expects that) and keep the count
increment inside the update mutex.

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv
Run the real LcdCommRevC._generate_update_image over many raw lengths
(including those that used to break: 248, 249, 250, 497, 498, 1992 and
~227 KB), for 2.1", 5" and 8" sub-revisions, with a model of the display
packet parsing; check the render count restarts at 0 after a full frame.

Claude-Session: https://claude.ai/code/session_015HUJhXMdZg27SVrwtSV3Dv

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant