This obsoleted page documents the beginnings of a project to connect Sun Type 5 keyboards to a PC via USB. The project worked, but I was lacking some important tools to complete it. By the time I got the tools, Sun had done away with its proprietary RS-232-esque keyboard and mouse connectors, and moved to USB. There are lots of Sun Type 6 and 7 keyboards out there in both Unix and PC layouts. I ﬁnd the feel of the Type 5 superior to the newer ones, but at least you don't need extra hardware!
For users of Linux: this project was undertaken in the days of Linux 2.4. Linux 2.6 has built-in support for Sun serial keyboards attached to the serial port with a simple level shifter. Sun keyboards are 1200 bps serial devices, but they signal at TTL levels, not RS-232 levels. The MAX232 chip with a few passive external components is the standard solution to this problem, and the whole circuit can be built inside the casing of a DB9 serial plug. Of course, this arrangement only works after a Linux 2.6 kernel has started, so it won't work in the BIOS or other operating systems.
For the fun of it, I've redeveloped the hardware using an AVR microcontroller, but this hasn't been tested. I expect most of the software will still be good though.
A friend and I have wanted to connect Sun Type 5 keyboards for ages. I even managed to get a wonderful, Anykey keyboard for my machine (tons of keys, on-board remapping and macro facilities, niice). But only an old-style IBM keyboard beats the feel of a Sun keyboard. Type 4 or Type 5, mind you. Type 3 keyboards were sheer horror. Type 6, in accordance with Sun's modern design policies, is disgusting.
Everyone and their granny has designed a box to connect Sun keyboards to PCs. I liked none of them. The keyboards last a lifetime, so might as well make an adaptor that will outlast the aging AT and PS/2 keyboard connectors, right?
So this is a project to connect Sun keyboards to any computer with USB support.
This page is still in the making, expect updates to reflect the state of work.
Sun Type 5 keyboards are largish, very stylish devices matching the design of early Nineties SPARCs. They have a gorgeous, soft feel with great feedback for easy, rapid typing. They have a large number of keys aimed at UNIX workstations: Caps Lock is out of the way; Control is on the home row, where it should be, because it's used a lot in UNIX; Escape is at the top left corner of the alphanumeric area, useful for
vi editing (although Control-[ is much handier for the truly initiated); there are Alt, AltGr and two Meta keys; a Compose key; monitor/volume control keys and a power button. You can ﬁnd no less than 26 function keys; 13 are labeled Help, Copy, et cetera, twelve are where PC users would expect them, and there's a blank key where the Escape key would be on a PC keyboard. These come in really handy for shortcuts and editing. The keyboard also features a socket for Sun serial mice, and oﬀer provision for a left handed mouse. Did I mention they're great for touch-typing?
Technically speaking, they're simple serial devices, talking to the machine at 1200 bps through an 8-pin mini-DIN plug. No hardware handshaking or anything. The mouse's serial signal is repeated to the computer using one pin. Simple!
After evaluating diﬀerent microcontrollers, I decided to use Cypress/Anchor Chips' AN2131, also known as EZ-USB. This chip has remarkable features to speed up development. Fortunately, the nice people at Keyspan produce a cheap(ish) RS-232 dongle based on the AN2131. It's cheaper than designing and building my own board, anyway. And it's pretty.
The remarkable feature of this chip is that it's completely ﬁeld-programmable. You can download new ﬁrmwares to it every time it boots, making it behave diﬀerently. Stick a bigger serial EEPROM in there, and you have a semipermanent ﬁrmware. The USB chip still responds to upgrade commands, so you can reprogram its EEPROM anytime you like.
There are two modiﬁcations to be implemented here:
- Add an 8-pin Mini DIN socket. The general idea is to solder wires and attach a line socket dangling from the back of the box. A bit unseemly, but better than many other solutions. The Sun Keyboard can't attach directly to the DB-9 port. It may be RS-232 serial, but it uses TTL levels, not RS-232 levels. The Keyspan's DB9 uses sort-of RS-232 levels, but they won't work on the Sun keyboard. I could use a MAX-232 RS-232 transceiver to connect the two, but it needs extra power, and it's more expensive than a little cable and a line socket.
Besides, the Sun keyboard needs 5V power and uses a second data in pin for the mouse. And I really want to be able to revert the dongle to its originally intended use whenever I feel like it. Perhaps some day I'll manage to cram both Sun keyboard support and a basic RS-232 ﬁrmware in the machine's EEPROM.
- Which brings us to the second, harder modiﬁcation. The Keyspan dongle is a soft-only device. It only has a 16-byte I²C EEPROM (a Microchips 24LC00 in a miniscule MSOP package). The EEPROM holds the USB device's identiﬁcation words. They allow the host to identify the device as a Keyspan USA-19Qi and to download the ﬁrmware to the adaptor. That's all well and ﬁne, and very clever, but it doesn't allow the device to work at boot time. We need it to do so in case we have to use the machine's BIOS. A USB keyboard should work from the onset. So we need to reprogram the EEPROM. Well, actually we need a bigger EEPROM. Around 64 kbits will do, say a 24LC64. All 24LCxx parts are pin compatible anyway.
We can't just add a new EEPROM to the device. If a 24LC00 is installed, no additional EEPROMs can be added. We need to replace the chip somehow.
Excellent! The EZ-HID project has a Sun Keyboard ﬁrmware for the EZ-USB. Just what I need. Now for some obligatory modiﬁcations to the code!
Keyspan adaptors arrived. They're cute! They're also very, very small. Having second thoughts about the soldering.
First step: get the adaptor to work as a serial port. D'oh! My kernel is missing the ﬁrmware. Downloaded new, non-GPL (eek) ﬁrmware from Keyspan, and installed it. No luck yet, as the device is a new model unsupported by my 2.4.18 driver (Model USA-19Qi).
I set out to patch the kernel. Managed to get the device detected and the driver loaded dynamically. Good. Now try to ﬁnd out why the baud rate divisor is so absolutely wrong. D'oh number 2! Keyspan's addenda to the Linux driver add full support for my device. I take solace in the fact that my own kernel patch was almost identical to Keyspan's (apart from that ‘minor’ problem with the baud divisor).
I ﬁnally get my trusty Palm IIIx to talk to the serial port. Fire up a
getty and login to Vennëa from the Palm (I always liked that). At this point, I have an incredibly messy desk, full of other serial devices used for testing, including a 1989 Microsoft Mouse (don't knock it, they made good hardware then ― maybe they should've been Microhard), my GPS receiver, mobile phone, et cetera. Look at the photo to see exactly what ‘messy’ means.
Quiz: how many CPUs on the desk? Including Vennëa's tower case (not visible in the photo), I count eight: a Dragonball EZ in the Palm; some reasonably strong microcontroller or small CPU in the Anykey keyboard (it even has 2 kbytes of RAM); the AN2131 chip in the Keyspan dongle; a PIC 16Cxx microcontroller in the mouse (nice! A mouse with hack value); an 80186 in the GPS; and some otherwordly weirdness in the Nokia phone. Plus Vennëa's Duron and the RISC CPU on the DVD decoder card. I have more CPU's on my desk than IBM once thought would exist in the entire world!
Ok, the break is over. Get the 8051 compiler out and start learning how to program the beastie. Lots of frustration later (it's diﬃcult to debug with only one LED and so many, many failure points), I get the LED on the dongle to blink at changing, funky rates. Yay!
USB time. Do more reading on the EZ-USB part of the AN2131. Code some. More reading. Give up, read the EZ-HID project's Sun keyboard ﬁrmware. Compile it, install it. No joy. Go through the code. Realise that the ﬁrmware won't register the HID device unless a Sun keyboard is installed. Okay, how about if I comment out this and this and this line? Compile, download ― and the kernel detects an ‘Acme USB Widgets’ USB keyboard and mouse. Then proceeds to spray the host with random scancodes, bringing my X server down, then rebooting (!). This is almost a trojan!
Now comes the hard part: hardware changes. Attaching the keyboard cable seems a very scary prospect. The EZ-USB chip is 10 by 10 mm, with 11 pins on each side. And space between them. Better spend some time reading about SMT soldering.
And what do I do about the I²C EEPROM? It's far too small for me to solder. Thankfully, Usenet has some help on the matter. I decide to order ordinary DIP EEPROMs because, with 2.54 mm between pin centres, it's easier to solder. All I need is four wires from the old IC to the new one, which I decide I'll glue somewhere. Plenty of headroom in the translucent box of the Keyspan. I decide not to desolder the 24LC00 if I can help it, but to disable it by cutting its data (SDA) and clock (SCL) pins with an X-Acto knife, then very carefully soldering the ﬁnest insulated wire I can ﬁnd to the 24LC64's corresponding pins (and also Vcc and Vss to provide power to the part).
I'm beginning to wish for a watchmaker's loupe. At least I have a ‘Helping Hands’ stand, a little, heavy stand which can hold PCBs and cables for you while you do soldering work on them. It even has a passable magnifying glass. I'll also need tweezers and soldering wick for easier desoldering. Oh, and the ﬁnest soldering iron tip I can ﬁnd. Scary!