Skip to content

fix(display): support the V2 board's CST3530 touch controller - #138

Merged
TheMaxMur merged 10 commits into
TheMaxMur:mainfrom
Babel36acl:cst3530-touch
Nov 4, 2026
Merged

TheMaxMur merged 10 commits into
TheMaxMur:mainfrom
Babel36acl:cst3530-touch

Conversation

@Babel36acl

Copy link
Copy Markdown
Contributor

display: support the V2 board's CST3530 touch controller

What happens

On a V2 Waveshare RP2350-Touch-LCD-2.8 the display flavor draws, shows the
first-run Set a PIN? prompt — and no tap ever registers. The key is not
degraded, it is unusable: on this flavor the panel is the user-presence gate,
so every FIDO operation waits on a touch that can never arrive.

Why

Waveshare shipped two revisions of the board and the difference is the touch
part (their product page lists it per revision):

revision touch IC 7-bit addr register addresses
V1 CST328 0x1A 2 bytes (0xD000 report)
V2 (2026-10-14) CST3530 0x58 4 bytes (0xD0070000 report)

firmware/src/display.rs talks to the CST328, so on a V2 board every transfer
NAKs and Touch::read returns None forever. The panel pins, the reset line
and the reset pulse are identical between revisions — only the controller is
different, and neither address can be probed for at runtime (the wrong one just
fails), so this has to be a compile-time choice.

What this does

  • rsk-ui::touch::parse_cst3530 — pure parser beside parse_cst328, under host
    tests: point count in [3]'s low nibble, x/y low bytes in [4]/[5], the
    strength, the two high nibbles packed into [7], finger event in [8]'s high
    nibble (a lift frame carries the last coordinate and must not count as a tap).
  • firmware/src/display.rs — read_report() per chip behind
    cfg(display_tp = …): the CST3530 reads nine bytes at 0xD0070000 and acks by
    writing the bare 0xD00002AB address; the CST328 path is unchanged, including
    its 0xD109 normal-mode write (not a CST3530 register, so it is CST328-only).
  • firmware/build.rs — DISPLAY_TP_CHIP=cst328|cst3530 (default cst328, also
    settable as display.tp_chip in a board file), refused loudly on any other
    value.
  • nix/firmware.nix — tpChip knob + a firmware-display-v2 package.
  • docs/guides/display.md — the revision table, the symptom, and how to pick.
  • docs/assurance-matrix.md + assurance/configurations.toml — regenerated with
    scripts/matrix_gate.py --write; the new column arrives as gap cells with a
    settling question (settled_by = "evidence": which check.sh rows have to run
    on this image, and whether any of them reaches a presence gesture at all — a
    suite that presses BOOTSEL proves nothing when presence is a panel read). I
    deliberately did not invent an equivalent disposition: the closure is
    firmware-display's, not the default build's, and the gate refuses that basis.

Testing

Rebuilt from source on x86_64 Linux with rustup (thumbv8m.main-none-eabihf),
arm-none-eabi-gcc 12.2.1, flip-link, and picotool 2.3.1 built from source:

  • cargo test -p rsk-ui — green, including five new CST3530 parser cases.
  • LED_KIND=none FLASH_SIZE=16M DISPLAY_TP_CHIP=cst3530 cargo build --release -p firmware --features display
    — builds; the build script's cfg log confirms display_tp="cst3530".
  • scripts/pt.sh fences the store (0x00e7f000..0x00fff000, NSBOOT denied) and
    picotool uf2 convert produces a 2.4 MB UF2.
  • The default (CST328) display build and the non-display build both still build.

One warning shows up on both configurations and is not from this change: the
linker prints address (0x1000013c) of section .text is not a multiple of alignment (8) — identical address on the untouched CST328 build, so it belongs
to the toolchain/linker-script pair rather than to the touch driver. The
rsk-rsa "incorrect section attributes" assembler warnings are likewise from the
distro arm-none-eabi-gcc instead of the pinned gcc-arm-embedded.

Hardware: verified on a V2 board (16 MB flash). DISPLAY_TP_CHIP=cst3530
image flashed over BOOTSEL; the panel's touch responds and the on-screen flow is
usable, where the same image with the CST328 driver drew the screen and ignored
every tap. No change was needed to the report layout or the axis mapping.

@Babel36acl

Copy link
Copy Markdown
Contributor Author

Filed #139 for the hardware-revision side of this (symptom + how to tell V1 from V2 + what I'm asking about flavor policy), so the design discussion stays here and the tracker has an entry other V2 owners can find.

@Babel36acl

Copy link
Copy Markdown
Contributor Author

CI note, so the red does not get read as this patch's doing: 39 of 40 checks pass, including all fourteen flavors — display and board-waveshare-touch-lcd among them — and the sole failure is the check job's cargo-audit (SCA) row.

