/** * ArduinoMcu — thin avr8js wrapper for ATmega328P (Arduino Uno). * * Only digital I/O is modelled (ports B, C, D). Each step advances * the MCU by `floor(seconds * 16e6)` clock cycles (16 MHz clock). */ import type { MicrocontrollerCore } from "./mcu.js"; /** * Structural stand-in for the avr8js module namespace, used for the PUBLIC * registration seam. * * WHY not `typeof import("avr8js")` here: this type lands in the signatures of * setAvr8Module/getAvr8Module, so tsc writes it into arduino.d.ts. A shipped * declaration that resolves avr8js makes `tsc` fail for the analog-only * consumer the README sells ("no MCU emulators pulled in") — the peer is not * installed, so the reference dangles unless they set skipLibCheck. Keeping * avr8js in internal positions only is exactly why rp2040js never reaches the * Pico wrapper's .d.ts, where the seam is typed as a brownout-owned ctor. * * CPU is the only member the seam itself touches (the interop probe below); the * wrapper's real avr8js typing lives on its private fields, which are erased. */ export interface Avr8ModuleLike { CPU: unknown; } export declare function setAvr8Module(mod: Avr8ModuleLike): void; export declare function getAvr8Module(): Avr8ModuleLike | null; /** Parse Intel HEX text into a byte array at offset 0. */ export declare function parseIntelHex(hex: string): Uint8Array; export type PinDriveState = "out-high" | "out-low" | "input" | "input-pullup" | "input-pulldown"; /** * A single GPIO edge captured inside one sim step. * `level` is the post-write drive level: High->1, Low->0, Hi-Z->null. * `cycle` is cpu.cycles at the moment of the PORT/DDR register write. */ export interface PinEvent { pin: string; level: 0 | 1 | null; cycle: number; } export declare class ArduinoMcu implements MicrocontrollerCore { /** Digital-capable I/O pins (D0-D13, A0-A5); A6/A7 are analog-only and excluded. */ readonly ioPins: readonly string[]; /** ADC-capable pins (A0-A7; A6/A7 Nano-only, skipped for Uno by the engine). */ readonly analogPins: readonly string[]; private readonly avr; private cpu; private portB; private portC; private portD; private timer0; private timer1; private timer2; private adc; private _cyclesOwed; private _pinEvents; private _lastPinLevel; private _writeObserver; constructor(hexText: string); /** Advance the MCU by `seconds` of wall-clock time. */ step(seconds: number): void; /** * Current drive state for an Arduino-numbered pin (e.g. "d13", "a0"). * Returns the electrical input mode when the pin DDR bit is 0, preserving * the AVR's internal pull-up state for the analog solver. * Analog-only pins (Nano A6/A7) always return "input" — they have no DDR/PORT path. */ pinDriveState(arduinoPin: string): PinDriveState; /** Feed an external voltage level into a digital input pin. No-op for analog-only pins. */ setInputBit(arduinoPin: string, level: 0 | 1): void; /** * Feed an external analog voltage into an A-pin so the next `analogRead()` returns * a true 10-bit sample. Out-of-range pins (or D-pins) are ignored. */ setAnalogVolts(arduinoPin: string, volts: number, vcc?: number): void; /** All GPIO edges captured during the most recent step(), in capture order. */ 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 _capturePort; private _port; } /** All Arduino digital-capable I/O pin IDs (D0-D13, A0-A5). Excludes analog-only Nano pins. */ export declare const ARDUINO_IO_PINS: string[]; /** Every A-pin that participates in ADC reads (A0-A7). A6/A7 are Nano-only. */ export declare const ARDUINO_ANALOG_PINS: string[]; /** Pins that exist only on the Nano (not the Uno). Engine skips ADC sampling for these on Uno-kind boards. */ export declare const ARDUINO_NANO_ONLY_PINS: Set;