Sun keyboard to USB converter
Note that a newer version has been released. This page still contains all relevant background info though.
See page 2 for a more in-depth description of how the converter works and its source code. The converter's USB communication is (heavily) based on Brad Minch's project 2 firmware, so my thanks go out to him.
The converter built as a PIC18F4550 based prototype setup.
After hearing positive things about Sun's old keyboards, and the Type 5 in particular, I decided to try and hook it up to a PC. Linux supports them via the serial port and there's a hard to build PS/2 and a half finished USB converter out there; for all compatibility, features and fun I decided to build my own USB converter. The converter should work with Type 4 keyboards too.
The converter offers the following features:
- Sun keyboard works as a standard USB (HID) keyboard.
- Keyboard is supported in the BIOS and DOS.
- Acts like a Type 6 USB keyboard...
- ...but the Sun specific keys can be remapped for use in Windows.
- Keyboard layout can be changed: caps lock/control and escape/tilde can be switched so both PC and Unix style Type 5 keyboards can be set to your preferred layout.
- Modifier keys such as alt, meta and compose can be individually switched to their PC keyboard counterparts (ie meta becomes alt).
- Keyboard's power key can wake up PC over USB.
Unfortunately the converter has one big disadvantage: the volume and power keys aren't directly recognized as such (this would require implementing a composite USB device). Unix should be able to map commands to their keycodes though, and when put into their secondary mode they do send codes that Windows recognizes. An application such as Hoekey can then be used to assign functions to them. See special keys below for more information.
Hardware
The ISCP connector is used to program the chip, see software below. If you have an socket-based PIC programmer you can leave it out. Some other comments on the schematic:
- The PIC18F2550 is a very nice smaller (28 pin) replacement chip that works without any modifications to the hard- or software. Make sure to check the pin numbers though, they won't match most of the time.
- The 22 µF capacitor C2 supposedly can be anything between 1 and 22uF; it can even be left out altogether (may result in instability).
- The decoupling caps C1 and C2 should be positioned as close as possible to one of the Vdd/Vss pairs.
- The USB decoupling cap Cusb can be anything from 220 to 470 nF.
- The clock crystal can be replaced by many other sources, see the PIC datasheet. This requires changes in the configuration fuses and the USART_DIV definition in the source code.
- The two inverters can be implemented in various ways, the easiest is a 7404 (or equivalent) inverter chip, which contains six of them. On B4 and later versions of the microcontroller, they should be able to be left out; quote of the B4 errata: "The TXCKP (BAUDCON<4>) and RXDTP (BAUDCON<5>) bits enable the TX and RX signals to be inverted (polarity reversed)." I haven't verified this myself and this isn't done in the code.
- The mini DIN-8 connector is numbered looking at the front of a female connector.
- Click for the pinout of a type B USB socket.
- Do not connect a programmer while the USB cable is plugged in. If you want to be able to program the chip while it's plugged in, don't connect the ICSP connector Vdd pin (which means it has to be plugged in for programming to work).
- Getting programming errors when using a cheap (homebuilt) programmer? To quote the WinPic site:
There was a note on the Microchip forum (by Olin Lathrop) about programming the dsPIC30F201(**), suggesting to put 22..47 pF on the PGD and PGC lines to ground near the target chip. In addition, put a 100 ohm resistor in series with the PGD line between target chip and the cap. The resistor and cap on the PGD line low pass filter the PGD signal when it is driven by the target chip. This reduces the high frequencies that can couple onto the PGC line. The cap on the PGC line makes it less suceptible to coupled noise.
The finished converter, based on the smaller (but compatible) PIC18F2550... a PCB would have been nicer though. It has a number of extra components over the schematic: a reset and bootloader button (+ pull-up resistors) for easier further development, a LED to show that it's on, a jumper to choose between external and USB power and a small RC network for more stable programming (see the schematic notes). The pin header in the top left is the ICSP (programming) header, the bottom left header is USB, the bottom right one connects to the Sun mini-DIN connector.
Software
The software can be downloaded here. As far as programmers and software goes, I recommend the ICD2 in combination with MPLAB, or WinPic and a supported programmer. Also included is a version of the software for use with Microchip's USB bootloader. Setting up the bootloader is outside the scope of this document, but offers tons of advantages. The source code for the software can be found on the second page of this document.
Special Keys
The Sun keyboards have a number of keys that aren't present on a standard PC keyboard. These include the the volume, power, and 'Sun' keys (help, stop, again, etc). The converter emulates a Type 6 USB keyboard; it should work with Solaris without problems. Other Unix-like operating systems can be made te recognize the codes these special keys report too. Unfortunately, Windows doesn't report any virtual (=internal) key codes when these keys (except for power, but no function is mapped to its code) are pressed, making them unable to do anything. I haven't been succesful in getting the Sun, volume and power keys to be recognized as standard PC-style media/volume/power keys as found on many keyboards. To do this the convertor would need to be implement a composite USB device, which is something I have haven't gotten to work. Still, the keys can be made to work with Windows, see below.
There's also different styles of Sun keyboards: Unix style keyboard have the escape/tilde and control/caps lock pairs switched compared to PC keyboards. To further complicate matters a Sun keyboard has the modifier keys (alt,meta,etc) in other positions than a PC keyboard. Note that by default the meta and compose keys do work fine though, they report the same scancodes as the Windows and Application keys respectively.
To solve these two problems the adapter has the ability to switch some keys between two options. This allows the special keys to report scan codes that work with Windows (and can then be mapped to a function) and the modifier and style dependent keys to be changed to your preferred layout. To change a key's setting, just hold scroll lock and press the key. This will toggle between its two configurations. To reset all keys to their default values (Sun Type 6 style), hold scroll lock and press pause. For a list of keys, their alternatives, and the Windows scan codes the alternatives to special keys report, see this file.
Once a special key has been made to be recognized by Windows it still won't do anything useful, as Windows doesn't know what to do with the reported virtual key code. Software such as Hoekey can be used to map the keys' scan codes to useful functions. Here's the settings needed to let the keys work with Hoekey; I've set up some basic functions for most keys.
In conclusion, getting the special keys to work in Windows entails changing their mode (hold scroll lock and press the key to change) and using software to map the now recognized key to a function. With the provided Hoekey configuration this is a piece of cake. Some other keys can be changed to alternatives depending on your prefered layout.
Files
Special Sun keys, their various scan codes, and their alternative configurations
Sample HoeKey configuration
Sun keyboard converter compiled code