From 908ad7340c25882b555385564b4fea1caab09baf Mon Sep 17 00:00:00 2001 From: m5agent <329351612+m5agent@users.noreply.github.com> Date: Wed, 2 Dec 2026 01:42:07 +0800 Subject: [PATCH 1/3] Pin the native esp32sim FastEPD Clippy milestone --- scripts/esp32sim-runtime.lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/esp32sim-runtime.lock.json b/scripts/esp32sim-runtime.lock.json index 23542a3f2..52ada89d8 100644 --- a/scripts/esp32sim-runtime.lock.json +++ b/scripts/esp32sim-runtime.lock.json @@ -1,7 +1,7 @@ { "repository": "https://github.com/m5agent/esp32sim.git", - "ref": "refs/tags/m5-milestone-papers3-fastepd-20261201", - "commit": "aafa4dfa7da9e36e9deacdbf2683b47d7d4588c9", + "ref": "refs/tags/m5-milestone-fastepd-clippy-20261202", + "commit": "a62c8769c144a402da672682bc4400e95988332b", "roms": { "esp32s3_rev0_rom.elf": "c0ce0f338d1de1bdc6efbef1591779a2a42c1ab7d759d3c6ae8ae63a7dd34cfd", "esp32p4_rev0_rom.elf": "948f2c7d108d04a9c3a982f9c1c498fb17f2c4a68abc51f87782592034d7ce44", From 3f4b3e22963662458cb060064370cf6974339cb6 Mon Sep 17 00:00:00 2001 From: m5agent <329351612+m5agent@users.noreply.github.com> Date: Wed, 2 Dec 2026 02:00:21 +0800 Subject: [PATCH 2/3] Route native Cardputer navigation keys through Fn matrix chords --- docs/device-service-api.md | 5 +- .../tests/test_device_service_esp32sim.py | 54 +++++++++++++++++++ platform/tools/device_service.py | 32 +++++++---- platform/tools/device_service_esp32sim.py | 6 ++- platform/tools/device_service_input.py | 6 ++- 5 files changed, 90 insertions(+), 13 deletions(-) diff --git a/docs/device-service-api.md b/docs/device-service-api.md index c03896dcb..e464d730e 100644 --- a/docs/device-service-api.md +++ b/docs/device-service-api.md @@ -4613,7 +4613,10 @@ and returns `timing.completion:"queued"`. Keys go down in list order and up in reverse order through the board's keyboard controller, followed by `settle_seconds`. For Fn+Left, send `["fn", "comma"]`. Use `dot`, `slash` and `semicolon` for - Fn+Down, Fn+Right and Fn+Up. + Fn+Down, Fn+Right and Fn+Up. Direct `kind:"key"` or `kind:"keyboard"` + inputs for `esc`, the arrow keys and `delete` use the mapped Fn chord. + Use `tap`, `click` or `hold` for these actions. Raw physical edges + continue to use their physical key names, such as `grave_accent` or `del`. - Dial `encoder` accepts a signed nonzero integer between -128 and 128 and changes the native quadrature controller's detent target. A second request while movement is pending returns HTTP 409 `input_busy`. A diff --git a/platform/tests/test_device_service_esp32sim.py b/platform/tests/test_device_service_esp32sim.py index 0799f39a1..774b731a0 100644 --- a/platform/tests/test_device_service_esp32sim.py +++ b/platform/tests/test_device_service_esp32sim.py @@ -301,6 +301,60 @@ def test_cardputer_keyboard_chords_use_physical_key_edges(self): (code, 400 if code == "invalid_input" else 409)) session.control.request.assert_not_called() + def test_cardputer_direct_navigation_uses_keyboard_matrix_edges(self): + punctuation = {"esc": "`", "escape": "`", "left": ",", "right": "/", + "up": ";", "down": ".", "delete": "del"} + for device in ("cardputer", "cardputer-adv"): + for key, physical in punctuation.items(): + with self.subTest(device=device, key=key): + session = self._input_session(device) + payload = {"kind": "key", "key": key, "action": "tap", "settle_seconds": 1.0} + receipt = session.inject(payload) + self.assertTrue(receipt["accepted"]) + self.assertEqual(receipt["action"], "tap") + self.assertEqual(receipt["timing"], { + "clock": "host", "completion": "events_sent", "hold_seconds": 0.12, "presses": 1, + }) + self.assertEqual([call.args for call in session.control.request.call_args_list], [ + ("key-edge", ("fn", 1)), ("key-edge", (physical, 1)), + ("key-edge", (physical, 0)), ("key-edge", ("fn", 0)), + ]) + self.assertEqual([call.args for call in session._stop_event.wait.call_args_list], + [(0.12,), (1.0,)]) + self.assertNotIn("qcodes", receipt["input"]) + + def test_cardputer_review_setup_uses_direct_navigation_hold(self): + for device in ("cardputer", "cardputer-adv"): + with self.subTest(device=device): + session = self._input_session(device) + step = {"kind": "keyboard", "key": "Esc", "action": "hold", + "seconds": 0.4, "settle_seconds": 0.25} + receipt = session._inject_review_setup(step) + self.assertTrue(receipt["accepted"]) + self.assertEqual([call.args for call in session.control.request.call_args_list], [ + ("key-edge", ("fn", 1)), ("key-edge", ("`", 1)), + ("key-edge", ("`", 0)), ("key-edge", ("fn", 0)), + ]) + self.assertEqual([call.args for call in session._stop_event.wait.call_args_list], + [(0.4,), (0.25,)]) + + def test_cardputer_navigation_rejects_unmapped_keys_without_edges(self): + for device in ("cardputer", "cardputer-adv"): + with self.subTest(device=device): + session = self._input_session(device) + with self.assertRaises(ServiceError) as error: + session.inject({"kind": "key", "key": "f24"}) + self.assertEqual((error.exception.code, error.exception.status), ("not_supported_on_runtime", 409)) + self.assertIn("f24", error.exception.message) + with patch("device_service.board_controls", return_value={"keyboard": []}): + with self.assertRaises(ServiceError) as error: + session.inject({"kind": "key", "key": "esc"}) + self.assertEqual((error.exception.code, error.exception.status), ("unsupported_input", 409)) + self.assertIn("esc", error.exception.message) + session.control.request.assert_not_called() + session.inject({"kind": "key", "key": "delete", "action": "down"}) + session.control.request.assert_called_once_with("key-edge", ("del", 1)) + def test_esp32sim_chords_check_every_qemu_profile_key(self): for device in ("cardputer", "cardputer-adv"): session = self._input_session(device) diff --git a/platform/tools/device_service.py b/platform/tools/device_service.py index cc35e5d08..6a19ef2a1 100644 --- a/platform/tools/device_service.py +++ b/platform/tools/device_service.py @@ -87,9 +87,12 @@ ) from device_service_input import ( # noqa: E402 CLICK_SECONDS, + KEYBOARD_BOARDS, NAVIGATION_KEYS, SEMANTIC_INPUT_KINDS, action_seconds, + board_controls, + keyboard_code, normalize_semantic_input, send_semantic_input, ) @@ -11794,6 +11797,24 @@ def _decode_frame_metrics(self, data, *, analyze): return result def validate_input(self, payload): + if (self.spec.id in KEYBOARD_BOARDS and isinstance(payload, dict) + and payload.get("kind") in ("key", "keyboard")): + key = payload.get("key") + name = key.strip().lower() if isinstance(key, str) else None + action = payload.get("action", "tap") + if isinstance(action, str): + action = action.lower() + if (name in NAVIGATION_KEYS or name == "escape") and action in ("tap", "click", "hold"): + seconds = CLICK_SECONDS + if action == "hold": + seconds = action_seconds(payload, "seconds", 1) + elif payload["kind"] == "key": + seconds = action_seconds(payload, "hold_seconds", CLICK_SECONDS) + settle = action_seconds(payload, "settle_seconds", 0.3, minimum=0) + qcodes = keyboard_code(self.spec, board_controls(self.spec), name) + return {"kind": payload["kind"], "op": "key-edges", "target": "keyboard", + "names": [name], "qcodes": qcodes, "action": action, + "seconds": seconds, "settle_seconds": settle} if isinstance(payload, dict) and ( payload.get("kind") == "chord" or (payload.get("kind") == "button" and payload.get("action") == "double_click") @@ -11831,7 +11852,7 @@ def inject(self, payload): 409) from error receipt = ( {key: value for key, value in command.items() if key not in {"op", "qcodes"}} - if command["kind"] == "chord" else command + if command["kind"] == "chord" or command["op"] == "key-edges" else command ) presses = 2 if command["action"] == "double_click" else 1 timing = {"clock": "host", "completion": "events_sent", @@ -11885,20 +11906,13 @@ def inject(self, payload): return {**self.snapshot(), "input": command, "accepted": True} def _inject_review_setup(self, step: dict) -> dict: - key = step.get("key") - nav = NAVIGATION_KEYS.get(key.lower()) if isinstance(key, str) else None - if (nav and step["kind"] in {"key", "keyboard"} and self.spec.id in {"cardputer", "cardputer-adv"} - and step.get("action", "tap") in {"tap", "click", "hold"}): - duration = step.get("seconds", 1) if step.get("action") == "hold" else 0.12 - step = {"kind": "chord", "target": "keyboard", "keys": ["fn", nav], - "settle_seconds": step.get("settle_seconds", 0.3), "seconds": duration} if step["kind"] != "chord": return self.inject(step) self._require_runtime_permission("input.write") keys = step.get("keys") if not isinstance(keys, list) or not 2 <= len(keys) <= 4: raise ServiceError("invalid_input", "chord keys must be an array of 2 to 4 names", 400) - target = step.get("target", "keyboard" if self.spec.id in {"cardputer", "cardputer-adv"} else "button") + target = step.get("target", "keyboard" if self.spec.id in KEYBOARD_BOARDS else "button") if target not in {"keyboard", "button"}: raise ServiceError("invalid_input", "chord target must be button or keyboard", 400) field = "key" if target == "keyboard" else "control" diff --git a/platform/tools/device_service_esp32sim.py b/platform/tools/device_service_esp32sim.py index 700e9b145..0033222c3 100644 --- a/platform/tools/device_service_esp32sim.py +++ b/platform/tools/device_service_esp32sim.py @@ -543,8 +543,10 @@ def input_command(device, payload, *, board=None): return "pmic-key", ("long" if action == "hold" else "short",), settle if kind != "button" and device in {"cardputer", "cardputer-adv"}: key = KEY_ALIASES.get(name, name) - if key in KEYS: - return "key", (key, hold), settle + if key not in KEYS: + raise ServiceError("not_supported_on_runtime", + f"Keyboard key {name!r} has no esp32sim mapping for {device}", 409) + return "key", (key, hold), settle if kind == "imu": accel = vector(payload, "accel", 32) gyro = vector(payload, "gyro", 4000) diff --git a/platform/tools/device_service_input.py b/platform/tools/device_service_input.py index 0364dd5be..28c13f145 100644 --- a/platform/tools/device_service_input.py +++ b/platform/tools/device_service_input.py @@ -82,7 +82,11 @@ def keyboard_code(spec, controls, key, *, in_chord=False): if key in NAVIGATION_KEYS and spec.id in KEYBOARD_BOARDS: if in_chord: raise ServiceError("invalid_input", "chords require physical keys; use Fn with the physical key", 400) - return [fn, NAVIGATION_KEYS[key]] + nav = NAVIGATION_KEYS[key] + keyboard = controls.get("keyboard", ()) + if fn not in keyboard or nav not in keyboard: + raise unavailable(f"keyboard navigation key {key} has no physical mapping on this board") + return [fn, nav] if key not in controls.get("keyboard", ()): raise unavailable(f"keyboard key {key} has no model input on this board") return [key] From cc6f2cdf91297dd8209ca9362c4e98f37d5b444e Mon Sep 17 00:00:00 2001 From: m5agent <329351612+m5agent@users.noreply.github.com> Date: Wed, 2 Dec 2026 02:10:13 +0800 Subject: [PATCH 3/3] Refresh platform snapshot for the navigation tests --- docs/project-snapshot.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/project-snapshot.md b/docs/project-snapshot.md index 019968160..bdb3e13bf 100644 --- a/docs/project-snapshot.md +++ b/docs/project-snapshot.md @@ -155,11 +155,11 @@ ## 代码与文档规模 -- `platform/tools`:`105` 个 Python 模块,`63248` 行;规模最大的模块如下。 +- `platform/tools`:`105` 个 Python 模块,`63268` 行;规模最大的模块如下。 | 模块 | 行数 | | --- | ---: | -| `device_service.py` | 16564 | +| `device_service.py` | 16578 | | `firmware_manifest.py` | 3640 | | `user_firmware_matrix.py` | 2347 | | `network_sandbox.py` | 2171 | @@ -168,11 +168,11 @@ - `tests/`:`184` 个可执行 Python 测试文件,分布在 `85` 个目录;`253` 个 evidence JSON。 - `patches/`:`17` 个补丁组,`386` 个 patch 文件。 -- 文档:`762` 个 Markdown 页面;除本生成页外共 `84338` 行。 +- 文档:`762` 个 Markdown 页面;除本生成页外共 `84341` 行。 ## 文档与测试 -- 平台测试:`2617` 项。 +- 平台测试:`2620` 项。 - Docs 新鲜度登记:`290` 行;其中非历史页 `269` 行,历史固定页 `21` 行。 - 文档职责分布:待办 `3`,契约 `9`,证据/差异 `135`,历史固定 `21`,实现/设计 `15`,参考 `101`,工作流/导航 `6`。 - 全量文档盘点:`762` 个 Markdown 页面;职责分布:权威/专题页 `290`,设备档案 `41`,示例 `1`,治理/入口 `9`,文档导航 `1`,其他 `10`,补丁说明 `22`,平台说明 `26`,仓内历史记录 `5`,测试/用例说明 `249`,未登记 docs 页面 `4`,第三方来源说明 `104`。