Commit Graph

95 Commits

Author SHA1 Message Date
David Montero 19f50d9abc test_intel: phase A — 8080 INTA bus protocol
Replace the synthesised-RST-7 stub with a real INTA bus cycle. When
int_pending && IME, the chip emits status byte 0x23 on D during T1
(M1+INTA+WO̅) and samples the RST opcode external hardware drives on
the data bus during DBIN. Decodes RST n (0xC7..0xFF) and push+vectors.
Multi-byte INTA opcodes (CALL nnn) deferred.

Test rewrites the INT case to install a fixture INTA driver: snoop
SYNC + status byte, latch a pending flag, drive RST 5 (0xEF) on the
data bus during the next DBIN edge. Driver registers AFTER fake_rom
so its late drive overrides fake_rom's program-byte drive on the
same DBIN edge.

Tests: 8080 17→18 passing; test_intel 63→64 passing.

Adds master plan doc autosearch/18_complete_emulation_plan.md
covering phases A-G (this commit completes phase A).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 04:33:55 +02:00
David Montero 323366dc53 test_intel: status docs for completed chip lineup
All 5 retro CPUs (Intel 4004/4040/8080/8086 + Zilog Z80) plus all 3
bus devices (rom-32k, ram-64k, latch-8282) are now implemented.
Update top-level matrix and per-chip READMEs to reflect 63/80 tests
passing, 0 failed, 17 deferred.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 03:59:44 +02:00
David Montero f9906c3ad5 test_intel: Intel 8086 chip (minimum mode baseline)
~750 LOC clean-room from Intel iAPX 86,88 User's Manual (Oct 1979),
cross-validated against 8086tiny (MIT), MartyPC (MIT, hardware-
validated 99.9997% on SingleStepTests 8088 V2), YJDoc2/8086-Emulator
(Apache+MIT). No GPL refs (Fake86, DOSBox, MAME, QEMU all excluded).

Implemented:
- 40-pin minimum-mode contract (AD0..AD15, A16..A19, ALE, RD, WR,
  M/IO, DT/R̅, DEN̅, BHE̅, INTR, NMI, INTA̅, RESET, READY, TEST̅, CLK,
  HOLD, HLDA, MN/MX̅, VCC, GND).
- Reset state per [I86] PDF p.51: CS=0xFFFF, IP=0, all other segs=0,
  flags clear with reserved bits canonicalised. First fetch at the
  physical address 0xFFFF0 with proper ALE strobe.
- Bus cycle T1-T4 (instruction-per-tick collapse): drive AD with low
  16 addr, A with high 4, pulse ALE, switch AD to input, assert RD̅
  (or drive data + WR̅ for writes).
- 20-bit physical addressing: (segment<<4)+offset modulo 1 MB.
- Register file: AX/BX/CX/DX with byte halves (union), SP/BP/SI/DI,
  IP, CS/DS/ES/SS, FLAGS.
- ModR/M decode for memory operands (Table 4-10 effective-address
  formulas with default-segment selection).
- ISA subset: NOP, HLT, MOV reg/imm and r/m forms, MOV sreg, MOV
  AL/AX,[addr]; ADD/OR/ADC/SBB/AND/SUB/XOR/CMP r/m + r and reverse
  + AL/AX-imm forms; Group 1 (immediate ALU); INC/DEC r16; PUSH/POP
  r16; PUSHF/POPF; CLC/STC/CLI/STI/CLD/STD/CMC; conditional short
  jumps Jcc; JMP near/short/far; CALL near/far; RET near/far +imm;
  LOOP/LOOPE/LOOPNE/JCXZ; Group 5 (INC/DEC/CALL/JMP/PUSH r/m16);
  segment-override prefixes.

Deferred (17 it.todo tests across ISA/integration):
- String ops (MOVS/CMPS/SCAS/LODS/STOS) with REP prefix.
- MUL/DIV/IMUL/IDIV.
- BCD adjust (DAA/DAS/AAA/AAS/AAM/AAD).
- Port I/O (IN/OUT).
- Hardware interrupts (NMI/INTR vectoring + INTA cycle).
- Maximum-mode bus protocol.
- Cycle-accurate prefetch queue.

Brings test_intel to 63 passing tests (was 60), 0 failed, 17 todo.
All 6 chips from the original plan (8080, Z80, 4004, 4040, 8086,
plus rom-32k/ram-64k/latch-8282 bus devices) now compiled and
their pin contracts + reset behavior + bus protocols are validated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 03:58:49 +02:00
David Montero 173418aaf5 autosearch: Intel 8086 + 8282 spec + reference impls
Authoritative spec from Intel iAPX 86,88 User's Manual (1979) +
embedded 8282/8283 datasheet in Appendix B. Cross-validation against
three permissively-licensed open-source emulators:
- 8086tiny (MIT, Adrian Cable, ~600 LOC)
- MartyPC (MIT, dbalsom, hardware-validated, 99.9997% on 8088 V2 tests)
- YJDoc2/8086-Emulator (Apache+MIT, partial)

