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:
@@ -347,3 +347,44 @@ TEST(unit/fog_sight_covers_marine_fire_range)
|
||||
units[3].tx = 12; units[3].ty = 12; // droid at the edge tile
|
||||
EXPECT_EQ(acquireTarget(0), 3); // marine locks it in the light
|
||||
}
|
||||
|
||||
// --- emulator shim: GPIO-matrix pin ownership ------------------------------
|
||||
// Parity tests for the pin model that reproduces hardware-only bugs here:
|
||||
// a peripheral driver (i2s_set_pin, ...) claims a pin and drives it, so an
|
||||
// input/ISR on the same GPIO stops seeing the outside world. Regression for
|
||||
// the sound engine silently claiming GPIO0 (MCLK-capable!) and killing the
|
||||
// trackball click line on the device while every emulator build looked fine.
|
||||
|
||||
TEST(unit/shim_claimed_pin_is_dead_input)
|
||||
{
|
||||
test::resetInput();
|
||||
emu::releasePin(BOARD_BOOT_PIN);
|
||||
EXPECT_EQ(digitalRead(BOARD_BOOT_PIN), HIGH); // free pulled-up input
|
||||
|
||||
emu::claimPin(BOARD_BOOT_PIN, "test MCLK");
|
||||
EXPECT(digitalRead(BOARD_BOOT_PIN) == LOW); // driven line, idles low
|
||||
emu::setPin(BOARD_BOOT_PIN, HIGH); // the outside world...
|
||||
EXPECT(digitalRead(BOARD_BOOT_PIN) == LOW); // ...cannot move it
|
||||
|
||||
emu::releasePin(BOARD_BOOT_PIN); // peripheral released
|
||||
EXPECT_EQ(digitalRead(BOARD_BOOT_PIN), HIGH); // input again
|
||||
}
|
||||
|
||||
TEST(unit/shim_edge_survives_same_dispatch_pulse)
|
||||
{
|
||||
// A press+release fully contained between two dispatchIsrs() calls used
|
||||
// to be invisible to the level-diff sweep (the click was swallowed).
|
||||
test::resetInput();
|
||||
emu::releasePin(BOARD_BOOT_PIN);
|
||||
detachInterrupt(BOARD_BOOT_PIN);
|
||||
static int fires;
|
||||
fires = 0;
|
||||
attachInterrupt(BOARD_BOOT_PIN, [] { fires++; }, FALLING);
|
||||
emu::setPin(BOARD_BOOT_PIN, LOW);
|
||||
emu::setPin(BOARD_BOOT_PIN, HIGH); // pulse within one batch
|
||||
emu::dispatchIsrs();
|
||||
EXPECT_EQ(fires, 1); // the edge must survive
|
||||
|
||||
detachInterrupt(BOARD_BOOT_PIN);
|
||||
emu::releasePin(BOARD_BOOT_PIN);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user