Alexios' Home Page

Sun keyboards on USB 

HomeHardware hacks ► Sun keyboards on USB ►

Warning: this is really sloppy work. It lacks numerous links and references, and is probably full of errors. As soon as the project has produced something tangible I'll clean this page up.
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.

[A Sun Type 5 keyboard]
All hail the King of Keyboards: a glorious Sun Type 5c.

Sun Keyboards

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 in 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 find 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 offer 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!

Hardware

After evaluating different 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.
[Keyspan's USA-19Qi USB PDA Adaptor]
Smaller than it looks: Keyspan's USA-19Qi USB PDA Adaptor.

The remarkable feature of this chip is that it's completely field-programmable. You can download new firmwares to it every time it boots, making it behave differently. Stick a bigger serial EEPROM in there, and you have a semipermanent firmware. The USB chip still responds to upgrade commands, so you can reprogram its EEPROM anytime you like.

[USA-19Qi, the
full monty]
USA-19Qi does the full monty. The large socket is a DB9. It's that small (the AN2131 chip is 1cm square).

There are two modifications to be implemented here:

  1. 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 firmware in the machine's EEPROM.

  2. Which brings us to the second, harder modification. The Keyspan dongle is a soft-only device. It only has a 16-byte I2C EEPROM (a Microchips 24LC00 in a miniscule MSOP package). The EEPROM holds the USB device's identification words. They allow the host to identify the device as a Keyspan USA-19Qi and to download the firmware to the adaptor. That's all well and fine, 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.

Software

Excellent! The EZ-HID project has a Sun Keyboard firmware for the EZ-USB. Just what I need. Now for some obligatory modifications to the code!

The Saga

Day 1

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 firmware. Downloaded new, non-GPL (eek) firmware 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 find 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 finally 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.

[Project day 1]
Hardware hacking is messy work. Day 1.

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 difficult 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 firmware. Compile it, install it. No joy. Go through the code. Realise that the firmware 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!

[I2C EEPROM]
‘I need to desolder WHAT?’ (it's 5mm by 3mm, including the pins)

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 I2C 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 finest insulated wire I can find 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 finest soldering iron tip I can find. Scary!