/** * RP2040Mcu — a MicrocontrollerCore backed by rp2040js (Raspberry Pi Pico). * * This is the engine-coupling layer only: it maps the shared MicrocontrollerCore * contract onto rp2040js's GPIO/ADC/CPU so the MNA solver can drive and sample a * Pico exactly the way it already does an Arduino (avr8js). Firmware/MicroPython * loading (UF2 + the raw-REPL script path) is layered on top via `loadFirmware` * and is intentionally separable from the coupling so the coupling can be * unit-tested against real rp2040js without booting a full image. * * Clocking mirrors rp2040js's own Simulator.execute: each instruction returns a * cycle count and advances the SimulationClock (125 MHz => 8 ns/cycle), and WFI * fast-forwards to the next scheduled alarm. `step(seconds)` runs that loop for a * wall-clock budget so timers/ADC/USB alarms fire, honoring the same * outputs-valid-after-step / inputs-consumed-next-step phasing as ArduinoMcu. */ import type { MicrocontrollerCore, PinDriveState, PinEvent } from "./mcu.js"; /** Digital-capable header + LED pins. */ export declare const RP2040_IO_PINS: readonly string[]; /** ADC-capable pins (GP26/27/28 => ADC0/1/2). */ export declare const RP2040_ANALOG_PINS: readonly string[]; /** * Parse a Raspberry Pi UF2 image and copy its payload into `flash` at the * offset each block targets (relative to 0x10000000). Non-flash blocks are * ignored. Returns the number of blocks applied. */ export declare function loadUF2IntoFlash(uf2: Uint8Array, flash: Uint8Array): number; export declare class RP2040Mcu implements MicrocontrollerCore { readonly ioPins: readonly string[]; readonly analogPins: readonly string[]; private sim; private rp2040; private cdc; private _firmware?; private _pinEvents; private _lastLevel; private _removeListeners; private _writeObserver; private _serialOut; private _connected; private _pendingSource; private _replPhase; private _nudgeCount; private _heldReads; private _txQueue; /** @param firmware optional UF2 image (e.g. MicroPython) to boot from flash. */ constructor(firmware?: Uint8Array); /** * (Re)build the emulator from scratch and boot the firmware. Used by the * constructor and reset(); a full rebuild is the reliable way to re-enumerate * USB so the REPL feed can re-run after reset(). */ private boot; /** Copy a UF2 firmware image into flash and jump the core into flash boot2. */ loadFirmware(uf2: Uint8Array): void; /** * Queue a MicroPython program to run. It is fed to the REPL (raw mode) once * the firmware has booted and USB has enumerated — driven across step() calls * so the contract stays synchronous. Re-queueing replaces the program on the * next boot; call reset() to re-run from a clean state. */ runScript(source: string): void; /** True once the queued program has been submitted to the REPL. */ get scriptStarted(): boolean; private send; /** Move queued REPL bytes into USBCDC's tx FIFO, as far as it has room. */ private fillTxFifo; private pumpRepl; step(seconds: number): void; pinDriveState(pin: string): PinDriveState; setInputBit(pin: string, level: 0 | 1): void; /** * Feed an external analog voltage into an ADC pin. rp2040js reads * `channelValues` as raw 12-bit conversion results, so the voltage is * converted to counts against ADC_VREF. The engine does not model the * ADC_VREF pad separately; on the Pico it is the filtered 3V3 rail, which is * what the engine passes as `vcc`. */ setAnalogVolts(pin: string, volts: number, vcc?: number): void; getStepPinEvents(): readonly PinEvent[]; /** H11 readback seam (see MicrocontrollerCore.setStepWriteObserver). */ setStepWriteObserver(observer: ((events: readonly PinEvent[]) => void) | null): void; /** Drop the captured edges without advancing (see MicrocontrollerCore). */ clearStepPinEvents(): void; reset(): void; private installListeners; private removeListeners; }