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

Working tree:

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

Base tree:

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

Purpose:

Fix PS/2 mouse/keyboard loss after unplug/replug without changing firmware. The PS/2 lines are handled directly in FPGA logic; firmware only consumes decoded keyboard/mouse/OSD data.

Changes:

- `rtl/minimig/userio_ps2mouse.v`
  - Adds a longer receive/transaction timeout so partial packets after replug cannot wait forever.
  - Resets the mouse command sequence on timeout so the host sends reset/sample-rate/read-type/enable-reporting again.
  - Detects mouse BAT/status bytes or invalid first packet bytes while idle and restarts mouse initialization.
- `rtl/minimig/ciaa_ps2keyboard.v`
  - Adds timeouts to the keyboard LED command ACK waits.
  - Recovers from partial PS/2 receive frames instead of waiting indefinitely.
- `fpga/edgeartix7/edgeartix7_v0/xc7a35t/ps2.xdc`
  - Enables internal pullups on keyboard clock/data to match the mouse port behavior.

Build:

Use the existing incremental implementation flow:

```sh
vivado -mode batch -source tcl/build_edge_bitstream_incremental_from_stable.tcl
```

Default incremental reference:

`/home/ranko/Documents/Edge/edge-minimigaga-vga-hdmi-osd-joy-incremental-stable-route/edge-minimigaga-vga-hdmi/project_1/project_1.runs/impl_1/minimig_edge_top_routed.dcp`

Override if needed:

```sh
EDGE_INCREMENTAL_DCP=/path/to/minimig_edge_top_routed.dcp vivado -mode batch -source tcl/build_edge_bitstream_incremental_from_stable.tcl
```
