A Programmable Keyboard Controller

I was frustrated by the Mac keyboard layout and also noticed that a lot of projects require some kind of custom keyboard controller (for example, if you’re trying to hack and old PS2 keyboard to work with a modern system. For this reason I decided to create a programmable keyboard controller.

The controller is based around a AT90USBKey and uses the LUFA library to manage the USB HID stuff.

To use the keyboard controller you need to removed the existing controller from your keyboard (hence the Mac keyboard disassembly I previously posted). Once removed you need to connect the keyboard matrix to the controller. It doesn’t really matter how you connect it, the idea is that the keyboard will learn the keyboard layout.

Here’s a close up of the controller installed in a Mac full size keyboard:

And a slightly less elegant hack in to a Mini mac keyboard:

To program the keyboard, open notepad or another text editor on your computer. Plug the keyboard in while holding down a key. The keyboard will being typing text in to the text editor. It’ll start my printing a welcome message and will then ask you to press keys on your keyboard.

The controller is now learning which key is which. It’s continually scanning the keyboard matrix, and when it detects a short between pins it registers this as the key it’s currently learning. Once training is complete the controller writes the matrix layout information to the AT90s internal flash. So you only need to train once.

The whole thing seems to work pretty well, though I think my debouncing logic could do with some work. Suggestions are welcome.

I’ve put all the code on sourceforge here.

If you’re interested in using or developing from this code, please let me know. I think a keyboard controller like this could be a generally useful tool for hacking projects.