# PS/2 Hotplug Recovery - 2026-04-21

Base tree:

`/home/ranko/Documents/Edge/edge-minimigaga-vga-hdmi-osd-joy-swap-incremental-route/edge-minimigaga-vga-hdmi`

New working tree:

`/home/ranko/Documents/Edge/edge-minimigaga-vga-hdmi-osd-joy-swap-ps2-hotplug-incremental-route/edge-minimigaga-vga-hdmi`

## Finding

The PS/2 clock/data pins are connected directly to FPGA logic. The ARM firmware consumes already-decoded input and OSD state, but it does not run the low-level PS/2 mouse or keyboard protocol.

The mouse worked at boot because the FPGA mouse module sends the PS/2 reset/sample-rate/read-type/enable-reporting command sequence after core reset. After unplug/replug, the mouse powers back up with reporting disabled, but the old logic did not reliably restart that initialization sequence.

The keyboard could also become stuck waiting for a PS/2 LED command ACK or for a partial receive frame that never completes after a disconnect.

## Change

Changed:

```text
rtl/minimig/userio_ps2mouse.v
rtl/minimig/ciaa_ps2keyboard.v
fpga/edgeartix7/edgeartix7_v0/xc7a35t/ps2.xdc
```

Mouse recovery:

- Extends the receive/transaction timeout.
- Resets the mouse command sequence on timeout.
- Restarts initialization when BAT/status bytes or invalid first packet bytes are seen while waiting for normal packet data.
- Times out partial packet waits in all packet-byte states.

Keyboard recovery:

- Adds timeout recovery to LED command ACK wait states.
- Allows the partial-frame receive state to timeout even when the PS/2 receiver still appears busy.
- Enables keyboard PS/2 internal pullups in the XDC.

## Validation

Lint:

```bash
verilator --lint-only --no-timing -Wno-fatal --top-module userio_ps2mouse rtl/minimig/userio_ps2mouse.v
verilator --lint-only --no-timing -Wno-fatal --top-module ciaa_ps2keyboard rtl/minimig/ciaa_ps2keyboard_map.v rtl/minimig/ciaa_ps2keyboard.v
```

The mouse module lint completed cleanly. The keyboard lint completed with pre-existing width/case warnings in `ciaa_ps2keyboard_map.v`.

Build:

```bash
/tools/Xilinx/2025.2/Vivado/bin/vivado -mode batch -source tcl/build_edge_bitstream_incremental_from_stable.tcl
```

Vivado result:

```text
impl_1 status: write_bitstream Complete!
```
