thejpster / monotron

A simple 8-bit home computer style application for the TI Tiva-C Launchpad
Apache License 2.0
191 stars 9 forks source link

Write the PS/2 keyboard/mouse controller firmware #50

Open thejpster opened 5 years ago

thejpster commented 5 years ago

The AtMega48 drives the two PS/2 ports and the LPT port. It'll need firmware.

There's only 4 KiB flash and 512 bytes RAM so it'll need to be compact!

I propose a basic command/response protocol:

Commands: 0x00 - Reset to serial bootloader (may not implement this) 0x01 - Get keyboard data 0x02 - Get mouse data 0x03 - Get LPT status 0x04 - Write LPT bytes to buffer 0x05 - Write LPT status bits x 0x06 - Set keyboard LEDs x

Responses: 0x00 - Will reboot 0x01 - Keyboard data (raw PS/2 Scan Code Set 2) 0x02 - Mouse data (raw PS/2 mouse data bytes) 0x03 - LPT status 0x04 - Write LPT byte confirmed 0x05 - Write LPT status confirmed 0x06 - Write keyboard LEDs confirmed

This should keep the number of bytes in the Cortex-M4's UART buffer to a minimum (it's only 16 bytes long), and allow the Cortex-M4 to only ask for keyboard data when it's not drawing video.

The AtMega48 will handle keyboard init and mouse init on start-up. It will also handle the handshaking with the printer.

thejpster commented 5 years ago

Ugh. I couldn't face writing C or C++ for AVR so I bought some STM32F0 chips in TSSOP-20 package, and some TSSOP-20 to DIP adaptors.

On the next PCB revision, the PS/2 connectors will be on a riser PCB with the keyboard controller. You can then remove this and fit a USB keyboard controller instead if desired.

thejpster commented 5 years ago

You could even do a riser board which supported a scan matrix GPIO keyboard (e.g. a C64 keyboard, or an Amiga keyboard).