/** * MicrocontrollerCore — the engine-facing abstraction over a microcontroller * emulator. The avr8js-backed `ArduinoMcu` is the first implementation; a * future rp2040js-backed Raspberry Pi Pico core implements the same contract, * so the engine's drive-stamp and input-sample loops stay core-agnostic and * `SimState.arduinos` can hold a heterogeneous mix of boards. * * I/O phasing invariant (must hold for every implementation): one converged * electrical interval is committed first, then its endpoint inputs are pushed * through `setInputBit`/`setAnalogVolts` and `step()` advances the core exactly * once. The resulting `pinDriveState()` and ordered `PinEvent`s are applied by * the next MNA interval. Rejected electrical trials therefore never advance * firmware, and each accepted endpoint is sampled once. */ import { type PinDriveState, type PinEvent } from "./arduino.js"; import type { RP2040Mcu } from "./rp2040.js"; export type { PinDriveState, PinEvent }; export { setAvr8Module, getAvr8Module } from "./arduino.js"; /** * The rp2040js-backed Pico core is a large emulator that we keep OUT of the base * worker bundle. `./rp2040` (and thus `rp2040js`) is imported only as a type here; * the worker `import()`s it lazily when a Pico is actually placed and registers * the constructor below, so the synchronous `mcuFactory` can build one without a * static dependency edge. Until registered (like an unregistered firmware), a * Pico stays inert; a reload boots it once both are present. */ type Rp2040Ctor = new (firmware?: Uint8Array) => RP2040Mcu; export declare function setRp2040Module(ctor: Rp2040Ctor): void; export declare function getRp2040Module(): Rp2040Ctor | null; export declare function setMcuFirmware(kind: string, image: Uint8Array): void; export declare function getMcuFirmware(kind: string): Uint8Array | undefined; /** * Program image loaded into a core. Arduino boards run a compiled Intel HEX * (`hex`); MicroPython boards (Pico) will run source (`script`). Only the * field(s) relevant to the target kind are read by `mcuFactory`. */ export interface McuProgram { hex?: string; script?: string; } export interface MicrocontrollerCore { /** Digital-capable I/O pin ids this core exposes (engine iterates these). */ readonly ioPins: readonly string[]; /** Pin ids that participate in ADC reads. */ readonly analogPins: readonly string[]; /** Advance the core by `seconds` of wall-clock time. */ step(seconds: number): void; /** Current drive state of a pin, including weak internal input pulls. */ pinDriveState(pin: string): PinDriveState; /** Feed an external logic level into a digital input pin. */ setInputBit(pin: string, level: 0 | 1): void; /** Feed an external analog voltage into an ADC-capable pin. */ setAnalogVolts(pin: string, volts: number, vcc?: number): void; /** GPIO edges captured during the most recent `step()`, in capture order. */ getStepPinEvents(): readonly PinEvent[]; /** * Drop the captured step events without advancing. The engine calls this * when it decides a core will not step (unpowered): step() is the only * place a core clears its own list, so a skipped core would otherwise keep * describing its last powered step forever, and edge decoders must not * re-replay those stale edges. Optional: this interface is public * (brownout/mcu, and DeviceContext.arduinos), so a core that predates it * keeps compiling, and the engine treats a missing implementation as the * pre-H13 behaviour for that core (its stale list is fenced by the * consumed-once gate alone). */ clearStepPinEvents?(): void; /** Re-load the program image and clear runtime state. */ reset(): void; /** * H11 readback: feed every GPIO write the core captures during the next * step() to this observer, synchronously as each write happens, with only * the events that write appended — the same stream, in the same order, * getStepPinEvents() returns at the end of the step. The engine uses it to * run a clocked part's digital shadow inside the step and push the part's * output levels back through setInputBit, so a read between two writes * (a shiftIn()) sees the level the writes produced. One observer pairs * with exactly one step(); the engine passes null right after. Optional: a * core without it cannot be read back to mid-step, and the engine builds * no shadow against it. */ setStepWriteObserver?(observer: ((events: readonly PinEvent[]) => void) | null): void; } /** * Construct the core for a microcontroller board kind, or null when the kind * isn't a known MCU or the program image is empty (nothing to run). Today only * the avr8js Arduino core; extend the dispatch here for new MCU kinds (e.g. * `raspberry_pi_pico`). */ export declare function mcuFactory(kind: string, program: McuProgram): MicrocontrollerCore | null;