From ede49e2e78ffe157c84bbd6ff42758aab669bd13 Mon Sep 17 00:00:00 2001 From: David Montero Crespo Date: Thu, 6 Aug 2026 00:54:54 +0200 Subject: [PATCH] feat(sim): duck-type the browser MicroPython path so pro simulators plug in The in-browser MicroPython run path required `sim instanceof RP2040Simulator`, so an overlay-registered pro simulator (e.g. the RP2350's ARM MicroPython) could never use it. Accept any simulator exposing loadMicroPython(files) instead - generic plumbing, no board-specific reference; a sim without the method is a no-op exactly as before. RP2040 behavior is unchanged. --- frontend/src/store/useSimulatorStore.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/src/store/useSimulatorStore.ts b/frontend/src/store/useSimulatorStore.ts index 1c1ceeb3..7c1161f0 100644 --- a/frontend/src/store/useSimulatorStore.ts +++ b/frontend/src/store/useSimulatorStore.ts @@ -1993,9 +1993,16 @@ export const useSimulatorStore = create((set, get) => { esp32Bridge.setPendingMicroPythonCode(prelude + mainFile.content); } } else { - // RP2040 path: load firmware + filesystem in browser - const sim = getBoardSimulator(boardId); - if (!(sim instanceof RP2040Simulator)) return; + // Browser-side firmware+filesystem path. Any simulator exposing + // `loadMicroPython(files)` plugs in here — the OSS RP2040Simulator, or + // an overlay-registered pro simulator (e.g. the RP2350's ARM + // MicroPython). Duck-typed rather than `instanceof RP2040Simulator` so + // pro boards need no change here; a sim without the method is a no-op. + const sim = getBoardSimulator(boardId) as { + attachPioPeripheral?: (kind: string, id: string) => void; + loadMicroPython?: (files: Array<{ name: string; content: string }>) => Promise; + } | null; + if (typeof sim?.loadMicroPython !== 'function') return; // (Re)attach the PIO peripheral before loading firmware. An example // deep-link adds the board during render, which can race the pro // overlay's async mountPro that installs the CYW43 factory — so the @@ -2004,7 +2011,7 @@ export const useSimulatorStore = create((set, get) => { // is idempotent; by run time the factory is installed, so a paid user // gets the W peripheral -> the RPI_PICO_W firmware variant. No-op in // OSS (no factory) and for free users (factory returns null). - sim.attachPioPeripheral(board.boardKind, boardId); + sim.attachPioPeripheral?.(board.boardKind, boardId); await sim.loadMicroPython(files); }