Excluded GPL refs: Fake86, DOSBox, MAME, QEMU.

Critical findings for clean-room implementation:
- 40-pin DIP min-mode pinout with AD0..AD15 multiplexed (low addr in
  T1, data in T2..T4) and A16..A19/S3..S6 multiplexed.
- Reset state: CS=0xFFFF, IP=0, all other segs=0. Physical first
  fetch at 0xFFFF0.
- ALE pulses high in T1, falls at end of T1 — external 8282 latches
  on falling edge to demux.
- ModR/M decode: 16-bit effective-addr table from the manual.
- DAA differs from 8080 only in the carry-treatment around BCD
  borrow; AAA/AAS/AAM/AAD specific to 8086.
- MUL/DIV: OF and CF defined; SF/ZF/AF/PF undefined per Intel.
- Undocumented: POP CS (0x0F) and SALC (0xD6) — original 8086 only,
  removed in 80186+.

PDFs (62 MB iAPX manual, 215 KB 8282 datasheet) saved under pdfs/.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 03:53:36 +02:00
David Montero 4aa13897c6 test_intel: Z80 INT handling + promoted todo tests
Z80 chip enhancements:
- Add maskable INT̅ handling. Pin is level-triggered, active-low. The
  on_int watcher tracks line state; step() services at instruction
  boundaries when IFF1=1.
- IM 0/1 vector to 0x0038; IM 2 vectors via I:00 indirection (no
  interrupt-controller hardware on the bus, so we approximate the
  data byte as 0x00 — user code must pre-load the vector table).
