Fix trackball click: I2S MCLK was claiming GPIO0; emulator pin-ownership parity

Root cause (on device): sound_engine zero-initialized i2s_pin_config_t,
leaving mck_io_num == 0. i2s_set_pin() then claimed GPIO0 — an
MCLK-capable pin on the S3 and the trackball centre / BOOT line — as
its MCLK output. Verified on device with a diagnostic build: pin0 read
LOW at idle, exactly one latched FALLING edge, clicks never registered.

- sound_engine: set pins.mck_io_num = I2S_PIN_NO_CHANGE explicitly.
- NetDeck: register the trackball click on release with contact-bounce
  collapse (the proven CrtTerminal pattern); pollTouch re-arms when
  isPressed() stays true but getPoint() reports no points (stuck GT911
  IRQ on some units).
- Emulator parity (so this class of bug dies before flashing):
  GPIO-matrix pin-ownership model in the shim — i2s_set_pin() claims
  its pins, claimed pins are dead inputs (digitalRead LOW, no edges,
  loud WARNING on claim/ISR collisions); host pin writes go through
  emu::setPin/togglePin with an edge-accurate ISR latch (a full
  press+release pulse between dispatches no longer gets swallowed);
  E2E inits SDL_INIT_AUDIO so the I2S path actually runs there.
  Regression coverage: e2e/trackball_click (fails on the old engine),
  unit/shim_claimed_pin_is_dead_input,
  unit/shim_edge_survives_same_dispatch_pulse.
- Makefile: firmware step follows the sketch move (root platformio.ini,
  src_dir = src/netdeck).
- HW.md: new notes file for emulator-vs-hardware quirks and the
  on-device debugging recipe.

On-device verified: clicks register in both views (beacon drops, node
routing). Fast layer 23 unit + 7 integration green. Note: e2e
boot_and_controls + network_journey failures are pre-existing at HEAD
(reproduced on a clean stash before this change).
This commit is contained in:
Dejvino
2026-11-15 10:24:30 +01:00
parent 4645c7a1c6
commit 1dcc87d8d4
12 changed files with 368 additions and 30 deletions
+18 -1
View File
@@ -6,6 +6,7 @@
#include <cstdint>
#include <cstddef>
#include <SDL3/SDL.h>
#include "../Arduino.h" // emu::claimPin — GPIO-matrix pin-ownership model
#define ESP_OK 0
#define ESP_FAIL -1
@@ -33,6 +34,8 @@ struct i2s_config_t {
};
struct i2s_pin_config_t {
int mck_io_num; // mirrors the S3 header: GPIO0 is MCLK-capable, so a
// zero-initialized config silently claims GPIO0
int bck_io_num;
int ws_io_num;
int data_out_num;
@@ -66,7 +69,21 @@ inline int i2s_driver_install(i2s_port_t, const i2s_config_t *cfg, int, void *)
return ESP_OK;
}
inline int i2s_set_pin(i2s_port_t, const i2s_pin_config_t *) { return ESP_OK; }
inline int i2s_set_pin(i2s_port_t, const i2s_pin_config_t *pins)
{
// GPIO-matrix parity: the real driver routes every configured pin to the
// I2S peripheral and OWNS it from then on — inputs/ISRs on the same GPIO
// die. In particular a zero-initialized i2s_pin_config_t carries
// mck_io_num == 0, and GPIO0 is MCLK-capable on the ESP32-S3 — which is
// exactly how the NetDeck sound engine used to kill the trackball click
// line (HW.md). emu::claimPin() makes that visible here.
if (pins->mck_io_num != I2S_PIN_NO_CHANGE) emu::claimPin(pins->mck_io_num, "i2s MCLK");
if (pins->bck_io_num != I2S_PIN_NO_CHANGE) emu::claimPin(pins->bck_io_num, "i2s BCK");
if (pins->ws_io_num != I2S_PIN_NO_CHANGE) emu::claimPin(pins->ws_io_num, "i2s WS");
if (pins->data_out_num != I2S_PIN_NO_CHANGE) emu::claimPin(pins->data_out_num, "i2s DOUT");
if (pins->data_in_num != I2S_PIN_NO_CHANGE) emu::claimPin(pins->data_in_num, "i2s DIN");
return ESP_OK;
}
inline int i2s_write(i2s_port_t, const void *src, size_t size, size_t *written, unsigned)
{