Two vulnerabilities landed in the advisory database on 2026-10-23, both already in Cargo.lock on main:

  • RUSTSEC-2026-0387 — crypto-bigint 0.7.5, timing variability (fix: >= 0.7.6)
  • RUSTSEC-2026-0385 — ctutils 0.4.2, non-constant-time mask generation (fix: >= 0.4.4)

This diff does not touch Cargo.lock or Cargo.toml, and main's last ci run was 2026-10-20 (green, run 39331018007) — i.e. the advisory drift predates this branch and would fail any run made after the 23rd. Nothing in the CST3530 change can reach it.

A lock-only fix exists and is small (cargo update -p crypto-bigint --precise 0.7.6 pulls ctutils to 0.4.7; scoped, no source change). I have not included it here — dependency moves are your trust base and this branch is one topic. Say the word and I will send it as its own PR so this one can go green on its own merits.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

Development firmware for this pull request: https://rskey.fob.wtf/preview?pr=138

The link always opens the latest successful preview build.

@TheMaxMur

Copy link
Copy Markdown
Owner

Please sign your commits

Comment thread firmware/src/main.rs Resolved
Waveshare shipped two revisions of the reference board and the difference is
the touch controller: V1 has a CST328 (7-bit 0x1A, two-byte register
addresses, the report block at 0xD000), the V2 of 2026-10-14 a CST3530
(7-bit 0x58, four-byte register addresses, the report block at 0xD0070000).

The display flavor hard-codes the CST328, so on a V2 board every read NAKs and
`Touch::read` answers "no finger" forever: the panel draws, the first-run
"Set a PIN?" prompt appears, and nothing on it responds — the key is unusable
rather than merely degraded, because on this flavor the panel IS the presence
gate. Neither address can be probed for at runtime (the wrong one simply
fails), so the choice is compile-time: `DISPLAY_TP_CHIP=cst328|cst3530`,
defaulting to the V1 part, plus a `firmware-display-v2` package that sets it.

The bit-twiddling goes in `rsk-ui::touch::parse_cst3530` beside the CST328
parser, under host tests, for the same reason that one lives there: a wrong
reconstruction maps a tap to the wrong button. The CST3530 reports nine bytes
— point count in `[3]`'s low nibble, then x/y low bytes, strength, the two
high nibbles packed into `[7]`, and the finger event in `[8]`'s high nibble —
and every read has to write the bare 0xD00002AB address to ack the frame. The
reset pulse and the panel pins are identical between revisions, so nothing
else changes: no mode write (0xD109 is not a CST3530 register), same I2C bus,
same axes.

Verified on the NAS with a rustup toolchain (thumbv8m.main-none-eabihf,
picotool 2.3.1 for the partition table and the UF2): `cargo test -p rsk-ui`
green including five new CST3530 parser cases, `DISPLAY_TP_CHIP=cst3530`
builds and produces a UF2 with the store fenced by scripts/pt.sh, the default
CST328 path still builds, and docs/assurance-matrix.md is regenerated (a new
`firmware-display-v2` column, its settling question recorded in
assurance/configurations.toml).
cargo fmt --all -- --check flagged the blocking_write_read call: one line over
the width. No behaviour change; check.sh's first row is fmt, so this is what
turned CI red before anything else could run.
`check` has been red on `main` since 2026-10-23, and that row is what holds
this PR at BLOCKED: cargo-audit reports RUSTSEC-2026-0387 (crypto-bigint
0.7.5, timing variability) and RUSTSEC-2026-0385 (ctutils 0.4.2,
non-constant-time mask generation).

0.7.6, 0.7.7 and 0.7.8 are yanked by the author, and cargo still warns when
one is pinned by --precise. 0.7.9 and 0.7.10 are the published releases the
registry will resolve normally, so the pin is 0.7.10; it requires
ctutils >= 0.4.6 and lands on 0.4.7.

Lock file only: no manifest bump, no source change, no new dependency. Host
tests 1304 passed / 0 failed; firmware builds for thumbv8m.main with
`--features display`. Squash it away and this branch is the touch driver
alone.
`ci`'s audit rows scan three lock files, not one. The root lock was handled
in 8cb5a9e; `tools/tui` still reported three vulnerabilities and
`tools/emu` two, all from the same pair:

  RUSTSEC-2026-0387  crypto-bigint 0.7.5  -> 0.7.10
  RUSTSEC-2026-0385  ctutils 0.4.2        -> 0.4.7

`tools/tui` also carried crypto-bigint 0.5.5, and the 0.5 line has no
release with the fix, so its dependent `p256` has to move: 0.13.2 -> 0.14.0.
That drops ecdsa 0.16, elliptic-curve 0.13, sec1 0.7 and signature 2, and
pulls pkcs8 0.11 / spki 0.8 in their place.

