artemisamsx / artemisa

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

Prototype PS2 keyboard adapter fails #127

Closed apoloval closed 4 years ago

apoloval commented 4 years ago

The prototype unit of PS2 Keyboard Adapter I use for the tests use to fail.

It starts responding normally. But after a while, some random keys are detected as pressed. I think this may be caused by the board itself. It seems some 595s are not working as expected and they show pressed keys that have not been reported by the microcontroller.

In fact, I could not reproduce this behavior in the Arduino board. That's why I think it is an issue with the 595s matrix.

I would be useful to test other boards to confirm they work well with the latest version of the firmware.

apoloval commented 4 years ago

Tested in another board. And the bug was reproduced with the latest firmware version. Using the old one works perfectly.

It seems there is a bug in the firmware that is causing this malfunction.

apoloval commented 4 years ago

I debugged the board connected to the MSX with the serial monitor connected via Arduino board.

It seems the root cause is that the new ps2 lib implementation assumes the keyboard communication can be inhibited at any time. We are receiving 0x00 bytes from the keyboard. This usually means an error due to buffer overrun in the keyboard size. And it makes sense.

When a scancode is received from the keyboard, it is stored in a variable (1-byte buffer). Then the PS2 communication is inhibited. When that scancode is read from the firmware, the PS2 port is marked as idle again, allowing the keyboard to send more bytes.

If the firmware takes too much time to read the buffered scancode, the keyboard may need to send some bytes, but it cannot due to inhibited comms. It could happen that further keystrokes are ignored by the keyboard, because they cannot be transferred to the controller.

The solution is to implement an input buffer in the controller so the keyboard can transmit bytes when it have. Without inhibiting.

apoloval commented 4 years ago

Okay, we finally reached an implementation that works!

Fixed in 5d728e53001c5bd1865f94ccfc06102dfc550c43.