I recently accquired a DEC VT220 video terminal which was fully functional asides from a little dirt on its case, however, it was not usable yet as I did have the proper keyboard for the terminal.
Because I did not have the money to buy the keyboard I started thinking about adapting a PC keyboard to work with it. Fortunately, the service manual for the terminal was available, which provided me with a description of both the hard- and software interface for the keyboard. The descriptions given in this manual were written almost like a specification and made implementing these features very easy.
The interface used by the LK201 ( the type number of the keyboard the VT220 uses) is a binary protocol over 4800 8N1 RS232. This meant that a run of the mill microcontroller should easily be able to implement it. I chose an Arduino Nano because my hackerspace had these on hand.
At first I tried to translate the PS2 scancodes as they came in from the keyboard and forward them to the terminal. This approach made implementing the more advanced features such as auto repeat and make/break codes more difficult. In the end I decided on having the PS2 code update a virtual key array in the interrupt handler and having the keyboard emulator code treat that as a real key array which it periodically scans. This made it a lot easier to implement the behaviour specified by the manual.
This approach worked and I was now able to operate the set-up menu of the terminal, however, it was not stable and would often start spamming fictitious keystrokes or auto repeats of keys that had never been pressed. After a lot of debugging I discovered that the software serial port I was using for talking to the terminal was interfering with the timing of the PS2 interrupts and thereby corrupting data whenever a PS2 receive coincided with a serial receive. Switching to the hardware UART fixed this. The reason I did not immediately choose to use the hardware port was because I wanted to have a debugging port available during the firmware development. Not having this debug port would have made development a whole lot harder, but when it eventually turned out to be causing bugs of it's own I had no other choice than to stop using it.
The LK201 is more than just a simple keyboard translating switch press or release information into serial data, it also contains the speaker for the terminal and four status LED's which can be individually controlled by the terminal. In order to make the keyboard easier to use I decided not to put these LEDs and the buzzer into the converter box, but on the keyboard itself. I opened the PS2 keyboard and used an old soldering iron to melt holes for the LEDs. I also used a labelwriter to produce the correct keycap markings for the new keyboard.
The source code for this project is available at it's github repository. The schematics are available here.
This article was written using VIM on my VT220 using the keyboard emulator. It is thus not only "working" but usable as well