- INTA cycle clears IFF1 and IFF2 per Zilog UM008003 p. 24.
- Power-on reset state: chip starts with reset_active=true so the
  RESET̅ rising edge releases the chip (the watcher only fires on
  edges; without an initial-true assumption, setting RESET=false
  was a no-op and the chip executed instructions during the
  test's pre-reset cycles).

Test infrastructure:
- bootZ80 no longer advances time after RESET deassert. Same lesson
  as bootCpu in the 8080 tests — caller may need to poke RAM
  contents BEFORE the chip executes.

5 it.todo tests promoted to passing:
- LDIR copies a memory block from HL to DE
- LD A, (IX+d) reads via IX with signed displacement
- EXX swaps the main register set with the shadow set
- NMI̅ falling edge pushes PC and vectors to 0x0066
- IM 1 + INT̅ vectors to 0x0038

Total test_intel: 60 passing (was 55), 0 failed, 17 todo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 03:53:06 +02:00
David Montero 148c56d6dc test_intel: complete Intel 4040 new instructions
The 4040 is a binary-compatible superset of the 4004. This commit:

- Adds the full 4004 ISA into 4040.c (LD/XCH/INC/ADD/SUB/JCN/JUN/
  JMS/BBL/FIM/FIN/JIN/SRC/ISZ/LDM/I-O/ACC group/DAA/KBP/etc.) so the
  4040 actually executes user code, not just NOPs.
- Adds the 14 4040-only opcodes per MCS-40 p. 1-22 at OPR=0000
  OPA=0x01..0x0E:
    HLT, BBS, LCR, OR4, OR5, AN6, AN7, DB0, DB1, SB0, SB1, EIN, DIN,
    RPM (4289 stub).
- Implements bank-aware register access — physical reg[0..7] is
  bank 0's R0..R7, reg[8..15] is shared R8..R15, reg[16..23] is
  bank 1's R0..R7. SB0/SB1 toggle the active R0..R7 mapping.
- 7-deep PC stack (vs 4004's 3-deep) per MCS-40 p. 1-12.
- Interrupt vectoring already in place from prior commit; BBS now
  pops PC and clears INTA.

3 it.todo tests promoted to passing:
- INT high after EIN vectors PC to 0x003 and asserts INTA.
- BBS pops PC and clears INTA.
- SB1 + FIM writes to bank-1 R0..R7 (verified by ISZ wrap behaviour:
  bank-0 R0=F → ISZ wraps to 0 → no branch, distinguishing from a
  buggy SB1 that would have aliased the write to bank 0).

Adds Bus4040 helper (parallel to Bus4004) for feeding opcodes via
the multiplexed nibble bus. Total test_intel: 55 passing (was 52),
0 failed, 22 todo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 03:44:01 +02:00
David Montero ab90bd7618 test_intel: complete Intel 4004 ISA
All 46 4004 instructions implemented per MCS-4 manual ([M4] Table V):
- ALU: NOP, INC Rn, ADD/SUB Rn, LD/XCH Rn, IAC/DAC, RAL/RAR, CMA, CMC,
  STC, CLB, CLC, TCC, TCS, DAA, KBP
- Memory/IO: SRC Pn (no-op stub), I/O group (WRM/WMP/WRR/WPM/WR0..3,
  RDM/RDR/ADM/RD0..3, SBM) all decoded; RAM-side effects stubbed
  pending real 4001/4002 chips
- Control flow: JUN (12-bit jump), JMS (push+jump), BBL (pop+ACC),
  JCN with full C1/C2/C3/C4 condition logic, ISZ in-page branch,
  FIM (load reg pair), FIN/JIN (indirect via P0)
- DCL: load CMRAM bank select

Plus a Bus4004 helper class in 4004.test.js that mirrors a 4001 ROM
chip — pre-drives D0..D3 with the appropriate nibble during M1/M2,
tracks observed PC via the chip's A1/A2/A3 address-bus drives. This
mechanism lets the test feed arbitrary opcode streams without
needing a separate 4001 ROM chip on the canvas.

5 new ISA tests promoted from it.todo to passing:
- NOP advances PC by 1
- JUN jumps to 12-bit target
- JMS+BBL stack push/pop
- JCN with C4 jumps when TEST is logic-0
- JCN does not jump when condition false

3 it.todo remain: LDM, FIM, Busicom-style integration. These need
accumulator-state observability (a fake 4002 RAM via SRC+WRM) to
test, which is deferred.

Total test_intel: 52 passing (was 43), 0 failed, 25 todo.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 03:38:11 +02:00
David Montero Crespo bcc7129aa3 feat: Add support for SSD168x ePaper panels
- Introduced EPaperPanels.ts to define configurations for various ePaper panels including dimensions, refresh rates, and controller details.
- Implemented SSD168xDecoder.ts to handle the decoding of SPI commands for the SSD168x family of ePaper displays.
- Created EPaperPart.ts to manage the simulation of ePaper panels, integrating with the existing simulator architecture and handling events.
- Added example sketches for 2.13", 2.9", 4.2", and 7.5" ePaper displays, demonstrating basic functionality and text rendering.
- Ensured compatibility with AVR, RP2040, and ESP32 platforms, with appropriate pin configurations for each.
2026-04-29 22:23:00 -03:00
David Montero 4a2fa68e51 test_intel: Intel 8282 octal latch
Companion chip for 8086 minimum-mode boards that demultiplexes
AD0..AD15 → A0..A15 under control of ALE. ~80 LOC clean-room from
the public Intel 8282/8283 datasheet.

Pin contract (20-pin DIP): DI0..7 in, DO0..7 out, STB strobe, OE̅
output enable, VCC, GND. Behaviour:
  STB=1, OE̅=0 → DO follows DI (transparent)
  STB falling → latch held while STB=0
  OE̅=1 → DO pins released (modelled as VX_INPUT)

Tests: 4/4 passing (pin contract, transparent mode, latch hold,
output enable). Brings test_intel total to 47 passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 22:51:19 +02:00
David Montero ef812c3d9b test_intel: Intel 4004 + 4040 chip implementations
The two earliest commercial Intel CPUs as velxio custom chips:

- 4004.c (~150 LOC): 16-pin DIP, 8-phase frame (A1..X3), SYNC at A1
  with PC nibble walk on D0..D3 (low-first per MCS-4 Fig. 2), CMROM
  strobe during M1. ISA decoded as NOP for now — full 46-instruction
  set deferred to ISA phase.

- 4040.c (~250 LOC): 24-pin DIP per MCS-40 pp. 1-5/1-6 (STP/STPA/INT/
  INTA/CY/dual CMROM/dual standby Vdd). 4004-compatible bus + STP
  latched at M2 → STPA asserts at X3 + INT forced JMS to PC=0x003.
  14 new opcodes decoded as NOP for now.

Test refinements (analogous to bootCpu fix from 8080 work):
- bootChip no longer advances time post-RESET so first observed cycle
  starts at A1 of cycle 0 with PC=0.
- SYNC sampler latches on first edge (was over-collecting on
  subsequent SYNC pulses).
- 4040 test renamed STOP→STP, STOPACK→STPA per MCS-40 datasheet pin
  names; added INTA, CY, VDD1, VDD2 pins; SYNC-stops assertion
  removed (manual: STOP mode keeps clock and SYNC running).

Brings test_intel suite from 37 to 43 passing tests; 0 failures;
remaining 3 active are 8086 (deferred), 29 todo are intentional
deferred integration tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 22:45:34 +02:00
David Montero fd93c703c6 autosearch: Intel 4004/4040 spec + reference impls
Authoritative spec docs cite Intel MCS-4 (Feb 1973) and MCS-40 (Nov 1974)
manuals page-by-page. Reference-implementations doc surveys four
permissively-licensed open-source emulators (markablov/i40xx,
Kostu96/K4004, lpg2709/emulator-Intel-4004, alshapton/Pyntel4004) for
cross-validation, explicitly excluding GPL sources (MAME mcs40,
carlini/intel-4004-in-4004-bytes-of-c).

Critical findings:
- 4040 interrupt vector is fixed at PC=0x003 (no vector table).
- New 4040 instructions all live at OPR=0000, OPA=0x01..0x0E.
- 4004 DAA (opcode 0xFB) is single-nibble, very different from 8080.
- 4040 STP/STPA/INTA pin names per datasheet (not STOP/STOPACK).
- R16..R23 are not directly named — they're Bank-1 R0..R7 via SB0/SB1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 22:37:16 +02:00
David Montero e493304cd6 autosearch — Research notes for Intel + Z80 custom-chip emulation 2026-04-29 22:24:02 +02:00
David Montero Crespo 89c9d7c6c6 Implement TCP and UDP NAT services for chip-initiated connections
- Added tcp_nat.py to handle TCP NAT, implementing the three-way handshake, data flow, and connection state management.
- Introduced udp_nat.py for UDP NAT, managing chip-initiated datagrams and maintaining flow state.
- Created integration tests in test_picow_net_bridge.py to validate the functionality of the TCP and UDP NAT implementations, including ARP, DHCP, ICMP, and DNS interactions.
2026-04-29 08:43:41 -03:00
David Montero Crespo 175b248108 feat(epaper): Add SVG layouts and emulation plan for ePaper panels
- Introduced SVG layout dimensions for Phase 1 (B/W mono) and Phase 2 (colour) ePaper panels, detailing active areas, bezels, and pin layouts.
- Developed a phased emulation plan outlining the architecture and deliverables for different panel types, including SSD168x and UC81xx.
- Created a canonical "Hello, World!" sketch for the 1.54" ePaper panel, ensuring compatibility across ESP32, Raspberry Pi Pico, and Arduino Uno.
- Implemented a pure Python SSD168x decoder to validate SPI command sets and framebuffers against specifications.
- Added tests for compiling the hello-world sketch across supported boards and for the SSD168x protocol to ensure correct framebuffer behavior.
2026-04-29 02:33:59 -03:00
David Montero Crespo 641ac8c1de Add comprehensive tests for Cyw43Emulator functionality and lifecycle
- Implemented handshake tests to validate initial bus state and register responses.
- Created end-to-end tests for Pico W LED blinking using MicroPython firmware.
- Added SDPCM framing tests to ensure proper encoding and decoding of control frames.
- Developed IOCTL tests to verify command responses and state changes in the emulator.
- Established a full lifecycle test for WiFi operations, including scanning, connecting, and packet handling.
- Introduced TypeScript configuration for test files to ensure compatibility and strict type checking.
2026-04-29 00:21:26 -03:00
David Montero Crespo 7f2014bef7 Add ESP32 chip demos and comprehensive tests for I2C, SPI, and UART interactions
- Implemented `esp32_spi_chip_demo.ino` to demonstrate SPI communication with a 74HC595 shift register.
- Created `esp32_uart_chip_demo.ino` for UART loopback testing with ROT13 transformation.
- Added Python tests for compiling chips and sketches, ensuring valid WASM output and successful compilation for various board families.
- Developed end-to-end tests for ESP32 with custom chips using I2C and SPI, validating synchronous communication through the backend.
- Introduced GPIO bridge tests to verify serial communication and GPIO state changes.
- Ensured all tests validate the expected behavior of the custom chips and their interaction with the ESP32 firmware.
2026-04-28 19:24:39 -03:00
David Montero Crespo fa170a082a Add shared validators and test configurations for Velxio projects
https://github.com/kritishmohapatra/100_Days_100_IoT_Projects
- Introduced `_lib.py` containing shared validators for board support and static source analysis for MicroPython projects.
- Added `conftest.py` to configure pytest for the test suite, simplifying import paths.
- Created `NOT_SUPPORTED.md` files for two projects indicating they cannot be emulated in Velxio due to lack of source code.
- Implemented unit tests for the unsupported projects to verify the presence of the NOT_SUPPORTED marker and source preservation.
2026-04-28 00:36:05 -03:00
David Montero Crespo 8e769f8a4e feat(multi-board): add wire-aware cross-board interconnect router
Fixes the user-reported bug where two RPi Pico W boards wired GP0↔GP1
running SerialPassthrough don't communicate. Replaces the broken
broadcast-style cross-board logic in addBoard (only routed AVR↔Pi3B,
ignored wires entirely, no RP2040↔anything path) with a wire-aware
Interconnect singleton.

Architecture: digital pin transitions are the lowest-common-denominator
abstraction. Each simulator's hardware peripherals (UART/I2C/SPI) and
bit-banging libraries (SoftwareSerial, software I2C) decode the
transitions naturally — propagate the pin and the protocols come for
free. For cross-process boards (ESP32 backend QEMU, Pi3B QEMU) a
byte-level shortcut is additionally enabled on hardware-UART pin
pairs to handle high-baud links over WebSocket latency.

Implementation:
- New simulation/Interconnect.ts singleton subscribes to wire/board
  changes via the Zustand store. Handlers per tier: browser-sim →
  pinManager.onPinChange, ESP32 → Esp32Bridge.sendPinEvent, Pi3B →
  bridge.sendPinEvent. Re-entrancy guard via per-(board,pin) Set.
- New utils/boardProtocols.ts classifies pins (uart-tx, i2c-sda, etc.)
  per board kind, used as optimization hint for the byte shortcut.
- types/wire.ts: added signalType field, exports WireSignalType /
  WireColorMap (fixes a pre-existing TS import error in wireColors).
- Deleted the bridgeMap/simulatorMap broadcast forEach blocks in
  addBoard. Initial board + future boards register with Interconnect
  via setInterconnectRuntime + store subscription.
- PinManager.resetPinStates() helper for test isolation.

Tests (16 new files, 96 tests, all passing):
- Per-pair × per-protocol matrix: dual-arduino-digital,
  dual-pico-digital, arduino-pico-digital, triple-pico-digital-chain,
  dual-arduino-hw-uart, dual-arduino-software-serial,
  arduino-pico-mixed-uart, arduino-esp32-uart, dual-esp32-uart,
  pi3-pico-uart, arduino-pico-i2c, arduino-arduino-spi,
  interconnect-routing, dual-arduino-multi-protocol (UART+I2C+SPI+
  digital + concurrent), dual-pico-multi-protocol (UART0+UART1 alt+
  I2C0+I2C1+SPI0+digital + 3-Pico star topology)
- Updated dual-pico-serial-passthrough to assert correct behaviour
- Backend test/multi_board_esp32/test_dual_esp32_serial.py for two
  real QEMU instances (skip-graceful when lcgamboa lib absent)

Verified: 1107/1107 tests pass, zero regressions, vite build OK.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-25 19:47:40 -03:00
davidmonterocrespo24 2bc492c16f test(e2e): add ESP32 + SPICE photodiode co-simulation test
Follows the same pattern as test_esp32_spice_analog.mjs and
test_esp32_spice_ntc_bridge.mjs: compile an ESP32 sketch on-the-fly via
/api/compile/, boot QEMU through the backend WebSocket, and sweep lux
levels while verifying analogRead() returns what ngspice solved.

The netlist uses the exact photodiode cards emitted by
frontend/.../componentToSpice.ts (D_<id> + I_<id>_ph + DPHOTO model), so
any drift in the frontend SPICE mapper surfaces here.

Validated against the live Docker container — lux=0/1000/2500 produce
raw=4095/2854/992, matching the expected 4095/2854/993 within ±1 LSB
and monotonically decreasing with brightness as expected.

The package-lock.json churn is a pre-existing drift: eecircuit-engine
was in package.json but missing from the lock — npm install re-added it.

Companion workflow change (registering the test in backend-e2e-tests.yml)
lives in a separate commit that requires a PAT with workflow scope to push.
2026-04-24 19:20:02 +02:00
David Montero Crespo 07c9718bc3 test: update BMP280 chip ID assertions and clarify tagName uniqueness in metadata drift test 2026-04-21 17:31:51 -03:00
David Montero Crespo 53efc226a3 Merge branch 'master' into feature/electrical-simulation-ngspice
# Conflicts:
#	deploy/entrypoint.sh
#	frontend/src/components/examples/ExamplesGallery.tsx
2026-04-21 17:11:26 -03:00
David Montero Crespo a1d3179e1c Add SPICE behavior tests for analog examples and update example circuit definitions 2026-04-21 13:20:48 -03:00
David Montero Crespo dcb8a92b79 feat: enhance electrical simulation and testing framework
- Decoupled electrical simulation from the simulator store, ensuring SPICE is always active for accurate circuit analysis.
- Removed feature flag for electrical simulation, simplifying the state management.
- Preloaded SPICE engine at app start to eliminate latency during the first solve.
- Added comprehensive tests for MOSFET PWM LED behavior and NPN transistor switch functionality, ensuring correct current flow and response to pin states.
- Implemented diagnostics for floating input nodes in RC low-pass filter circuits, addressing singular matrix issues in SPICE simulations.
- Introduced active semiconductor metadata registry for better component management and simulation fidelity.
- Updated Vite configuration to force re-bundling of local wokwi-elements after component additions.
2026-04-20 16:38:31 -03:00
David Montero b86273870e docs: add Docker production error report (2026-04-19)
Documents 5 issues found in production logs: RPi3 missing QEMU boot
files (51 hits), ESP32-S3 unsupported machine type, WebSocket race
condition, Google OAuth unhandled 400, and the uvicorn keepalive crash
that was mitigated in 8e3c00e.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-19 00:37:07 +02:00
David Montero Crespo df37fdf6a4 feat: add 40 circuit examples + matching SPICE tests
Adds frontend/src/data/examples-circuits.ts with 40 new examples organized
into 6 categories, each demonstrating a specific analog/digital/electromech
concept that the SPICE engine can simulate end-to-end:

PASSIVE / ANALOG (10):
  voltage-divider, rc-low-pass-filter, wheatstone-bridge,
  ntc-temperature, led-current-limiting, parallel-resistors,
  pot-adc-reader, photoresistor-light, multi-led-bar,
  capacitor-charge-curve

TRANSISTOR / SEMICONDUCTOR (8):
  npn-led-switch, pnp-high-side-switch, mosfet-pwm-led,
  diode-rectifier, zener-regulator, schottky-reverse-protection,
  bjt-common-emitter, darlington-high-current

OP-AMP (5):
  opamp-inverting, opamp-voltage-follower, opamp-comparator,
  opamp-difference, opamp-schmitt-trigger

LOGIC GATES (6):
  and-gate-alarm, xor-toggle-detector, nand-sr-latch,
  full-adder, binary-counter-leds, logic-probe

ELECTROMECHANICAL (4):
  relay-led-switch, optocoupler-signal,
  l293d-motor-control, l293d-speed-pwm

POWER / REGULATOR (3):
  power-supply-7805, lm317-adjustable-psu, battery-voltage-monitor

BOARD-SPECIFIC (4):
  esp32-dual-adc, mega-multi-led, nano-sensor-station,
  esp32-pwm-led-rgb (uses ESP32 LEDC peripheral)

The new examples are appended to exampleProjects[] in examples.ts so the
existing gallery and category filters pick them up automatically.

test/test_circuit/test/spice_examples.test.js validates each example's
analog topology in ngspice — 45 individual assertions covering all 40
examples (plus extra cases for NTC/Zener sweeps and L293D direction).

Sandbox tally: 164 -> 209 tests, 7.9s runtime, all green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 00:52:51 -03:00
David Montero Crespo 3197935461 feat: add ESP32 + ngspice co-simulation E2E tests
Three new end-to-end tests that combine ESP32 QEMU emulation (via backend
WebSocket) with ngspice-WASM analog circuit solving:

1. test_esp32_spice_analog.mjs — voltage divider sweep
   - Compiles a sketch that reads analogRead(34)
   - Solves two voltage dividers with ngspice (R1/R2=10k/10k then 10k/30k)
   - Injects solved V(mid) into ESP32's ADC via esp32_adc_set
   - Verifies Serial output matches within +-50 counts (12-bit ADC)
   - Confirms circuit change is detected (different ADC values)

2. test_esp32_spice_ntc_bridge.mjs — Wheatstone bridge temperature sweep
   - NTC thermistor in a bridge (0C / 25C / 50C)
   - ngspice solves the bridge for each temperature
   - ESP32 reads both legs (ADC34+ADC35), computes R_ntc and T via beta model
   - Verifies temperature within +-5C tolerance across sweep

3. test_esp32_spice_smoke.mjs — ngspice-only smoke test (no backend needed)

Also adds eecircuit-engine to test/backend/e2e/package.json.

Prerequisites: backend on localhost:8001 with esp32 core installed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 23:28:47 -03:00
David Montero Crespo 36543e2479 feat: expand SPICE component catalog (fases 9 + 10)
Adds 44 SPICE mappers, 58 custom metadata entries, and 12 visual
Web Components covering logic gates, transistors, op-amps, regulators,
sources, electromechanical parts and integrated-circuit packaging.

Fase 9 — component catalog expansion
------------------------------------
- 7 logic gates (AND/OR/NAND/NOR/XOR/XNOR + NOT) as SPICE B-sources
- 8 multi-input gates (AND/OR/NAND/NOR with 3 and 4 inputs)
- 9 transistors: 5 BJTs (incl. PNP 2N3906/BC557) + 4 MOSFETs (incl.
  P-channel IRF9540/FQP27P06). NMOS refactored from Level=3 W=0.1
  (hangs ngspice) to Level=1 with sane W/L
- 5 op-amps: LM358, LM741, TL072, LM324 with per-chip saturation
  rails + opamp-ideal
- 4 linear regulators (7805, 7812, 7905, LM317) with dropout
- 3 batteries (9V, AA, coin-cell) with realistic ESR
- Signal generator (sine / square / DC)
- 2 Schottky diodes (1N5817, 1N5819) + photodiode (lux-driven
  current source)

Fase 10 — electromechanical + ICs
---------------------------------
- Relay (SPDT): coil + L + S-switch with native hysteresis +
  flyback diode, inverted-control trick for the NC contact
- Optocouplers 4N25 and PC817 (LED + CCCS with CTR=0.5 / 1.0)
- 7 74HC ICs as DIP-14 packages emitting 4 or 6 B-sources per
  component (first mapper pattern emitting multiple device cards)
- 3 flip-flops (D, T, JK) — digital-sim only (edge detection is
  not representable in ngspice .op)
- L293D dual H-bridge motor driver

Infrastructure
--------------
- scripts/component-overrides.json gains a _customComponents[] array
  that lets new Velxio-only parts survive metadata regeneration
  (previously applyOverrides() could only patch wokwi-elements
  components that had already been scanned)
- scripts/generate-component-metadata.ts injects custom entries
  before the patch loop
- New ComponentCategory values: 'logic', 'analog', 'electromech'
- frontend/src/components/DynamicComponent.tsx PASSIVE tracing
  extended from just ['resistor','resistor-us'] to 9 two-terminal
  passives with per-part pin name maps
- New CI workflow test-circuit.yml runs the sandbox on push/PR
- frontend-tests.yml regenerates metadata and fails if committed
  JSON is stale
- Documented 2 new ngspice gotchas in circuit-emulation-gotchas.md:
  unicode in netlist titles silently hangs the parser, and
  MOSFET Level=3 + W=0.1m causes .op to hang
- 164/164 sandbox tests passing in ~9 s (was 88 pre-fase-9)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 22:41:26 -03:00
davidmonterocrespo24 ed9911dcc3 feat: electrical simulation via ngspice-WASM (eecircuit-engine)
Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy-
loaded  toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate
with real analog behaviour: correct voltages on wires, real I–V curves on
LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM
driving RC filters, transistors, op-amps, diodes, MOSFETs, etc.

Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle
stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates
electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false.

Frontend additions:
- simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with
  UnionFind over wires, componentToSpice mapping (24 metadataIds incl.
  real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148,
  1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with
  debounced coalescing, AVRSpiceBridge for quasi-static co-simulation.
- store/useElectricalStore: Zustand slice, feature-flag aware.
- components/analog-ui/:  toolbar toggle + SVG voltage overlay.
- components/components-instruments/: Voltmeter, Ammeter probes.
- 62 tests (spice-*, netlist-builder, component-to-spice, instruments).

Sandbox (test/test_circuit/): 47-test validation sandbox that proved
the approach (hand-rolled MNA baseline + ngspice pipeline) before
porting to the app. Kept as reference.

Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering
architecture, solvers, components, AVR bridge, gotchas, performance,
integration plan, API reference, appendix) + electrical-simulation-
user-guide.md (end-user facing).

Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 12:11:54 +00:00
David Montero Crespo c65acdb1dc Add end-to-end test for MicroPython on Raspberry Pi Pico using rp2040js
- Implemented a comprehensive test script (test_micropython_pico.mjs) that performs the following:
  - Part 1: Checks backend compilation of a simple Arduino sketch for the rp2040:rp2040:rpipico board.
  - Part 2: Downloads MicroPython v1.20.0 UF2 firmware and loads it into a rp2040js simulator.
  - Part 3: Simulates the Pico, verifies REPL output, and checks execution of injected Python code.
- Includes detailed logging and error handling for each step of the process.
2026-04-13 10:02:21 -03:00
David Montero Crespo 74e25eb4b2 feat: Update MicroPython firmware handling for ESP32; add end-to-end test and mark subproject commits as dirty 2026-04-12 23:55:11 -03:00
David Montero Crespo d4a48e6e1e feat: Skip real paths test in CI; mark subproject commits as dirty 2026-04-11 15:49:32 -03:00
David Montero Crespo 382e13cfe7 feat: Update components metadata timestamp and mark subproject commits as dirty; add diagnostic test for real library paths 2026-04-11 15:42:38 -03:00
David Montero Crespo 2ba8020438 feat: Enhance ESPIDFCompiler library resolution logic; add support for dynamic library detection and patching in CMakeLists.txt
refactor: Update wiring examples for E32 OLED integration; correct pin mappings for VCC, GND, DATA, and CLK
test: Improve unit tests for ESPIDFCompiler; add scenarios for library resolution and CMake patching
chore: Mark subproject commits as dirty for wokwi-libs
2026-04-11 15:25:40 -03:00
David Montero Crespo 6b161eab34 feat: Enhance CI workflows for backend unit and e2e tests; add environment setup and skip timing-sensitive tests in CI 2026-04-10 23:47:25 -03:00
David Montero Crespo 7971743174 Add unit tests for I2C slave devices, MCP tools, and WiFi/BLE status parser
- Implement tests for BMP280, DS1307, DS3231, I2CWriteSink, and MPU6050 slaves in test_i2c_slaves.py.
- Create test suite for Velxio MCP server tools in test_mcp_tools.py, covering Wokwi utilities and circuit management functions.
- Add tests for parsing WiFi and BLE serial output in test_wifi_status_parser.py, ensuring correct status events are captured.
2026-04-10 23:39:51 -03:00
David Montero Crespo 5795b1d506 Fix MPU6050Slave I2C handling and add comprehensive tests
- Updated the threshold for switching to data mode in MPU6050Slave from 2 to 3 WHO_AM_I reads to ensure correct chip identification.
- Enhanced comments in the code to clarify the sequence of I2C events during initialization.
- Added a new test file `test_mpu6050_emulation.py` to validate the MPU6050Slave state machine and ensure it handles the full Adafruit_MPU6050::begin() event sequence correctly.
- Updated existing tests to reflect the changes in the I2C handling logic.
- Modified `components-metadata.json` to update the generated timestamp.
- Marked submodules `rp2040js` and `wokwi-elements` as dirty to reflect local changes.
2026-04-09 02:04:41 -03:00
David Montero Crespo 01f75cf313 feat: implement eager scan for LEDC GPIO mapping and add tests for race condition fix 2026-03-24 13:54:44 -03:00
David Montero Crespo b166b8de37 feat: add ESP32 lcgamboa test suite, sketches and firmware binaries
- test/esp32/test_esp32_lib_bridge.py: 28-test suite for ESP32 emulation
  via libqemu-xtensa.dll (GPIO, UART, ADC, pinmap, DLL symbols, manager API)
- test/esp32/test_arduino_esp32_integration.py: 13-test integration suite
  simulating Arduino Uno ↔ ESP32 serial communication (LED_ON/OFF, PING/PONG,
  GPIO transitions, rapid burst, unknown command resilience)
- sketches/blink_lcgamboa/: IRAM/DRAM-safe blink firmware (5× GPIO2 toggle)
- sketches/serial_led/: ESP32 firmware responding to serial commands over UART0
- sketches/arduino_serial_controller/: Arduino Uno sketch for serial LED control
- sketches/blink_qemu.ino: reference blink sketch for stock QEMU
- binaries_lcgamboa/: pre-compiled 4 MB merged flash images for QEMU
  (blink_lcgamboa + serial_led, arduino-esp32 2.0.17 + FlashMode=dio)
- .gitignore: exclude DLL/ROM binaries (too large) and .elf/.map build artifacts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-14 12:28:40 -03:00
David Montero Crespo c957190061 feat: implement ESP32 emulation support via libqemu-xtensa.dll and enhance simulation API 2026-03-14 02:32:48 -03:00
David Montero Crespo 1bbb1ad4d2 feat: add initial ESP32 test module 2026-03-13 22:55:45 -03:00
David Montero Crespo dc03c28fff feat: Enhance ESP32 support in simulator and QEMU management 2026-03-13 22:55:37 -03:00
David Montero Crespo cc3030200c feat: add multi-board integration tests for Raspberry Pi 3B and backend functionality 2026-03-13 00:15:14 -03:00
David Montero Crespo a07c76470e feat: enhance AVR USART RX handling with software queue and improve logging 2026-03-12 22:11:06 -03:00
David Montero Crespo 13997ff491 feat: add documentation page and Arduino serial integration test
- Created a new DocsPage component for project documentation with links to GitHub and Discord.
- Added Arduino sketch for serial communication test between Raspberry Pi and Arduino.
- Implemented avr_runner.js to emulate ATmega328P and bridge serial communication over TCP.
- Developed a Python test script to validate the serial integration between the emulated Raspberry Pi and Arduino.
2026-03-12 08:17:29 -03:00
David Montero Crespo 02c69c23f6 feat: add ESP32 emulator with QEMU WebAssembly integration and basic GPIO functionality tests 2026-03-10 18:01:05 -03:00