Skip to content

tdui: canvas pages, big characters, more cells with PSRAM - #16

Merged
schikani merged 1 commit into
mainfrom
tdui-cells
Nov 2, 2026
Merged

schikani merged 1 commit into
mainfrom
tdui-cells

Conversation

@schikani

@schikani schikani commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Python screens built from many put()/fill() calls cost Python time and
appeared piece by piece, because the desktop draws whatever has arrived every
10 ms. Measured on an ESP32-S3 with a full-screen 100x30 HMI (six screens):
a screen switch took 60–310 ms of Python time and 31–224 drawing requests,
while the serial link carried only 1–9 KB. The script was the bottleneck,
not the link or the desktop.

Changes

  • Canvas pages: w.canvas(..., pages=n) keeps up to 16 pictures
    (tdui.MAX_PAGES) on the desktop.
    • draw_to(n) draws into a page while the window shows another.
    • show(n) shows a page whole, in one step.
    • copy_page(src, dst) copies a picture.
    • resize() keeps every page.
    • Drawing into a hidden page doesn't redraw the window.
  • Big characters: canvas.big(x, y, text, fg, bg, scale, width) draws
    digits, A–Z and - + % / . : with half blocks, in one request (scale 1–4).
    width right-aligns the text and blanks the rest. tdui.big_size() gives
    the size.
  • Cheaper drawing calls: put() and fill() call _tdui.send directly,
    two Python calls fewer each.
  • More cells with PSRAM: tdui.MAX_CELLS counts every page. It's 32000 on
    boards with PSRAM and in the PC programs (192 KB at most, only while a
    script runs), and 2000 without PSRAM as before. tdui reads it from
    _tdui, and the error message gives the real number.
  • Protocol: new requests TD_PYUI_PAGE, TD_PYUI_PAGE_COPY and
    TD_PYUI_BIG, added after the existing ones, so existing scripts are
    unchanged.
  • Regenerated MicroPython: third_party/micropython is regenerated for
    the new tdui.py (MicroPython v1.29.0).

Result

With a page per screen and big(), the same HMI switches in 33–82 ms, and
each screen appears at once:

Page Before After
POWER 306 ms 68–82 ms
HOME 155 ms 45–50 ms
TEMPERATURE 109 ms 33–47 ms
STATUS 76 ms 40–63 ms

Testing

  • PC build: all 13 tests pass, including the new tests/test_pyui.c
    (pages, copy, resize, big characters, the page and cell limits).
  • Firmware builds: ESP32-S3, ESP32-C6 and classic ESP32 all build.
  • On an ESP32-S3:
    • the HMI benchmark above;
    • its keypad drawn on a copy of the screen;
    • the documentation's example.

Docs: tinydesk-project.github.io, branch tdui-cells.

Python screens built from many put()/fill() calls cost Python time and
appeared piece by piece, since the desktop draws what has arrived every
10 ms. Measured on an ESP32-S3 with a full-screen 100x30 HMI: a screen
switch took 60-310 ms of Python time, with 31-224 drawing requests, while
the link carried only 1-9 KB.

- Canvas pages: w.canvas(..., pages=n) keeps up to 16 pictures
  (TD_PYUI_MAX_PAGES) on the desktop. draw_to(n) draws into a page while
  the window shows another, show(n) shows a page whole in one step,
  copy_page(src, dst) copies a picture; resize keeps every page. New
  requests TD_PYUI_PAGE and TD_PYUI_PAGE_COPY; drawing into a hidden page
  does not redraw the window.
- canvas.big(x, y, text, fg, bg, scale, width): big characters (digits,
  A-Z, - + % / . : and space; 3x5 pixels, two to a cell with the half
  blocks, scale 1-4) drawn by the desktop in one request (TD_PYUI_BIG);
  width right-aligns and blanks the rest. tdui.big_size() gives the size.
- put() and fill() call _tdui.send directly, two Python calls fewer each.
- tdui.MAX_CELLS, all canvases of a script with every page counted, is
  32000 on boards with PSRAM and on the PC (192 KB at most, while a
  script runs), 2000 without PSRAM as before; tdui reads it from _tdui,
  and the error message gives the real number.

With a page per screen and big(), the same HMI switches in 33-82 ms and
each screen appears at once. Existing scripts are unchanged. Tests:
test_pyui (pages, copy, resize, big characters, the page and cell
limits). third_party/micropython regenerated for the new tdui.py.
@schikani
schikani merged commit dcc2b43 into main Nov 2, 2026
14 checks passed
@schikani
schikani deleted the tdui-cells branch November 2, 2026 04:56
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