artemisamsx / artemisa

Schematics, PCB designs and HDL simulations to build a 8-bits MSX computer
Other
62 stars 11 forks source link

Detect keyboard disconnections and reset upon reconnect #126

Closed apoloval closed 4 years ago

apoloval commented 4 years ago

In theory, we could disconnect the PS2 keyboard with the computer running. But it would reset and will reach an initial state, and not the state the computer has. This means the status of the LEDs will be inconsistent.

This can be prevented by just sending some periodic pings to the keyboard to detect whether it is connected. With this we can detect if the keyboard have been just connected, and send the initial state we need.

apoloval commented 4 years ago

The suggested solution could be overcomplicated. When PS2 keyboard is connected, it sends a 0xAA scancode by its own. This indicates the self-test passed after a reset command (0xEE) or after power on. We could use this command to infer the keyboard has been reconnected, and send the LED state at that point.

apoloval commented 4 years ago

A really interesting resource: the Renesas manual to write microcontroller programs for PS2 devices.

apoloval commented 4 years ago

We finally got inspired by Renesas paper and reimplemented the things assuming only one scancode can be received at a time. This simplifies the code a lot.

Also, we had fixed the reconnect issue by detecting the 0xAA command and sending again the LED status when that happens.

Merged in d691fd4477466710cbf09543a2859a187c237f5a.