The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
feat(harness-pro): a second board, and a face big enough to draw the desk
0xdiego253325ed828be8
diff --git a/cli/src/cable/cableHost.spec.ts b/cli/src/cable/cableHost.spec.tsindex a5f2d670e..4f5dd73e9 100644--- a/cli/src/cable/cableHost.spec.ts+++ b/cli/src/cable/cableHost.spec.ts@@ -48,7 +48,7 @@ const REMOTE: FleetMachine = { machineId: 'other', name: 'office-imac', state: '/** The window, open on one tab that holds these panes in this order. */function onTab(host: DaemonCableHost, agentIds: string[], id = 't1'): void {- host.setSwarms({ active: id, swarms: [{ id, name: 'Tab', agentIds, panes: agentIds.length }] })+ host.setSwarms({ active: id, swarms: [{ id, name: 'Tab', agentIds, panes: agentIds.length }], tiles: [] })host.setDesk(agentIds)}@@ -629,6 +629,7 @@ describe('DaemonCableHost.listSwarms', () => {{ id: 'shell', name: 'harness-2', agentIds: [], panes: 1 },{ id: 'fresh', name: 'New Harness', agentIds: [], panes: 0 },],+ tiles: [],})expect(host.listSwarms()).toEqual({selected: 'work',@@ -639,13 +640,14 @@ describe('DaemonCableHost.listSwarms', () => {// Nothing on it at all — still nothing the dial can offer, which was always the intent.{ id: 'fresh', name: 'New Harness', agents: 0, panes: 0 },],+ tiles: [],})})it('says nothing at all while no window is connected', () => {const host = new DaemonCableHost(wiring(), fleetOf([]))host.setSwarms(null)- expect(host.listSwarms()).toEqual({ selected: '', swarms: [] })+ expect(host.listSwarms()).toEqual({ selected: '', swarms: [], tiles: [] })})})diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.tsindex ddec36807..a3ee9ab92 100644--- a/cli/src/cable/cableSession.spec.ts+++ b/cli/src/cable/cableSession.spec.ts@@ -82,7 +82,7 @@ function makeHost(over: Partial<CableHost> = {}) {listMachines: async () => ({ machines: [LOCAL_ROW], source: 'backend' as const }),selectedMachine: () => 'mac-local',selectMachine: async () => ({ ok: true as const }),- listSwarms: () => ({ selected: '', swarms: [] }),+ listSwarms: () => ({ selected: '', swarms: [], tiles: [] }),listUnread: () => [],selectSwarm: vi.fn(),appName: () => 'harness',@@ -204,13 +204,13 @@ describe('cable session', () => {})it('names the swarms once and again only when they change, and relays a pick', async () => {- let swarms = { selected: 's1', swarms: [{ id: 's1', name: 'Workshop', agents: 2, panes: 2 }, { id: 's2', name: 'Launch', agents: 0, panes: 0 }] }+ let swarms = { selected: 's1', swarms: [{ id: 's1', name: 'Workshop', agents: 2, panes: 2 }, { id: 's2', name: 'Launch', agents: 0, panes: 0 }], tiles: [] }const host = makeHost({ listSwarms: () => swarms })const { session, port } = await connect(host)port.say({ t: 'hello', product: 'harness', mac: 'aa:bb' })await vi.waitFor(() => expect(port.types()).toContain('agents.end'))expect(port.sent.filter((m) => m.t === 'swarms')).toEqual([- { t: 'swarms', selected: 's1', items: [{ id: 's1', name: 'Workshop', agents: 2, panes: 2 }, { id: 's2', name: 'Launch', agents: 0, panes: 0 }] },+ { t: 'swarms', selected: 's1', items: [{ id: 's1', name: 'Workshop', agents: 2, panes: 2 }, { id: 's2', name: 'Launch', agents: 0, panes: 0 }], tiles: [] },])// Ticks with nothing new say nothing new — the same rule as the wheel.@@ -232,13 +232,13 @@ describe('cable session', () => {// The change this field exists for: a terminal opened on a tab that holds no agent moves the// TILE count and nothing else. A diff watching only `agents` swallowed that push and left the// dial showing a row it still believed was empty — the row it would then refuse to list.- let swarms = { selected: 's1', swarms: [{ id: 's1', name: 'Shell', agents: 0, panes: 0 }] }+ let swarms = { selected: 's1', swarms: [{ id: 's1', name: 'Shell', agents: 0, panes: 0 }], tiles: [] }const host = makeHost({ listSwarms: () => swarms })const { session, port } = await connect(host)port.say({ t: 'hello', product: 'harness', mac: 'aa:bb' })await vi.waitFor(() => expect(port.sent.filter((m) => m.t === 'swarms')).toHaveLength(1))- swarms = { selected: 's1', swarms: [{ id: 's1', name: 'Shell', agents: 0, panes: 1 }] }+ swarms = { selected: 's1', swarms: [{ id: 's1', name: 'Shell', agents: 0, panes: 1 }], tiles: [] }await vi.waitFor(() => expect(port.sent.filter((m) => m.t === 'swarms')).toHaveLength(2))expect(port.sent.filter((m) => m.t === 'swarms')[1]).toMatchObject({items: [{ id: 's1', agents: 0, panes: 1 }],diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.tsindex 165b325ed..3ef3f2f61 100644--- a/cli/src/cable/cableSession.ts+++ b/cli/src/cable/cableSession.ts@@ -177,10 +177,31 @@ export interface CableSwarm {panes: number}+/**+ * ONE TILE OF THE ACTIVE SWARM'S GRID, exactly where the window put it.+ *+ * Unit rectangle in THOUSANDTHS of the grid, so it crosses as integers and a device can scale it to+ * whatever face it has. `agentId` is empty for a tile the device cannot drive — a shell, a viewer —+ * which still holds its place, because a shape with a tile missing is not that shape.+ *+ * Relayed, never computed here. The window is the only side that knows whether this grid came from a+ * preset, from `auto` (whose column count it measures against its own width) or from a hand-dragged+ * resize, and the one rule `pane_preset.dart` asks of everybody is that the shape is described once.+ */+export interface CableTile {+ x1: number+ y1: number+ x2: number+ y2: number+ agentId: string+}+/** The window's swarms as it last described them, or null while no window is connected. */export interface AppSwarms {active: stringswarms: Array<{ id: string; name: string; agentIds: string[]; panes: number }>+ /** The ACTIVE swarm's grid. Empty from a window that predates the field, or one with no panes. */+ tiles: CableTile[]}/** Why the list is as short as it is. The dial renders this, instead of drawing an empty wheel. */@@ -216,7 +237,7 @@ export interface CableHost {*/selectMachine(machineId: string): Promise<{ ok: true } | { ok: false; code: string; message: string }>/** The window's swarms and which is on screen. Empty with no window: the dial then draws no swarm line. */- listSwarms(): { selected: string; swarms: CableSwarm[] }+ listSwarms(): { selected: string; swarms: CableSwarm[]; tiles: CableTile[] }/** The dial picked a swarm. Relayed to the window, which switches and re-describes its desk. */selectSwarm(swarmId: string): voidappName(): string@@ -288,7 +309,7 @@ export interface CableHost {* The image to offer a dial running `runningVersion`, or null for "nothing to do" — which covers a* dial that is current, a dev build that must not be touched, and an unreachable manifest.*/- firmwareFor?(runningVersion: string): Promise<{ version: string; image: Buffer; sha256: string } | null>+ firmwareFor?(runningVersion: string, hw?: string): Promise<{ version: string; image: Buffer; sha256: string } | null>/*** A dial greeted us, or the port went away.*@@ -352,6 +373,8 @@ export class CableSession {private decoder = new CableDecoder()private timer: NodeJS.Timeout | null = nullprivate greetedMac: string | null = null+ /** The board this device says it is (`hello.hw`). Decides which firmware it may be offered. */+ private greetedHw: string | undefinedprivate greetedFw: string | null = nullprivate lastRx = 0private stopped = false@@ -724,6 +747,7 @@ export class CableSession {// from the log on 2026-08-24.const fw = str('fw') ?? '?'const hw = str('hw')+ this.greetedHw = hw || undefinedif (mac !== this.greetedMac || fw !== this.greetedFw) {const returning = mac === this.greetedMacthis.greetedMac = mac@@ -962,7 +986,9 @@ export class CableSession {private async maybeOfferFirmware(runningVersion: string): Promise<void> {if (!this.host.firmwareFor || this.transfer || !runningVersion) return- const candidate = await this.host.firmwareFor(runningVersion).catch(() => null)+ // The BOARD goes with the version. Which manifest entry this device's image comes from is decided+ // from its own hello, never defaulted — see otaKeyForBoard.+ const candidate = await this.host.firmwareFor(runningVersion, this.greetedHw).catch(() => null)// Keyed by DIAL as well as version. Holding bare version strings made this a statement about the// image rather than about the board: offer 0.0.42 to one dial, swap in a second still on 0.0.41, and// the second was refused because that version had been offered — to someone else. It then sat on the@@ -1279,17 +1305,28 @@ export class CableSession {}private async syncSwarmsNow(force: boolean): Promise<void> {- const { selected, swarms } = this.host.listSwarms()+ const { selected, swarms, tiles } = this.host.listSwarms()// `panes` belongs in the key as much as `agents` does. Opening a terminal on a tab that holds no// agent moves only the tile count, and a key blind to it would swallow that push and leave the// dial showing a tab it still believes is empty — the very row this field exists to keep.- const key = `${selected}|${swarms.map((s) => `${s.id}:${s.name}:${s.agents}:${s.panes}`).join('|')}`+ // The active tab's SHAPE belongs in the key too, and it is the only part of this that can change+ // with no row changing at all: re-arranging four panes moves every tile and leaves the counts+ // exactly where they were, which a key blind to it would swallow — leaving the device drawing the+ // shape the tab used to have.+ const shape = tiles.map((t) => `${t.x1},${t.y1},${t.x2},${t.y2},${t.agentId}`).join(';')+ const key = `${selected}|${swarms.map((s) => `${s.id}:${s.name}:${s.agents}:${s.panes}`).join('|')}|${shape}`if (!force && key === this.lastSwarmsKey) returnthis.lastSwarmsKey = keythis.log(`cable: swarms → ${swarms.length}${selected ? ` (on ${selected})` : ''}${force ? ' [push]' : ''}`)// ONE frame, not a begin/row/end stream: two dozen rows of an id, a name and a count fit in a// kilobyte, and the dial replaces the whole list on arrival either way.- await this.send({ t: 'swarms', selected, items: swarms.map((s) => ({ id: s.id, name: s.name, agents: s.agents, panes: s.panes })) })+ await this.send({+ t: 'swarms', selected,+ items: swarms.map((s) => ({ id: s.id, name: s.name, agents: s.agents, panes: s.panes })),+ // Flat quads plus an id, rather than objects: this is read by a C parser on a device, and four+ // numbers in a row cost it nothing to walk.+ tiles: tiles.map((t) => ({ x1: t.x1, y1: t.y1, x2: t.x2, y2: t.y2, a: t.agentId })),+ })}// ── machines ──────────────────────────────────────────────────────────────────────────────────────diff --git a/cli/src/localWsServer.spec.ts b/cli/src/localWsServer.spec.tsindex 4dd4b6100..82f705f7a 100644--- a/cli/src/localWsServer.spec.ts+++ b/cli/src/localWsServer.spec.ts@@ -299,7 +299,10 @@ describe('local CLI WebSocket', () => {// No count at all, from a window too old to send one: as many tiles as agents, which is what// this row meant before the field existed.{ id: 's2', name: 'Launch', agentIds: [], panes: 0 },- ] }])+ // This window sent no `tiles`, which is how every window behaved until it had a device with a+ // face big enough to draw one. Empty is the honest reading, and the device falls back to+ // deriving the shape from the count exactly as it does today.+ ], tiles: [] }])// Like app_panes: a fact about this desk, so the machine never sees it.expect(backend.frames.map((frame) => frame.type)).toEqual([])diff --git a/cli/src/localWsServer.ts b/cli/src/localWsServer.tsindex 8acc9f4c4..a02261547 100644--- a/cli/src/localWsServer.ts+++ b/cli/src/localWsServer.ts@@ -206,7 +206,22 @@ function appSwarmsFrom(payload: unknown): AppSwarms | null {}if (swarms.length === 0) return nullconst active = typeof p.active === 'string' && swarms.some((s) => s.id === p.active) ? p.active : swarms[0].id- return { active, swarms }+ // Absent from a window that predates the field, and absent is the honest answer: the far side falls+ // back to deriving a shape from the count, which is what it did before any window sent one.+ const tiles: AppSwarms['tiles'] = []+ for (const row of Array.isArray(p.tiles) ? p.tiles : []) {+ if (!row || typeof row !== 'object') continue+ const t = row as Record<string, unknown>+ const n = (v: unknown): number | null =>+ typeof v === 'number' && Number.isFinite(v) ? Math.max(0, Math.min(1000, Math.round(v))) : null+ const x1 = n(t.x1), y1 = n(t.y1), x2 = n(t.x2), y2 = n(t.y2)+ // A tile with no area is not a tile. Dropping it here rather than on the device keeps the far+ // side's rule simple: every row it receives is drawable.+ if (x1 === null || y1 === null || x2 === null || y2 === null || x2 <= x1 || y2 <= y1) continue+ tiles.push({ x1, y1, x2, y2, agentId: typeof t.agentId === 'string' ? t.agentId : '' })+ if (tiles.length === 24) break // the window's own ceiling, same as the rows above+ }+ return { active, swarms, tiles }}function binaryBytes(raw: RawData): Uint8Array {diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex efd3c1ab6..65a396408 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -4,7 +4,7 @@ import 'dart:math' show Random;import 'package:dio/dio.dart';-import 'dart:ui' show Color;+import 'dart:ui' show Color, Rect; // Rect: activeTileShape, the same one pane_preset.dart returnsimport 'package:flutter/foundation.dart';import 'package:flutter/widgets.dart'@@ -2312,9 +2312,37 @@ class AppNotifier extends ChangeNotifier {for (final pane in panes)if (onDial(pane)) pane.agentId!,];+ // THE ACTIVE SWARM'S SHAPE, for a device with a face big enough to draw it.+ //+ // This used to say "names and member ids only — the layout inside a swarm is this window's+ // business", and for the round dial that was right: 466px of circle holds one tile, so there was no+ // shape to send. The square device draws the tab as a grid, and a grid that does not follow the+ // window is worse than no grid — it puts an agent somewhere it is not (owner, 2026-09-27: "change+ // layout trên app, dưới device ko thấy change theo").+ //+ // RECTANGLES, NOT A PRESET NAME. Sending `cols3` would make the far side re-derive the geometry+ // from it, which is the duplication `pane_preset.dart` exists to prevent — and it could not express+ // `auto` (whose column count this window MEASURES) or a manual resize at all. These are the very+ // rectangles this window laid out, in thousandths so they cross as integers.+ //+ // ONE ROW PER PANE, including the ones the device cannot drive: a shell or a viewer holds its place+ // in the grid, and dropping it would leave the shape with a hole in it. `agentId` is empty for+ // those, which is how the far side knows to draw it as a pane rather than as an agent.+ final shape = activeTileShape;+ final activeTiles = shape == null+ ? const <Map<String, Object>>[]+ : [+ for (var i = 0; i < shape.length && i < panes.length; i++)+ {+ 'x1': (shape[i].left * 1000).round(),+ 'y1': (shape[i].top * 1000).round(),+ 'x2': (shape[i].right * 1000).round(),+ 'y2': (shape[i].bottom * 1000).round(),+ 'agentId': panes[i].agentId ?? '',+ },+ ];// The swarms travel with the tiles: the dial names the one on screen above the agent and offers- // the others, and a pick there comes back as `dial_swarm`. Names and member ids only — the layout- // inside a swarm is this window's business.+ // the others, and a pick there comes back as `dial_swarm`.final swarmRows = [for (final swarm in swarms){@@ -2365,6 +2393,9 @@ class AppNotifier extends ChangeNotifier {.sendTerminalFrame('app_swarms', {'active': activeSwarmId,'swarms': swarmRows,+ // Only the active one's. It is the only grid the device draws, and sending every tab's+ // geometry would be two dozen shapes to carry one.+ 'tiles': activeTiles,}).catchError((_) => false),);@@ -9921,6 +9952,24 @@ class AppNotifier extends ChangeNotifier {/// Only `auto` needs telling: it measures the window, so it is the one shape/// whose columns are not in its own description. Reported by the grid as it/// builds; null until then, and then the shape's own guess stands.+ /// The rectangles the active swarm's tiles actually occupy, as fractions of+ /// the grid — a manual arrangement when there is one, the chosen preset+ /// otherwise, and null when neither can describe this many panes.+ ///+ /// Written once and read from every place that needs to know where a tile is:+ /// the two wrap helpers, the neighbour walk, and the cable. It used to be+ /// copied out at each of those, which is the bug `pane_preset.dart` opens by+ /// warning about — a shape described twice drifts, and the copy on the cable+ /// would have drifted onto another screen.+ List<Rect>? get activeTileShape {+ final count = panes.length;+ if (count < 1) return null;+ final shape = activeSwarm.arranged?.tiles.length == count+ ? activeSwarm.arranged!.tiles+ : presetFor(count)?.tilesFor(count, columns: gridColumns);+ return (shape != null && shape.length == count) ? shape : null;+ }+int? get gridColumns => activeSwarm.gridColumns;set gridColumns(int? value) => activeSwarm.gridColumns = value;@@ -9953,10 +10002,8 @@ class AppNotifier extends ChangeNotifier {int? _wrapVertically(int delta) {final count = panes.length;if (count < 2) return null;- final shape = activeSwarm.arranged?.tiles.length == count- ? activeSwarm.arranged!.tiles- : presetFor(count)?.tilesFor(count, columns: gridColumns);- if (shape == null || shape.length != count) return null;+ final shape = activeTileShape;+ if (shape == null) return null;final at = panes.indexWhere((pane) => pane.id == focusedPaneId);if (at < 0) return null;@@ -10046,10 +10093,8 @@ class AppNotifier extends ChangeNotifier {int? _neighbour({required int dx, required int dy}) {final count = panes.length;if (count < 2) return null;- final shape = activeSwarm.arranged?.tiles.length == count- ? activeSwarm.arranged!.tiles- : presetFor(count)?.tilesFor(count, columns: gridColumns);- if (shape == null || shape.length != count) return null;+ final shape = activeTileShape;+ if (shape == null) return null;final at = panes.indexWhere((pane) => pane.id == focusedPaneId);if (at < 0) return null;diff --git a/devices/harness-device/firmware/.gitignore b/devices/harness-device/firmware/.gitignoreindex a3951eb9e..9862aadc7 100644--- a/devices/harness-device/firmware/.gitignore+++ b/devices/harness-device/firmware/.gitignore@@ -1,5 +1,8 @@# ESP-IDF build output & downloaded components (regenerated by idf.py)+# build.<target>/ too: one project now builds for two boards, each into its own directory.build/+build.dial/+build.pro/managed_components/.cache/# dependencies.lock is TRACKED (2026-09-17): it is the exact component set the release was built and@@ -10,10 +13,19 @@ managed_components/# Generated config. sdkconfig.defaults is the tracked source of truth; CMakeLists.txt regenerates# sdkconfig whenever the defaults hash changes (see the comment there), leaving the old one as# sdkconfig.superseded.+# …and the per-target names the two-board split produced. sdkconfig.defaults + the per-target+# sdkconfig.defaults.esp32s3 / .esp32p4 stay TRACKED — they are the source of truth; everything+# generated from them does not.sdkconfigsdkconfig.oldsdkconfig.supersededsdkconfig.defaults.stamp+sdkconfig.dial+sdkconfig.pro+sdkconfig.dial.superseded+sdkconfig.pro.superseded+sdkconfig.dial.defaults.stamp+sdkconfig.pro.defaults.stampbuild-arm# Local pairing secrets (WiFi password / API key) — do not commit.diff --git a/devices/harness-device/firmware/CMakeLists.txt b/devices/harness-device/firmware/CMakeLists.txtindex de2dbcd96..a5371b7e2 100644--- a/devices/harness-device/firmware/CMakeLists.txt+++ b/devices/harness-device/firmware/CMakeLists.txt@@ -1,7 +1,18 @@-# Top-level ESP-IDF project file for the Interns commander device.+# Top-level ESP-IDF project file. ONE project, TWO boards.#-# Board: the Harness device (ESP32-S3R8, 466x466 round AMOLED, CO5300).-# Requires ESP-IDF >= 5.5. Build with: idf.py set-target esp32s3 && idf.py build+# dial ESP32-S3R8 · 466x466 round AMOLED (CO5300, QSPI) · CST9217 or CST816S touch+# pro ESP32-P4 · 720x720 square LCD (ST7703I, MIPI-DSI) · GT911 touch+#+# They share the cable protocol, the OTA path, the config store and the screens; they differ in the SoC,+# so the split is made at compile time by CONFIG_IDF_TARGET_* (main/board/board_pins.h) rather than by+# the runtime probe that tells the two DIALS apart (main/board/board.h).+#+# Requires ESP-IDF >= 5.5. Build either board through the Makefile at the repo root:+#+# make dial-build make dial-flash # -B build.dial -D SDKCONFIG=sdkconfig.dial+# make pro-build make pro-flash # -B build.pro -D SDKCONFIG=sdkconfig.pro+#+# A bare `idf.py build` here still means the dial, so older muscle memory keeps working.cmake_minimum_required(VERSION 3.16)# ── Keep sdkconfig honest about sdkconfig.defaults ───────────────────────────────────────────────────@@ -14,14 +25,32 @@ cmake_minimum_required(VERSION 3.16)# silently kept the old values. It surfaced as a broken build (a new font was referenced) and, worse, as# published firmware that overflowed the main stack mid-OTA and could never update itself.#-# So: stamp the hash of sdkconfig.defaults beside sdkconfig. When they disagree, delete sdkconfig and let-# IDF re-seed it. Day-to-day menuconfig still works; a pull that changes defaults re-applies automatically.+# So: stamp the hash of the defaults beside sdkconfig. When they disagree, delete sdkconfig and let IDF+# re-seed it. Day-to-day menuconfig still works; a pull that changes defaults re-applies automatically.# A deliberate local tweak belongs in sdkconfig.defaults, where it is reviewable and reaches everyone.-set(_sdkcfg "${CMAKE_CURRENT_LIST_DIR}/sdkconfig")-set(_defaults "${CMAKE_CURRENT_LIST_DIR}/sdkconfig.defaults")-set(_stamp "${CMAKE_CURRENT_LIST_DIR}/sdkconfig.defaults.stamp")-if(EXISTS "${_defaults}")- file(SHA256 "${_defaults}" _defaults_hash)+#+# TWO BOARDS, TWO SDKCONFIGS. Each build passes its own (`idf.py -D SDKCONFIG=sdkconfig.pro`), so the+# stamp has to follow that file rather than assume the default name — one shared stamp would have each+# board's build delete the other board's config, every time, for ever. And the hash covers EVERY defaults+# file, not just the one this target reads: the alternative is a build that quietly keeps a stale config+# because the change happened to land in the other target's file.+if(DEFINED SDKCONFIG)+ get_filename_component(_sdkcfg "${SDKCONFIG}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_LIST_DIR}")+else()+ set(_sdkcfg "${CMAKE_CURRENT_LIST_DIR}/sdkconfig")+endif()+set(_stamp "${_sdkcfg}.defaults.stamp")+file(GLOB _defaults "${CMAKE_CURRENT_LIST_DIR}/sdkconfig.defaults" "${CMAKE_CURRENT_LIST_DIR}/sdkconfig.defaults.*")+list(REMOVE_ITEM _defaults "${_stamp}")+list(FILTER _defaults EXCLUDE REGEX "\\.stamp$")+list(SORT _defaults)+if(_defaults)+ set(_defaults_hash "")+ foreach(_f IN LISTS _defaults)+ file(SHA256 "${_f}" _one)+ string(APPEND _defaults_hash "${_one}")+ endforeach()+ string(SHA256 _defaults_hash "${_defaults_hash}")set(_prev_hash "")if(EXISTS "${_stamp}")file(READ "${_stamp}" _prev_hash)@@ -29,11 +58,11 @@ if(EXISTS "${_defaults}")endif()if(EXISTS "${_sdkcfg}" AND NOT _prev_hash STREQUAL _defaults_hash)message(WARNING- "sdkconfig.defaults changed since this sdkconfig was generated -- regenerating it.\n"- "Any local `idf.py menuconfig` tweak not present in sdkconfig.defaults is being discarded; "- "put it in sdkconfig.defaults if it should survive.\n"- "Previous config saved as sdkconfig.superseded.")- file(RENAME "${_sdkcfg}" "${CMAKE_CURRENT_LIST_DIR}/sdkconfig.superseded")+ "sdkconfig.defaults changed since ${_sdkcfg} was generated -- regenerating it.\n"+ "Any local `idf.py menuconfig` tweak not present in a sdkconfig.defaults file is being "+ "discarded; put it there if it should survive.\n"+ "Previous config saved as ${_sdkcfg}.superseded.")+ file(RENAME "${_sdkcfg}" "${_sdkcfg}.superseded")endif()file(WRITE "${_stamp}" "${_defaults_hash}")endif()diff --git a/devices/harness-device/firmware/dependencies.lock b/devices/harness-device/firmware/dependencies.lockindex 0db70bd6f..5b21ffd37 100644--- a/devices/harness-device/firmware/dependencies.lock+++ b/devices/harness-device/firmware/dependencies.lock@@ -111,6 +111,6 @@ direct_dependencies:- idf- lvgl/lvgl- waveshare/esp_lcd_touch_cst9217-manifest_hash: ca9f548ea419ce355930a24f0f9efc14504d0a0f4ac0669b266c207edb51fde2+manifest_hash: c5505980965e154c4fb454b57b0844f7af33e68edde118fa25735edf295328f4target: esp32s3version: 2.0.0diff --git a/devices/harness-device/firmware/main/CMakeLists.txt b/devices/harness-device/firmware/main/CMakeLists.txtindex 08a7be5de..e9ffe6c43 100644--- a/devices/harness-device/firmware/main/CMakeLists.txt+++ b/devices/harness-device/firmware/main/CMakeLists.txt@@ -1,7 +1,84 @@# Single "main" component holding all app sources. Board drivers live under board/# and the LVGL UI under ui/.-idf_component_register(- SRCS+#+# TWO BOARDS, ONE COMPONENT. What each one builds is chosen by IDF_TARGET, because the difference is the+# SoC and nothing about an ESP32-S3 image can run on an ESP32-P4. See ../CMakeLists.txt for the pair.+#+# The Pro's list is deliberately short while the board is being brought up. The portable half of this+# firmware — the cable protocol, the config store, OTA, the screens — is not board-dependent and joins+# the list a file at a time as each is proved on the new hardware, rather than all at once against a+# panel that has never lit up. board/pro_bringup.c carries its own app_main for exactly that window,+# and goes away when the shared one takes over.++if(IDF_TARGET STREQUAL "esp32p4")++ set(BOARD_SRCS+ # the portable half, shared verbatim with the dial+ "app_main.c"+ "ram_telemetry.c"+ "config_store.c"+ "device_mac.c"+ "cable_frame.c"+ "cable_link.c"+ "last_words.c"+ "cable_client.c"+ "cable_machines.c"+ "fw_update.c"+ "audio_client.c"+ "audio_capture.c"+ # this board's own+ "board/board_i2c.c"+ "board/board_pro.c"+ "board/ptt_pro.c"+ "board/power_pro.c"+ "ui/display.c"+ "ui/panel_pro.c"+ "ui/touch.c"+ "ui/touch_gt911.c"+ # the screens, and the faces they are drawn in — identical files on both boards+ "ui/ui_screens.c"+ "ui/carousel_ring.c"+ "ui/geist_reg_16.c"+ "ui/geist_reg_20.c"+ "ui/geist_reg_24.c"+ "ui/geist_reg_25.c"+ "ui/geist_med_28.c"+ "ui/geist_med_32.c"+ "ui/geist_reg_32.c"+ "ui/geist_reg_34.c"+ "ui/geist_reg_38.c"+ "ui/geist_med_38.c"+ "ui/geist_med_48.c"+ "ui/geist_med_64.c"+ "ui/geist_sem_24.c"+ "ui/icons_settings.c"+ "ui/icons_engine.c"+ "ui/icons_voice.c"+ "ui/spinner_spokes.c"+ )+ set(BOARD_REQUIRES+ esp_driver_i2c+ esp_driver_gpio+ esp_driver_ledc+ esp_lcd+ esp_lcd_touch+ esp_timer+ driver+ lvgl+ esp_psram+ json+ nvs_flash+ app_update+ esp_partition+ mbedtls+ esp_adc+ esp_codec_dev+ esp_driver_i2s+ )++else() # esp32s3 — the round dial++ set(BOARD_SRCS"app_main.c""ram_telemetry.c""config_store.c"@@ -20,7 +97,9 @@ idf_component_register("board/board_table.c""board/power.c""ui/display.c"+ "ui/panel_dial.c""ui/touch.c"+ "ui/touch_cst.c""ui/ui_screens.c""ui/carousel_ring.c""ui/geist_reg_20.c"@@ -40,11 +119,8 @@ idf_component_register("ui/spinner_spokes.c""ui/icons_engine.c""ui/icons_voice.c"- INCLUDE_DIRS- "."- "ui"- "board"- REQUIRES+ )+ set(BOARD_REQUIRESnvs_flashesp_wifiesp_netif@@ -65,6 +141,17 @@ idf_component_register(driverjsonlvgl+ )++endif()++idf_component_register(+ SRCS ${BOARD_SRCS}+ INCLUDE_DIRS+ "."+ "ui"+ "board"+ REQUIRES ${BOARD_REQUIRES})# snprintf() is bounded (it truncates, never overflows), but -O2 enables a noisy@@ -90,7 +177,16 @@ endif()# BRING-UP PROBE: `idf.py -DBOARD_PROBE=1 build` (separate build dir recommended). app_main runs# board/board_probe.c before the display comes up and prints what is on the I2C bus, which reset pins# do what, and what each touch driver reads idle. Never set for a release image.-if(BOARD_PROBE)+# PANEL BISECT: `idf.py -DPRO_PANEL_DIAG=1 build` on the Pro. No UI, no LVGL — the panel shows its own+# colour bars while the backlight sweeps its whole range, so "the screen is blank" splits into "no video"+# and "no light" without guessing. See board/pro_bringup.c.+if(PRO_PANEL_DIAG)+ target_compile_definitions(${COMPONENT_LIB} PRIVATE PRO_PANEL_DIAG=1)+endif()++# The dial's own probe. The Pro does not need a flag for this: board/pro_bringup.c IS the probe until+# the shared app_main takes the board over.+if(BOARD_PROBE AND NOT IDF_TARGET STREQUAL "esp32p4")target_compile_definitions(${COMPONENT_LIB} PRIVATE BOARD_PROBE=1)target_sources(${COMPONENT_LIB} PRIVATE "board/board_probe.c")endif()diff --git a/devices/harness-device/firmware/main/app_main.c b/devices/harness-device/firmware/main/app_main.cindex 2ebaaf03b..176ad2ee0 100644--- a/devices/harness-device/firmware/main/app_main.c+++ b/devices/harness-device/firmware/main/app_main.c@@ -43,23 +43,14 @@ static const char *TAG = "app";// that carries them from its cache into the UI.#define MAX_PROJECTS CABLE_MAX_AGENTS-// ── boot button ─────────────────────────────────────────────────────────────────────────────────────+// ── factory reset ───────────────────────────────────────────────────────────────────────────────────-// BOOT (GPIO0) held at power-on = factory reset. All that is left to clear is the screen brightness and+// A button held through power-on = factory reset. All that is left to clear is the screen brightness and// the voice language — the credentials this used to wipe do not exist any more.-static bool boot_button_held(void)-{- gpio_config_t io = {- .pin_bit_mask = 1ULL << BSP_BOOT_BUTTON,- .mode = GPIO_MODE_INPUT,- .pull_up_en = GPIO_PULLUP_ENABLE,- };- gpio_config(&io);- // Two reads a moment apart: a single sample catches the pin mid-transition on a cold boot.- if (gpio_get_level(BSP_BOOT_BUTTON) != 0) return false;- vTaskDelay(pdMS_TO_TICKS(50));- return gpio_get_level(BSP_BOOT_BUTTON) == 0;-}+//+// WHICH button, and whether there is one at all, is the board's to answer (board.h): the dial reads BOOT,+// and the Pro has nothing it could read, because its only switch is the one that just turned it on.+static bool boot_button_held(void) { return board_factory_reset_requested(); }// ── the agent list ──────────────────────────────────────────────────────────────────────────────────diff --git a/devices/harness-device/firmware/main/board/board.c b/devices/harness-device/firmware/main/board/board.cindex a8cb2515a..74878f12b 100644--- a/devices/harness-device/firmware/main/board/board.c+++ b/devices/harness-device/firmware/main/board/board.c@@ -1,4 +1,5 @@#include "board.h"+#include "board_pins.h"#include <stdio.h>@@ -76,3 +77,18 @@ const char *board_describe(void)b->has_pmic ? "yes" : "no", b->lcd_rst, b->touch_rst);return s_describe;}++// BOOT (GPIO0) held at power-on. Two reads a moment apart: a single sample catches the pin mid-transition+// on a cold boot. Moved here from app_main.c when the Pro — which has no such button — joined the build.+bool board_factory_reset_requested(void)+{+ const gpio_config_t io = {+ .pin_bit_mask = 1ULL << BSP_BOOT_BUTTON,+ .mode = GPIO_MODE_INPUT,+ .pull_up_en = GPIO_PULLUP_ENABLE,+ };+ gpio_config(&io);+ if (gpio_get_level(BSP_BOOT_BUTTON) != 0) return false;+ vTaskDelay(pdMS_TO_TICKS(50));+ return gpio_get_level(BSP_BOOT_BUTTON) == 0;+}diff --git a/devices/harness-device/firmware/main/board/board.h b/devices/harness-device/firmware/main/board/board.hindex f2b0007d5..901065d89 100644--- a/devices/harness-device/firmware/main/board/board.h+++ b/devices/harness-device/firmware/main/board/board.h@@ -15,7 +15,9 @@#include <stdbool.h>#include <stdint.h>-typedef enum { TOUCH_NONE = 0, TOUCH_CST9217, TOUCH_CST816S } touch_chip_t;+// GT911 is the Pro's, and it is never the ANSWER to a probe — that board has one controller and knows+// it at build time (board_pro.c). It is in this enum so the shared log line and `hello.hw` can name it.+typedef enum { TOUCH_NONE = 0, TOUCH_CST9217, TOUCH_CST816S, TOUCH_GT911 } touch_chip_t;typedef struct {const char *name; // goes up the cable in `hello.hw`, and into the boot log@@ -40,3 +42,10 @@ void board_from_acks(const uint8_t *acks, int n, board_t *out);// One line, for the boot log and the daemon: "touch=cst816s pmic=no rst=1/2".const char *board_describe(void);++// Was a factory reset asked for by holding a button through power-on?+//+// A BOARD FACT, not a policy, which is why it lives here. The dial reads BOOT (GPIO0), a button that is+// up unless somebody is holding it. The Pro has no such button: its only switch is the one that turns the+// board on, so it is BY DEFINITION held at this moment and can never mean anything else.+bool board_factory_reset_requested(void);diff --git a/devices/harness-device/firmware/main/board/board_i2c.c b/devices/harness-device/firmware/main/board/board_i2c.cindex 27cda730a..ea466b399 100644--- a/devices/harness-device/firmware/main/board/board_i2c.c+++ b/devices/harness-device/firmware/main/board/board_i2c.c@@ -9,7 +9,7 @@ i2c_master_bus_handle_t board_i2c_get(void){if (s_bus) return s_bus;i2c_master_bus_config_t cfg = {- .i2c_port = I2C_NUM_0,+ .i2c_port = BSP_I2C_PORT,.sda_io_num = BSP_I2C_SDA,.scl_io_num = BSP_I2C_SCL,.clk_source = I2C_CLK_SRC_DEFAULT,diff --git a/devices/harness-device/firmware/main/board/board_pins.h b/devices/harness-device/firmware/main/board/board_pins.hindex a17bf9cb2..3652a18c8 100644--- a/devices/harness-device/firmware/main/board/board_pins.h+++ b/devices/harness-device/firmware/main/board/board_pins.h@@ -1,44 +1,20 @@-// Pin map for the Harness device (ESP32-S3, 466x466 round AMOLED).+// Which board's pin map this image is built against.//-// Verified on both shipped boards — see board/board.c for how the two are told apart at boot.-// The AMOLED is powered directly (no AXP2101 rail gating needed for display),-// reset is a real GPIO, and the panel uses the espressif/esp_lcd_co5300 driver.+// THE CHOICE IS THE SoC, and that is why it is made here and not by board_detect(). The two dials+// differ in things the I2C bus can be asked about — a touch controller, a reset pin, whether a PMIC+// answers — so they share one image and settle it at boot (board.h). A different SoC cannot be asked:+// ESP32-S3 code does not run on an ESP32-P4 at all, so the panel bus, the resolution and the whole pin+// map are decided by which target the image was built for.+//+// Every file keeps including board_pins.h. Nothing includes pins_dial.h or pins_pro.h directly.#pragma once-// ---- AMOLED panel: CO5300 over QSPI -----#define BSP_LCD_H_RES 466-#define BSP_LCD_V_RES 466-#define BSP_LCD_BIT_PER_PIXEL 16 // RGB565--#define BSP_LCD_QSPI_CS 12-#define BSP_LCD_QSPI_SCLK 38-#define BSP_LCD_QSPI_D0 4-#define BSP_LCD_QSPI_D1 5-#define BSP_LCD_QSPI_D2 6-#define BSP_LCD_QSPI_D3 7-// LCD reset: per board — board()->lcd_rst (board.h). GPIO39 on the CST9217 dial, GPIO1 on the CST816S one.--// ---- I2C bus (touch + PMIC share it) -----#define BSP_I2C_SDA 15-#define BSP_I2C_SCL 14-#define BSP_I2C_FREQ_HZ 400000--// ---- Capacitive touch: CST9217 (I2C) — wired for future use, not required in v1 -----// Touch controller address and reset: per board — board()->touch / ->touch_rst (board.h).-#define BSP_TOUCH_INT 11--// ---- Power management: AXP2101 (I2C) -----#define BSP_AXP2101_I2C_ADDR 0x34 // present only when board()->has_pmic--// ---- Audio: dual-mic → ES7210 ADC (capture) + ES8311 codec, on the shared I2C; I2S bus -----// Mic capture (ES7210) only in v1.-#define BSP_I2S_MCLK 16 // MCLK is GPIO16 on the shipped board (not 42)-#define BSP_I2S_BCLK 9-#define BSP_I2S_WS 45-#define BSP_I2S_DOUT 8 // codec → ESP (mic data in to ESP)-#define BSP_I2S_DIN 10 // ESP → codec (speaker; unused for mic-only)-#define BSP_PA_IO 46 // speaker power-amp enable (unused for mic-only)-// ES7210 (ADC) + ES8311 (codec) default I2C addresses (esp_codec_dev defaults).+#include "sdkconfig.h"-// ---- Buttons -----#define BSP_BOOT_BUTTON 0 // hold at power-on to factory-reset pairing+#if defined(CONFIG_IDF_TARGET_ESP32P4)+#include "pins_pro.h"+#elif defined(CONFIG_IDF_TARGET_ESP32S3)+#include "pins_dial.h"+#else+#error "no pin map for this target — add one beside pins_dial.h / pins_pro.h"+#endifdiff --git a/devices/harness-device/firmware/main/board/board_pro.c b/devices/harness-device/firmware/main/board/board_pro.cnew file mode 100644index 000000000..8dab54d9a--- /dev/null+++ b/devices/harness-device/firmware/main/board/board_pro.c@@ -0,0 +1,52 @@+/*+ * Which board this is, on a board where the answer is already known.+ *+ * The dial's board.c PROBES: two dials ship from one image and they differ in things the I2C bus can be+ * asked about, so it asks. Here there is nothing to ask. The Pro is a different SoC, so an image built+ * for it cannot be running on anything else — `board_detect()` has no work to do and the table below is+ * a constant.+ *+ * It exists all the same, rather than being #ifdef'd away at the five call sites that read it, because+ * those five are shared code (display.c, touch.c, power.c, ptt.c, cable_client.c) and a constant is+ * cheaper than a branch in each of them. `hello.hw` on the cable carries `name`, so the daemon and its+ * logs can tell a Pro from a dial without a protocol change.+ */+#include "board.h"+#include "board_pins.h"++#include "esp_log.h"++static const board_t s_pro = {+ .name = "harness-pro",+ .lcd_rst = BSP_LCD_RST,+ .touch_rst = BSP_TOUCH_RST,+ .touch = TOUCH_GT911,+ /* The GT911 reports panel-aligned on this board — confirmed on the glass: a touch on the top-left+ * corner mark moves the cursor to the top-left corner. */+ .touch_mirror = false,+ /* An IP5306, not an AXP2101. It answers battery percentage and charge state the same way as far as+ * the UI is concerned, which is what this flag gates. */+ .has_pmic = true,+};++void board_detect(void)+{+ ESP_LOGI("board", "%s", board_describe());+}++const board_t *board(void) { return &s_pro; }++const char *board_describe(void)+{+ return "board=harness-pro touch=gt911 pmic=ip5306 lcd=st7703/720x720";+}++/*+ * Never. There is no button this could read.+ *+ * The Pro's only switch is its power button, and pressing it is how the board got here — at the moment+ * app_main asks this question the button is, by construction, still down. Reading it would factory-reset+ * the device on every single power-on. A reset gesture for this board has to be something else (a touch+ * held through boot, say) and is not invented here.+ */+bool board_factory_reset_requested(void) { return false; }diff --git a/devices/harness-device/firmware/main/board/pins_dial.h b/devices/harness-device/firmware/main/board/pins_dial.hnew file mode 100644index 000000000..0978914b9--- /dev/null+++ b/devices/harness-device/firmware/main/board/pins_dial.h@@ -0,0 +1,45 @@+// Pin map for the round dial (ESP32-S3, 466x466 AMOLED). Reached through board_pins.h, never directly.+//+// Verified on both shipped boards — see board/board.c for how the two are told apart at boot.+// The AMOLED is powered directly (no AXP2101 rail gating needed for display),+// reset is a real GPIO, and the panel uses the espressif/esp_lcd_co5300 driver.+#pragma once++// ---- AMOLED panel: CO5300 over QSPI ----+#define BSP_LCD_H_RES 466+#define BSP_LCD_V_RES 466+#define BSP_LCD_BIT_PER_PIXEL 16 // RGB565++#define BSP_LCD_QSPI_CS 12+#define BSP_LCD_QSPI_SCLK 38+#define BSP_LCD_QSPI_D0 4+#define BSP_LCD_QSPI_D1 5+#define BSP_LCD_QSPI_D2 6+#define BSP_LCD_QSPI_D3 7+// LCD reset: per board — board()->lcd_rst (board.h). GPIO39 on the CST9217 dial, GPIO1 on the CST816S one.++// ---- I2C bus (touch + PMIC share it) ----+#define BSP_I2C_PORT 0+#define BSP_I2C_SDA 15+#define BSP_I2C_SCL 14+#define BSP_I2C_FREQ_HZ 400000++// ---- Capacitive touch: CST9217 (I2C) — wired for future use, not required in v1 ----+// Touch controller address and reset: per board — board()->touch / ->touch_rst (board.h).+#define BSP_TOUCH_INT 11++// ---- Power management: AXP2101 (I2C) ----+#define BSP_AXP2101_I2C_ADDR 0x34 // present only when board()->has_pmic++// ---- Audio: dual-mic → ES7210 ADC (capture) + ES8311 codec, on the shared I2C; I2S bus ----+// Mic capture (ES7210) only in v1.+#define BSP_I2S_MCLK 16 // MCLK is GPIO16 on the shipped board (not 42)+#define BSP_I2S_BCLK 9+#define BSP_I2S_WS 45+#define BSP_I2S_DOUT 8 // codec → ESP (mic data in to ESP)+#define BSP_I2S_DIN 10 // ESP → codec (speaker; unused for mic-only)+#define BSP_PA_IO 46 // speaker power-amp enable (unused for mic-only)+// ES7210 (ADC) + ES8311 (codec) default I2C addresses (esp_codec_dev defaults).++// ---- Buttons ----+#define BSP_BOOT_BUTTON 0 // hold at power-on to factory-reset pairingdiff --git a/devices/harness-device/firmware/main/board/pins_pro.h b/devices/harness-device/firmware/main/board/pins_pro.hnew file mode 100644index 000000000..7905962ad--- /dev/null+++ b/devices/harness-device/firmware/main/board/pins_pro.h@@ -0,0 +1,98 @@+// Pin map for Harness Pro (ESP32-P4, 720x720 square LCD). Reached through board_pins.h, never directly.+//+// Module: WT01P4C5-S1 (Wireless-Tag) — ESP32-P4 + ESP32-C5 in one package, 16 MB flash, 32 MB hex PSRAM.+//+// EVERY NUMBER HERE WAS READ OFF A WORKING BOARD, not off the schematic: they come from the vendor's+// HARDWARE.md §10, which was written from the BSP that runs on this hardware. Where the schematic and+// that document disagree, the document wins — it is the one that has been on a bench.+//+// The ESP32-C5 half of the module is deliberately absent from this file. It is the Wi-Fi coprocessor,+// reachable only over an internal SDIO link (P4 GPIO14-19, reset on GPIO13), and this firmware has no+// network path of any kind: it talks to its daemon over the USB cable and nothing else (cable_link.h).+// So the C5 is never reset and never powered up, and its pins are left alone.+#pragma once++// ---- LCD panel: ST7703I 720x720 over MIPI-DSI ----+#define BSP_LCD_H_RES 720+#define BSP_LCD_V_RES 720+#define BSP_LCD_BIT_PER_PIXEL 16 // RGB565++#define BSP_LCD_RST 4 // ST7703 reset. A SEPARATE LINE from the touch reset below —+ // an earlier revision of this board tied them together and+ // this one does not, so the two reset sequences must not be+ // merged (HARDWARE.md §13).+#define BSP_LCD_DSI_LANES 2+#define BSP_LCD_DSI_LANE_MBPS 480+#define BSP_LCD_DSI_PHY_LDO_CHAN 3 // internal LDO channel VO3 …+#define BSP_LCD_DSI_PHY_LDO_MV 2500 // … at 2500 mV, powered before the DSI bus is created++// ---- Backlight: PWM into the feedback pin of an AP3032 boost ----+// Real dimming, unlike the dial's software overlay: duty is INVERTED (a higher duty is dimmer), so+// panel_st7703.c converts a percentage rather than writing it straight through.+#define BSP_LCD_BL_PWM 21 // LEDC+#define BSP_LCD_BL_EN 11 // boost enable (also pulled up by R27)+#define BSP_LCD_BL_FREQ_HZ 5000+#define BSP_LCD_BL_RES_BITS 10++// ---- I2C bus: touch + both codecs + the power IC ----+// Hand-fitted 2.2k pull-ups to 3V3 on both lines, with the P4's internal pull-ups on top.+#define BSP_I2C_PORT 1+#define BSP_I2C_SDA 7+#define BSP_I2C_SCL 8+#define BSP_I2C_FREQ_HZ 400000++// ---- Capacitive touch: GT911 ----+// ⚠️ GT911 LATCHES ITS OWN I2C ADDRESS from the level of INT at the rising edge of RESET, so the order+// in board_pro.c is load-bearing and the esp_lcd_touch driver must be given GPIO_NUM_NC for its reset:+// the board layer has already done it by hand (HARDWARE.md §5).+#define BSP_TOUCH_RST 26+#define BSP_TOUCH_INT 27+#define BSP_TOUCH_ADDR 0x5D // primary; 0x14 is the fallback the probe tries next+#define BSP_TOUCH_ADDR_ALT 0x14++// ---- Audio: ES8311 (speaker DAC + amp) + ES7210 (3-mic array), one shared I2S bus ----+#define BSP_I2S_MCLK 23+#define BSP_I2S_BCLK 22+#define BSP_I2S_WS 10+#define BSP_I2S_DOUT 9 // P4 → ES8311 (speaker)+#define BSP_I2S_DIN 46 // ES7210 → P4 (microphones)+#define BSP_PA_IO 54 // CTRL_SPK → NS4150B amplifier enable++// THREE mics, and the TDM slot order is NOT the physical order. Measured on this board:+// slot 0 = MIC1 (front-left) slot 1 = MIC3 (rear) slot 2 = MIC2 (front-right) slot 3 = unwired+// Two kinds of mask follow from that and they must never be swapped even though their bit ranges+// overlap: gain is set per PHYSICAL mic, capture channels are chosen per SERIALIZED TDM slot.+#define BSP_ES7210_TDM_SLOTS 4+#define BSP_ES7210_SLOT_MIC1 0+#define BSP_ES7210_SLOT_MIC3 1+#define BSP_ES7210_SLOT_MIC2 2++// ---- Power: IP5306 charger/boost + a latch the firmware has to hold ----+#define BSP_IP5306_I2C_ADDR 0x75+// ⚠️ PWR_HOLD MUST BE DRIVEN HIGH IN THE FIRST LINES OF app_main. The board latches its own power+// through an analog circuit when the button is pressed, and that latch lets go shortly after boot —+// if firmware has not taken over by then the board switches itself off mid-startup.+#define BSP_PWR_HOLD 1 // output, high = stay on; low = cut power immediately+#define BSP_PWR_BTN 2 // input, active low — the physical button, independent of the latch+// Battery percentage comes from a divider, NOT from the IP5306's own fuel-gauge register: that register+// is documented only by community reverse-engineering and reads back nonsense on this board.+#define BSP_VBAT_ADC_GPIO 20 // ADC1 channel 4, VBAT/3 through a 200k/100k divider+#define BSP_VBAT_DIVIDER 3++// ---- Other peripherals ----+#define BSP_WS2812_IO 3 // single RGB LED, RMT, GRB order+#define BSP_HAPTIC_IO 28 // vibration motor, LEDC PWM++// ---- microSD (SDMMC slot 0 — fixed IO MUX pins on the P4, not remappable) ----+#define BSP_SD_D0 39+#define BSP_SD_D1 40+#define BSP_SD_D2 41+#define BSP_SD_D3 42+#define BSP_SD_CLK 43+#define BSP_SD_CMD 44+#define BSP_SD_LDO_CHAN 4 // internal LDO VO4 …+#define BSP_SD_LDO_MV 3300 // … at 3300 mV, required before a card will mount++// ---- Buttons ----+// There is no BOOT-button factory reset here the way the dial has one: this board's only button is the+// power button above, and it is read through BSP_PWR_BTN.diff --git a/devices/harness-device/firmware/main/board/power_pro.c b/devices/harness-device/firmware/main/board/power_pro.cnew file mode 100644index 000000000..e7a0af407--- /dev/null+++ b/devices/harness-device/firmware/main/board/power_pro.c@@ -0,0 +1,134 @@+/*+ * The Pro's battery, through an IP5306 and an ADC.+ *+ * Same five questions as the dial's AXP2101 driver (power.h), different answers underneath.+ *+ * ⚠️ THE FUEL GAUGE IS NOT USED, DELIBERATELY. The IP5306 has a register that reports a battery+ * percentage and it is tempting; it is also documented only by community reverse-engineering and reads+ * back nonsense on this board (HARDWARE.md §7). The percentage here comes from measuring the voltage on+ * a divider and interpolating a Li-ion curve, which is less clever and actually right.+ *+ * ⚠️ AND "CHARGING" IS TRUE WHENEVER A USB CABLE IS IN. The IP5306's VIN is diode-OR'd from every USB+ * socket on the board, including the debug one, so plugging in to read the log makes it report charging.+ * That is the circuit behaving correctly, not a bug to chase: a bench session always looks like a charge.+ */+#include "power.h"++#include "board_i2c.h"+#include "board_pins.h"++#include "esp_adc/adc_oneshot.h"+#include "esp_log.h"++static const char *TAG = "power";++#define IP5306_REG_READ0 0x70 /* bit 3: 1 = charging */+#define IP5306_REG_READ1 0x71 /* bit 3: 1 = full */++static i2c_master_dev_handle_t s_ip5306;+static adc_oneshot_unit_handle_t s_adc;+static bool s_ready;++static bool ip5306_read(uint8_t reg, uint8_t *out)+{+ if (!s_ip5306) return false;+ return i2c_master_transmit_receive(s_ip5306, ®, 1, out, 1, 50) == ESP_OK;+}++bool power_init(void)+{+ i2c_master_bus_handle_t bus = board_i2c_get();+ if (!bus) return false;++ const i2c_device_config_t dev = {+ .dev_addr_length = I2C_ADDR_BIT_LEN_7,+ .device_address = BSP_IP5306_I2C_ADDR,+ .scl_speed_hz = BSP_I2C_FREQ_HZ,+ };+ if (i2c_master_bus_add_device(bus, &dev, &s_ip5306) != ESP_OK) {+ ESP_LOGE(TAG, "IP5306 would not open at 0x%02X", BSP_IP5306_I2C_ADDR);+ return false;+ }++ const adc_oneshot_unit_init_cfg_t unit = { .unit_id = ADC_UNIT_1 };+ if (adc_oneshot_new_unit(&unit, &s_adc) != ESP_OK) {+ ESP_LOGE(TAG, "battery ADC unit refused");+ return false;+ }+ /* 12 dB of attenuation because the divider puts a full battery at ~1.4 V and the lower ranges clip+ * there — a clipped reading looks exactly like a flat battery. */+ const adc_oneshot_chan_cfg_t chan = { .atten = ADC_ATTEN_DB_12, .bitwidth = ADC_BITWIDTH_DEFAULT };+ if (adc_oneshot_config_channel(s_adc, ADC_CHANNEL_4, &chan) != ESP_OK) {+ ESP_LOGE(TAG, "battery ADC channel refused");+ return false;+ }++ s_ready = true;+ ESP_LOGI(TAG, "IP5306 at 0x%02X · battery on ADC1_CH4 (GPIO%d, /%d divider)",+ BSP_IP5306_I2C_ADDR, BSP_VBAT_ADC_GPIO, BSP_VBAT_DIVIDER);+ return true;+}++/* Millivolts at the battery, averaged: one sample of an ADC carries enough noise to make the percentage+ * jitter by a few points between two ticks of the status bar. */+static int battery_mv(void)+{+ if (!s_ready) return 0;+ int sum = 0, taken = 0;+ for (int i = 0; i < 8; i++) {+ int raw = 0;+ if (adc_oneshot_read(s_adc, ADC_CHANNEL_4, &raw) != ESP_OK) continue;+ sum += raw;+ taken++;+ }+ if (!taken) return 0;+ /* 12 dB attenuation spans roughly 0–3100 mV across the 12-bit range; the divider is the rest. */+ const int at_pin_mv = (sum / taken) * 3100 / 4095;+ return at_pin_mv * BSP_VBAT_DIVIDER;+}++/*+ * A single Li-ion cell's voltage/charge curve, piecewise-linear, from HARDWARE.md §7.+ *+ * It is a curve and not a straight line because the cell's is: most of the useful charge sits between+ * 3.7 V and 4.1 V, and a linear map of 3.0–4.2 V onto 0–100% reads 50% on a battery that is nearly flat.+ */+static const struct { int mv; int pct; } CURVE[] = {+ { 4200, 100 }, { 4100, 95 }, { 4000, 87 }, { 3900, 76 }, { 3800, 65 }, { 3700, 50 },+ { 3600, 25 }, { 3500, 12 }, { 3400, 6 }, { 3300, 2 }, { 3000, 0 },+};++int power_battery_pct(void)+{+ const int mv = battery_mv();+ if (mv <= 0) return -1; /* no reading — the UI shows no battery rather than 0% */+ if (mv >= CURVE[0].mv) return 100;+ for (size_t i = 1; i < sizeof(CURVE) / sizeof(CURVE[0]); i++) {+ if (mv >= CURVE[i].mv) {+ const int span_mv = CURVE[i - 1].mv - CURVE[i].mv;+ const int span_pct = CURVE[i - 1].pct - CURVE[i].pct;+ return CURVE[i].pct + (mv - CURVE[i].mv) * span_pct / span_mv;+ }+ }+ return 0;+}++bool power_is_charging(void)+{+ uint8_t v = 0;+ return ip5306_read(IP5306_REG_READ0, &v) && (v & 0x08);+}++/* External power present. On this board that is the same fact as "charging" — there is no separate VBUS+ * sense — which is why a full battery on a plugged-in device reports charging false and external true. */+bool power_is_on_external(void)+{+ uint8_t v = 0;+ if (ip5306_read(IP5306_REG_READ0, &v) && (v & 0x08)) return true;+ return ip5306_read(IP5306_REG_READ1, &v) && (v & 0x08); /* full, still on the charger */+}++/* The dial's AXP2101 latches a power-key tap for software to collect. There is nothing to collect here:+ * the Pro's button is a plain GPIO and board/ptt_pro.c reads it directly, with the press edge and the+ * hold thresholds in one place. */+bool power_take_pwrkey_tap(void) { return false; }diff --git a/devices/harness-device/firmware/main/board/ptt_pro.c b/devices/harness-device/firmware/main/board/ptt_pro.cnew file mode 100644index 000000000..9cc645d75--- /dev/null+++ b/devices/harness-device/firmware/main/board/ptt_pro.c@@ -0,0 +1,109 @@+/*+ * The Pro's one button, doing the work the dial spreads over two.+ *+ * The dial has a BOOT button and, on one of the two variants, a PMIC power key (ptt.c). This board has a+ * single physical switch, so the same three meanings are told apart by how long it is held — and the+ * shortest one keeps the shortest gesture, because interrupting a running turn is the thing you reach+ * for in a hurry:+ *+ * tap → back / stop the turn (the dial's BOOT press)+ * hold ≥ 0.8 s → screen off / on (the dial's BOOT hold and PWR tap)+ * hold ≥ 5 s → power off (this board only — the dial has no off)+ *+ * The 5-second one exists because this board CAN switch itself off: PWR_HOLD released cuts the rail.+ * That is also why it is last and longest — it is the only irreversible one, and a UI that has frozen is+ * exactly when a person needs it, so it must not depend on anything above this task still working.+ *+ * The button is read on GPIO2 and the latch is held on GPIO1. They are separate pins by design+ * (HARDWARE.md §7), so reading the button here cannot disturb the latch.+ */+#include "ptt.h"++#include "board.h"+#include "board_pins.h"+#include "ui/display.h"+#include "ui/ui_screens.h"++#include "driver/gpio.h"+#include "esp_log.h"+#include "esp_timer.h"+#include "freertos/FreeRTOS.h"+#include "freertos/task.h"++static const char *TAG = "ptt";++#define POLL_MS 50 /* finer than the dial's 100ms: one button carries three meanings here */+#define HOLD_SCREEN_MS 800+#define HOLD_POWER_OFF_MS 5000++static void screen_toggle(const char *why)+{+ /* Hold the LVGL lock: display_sleep/wake touch LVGL timers and the panel, and normally run on the+ * LVGL task; the recursive mutex serialises this task's call with it. Same rule as ptt.c. */+ display_lock();+ if (display_is_asleep()) { ESP_LOGI(TAG, "%s → screen ON", why); display_wake(); }+ else { ESP_LOGI(TAG, "%s → screen OFF", why); display_sleep(); }+ display_unlock();+}++/*+ * Cut the rail. Everything before the last line is courtesy — the screen going dark so the person sees+ * the press land, and a moment for any log or NVS write to drain. Releasing PWR_HOLD is not a request;+ * the board is off on the next instruction, so nothing may be left to do after it.+ */+static void power_off(void)+{+ ESP_LOGW(TAG, "power button held %ds → powering off", HOLD_POWER_OFF_MS / 1000);+ display_lock();+ display_sleep();+ display_unlock();+ vTaskDelay(pdMS_TO_TICKS(50));+ gpio_set_level(BSP_PWR_HOLD, 0);+ vTaskDelay(portMAX_DELAY); /* not reached; the rail is gone */+}++static void ptt_task(void *arg)+{+ (void)arg;+ const gpio_config_t cfg = {+ .pin_bit_mask = 1ULL << BSP_PWR_BTN,+ .mode = GPIO_MODE_INPUT,+ .pull_up_en = GPIO_PULLUP_ENABLE,+ .pull_down_en = GPIO_PULLDOWN_DISABLE,+ .intr_type = GPIO_INTR_DISABLE,+ };+ gpio_config(&cfg);++ int prev = 1; /* active low: 1 = up, 0 = pressed */+ int64_t pressed_at = 0;+ bool screen_fired = false;++ for (;;) {+ const int now = gpio_get_level(BSP_PWR_BTN);++ if (prev == 1 && now == 0) { /* fresh press */+ /* The press edge acts at once, exactly as the dial's does — waiting to see whether it+ * becomes a hold would put a delay on the one gesture that is used in a hurry. */+ if (display_is_asleep()) { display_lock(); display_wake(); display_unlock(); }+ ESP_LOGI(TAG, "button press → back / stop turn");+ ui_boot_pressed();+ pressed_at = esp_timer_get_time();+ screen_fired = false;+ } else if (now == 0) { /* still down */+ const int64_t held_ms = (esp_timer_get_time() - pressed_at) / 1000;+ if (held_ms >= HOLD_POWER_OFF_MS) power_off();+ if (!screen_fired && held_ms >= HOLD_SCREEN_MS) {+ screen_fired = true; /* once per press */+ screen_toggle("button hold");+ }+ }+ prev = now;++ vTaskDelay(pdMS_TO_TICKS(POLL_MS));+ }+}++void ptt_start(void)+{+ xTaskCreate(ptt_task, "ptt", 4096, NULL, 5, NULL);+}diff --git a/devices/harness-device/firmware/main/cable_client.c b/devices/harness-device/firmware/main/cable_client.cindex c659a94e5..7c6c05555 100644--- a/devices/harness-device/firmware/main/cable_client.c+++ b/devices/harness-device/firmware/main/cable_client.c@@ -424,6 +424,34 @@ static void handle_swarms(const cJSON *p)n++;}ui_swarms_replace(rows, n, str_of(p, "selected"));++ /* …and the selected tab's shape, which rides the same frame so the two can never be read half+ * updated: a grid drawn against the previous tab's rectangles puts agents where they are not. */+ static cable_tile_t tiles[SWARM_TILES_MAX];+ int tn = 0;+ const cJSON *ti = NULL;+ cJSON_ArrayForEach(ti, cJSON_GetObjectItemCaseSensitive(p, "tiles")) {+ if (tn >= SWARM_TILES_MAX) break;+ const cJSON *x1 = cJSON_GetObjectItemCaseSensitive(ti, "x1");+ const cJSON *y1 = cJSON_GetObjectItemCaseSensitive(ti, "y1");+ const cJSON *x2 = cJSON_GetObjectItemCaseSensitive(ti, "x2");+ const cJSON *y2 = cJSON_GetObjectItemCaseSensitive(ti, "y2");+ if (!cJSON_IsNumber(x1) || !cJSON_IsNumber(y1) || !cJSON_IsNumber(x2) || !cJSON_IsNumber(y2)) continue;+ tiles[tn].x1 = (int16_t)x1->valuedouble;+ tiles[tn].y1 = (int16_t)y1->valuedouble;+ tiles[tn].x2 = (int16_t)x2->valuedouble;+ tiles[tn].y2 = (int16_t)y2->valuedouble;+ /* The daemon already refuses an empty rectangle, so a bad one here is a wire fault rather+ * than a shape — drop it rather than draw nothing at that seat. */+ if (tiles[tn].x2 <= tiles[tn].x1 || tiles[tn].y2 <= tiles[tn].y1) continue;+ const cJSON *a = cJSON_GetObjectItemCaseSensitive(ti, "a");+ snprintf(tiles[tn].agent_id, sizeof(tiles[tn].agent_id), "%s",+ cJSON_IsString(a) ? a->valuestring : "");+ tn++;+ }+ /* Tagged with the tab these rectangles are OF — the same `selected` the rows above carry, read+ * from the same frame so the two can never disagree. */+ ui_tiles_replace(tiles, tn, str_of(p, "selected"));}static void session_up(const cJSON *p)diff --git a/devices/harness-device/firmware/main/cable_client.h b/devices/harness-device/firmware/main/cable_client.hindex afb9c4997..6e0488ef2 100644--- a/devices/harness-device/firmware/main/cable_client.h+++ b/devices/harness-device/firmware/main/cable_client.h@@ -161,6 +161,25 @@ typedef struct {int panes;} cable_swarm_t;+/*+ * ONE TILE OF THE SELECTED TAB'S GRID, exactly where the window put it.+ *+ * Unit rectangle in THOUSANDTHS of the grid — integers on the wire, scaled to whatever face reads+ * them. `agent_id` is empty for a tile this device cannot drive (a shell, a viewer); it still holds+ * its place, because a shape with a tile missing is not that shape.+ *+ * RELAYED, NEVER DERIVED. The device used to guess the shape from the agent count via the app's+ * `PanePreset.defaultFor`, which is right until somebody picks a different preset — and it could never+ * express `auto` (whose column count the window MEASURES against its own width) or a hand-dragged+ * resize at all. An empty list means a daemon or a window too old to send one, and the guess is still+ * there behind it.+ */+#define SWARM_TILES_MAX 24 // the window's own ceiling, same as the rows above+typedef struct {+ int16_t x1, y1, x2, y2; // 0..1000+ char agent_id[ID_MAX];+} cable_tile_t;+// One row of the window's unread list, as `notif.replace` carries it. `summary` is the last recap for// a finished turn and empty for a question — the dial kept that question's own text from when it asked.typedef struct {diff --git a/devices/harness-device/firmware/main/device_mac.c b/devices/harness-device/firmware/main/device_mac.cindex d891838c5..5fcc5c835 100644--- a/devices/harness-device/firmware/main/device_mac.c+++ b/devices/harness-device/firmware/main/device_mac.c@@ -14,9 +14,14 @@ bool device_mac_str(char *out, size_t cap)out[0] = '\0';uint8_t mac[6] = { 0 };- // ESP_MAC_WIFI_STA, not the AP or the base MAC: it is the address the device uses on the network the- // user actually sees, so it matches what any other tooling would report for this unit.- esp_err_t err = esp_read_mac(mac, ESP_MAC_WIFI_STA);+ // ESP_MAC_BASE — the chip's own factory address, and the one identifier this firmware has that is+ // stable, unique and needs no pairing. It is what the daemon uses to tell one device from another+ // before a byte of protocol is exchanged.+ //+ // It used to ask for ESP_MAC_WIFI_STA, which on the dial is the same value. On the Pro it is not a+ // value at all: the ESP32-P4 has no radio of its own (its Wi-Fi lives in a coprocessor this firmware+ // never wakes), so that read fails with ESP_ERR_NOT_FOUND and the hello went out carrying "mac":"".+ esp_err_t err = esp_read_mac(mac, ESP_MAC_BASE);if (err != ESP_OK) {ESP_LOGE(TAG, "esp_read_mac failed: %d", (int)err);return false;diff --git a/devices/harness-device/firmware/main/idf_component.yml b/devices/harness-device/firmware/main/idf_component.ymlindex 1479fd3d6..175e4e884 100644--- a/devices/harness-device/firmware/main/idf_component.yml+++ b/devices/harness-device/firmware/main/idf_component.yml@@ -1,4 +1,8 @@# Managed component dependencies (pulled by the IDF Component Manager on build).+#+# Anything that names a panel, a touch controller or a codec carries a `rules:` target guard — the two+# boards share this file, and a driver built for the other one's silicon is at best dead weight and at+# worst a build that will not configure (esp_lcd_co5300 does not claim esp32p4 at all).dependencies:idf:version: ">=5.5.0"@@ -10,19 +14,53 @@ dependencies:# something a fresh build should do on its own.lvgl/lvgl: "~9.5.0"# Official CO5300 AMOLED panel driver (the controller on this board).- espressif/esp_lcd_co5300: "*"+ espressif/esp_lcd_co5300:+ version: "*"+ rules:+ - if: "target in [esp32s3]"# Capacitive touch → LVGL pointer indev for swipe. BOTH controllers are linked in: the two dials# that ship differ here (CST9217 on one, CST816S on the other) and one image serves both — the# board is detected at boot (board/board.c) and the matching driver is opened. Pulls esp_lcd_touch.- waveshare/esp_lcd_touch_cst9217: "*"- espressif/esp_lcd_touch_cst816s: "^1.1.2"- # Audio codec abstraction + ES7210 (ADC/mic) + ES8311 drivers for mic capture.+ waveshare/esp_lcd_touch_cst9217:+ version: "*"+ rules:+ - if: "target in [esp32s3]"+ espressif/esp_lcd_touch_cst816s:+ version: "^1.1.2"+ rules:+ - if: "target in [esp32s3]"+ # Audio codec abstraction + ES7210 (ADC/mic) + ES8311 drivers for mic capture. NO target rule: both+ # boards carry the same two codecs, which is the one piece of the dial's hardware the Pro repeats+ # exactly — so audio_capture.c compiles for both with nothing but a different pin map.espressif/esp_codec_dev: "*"# WebSocket client used by commander_client.c. Pinned below 1.3.0: newer# releases call esp_transport_ws_get_redir_uri(), which this IDF 5.5's# tcp_transport does not provide (no HTTP-redirect support).- espressif/esp_websocket_client: "~1.2.0"+ espressif/esp_websocket_client:+ version: "~1.2.0"+ rules:+ - if: "target in [esp32s3]"# libsodium — the E2EE crypto stack (Ed25519, X25519, ristretto255 CPace, ChaCha20-Poly1305,# SHA-2, HKDF/HMAC). Backs devices/harness-device/firmware/main/e2ee/e2ee_core.c (byte-identical twin of the web/adapter# TS core). The Espressif port wires randombytes to the hardware RNG. See e2ee_core.h.- espressif/libsodium: "^1.0.20"+ espressif/libsodium:+ version: "^1.0.20"+ rules:+ - if: "target in [esp32s3]"++ # ── Harness Pro (ESP32-P4) ────────────────────────────────────────────────────────────────────────+ # The panel driver carries everything the vendor BSP would have given us and that we cannot derive+ # ourselves: the ST7703's power-on register sequence, and the DSI timings for THIS panel —+ # ST7703_720_720_PANEL_60HZ_DPI_CONFIG (38 MHz pixel clock, porches 50/20/50 by 20/4/20) and+ # ST7703_PANEL_BUS_DSI_2CH_CONFIG (2 lanes at 480 Mbps). It is published for esp32p4 only.+ waveshare/esp_lcd_st7703:+ version: "^2.0.0"+ rules:+ - if: "target in [esp32p4]"+ # GT911 → LVGL pointer indev. Its reset is done BY HAND in board/pro_bringup.c before this driver is+ # opened, because the chip decides its own I2C address from the INT pin at the rising edge of RESET —+ # so the driver is always given GPIO_NUM_NC and must never be allowed to pulse it again.+ espressif/esp_lcd_touch_gt911:+ version: "^1.1.0"+ rules:+ - if: "target in [esp32p4]"diff --git a/devices/harness-device/firmware/main/ui/display.c b/devices/harness-device/firmware/main/ui/display.cindex a4ef54679..e9bf373ab 100644--- a/devices/harness-device/firmware/main/ui/display.c+++ b/devices/harness-device/firmware/main/ui/display.c@@ -1,47 +1,21 @@#include "display.h"+#include "panel.h"#include <stdlib.h>#include "touch.h"#include "ui_screens.h"-#include "board_pins.h"-#include "board.h"#include "ram_telemetry.h"#include "freertos/FreeRTOS.h"#include "freertos/task.h"#include "freertos/semphr.h"-#include "esp_lcd_panel_io.h"-#include "esp_lcd_panel_ops.h"-#include "esp_lcd_co5300.h"-#include "driver/spi_master.h"#include "esp_heap_caps.h"#include "esp_timer.h"#include "esp_log.h"#include "esp_task_wdt.h"#include "lvgl.h"-// CO5300 power-on / init register sequence, taken verbatim from the panel-// vendor's reference BSP. The leading 0xFE/0x19/0x1C block is what was missing-// before — without it the panel never lights up.-static const co5300_lcd_init_cmd_t s_co5300_init_cmds[] = {- {0xFE, (uint8_t[]){0x20}, 1, 0},- {0x19, (uint8_t[]){0x10}, 1, 0},- {0x1C, (uint8_t[]){0xA0}, 1, 0},- {0xFE, (uint8_t[]){0x00}, 1, 0},- {0xC4, (uint8_t[]){0x80}, 1, 0},- {0x3A, (uint8_t[]){0x55}, 1, 0}, // 16bpp RGB565- {0x35, (uint8_t[]){0x00}, 1, 0},- {0x53, (uint8_t[]){0x20}, 1, 0},- {0x51, (uint8_t[]){0xFF}, 1, 0}, // panel at native max — perceived brightness is dimmed in software (ui_set_brightness overlay)- {0x63, (uint8_t[]){0xFF}, 1, 0},- {0x2A, (uint8_t[]){0x00, 0x06, 0x01, 0xD7}, 4, 0}, // col 6..471- {0x2B, (uint8_t[]){0x00, 0x00, 0x01, 0xD1}, 4, 600}, // row 0..465- {0x11, NULL, 0, 600}, // sleep out- {0x29, NULL, 0, 0}, // display on-};static const char *TAG = "display";-static esp_lcd_panel_handle_t s_panel;-static esp_lcd_panel_io_handle_t s_io; // kept so brightness (DCS 0x51) can be re-sent at runtimestatic lv_display_t *s_disp;static SemaphoreHandle_t s_lvgl_mutex;static bool s_asleep; // panel turned off after idle to save battery@@ -50,33 +24,6 @@ static void *s_lvgl_psram_pool; // lifetime-owned 64KiB secondary LVGL// Turn the panel off after this long without a touch. Wake with a double-tap (see touch.c).#define IDLE_MS 300000 // 5 minutes-// LVGL draw buffers in internal DMA RAM: each is about 1/16 screen,-// double-buffered for about 1/8 screen total.-// NOTE: in LVGL v9, sizeof(lv_color_t) is NOT the pixel byte size — for RGB565-// each pixel is 2 bytes regardless. Size buffers explicitly by bytes-per-pixel.-#define DRAW_LINES (BSP_LCD_V_RES / 16) // smaller so both draw buffers fit in internal DMA RAM-#define BYTES_PER_PX (BSP_LCD_BIT_PER_PIXEL / 8) // RGB565 -> 2-static uint8_t *s_buf1;-static uint8_t *s_buf2;--// esp_lcd "color trans done" → tell LVGL the flush finished. Uses the global-// display handle (the callback fires only after s_disp is created and rendering-// has started, so it is always valid by then).-static bool on_color_done(esp_lcd_panel_io_handle_t io, esp_lcd_panel_io_event_data_t *e, void *ctx)-{- if (s_disp) lv_display_flush_ready(s_disp);- return false;-}--// LVGL flush callback → push the rendered area to the CO5300. The SW renderer already emits big-endian-// RGB565 (display color format = RGB565_SWAPPED), so no per-pixel swap here — just DMA the area out.-static void lvgl_flush(lv_display_t *disp, const lv_area_t *area, uint8_t *px)-{- // Asleep: the panel is off — don't push pixels (events still update the offscreen tree and are- // shown on wake). Ack immediately so LVGL doesn't block waiting for the (skipped) DMA done.- if (s_asleep) { lv_display_flush_ready(disp); return; }- esp_lcd_panel_draw_bitmap(s_panel, area->x1, area->y1, area->x2 + 1, area->y2 + 1, px);-}// LVGL needs a millisecond tick.static void tick_cb(void *arg) { lv_tick_inc(2); }@@ -137,62 +84,16 @@ static void lvgl_task(void *arg)}}-// CO5300 addresses pixels in 2px units, so partial-update areas must start on an-// even coordinate and end on an odd one (matches the vendor BSP's rounder).-static void rounder_cb(lv_event_t *e)-{- lv_area_t *area = lv_event_get_param(e);- area->x1 = (area->x1 >> 1) << 1;- area->y1 = (area->y1 >> 1) << 1;- area->x2 = ((area->x2 >> 1) << 1) + 1;- area->y2 = ((area->y2 >> 1) << 1) + 1;-}-static void panel_bringup(void)-{- // QSPI bus + IO using the CO5300 driver's config macros (4 data lines).- const spi_bus_config_t bus = CO5300_PANEL_BUS_QSPI_CONFIG(- BSP_LCD_QSPI_SCLK, BSP_LCD_QSPI_D0, BSP_LCD_QSPI_D1, BSP_LCD_QSPI_D2, BSP_LCD_QSPI_D3,- BSP_LCD_H_RES * BSP_LCD_V_RES * BYTES_PER_PX);- ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &bus, SPI_DMA_CH_AUTO));-- esp_lcd_panel_io_handle_t io;- esp_lcd_panel_io_spi_config_t io_cfg = CO5300_PANEL_IO_QSPI_CONFIG(BSP_LCD_QSPI_CS, on_color_done, NULL);- io_cfg.trans_queue_depth = 10;- ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI2_HOST, &io_cfg, &io));- s_io = io; // stash for display_set_brightness()-- co5300_vendor_config_t vendor = {- .init_cmds = s_co5300_init_cmds,- .init_cmds_size = sizeof(s_co5300_init_cmds) / sizeof(s_co5300_init_cmds[0]),- .flags = { .use_qspi_interface = 1 },- };- esp_lcd_panel_dev_config_t pcfg = {- .reset_gpio_num = board()->lcd_rst, // differs between the two dials — see board.h- .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,- .bits_per_pixel = BSP_LCD_BIT_PER_PIXEL,- .vendor_config = &vendor,- };- ESP_ERROR_CHECK(esp_lcd_new_panel_co5300(io, &pcfg, &s_panel));- ESP_ERROR_CHECK(esp_lcd_panel_set_gap(s_panel, 0x06, 0)); // 6px column offset- ESP_ERROR_CHECK(esp_lcd_panel_reset(s_panel));- ESP_ERROR_CHECK(esp_lcd_panel_init(s_panel));- ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(s_panel, true));-}-// Re-send the CO5300 "Write Display Brightness" (DCS 0x51). 0x00 = dimmest, 0xFF = max. Safe to call-// any time after display_init(); no-op before the panel IO exists.-void display_set_brightness(uint8_t level)-{- if (!s_io) return;- esp_lcd_panel_io_tx_param(s_io, 0x51, (uint8_t[]){ level }, 1);-}static void display_init_impl(int draw_lines, bool with_touch){s_lvgl_mutex = xSemaphoreCreateRecursiveMutex();- panel_bringup();+ /* Bus and controller first, as they always have been: the CO5300's power-on sequence carries 600ms+ * of delays and none of it wants LVGL to exist yet. */+ ESP_ERROR_CHECK(panel_bringup());lv_init();@@ -226,25 +127,9 @@ static void display_init_impl(int draw_lines, bool with_touch)ram_telemetry_set_lvgl_ready();ram_telemetry_checkpoint("lvgl_pool_ready");- // Draw buffers in INTERNAL DMA RAM (not PSRAM): the LCD flush reads these over QSPI DMA, and- // sharing the octal PSRAM with the CPU-written audio record buffer stalled the flush DMA →- // LVGL hung in wait_for_flushing → watchdog. Internal DMA RAM has no such contention.- // `draw_lines` is small in the OTA boot mode so the internal RAM freed goes to the big WiFi RX buffers.- size_t buf_bytes = BSP_LCD_H_RES * draw_lines * BYTES_PER_PX;- s_buf1 = heap_caps_malloc(buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);- s_buf2 = heap_caps_malloc(buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);- if (!s_buf1 || !s_buf2) ESP_LOGE(TAG, "draw buffer alloc failed");- ESP_LOGI(TAG, "draw buffers %u B x2 (internal); free internal: %u",- (unsigned)buf_bytes, (unsigned)heap_caps_get_free_size(MALLOC_CAP_INTERNAL));-- s_disp = lv_display_create(BSP_LCD_H_RES, BSP_LCD_V_RES);- lv_display_set_flush_cb(s_disp, lvgl_flush);- // Render directly in the panel's byte order (big-endian RGB565). The CO5300 wants byte-swapped- // RGB565; letting the SW renderer emit it saves a per-pixel CPU swap on every flush (a big win for- // scroll/pan smoothness — that loop ran over the whole moving region each frame).- lv_display_set_color_format(s_disp, LV_COLOR_FORMAT_RGB565_SWAPPED);- lv_display_set_buffers(s_disp, s_buf1, s_buf2, buf_bytes, LV_DISPLAY_RENDER_MODE_PARTIAL);- lv_display_add_event_cb(s_disp, rounder_cb, LV_EVENT_INVALIDATE_AREA, NULL);+ /* …and now the board's own half: draw buffers, the LVGL display, the flush. */+ ESP_ERROR_CHECK(panel_attach(draw_lines, &s_disp));+// The LVGL default theme is light (LV_THEME_DEFAULT_DARK 0) → the auto-created default screen is WHITE.// The refresh task paints that white screen for a few frames on every boot/reboot before app_main loads@@ -263,14 +148,21 @@ static void display_init_impl(int draw_lines, bool with_touch)// Big stack: rendering long wrapped multi-line labels (the event reader) is stack-heavy.xTaskCreatePinnedToCore(lvgl_task, "lvgl", 16384, NULL, 4, NULL, 1);- ESP_LOGI(TAG, "display + LVGL ready (%dx%d)", BSP_LCD_H_RES, BSP_LCD_V_RES);+ /* Asked of the display that was actually created, not of the board's constants — so this line+ * reports what LVGL has rather than what the pin map claims. */+ ESP_LOGI(TAG, "display + LVGL ready (%" LV_PRId32 "x%" LV_PRId32 ")",+ lv_display_get_horizontal_resolution(s_disp), lv_display_get_vertical_resolution(s_disp));}-void display_init(void) { display_init_impl(DRAW_LINES, true); }+void display_init(void) { display_init_impl(panel_draw_lines(), true); }// Minimal display for the OTA boot mode: quarter-height draw buffers (frees ~40KB internal for the big// WiFi RX buffers) and no touch — just enough to render the OTA progress screen.-void display_init_ota(void) { display_init_impl(DRAW_LINES / 4 > 0 ? DRAW_LINES / 4 : 1, false); }+void display_init_ota(void)+{+ const int quarter = panel_draw_lines() / 4;+ display_init_impl(quarter > 0 ? quarter : 1, false);+}// The LVGL lock, with a voice. Every task that draws takes it; the LVGL task takes it every 20ms. A wait// past LOCK_WARN_MS is not a busy frame — it is a task that took the lock and blocked inside it (a cable@@ -301,6 +193,10 @@ void display_unlock(void) { xSemaphoreGiveRecursive(s_lvgl_mutex); }bool display_is_asleep(void) { return s_asleep; }+// Forwarded, so every existing call site keeps the name it has always used while the thing that carries+// it out is now the board's. The dial re-sends a DCS register; the Pro moves a PWM (panel.h).+void display_set_brightness(uint8_t level) { panel_set_brightness(level); }+// Optional power hook: cb(false) on sleep, cb(true) on wake. The UI uses it to arm the screen-lock on// sleep and show the pattern-unlock overlay on wake. Runs under display_lock (recursive), so the cb may// touch LVGL. NULL until registered.@@ -317,7 +213,7 @@ void display_sleep(void){if (s_asleep) return;s_asleep = true;- esp_lcd_panel_disp_on_off(s_panel, false);+ panel_power(false);// Stop the render/flush pipeline while the panel is off so a live animation (the connecting-screen// spinner) doesn't keep re-rendering into the draw buffers for pixels no one sees. The indev read// timer is separate and keeps running, so double-tap-to-wake stays responsive.@@ -333,7 +229,7 @@ void display_wake(void)lv_timer_resume(lv_display_get_refr_timer(s_disp)); // re-enable rendering (paused in display_sleep)lv_obj_invalidate(lv_screen_active()); // repaint current screen (flushed by the LVGL task's refr timer)lv_display_trigger_activity(s_disp); // re-arm the idle timer- esp_lcd_panel_disp_on_off(s_panel, true);+ panel_power(true);if (s_power_cb) s_power_cb(true); // show the pattern-unlock overlay if the lock is armedESP_LOGI(TAG, "wake (panel on)");// NB: no synchronous lv_refr_now / fade here — display_wake runs from the ptt (button A) and touch tasksdiff --git a/devices/harness-device/firmware/main/ui/metrics_round466.h b/devices/harness-device/firmware/main/ui/metrics_round466.hnew file mode 100644index 000000000..146dcb816--- /dev/null+++ b/devices/harness-device/firmware/main/ui/metrics_round466.h@@ -0,0 +1,115 @@+// The round dial: 466x466 AMOLED, 1.75" across, 10.48 px/mm.+//+// EVERY NUMBER HERE IS WHAT SHIPPED. It was lifted out of ui_screens.c unchanged when the square board+// arrived, comments and all, so that the extraction could be proved by the dial rendering identically.+// Treat a change to this file as a change to the dial, not as tidying.+//+// The governing constraint, and the reason so many of these are odd numbers: content must stay inside+// the inscribed square or the corners clip it, and the usable WIDTH varies with height — so a value+// here is often a chord measured at one particular y, not a margin anyone chose.+#pragma once++// ── the face ────────────────────────────────────────────────────────────────────────────────────────+#define UI_FACE_W 466+#define UI_FACE_H 466+#define UI_CX 233 // centre; also the rim radius, which is why it appears in clearances+#define UI_CY 233++// ── the readable column ─────────────────────────────────────────────────────────────────────────────+#define SCREEN_PAD 18+// A CHORD, not a margin: the widest column whose corners never clip, measured across the circle's mid+// band where the usable width is much larger than the inscribed square's.+#define SAFE_CONTENT_W 384+#define SAFE_W lv_pct(72) // ~335px — wrapped text on the side screens stays inside the curve++// ── Overview (mockup/overview-v3.html, "H · Halo, no ring") ──────────────────────────────────────────+// FIXED seats, not a growing column: nothing moves when the status changes, the words change. The far+// corner of every control is inside the 233px rim, above the home-swipe band (y >= 400) and below the+// notification pull-down band (y < 90).+#define OV_ROW_Y 118 // "8 agents" on one baseline: the count at 64, the word at 38+#define OV_NUM_H 72 // the row's height — the digit's line box+#define OV_ROW_GAP 14 // between the digit and the word+#define OV_STATUS_Y 204 // "N working" / "All idle", Geist 38+#define OV_SIDE_D 64 // Inbox and Settings: 64px rounds, 30px glyphs+#define OV_BELL_X 78+#define OV_GEAR_X 324+#define OV_SIDE_Y 308+// Voice: an 88px round on the axis, dropped 50px below the sides so the three follow the bezel the way+// the old arc did, the middle one nearest the resting thumb. Its lowest point is 434 — 201px from the+// centre, 32px inside the rim.+#define OV_VOICE_D 88+#define OV_VOICE_X 189+#define OV_VOICE_Y 346++// ── agent tile ──────────────────────────────────────────────────────────────────────────────────────+#define TILE_PAD_TOP 119 // 84 -> 117 -> 112 -> 109 -> 124 -> 109 -> 119 (row stays at y=69)+#define TILE_NAME_GAP 21+#define TILE_ARC_Y 322 // the action arc, and the floor a centred block must clear+#define TILE_ARC_GAP 20++// ── the action arc ──────────────────────────────────────────────────────────────────────────────────+// AN ARC, NOT A ROW, and that is the bezel's doing: three 80px buttons need ~300px of width, and at the+// height a thumb wants them this face is only 148px wide. Spread on a radius-160 arc at +/-36 degrees+// the farthest point of any button is 200px from centre, 33px inside the glass. Voice stays dead centre+// at the bottom — the one pressed ten times to the others' one must not move — and sits 31px lower,+// which is the vertical half of that same offset.+#define ACT_BTN_D 80+#define ACT_PREV_X 79+#define ACT_NEXT_X 307+#define ACT_Y 322+#define ACT_VOICE_D 80+#define ACT_VOICE_X 193+#define ACT_VOICE_Y 353++// ── notification drawer ─────────────────────────────────────────────────────────────────────────────+// A centred band, because the top and bottom of a circle are not there to put a list in.+#define NOTIF_LIST_W 360+#define NOTIF_LIST_H 320++// ── settings, pairing, pickers ──────────────────────────────────────────────────────────────────────+// 320 wide only fits the circle between y~64 and y~402 — 338px, i.e. exactly four 84px rows, which is+// why the fifth has to be scrolled to rather than squeezed in.+#define SET_ROW_W 320+#define SET_ROW_H 84+#define SET_LIST_PAD 65+#define PAIR_W 360+#define PICK_PAD_V 200+#define BRIGHT_BOX_W 427+#define MACHINE_ROW_W 427++// ── pattern lock ────────────────────────────────────────────────────────────────────────────────────+#define LK_GAP 113 // dot spacing — matches the "Create your pattern" Figma grid+#define LK_CX UI_CX+#define LK_CY UI_CY++// ── voice waveform ──────────────────────────────────────────────────────────────────────────────────+// Seven bars, Figma 1:1 on this face. The pitch is expressed as tenths so the centre column lands on a+// whole pixel: 224/10 = 22.4px between bars.+#define WAVE_PITCH_X10 224++// ── gesture edge bands (ui/touch.c) ─────────────────────────────────────────────────────────────────+// An upward swipe must START at or below UI_HOME_EDGE_Y to count as a bottom-edge swipe to Overview.+// Bottom ~14% band; well below where mid-tile "swipe-up = open detail" gestures begin.+// The reader's is much narrower — the bottom ~20px — because there the only non-scroll vertical gesture+// is that one swipe.+#define UI_HOME_EDGE_Y 400+#define UI_READER_HOME_EDGE_Y 446++// ── how much the tile body holds ────────────────────────────────────────────────────────────────────+// All three follow from ONE number: the body is 136px here (y 166 -> the 302 clamp), and everything+// below is what fits in it. They are not preferences.+//+// RECAP_MAX_CHARS is two lines of geist_med_28 across SAFE_CONTENT_W, and the comment at the card says+// why it is a cap at all: forty glyphs is what fits without the card touching the action arc.+// How many lines the recap card is pinned to. Two, and the cap above follows from it: a third would reach the action arc at y=322.+#define RECAP_LINES 2+#define RECAP_MAX_CHARS 40+#define TODO_VISIBLE_ROWS 4 // the rest scroll — keeps the status line on screen+#define AGENTS_VISIBLE_ROWS 3 // the rest scroll — coexists with the tool line++// ── the desk grid ───────────────────────────────────────────────────────────────────────────────────+// NOT ON THIS FACE. The grid draws the tab's agents in the same arrangement the Mac has them in, which+// needs a rectangle big enough to hold a recognisable shape: a 466 circle can carry one tile, and one+// tile is what the carousel already is. The dial's home stays the carousel.+#define UI_DESK_GRID 0+diff --git a/devices/harness-device/firmware/main/ui/metrics_square720.h b/devices/harness-device/firmware/main/ui/metrics_square720.hnew file mode 100644index 000000000..7b9560cb9--- /dev/null+++ b/devices/harness-device/firmware/main/ui/metrics_square720.h@@ -0,0 +1,143 @@+// Harness Pro: 720x720 LCD, 3.95" across, 10.01 px/mm.+//+// RE-DERIVED, NOT SCALED. The dial is 10.48 px/mm and this panel is 10.01 — within 5%, so a pixel means+// the same thing to a thumb on both and the type is shared unchanged. What differs is that the corners+// exist: the usable area goes from 170k pixels to 518k, and every number in metrics_round466.h that was+// a chord, an arc or a clearance from a rim is simply free here.+//+// These are the numbers from devices/harness-pro/mockup/ui-port.html, which was drawn 1:1 against the+// real palette and reviewed before any of this was built.+#pragma once++// ── the face ────────────────────────────────────────────────────────────────────────────────────────+#define UI_FACE_W 720+#define UI_FACE_H 720+#define UI_CX 360+#define UI_CY 360++// ── the readable column ─────────────────────────────────────────────────────────────────────────────+// A real margin this time. The rim used to be the margin; a square has to draw its own.+#define SCREEN_PAD 32+#define SAFE_CONTENT_W 656 // 720 - 2*32+#define SAFE_W lv_pct(85) // ~612px++// ── Overview ────────────────────────────────────────────────────────────────────────────────────────+// The dial's shape ports unchanged — one number in the middle, the hand's controls along the bottom —+// and the arc flattens into a row, because the reason it was an arc was the bezel.+#define OV_ROW_Y 124+#define OV_NUM_H 72+#define OV_ROW_GAP 14+#define OV_STATUS_Y 210+#define OV_SIDE_D 88+#define OV_BELL_X 152+#define OV_GEAR_X 480+#define OV_SIDE_Y 548+#define OV_VOICE_D 112+#define OV_VOICE_X 304+#define OV_VOICE_Y 536 // 12px proud of its neighbours, so it still reads as the primary++// ── agent tile ──────────────────────────────────────────────────────────────────────────────────────+// The body runs 191 -> 546, which is 355px against the dial's 136. That is where the room goes: a recap+// card of four lines instead of two, or a verb, a full tool path, three sub-agents and four todos with+// 22px still clear of the buttons.+#define TILE_PAD_TOP 112+#define TILE_NAME_GAP 28+#define TILE_ARC_Y 568+#define TILE_ARC_GAP 22++// ── the action row ──────────────────────────────────────────────────────────────────────────────────+// A straight row, and 96px targets rather than 80 — not for legibility but for the finger: 80px at+// 10.48 px/mm is 7.6mm, 96 at 10.01 is 9.6mm, and this face can afford to be generous. The width the+// square frees is deliberately left empty; three is still the right number of things to press.+#define ACT_BTN_D 96+#define ACT_PREV_X 168+#define ACT_NEXT_X 456+#define ACT_Y 568+#define ACT_VOICE_D 112+#define ACT_VOICE_X 304+#define ACT_VOICE_Y 560++// ── notification drawer ─────────────────────────────────────────────────────────────────────────────+// Four cards rather than two and a bit: a card is 134px, and 104 + 4*134 + 3*14 = 682 fits inside the+// 692 the face allows. Half of NOTIF_MAX at a glance.+#define NOTIF_LIST_W 656+#define NOTIF_LIST_H 496++// ── settings, pairing, pickers ──────────────────────────────────────────────────────────────────────+// Seven rows instead of four. The dial fits exactly four 84px rows between y~64 and y~402 and has to+// scroll to the fifth; here 90 + 7*84 = 678 lands inside the face with the row height unchanged, which+// matters — the row is sized for a fingertip, not for the screen.+#define SET_ROW_W 560+#define SET_ROW_H 84+#define SET_LIST_PAD 90+#define PAIR_W 560+#define PICK_PAD_V 260+#define BRIGHT_BOX_W 620+#define MACHINE_ROW_W 620++// ── pattern lock ────────────────────────────────────────────────────────────────────────────────────+// Spacing follows the face rather than the finger: the dots are targets whose SEPARATION is what stops+// two adjacent ones co-triggering, so a wider face wants a wider grid.+#define LK_GAP 150+#define LK_CX UI_CX+#define LK_CY UI_CY++// ── voice waveform ──────────────────────────────────────────────────────────────────────────────────+// Seven bars across a wider face: 346/10 = 34.6px between bars keeps the group the same proportion of+// the glass it is on the dial.+#define WAVE_PITCH_X10 346++// ── gesture edge bands (ui/touch.c) ─────────────────────────────────────────────────────────────────+// An upward swipe must START at or below UI_HOME_EDGE_Y to count as a bottom-edge swipe to Overview.+// The same proportions as the dial, on a taller face: ~14% of the height for the carousel band and the+// bottom ~30px for the reader. Held as proportions rather than pixels because what they describe is how+// far a thumb reaches from the bottom edge, and that has not changed.+#define UI_HOME_EDGE_Y 620+#define UI_READER_HOME_EDGE_Y 690++// ── how much the tile body holds ────────────────────────────────────────────────────────────────────+// The body is 355px here against the dial's 136, and these are what that buys. Measured, not hoped:+// verb 38 + 12 + tool 27 + 18 + three sub-agents 99 + 18 + four todos 135 = 347 into 355, with the+// action row still 22px clear.+//+// The row counts are what fits when BOTH lists are on screen at once. Either alone goes to seven, which+// is what the widgets scroll to; the pair is the case that has to be right.+// How many lines the recap card is pinned to. Four. The body has 355px and the card takes 205 of it, leaving 132 for whatever the turn also+// produced — a todo list, or simply air.+#define RECAP_LINES 4+#define RECAP_MAX_CHARS 120 // four lines rather than two+#define TODO_VISIBLE_ROWS 4+#define AGENTS_VISIBLE_ROWS 3++// ── the desk grid ───────────────────────────────────────────────────────────────────────────────────+// The tab's agents, laid out the way the Mac lays them out. The canvas below is the same proportion as+// a window's terminal area (1.34:1), so the app's unit rectangles land on it recognisably — which is the+// whole point: you find an agent by WHERE it is, not by reading a list.+#define UI_DESK_GRID 1+#define DESK_GRID_X SCREEN_PAD+#define DESK_GRID_Y 88 // under the tab strip+#define DESK_GRID_W 656+// ALL THE WAY DOWN, 88 -> 688, with the face's own 32px margin under it.+//+// It was 488, stopping at 576 to leave room for the hand's row of ‹ ◉ › at 600 — a row that is drawn on+// scr_projects and is therefore BEHIND this overlay, invisible, the whole time the grid is up. So the+// bottom 144px was reserved for something nobody can see, and the tiles were a fifth shorter than the+// glass allows for it (owner, 2026-09-27: "phía dưới trong 1 đoạn ko làm gì, cho agent dài ra luôn đi").+//+// There is nothing for the hand to do here anyway: ‹ › walk between agents and there is no one agent on+// this face, and Voice belongs to a tile. The grid IS the control.+#define DESK_GRID_H 600+#define DESK_GRID_GAP 12+// A tile says two things, sized to the room it has. Three steps rather than a formula, because the+// jump from a full-height tile to a quarter one is not linear and a formula reads worse at both ends.+// The tab line: the first thing on the glass, and the one the app's own rule governs — only the tab you+// are on has a fill. Names are clipped rather than wrapped so the line never becomes two.+#define DESK_STRIP_X 24+#define DESK_STRIP_Y 24+#define DESK_STRIP_H 52+#define DESK_TAB_H 52+#define DESK_TAB_NAME_MAX 300++#define DESK_MARK_LG 40+#define DESK_MARK_MD 32+#define DESK_MARK_SM 24diff --git a/devices/harness-device/firmware/main/ui/panel.h b/devices/harness-device/firmware/main/ui/panel.hnew file mode 100644index 000000000..207ba123c--- /dev/null+++ b/devices/harness-device/firmware/main/ui/panel.h@@ -0,0 +1,35 @@+// The panel, as the rest of the firmware needs to know it.+//+// ONE INTERFACE, TWO IMPLEMENTATIONS, CHOSEN BY THE BUILD — panel_dial.c for the round CO5300 over QSPI,+// panel_pro.c for the square ST7703 over MIPI-DSI (main/CMakeLists.txt picks by IDF_TARGET). Everything+// above this line is the same on both boards and lives in display.c: the LVGL lock, its memory pool, the+// tick, the handler task, the idle blank, the heartbeat.+//+// The two calls are separate rather than one `panel_open()` because the order matters and differs from+// what a single call could express: the bus and the controller come up BEFORE lv_init(), and the LVGL+// display is attached after it. That is the order the dial has always used and there was no reason to+// change it for the sake of a tidier signature.+#pragma once++#include <stdint.h>++#include "esp_err.h"+#include "lvgl.h"++// Bus + controller. No LVGL involved; safe to call before lv_init().+esp_err_t panel_bringup(void);++// Allocate draw buffers `draw_lines` tall, create the LVGL display and register the flush for it.+// Call after lv_init() and after the LVGL memory pool exists.+esp_err_t panel_attach(int draw_lines, lv_display_t **out_display);++// 0 = dimmest, 255 = brightest. Applied live; a no-op before panel_bringup().+// The dial re-sends a DCS register; the Pro moves a real PWM. Same range either way.+void panel_set_brightness(uint8_t level);++// The panel's own power, for the idle blank. Not the backlight: on the dial there is no backlight.+void panel_power(bool on);++// How tall one draw buffer should be on this board — a board decides this, because it follows from the+// resolution and from how much internal DMA RAM the rest of that board's firmware needs.+int panel_draw_lines(void);diff --git a/devices/harness-device/firmware/main/ui/panel_dial.c b/devices/harness-device/firmware/main/ui/panel_dial.cnew file mode 100644index 000000000..9a8fdd844--- /dev/null+++ b/devices/harness-device/firmware/main/ui/panel_dial.c@@ -0,0 +1,163 @@+/*+ * The round dial's panel: CO5300 AMOLED, 466x466, over QSPI.+ *+ * Lifted out of display.c when the square board arrived, and deliberately UNCHANGED in the lifting —+ * every register, every offset and every comment below is what shipped, because the dial had to keep+ * behaving identically through the split. What display.c kept is everything that was never about this+ * controller: the LVGL lock, the pool, the tick, the task, the idle blank.+ *+ * The twin is panel_pro.c. See panel.h for the contract they share.+ */+#include "panel.h"++#include "board.h"+#include "board_pins.h"+#include "display.h"++#include "driver/spi_master.h"+#include "esp_heap_caps.h"+#include "esp_lcd_co5300.h"+#include "esp_lcd_panel_io.h"+#include "esp_lcd_panel_ops.h"+#include "esp_log.h"++static const char *TAG = "panel_dial";++static esp_lcd_panel_handle_t s_panel;+static esp_lcd_panel_io_handle_t s_io; // kept so brightness (DCS 0x51) can be re-sent at runtime+static lv_display_t *s_disp;+static uint8_t *s_buf1;+static uint8_t *s_buf2;++// LVGL draw buffers in internal DMA RAM: each is about 1/16 screen,+// double-buffered for about 1/8 screen total.+// NOTE: in LVGL v9, sizeof(lv_color_t) is NOT the pixel byte size — for RGB565+// each pixel is 2 bytes regardless. Size buffers explicitly by bytes-per-pixel.+#define DRAW_LINES (BSP_LCD_V_RES / 16) // smaller so both draw buffers fit in internal DMA RAM+#define BYTES_PER_PX (BSP_LCD_BIT_PER_PIXEL / 8) // RGB565 -> 2++int panel_draw_lines(void) { return DRAW_LINES; }++// CO5300 power-on / init register sequence, taken verbatim from the panel+// vendor's reference BSP. The leading 0xFE/0x19/0x1C block is what was missing+// before — without it the panel never lights up.+static const co5300_lcd_init_cmd_t s_co5300_init_cmds[] = {+ {0xFE, (uint8_t[]){0x20}, 1, 0},+ {0x19, (uint8_t[]){0x10}, 1, 0},+ {0x1C, (uint8_t[]){0xA0}, 1, 0},+ {0xFE, (uint8_t[]){0x00}, 1, 0},+ {0xC4, (uint8_t[]){0x80}, 1, 0},+ {0x3A, (uint8_t[]){0x55}, 1, 0}, // 16bpp RGB565+ {0x35, (uint8_t[]){0x00}, 1, 0},+ {0x53, (uint8_t[]){0x20}, 1, 0},+ {0x51, (uint8_t[]){0xFF}, 1, 0}, // panel at native max — perceived brightness is dimmed in software (ui_set_brightness overlay)+ {0x63, (uint8_t[]){0xFF}, 1, 0},+ {0x2A, (uint8_t[]){0x00, 0x06, 0x01, 0xD7}, 4, 0}, // col 6..471+ {0x2B, (uint8_t[]){0x00, 0x00, 0x01, 0xD1}, 4, 600}, // row 0..465+ {0x11, NULL, 0, 600}, // sleep out+ {0x29, NULL, 0, 0}, // display on+};++// esp_lcd "color trans done" → tell LVGL the flush finished. Uses the global+// display handle (the callback fires only after s_disp is created and rendering+// has started, so it is always valid by then).+static bool on_color_done(esp_lcd_panel_io_handle_t io, esp_lcd_panel_io_event_data_t *e, void *ctx)+{+ if (s_disp) lv_display_flush_ready(s_disp);+ return false;+}++// LVGL flush callback → push the rendered area to the CO5300. The SW renderer already emits big-endian+// RGB565 (display color format = RGB565_SWAPPED), so no per-pixel swap here — just DMA the area out.+static void lvgl_flush(lv_display_t *disp, const lv_area_t *area, uint8_t *px)+{+ // Asleep: the panel is off — don't push pixels (events still update the offscreen tree and are+ // shown on wake). Ack immediately so LVGL doesn't block waiting for the (skipped) DMA done.+ if (display_is_asleep()) { lv_display_flush_ready(disp); return; }+ esp_lcd_panel_draw_bitmap(s_panel, area->x1, area->y1, area->x2 + 1, area->y2 + 1, px);+}++// CO5300 addresses pixels in 2px units, so partial-update areas must start on an+// even coordinate and end on an odd one (matches the vendor BSP's rounder).+static void rounder_cb(lv_event_t *e)+{+ lv_area_t *area = lv_event_get_param(e);+ area->x1 = (area->x1 >> 1) << 1;+ area->y1 = (area->y1 >> 1) << 1;+ area->x2 = ((area->x2 >> 1) << 1) + 1;+ area->y2 = ((area->y2 >> 1) << 1) + 1;+}++esp_err_t panel_bringup(void)+{+ // QSPI bus + IO using the CO5300 driver's config macros (4 data lines).+ const spi_bus_config_t bus = CO5300_PANEL_BUS_QSPI_CONFIG(+ BSP_LCD_QSPI_SCLK, BSP_LCD_QSPI_D0, BSP_LCD_QSPI_D1, BSP_LCD_QSPI_D2, BSP_LCD_QSPI_D3,+ BSP_LCD_H_RES * BSP_LCD_V_RES * BYTES_PER_PX);+ ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &bus, SPI_DMA_CH_AUTO));++ esp_lcd_panel_io_handle_t io;+ esp_lcd_panel_io_spi_config_t io_cfg = CO5300_PANEL_IO_QSPI_CONFIG(BSP_LCD_QSPI_CS, on_color_done, NULL);+ io_cfg.trans_queue_depth = 10;+ ESP_ERROR_CHECK(esp_lcd_new_panel_io_spi(SPI2_HOST, &io_cfg, &io));+ s_io = io; // stash for display_set_brightness()++ co5300_vendor_config_t vendor = {+ .init_cmds = s_co5300_init_cmds,+ .init_cmds_size = sizeof(s_co5300_init_cmds) / sizeof(s_co5300_init_cmds[0]),+ .flags = { .use_qspi_interface = 1 },+ };+ esp_lcd_panel_dev_config_t pcfg = {+ .reset_gpio_num = board()->lcd_rst, // differs between the two dials — see board.h+ .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,+ .bits_per_pixel = BSP_LCD_BIT_PER_PIXEL,+ .vendor_config = &vendor,+ };+ ESP_ERROR_CHECK(esp_lcd_new_panel_co5300(io, &pcfg, &s_panel));+ ESP_ERROR_CHECK(esp_lcd_panel_set_gap(s_panel, 0x06, 0)); // 6px column offset+ ESP_ERROR_CHECK(esp_lcd_panel_reset(s_panel));+ ESP_ERROR_CHECK(esp_lcd_panel_init(s_panel));+ ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(s_panel, true));+ return ESP_OK;+}++// Re-send the CO5300 "Write Display Brightness" (DCS 0x51). 0x00 = dimmest, 0xFF = max. Safe to call+// any time after display_init(); no-op before the panel IO exists.+void panel_set_brightness(uint8_t level)+{+ if (!s_io) return;+ esp_lcd_panel_io_tx_param(s_io, 0x51, (uint8_t[]){ level }, 1);+}++esp_err_t panel_attach(int draw_lines, lv_display_t **out_display)+{+ // Draw buffers in INTERNAL DMA RAM (not PSRAM): the LCD flush reads these over QSPI DMA, and+ // sharing the octal PSRAM with the CPU-written audio record buffer stalled the flush DMA →+ // LVGL hung in wait_for_flushing → watchdog. Internal DMA RAM has no such contention.+ // `draw_lines` is small in the OTA boot mode so the internal RAM freed goes to the big WiFi RX buffers.+ size_t buf_bytes = BSP_LCD_H_RES * draw_lines * BYTES_PER_PX;+ s_buf1 = heap_caps_malloc(buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);+ s_buf2 = heap_caps_malloc(buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);+ if (!s_buf1 || !s_buf2) ESP_LOGE(TAG, "draw buffer alloc failed");+ ESP_LOGI(TAG, "draw buffers %u B x2 (internal); free internal: %u",+ (unsigned)buf_bytes, (unsigned)heap_caps_get_free_size(MALLOC_CAP_INTERNAL));++ s_disp = lv_display_create(BSP_LCD_H_RES, BSP_LCD_V_RES);+ lv_display_set_flush_cb(s_disp, lvgl_flush);+ // Render directly in the panel's byte order (big-endian RGB565). The CO5300 wants byte-swapped+ // RGB565; letting the SW renderer emit it saves a per-pixel CPU swap on every flush (a big win for+ // scroll/pan smoothness — that loop ran over the whole moving region each frame).+ lv_display_set_color_format(s_disp, LV_COLOR_FORMAT_RGB565_SWAPPED);+ lv_display_set_buffers(s_disp, s_buf1, s_buf2, buf_bytes, LV_DISPLAY_RENDER_MODE_PARTIAL);+ lv_display_add_event_cb(s_disp, rounder_cb, LV_EVENT_INVALIDATE_AREA, NULL);++ if (out_display) *out_display = s_disp;+ return ESP_OK;+}++// The AMOLED's own power. There is no backlight on this board — the pixels are the light — so the idle+// blank is the panel itself going off.+void panel_power(bool on)+{+ if (s_panel) esp_lcd_panel_disp_on_off(s_panel, on);+}diff --git a/devices/harness-device/firmware/main/ui/panel_pro.c b/devices/harness-device/firmware/main/ui/panel_pro.cnew file mode 100644index 000000000..dc044e5a8--- /dev/null+++ b/devices/harness-device/firmware/main/ui/panel_pro.c@@ -0,0 +1,267 @@+/*+ * Harness Pro panel: ST7703I, 720x720, MIPI-DSI, two lanes at 480 Mbps.+ *+ * The dial's panel and this one differ in kind, not degree, and the difference decides the shape of this+ * file. The dial partial-renders into two small buffers in internal DMA RAM and pushes them over QSPI+ * (ui/display.c). A DPI panel is scanned out continuously by the DSI peripheral from a framebuffer in+ * PSRAM, so LVGL renders a WHOLE screen into a spare buffer and the flush is a pointer swap — no pixels+ * move. That is why this uses LV_DISPLAY_RENDER_MODE_FULL with the panel's own two framebuffers rather+ * than draw buffers of our own: handing LVGL the memory the panel already scans is what makes the swap+ * free, and it is also what makes it tear-free, because the swap happens between refreshes.+ *+ * Everything the vendor BSP would have carried — the ST7703's power-on register sequence and this+ * panel's DSI timings — comes from waveshare/esp_lcd_st7703 instead. The two config macros below are the+ * whole of it: 38 MHz pixel clock, porches 50/20/50 by 20/4/20, and the init commands inside the driver.+ */+#include "panel.h"++#include "board_pins.h"+#include "display.h"++#include "driver/gpio.h"+#include "driver/ledc.h"+#include "esp_check.h"+#include "esp_lcd_mipi_dsi.h"+#include "esp_lcd_panel_ops.h"+#include "esp_lcd_panel_vendor.h"+#include "esp_lcd_st7703.h"+#include "esp_ldo_regulator.h"+#include "esp_heap_caps.h"+#include "esp_log.h"++static const char *TAG = "panel_pro";++#define BL_TIMER LEDC_TIMER_0+#define BL_CHANNEL LEDC_CHANNEL_0+#define BL_MAX_DUTY ((1 << BSP_LCD_BL_RES_BITS) - 1)++static esp_lcd_panel_handle_t s_panel;+static esp_lcd_panel_io_handle_t s_io;+static esp_lcd_dsi_bus_handle_t s_bus;+static esp_ldo_channel_handle_t s_phy_pwr;+static lv_display_t *s_disp;++/*+ * Backlight. An AP3032 boost drives the LED string and its feedback pin is what this PWM moves, so the+ * duty is INVERTED — more duty is dimmer. The invert is done by the LEDC peripheral rather than by+ * arithmetic here, so the number in the register reads the same way the number in the code does.+ *+ * This is real dimming. The dial has no brightness control in hardware and fakes it with a translucent+ * overlay over the whole UI (ui_screens.c), which costs a composited layer on every frame; this board+ * does not need that, and at M2 the overlay should be switched off for it rather than stacked on top.+ */+static void backlight_init(void)+{+ const gpio_config_t en = {+ .pin_bit_mask = 1ULL << BSP_LCD_BL_EN,+ /* INPUT_OUTPUT, not OUTPUT: a plain output pin reads back 0 whatever it is driving, which made+ * the diagnostic line below report BL_EN=0 on a backlight that was on. */+ .mode = GPIO_MODE_INPUT_OUTPUT,+ .pull_up_en = GPIO_PULLUP_DISABLE,+ .pull_down_en = GPIO_PULLDOWN_DISABLE,+ .intr_type = GPIO_INTR_DISABLE,+ };+ gpio_config(&en);+ gpio_set_level(BSP_LCD_BL_EN, 1);++ const ledc_timer_config_t timer = {+ .speed_mode = LEDC_LOW_SPEED_MODE,+ .duty_resolution = BSP_LCD_BL_RES_BITS,+ .timer_num = BL_TIMER,+ .freq_hz = BSP_LCD_BL_FREQ_HZ,+ .clk_cfg = LEDC_AUTO_CLK,+ };+ ledc_timer_config(&timer);++ const ledc_channel_config_t ch = {+ .gpio_num = BSP_LCD_BL_PWM,+ .speed_mode = LEDC_LOW_SPEED_MODE,+ .channel = BL_CHANNEL,+ .timer_sel = BL_TIMER,+ .duty = 0,+ .hpoint = 0,+ .flags.output_invert = true,+ };+ ledc_channel_config(&ch);+}++/* 0..255 to match the dial's DCS register range, so one UI setting drives both boards. */+void panel_set_brightness(uint8_t level)+{+ ledc_set_duty(LEDC_LOW_SPEED_MODE, BL_CHANNEL, (uint32_t)BL_MAX_DUTY * level / 255u);+ ledc_update_duty(LEDC_LOW_SPEED_MODE, BL_CHANNEL);+}++/* The idle blank. This panel is backlit, so "off" is the backlight rather than the pixels — cutting the+ * DSI stream instead would take a full re-init to come back from, and the dial's wake is instant. */+static uint8_t s_level_before_blank = 255;+void panel_power(bool on)+{+ if (!on) {+ s_level_before_blank = (uint8_t)(ledc_get_duty(LEDC_LOW_SPEED_MODE, BL_CHANNEL) * 255u / BL_MAX_DUTY);+ panel_set_brightness(0);+ gpio_set_level(BSP_LCD_BL_EN, 0);+ } else {+ gpio_set_level(BSP_LCD_BL_EN, 1);+ panel_set_brightness(s_level_before_blank);+ }+}++/* A twelfth of the face. Two buffers of it are 169 KiB of the ~525 KiB internal RAM this board starts+ * with, which leaves room for the audio path that joins later. */+#define DRAW_LINES 60+int panel_draw_lines(void) { return DRAW_LINES; }++static esp_err_t pro_panel_self_test(bool on)+{+ if (!s_panel) return ESP_ERR_INVALID_STATE;+ esp_err_t err = esp_lcd_dpi_panel_set_pattern(s_panel, on ? MIPI_DSI_PATTERN_BAR_VERTICAL+ : MIPI_DSI_PATTERN_NONE);+ /* Logged rather than returned quietly: this is the one call whose failure would leave a blank+ * screen looking exactly like a panel that is not there at all. */+ if (err != ESP_OK) ESP_LOGE(TAG, "pattern %s refused: %s", on ? "on" : "off", esp_err_to_name(err));+ return err;+}++/* Read back what the backlight is actually being driven with, so a brightness bug and a video bug can+ * be told apart from the log instead of by eye. */+static void pro_panel_backlight_debug(void)+{+ ESP_LOGI(TAG, "backlight · BL_EN(GPIO%d)=%d · PWM GPIO%d · duty=%lu/%d · inverted",+ BSP_LCD_BL_EN, gpio_get_level(BSP_LCD_BL_EN), BSP_LCD_BL_PWM,+ (unsigned long)ledc_get_duty(LEDC_LOW_SPEED_MODE, BL_CHANNEL), BL_MAX_DUTY);+}++/*+ * The copy into the framebuffer has finished, so LVGL may reuse the draw buffer.+ *+ * ON_COLOR_TRANS_DONE, NOT ON_REFRESH_DONE, and the difference is why the first version of this file+ * drew nothing at all. `on_refresh_done` reports that the panel finished SCANNING a frame, which is+ * what a buffer-switch scheme waits for; `on_color_trans_done` reports that the pixels asked for by+ * draw_bitmap have actually landed, which is what a copying flush waits for. Registering only the+ * former left every flush un-acknowledged: LVGL rendered one frame, called flush, and waited for a+ * release that never came — a blank screen with no error anywhere. (Espressif's own LVGL adapter picks+ * between the two on exactly this distinction; see its v9 bridge.)+ */+static bool on_color_trans_done(esp_lcd_panel_handle_t panel, esp_lcd_dpi_panel_event_data_t *edata, void *ctx)+{+ lv_display_t *disp = (lv_display_t *)ctx;+ lv_display_flush_ready(disp);+ return false;+}++static void flush_cb(lv_display_t *disp, const lv_area_t *area, uint8_t *px_map)+{+ /* Blanked: the backlight is off, so nothing would be seen. Ack at once rather than making LVGL wait+ * on a copy whose result nobody can look at — the same rule panel_dial.c follows. */+ if (display_is_asleep()) { lv_display_flush_ready(disp); return; }+ /* Partial render: LVGL has drawn one band into its own buffer and this copies that band into the+ * framebuffer the panel scans. The copy is DMA2D's, not the CPU's (`use_dma2d` in the DPI config). */+ esp_lcd_panel_draw_bitmap(s_panel, area->x1, area->y1, area->x2 + 1, area->y2 + 1, px_map);+ /* flush_ready comes from on_color_trans_done, not from here. */+}++esp_err_t panel_bringup(void)+{++ backlight_init(); /* enable the boost early; duty stays 0 until there is something to show */++ /* The DSI PHY runs off an internal LDO, and it has to be up before the bus is created. Getting this+ * wrong does not fail loudly — the bus is created and the panel simply never lights. */+ const esp_ldo_channel_config_t ldo = {+ .chan_id = BSP_LCD_DSI_PHY_LDO_CHAN,+ .voltage_mv = BSP_LCD_DSI_PHY_LDO_MV,+ };+ ESP_RETURN_ON_ERROR(esp_ldo_acquire_channel(&ldo, &s_phy_pwr), TAG, "DSI PHY LDO (VO%d) refused",+ BSP_LCD_DSI_PHY_LDO_CHAN);++ esp_lcd_dsi_bus_config_t bus = ST7703_PANEL_BUS_DSI_2CH_CONFIG();+ ESP_RETURN_ON_ERROR(esp_lcd_new_dsi_bus(&bus, &s_bus), TAG, "dsi bus");++ esp_lcd_dbi_io_config_t dbi = ST7703_PANEL_IO_DBI_CONFIG();+ ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_dbi(s_bus, &dbi, &s_io), TAG, "dbi io");++ esp_lcd_dpi_panel_config_t dpi = ST7703_720_720_PANEL_60HZ_DPI_CONFIG(LCD_COLOR_PIXEL_FORMAT_RGB565);+ /* ONE framebuffer. LVGL renders into small buffers of its own and each flush copies a band into+ * this one — the same partial-render shape the dial uses, which is why display.c can end up owning+ * both boards rather than branching. Handing LVGL the panel's own framebuffers instead would save+ * the copy, but it needs the buffer-switch protocol and its own tear handling; that is an+ * optimisation for later, on a panel that is already known to work. */+ dpi.num_fbs = 1;++ const st7703_vendor_config_t vendor = {+ .mipi_config = { .dsi_bus = s_bus, .dpi_config = &dpi },+ };+ const esp_lcd_panel_dev_config_t dev = {+ .reset_gpio_num = BSP_LCD_RST,+ .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,+ .bits_per_pixel = BSP_LCD_BIT_PER_PIXEL,+ .vendor_config = (void *)&vendor,+ };+ ESP_RETURN_ON_ERROR(esp_lcd_new_panel_st7703(s_io, &dev, &s_panel), TAG, "st7703");+ ESP_RETURN_ON_ERROR(esp_lcd_panel_reset(s_panel), TAG, "panel reset");+ ESP_RETURN_ON_ERROR(esp_lcd_panel_init(s_panel), TAG, "panel init");+ return ESP_OK;+}++esp_err_t panel_attach(int draw_lines, lv_display_t **out_display)+{+ esp_err_t err;++ /* Draw buffers in INTERNAL DMA RAM, for the reason display.c gives on the dial: the flush reads+ * these while the CPU writes the next band, and putting both in the same external memory makes the+ * two contend. See panel_draw_lines() for how tall they are and why. */+ /* 64-BYTE ALIGNED, AND THE SIZE ROUNDED UP TO MATCH. That is the L2 cache line, and the PPA reaches+ * these buffers through the cache: a buffer that starts mid-line, or ends mid-line, cannot be+ * invalidated without dragging a neighbour's bytes in or out with it. LVGL is told the same number+ * through CONFIG_LV_DRAW_BUF_ALIGN, and its PPA unit refuses to compile if the two disagree. */+ const size_t line = 64;+ size_t buf_bytes = BSP_LCD_H_RES * draw_lines * (BSP_LCD_BIT_PER_PIXEL / 8);+ buf_bytes = (buf_bytes + line - 1) / line * line;+ uint8_t *buf1 = heap_caps_aligned_alloc(line, buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);+ uint8_t *buf2 = heap_caps_aligned_alloc(line, buf_bytes, MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA);+ if (!buf1 || !buf2) {+ ESP_LOGE(TAG, "draw buffers (%u B x2) would not fit in internal DMA RAM", (unsigned)buf_bytes);+ return ESP_ERR_NO_MEM;+ }++ s_disp = lv_display_create(BSP_LCD_H_RES, BSP_LCD_V_RES);+ if (!s_disp) return ESP_ERR_NO_MEM;+ /* Plain RGB565, NOT the dial's RGB565_SWAPPED: that swap exists because the CO5300 is fed over QSPI+ * in the panel's byte order, and DSI is not. Getting it wrong here is not subtle — the whole screen+ * comes out in the wrong hue. */+ lv_display_set_color_format(s_disp, LV_COLOR_FORMAT_RGB565);+ lv_display_set_buffers(s_disp, buf1, buf2, buf_bytes, LV_DISPLAY_RENDER_MODE_PARTIAL);+ lv_display_set_flush_cb(s_disp, flush_cb);++ const esp_lcd_dpi_panel_event_callbacks_t cbs = { .on_color_trans_done = on_color_trans_done };+ err = esp_lcd_dpi_panel_register_event_callbacks(s_panel, &cbs, s_disp);+ /* Without this LVGL never gets its buffer back and the screen stays on frame one. Loud, not a warning. */+ if (err != ESP_OK) {+ ESP_LOGE(TAG, "flush-done callback refused (%s) — LVGL would stall after one frame",+ esp_err_to_name(err));+ return err;+ }++ /*+ * FULL BRIGHTNESS, HERE, BECAUSE NOTHING ELSE WILL DO IT.+ *+ * The dial comes up lit without anyone asking: the last entries of its CO5300 power-on sequence are+ * {0x51, 0xFF} — panel at native maximum — and ui_set_brightness() then dims in SOFTWARE, with a+ * translucent layer over the whole UI. So app_main never calls display_set_brightness() on either+ * board, and a Pro whose backlight was left at the duty backlight_init() set (zero) drew a perfect,+ * invisible screen: the daemon paired, the log said `ui: face: overview`, and the glass was black.+ *+ * Matching the dial means coming up at maximum and letting the UI's own overlay do the dimming.+ * Using this PWM for the user's brightness setting instead — which is what the hardware is for — is+ * a change to ui_screens.c, not to this line.+ */+ panel_set_brightness(255);++ ESP_LOGI(TAG, "panel up · %dx%d · %d lanes @ %d Mbps · framebuffer %u KiB in PSRAM · draw buffers %u KiB x2",+ BSP_LCD_H_RES, BSP_LCD_V_RES, BSP_LCD_DSI_LANES, BSP_LCD_DSI_LANE_MBPS,+ (unsigned)(BSP_LCD_H_RES * BSP_LCD_V_RES * 2 / 1024), (unsigned)(buf_bytes / 1024));++ if (out_display) *out_display = s_disp;+ return ESP_OK;+}diff --git a/devices/harness-device/firmware/main/ui/touch.c b/devices/harness-device/firmware/main/ui/touch.cindex adacc1795..ad9ff013f 100644--- a/devices/harness-device/firmware/main/ui/touch.c+++ b/devices/harness-device/firmware/main/ui/touch.c@@ -1,4 +1,6 @@#include "touch.h"+#include "touch_ctrl.h"+#include "ui_metrics.h"#include "cable_client.h"#include "board_pins.h"@@ -6,10 +8,9 @@#include "board.h"#include "display.h"#include "ui_screens.h" // ui_swipe_begin/end for the circular edge-swipe-#include "driver/i2c_master.h"+/* No controller header here any more: which chip this is, and how to open it, is touch_ctrl.h's — and+ * the CST drivers do not exist for the Pro's target at all, so including them would break that build. */#include "esp_lcd_panel_io.h"-#include "esp_lcd_touch_cst816s.h"-#include "esp_lcd_touch_cst9217.h"#include "esp_log.h"#include "lvgl.h"#include <stdlib.h>@@ -97,17 +98,27 @@ static bool double_tap(bool pressed, uint16_t x, uint16_t y)#define SCROLL_EVERY_MS 50 // ...or this long, whichever comes first// Ceiling on the reported speed, px/s. One jittery sample across a 4ms window reads as thousands of pixels// a second; with no lid that lands on the far side as a fling to the end of the scrollback. ~6000 is well-// past anything a hand does on a 466px face and still finite.+// past anything a hand does on either face and still finite — a speed, so it is the hand's again.#define SCROLL_V_MAX 6000+// ⚠️ THESE ARE PHYSICAL DISTANCES, AND THAT IS WHY THEY DO NOT CHANGE WITH THE FACE.+//+// It is tempting to scale a pixel threshold when the screen grows from 466 to 720, and it would be+// wrong. The two panels are 10.48 and 10.01 pixels per millimetre — within 5% — so 55px is about 5.3mm+// on both, and what this number decides is whether a FINGER moved far enough to have meant it. That+// judgement is about the hand, not the glass. Scaling it would make the bigger screen need a longer+// drag for the same intent.+//+// The edge bands are the opposite case and do scale (UI_HOME_EDGE_Y, ui_metrics.h): they describe where+// on the face a gesture STARTS, which is a fact about the face.#define SWIPE_MIN_PX 55#define TAP_MAX_MS 700 // a near-still press shorter than this = a tap (not a hold/long-press)// Home gesture: an upward swipe must START at/below this y (panel is 466 tall) to count as a bottom-edge// swipe → Overview. Bottom ~14% band; well below where mid-tile "swipe-up = open detail" gestures begin.-#define BOTTOM_EDGE_PX 400+#define BOTTOM_EDGE_PX UI_HOME_EDGE_Y// On the detail reader the ONLY non-scroll vertical gesture is a tight bottom-edge up-swipe → Overview, so it// uses a much narrower band than the carousel screens: a swipe that STARTS within the bottom ~20px (panel 466).-#define READER_HOME_EDGE_PX 446+#define READER_HOME_EDGE_PX UI_READER_HOME_EDGE_Y// A single tap toggles the detail reader (open on projects / close on the reader), but a double-tap// starts voice. They're indistinguishable until the double-tap window passes, so DEFER the tap's action// by DOUBLE_TAP_MS and cancel it if a 2nd tap arrives (that's a start-voice). A tap while RECORDING is@@ -252,6 +263,15 @@ static void swipe_track(bool pressed, uint16_t x, uint16_t y)int home_edge = reader ? READER_HOME_EDGE_PX : BOTTOM_EDGE_PX;// HOME gesture: an upward swipe that STARTED at the bottom edge → jump to Overview. (y grows downward;// the driver already applies the panel mirror, so sy near y_max = the physical bottom.)+ // THE DESK OWNS THE GLASS WHILE IT IS UP, AND IT IS HOME. Its tiles take taps through LVGL; what+ // this classifier must not do is act on the carousel underneath — a horizontal swipe here would+ // walk agents on a screen that is not showing them, and the home swipe has nowhere to go, because+ // this IS where home goes. So on the desk it answers nothing.+#if UI_DESK_GRID+ if (!voice && ui_desk_is_open()) {+ /* home is already on screen — nothing above it, nothing beside it */+ } else+#endifif (!voice && sy >= home_edge && dy < -SWIPE_MIN_PX && abs(dy) > abs(dx)) {ESP_LOGI(TAG, "gesture: home (dy=%d)", dy);ui_home_overview();@@ -293,11 +313,66 @@ static void swipe_track(bool pressed, uint16_t x, uint16_t y)// LVGL reads the latest touch point. Marshalled by LVGL's own task; reading the// CST9217 over I2C from here is fine (LVGL task holds no conflicting lock).-static bool touch_open(void);static void touch_reinit(void);-static const char *touch_chip_name(void)+// The board's own, so a new controller needs no case here (touch_ctrl.h).+#define touch_chip_name() touch_ctrl_name()++/*+ * PINCH IN — two fingers closing — means "out one level".+ *+ * The grid is the fleet seen from above and an agent is the fleet seen from inside, so closing the hand+ * goes out and there is nothing else it could mean. It is also the only gesture left that collides with+ * nothing: one finger sideways walks the siblings, one finger up and down scrolls the agent's lists, and+ * a pull from the top edge is the drawer.+ *+ * WHY THIS LIVES HERE AND NOT IN LVGL. An `lv_indev` of type POINTER carries ONE point, by design — there+ * is nowhere in it to put a second finger. The controller has them: esp_lcd_touch_get_coordinates() fills+ * as many as you ask for and the GT911 reports five. So this file reads two, recognises the shape itself,+ * and hands LVGL the first point exactly as it always did. LVGL never learns that the second finger+ * existed, which is what keeps every screen's buttons behaving the same way.+ *+ * The thresholds are deliberately loose. A pinch on a device lying flat on a desk is a thumb and one+ * finger, not a precise two-handed gesture, and the cost of missing one is that the person pinches again+ * — while the cost of firing on a stray second contact is a screen that leaves under their hand.+ */+#define PINCH_MIN_START_PX 120 // the fingers must START this far apart, or it is a fumbled single touch+#define PINCH_CLOSE_RATIO 60 // …and end at most this % of that distance+#define PINCH_MIN_TRAVEL_PX 60 // …having actually closed by this much, so a slow drift is not a pinch++static int32_t s_pinch_start_d; // distance when the second finger landed, 0 when not tracking+static bool s_pinch_fired; // once per two-finger press++static int32_t touch_span(const uint16_t *xs, const uint16_t *ys){- return board()->touch == TOUCH_CST816S ? "CST816S" : board()->touch == TOUCH_CST9217 ? "CST9217" : "no-touch";+ const int32_t dx = (int32_t)xs[0] - (int32_t)xs[1];+ const int32_t dy = (int32_t)ys[0] - (int32_t)ys[1];+ // Manhattan rather than Euclidean: no sqrt on the LVGL task, and for "did they close" the difference+ // between the two is a constant factor that the thresholds above already absorb.+ return (dx < 0 ? -dx : dx) + (dy < 0 ? -dy : dy);+}++// Returns true when this sample completes a pinch-in. Fed every read, with however many points the+// controller gave us.+static bool pinch_track(uint8_t count, const uint16_t *xs, const uint16_t *ys)+{+ // Nothing to go out TO on a face with no desk (UI_DESK_GRID), so the gesture is not merely inert+ // there — it is not tracked at all. Left tracking, a stray second contact on the dial would swallow+ // the press that carried it and the finger would land on nothing.+ if (!UI_DESK_GRID) return false;+ if (count < 2) { s_pinch_start_d = 0; s_pinch_fired = false; return false; }+ const int32_t d = touch_span(xs, ys);+ if (s_pinch_start_d == 0) {+ // The second finger has just landed. Remember how far apart they were; a pair that starts close+ // together cannot pinch, which is what stops a palm resting on the glass from navigating.+ s_pinch_start_d = d > PINCH_MIN_START_PX ? d : -1;+ return false;+ }+ if (s_pinch_start_d < 0 || s_pinch_fired) return false;+ if (s_pinch_start_d - d < PINCH_MIN_TRAVEL_PX) return false;+ if (d * 100 > s_pinch_start_d * PINCH_CLOSE_RATIO) return false;+ s_pinch_fired = true;+ ESP_LOGI(TAG, "gesture: pinch in (%d → %d px) → out one level", (int)s_pinch_start_d, (int)d);+ return true;}static void touch_read(lv_indev_t *indev, lv_indev_data_t *data)@@ -312,7 +387,10 @@ static void touch_read(lv_indev_t *indev, lv_indev_data_t *data)data->state = LV_INDEV_STATE_RELEASED;return;}- uint16_t x = 0, y = 0, strength = 0;+ // TWO points, not one. The extra is only ever read by pinch_track(); everything below this line+ // uses xs[0]/ys[0] and behaves exactly as it did when one was all that was fetched.+ uint16_t xs[2] = { 0, 0 }, ys[2] = { 0, 0 }, ss[2] = { 0, 0 };+ uint16_t x = 0, y = 0;uint8_t cnt = 0;esp_err_t rc = esp_lcd_touch_read_data(s_tp);bool pressed;@@ -320,8 +398,8 @@ static void touch_read(lv_indev_t *indev, lv_indev_data_t *data)if (rc == ESP_OK) {s_read_fail_run = 0;s_noack_run = 0;- pressed = esp_lcd_touch_get_coordinates(s_tp, &x, &y, &strength, &cnt, 1) && cnt > 0;- if (pressed) ok_reads++;+ pressed = esp_lcd_touch_get_coordinates(s_tp, xs, ys, ss, &cnt, 2) && cnt > 0;+ if (pressed) { x = xs[0]; y = ys[0]; ok_reads++; }} else if (rc == ESP_ERR_INVALID_RESPONSE && board()->touch == TOUCH_CST9217) {// CST9217 ONLY. The CST816S driver answers ESP_OK on every idle read (measured on that board, 30/30)// and clears its own point table, so this rule would have nothing to do there — and must not run@@ -338,7 +416,8 @@ static void touch_read(lv_indev_t *indev, lv_indev_data_t *data)// Three misses in a row (~100ms) before the finger is declared gone, so one dropped sample// mid-drag cannot split a stroke in two.s_read_fail_run = 0;- pressed = esp_lcd_touch_get_coordinates(s_tp, &x, &y, &strength, &cnt, 1) && cnt > 0;+ pressed = esp_lcd_touch_get_coordinates(s_tp, xs, ys, ss, &cnt, 2) && cnt > 0;+ if (pressed) { x = xs[0]; y = ys[0]; }if (pressed && ++s_noack_run >= NOACK_RELEASE_READS) {ESP_LOGW(TAG, "release inferred: no ACK for %u reads while held at (%u,%u) — the chip's release frame was missed",(unsigned)s_noack_run, x, y);@@ -365,6 +444,20 @@ static void touch_read(lv_indev_t *indev, lv_indev_data_t *data)touch_reinit();}}+ /*+ * The second finger, before anything else looks at the first.+ *+ * Acted on HERE rather than at release, for the same reason the BOOT press is: a pinch is finished+ * the moment the fingers have closed, and waiting for them to lift would leave the screen sitting+ * there after the hand had already said what it meant. The rest of the press is then swallowed, so+ * the fingers coming apart again cannot be read as a swipe on the screen that just arrived.+ */+ if (pinch_track(cnt, xs, ys)) {+ s_swallow_until_release = true;+ scroll_abort();+ if (!display_is_asleep()) ui_desk_open(); // takes the lock itself+ }+if (pressed && !activity_prev) {s_activity_gen++;s_presses++;@@ -430,9 +523,23 @@ static void touch_read(lv_indev_t *indev, lv_indev_data_t *data)// top of the face, inside a 90px band this would otherwise swallow whole, so the one control// that leaves the screen could never be pressed. A modal chooser also has no business// offering a pull-to-notifications on top of itself.+ // …and, on the Pro, not on its fixed tab line, which sits inside this band by design: it is+ // the first thing on the glass, so the band would swallow every tap on the one control that+ // is always there. Same exemption as the bell, immediately above.+ //+ // #if, not a runtime `if`: the round face has no such line and this is the dial's own touch+ // path, which must come out of the compiler unchanged — the whole square port is held to that.s_band_drag = !display_is_asleep() && !ui_reader_is_open() && !ui_switch_is_open() &&!ui_picker_is_open() && !ui_notif_pill_hit(x, y) &&+#if UI_DESK_GRID+ /* …and, on the Pro, below the fixed tab line: the band's depth overlaps it, and a+ * press it captures is a tab press that never happens. The floor applies only to+ * STARTING one — an open drawer still owns the whole face, as it must to be closed. */+ (ui_notif_is_open() ||+ (y >= ui_notif_band_top_px() && y < ui_notif_pull_zone_px()));+#else(ui_notif_is_open() || y < ui_notif_pull_zone_px());+#endifndy0 = ndyl = y; ncap = s_band_drag;if (s_band_drag) ESP_LOGI(TAG, "band: captured at y=%u (drawer %s)", y, ui_notif_is_open() ? "open" : "closed");} else if (pressed && s_band_drag) {@@ -523,52 +630,6 @@ static void touch_read(lv_indev_t *indev, lv_indev_data_t *data)// Bring the touch controller up on the shared bus — whichever one this dial has (board.h). Everything// that can fail, logs and leaves s_tp NULL.-static bool touch_open(void)-{- i2c_master_bus_handle_t bus = board_i2c_get();- if (!bus) {- ESP_LOGW(TAG, "shared i2c bus unavailable — touch disabled");- return false;- }- const board_t *b = board();- if (b->touch == TOUCH_NONE) {- ESP_LOGW(TAG, "no touch controller answered on the bus — touch disabled");- return false;- }-- esp_lcd_panel_io_i2c_config_t io_cfg = b->touch == TOUCH_CST816S- ? (esp_lcd_panel_io_i2c_config_t)ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG()- : (esp_lcd_panel_io_i2c_config_t)ESP_LCD_TOUCH_IO_I2C_CST9217_CONFIG();- io_cfg.scl_speed_hz = BSP_I2C_FREQ_HZ;- if (esp_lcd_new_panel_io_i2c(bus, &io_cfg, &s_tp_io) != ESP_OK) {- ESP_LOGW(TAG, "touch panel io failed — touch disabled");- s_tp_io = NULL;- return false;- }-- esp_lcd_touch_config_t tp_cfg = {- .x_max = 466,- .y_max = 466,- .rst_gpio_num = b->touch_rst,- .int_gpio_num = BSP_TOUCH_INT,- // The CST9217 is mounted 180° relative to the CO5300 on its board, so BOTH axes are reversed vs- // the display (horizontal swipe and vertical scroll/taps). The CST816S reports panel-aligned- // coordinates — measured: mirrored, a touch landed 180° from the finger.- .flags = { .swap_xy = 0, .mirror_x = b->touch_mirror, .mirror_y = b->touch_mirror },- };- esp_err_t err = b->touch == TOUCH_CST816S- ? esp_lcd_touch_new_i2c_cst816s(s_tp_io, &tp_cfg, &s_tp)- : esp_lcd_touch_new_i2c_cst9217(s_tp_io, &tp_cfg, &s_tp);- if (err != ESP_OK) {- ESP_LOGW(TAG, "%s init failed (%s) — touch disabled", touch_chip_name(), esp_err_to_name(err));- s_tp = NULL;- esp_lcd_panel_io_del(s_tp_io);- s_tp_io = NULL;- return false;- }- return true;-}-// Tear the controller down and bring it back. Runs on the LVGL task (the indev read), where the driver's// own I2C use already lives, so nothing else can be mid-transaction with it. The first real FIX in this// file rather than a description: a controller that stopped answering gets a reset and a fresh init, and@@ -577,7 +638,7 @@ static void touch_reinit(void){if (s_tp) { esp_lcd_touch_del(s_tp); s_tp = NULL; }if (s_tp_io) { esp_lcd_panel_io_del(s_tp_io); s_tp_io = NULL; }- if (touch_open()) ESP_LOGI(TAG, "%s back after reinit", touch_chip_name());+ if (touch_ctrl_open(&s_tp_io, &s_tp)) ESP_LOGI(TAG, "%s back after reinit", touch_chip_name());else ESP_LOGW(TAG, "%s reinit failed — retrying in %ds", touch_chip_name(), REINIT_RETRY_MS / 1000);}@@ -593,7 +654,7 @@ void touch_stats(touch_stats_t *out)void touch_init(void){- if (!touch_open()) return;+ if (!touch_ctrl_open(&s_tp_io, &s_tp)) return;lv_indev_t *indev = lv_indev_create();lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);diff --git a/devices/harness-device/firmware/main/ui/touch_cst.c b/devices/harness-device/firmware/main/ui/touch_cst.cnew file mode 100644index 000000000..50f07b8d0--- /dev/null+++ b/devices/harness-device/firmware/main/ui/touch_cst.c@@ -0,0 +1,74 @@+/*+ * The round dial's touch controllers: CST9217 or CST816S, whichever answered the bus at boot.+ *+ * Lifted out of ui/touch.c when the square board arrived, and unchanged in the lifting. Two dials ship+ * from one image and differ here, which is why this still branches at RUNTIME on board()->touch — that+ * is a different axis from the compile-time one that chose this file over touch_gt911.c.+ */+#include "touch_ctrl.h"++#include "board.h"+#include "board_pins.h"+#include "board_i2c.h"+#include "ui_metrics.h"++#include "esp_lcd_touch_cst816s.h"+#include "esp_lcd_touch_cst9217.h"+#include "esp_log.h"++static const char *TAG = "touch";++const char *touch_ctrl_name(void)+{+ return board()->touch == TOUCH_CST816S ? "CST816S" : board()->touch == TOUCH_CST9217 ? "CST9217" : "no-touch";+}++bool touch_ctrl_open(esp_lcd_panel_io_handle_t *out_io, esp_lcd_touch_handle_t *out_tp)+{+ esp_lcd_panel_io_handle_t s_tp_io = NULL;+ esp_lcd_touch_handle_t s_tp = NULL;+ i2c_master_bus_handle_t bus = board_i2c_get();+ if (!bus) {+ ESP_LOGW(TAG, "shared i2c bus unavailable — touch disabled");+ return false;+ }+ const board_t *b = board();+ if (b->touch == TOUCH_NONE) {+ ESP_LOGW(TAG, "no touch controller answered on the bus — touch disabled");+ return false;+ }++ esp_lcd_panel_io_i2c_config_t io_cfg = b->touch == TOUCH_CST816S+ ? (esp_lcd_panel_io_i2c_config_t)ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG()+ : (esp_lcd_panel_io_i2c_config_t)ESP_LCD_TOUCH_IO_I2C_CST9217_CONFIG();+ io_cfg.scl_speed_hz = BSP_I2C_FREQ_HZ;+ if (esp_lcd_new_panel_io_i2c(bus, &io_cfg, &s_tp_io) != ESP_OK) {+ ESP_LOGW(TAG, "touch panel io failed — touch disabled");+ s_tp_io = NULL;+ return false;+ }++ esp_lcd_touch_config_t tp_cfg = {+ .x_max = UI_FACE_W,+ .y_max = UI_FACE_H,+ .rst_gpio_num = b->touch_rst,+ .int_gpio_num = BSP_TOUCH_INT,+ // The CST9217 is mounted 180° relative to the CO5300 on its board, so BOTH axes are reversed vs+ // the display (horizontal swipe and vertical scroll/taps). The CST816S reports panel-aligned+ // coordinates — measured: mirrored, a touch landed 180° from the finger.+ .flags = { .swap_xy = 0, .mirror_x = b->touch_mirror, .mirror_y = b->touch_mirror },+ };+ esp_err_t err = b->touch == TOUCH_CST816S+ ? esp_lcd_touch_new_i2c_cst816s(s_tp_io, &tp_cfg, &s_tp)+ : esp_lcd_touch_new_i2c_cst9217(s_tp_io, &tp_cfg, &s_tp);+ if (err != ESP_OK) {+ ESP_LOGW(TAG, "%s init failed (%s) — touch disabled", touch_ctrl_name(), esp_err_to_name(err));+ s_tp = NULL;+ esp_lcd_panel_io_del(s_tp_io);+ s_tp_io = NULL;+ return false;+ }+ *out_io = s_tp_io;+ *out_tp = s_tp;+ return true;+}diff --git a/devices/harness-device/firmware/main/ui/touch_ctrl.h b/devices/harness-device/firmware/main/ui/touch_ctrl.hnew file mode 100644index 000000000..670b8143d--- /dev/null+++ b/devices/harness-device/firmware/main/ui/touch_ctrl.h@@ -0,0 +1,19 @@+// Opening the board's touch controller — the one part of ui/touch.c that is not the same on both boards.+//+// Everything else in that file turned out to be portable already: the swipe tracker, the double-tap+// window, the edge bands, the stuck-press watchdog, the reinit-on-silence loop. Even the one chip quirk+// it carries (the CST9217's missing ACK) was already gated on board()->touch rather than compiled in.+// So the split is this small: hand back an opened controller and say what it is called.+#pragma once++#include <stdbool.h>++#include "esp_lcd_panel_io.h"+#include "esp_lcd_touch.h"++// Open the controller this board has. On success both handles are set and true is returned; on failure+// nothing is left allocated and touch.c retries on its own schedule.+bool touch_ctrl_open(esp_lcd_panel_io_handle_t *out_io, esp_lcd_touch_handle_t *out_tp);++// For the log lines: "CST9217", "GT911", … Never NULL.+const char *touch_ctrl_name(void);diff --git a/devices/harness-device/firmware/main/ui/touch_gt911.c b/devices/harness-device/firmware/main/ui/touch_gt911.cnew file mode 100644index 000000000..0bc85cd72--- /dev/null+++ b/devices/harness-device/firmware/main/ui/touch_gt911.c@@ -0,0 +1,122 @@+/*+ * Harness Pro touch: opening a GT911 on the shared I2C bus.+ *+ * Only the opening. Everything a finger then does — the swipe tracker, the double-tap window, the edge+ * bands, the stuck-press watchdog, the reinit-on-silence loop — is ui/touch.c, unchanged, shared with+ * the dial. See touch_ctrl.h.+ *+ * ⚠️ THE RESET SEQUENCE BELOW IS THE WHOLE POINT OF THIS FILE, and it is not a formality.+ *+ * A GT911 chooses its own I2C address from the level of its INT pin at the RISING EDGE of its RESET:+ * INT low picks 0x5D, INT high picks 0x14. So the pins have to be driven in one specific order, and the+ * order has to complete before anything probes the bus. Get it wrong — most easily by leaving INT+ * floating while reset is released — and the chip comes up at an address nobody is looking at, or does+ * not come up at all. The symptom is a touch controller that "is not on the bus", which sends you+ * looking at wiring that is fine.+ *+ * Because this is done by hand, the driver is then told GPIO_NUM_NC for its own reset pin. Given the+ * real pin it would pulse it again on open, with INT already switched to an input, and undo exactly the+ * choice made here. The dial has nothing like this: its CST controllers take a plain reset pulse.+ */+#include "touch_ctrl.h"++#include "board_i2c.h"+#include "board_pins.h"+#include "ui_metrics.h"++#include "driver/gpio.h"+#include "esp_lcd_touch_gt911.h"+#include "esp_log.h"+#include "freertos/FreeRTOS.h"+#include "freertos/task.h"++static const char *TAG = "touch";++const char *touch_ctrl_name(void) { return "GT911"; }++/* INT low → RESET low 20 ms → RESET high → 50 ms to settle → INT released to input.+ * The 20 ms and the 50 ms are the vendor's, and both matter: the first is the reset pulse the chip+ * needs to see, the second is how long it takes to read its own straps and answer on the bus. */+static void reset_into_primary_address(void)+{+ const gpio_config_t out = {+ .pin_bit_mask = (1ULL << BSP_TOUCH_RST) | (1ULL << BSP_TOUCH_INT),+ .mode = GPIO_MODE_OUTPUT,+ .pull_up_en = GPIO_PULLUP_DISABLE,+ .pull_down_en = GPIO_PULLDOWN_DISABLE,+ .intr_type = GPIO_INTR_DISABLE,+ };+ gpio_config(&out);++ gpio_set_level(BSP_TOUCH_INT, 0); /* the strap: low selects 0x5D */+ gpio_set_level(BSP_TOUCH_RST, 0);+ vTaskDelay(pdMS_TO_TICKS(20));+ gpio_set_level(BSP_TOUCH_RST, 1); /* the edge that latches the address */+ vTaskDelay(pdMS_TO_TICKS(50));++ const gpio_config_t in = {+ .pin_bit_mask = 1ULL << BSP_TOUCH_INT,+ .mode = GPIO_MODE_INPUT,+ .pull_up_en = GPIO_PULLUP_DISABLE,+ .pull_down_en = GPIO_PULLDOWN_DISABLE,+ .intr_type = GPIO_INTR_DISABLE,+ };+ gpio_config(&in);+}++bool touch_ctrl_open(esp_lcd_panel_io_handle_t *out_io, esp_lcd_touch_handle_t *out_tp)+{+ reset_into_primary_address();++ i2c_master_bus_handle_t bus = board_i2c_get();+ if (!bus) {+ ESP_LOGW(TAG, "shared i2c bus unavailable — touch disabled");+ return false;+ }++ /* Which address answered is a FACT ABOUT THE BOARD, not a preference: the strap above should make it+ * 0x5D every time, so a board that answers on 0x14 means the sequence did not take and is worth a+ * line in the log rather than a silent fallback. */+ esp_lcd_panel_io_i2c_config_t io_cfg = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG();+ io_cfg.scl_speed_hz = BSP_I2C_FREQ_HZ;+ if (i2c_master_probe(bus, BSP_TOUCH_ADDR, 50) != ESP_OK) {+ if (i2c_master_probe(bus, BSP_TOUCH_ADDR_ALT, 50) != ESP_OK) {+ ESP_LOGW(TAG, "GT911 answered at neither 0x%02X nor 0x%02X — check the reset order",+ BSP_TOUCH_ADDR, BSP_TOUCH_ADDR_ALT);+ return false;+ }+ ESP_LOGW(TAG, "GT911 came up at its backup address 0x%02X — the INT strap did not take",+ BSP_TOUCH_ADDR_ALT);+ io_cfg.dev_addr = BSP_TOUCH_ADDR_ALT;+ }++ esp_lcd_panel_io_handle_t io = NULL;+ if (esp_lcd_new_panel_io_i2c(bus, &io_cfg, &io) != ESP_OK) {+ ESP_LOGW(TAG, "touch panel io failed — touch disabled");+ return false;+ }++ const esp_lcd_touch_config_t cfg = {+ .x_max = UI_FACE_W,+ .y_max = UI_FACE_H,+ /* Both NC on purpose. Reset is done above and must not be repeated; the interrupt pin is read by+ * polling, as on the dial — an ISR buys nothing at 30 Hz.+ *+ * No mirror and no swap: confirmed on the glass, a touch on the top-left corner mark puts the+ * cursor on the top-left corner. The dial's CST9217 needs both axes reversed; this one does not. */+ .rst_gpio_num = GPIO_NUM_NC,+ .int_gpio_num = GPIO_NUM_NC,+ .flags = { .swap_xy = 0, .mirror_x = 0, .mirror_y = 0 },+ };+ esp_lcd_touch_handle_t tp = NULL;+ if (esp_lcd_touch_new_i2c_gt911(io, &cfg, &tp) != ESP_OK) {+ ESP_LOGW(TAG, "GT911 init failed — touch disabled");+ esp_lcd_panel_io_del(io);+ return false;+ }++ ESP_LOGI(TAG, "GT911 @ 0x%02X · %dx%d", io_cfg.dev_addr, UI_FACE_W, UI_FACE_H);+ *out_io = io;+ *out_tp = tp;+ return true;+}diff --git a/devices/harness-device/firmware/main/ui/ui_metrics.h b/devices/harness-device/firmware/main/ui/ui_metrics.hnew file mode 100644index 000000000..f7c0f3593--- /dev/null+++ b/devices/harness-device/firmware/main/ui/ui_metrics.h@@ -0,0 +1,24 @@+// Where things sit on the glass — the one file that differs between a round face and a square one.+//+// ui_screens.c used to carry these itself, and every value in it was a device pixel on a 466 circle.+// That was not a style: a round face eats its own corners, so the numbers were measured against a+// CHORD rather than a margin, and several of them say so in their comments. A square face has no such+// constraint, so the two sets below are re-derived rather than scaled.+//+// WHAT IS NOT HERE: type sizes. The two panels are 10.48 and 10.01 pixels per millimetre — within 5% —+// so a 38px name is the same size against a thumb on both, and the fonts are shared unchanged. Scaling+// type with the resolution would make the Pro read like a tablet held at arm's length.+//+// metrics_round466.h holds exactly what shipped. If a value in it ever changes, that is a change to the+// dial and must be treated as one.+#pragma once++#include "sdkconfig.h"++#if defined(CONFIG_IDF_TARGET_ESP32P4)+#include "metrics_square720.h"+#elif defined(CONFIG_IDF_TARGET_ESP32S3)+#include "metrics_round466.h"+#else+#error "no screen metrics for this target"+#endifdiff --git a/devices/harness-device/firmware/main/ui/ui_screens.c b/devices/harness-device/firmware/main/ui/ui_screens.cindex 7db93c774..addcc74b8 100644--- a/devices/harness-device/firmware/main/ui/ui_screens.c+++ b/devices/harness-device/firmware/main/ui/ui_screens.c@@ -1,3 +1,4 @@+#include "ui_metrics.h"#include "ui_screens.h"#include "carousel_ring.h"#include "display.h"@@ -61,9 +62,6 @@ extern const lv_font_t geist_sem_24; // largest display: tile agent name + over// so nothing reaches the curved edge. 330px is the widest column whose corners never clip; centred// text makes the side margins read as intentional. Both axes centred + short content = stays in the// circle's safe band (no top/bottom arc clip).-#define SCREEN_PAD 18-#define SAFE_CONTENT_W 384 // centred column for readable content — wide, since content sits in the- // circle's mid band where the usable width is much larger than the inscribed square// The Overview's seats (mockup/overview-v3.html, "H · Halo, no ring"). FIXED, not a growing column: nothing// moves when the status changes, the words change. Every number is a device pixel on the 466 face; the far// corner of every control is inside the 233px rim, above the home-swipe band (y ≥ 400) and below the@@ -72,29 +70,15 @@ extern const lv_font_t geist_sem_24; // largest display: tile agent name + over// The shape follows what round devices agree on — the centre is one number, the lower arc is for the// hand: Inbox · Voice · Settings on one arc, Voice larger and on the axis, wearing the same 44px mic the// agent tile wears. Goal and Loop are gone from this face: they are ways of speaking, not things to see.-#define OV_ROW_Y 118 // "8 agents" on one baseline: the count in the 64px digits face, the word at 38-#define OV_NUM_H 72 // the row's height — the digit's line box-#define OV_ROW_GAP 14 // between the digit and the word-#define OV_STATUS_Y 204 // "N working" / "All idle", Geist 38-#define OV_SIDE_D 64 // Inbox and Settings: 64px rounds, 30px glyphs, centred on y=340-#define OV_BELL_X 78-#define OV_GEAR_X 324-#define OV_SIDE_Y 308// Voice: an 88px round on the axis, no caption (owner: "bỏ chữ Voice luôn, icon là đủ") — the caption's// height went to the button — and dropped 50px below the sides (centre y=390; owner, twice: 10 then 30// more) so the three follow the bezel the way the old arc did, the middle one nearest the resting thumb.// Its lowest point is 434, 201px from the centre, 32px inside the rim. Its lower third is in the home// band: a tap there is a tap, and a swipe up that starts on it is the button's, so the home gesture is// made from beside it, as it always was with a button on the axis.-#define OV_VOICE_D 88-#define OV_VOICE_X 189-#define OV_VOICE_Y 346-#define SAFE_W lv_pct(72) // ~335px — wrapped text on the side screens stays inside the curve// MAX_PROJECTS comes from commander_client.h (shared with app_main's fetch buffers) so the UI tile// array and the WS fetch never disagree; the UI keeps only a shell per project + a materialized window.#define MAX_EVENTS 1 // tile shows only the latest event (the most recent summary)-#define TODO_VISIBLE_ROWS 4 // todo checklist shows this many rows; the rest scroll (keeps status on screen)-#define AGENTS_VISIBLE_ROWS 3 // sub-agent list shows this many rows; the rest scroll (coexists with the tool line)#define BUSY_DOTS 3 // "processing" indicator = this many blinking dots (a loading animation)#define PREVIEW_BYTES 220 // tile teaser length (bytes, UTF-8 safe) — one card has room for a longer// tease; full text still via tap-to-read@@ -133,9 +117,6 @@ extern const lv_font_t geist_sem_24; // largest display: tile agent name + over// Settings list geometry (Figma): uniform rows, stacked contiguously, four of them inside the round face.// 320 wide only fits the circle between y~64 and y~402 — 338px, i.e. exactly four 84px rows, which is why// the fifth has to be scrolled to rather than squeezed in.-#define SET_ROW_W 320-#define SET_ROW_H 84-#define SET_LIST_PAD 65 // first row starts where the design puts it; the list scrolls by one row// The label font of a settings row, referenced ONCE so the one-line height pin, the default trailing// font and the baseline nudge can never drift from it — they did, and a 32px label ended up pinned// into a 28px box.@@ -143,7 +124,6 @@ extern const lv_font_t geist_sem_24; // largest display: tile agent name + over#define COL_SET_ICON lv_color_hex(0xffffff) // settings row icon (white, per New Setting Figma)#define COL_BRIGHT lv_color_hex(0x059600) // brightness fill — the green the Figma track starts from-#define PAIR_W 360static lv_obj_t *scr_pairing, *scr_connecting, *scr_error, *scr_projects;static lv_obj_t *scr_reader, *reader_lbl; // full-screen scrollable reader for one event's full text@@ -423,6 +403,21 @@ static void chip_clip(const char *src, char *out, size_t cap, size_t max_glyphs)static void tile_changed(lv_event_t *e); // tileview swipe tracker (defined below)static void carousel_scroll(lv_event_t *e); // per-frame leading-edge cover for the 1-agent ring (defined below)static void rebuild_page_dots(void); // (re)build the bottom page-indicator dots (defined below)+#if UI_DESK_GRID+static void tabline_sync(void); // show/hide the fixed tab line for the face on screen (defined below)+static void tabline_rebuild(void); // …redraw it from the swarm model+static void tabline_repaint(void); // …or just move the fill, keeping the buttons and the scroll+static void desk_rebuild(void); // the desk's tiles, from the agent model+// A tab was just picked and the ring for it has not arrived. The grid draws nothing while this holds —+// see desk_tab_tap. Bounded in time as well as by the ring, so a push that never comes cannot leave an+// empty face: past DESK_PENDING_MS the grid gives up waiting and draws what it knows.+static bool s_desk_pending;+static uint32_t s_desk_pending_ms;+#define DESK_PENDING_MS 1200+static bool desk_is_open_raw(void);+static bool desk_has_a_shape(void); // …and whether a grid of it is worth drawing at all+static void desk_only_agent(char *out, size_t cap);+#endifstatic void rebuild_overview_tile(void); // refresh the overview tile's "N agents" label (defined below)static void overview_actions_apply(void);// enable/disable the Overview Voice / Goal / Loop actionsstatic void overview_working_apply(void);// refresh the "<N> <gerund>…" sub-line from the agents' busy_model flags@@ -456,7 +451,6 @@ static int find_proj(const char *id); // index of the project with th#define PICK_OWNER_LANG 1 // voice language — local, persisted to NVS#define PICK_OWNER_ACTION 2 // Voice / Goal / Loop — starts a turn on the active agent// Half the screen minus half a row: what lets the FIRST and LAST row reach the middle of the wheel.-#define PICK_PAD_V 200// The wheel has TWO owners: the per-agent Model/Effort profile, and Settings > Voice language. It once// had a third (an auto|goal|loop mode picker) whose flag was removed when the three action buttons// replaced it — this brings a flag back, deliberately. The two owners commit to different places@@ -591,8 +585,8 @@ static const char *tile_resting_text(const proj_t *p)// LV_SCROLL_SNAP_CENTER + LV_OBJ_FLAG_SCROLL_ONE (exactly what lv_tileview uses internally, so the feel// is identical), and each tile is positioned at column*width. carousel_goto centers a column;// carousel_col reads which column is centered from the scroll position.-static int32_t carousel_w(void) { int32_t w = tileview ? lv_obj_get_width(tileview) : 0; return w > 0 ? w : 466; }-static int32_t carousel_h(void) { int32_t h = tileview ? lv_obj_get_height(tileview) : 0; return h > 0 ? h : 466; }+static int32_t carousel_w(void) { int32_t w = tileview ? lv_obj_get_width(tileview) : 0; return w > 0 ? w : UI_FACE_W; }+static int32_t carousel_h(void) { int32_t h = tileview ? lv_obj_get_height(tileview) : 0; return h > 0 ? h : UI_FACE_H; }// A REPORT LEAVES THE DIAL ONLY WHEN A FINGER MOVED THE CAROUSEL.//// Everything that moves it from code — a rebuilt list re-anchoring, the ring count changing, a tile being@@ -1178,7 +1172,7 @@ static void wave_tick(lv_timer_t *t)int32_t h = (int32_t)s_wave_rest[k] * amp / 1000;if (h < 2) h = 2;lv_obj_set_height(s_wave[k], h);- lv_obj_set_y(s_wave[k], 233 - h / 2); // stay centred on the midline as it grows/shrinks+ lv_obj_set_y(s_wave[k], UI_CY - h / 2); // stay centred on the midline as it grows/shrinks}}// Start/stop the waveform: spin up the shared travelling-phase timer and seed one frame immediately (so nothing@@ -1327,14 +1321,11 @@ static void busy_dots_tick(lv_timer_t *t)// security: a smudge trail on the AMOLED or a shoulder-surf can leak the shape — enough to stop a// passer-by poking your agents, not a determined attacker.enum { LK_UNLOCK, LK_SET, LK_CONFIRM, LK_DISABLE };-#define LK_GAP 113 // dot spacing (px) — matches the "Create your pattern" Figma grid#define COL_LOCK_DOT lv_color_hex(0xffffff) // idle pattern dot (white, per Figma)#define COL_LOCK_GREEN lv_color_hex(0x75f958) // selected dot + line (bright green, per Figma)#define LK_HIT 44 // finger hit radius around a dot (< GAP/2 so adjacent dots don't co-trigger)#define LK_MIN 4 // minimum dots in a valid pattern#define LK_MAX_FAIL 5 // wrong unlock tries → unpair (wipe token + passcode) + reboot to pairing-#define LK_CX 233 // grid centre x-#define LK_CY 233 // grid centre y — screen centre (flat, dots-only)static lv_obj_t *s_lk_overlay;static lv_obj_t *s_lk_msg; // single message line ABOVE the grid (instruction / error). Empty@@ -1504,7 +1495,7 @@ static void lk_build(void)if (s_lk_overlay) return;lv_obj_t *ov = lv_obj_create(lv_layer_top());lv_obj_remove_style_all(ov);- lv_obj_set_size(ov, 466, 466);+ lv_obj_set_size(ov, UI_FACE_W, UI_FACE_H);lv_obj_set_pos(ov, 0, 0);lv_obj_set_style_bg_color(ov, COL_BG, 0); // flat black, like the originallv_obj_set_style_bg_opa(ov, LV_OPA_COVER, 0);@@ -1922,7 +1913,7 @@ void ui_init(void)s_overview_actions = lv_obj_create(s_overview_tile);lv_obj_remove_style_all(s_overview_actions);lv_obj_clear_flag(s_overview_actions, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);- lv_obj_set_size(s_overview_actions, 466, 466);+ lv_obj_set_size(s_overview_actions, UI_FACE_W, UI_FACE_H);lv_obj_set_pos(s_overview_actions, 0, 0);// A round control: transparent-ish ghost for the two sides, Voice's own green pair for the middle.@@ -2090,8 +2081,8 @@ void ui_init(void)lv_obj_set_style_radius(s_wave[k], LV_RADIUS_CIRCLE, 0); // rounded capslv_obj_set_style_bg_color(s_wave[k], COL_VOICE, 0);lv_obj_set_style_bg_opa(s_wave[k], LV_OPA_COVER, 0);- int cx = 233 + (k - 3) * 224 / 10; // pitch 22.4px, symmetric about centre- lv_obj_set_pos(s_wave[k], cx - 3, 233 - s_wave_rest[k] / 2);+ int cx = UI_CX + (k - 3) * WAVE_PITCH_X10 / 10; // pitch 22.4px, symmetric about centre+ lv_obj_set_pos(s_wave[k], cx - 3, UI_CY - s_wave_rest[k] / 2);lv_obj_remove_flag(s_wave[k], LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);lv_obj_add_flag(s_wave[k], LV_OBJ_FLAG_HIDDEN);}@@ -2428,7 +2419,7 @@ void ui_init(void)make_close_pill(s_notif_drawer, notif_bg_tap, 16);s_notif_list = lv_obj_create(s_notif_drawer); // scrollable column of cards (centered band, below the badge)lv_obj_remove_style_all(s_notif_list);- lv_obj_set_size(s_notif_list, 360, 320);+ lv_obj_set_size(s_notif_list, NOTIF_LIST_W, NOTIF_LIST_H);lv_obj_align(s_notif_list, LV_ALIGN_CENTER, 0, 34);lv_obj_set_flex_flow(s_notif_list, LV_FLEX_FLOW_COLUMN);lv_obj_set_style_pad_row(s_notif_list, 12, 0);@@ -2738,6 +2729,13 @@ void ui_land_after_reload(void)apply_active_from_col();update_content_window();rebuild_page_dots();+#if UI_DESK_GRID+ // …AND THEN THE DESK, which is what this face lands on. The carousel is still parked on the Overview+ // underneath, because that is what a back out of the grid and every swipe from here expects to find —+ // the desk is a face over the ring, not a replacement for it. What changes is which one you are+ // looking at when the machine's agents have finished arriving: the shape, not the count.+ ui_desk_open();+#endifdisplay_unlock();}@@ -3043,6 +3041,12 @@ static void agent_actions_apply(void)// ran. The ‹ › pair stays on a shell — moving on is always safe — so the arc is hidden as a whole// only when the tile is not an agent's at all, and Voice alone goes on a shell.set_hidden(s_agent_acts, !on);+#if UI_DESK_GRID+ // The fixed tab line answers to the same question this does — "what is on the face?" — so it rides+ // the same apply rather than a timer of its own. Every swipe, every turn edge, every wake and the+ // 1 Hz tick already reach here.+ tabline_sync();+#endifif (s_agent_voice_btn) set_hidden(s_agent_voice_btn, !on || is_terminal_tile(&s_proj[s_active_idx]));// …and ‹ › only where there is somewhere to go. A tab with ONE agent has no next and no previous, so// the pair leaves the arc entirely rather than sitting there greyed (owner, 2026-09-22: "khi tab chỉ@@ -3111,10 +3115,10 @@ static lv_obj_t *agent_step_glyph(lv_obj_t *parent, int dir)return l;}-static lv_obj_t *agent_act_btn(int32_t x, int32_t y, lv_event_cb_t cb)+static lv_obj_t *agent_act_btn(int32_t x, int32_t y, int32_t d, lv_event_cb_t cb){lv_obj_t *b = lv_button_create(s_agent_acts);- lv_obj_set_size(b, 80, 80);+ lv_obj_set_size(b, d, d);lv_obj_set_pos(b, x, y);lv_obj_set_style_bg_opa(b, LV_OPA_TRANSP, 0);lv_obj_set_style_bg_color(b, COL_FG, LV_STATE_PRESSED);@@ -3132,7 +3136,7 @@ static void build_agent_actions(void){s_agent_acts = lv_obj_create(scr_projects);lv_obj_remove_style_all(s_agent_acts);- lv_obj_set_size(s_agent_acts, 466, 466);+ lv_obj_set_size(s_agent_acts, UI_FACE_W, UI_FACE_H);lv_obj_set_pos(s_agent_acts, 0, 0);lv_obj_add_flag(s_agent_acts, LV_OBJ_FLAG_FLOATING | LV_OBJ_FLAG_HIDDEN);lv_obj_clear_flag(s_agent_acts, LV_OBJ_FLAG_SCROLLABLE | LV_OBJ_FLAG_CLICKABLE);@@ -3166,7 +3170,7 @@ static void build_agent_actions(void)// still reachable — a still hold on the tile is a Goal capture (touch.c) and the Overview keeps its// labelled Goal / Loop buttons. Set AGENT_TILE_GOAL_LOOP to 1 to draw the two marks again.#if AGENT_TILE_GOAL_LOOP- { lv_obj_t *b = agent_act_btn(79, 322, agent_goal_tap);+ { lv_obj_t *b = agent_act_btn(ACT_PREV_X, ACT_Y, ACT_BTN_D, agent_goal_tap);s_agent_goal_btn = b;lv_obj_t *ring = lv_obj_create(b);lv_obj_remove_style_all(ring);@@ -3189,7 +3193,7 @@ static void build_agent_actions(void)#endif// Voice — the centre of the arc, 31px lower than its neighbours (the ±36° offset). It does NOT move// sideways: it is the one under the resting thumb, and the other two spread away from it.- { lv_obj_t *b = agent_act_btn(193, 353, agent_voice_tap);+ { lv_obj_t *b = agent_act_btn(ACT_VOICE_X, ACT_VOICE_Y, ACT_VOICE_D, agent_voice_tap);s_agent_voice_btn = b;lv_obj_t *ic = lv_image_create(b);lv_image_set_src(ic, &icon_act_voice); // 44px native, colour baked — see the note on the asset@@ -3197,13 +3201,13 @@ static void build_agent_actions(void)// ‹ › — the previous/next pair, on the two arc spots Goal and Loop measured against the bezel// (owner, 2026-09-22, mockup option A: "vừa swipe được vừa bấm nút được"). Same 80px circles, same// pressed fill; the glyph is a 30px chevron in the muted ink.- { lv_obj_t *b = agent_act_btn(79, 322, agent_prev_tap);+ { lv_obj_t *b = agent_act_btn(ACT_PREV_X, ACT_Y, ACT_BTN_D, agent_prev_tap);s_agent_prev_btn = b;s_agent_prev_glyph = agent_step_glyph(b, -1);lv_obj_add_event_cb(b, agent_step_press, LV_EVENT_PRESSED, s_agent_prev_glyph);lv_obj_add_event_cb(b, agent_step_press, LV_EVENT_RELEASED, s_agent_prev_glyph);lv_obj_add_event_cb(b, agent_step_press, LV_EVENT_PRESS_LOST, s_agent_prev_glyph); }- { lv_obj_t *b = agent_act_btn(307, 322, agent_next_tap);+ { lv_obj_t *b = agent_act_btn(ACT_NEXT_X, ACT_Y, ACT_BTN_D, agent_next_tap);s_agent_next_btn = b;s_agent_next_glyph = agent_step_glyph(b, +1);lv_obj_add_event_cb(b, agent_step_press, LV_EVENT_PRESSED, s_agent_next_glyph);@@ -3213,7 +3217,7 @@ static void build_agent_actions(void)#if AGENT_TILE_GOAL_LOOP// Loop — the exported Figma repeat arrows, the same mark the Overview carries, and the mirror of Goal's// 20px push: 287 → 307.- { lv_obj_t *b = agent_act_btn(307, 322, agent_loop_tap);+ { lv_obj_t *b = agent_act_btn(ACT_NEXT_X, ACT_Y, ACT_BTN_D, agent_loop_tap);s_agent_loop_btn = b;lv_obj_t *ic = lv_image_create(b);lv_image_set_src(ic, &icon_act_loop); // 44px native, colour baked@@ -3292,6 +3296,27 @@ bool ui_action_hit(uint16_t x, uint16_t y)// Rebuilt on snap (tile_changed) + on list changes — never per-frame — so it's cheap and doesn't touch the WS.static void rebuild_page_dots(void){+#if UI_DESK_GRID+ // THE DESK IS THE HOME on this face, so it has to follow the model — and this is the one call every+ // path that changes what agents exist already makes. It was the dots' hook when there were dots; the+ // dots are gone and the grid inherits it rather than growing a second set of call sites that would+ // drift from these.+ // …and this IS the ring arriving, so whatever the desk was waiting for after a tab pick is here.+ s_desk_pending = false;+ if (desk_is_open_raw()) {+ if (!desk_has_a_shape()) {+ // The tab turned out to hold one agent. Close and land on it — and no recursion guard is+ // needed, because ui_desk_close() clears s_desk_open before ui_focus_project re-enters+ // here, so the second pass finds the desk shut and does nothing.+ char id[sizeof(s_proj[0].id)];+ desk_only_agent(id, sizeof id);+ ui_desk_close();+ if (id[0]) ui_focus_project(id);+ } else {+ desk_rebuild();+ }+ }+#endif// Page-indicator dots removed per design — keep the container empty + hidden. All callers stay no-ops.if (!page_dots) return;lv_obj_clean(page_dots);@@ -3457,7 +3482,6 @@ void ui_set_brightness(uint8_t level)// Figma "New Setting" (Brightness): the track is 427 wide at y=231, with the title above it at y=151.// 306 was the width from when this control was a row squeezed into the settings list; on its own screen// it gets the design's full width.-#define BRIGHT_BOX_W 427// The fill has a 20% floor: min brightness IS 20%, so the fill bottoms out at 1/5 of the box, never empty.#define BRIGHT_FILL_MIN (BRIGHT_BOX_W / 5)@@ -4523,7 +4547,6 @@ static char *dup_str(const char *s)// back without it left the words floating on the black face with nothing holding them. Same surface as// before — flat #23252f, 28px radius, a hairline at 20% — with the vertical padding down from 18 to 14:// the card holds two pinned lines now instead of a paragraph that could be one.-#define RECAP_MAX_CHARS 40#define RECAP_FONT (&geist_med_28)#define RECAP_LINE_SPACE 3#define RECAP_CARD_PAD_H 18@@ -4532,9 +4555,10 @@ static char *dup_str(const char *s)#define RECAP_CARD_PAD_V 19/** The text column inside the card: the safe width less the padding and the hairline each side. */#define RECAP_TEXT_W (SAFE_CONTENT_W - 2 * RECAP_CARD_PAD_H - 2)-/** The card's fixed height: two lines of recap, the space between them, the padding, and the 1px edge- * on each side. Fixed so the box does not breathe as the carousel moves between tiles. */-#define RECAP_CARD_H (2 * lv_font_get_line_height(RECAP_FONT) + RECAP_LINE_SPACE \+/** The card's fixed height: RECAP_LINES lines of recap, the spaces between them, the padding, and the+ * 1px edge on each side. Fixed so the box does not breathe as the carousel moves between tiles. */+#define RECAP_CARD_H (RECAP_LINES * lv_font_get_line_height(RECAP_FONT) \+ + (RECAP_LINES - 1) * RECAP_LINE_SPACE \+ 2 * RECAP_CARD_PAD_V + 2)static void tile_layout_apply(proj_t *p); // the tile's two layouts, chosen by state — defined with its macros below@@ -4588,8 +4612,8 @@ static void render_recap_block(proj_t *p)// chips use, for the same reason. The ellipsis is added here rather than by the cutter because only// this caller can tell a clip from a recap that was simply short.//- // The card is pinned to exactly two lines: 40 glyphs cannot need a third at this width, and pinning- // it keeps every tile's card the same size, so walking the carousel does not make the box breathe.+ // The card is pinned to RECAP_LINES, which keeps every tile's card the same size — walking the+ // carousel must not make the box breathe.//// THE PIN MOVED FROM THE LABEL TO THE CARD, and that is the whole fix. A label pinned to two lines// draws its text from the top, because LVGL labels have no vertical alignment — so a one-line recap@@ -4600,17 +4624,18 @@ static void render_recap_block(proj_t *p)char cut[RECAP_MAX_CHARS * 4 + 8];chip_clip(p->m_preview, cut, sizeof(cut) - 4, RECAP_MAX_CHARS);bool clipped = strlen(cut) < strlen(p->m_preview);- // TWO LINES BY MEASUREMENT, not by glyph count. Forty glyphs "cannot need a third line" only when- // the words break kindly; a recap of short words with diacritics wrapped onto three, and the card —- // pinned to two — sliced the third through the middle of its glyphs. So the text is laid out at the- // card's width and trimmed, a glyph at a time, until it fits in two lines with its "…" on the second.- const int32_t two_lines = 2 * lv_font_get_line_height(RECAP_FONT) + RECAP_LINE_SPACE;+ /* The card is pinned to RECAP_LINES, so the text is trimmed until it fits in exactly that many —+ * by MEASUREMENT, not by glyph count. A cap of N glyphs "cannot need another line" only when the+ * words break kindly; a recap of short words with diacritics wrapped one line further and the card,+ * pinned, sliced the last one through the middle of its glyphs. */+ const int32_t line_budget = RECAP_LINES * lv_font_get_line_height(RECAP_FONT)+ + (RECAP_LINES - 1) * RECAP_LINE_SPACE;for (;;) {char probe[sizeof(cut) + 4];snprintf(probe, sizeof probe, "%s%s", cut, clipped ? "\xE2\x80\xA6" : "");lv_point_t sz;lv_text_get_size(&sz, probe, RECAP_FONT, 0, RECAP_LINE_SPACE, RECAP_TEXT_W, LV_TEXT_FLAG_NONE);- if (sz.y <= two_lines || !cut[0]) break;+ if (sz.y <= line_budget || !cut[0]) break;// Drop the last glyph (UTF-8: back over continuation bytes) and any space it leaves behind.size_t n = strlen(cut);do { n--; } while (n > 0 && ((unsigned char)cut[n] & 0xC0) == 0x80);@@ -4662,19 +4687,15 @@ static void render_busy_row(proj_t *p)// a mismatch shows up as the tile shifting after every turn. The name sits at the mockup's y=124 — 15px// lower than it did, which is what losing the machine line under it paid for.// The chip row's own offset is NOT here — it is derived from the chip metrics in ctl_row_y().-#define TILE_PAD_TOP 119 // 84 → 117 → 112 → 109 → 124 → 109 → 119 (CTL_NAME_GAP: row stays at y=69)// Agent name BOTTOM → card top. The card is 2×28px lines + 14px padding + a hairline = 111px, so 21 puts// it at y=191 and ends it at y=302 — 20px clear of the action arc at y=322. It went 27 → 25 → 32 → 16 →// 11 → 21 as what sits under the name changed shape and then asked for more air around it.-#define TILE_NAME_GAP 21// The action arc — Goal / prev / next / Loop, built at y=322 in agent_actions_apply — and the air the// centred layout keeps above it. Named here because tile_center_if_cardless has to know where the// bottom of the face stops being free.-#define TILE_ARC_Y 322-#define TILE_ARC_GAP 20// ONE ANCHOR, TWO RESTING PLACES — and which one a tile uses is decided by whether it has a card.//@@ -5765,8 +5786,16 @@ int ui_notif_pull_zone_px(void)// ever swallowing presses — including the X at y=16..48 that closes the tile (owner, 2026-09-14:// "nút X tắt ở màn hình setting chưa work").if (lv_screen_active() == scr_projects && s_settings_active) return 0;+#if UI_DESK_GRID+ // ONE DEPTH ON THIS FACE, measured from the floor. The 44 below exists to protect the tab pill that+ // floats in the dial's top band; here that pill is gone — the fixed tab line carries the tab, and the+ // band starts underneath it — so there is nothing up there left to protect and no reason for the+ // agent screen to have the shallower band.+ return ui_notif_band_top_px() + 90;+#elsebool agent_tile = lv_screen_active() == scr_projects && !s_overview_active && !s_settings_active && !s_machines_active;return agent_tile ? 44 : 90; // narrow on agent tiles so the tab pill still gets taps+#endif}// A FOCUS THE RING COULD NOT HONOUR YET, kept until it can.@@ -5870,10 +5899,690 @@ static void overview_settings_tap(lv_event_t *e)// The home gesture is a TOGGLE between the two rings: from an agent it goes to the Overview; from the// Overview or Settings it goes back to the agent the strip was on. Nothing else crosses between them.+#if UI_DESK_GRID+// ── the desk grid ───────────────────────────────────────────────────────────────────────────────────+//+// The tab's agents, drawn in the arrangement the Mac has them in.+//+// THE POINT IS THAT YOU DO NOT READ IT. On the Mac, Lich su has been the tall pane on the left all+// morning; on this glass it is the tall tile on the left, so the hand goes there without the eye+// stopping to check. A sorted list is better when you are hunting for something; a map is better when+// you already know which one you mean, and beside a Mac showing the same shape that is most of the time.+//+// A tile therefore holds two things and no more: the engine's mark and the agent's name. Everything a+// tile could also say — the tool it is in, its todos, the seconds — is one tap away on the agent's own+// screen, where there is room to say it properly. Crowding it in here would cost the one thing this+// screen is for.+//+// The shapes below are the app's own (`desktop/lib/state/pane_preset.dart`), as thousandths so the+// arithmetic stays integer. The device is not told which shape a tab uses — `cable_swarm_t` carries the+// pane COUNT and nothing about their arrangement — so it draws the app's DEFAULT for that count. That is+// right whenever nobody chose otherwise, which is most tabs, and wrong in a mild way when they did: the+// same agents, differently arranged. Sending the preset id would close the gap; see the mockup.++typedef struct { int16_t x1, y1, x2, y2; } desk_rect_t; // thousandths of the canvas++// One left, two right (3); quadrants (4); centre-tall (5) — the defaults the app picks unasked.+static const desk_rect_t DESK_1[] = { {0,0,1000,1000} };+static const desk_rect_t DESK_2[] = { {0,0,500,1000}, {500,0,1000,1000} };+// THREE FULL-HEIGHT COLUMNS, not a main-left. The app's PanePreset.defaultFor(3) is `cols3`+// (desktop/lib/state/pane_preset.dart) — `mainLeft` is one of the shapes the picker OFFERS for three,+// and offering is not defaulting. Reading the picker's list instead of defaultFor is how this ended up+// drawing a shape a tab has to be deliberately put into (owner, 2026-09-27: "layout view ko giong app").+static const desk_rect_t DESK_3[] = { {0,0,333,1000}, {333,0,667,1000}, {667,0,1000,1000} };+static const desk_rect_t DESK_4[] = { {0,0,500,500}, {500,0,1000,500}, {0,500,500,1000}, {500,500,1000,1000} };+static const desk_rect_t DESK_5[] = { {0,0,333,500}, {333,0,667,1000}, {667,0,1000,500},+ {0,500,333,1000}, {667,500,1000,1000} };++#define DESK_MAX_TILES 9 // three columns by three rows; a tab with more shows the first nine and "+N"++// Fill `out` with the shape for `n` tiles and return how many it wrote.+//+// Every table above is PanePreset.defaultFor(n) resolved through tilesFor(n) — 2 splitLong, 3 cols3,+// 4 quad, 5 middleMain — and six or more is `auto`, whose column count the app MEASURES from the+// window's width. The device cannot measure it, so it uses the same fallback the app's own diagrams+// use when they have no window to measure either (_autoColumnsForDrawing): three up to six, four above.+static int desk_shape(int n, desk_rect_t *out)+{+ if (n <= 0) return 0;+ if (n > DESK_MAX_TILES) n = DESK_MAX_TILES;+ const desk_rect_t *fixed = NULL;+ switch (n) {+ case 1: fixed = DESK_1; break;+ case 2: fixed = DESK_2; break;+ case 3: fixed = DESK_3; break;+ case 4: fixed = DESK_4; break;+ case 5: fixed = DESK_5; break;+ default: break;+ }+ if (fixed) { memcpy(out, fixed, (size_t)n * sizeof(*out)); return n; }++ const int cols = n <= 6 ? 3 : 4;+ const int rows = (n + cols - 1) / cols;+ for (int i = 0; i < n; i++) {+ const int r = i / cols, c = i % cols;+ // Thousandths, computed from the index rather than accumulated, so the last column and the last+ // row always land exactly on 1000 and no tile is a pixel short of the edge.+ out[i].x1 = (int16_t)(c * 1000 / cols);+ out[i].x2 = (int16_t)((c + 1) * 1000 / cols);+ out[i].y1 = (int16_t)(r * 1000 / rows);+ out[i].y2 = (int16_t)((r + 1) * 1000 / rows);+ }+ return n;+}++static lv_obj_t *s_desk; // the grid overlay, on lv_layer_top beside the notification drawer+static bool s_desk_open;+// A tab's grid AS THE WINDOW LAID IT OUT, and WHICH tab it is of. See desk_tiles_usable().+static cable_tile_t s_tiles[SWARM_TILES_MAX];+static int s_tile_count;+static char s_tiles_swarm[SWARM_ID_MAX];++/*+ * WHAT EACH SEAT IS CURRENTLY SHOWING, so a redraw can be a repaint.+ *+ * desk_rebuild() runs from rebuild_page_dots(), which has eighteen call sites: every agent that goes+ * busy, every recap that lands, every carousel settle, every landing. Tearing down thirty objects and+ * building thirty more on each of those is the single most expensive thing this face does, and almost+ * every one of those events changes ONE label on ONE tile.+ *+ * So the shape is compared first. Same rectangles, same agents in the same seats — and only the tiles+ * whose name or state actually moved are touched. LVGL then invalidates those labels and nothing else,+ * which is the difference between redrawing 720x720 and redrawing a word.+ */+typedef struct {+ lv_obj_t *tile;+ lv_obj_t *name_lbl;+ lv_area_t area;+ char id[ID_MAX]; // empty for a seat with no agent behind it+ char name[NAME_MAX];+ uint32_t state; // the border colour, as a plain value so it compares+ bool strong;+} desk_seat_t;+static desk_seat_t s_seat[DESK_MAX_TILES];+static int s_seat_count;++// Which colour the tile's border takes. The same vocabulary as every other screen: green is a person+// being waited on, orange is work in flight, the muted green is a turn that just landed, grey is quiet —+// and grey is the neutral the border already wears, so a quiet tile is left exactly as it was.+//+// NOT the waveform's COL_VOICE for the question. That green is 0x00ff2f — a pure channel, chosen to be+// the brightest thing on a face where it appears alone for a second at a time. Here it would sit on the+// glass permanently, on a grid of up to nine tiles, and a grid with two of them outlined in it reads as+// an alarm rather than as "these two are waiting on you". The calm green says the same thing.+static lv_color_t desk_state_color(const proj_t *p, bool *strong)+{+ *strong = false;+ if (notif_is_question(p->id)) { *strong = true; return COL_GREEN; }+ if (p->busy_model) { *strong = true; return COL_ORANGE; }+ if (p->m_preview) return COL_GREEN;+ return lv_color_hex(0x2a2a32);+}++static void desk_tile_tap(lv_event_t *e)+{+ const int i = (int)(intptr_t)lv_event_get_user_data(e);+ if (i < 0 || i >= s_proj_count) return;+ // Copy the id before the overlay goes: hiding it does not free the model, but the focus call below+ // rebuilds the window and this pointer is into an array that reconcile may reorder.+ char id[sizeof(s_proj[0].id)];+ snprintf(id, sizeof id, "%s", s_proj[i].id);+ ui_desk_close();+ ui_focus_project(id);+}++static void desk_bg_tap(lv_event_t *e)+{+ (void)e;+ ui_desk_close();+}++// Build one tile. `d` is the mark's size, chosen from how much room the rectangle has — a full-height+// tile gets the big pair, a quarter the small one, which is the same emphasis the pane has on the Mac.+/*+ * One seat of the grid. `idx` is an index into s_proj, or -1 for a seat the window has and this device+ * cannot drive — a shell, a viewer. Those still get a tile, because the shape is the window's and a+ * shape with a seat missing is a different shape: the agent beside the gap would move.+ *+ * -1 REACHED &s_proj[-1] FOR ONE BUILD, which read whatever sat below the array and drew a tile named+ * from it. On the glass that was an agent with no name and no mark — the "…" placeholder — in a tab+ * that had three real agents (owner, 2026-09-28, photo). Every read of `p` below is guarded now.+ */+static void desk_add_tile(int slot, int idx, const lv_area_t *a)+{+ proj_t *p = (idx >= 0 && idx < s_proj_count) ? &s_proj[idx] : NULL;+ const int32_t w = a->x2 - a->x1, h = a->y2 - a->y1;+ const bool large = w >= DESK_GRID_W * 45 / 100 && h >= DESK_GRID_H * 70 / 100;+ const bool medium = !large && (w >= DESK_GRID_W * 45 / 100 || h >= DESK_GRID_H * 45 / 100);+ const int32_t mark_d = large ? DESK_MARK_LG : medium ? DESK_MARK_MD : DESK_MARK_SM;+ const lv_font_t *font = large ? &geist_med_38 : medium ? &geist_med_32 : &geist_reg_25;++ lv_obj_t *t = lv_button_create(s_desk);+ lv_obj_remove_style_all(t);+ lv_obj_set_pos(t, a->x1, a->y1);+ lv_obj_set_size(t, w, h);+ lv_obj_set_style_bg_color(t, COL_CARD, 0);+ lv_obj_set_style_bg_opa(t, LV_OPA_COVER, 0);+ lv_obj_set_style_bg_color(t, lv_color_hex(0x23252f), LV_STATE_PRESSED);+ lv_obj_set_style_radius(t, 18, 0);+ lv_obj_set_style_border_width(t, 1, 0);+ lv_obj_set_style_border_color(t, lv_color_hex(0xa6a6a6), 0);+ lv_obj_set_style_border_opa(t, LV_OPA_20, 0);+ lv_obj_set_style_pad_all(t, 14, 0);+ lv_obj_set_flex_flow(t, LV_FLEX_FLOW_COLUMN);+ lv_obj_set_flex_align(t, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);+ lv_obj_set_style_pad_row(t, large ? 16 : 12, 0);+ lv_obj_clear_flag(t, LV_OBJ_FLAG_SCROLLABLE);+ // Only a seat with an agent behind it goes anywhere. A pane is drawn so the shape is right; there+ // is nothing on this device to show for it.+ if (p) lv_obj_add_event_cb(t, desk_tile_tap, LV_EVENT_CLICKED, (void *)(intptr_t)idx);++ // NO RAIL. There was one — six pixels of state colour down the left edge — and on the glass it read+ // as two neon stripes rather than as a fact about two agents (owner, 2026-09-27: "2 cái line xanh lá+ // cây là gì vậy"). A signal a person has to be told the meaning of is not a signal, and the app this+ // grid mirrors does not draw one, so the tile is the icon, the name, and nothing else.+ //+ // The state is not dropped, only quieted: it tints the tile's own hairline border, which is already+ // there on every tile and so changes nothing about the shape of the grid.+ bool strong = false;+ const lv_color_t state = p ? desk_state_color(p, &strong) : lv_color_hex(0x2a2a32);+ if (strong) { lv_obj_set_style_border_color(t, state, 0); lv_obj_set_style_border_opa(t, LV_OPA_40, 0); }++ bool recolor = false;+ const lv_image_dsc_t *mark = p ? engine_mark(p->engine, &recolor) : NULL;+ if (mark) {+ lv_obj_t *ic = lv_image_create(t);+ lv_obj_clear_flag(ic, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);+ lv_image_set_src(ic, mark);+ // Scaled from the 20px asset, the same way the chip row does it (ctl_mark_scale). This screen is+ // static between changes, so the transform runs on a redraw and not on every frame.+ lv_image_set_scale(ic, (int32_t)(256 * mark_d / CTL_MARK_SRC));+ lv_obj_set_style_image_recolor(ic, COL_CLAUDE, 0);+ lv_obj_set_style_image_recolor_opa(ic, recolor ? LV_OPA_COVER : LV_OPA_TRANSP, 0);+ }++ lv_obj_t *nm = lv_label_create(t);+ lv_obj_set_style_text_font(nm, font, 0);+ lv_obj_set_style_text_color(nm, p ? COL_FG : COL_MUTED, 0);+ lv_obj_set_style_text_align(nm, LV_TEXT_ALIGN_CENTER, 0);+ lv_obj_set_width(nm, w - 28);+ lv_label_set_long_mode(nm, LV_LABEL_LONG_DOT);+ lv_obj_set_height(nm, lv_font_get_line_height(font)); // one line, dots after — see swarm_lbl+ // A seat with nothing behind it says what it is rather than pretending to be an agent: it is a+ // pane in the window, and naming it "…" would read as an agent still loading.+ lv_label_set_text(nm, !p ? "pane" : (p->name[0] ? p->name : "…"));++ // …and record it, so the next redraw can be a repaint. See desk_seat_t.+ desk_seat_t *st = &s_seat[slot];+ st->tile = t;+ st->name_lbl = nm;+ st->area = *a;+ snprintf(st->id, sizeof st->id, "%s", p ? p->id : "");+ snprintf(st->name, sizeof st->name, "%s", lv_label_get_text(nm));+ st->state = lv_color_to_u32(state);+ st->strong = strong;+}++static void desk_tab_tap(lv_event_t *e)+{+ const int idx = (int)(intptr_t)lv_event_get_user_data(e);+ if (idx < 0 || idx >= s_swarm_count) return;+ char id[SWARM_ID_MAX];+ snprintf(id, sizeof id, "%s", s_swarms[idx].id);+ // Re-picking the one you are on is a no-op the window would also treat as one; skip the round trip.+ if (strcmp(id, s_swarm_selected) == 0) return;+ ESP_LOGI(TAG, "desk: tab → %s", id);+ cable_client_select_swarm(id);++ /*+ * LIGHT IT HERE, NOT WHEN THE WIRE SAYS SO.+ *+ * The fill used to wait for the `swarms` frame the window pushes back after it switches. The daemon+ * answers in about 7ms, but the frame is applied on this device between 60 and 700ms later — and+ * measured on the desk on 2026-09-27, two of five taps produced no apply at all inside a second. A+ * tab that does not light when it is pressed is a tab that reads as not pressed, so the person+ * presses it again, which is what "bấm tab qua lại vẫn ko mượt" was.+ *+ * Nothing is being guessed: the device is the one that decided, and the push that follows carries+ * the same selection and simply agrees. If the window refuses, its push says so and moves the fill+ * back — the state still comes from the window, it is just no longer what DRAWS.+ */+ snprintf(s_swarm_selected, sizeof(s_swarm_selected), "%s", id);+ tabline_repaint();++ // …AND THE GRID BELONGS TO THE OLD TAB UNTIL THE NEW RING LANDS. Leaving it up under a freshly lit+ // tab says those agents are in this tab, which they are not; the agent list arrives on refresh_task's+ // own tick, up to a second later. So the tiles go now and come back with the ring.+ s_desk_pending = true;+ s_desk_pending_ms = lv_tick_get();+ ui_desk_open();+}++/*+ * The tab line, drawn the way the app draws it: ONLY THE SELECTED TAB HAS A FILL, and every tab keeps+ * its number, because the number is how a person says which one they mean out loud — it is the same+ * ⌘1…⌘9 they use on the Mac (desktop/lib/widgets/workspace_bar_control.dart).+ *+ * NO STATE DOT, though the design asked for one. A dot saying "something in that tab is working, or+ * blocked" needs to know the agents of tabs you are NOT on, and the device does not: `cable_swarm_t`+ * carries a name, an agent COUNT and a pane count, and the count is explicit that it is "drawn as a+ * count, never as members". Drawing a dot from what is known here would light only the current tab,+ * which is the one you can already see. It needs a field on the swarms frame first.+ */+static lv_obj_t *s_tabline; // the tab line, and it NEVER leaves the glass — see tabline_sync()+static uint32_t s_tabline_sig; // what the line was last BUILT from: the tabs, not which one is picked++static bool tabline_shows(int i);++// FNV-1a over the BUTTONS the line would have: each shown row's index, id and name. Not over which one+// is filled — that is a repaint, and telling the two apart is the whole point of this.+//+// It does have to run the same filter the build does, because the filter reads the selection: an empty+// tab is hidden unless it is the one you are on, so moving onto or off one really does change which+// buttons exist, and that case must come out as a rebuild rather than as a repaint of a stale line.+static uint32_t tabline_sig(void)+{+ uint32_t h = 2166136261u;+ for (int i = 0; i < s_swarm_count; i++) {+ if (!tabline_shows(i)) continue;+ h ^= (uint32_t)i; h *= 16777619u;+ for (const char *q = s_swarms[i].id; *q; q++) { h ^= (uint8_t)*q; h *= 16777619u; }+ h ^= 0xffu; h *= 16777619u;+ for (const char *q = s_swarms[i].name; *q; q++) { h ^= (uint8_t)*q; h *= 16777619u; }+ h ^= 0xffu; h *= 16777619u;+ }+ return h ? h : 1u; // 0 means "never built"+}++/*+ * THE TAB LINE IS CHROME, NOT A SCREEN.+ *+ * It lives on the top layer, above whatever the body is showing, and it is the same object whether you+ * are looking at the grid of a tab's agents or at one agent inside it. That is the whole difference from+ * the dial, where the tab's name is a pill that belongs to the agent tile and goes away with it: here the+ * line is the one fixed thing, so "which tab am I in" is never a question the screen stops answering, and+ * changing tab is always one tap from wherever you are.+ */+// An untouched welcome tab is not a place the dial can go, and is not one here either — except the one+// on screen, whatever it is called. Same rule as swarm_picker_rebuild().+static bool tabline_shows(int i)+{+ if (i < 0 || i >= s_swarm_count) return false;+ return s_swarms[i].panes != 0 || strcmp(s_swarms[i].id, s_swarm_selected) == 0;+}++static void tabline_rebuild(void)+{+ if (!s_tabline) return;+ lv_obj_clean(s_tabline);++ for (int i = 0; i < s_swarm_count; i++) {+ const cable_swarm_t *w = &s_swarms[i];+ const bool here = strcmp(w->id, s_swarm_selected) == 0;+ if (!tabline_shows(i)) continue;++ lv_obj_t *t = lv_button_create(s_tabline);+ lv_obj_remove_style_all(t);+ lv_obj_set_size(t, LV_SIZE_CONTENT, DESK_TAB_H);+ lv_obj_set_style_pad_hor(t, 16, 0);+ lv_obj_set_style_radius(t, 14, 0);+ // The selected tab is told apart by a FILL and by its text being brighter — not by an outline in+ // the accent. A saturated blue border on the one thing that is always on screen reads as an alert+ // every time the eye passes it, which is exactly what chrome must not do.+ lv_obj_set_style_bg_color(t, lv_color_hex(0x1c1e24), 0);+ lv_obj_set_style_bg_opa(t, here ? LV_OPA_COVER : LV_OPA_TRANSP, 0);+ lv_obj_set_style_border_width(t, here ? 1 : 0, 0);+ lv_obj_set_style_border_color(t, lv_color_hex(0x2e323b), 0);+ lv_obj_set_flex_flow(t, LV_FLEX_FLOW_ROW);+ lv_obj_set_flex_align(t, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);+ lv_obj_set_style_pad_column(t, 9, 0);+ lv_obj_clear_flag(t, LV_OBJ_FLAG_SCROLLABLE);+ lv_obj_set_user_data(t, (void *)(intptr_t)i); // …and on the button, for tabline_repaint()+ lv_obj_add_event_cb(t, desk_tab_tap, LV_EVENT_CLICKED, (void *)(intptr_t)i);++ lv_obj_t *num = lv_label_create(t);+ lv_obj_set_style_text_font(num, &geist_reg_20, 0);+ lv_obj_set_style_text_color(num, here ? COL_MUTED : COL_INK_LOW, 0);+ lv_label_set_text_fmt(num, "%d", i + 1);++ lv_obj_t *nm = lv_label_create(t);+ lv_obj_set_style_text_font(nm, CTL_CHIP_FONT, 0);+ lv_obj_set_style_text_color(nm, here ? COL_FG : COL_MUTED, 0);+ lv_obj_set_style_max_width(nm, DESK_TAB_NAME_MAX, 0);+ lv_obj_set_height(nm, lv_font_get_line_height(CTL_CHIP_FONT)); // one line, dots after+ lv_label_set_long_mode(nm, LV_LABEL_LONG_DOT);+ lv_label_set_text(nm, w->name[0] ? w->name : "New Harness");++ // Keep the tab you are on in view when the strip is longer than the face.+ if (here) lv_obj_scroll_to_view(t, LV_ANIM_OFF);+ }+ s_tabline_sig = tabline_sig();+}++/*+ * MOVE THE FILL. Do not rebuild the line.+ *+ * Changing tab changes exactly one thing about this strip — which button is filled — and rebuilding it+ * to say that deletes and recreates every button, which loses the strip's sideways scroll and makes a+ * tap look like the whole line jumped (owner, 2026-09-27: "bấm tab qua lại vẫn ko mượt"). Walk what is+ * already there and restyle it.+ */+static void tabline_repaint(void)+{+ if (!s_tabline) return;+ const uint32_t n = lv_obj_get_child_count(s_tabline);+ for (uint32_t k = 0; k < n; k++) {+ lv_obj_t *t = lv_obj_get_child(s_tabline, k);+ const int i = (int)(intptr_t)lv_obj_get_user_data(t);+ if (i < 0 || i >= s_swarm_count) continue;+ const bool here = strcmp(s_swarms[i].id, s_swarm_selected) == 0;+ lv_obj_set_style_bg_opa(t, here ? LV_OPA_COVER : LV_OPA_TRANSP, 0);+ lv_obj_set_style_border_width(t, here ? 1 : 0, 0);+ lv_obj_t *num = lv_obj_get_child(t, 0);+ lv_obj_t *nm = lv_obj_get_child(t, 1);+ if (num) lv_obj_set_style_text_color(num, here ? COL_MUTED : COL_INK_LOW, 0);+ if (nm) lv_obj_set_style_text_color(nm, here ? COL_FG : COL_MUTED, 0);+ if (here) lv_obj_scroll_to_view(t, LV_ANIM_ON);+ }+}++static bool desk_is_open_raw(void) { return s_desk_open; }++/*+ * MAY THE PUSHED SHAPE BE DRAWN RIGHT NOW?+ *+ * Only when it is a shape OF THE TAB ON SCREEN. The window sends the rectangles of ITS active tab, and+ * this device lights a tab the instant it is pressed — before the window has switched, and sometimes+ * before it agrees at all. In that gap `s_tiles` describes the tab you just left, and drawing it puts+ * this tab's agents into the other tab's seats: three agents laid out in two panes, which is exactly+ * what came back off the glass (owner, 2026-09-28: "harness repo có 3 agent, mà device hiển thị ntn").+ *+ * Mismatch is not an error and not worth a log line — it is the ordinary state for the half second+ * between a press and the push that answers it. The derived shape covers it, as it did before any+ * window sent rectangles at all.+ */+static bool desk_tiles_usable(void)+{+ if (s_tile_count <= 0 || !s_tiles_swarm[0]) return false;+ if (strcmp(s_tiles_swarm, s_swarm_selected) != 0) return false;++ /*+ * …AND EVERY NAMED SEAT MUST BE AN AGENT THIS DEVICE ACTUALLY HOLDS.+ *+ * The shape arrives on the `swarms` frame and is applied the instant it lands. The roster does not:+ * `agents.end` raises a flag and refresh_task drains it on its own second-long tick, so for up to a+ * second after a tab change s_proj[] still holds the PREVIOUS tab's agents. Resolving this tab's+ * seats against that roster misses every one of them, and a miss used to draw the seat as "pane" —+ * so a tab with three agents came up as three boxes all labelled "pane" (owner, 2026-09-28, photo),+ * and it was the truthful-looking answer to the wrong question: those seats are agents, this device+ * just has not been handed them yet.+ *+ * An EMPTY id is different and stays a pane: that is a shell or a viewer, and the window is telling+ * us there is no agent there at all.+ *+ * Failing the whole shape rather than the seat is deliberate. A half-resolved grid is a picture that+ * is wrong in a way nobody can see is wrong; the derived shape is at least self-consistent, and this+ * heals itself on the very next rebuild_page_dots() — which is exactly what the arriving roster+ * calls.+ */+ for (int i = 0; i < s_tile_count; i++)+ if (s_tiles[i].agent_id[0] && find_proj(s_tiles[i].agent_id) < 0) return false;+ return true;+}++/*+ * A TAB WITH ONE AGENT HAS NO SHAPE TO SHOW.+ *+ * The grid exists so an agent can be found by WHERE it is among the others. With one tile there is no+ * "among the others" and no where: the grid becomes a full-screen button whose only purpose is to be+ * pressed once, and every road into the tab costs a tap that could not have gone anywhere else.+ *+ * ZERO agents still gets the grid, and that is not an oversight — "No agents in this tab" is the one+ * thing on the device that says so, and a tab you have just opened and found empty has to say it.+ */+static bool desk_has_a_shape(void)+{+ // SEATS, not agents, whenever the window has told us its seats. A tab holding one agent beside two+ // shells has a real arrangement to show, and skipping to the agent would hide the two panes that+ // are the reason the tab looks the way it does. Without a pushed shape there is nothing but the+ // agent count to go on, which is the old test.+ return (desk_tiles_usable() ? s_tile_count : s_proj_count) != 1;+}++// The single agent's id, copied out before anything can reorder the model. Empty when there is not+// exactly one.+static void desk_only_agent(char *out, size_t cap)+{+ if (s_proj_count == 1) snprintf(out, cap, "%s", s_proj[0].id);+ else if (cap) out[0] = '\0';+}++/*+ * WHERE THE LINE IS, AND WHERE IT IS NOT.+ *+ * It belongs to the two faces that are inside a tab — the desk, and an agent of that tab — because on+ * both of them "which tab" is a live fact the person is acting on. It does NOT belong on Settings, the+ * Machines list, the Overview, a chooser wheel, the pattern lock, the pairing screen or under the open+ * notification drawer: none of those are in a tab, and a tab line over them would be an offer to switch+ * away from a screen that has its own job. Sitting on lv_layer_top it would otherwise cover all of them.+ */+static void tabline_sync(void)+{+ const bool want = !display_is_asleep() && !s_notif_open && s_swarm_count > 0 &&+ (s_desk_open ||+ (lv_screen_active() == scr_projects && !s_overview_active &&+ !s_settings_active && !s_machines_active));+ if (!want) { set_hidden(s_tabline, true); return; }++ if (!s_tabline) {+ s_tabline = lv_obj_create(lv_layer_top());+ lv_obj_remove_style_all(s_tabline);+ lv_obj_set_pos(s_tabline, DESK_STRIP_X, DESK_STRIP_Y);+ lv_obj_set_size(s_tabline, UI_FACE_W - 2 * DESK_STRIP_X, DESK_STRIP_H);+ lv_obj_set_flex_flow(s_tabline, LV_FLEX_FLOW_ROW);+ lv_obj_set_flex_align(s_tabline, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);+ lv_obj_set_style_pad_column(s_tabline, 6, 0);+ lv_obj_set_scroll_dir(s_tabline, LV_DIR_HOR);+ lv_obj_set_scrollbar_mode(s_tabline, LV_SCROLLBAR_MODE_OFF);+ // NOT clickable itself: a tap between two tabs must fall through to whatever is behind — the+ // desk's background close, or the tile. Only the tabs take presses.+ lv_obj_clear_flag(s_tabline, LV_OBJ_FLAG_CLICKABLE);+ tabline_rebuild();+ }+ lv_obj_clear_flag(s_tabline, LV_OBJ_FLAG_HIDDEN);+ // In front of the desk, which is also on this layer and is moved to the front when it opens.+ lv_obj_move_foreground(s_tabline);+}++// WHERE THE NOTIFICATION PULL-DOWN MAY START, on a face whose top belongs to the tab line.+//+// The band is a top-edge zone ~90px deep, and the tab line sits at y 24..76 — inside it. Captured from+// press-down, the band swallowed every tap on the tabs and answered it with "nothing" on release, which+// is a tab strip that cannot be tapped at all (owner, 2026-09-27: "click chuyen tab rat kho").+//+// The bell's way out — exempt the control's rectangle — does not work here: lv_obj_hit_test refuses an+// object that is not CLICKABLE, and this container deliberately is not, so a tap in the gap between two+// tabs falls through to the tile behind. So the band gets a FLOOR instead: it starts where the line+// ends. There is still ~90px of it, just lower down, and a pull that begins on a tab is a tab press.+int ui_notif_band_top_px(void)+{+ return DESK_STRIP_Y + DESK_STRIP_H;+}++// Rebuild the whole grid from the model. Cheap enough to do on every open: a tab is a handful of tiles,+// and rebuilding is what keeps this from having to track which agent moved where.+static void desk_rebuild(void)+{+ if (!s_desk) return;+ if (s_desk_pending && lv_tick_elaps(s_desk_pending_ms) >= DESK_PENDING_MS) s_desk_pending = false;+ if (s_desk_pending) { // the tab moved; its agents are on their way+ if (s_seat_count) { lv_obj_clean(s_desk); s_seat_count = 0; }+ return;+ }++ /*+ * THE WINDOW'S OWN RECTANGLES FIRST, the derived shape second.+ *+ * With `tiles` on the wire this grid is the window's grid — every preset, `auto` at whatever column+ * count it measured, and a hand-dragged resize, all of them, because none of it is re-derived here.+ * Without it (an older daemon, an older app) the guess from PanePreset.defaultFor is still behind,+ * which is exactly how this behaved before the field existed.+ */+ desk_rect_t r[DESK_MAX_TILES];+ int seat[DESK_MAX_TILES]; // index into s_proj, or -1 for a pane this device cannot drive+ int n = 0, total;++ if (desk_tiles_usable()) {+ total = s_tile_count;+ for (int i = 0; i < s_tile_count && n < DESK_MAX_TILES; i++) {+ r[n].x1 = s_tiles[i].x1; r[n].y1 = s_tiles[i].y1;+ r[n].x2 = s_tiles[i].x2; r[n].y2 = s_tiles[i].y2;+ seat[n] = s_tiles[i].agent_id[0] ? find_proj(s_tiles[i].agent_id) : -1;+ n++;+ }+ } else {+ total = s_proj_count;+ n = desk_shape(total, r);+ for (int i = 0; i < n; i++) seat[i] = i;+ }++ if (n == 0) {+ lv_obj_clean(s_desk);+ s_seat_count = 0;+ lv_obj_t *empty = lv_label_create(s_desk);+ lv_obj_set_style_text_font(empty, &geist_reg_25, 0);+ lv_obj_set_style_text_color(empty, COL_MUTED, 0);+ lv_label_set_text(empty, "No agents in this tab");+ lv_obj_center(empty);+ return;+ }++ lv_area_t area[DESK_MAX_TILES];+ for (int i = 0; i < n; i++) {+ area[i].x1 = DESK_GRID_X + (int32_t)r[i].x1 * DESK_GRID_W / 1000;+ area[i].y1 = DESK_GRID_Y + (int32_t)r[i].y1 * DESK_GRID_H / 1000;+ area[i].x2 = DESK_GRID_X + (int32_t)r[i].x2 * DESK_GRID_W / 1000 - DESK_GRID_GAP;+ area[i].y2 = DESK_GRID_Y + (int32_t)r[i].y2 * DESK_GRID_H / 1000 - DESK_GRID_GAP;+ }++ /*+ * SAME SHAPE, SAME AGENTS? THEN REPAINT.+ *+ * The seats have to match by rectangle AND by which agent sits in each one — a tab whose agents+ * merely re-ordered is a different picture even though every rectangle is where it was. When they+ * all match, only a name or a state can have moved, and those are two style writes on one label.+ */+ bool same = (n == s_seat_count);+ for (int i = 0; same && i < n; i++) {+ const desk_seat_t *st = &s_seat[i];+ const proj_t *pp = (seat[i] >= 0 && seat[i] < s_proj_count) ? &s_proj[seat[i]] : NULL;+ same = st->tile && lv_obj_is_valid(st->tile) &&+ st->area.x1 == area[i].x1 && st->area.y1 == area[i].y1 &&+ st->area.x2 == area[i].x2 && st->area.y2 == area[i].y2 &&+ strcmp(st->id, pp ? pp->id : "") == 0;+ }++ if (same) {+ for (int i = 0; i < n; i++) {+ desk_seat_t *st = &s_seat[i];+ proj_t *pp = (seat[i] >= 0 && seat[i] < s_proj_count) ? &s_proj[seat[i]] : NULL;++ const char *want = !pp ? "pane" : (pp->name[0] ? pp->name : "…");+ if (strcmp(st->name, want) != 0) {+ lv_label_set_text(st->name_lbl, want);+ snprintf(st->name, sizeof st->name, "%s", want);+ }++ bool strong = false;+ const lv_color_t c = pp ? desk_state_color(pp, &strong) : lv_color_hex(0x2a2a32);+ if (lv_color_to_u32(c) != st->state || strong != st->strong) {+ lv_obj_set_style_border_color(st->tile, strong ? c : lv_color_hex(0xa6a6a6), 0);+ lv_obj_set_style_border_opa(st->tile, strong ? LV_OPA_40 : LV_OPA_20, 0);+ st->state = lv_color_to_u32(c);+ st->strong = strong;+ }+ }+ return;+ }++ // The shape really moved. Everything goes and everything comes back.+ lv_obj_clean(s_desk);+ s_seat_count = 0;+ for (int i = 0; i < n; i++) desk_add_tile(i, seat[i], &area[i]);+ s_seat_count = n;++ // A tab deeper than the grid says so rather than silently dropping the rest.+ if (total > n) {+ lv_obj_t *more = lv_label_create(s_desk);+ lv_obj_set_style_text_font(more, &geist_reg_20, 0);+ lv_obj_set_style_text_color(more, COL_MUTED, 0);+ lv_label_set_text_fmt(more, "+%d more", total - n);+ lv_obj_align(more, LV_ALIGN_TOP_RIGHT, -DESK_GRID_X, DESK_GRID_Y - 32);+ }+}++bool ui_desk_is_open(void) { return s_desk_open; }++void ui_desk_open(void)+{+ display_lock();+ // Straight through to the agent when the tab holds one. NOT while a pick is pending: the model+ // still belongs to the tab you just left, so "one agent" would be a fact about the wrong tab —+ // the ring lands a moment later and rebuild_page_dots makes the same decision on the right one.+ if (!s_desk_pending && !desk_has_a_shape()) {+ char id[sizeof(s_proj[0].id)];+ desk_only_agent(id, sizeof id);+ ui_desk_close(); // no-op unless it was already up+ display_unlock();+ if (id[0]) ui_focus_project(id);+ return;+ }+ if (!s_desk) {+ s_desk = lv_obj_create(lv_layer_top());+ lv_obj_remove_style_all(s_desk);+ lv_obj_set_size(s_desk, lv_pct(100), lv_pct(100));+ lv_obj_set_pos(s_desk, 0, 0);+ lv_obj_set_style_bg_color(s_desk, COL_BG, 0);+ lv_obj_set_style_bg_opa(s_desk, LV_OPA_COVER, 0);+ lv_obj_add_flag(s_desk, LV_OBJ_FLAG_CLICKABLE); // a tap on the gaps closes it+ lv_obj_add_event_cb(s_desk, desk_bg_tap, LV_EVENT_CLICKED, NULL);+ lv_obj_clear_flag(s_desk, LV_OBJ_FLAG_SCROLLABLE);+ }+ desk_rebuild();+ lv_obj_clear_flag(s_desk, LV_OBJ_FLAG_HIDDEN);+ lv_obj_move_foreground(s_desk);+ s_desk_open = true;+ tabline_sync();+ ESP_LOGI(TAG, "face: desk (%d agents)", s_proj_count);+ display_unlock();+}++void ui_desk_close(void)+{+ if (!s_desk_open) return;+ display_lock();+ s_desk_open = false;+ if (s_desk) lv_obj_add_flag(s_desk, LV_OBJ_FLAG_HIDDEN);+ tabline_sync();+ display_unlock();+}+#else+bool ui_desk_is_open(void) { return false; }+void ui_desk_open(void) { }+void ui_desk_close(void) { }+#endif /* UI_DESK_GRID */+void ui_home_overview(void){if (s_bright_dragging) return; // a brightness-slider drag on Settings is not a home swipe (mirror ui_swipe_*)ui_notif_close(); // no-op if closed; takes/releases the lock itself (must not nest inside our lock)+#if UI_DESK_GRID+ // On a face with room for the shape, HOME IS THE SHAPE. The carousel still exists — it is what walks+ // between agents once you are in one — but it stops being how you find anything, so the gesture that+ // used to land on the Overview ring lands on the desk instead.+ ui_desk_open();+ return;+#endifdisplay_lock();swarm_picker_close();if (s_ring != RING_AGENTS && lv_screen_active() == scr_projects) {@@ -6213,6 +6922,14 @@ static void notif_pill_tap(lv_event_t *e) { (void)e; ui_notif_open(); }static void swarm_line_paint(proj_t *p){if (!p || !p->ctl_row || !p->swarm_lbl) return;+#if UI_DESK_GRID+ // THE FIXED TAB LINE HAS ALREADY SAID THIS, and says it in the same band — the pill floats at+ // y≈62 and the line occupies 24..76. Two names for the same tab, one on top of the other. The pill+ // was the round face's only way to carry the fact, because there the line has nowhere to live; here+ // it is furniture, and the tap it offered (open the tab picker) is what the line itself now is.+ lv_obj_add_flag(p->ctl_row, LV_OBJ_FLAG_HIDDEN);+ return;+#endifconst cable_swarm_t *sel = NULL;for (int i = 0; i < s_swarm_count; i++) if (strcmp(s_swarms[i].id, s_swarm_selected) == 0) { sel = &s_swarms[i]; break; }if (!sel) { lv_obj_add_flag(p->ctl_row, LV_OBJ_FLAG_HIDDEN); return; }@@ -6226,6 +6943,57 @@ static void swarm_lines_repaint(void)for (int i = 0; i < s_proj_count; i++) if (s_proj[i].content_live) swarm_line_paint(&s_proj[i]);}+void ui_tiles_replace(const cable_tile_t *tiles, int count, const char *swarm_id)+{+#if !UI_DESK_GRID+ // A ROUND FACE HAS NOWHERE TO PUT A SHAPE. 466px of circle carries one tile, and one tile is what+ // the carousel already is — there is no arrangement to mirror, so the window's rectangles are a+ // fact this device has no use for. Taken and dropped rather than refused: the daemon sends the+ // same frame to both boards, and a dial that treated the field as an error would be a dial that+ // stopped reading swarms the day the window learned to send it.+ (void)tiles; (void)count; (void)swarm_id;+ return;+#else+ display_lock();+ if (count < 0) count = 0;+ if (count > SWARM_TILES_MAX) count = SWARM_TILES_MAX;++ /*+ * AND REDRAW, BECAUSE NOTHING ELSE WILL.+ *+ * The grid is rebuilt from rebuild_page_dots(), which every path that changes the AGENT model+ * calls — and re-arranging a tab changes no agent at all. Same tab, same members, same order, new+ * rectangles: the push arrived, s_tiles was updated, and the glass went on showing the old shape+ * until a tab change forced an agents push through. Which is exactly what it looked like from the+ * outside (owner, 2026-09-27: "đổi trên app, device ko tự thay đổi theo, phải chọn tab khác quay+ * lại mới thay đổi").+ *+ * On CHANGE only. This frame rides every swarms push — every tab switch, every pane opened — and+ * a rebuild that tears down and recreates every tile is not something to do when nothing moved.+ */+ const bool moved = count != s_tile_count ||+ strcmp(s_tiles_swarm, swarm_id ? swarm_id : "") != 0 ||+ (count && memcmp(s_tiles, tiles, (size_t)count * sizeof(*tiles)) != 0);+ if (count) memcpy(s_tiles, tiles, (size_t)count * sizeof(*tiles));+ s_tile_count = count;+ snprintf(s_tiles_swarm, sizeof(s_tiles_swarm), "%s", swarm_id ? swarm_id : "");+ if (moved) {+ // The first seat's id is printed because "which tab" and "how many" were never the question:+ // every seat came back unnamed, and the only two ways that happens are an id that never left+ // the window and an id this device does not hold. One line tells the two apart.+ int named = 0;+ for (int k = 0; k < count; k++) if (s_tiles[k].agent_id[0] && find_proj(s_tiles[k].agent_id) >= 0) named++;+ ESP_LOGI(TAG, "desk: shape → %d tiles on %s · %d named · [0]='%s'",+ count, s_tiles_swarm[0] ? s_tiles_swarm : "-", named,+ count ? s_tiles[0].agent_id : "");+ // Not while a tab pick is in flight: the grid is deliberately blank until its agents land, and+ // desk_rebuild() honours that itself — this would only redraw the same blank.+ if (s_desk_open) desk_rebuild();+ }+ display_unlock();+#endif+}+void ui_swarms_replace(const cable_swarm_t *rows, int count, const char *selected){display_lock();@@ -6235,6 +7003,13 @@ void ui_swarms_replace(const cable_swarm_t *rows, int count, const char *selectes_swarm_count = count;snprintf(s_swarm_selected, sizeof(s_swarm_selected), "%s", selected ? selected : "");swarm_lines_repaint();+#if UI_DESK_GRID+ // Rebuild only when the TABS changed. A push whose only news is which one is selected — every push+ // that follows a tap — moves the fill and leaves the buttons, and the strip keeps its scroll.+ if (s_tabline && tabline_sig() == s_tabline_sig) tabline_repaint();+ else tabline_rebuild();+ tabline_sync();+#endifno_agents_apply(); // the empty tab's eyebrow is the tab's nameif (s_swarm_screen && !lv_obj_has_flag(s_swarm_screen, LV_OBJ_FLAG_HIDDEN)) swarm_picker_rebuild();display_unlock();@@ -6391,7 +7166,7 @@ void ui_notif_open(void)lv_anim_t a; lv_anim_init(&a); // slide down from off-top (position anim — no snapshot layer)lv_anim_set_var(&a, s_notif_drawer);lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_y);- lv_anim_set_values(&a, -466, 0);+ lv_anim_set_values(&a, -UI_FACE_W, 0);lv_anim_set_duration(&a, 220);lv_anim_set_path_cb(&a, lv_anim_path_ease_out);lv_anim_start(&a);@@ -7634,7 +8409,6 @@ void ui_question_show(const char *project_id, const char *agent_name, const char// ── Machine picker (Settings → Machines) ──────────────────────────────────────────────────────────────static void machine_row_tap(lv_event_t *e); // fwd-#define MACHINE_ROW_W 427#define MACHINE_ROW_H 84// Machines center-focus WHEEL (smartwatch style): fixed-height rows; the one snapped to the middle is enlarged@@ -7938,9 +8712,14 @@ static void no_agents_apply(void)// tab has panes or it does not. Each is a different thing to do next, and the screen says that one// thing in the app's own words.//- // A: not connected — nothing is talking to us; the only move is to run the app on the computer.- // Also the shape for "connected, no window": the daemon is up but the app is shut, and the one- // thing to do is the same. The badge at the top says which of the two it is.+ // A: not connected — nothing is talking to us; the only move is to start Harness on the computer.+ // A′: connected but no window — Harness IS running (it is answering this very cable) and the app+ // has not attached. These used to share A's sentence, on the reading that the thing to do was the+ // same. It is not, and worse, it is a LIE the device can see is a lie: it says "Run Harness on+ // your computer" while holding an open session with that computer (owner, 2026-09-27: "rõ ràng+ // là app đang run, mà device lại hiện màn hình Run OpenHarness"). Measured on the desk: the app+ // was up for 4m46s before its local client attached, and the device spent all of it saying the+ // app was not running.// B′: connected, window open, no agents ANYWHERE — name the machine, offer Cmd N.// T: connected, window open, agents elsewhere, this tab empty — the tab's name, Cmd N, and a nudge// that the other tabs are a tap away (the eyebrow opens the TABS picker on the tiles; here it is@@ -7950,9 +8729,14 @@ static void no_agents_apply(void)set_hidden(s_na_eyebrow, true); // absent, not "Machine": the row is for a nameif (pill) set_hidden(pill, true);if (s_na_marks) set_hidden(s_na_marks, true);- lv_label_set_text(s_na_title, "Run OpenHarness\non your computer");+ // The title states what is TRUE from here, and the hint says what to do about it. `s_connected`+ // is the whole difference: it is this device holding a live session with that computer, so when+ // it is set the computer is demonstrably there and only the app is missing.+ lv_label_set_text(s_na_title, s_connected+ ? "Waiting for\nOpenHarness"+ : "Run OpenHarness\non your computer");lv_label_set_text(s_no_agents_hint_lbl, s_connected- ? "The dial follows the app.\nIt shows what the app shows."+ ? "Your computer is here.\nOpen the app to see your agents.": "The dial follows the app.\nIt connects on its own.");return;}@@ -8540,6 +9324,17 @@ void ui_boot_pressed(void)// While a question is shown, BOOT means "back" (cancel voice / dismiss the question). Otherwise, if// the visible project is WORKING, pop a "Cancel task?" confirm (a running turn is always shown on// the projects screen) so an accidental press can't kill it. Nothing running → ignore.+#if UI_DESK_GRID+ // THE DESK IS HOME on this face, so back means "up to the desk": on an agent it goes there, and on+ // the desk there is nothing above it, exactly as back on the dial's Overview does nothing. A WORKING+ // agent still gets its "Cancel task?" confirm first — that is what the press means while a turn is+ // in flight, and leaving the tile is not.+ if (ui_desk_is_open()) return;+#else+ // The desk first: it is the topmost thing on the glass when it is up, and "back" means the thing on+ // top, not the thing underneath. Same rule the question already follows below.+ if (ui_desk_is_open()) { ui_desk_close(); return; }+#endifdisplay_lock();bool q = s_q.active;int idx = (s_active_idx >= 0 && s_active_idx < s_proj_count) ? s_active_idx : 0;@@ -8550,7 +9345,14 @@ void ui_boot_pressed(void)lv_obj_clear_flag(s_cancel_confirm, LV_OBJ_FLAG_HIDDEN);overlay_raise(s_cancel_confirm);} else {+#if UI_DESK_GRID+ display_unlock();+ ESP_LOGI(TAG, "BOOT → desk");+ ui_desk_open();+ return;+#elseESP_LOGI(TAG, "BOOT → no working task, ignored");+#endif}display_unlock();}diff --git a/devices/harness-device/firmware/main/ui/ui_screens.h b/devices/harness-device/firmware/main/ui/ui_screens.hindex 719887597..d5d82cfc3 100644--- a/devices/harness-device/firmware/main/ui/ui_screens.h+++ b/devices/harness-device/firmware/main/ui/ui_screens.h@@ -8,6 +8,7 @@#include <stddef.h> // size_t (ui_project_id_at)#include "freertos/FreeRTOS.h"#include "freertos/task.h" // TaskHandle_t — ui_set_reload_waiter+#include "ui_metrics.h" // UI_DESK_GRID — which face this build is for, and so which of these exist#include "config_store.h"#include "../cable_machines.h" // cable_machine_t — the wheel's row, already parsed and diffed#include "../cable_client.h" // cable_swarm_t — one of the window's tabs, as the wire carries it@@ -149,6 +150,13 @@ bool ui_scroll_reportable(void);// "Home" gesture (touch.c): a swipe-up that STARTED at the bottom edge → jump to the Overview tile from// any screen (closes the notif drawer / leaves the reader/wifi/picker, then centers ring 0).void ui_home_overview(void);++// The desk grid: the tab's agents drawn in the arrangement the Mac has them in, one tile each, tap to+// open. Present only on a face with room for a recognisable shape (UI_DESK_GRID in ui_metrics.h); on the+// round dial these are no-ops and the carousel remains home.+void ui_desk_open(void);+void ui_desk_close(void);+bool ui_desk_is_open(void);// Voice-state queries for the gesture layer: is_recording = actively capturing (a tap stops it);// is_active = recording OR the clip still uploading (blocks a new start).bool ui_voice_is_recording(void);@@ -178,6 +186,12 @@ bool ui_notif_is_open(void);// button that lives inside that band can be pressed — a tap on the bell reaches LVGL and opens the// drawer; a pull that starts anywhere else in the band opens it too.bool ui_notif_pill_hit(uint16_t x, uint16_t y);+/* First y the notification pull-down may start on: the bottom of the fixed tab line, which owns the top+ * of the Pro's face. Declared only where UI_DESK_GRID — the round face has no line and no floor, and its+ * touch path must compile to exactly what it did before. */+#if UI_DESK_GRID+int ui_notif_band_top_px(void);+#endif// A swipe-up inside the open drawer → close it, but only if the list is already scrolled to the top// (otherwise the gesture is just scrolling the list).void ui_notif_swipe_up(void);@@ -235,6 +249,14 @@ void ui_machines_refresh(void);// Replace the whole list from one `swarms` frame. `selected` names the one the window has on screen; it// is what every tile's swarm line draws. count 0 hides the line. Safe from the reader task.void ui_swarms_replace(const cable_swarm_t *rows, int count, const char *selected);+/* The grid of the tab named by `swarm_id`, as the window laid it out.+ *+ * THE ID IS NOT DECORATION. These rectangles describe the APP's active tab, and this device can be+ * looking at a different one — it lights a tab the moment you press it and only learns whether the+ * window agreed a beat later. A shape drawn under the wrong tab puts agents in seats that belong to+ * another tab's panes, which is what "3 agents, 2 tiles" was. `count` 0, or an id that is not the tab+ * on screen, both mean the same thing: fall back to deriving a shape from what this tab holds. */+void ui_tiles_replace(const cable_tile_t *tiles, int count, const char *swarm_id);// Whether the selected machine is the computer at the other end of this cable. Everything that acts on// "this desk" — the focus report, the scroll report — asks this first.diff --git a/devices/harness-device/firmware/sdkconfig.defaults b/devices/harness-device/firmware/sdkconfig.defaultsindex d32084b25..4509ae81f 100644--- a/devices/harness-device/firmware/sdkconfig.defaults+++ b/devices/harness-device/firmware/sdkconfig.defaults@@ -1,11 +1,14 @@-# Default sdkconfig for the Interns commander device.-# These are applied on first `idf.py build`; tweak via `idf.py menuconfig`.+# Settings BOTH boards share. ESP-IDF reads this first, then appends sdkconfig.defaults.<target>+# for whichever of the two is being built — so anything that names a pin count, a PSRAM mode, a CPU+# clock or a radio belongs in the per-target file beside this one, not here.+#+# `idf.py build` with no target still builds the round dial: sdkconfig.defaults.esp32s3 carries+# CONFIG_IDF_TARGET, and the Pro is reached through `make pro-build` (see the Makefile) which sets its+# own target and its own sdkconfig file.-# --- Target / flash ----CONFIG_IDF_TARGET="esp32s3"+# --- Flash (both boards carry 16 MB) ---CONFIG_ESPTOOLPY_FLASHSIZE_16MB=yCONFIG_ESPTOOLPY_FLASHMODE_QIO=y-CONFIG_ESPTOOLPY_FLASHFREQ_80M=yCONFIG_PARTITION_TABLE_CUSTOM=yCONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"@@ -19,42 +22,9 @@ CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y# refuses a non-verified server ("No option for server verification is enabled").CONFIG_ESP_HTTPS_OTA_ALLOW_HTTP=y-# --- PSRAM (ESP32-S3R8 = 8MB octal PSRAM; LVGL object pool lives here) ----CONFIG_SPIRAM=y-CONFIG_SPIRAM_MODE_OCT=y-CONFIG_SPIRAM_SPEED_80M=y-CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y-CONFIG_SPIRAM_RODATA=y-CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384-CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y-CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y--# --- CPU ----CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y-# --- FreeRTOS ---CONFIG_FREERTOS_HZ=1000-# --- WiFi (STA for commander, AP for provisioning portal) ----CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y--# --- HTTP server (captive portal) ----CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024--# --- WebSocket client ----CONFIG_WS_TRANSPORT=y--# --- TLS (wss:// + https:// to the prod backend) ----# Verify the prod cert chain against Mozilla's CA roots via esp_crt_bundle_attach.-CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y-CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y-# Leave CONFIG_MBEDTLS_HAVE_TIME_DATE OFF (default) so the TLS handshake does NOT depend on a synced-# clock — REST pairing runs before SNTP, and cert validity dates are not enforced.-# Allocate mbedTLS buffers (~32KB per TLS conn: two 16KB record buffers) from the 8MB PSRAM instead-# of the ~150KB internal heap. Internal heap fragments after the first few TLS connections, so the-# persistent commander WSS + periodic REST fail ssl_setup with -0x7F00 (ALLOC_FAILED) / sock<0.-CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y-# --- Main task stack (UI + init) ---# OTA boot mode performs HTTP download and SHA verification on app_main. The# measured 8KiB stack left only 1,444B (17.6%); 10KiB restores the 25% margin.@@ -83,13 +53,6 @@ CONFIG_LV_ASSERT_HANDLER_INCLUDE="stdlib.h"CONFIG_LV_MEM_SIZE_KILOBYTES=8CONFIG_LV_MEM_POOL_EXPAND_SIZE_KILOBYTES=512-# --- LWIP: room for commander WS + HTTP client + DNS concurrently ----CONFIG_LWIP_MAX_SOCKETS=16-# Larger TCP send/recv buffers so continuous voice PCM streaming tolerates WiFi jitter-# (default ~5.7KB fills in ~180ms at 32KB/s → esp_websocket_client tears down on write-0).-CONFIG_LWIP_TCP_SND_BUF_DEFAULT=65534-CONFIG_LWIP_TCP_WND_DEFAULT=65534-CONFIG_LWIP_TCP_RECVMBOX_SIZE=16CONFIG_COMPILER_OPTIMIZATION_PERF=y# Panic output must reach the wire. The PRIMARY console is where the panic handler, the stack-overflowdiff --git a/devices/harness-device/firmware/sdkconfig.defaults.esp32p4 b/devices/harness-device/firmware/sdkconfig.defaults.esp32p4new file mode 100644index 000000000..2bfe7f41f--- /dev/null+++ b/devices/harness-device/firmware/sdkconfig.defaults.esp32p4@@ -0,0 +1,75 @@+# Harness Pro (WT01P4C5-S1: ESP32-P4 + ESP32-C5, 720x720 MIPI-DSI) — everything the dial does not share.+#+# Values taken from the vendor's HARDWARE.md, which was written off a board that runs. Not guessed from+# the P4 datasheet: the PSRAM mode and speed in particular are module facts, and the wrong pair boots to+# a blank screen rather than to an error.+CONFIG_IDF_TARGET="esp32p4"++# --- Silicon revision ---+# This module is the v3.x part (N16R32X). A v1.x board needs CONFIG_ESP32P4_SELECTS_REV_LESS_V3=y and+# CONFIG_ESP32P4_REV_MIN_100=y instead — the image will not boot on the other revision.+CONFIG_ESP32P4_REV_MIN_300=y++# --- PSRAM (32 MB hex SPI at 200 MHz, executing in place) ---+# 200 MHz is behind IDF_EXPERIMENTAL_FEATURES; without it the speed choice is not offered and the build+# silently drops to 80 MHz, which is not enough to keep three 720x720 framebuffers fed.+CONFIG_IDF_EXPERIMENTAL_FEATURES=y+CONFIG_SPIRAM=y+CONFIG_SPIRAM_MODE_HEX=y+CONFIG_SPIRAM_SPEED_200M=y+CONFIG_SPIRAM_SPEED=200+CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y+CONFIG_SPIRAM_RODATA=y+CONFIG_SPIRAM_XIP_FROM_PSRAM=y+# Small allocations stay in internal RAM, and 32 KiB of it is held back from the PSRAM-first allocator+# so an interrupt path always has somewhere to allocate from.+CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384+CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=32768++# --- CPU ---+CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_360=y++# --- MIPI-DSI ---+# The panel is fed by DMA from PSRAM, so the DSI interrupt must not be parked behind a cache miss on the+# very memory it is servicing: its handler is pinned in IRAM and its object in internal RAM.+CONFIG_LCD_DSI_ISR_HANDLER_IN_IRAM=y+CONFIG_LCD_DSI_OBJ_FORCE_INTERNAL=y++# --- Drawing ---------------------------------------------------------------------------------------+# PRO ONLY. None of this reaches the dial: the round face has its own defaults file, a different SoC and+# no accelerator to turn on. It is also 170k pixels against this face's 518k, so it never needed any of+# it — every switch below exists because the square costs three times as much to fill.+#+# The PPA is the P4's Pixel Processing Accelerator, and LVGL 9.5 already ships the draw unit for it+# (src/draw/espressif/ppa). It was simply never enabled. It takes FILL and IMAGE off the CPU, which is+# most of this UI by area: the desk is nine large rounded rectangles and nine marks, and the type — which+# the PPA does not touch — covers a few percent of the glass.+CONFIG_LV_USE_PPA=y+CONFIG_LV_USE_PPA_IMG=y++# A SECOND RASTERISING THREAD, on a chip with two 400 MHz cores and one of them idle while the other+# draws. LVGL splits a refresh across draw units; it needs an OS binding to do it, and LV_OS_NONE is why+# raising the count alone would have changed nothing.+CONFIG_LV_OS_FREERTOS=y+CONFIG_LV_DRAW_SW_DRAW_UNIT_CNT=2++# The engine marks are 20px assets drawn at 24/32/40 through lv_image_set_scale, and a scaled image is a+# bilinear transform per destination pixel. With no cache that transform ran again on every redraw of+# every tile. 256 KiB buys all of them, in PSRAM, where there are 26 MB free.+CONFIG_LV_CACHE_DEF_SIZE=262144+CONFIG_LV_IMAGE_HEADER_CACHE_DEF_CNT=16++# 60 Hz rather than 30. The panel scans at 59.2 Hz and LVGL was refusing to look at the screen more than+# every 33 ms, which put a whole extra frame of latency under every touch. Worth having only now that a+# frame fits in the budget; before the switches above it would only have burned the CPU twice as often.+CONFIG_LV_DEF_REFR_PERIOD=16++# Asserts everywhere, in IDF and in LVGL, on a build that has been on real hardware for days. SILENT+# keeps the abort (a failed invariant still stops) and drops the file/line strings and the formatting.+CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENT=y++# The PPA reads and writes through the L2 cache and refuses to build unless LVGL's buffer alignment+# matches the cache line, because a draw buffer that straddles a line cannot be invalidated without+# taking a neighbour with it. 64 here, 64 in CONFIG_CACHE_L2_CACHE_LINE_SIZE, and panel_pro.c allocates+# on the same boundary — see the aligned_alloc there.+CONFIG_LV_DRAW_BUF_ALIGN=64diff --git a/devices/harness-device/firmware/sdkconfig.defaults.esp32s3 b/devices/harness-device/firmware/sdkconfig.defaults.esp32s3new file mode 100644index 000000000..d6592564c--- /dev/null+++ b/devices/harness-device/firmware/sdkconfig.defaults.esp32s3@@ -0,0 +1,50 @@+# The round dial (ESP32-S3-Touch-AMOLED-1.75C) — everything the Pro does not share.+#+# Split out of sdkconfig.defaults when the Pro's ESP32-P4 target arrived; the values are unchanged from+# what shipped, so a dial built before and after the split gets the same sdkconfig.+#+# CONFIG_IDF_TARGET lives here rather than in the shared file so that `idf.py build` in a fresh+# checkout still means "the dial" — ESP-IDF falls back to this when nothing else names a target.+CONFIG_IDF_TARGET="esp32s3"+CONFIG_ESPTOOLPY_FLASHFREQ_80M=y++# --- PSRAM (ESP32-S3R8 = 8MB octal PSRAM; LVGL object pool lives here) ---+CONFIG_SPIRAM=y+CONFIG_SPIRAM_MODE_OCT=y+CONFIG_SPIRAM_SPEED_80M=y+CONFIG_SPIRAM_FETCH_INSTRUCTIONS=y+CONFIG_SPIRAM_RODATA=y+CONFIG_SPIRAM_MALLOC_ALWAYSINTERNAL=16384+CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y+CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y++# --- CPU ---+CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y++# --- WiFi (STA for commander, AP for provisioning portal) ---+CONFIG_ESP_WIFI_SOFTAP_SUPPORT=y++# --- HTTP server (captive portal) ---+CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024++# --- WebSocket client ---+CONFIG_WS_TRANSPORT=y++# --- TLS (wss:// + https:// to the prod backend) ---+# Verify the prod cert chain against Mozilla's CA roots via esp_crt_bundle_attach.+CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=y+CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=y+# Leave CONFIG_MBEDTLS_HAVE_TIME_DATE OFF (default) so the TLS handshake does NOT depend on a synced+# clock — REST pairing runs before SNTP, and cert validity dates are not enforced.+# Allocate mbedTLS buffers (~32KB per TLS conn: two 16KB record buffers) from the 8MB PSRAM instead+# of the ~150KB internal heap. Internal heap fragments after the first few TLS connections, so the+# persistent commander WSS + periodic REST fail ssl_setup with -0x7F00 (ALLOC_FAILED) / sock<0.+CONFIG_MBEDTLS_EXTERNAL_MEM_ALLOC=y++# --- LWIP: room for commander WS + HTTP client + DNS concurrently ---+CONFIG_LWIP_MAX_SOCKETS=16+# Larger TCP send/recv buffers so continuous voice PCM streaming tolerates WiFi jitter+# (default ~5.7KB fills in ~180ms at 32KB/s → esp_websocket_client tears down on write-0).+CONFIG_LWIP_TCP_SND_BUF_DEFAULT=65534+CONFIG_LWIP_TCP_WND_DEFAULT=65534+CONFIG_LWIP_TCP_RECVMBOX_SIZE=16diff --git a/devices/harness-pro/.gitignore b/devices/harness-pro/.gitignorenew file mode 100644index 000000000..93d3583a7--- /dev/null+++ b/devices/harness-pro/.gitignore@@ -0,0 +1,4 @@+# Design mockups: HTML frames used to agree on a layout BEFORE writing LVGL code. They are a+# conversation, not a build input — nothing here compiles or ships, and the PNG renders are megabytes.+# Same rule the dial's firmware keeps for its own mockup/ directory.+mockup/diff --git a/devices/harness-pro/PERF-REVIEW.md b/devices/harness-pro/PERF-REVIEW.mdnew file mode 100644index 000000000..95f116daf--- /dev/null+++ b/devices/harness-pro/PERF-REVIEW.md@@ -0,0 +1,216 @@+# Harness Pro — display performance review++2026-09-27 · against `build.pro` at `0x320ce0` (3 286 131 B) · ESP32-P4 @ 400 MHz · LVGL 9.5.0 · IDF 5.5.4++Read-only review. No code changed. Everything below is measured off the built ELF, the sdkconfig, or+the source — not estimated.++---++## The short version++The other team's numbers are real and their diagnosis of *what* is slow is correct. 46–74 ms for a+single display update is what a full 720×720 software re-rasterisation costs on this chip, and this+firmware triggers one on almost every model change.++Where I differ is on *why*, and therefore on the fix:++> **The 22–190× is measuring the removal of work we are doing needlessly — not the removal of LVGL.**+> The baseline being compared against is our destroy-and-rebuild pattern, not LVGL used properly.+> Most of that gap is recoverable inside LVGL, and three of the switches that would recover it are+> simply turned off.++There is also a ceiling nobody has mentioned: `LV_DEF_REFR_PERIOD = 33`, so the display refreshes at+30 Hz. **Any update that completes under ~16 ms is invisible.** Going 46 ms → 3 ms removes every+dropped frame a person can perceive. Going 3 ms → 0.4 ms changes nothing they can see. The headline+190× is largely spent past the point where it matters.++---++## What was measured++### The image is mostly fonts++```+glyph_bitmap : 2 037 757 B (19 symbols)+glyph_dsc : 79 008 B (19 symbols)+cmaps : 3 216 B+─────────────────────────────+font data : 2 119 981 B+whole image : 3 286 131 B+ → fonts are 64.6 % of the firmware+```++`geist_med_38.c` alone is 1.49 MB of source. Nineteen fonts are linked in at full character range.++**This single fact accounts for the team's "3 183 776 → 620 832 bytes, 80.5 % smaller".** Subsetting+the fonts to the glyphs the UI actually draws takes 2.12 MB to roughly 150 KB. That is an 80 %+reduction *without touching the framework at all*.++Worth being precise about what this buys: image size is an **OTA and flash** win, not primarily a+speed win. Only a few dozen glyphs are touched per frame, so the working set already fits in L2 — the+2 MB is mostly cold. Do it for the download time and the flash budget, and do not expect frames from+it.++### Three accelerators are present and switched off++| Switch | Now | Available | What it does |+|---|---|---|---|+| `LV_USE_PPA` | unset | `SOC_PPA_SUPPORTED=1`, and LVGL 9.5 ships `src/draw/espressif/ppa/` | Hardware fill + image blit. Our UI is almost entirely rounded-rect fills. |+| `LV_DRAW_SW_DRAW_UNIT_CNT` | `1` | `SOC_CPU_CORES_NUM=2` | A second rasterising thread. Needs `LV_USE_OS=FREERTOS`, currently unset. |+| `LV_CACHE_DEF_SIZE` | `0` | — | Image cache off. Every engine mark is drawn through `lv_image_set_scale()`, i.e. a bilinear transform, **on every redraw**. |++The PPA unit handles `LV_DRAW_TASK_TYPE_FILL` and `LV_DRAW_TASK_TYPE_IMAGE` — not labels. That is the+right half for this UI: the desk is nine large rounded rects plus nine scaled icons, and the text+covers a tiny fraction of the pixels.++**Note for the rewrite discussion: a custom framework loses this.** The PPA driver ships inside+LVGL 9.5 and would have to be rewritten by hand.++### The framebuffer is single++`panel_pro.c` sets `dpi.num_fbs = 1`. The DSI scans that buffer continuously while DMA2D writes new+bands into it. Two consequences:++- **Tearing** — there is no vsync-aligned swap, by construction.+- **Bus contention** — scan-out is `720 × 720 × 2 B × 59.2 Hz = 61.4 MB/s` read from PSRAM,+ permanently, and DMA2D's writes land in the same memory.++And the CPU is on that same bus: `SPIRAM_FETCH_INSTRUCTIONS=y`, `SPIRAM_RODATA=y`,+`SPIRAM_FLASH_LOAD_TO_PSRAM=y` mean **code and read-only data execute from PSRAM**, behind a+**128 KB L2 cache** serving a 3.3 MB image.++### Everything else already checks out++Worth saying plainly so nobody re-does it:++- **Draw buffers are already double** — `buf1`/`buf2`, 60 lines each, in internal DMA RAM.+ LVGL rasterises into one while DMA2D drains the other.+- **The band copy is already DMA2D**, not the CPU — `use_dma2d` is set by+ `ST7703_720_720_PANEL_60HZ_DPI_CONFIG`.+- **The DSI is correctly clocked** — 38 MHz over 840 × 764 total = 59.2 Hz, matching the panel.+- `COMPILER_OPTIMIZATION_PERF=y` (`-O2`).++---++## The three claims, one at a time++### 1 · "Render only diff, not the entire screen — 439 784 → 840 bytes"++**Right, and it is the single biggest win on the list. But LVGL already does this.**++LVGL keeps an invalid-area list and `LV_DISPLAY_RENDER_MODE_PARTIAL` only rasterises the dirty+rectangles. The reason the Pro re-renders ~440 KB instead of 840 B is our own application code:++```+$ grep -c "lv_obj_clean(" main/ui/ui_screens.c+10+```++Ten destroy-and-rebuild sites — the desk, the tab line, the notification list, the tab picker, the+pickers, the question screen. Every model change tears down the object tree and builds a new one,+which invalidates everything under it. One desk rebuild is:++```+9 tiles × (3 objects + 19 style/layout calls) + background + N tabs+ ≈ 30 lv_obj allocations, ~180 style property writes, one flex layout pass,+ then a full-screen invalidate+```++That is where the 46 ms lives — and it is perhaps a third object churn and two thirds the+full-screen rasterisation it forces.++**This was already proven on this device today.** The tab line used to rebuild every button on every+selection change; replacing that with a repaint that walks the existing children and changes only+the fill is ~30 lines, and it is exactly the 840-byte version of the same fix:++```c+static void tabline_repaint(void) /* move the fill, keep the buttons and the scroll */+```++The same treatment applied to `desk_rebuild()`, `notif_rebuild()` and the settings tiles is the bulk+of the claimed win, inside LVGL, at a cost of days not months.++### 2 · "Replace the general-purpose LVGL widget framework with a custom-built one"++**The strongest number behind this (80.5 % smaller) is a font problem, not a framework problem.**+2.12 MB of the 3.28 MB image is glyph data that nothing subsets.++Before a rewrite is the right call, the four things above have to be tried, because each is a config+line or a localised change:++1. Subset the fonts → ~2 MB back, most of the image claim.+2. Stop the destroy-and-rebuild → most of the frame claim.+3. `LV_USE_PPA=y` → hardware fills and image blits.+4. `LV_DRAW_SW_DRAW_UNIT_CNT=2` + `LV_USE_OS=FREERTOS` → the second core.++What a custom framework genuinely wins, and I do not want to argue these away:++- **A lower floor.** LVGL's per-refresh overhead — timer handler, style cascade, layout invalidation+ — is a few hundred microseconds even when nothing changed. 0.39 ms is at the edge of what LVGL can+ do; a purpose-built renderer can go under it.+- **Determinism.** You know exactly what invalidates, because you wrote it.+- **No style cascade** on 180 property writes per rebuild.++What it costs: the PPA draw unit, the font engine, the text shaping (including Vietnamese+diacritics), the scroll/flex layout, the gesture plumbing, and every bug already found in all of+them — **and the dial runs the same `ui_screens.c`**. A rewrite is a rewrite of both devices, or a+permanent fork.++### 3 · "Pixel buffering — CPU pre-loads/prepares pixels while waiting on the render"++**Already done at the draw-buffer level** — `lv_display_set_buffers(s_disp, buf1, buf2, …)`. LVGL+renders the next band into `buf2` while DMA2D copies `buf1`; the flush does not block the renderer.++**Not done at the framebuffer level**, and that is the real remaining version of this claim:+`num_fbs = 1`. Two framebuffers with a vsync-aligned swap would remove tearing and stop DMA2D's+writes landing in the buffer the DSI is reading.++One caution: moving to `num_fbs = 2` with `LV_DISPLAY_RENDER_MODE_DIRECT` means LVGL must maintain+dirty areas across **two** buffers, and a naive switch re-renders the whole screen every frame —+which for this UI (small, infrequent invalidations) would be **slower** than today, not faster. It is+a tearing fix first and a speed fix only for full-screen changes.++---++## Ranked, by gain over cost++| # | Change | Cost | Expect |+|---|---|---|---|+| 1 | **Subset the fonts** to the glyphs actually drawn | hours, build-script only | −2 MB image (−64 %); OTA over the cable gets far shorter |+| 2 | **Repaint instead of rebuild** at the 10 `lv_obj_clean` sites | days | the bulk of 46 ms → single-digit ms |+| 3 | `LV_USE_PPA=y` + `LV_USE_PPA_IMG=y` | one config line + measure | hardware fills/blits; biggest on the desk |+| 4 | `LV_CACHE_DEF_SIZE` > 0, **or better: pre-bake icons at 24/32/40 px** and delete `lv_image_set_scale` | hours | removes a bilinear transform per icon per redraw — and the 2× upscale of a 20 px asset looks bad anyway |+| 5 | `LV_USE_OS=FREERTOS` + `LV_DRAW_SW_DRAW_UNIT_CNT=2` | one config line + measure | up to ~1.8× on large redraws; watch core 0's cable/audio work |+| 6 | `COMPILER_OPTIMIZATION_ASSERTION_LEVEL` 2 → 1 | one line | a few percent, everywhere |+| 7 | `num_fbs = 2` + vsync swap | days, risky | fixes tearing; **may cost frames** — see above |+| 8 | Raise `LV_DEF_REFR_PERIOD` 33 → 16 | one line | only meaningful once 1–5 land |++Items 1, 3, 5, 6 and 8 are **five config lines**. They should be measured before anything is+rewritten.++---++## What is missing before any of this is decided++There is no frame instrumentation on the device. The `display: alive` line reports heap, PSRAM and+LVGL fragmentation, and no timing at all. Every number above about *where* the 46 ms goes is+inference from the code, not measurement.++The measurement build is small and should come first:++- `LV_USE_PERF_MONITOR=y` — LVGL's own FPS and CPU-load overlay.+- `LV_USE_SYSMON` / `LV_USE_PROFILER` for per-draw-task timings.+- One `esp_timer_get_time()` bracket around `desk_rebuild()` and around `lv_timer_handler()`, logged+ on change, so object churn and rasterisation can be told apart.++Without that split — **object churn vs. rasterisation** — a rewrite is being chosen on a number that+does not say which of the two it fixes, and the fix for one of them is a config flag.++---++## The one sentence++Our UI re-creates its object tree on every update and therefore re-rasterises the whole screen; that+is the 46 ms, it is our bug rather than LVGL's, and the accelerators that would absorb what remains+are shipped in the version of LVGL we already link and are switched off.