`device.rs` follows the 0.14 API the way `rsk-crypto` already does:
`Sec1Point` with `FromSec1Point`/`ToSec1Point`, the 65-byte `04 ‖ x ‖ y`
splice where `from_affine_coordinates` used to be, and a scalar drawn
through the existing rand_core 0.6 `OsRng` because 0.14's
`SecretKey::random` takes a 0.9 RNG. No algorithm change — `ecdh_pub`,
`ecdh_raw` and the KDF around them are untouched.

52 tui tests pass; fmt, `clippy -D warnings` and rustdoc are clean; all
three locks audit clean locally.
`cargo vet` keys an exemption by exact version, so once the audit fix moved
crypto-bigint to 0.7.10 and ctutils to 0.4.7 it reported both as unvetted
while the list still named 0.7.5 and 0.4.2.

Both stay exempted, not audited: this moves the version the existing entry
points at, which is how the other 241 entries here are written too.
`bcd-gate` is right, and this is a miss in the original patch: the CST3530
support does reach the image — a driver in `rsk-ui/src/touch.rs`, a build-time
`DISPLAY_TP_CHIP` switch in `firmware/build.rs`, and its arm in `display.rs` —
while `device_release` stayed at 0x09DB, last bumped by the PIV CCC change.

+1 hex, and the CHANGELOG entry says what moved and what did not: only the
`display` flavor gains a second controller. Every other flavor builds the same
image, but they all report the new counter because the constant is shared.
`citation-gate` caught what a `display`-flavor patch does to a tree that
cites line numbers: the bcdDevice comment pushed `main.rs` down three lines,
so `main.rs:1025`, `:963`, `:971`, `:803` and `:1170` each named the line
above the code they quote, and `display.rs:198` had already drifted to 247
when the CST3530 driver went in.

Only the anchors move; every cited page still describes the same code, so
the repair is the line number and then `--relock` for `formal/citations.lock`.
`citation-gate: ok — 1517 citations ... resolve`.
`assurance/configurations.toml` gained the CST3530 display preset in the touch
patch, so `matrix-gate` now derives

  40 P0-family properties × 32 build configurations = 1280 cells
  (37 covered, 143 equivalent, 0 conditional, 106 out-of-scope, 994 gap)

Ten bundle records still quoted the 31-configuration line — 1240 cells, 954
gap — and `bundle-gate` refuses a quoted count the gate no longer derives.
The three generated pages (`assurance-vector.md`, `platform-assumptions.md`,
the `release-manifest` region of `supply-chain.md`) are re-emitted from their
own `--write`, not hand-edited.
`firmware-display-v2` added a package column, so `matrix_gate.FLOOR_PACKAGES`
read 19 against a tree that derives 20. The floor is meant to be the count —
its own comment says a shrink is a deliberate edit in the same diff — and it
is now 20.

The bundle fixtures borrowed `31` off `31 build configurations` to construct a
claim the bare-integer rule would still accept. With the line carrying `32`,
`31` is a number the gate never writes, so the case reddened twice instead of
once: once for the noun it was aimed at, once for the digit. It borrows `32`
now, which is the same measurement against the current line.
Why a counter reached 0x09DC is a changelog entry; a growing list of bump
reasons beside the literal duplicates that changelog and will drift from
it. Removing the three lines shifts every later line of main.rs up by
three, so the citations past them are re-pointed and the lock re-taken.
@Babel36acl

Babel36acl commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Both points are addressed.

Signed commits. Every commit on the branch now carries an SSH signature from the key registered to my account, and GitHub reports verified: true / reason: valid on all ten. The nine unsigned commits had also been authored under a placeholder identity (lilith@local), which no signature could have tied to an account; fixing this required re-authoring them under my account as well as signing them. The rewrite did not change content: the tip’s tree hash is identical before and after (64ba933d), and the diff against main is the same size.

The 0x09DC comment block at firmware/src/main.rs:720 has been removed. You are right that it reads like changelog prose next to the literal, and this tree already indicates where that belongs—bcd_gate’s own failure message says to explain why in CHANGELOG.md, and the entry is there. Deleting the three lines shifts every later line of main.rs up by three, so the five citations after that point are re-pointed (806→803, 966→963, 974→971, 1028→1025, 1173→1170), and formal/citations.lock is re-locked (18 entries). docs/platform-assumptions.md was regenerated with platform_gate.py --write, not edited by hand.

Gates against the new tip: citation_gate (1,517 citations resolve), platform_gate, bundle_gate, token_refinement_gate, matrix_gate, and bcd_gate—all passing.

Two housekeeping notes. This push dismissed the earlier approval, so the review needs to be re-stamped; the runs it triggered remain in action_required until approved. The fork’s own CI did run: three jobs failed on network errors before reaching any check (failed to get semver / failed to get base64, curl failed [16] Error in the HTTP2 framing layer, and cache.nixos.org returning 416/200). I have re-run those jobs; nothing in the diff is implicated.

@TheMaxMur
TheMaxMur merged commit 6c026a8 into TheMaxMur:main Nov 4, 2026
40 checks passed
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.

2 participants