Tuesday 18 August 2015

Atari ST USB keyboard

I worked out the circuit for this a long time ago, but I've never actually built an Atari ST USB keyboard before. The main reason being the size of the case. If you have an ST case with only the keyboard and a USB keyboard controller in, it still takes up quite a bit of desk space, so I presumed no one would want one. The same with the Commodore Amiga.
Then someone asked for one, so here it is. The request was for a 1040ST, and I found a suitable candidate, this one looked quite nice, but actually appeared to be a 520STFM with a 1040STE badge? It also had a memory fault, and will serve as a supply of spares for another 1040STE I'm currently repairing.
The Atari ST keyboard has an integrated keyboard controller and two 9 way D joystick ports. This connects to the main board via a serial connection.
These are accessed from under the keyboard. A common source of faults on ST's is bad contacts on these, and this is caused by cracked solder joints due to mechanical damage. If you've ever had to wiggle a plug to get something like this to work, it's probably because of cracked joints like this. Wiggling the plugs just makes it worse as it stresses the other pins and can cause problems with them as well eventually.
So first task was to strip down the keyboard, clean all the contacts and fix the cracked joints on those connectors. I find the best way to deal with those is to effectively desolder them, removing all the existing solder, then resolder them with fresh solder.
The cable from the keyboard has an 8 way 0.1" on the end. To make wiring to the controller easier, I made a mating cable with the pin version of the Harwin M20 connectors.
The connections on that cable are as follows, the baud rate looks odd (7812.5), but this is a direct divisor of 1MHz (7812.5*128=1MHz), and also the 16MHz clock I was using.
  1. Ground
  2. Not connected (polarising pin)
  3. Floppy LED (active low)
  4. +5V power to keyboard
  5. Serial data from the keyboard (7812.5 baud, 8N1)
  6. Serial data to the keyboard
  7. Reset (active low)
  8. Ground
The cable was wired to a suitable USB keyboard controller, one of my smaller ones as few pins were required. This may have been a slight mistake as the ATmega8U2 on there ended up 98% full. I almost had to swap it out for an ATmega16U2.
The USB keyboard controller was fixed in the case so the connector could be accessed through an existing hole.
With that in place, it was just a case of writing the software. There are various documents online referring to the keyboard protocol. It turned out to be reasonably simple, Start by pulsing the reset line low, then there was an initial bit of communication to tell it to switch into a mode where it would report all keypresses and joystick movements. It is possible to configure it to work with one joystick and one mouse, rather than two joysticks, but I thought this would be more useful. Leave the ST mice for use with STs.
It was then just a case of reverse engineering what came back from the keyboard, each keypress and key release are sent as single bytes, and joystick movement is two bytes. These were translated into USB keyboard keypresses. I had to create a matrix of currently pressed keys and update that whenever anything came from the keyboard. There are two LEDs, one power which I left as that, and the other showed disk access, this now shows caps lock status.
When plugged into a PC or Mac or tablet, this appears as a USB keyboard and two USB joysticks, so can be used anywhere those could be used, including of course Atari ST emulators.
There is quite a lot of space left inside, enough for a Raspberry Pi or something like the Intel NUC I used in the Atari 800XL PC,
These and other similar USB keyboard controllers are available from my Tindie store.

See also a whole Intel i7 based PC installed in an Atari ST, using this adapter.

Update 2:
The current builds of these are a little tidied up over the original, the wires are now on the back of the board.
The yellow wire is no longer connected as it is unused, so there are two spare pins at the end.

Update 3:
A new dedicated version of the Atari ST USB keyboard controller is available from my Tindie Store.

2023 Update

USB Keyboard Controller Kits are available from my Sell My Retro store: