From 061bb91da11e7936a6f341639283199214e37b9e Mon Sep 17 00:00:00 2001 From: David Montero Date: Thu, 9 Jul 2026 19:16:37 +0200 Subject: [PATCH] fix(esp32-c3): drive digital inputs from the SPICE solve (spiceDrivenInputs) Esp32C3Simulator already had the GPIO_IN plumbing (setPinState -> gpioIn -> GPIO_IN_REG read) but never opted into connectDigitalInputsToMcu, so a pin wired to a switch/button was never fed the solved circuit voltage and digitalRead() ignored the real wiring. Enabling the flag (as AVRSimulator and RP2040Simulator already do) completes the issue #247 fix: the ESP32-C3 now reads GPIO2 from the SPICE solve, so toggling the slide switch flips the LED. BasicParts' button/slide-switch seed already yields to spiceDriven(), so there is no double-drive. --- frontend/src/simulation/Esp32C3Simulator.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/simulation/Esp32C3Simulator.ts b/frontend/src/simulation/Esp32C3Simulator.ts index be0347e1..01997859 100644 --- a/frontend/src/simulation/Esp32C3Simulator.ts +++ b/frontend/src/simulation/Esp32C3Simulator.ts @@ -112,6 +112,14 @@ const CYCLES_PER_FRAME = Math.round(CPU_HZ / 60); const CYCLES_PER_TICK = 160_000; export class Esp32C3Simulator { + // Opt into connectDigitalInputsToMcu: after every SPICE solve the connector + // thresholds each input pin's net voltage and pushes the logic level into the + // GPIO_IN register via setPinState(). So digitalRead() reflects the real + // wiring (a switch/button tied to 3V3 reads HIGH) instead of a hardcoded part + // seed. The connector skips MCU-driven output pins and floating (non-sourced) + // nets, so event-driven parts with no SPICE model keep driving their pins via + // the part layer. Mirrors AVRSimulator / RP2040Simulator. + readonly spiceDrivenInputs = true; private core: RiscVCore; private flash: Uint8Array; private dram: Uint8Array;