Page 1 of 2

Is remapping a USB keyboard using Teensy possible?

Posted: 13 Jun 2012, 14:34
by Limmy
I saw two USB converters from Soarer and Hasu with NKRO feature and layered mapping. Can similar thing be done with USB only keyboards? Since input signal is USB, I don't think NKRO is possible, but the focus of this device is to enable remapping/macro/configurable 2nd layer feature.

This is what has been done:
XT/AT/PS2/Terminal to USB Converter with NKRO ( http://geekhack.org/showwiki.php?title=Island:17458 ) by Soarer
PS/2 to USB keyboard converter for Teensy with mousekeys and NKRO ( http://geekhack.org/showwiki.php?title=Island:14618 ) by Hasu

I was wondering if similar thing could be achieved using an USB to USB remapper.

Here is how it is going to be used.
USB only Keyboard - USB - remapper - USB - computer

E.g. with this remapper you can
1. remap CapsLock in a USB keyboard to a control key
2. integrate second layer in Realforce 87U, e.g. you can make HHKB's 2nd layer into Realforce 87U
3. mouse keys and other fancy features could be possible

I do not have enough knowledge to see if this is even possible, but if PS/2 to USB converter can do it, I am guessing converting USB signal to another USB signal shouldn't be too hard. If this is possible, then every USB keyboard could potentially become a user configurable keyboard.

Thanks for reading.

Posted: 13 Jun 2012, 16:07
by Soarer
There was some discussion on GH about such a device, which got as far as identifying some suitable hardware.

Essentially...

The Teensy can't do USB host in hardware, and also only has a single USB port. There is a software USB implementation, V-USB, but it's quite a CPU hog. I'm not familiar with it, so I'm not sure how well it would perform for the host part of the device. Vinculum II has two USB ports which can be host, has a free (but not open source) toolchain, and reasonably priced breakout boards. Unfortunately it doesn't have a built-in bootloader, so an extra programming module is required (although it's not expensive).

Supporting a standard boot mode 6KRO keyboard would be fairly straightforward. Handling fancy NKRO implementations would be quite a bit more work, as would passing through any other functionality e.g. built-in pointing device or hub etc.

The actual remapping etc. stuff in the middle would be the easy bit :-D

Posted: 13 Jun 2012, 20:30
by Limmy
I guess it is not as simple as I thought it would be.

How does some USB keyboards work as PS/2 boards by putting on a small adapter? Are such keyboards designed to work that way?
*Answer to my question above: it seems to be the case because USB to PS/2 dongles are just rewiring with out any signal processing. See Human interface devices (HIDs) section in http://en.wikipedia.org/wiki/Universal_Serial_Bus

I heard Teensy is a computer that an process signals/data, is processing USB keyboard signal complicated? After all, it is couple of bytes sent over cable right? All that needs to be done is to figure out specific signals/data for such and such keys and replace it or send sequence of inputs. But again, USB device is supposedly polled by host so the polling part has to be done.. Hmm.. I begin to see how this could be complicated.. I should read a bit more.
*After spending some time reading GH posts, I am sad as I found the project hit a wall. My motto when solving a problem is simplest first then step by step. I would think after a simplest solution is proposed other people would find it easier to add to the simple solution. My first goal would be to make RF programmable with second layer. Other functionality, such as supporting hub or mouse input should be secondary, although it would be nice to have those features.

Anyway, thanks for the link in GH and a good summary.

Posted: 13 Jun 2012, 21:16
by Soarer
Well the host port has to enumerate devices on the bus (even if only one), read some descriptors for each, find the one it wants, and set it up. For anything more than boot mode, it would then query the device's report descriptors and configure itself to understand the reports (which is not trivial, since they are so flexible). For passing through other devices, it would need to replicate them on the device port so the host computer sees them (this may not even be possible for hubs).

All of the low-level stuff like polling and transfers is handled by hardware (on the Vinculum or AT90USB1287). But that is why I'm not sure V-USB could handle being host, or at least would be more work to get going.

With the Vinculum II it would be pretty easy to get a basic version started - they have good libraries and plenty of examples. I keep meaning to order a dev board, but I know I wouldn't find time to do anything with it for a while.

Posted: 14 Jun 2012, 11:14
by Icarium
Limmy wrote: How does some USB keyboards work as PS/2 boards by putting on a small adapter? Are such keyboards designed to work that way?
*Answer to my question above: it seems to be the case because USB to PS/2 dongles are just rewiring with out any signal processing. See Human interface devices (HIDs) section in http://en.wikipedia.org/wiki/Universal_Serial_Bus
I don't know for which keyboards this holds but that should of course be easily doable with a Teensy. All you have to do is get the keyboard to be in PS/2 mode.
I heard Teensy is a computer that an process signals/data, is processing USB keyboard signal complicated? After all, it is couple of bytes sent over cable right?
I think the core problem is, that this is not true. With USB you have to do actual two-way communication - which is quite complicated - to emulate a host. It is still doable in theory but that's what Soarer criticized as "possibly a CPU hog".
The CPU he is referring to is the microchip on the Teensy which is not really all that powerful. ;)

Soarer: Please correct me if I'm wrong. :)

Posted: 14 Jun 2012, 14:50
by Soarer
Something like that :) V-USB doesn't say it can do a host port, and there's no host code in the example projects that I could see. Still, it might be possible, but it for sure would be a lot more work than with hardware support! The CPU hog comment is because while it is actually sending or receiving, it has to have the CPU all to itself. Also, I presume that it has to respond to activity within a fairly short time, or it will miss it. This makes coding the rest of it more difficult, since it has to not delay handling such activity too much.

The Vinculum II has its downsides as well - there's no on-chip EEPROM (rather useful for storing remappings etc), and it requires a dongle for programming it. An external EEPROM chip could be added cheaply, but its a pain. It's odd because quite a few of their other products do have on-chip EEPROM. They have a bootloader which will load a new firmware from a USB memory stick, but it's not loaded onto the device by default (even on their breakout modules).

edited: V-USB doesn't say it can do host, I misread something :oops:

Posted: 14 Jun 2012, 15:56
by Maarten
I really should get into this whole Arduino business, looks like a lot of fun!

Would the board below combined with an UNO for example be able to 'intercept' USB mumbo-jumbo from a keyboard and do some switcheroo magic to do remapping thingies;

http://www.circuitsathome.com/products- ... or-arduino

Would be wicked to have a USB box that could remap any USB board.....

Posted: 14 Jun 2012, 16:45
by Soarer
Looks good!

Not sure how good the Arduino Uno client USB port is... presumably OK?

Engineering-wise, it's a bit disappointing to end up with such a multi-chip, two-pcb solution... but on the other hand, I just spotted a post that seems critical of the Vinculum toolchain and lack of solid architecture docs.

Posted: 14 Jun 2012, 17:04
by Maarten
Soarer wrote:Looks good!

Not sure how good the Arduino Uno client USB port is... presumably OK?
Well as far as i understand it Teensy still beats most 'true' arduino platforms when it comes to USB hardware emulation both in simplicity and functionality. But making any Arduino act like a keyboard should be very doable.

I do however agree that this approach would be a bit overkill from an engineering standpoint, it would just be soo much neater if you could have a tiny single-chip solution for this job. However, this complex approach also adds various other possibilities (communication over bluetooth or wifi/network command inputs for example)

Check out youtube btw, some real fun arduino keyboard stuff on there
http://www.youtube.com/watch?v=b_y5L2N67HI
http://www.youtube.com/watch?v=q7ncPsrqphg

Posted: 14 Jun 2012, 18:09
by Soarer
Ooh, another option... I guess the shield would work fine with the Sparkfun ATmega32U4 breakout, since it has a 3.3V regulator (the Teensy doesn't, sadly).

edit: Or... use a Teensy with an AT90USBKEY, and some simple custom comms protocol (over SPI?) between them. Benefit: standard AVR USB host, so LUFA could be used. Downside: size!!

Posted: 14 Jun 2012, 18:31
by Maarten
Hmmm.... this is getting interesting.. im keeping my eye on this thread ;)

Posted: 14 Jun 2012, 18:34
by Soarer
Heh, didn't quite sneak my edit in in time :lol:

Wish there was a small, cheap, no frills AT90USB1287 breakout...

Posted: 14 Jun 2012, 19:15
by Maarten
Soarer wrote:Wish there was a small, cheap, no frills AT90USB1287 breakout...
how good are your hack n slash modding skills?
board_x.JPG
board_x.JPG (573.65 KiB) Viewed 26647 times

Posted: 14 Jun 2012, 20:16
by Soarer
Where's that from? Looks pretty good already!

Posted: 14 Jun 2012, 20:19
by RC-1140
That's apparently an USB Tipro Controller board. I wish I had an USB one too. I only have two PS/2 ones.

Posted: 14 Jun 2012, 20:26
by Soarer
Ah, right. Yeah, that would need some rework :ugeek:

Posted: 14 Jun 2012, 22:26
by Maarten
Well yeah, would need quite a bit of work actually but at least it has something very close to your beloved AT90USB128x ;)

Posted: 14 Jun 2012, 22:41
by Soarer
x?! The good bit is the 7!!!

AT90USB647 would be fine too, but seems even more rare than the '1287.

Posted: 15 Jun 2012, 08:43
by hasu
I bought USB Shield for Arduino from sparkfun a year ago for this purpose but shortly I stuck and gave up USB-USB converter due to lack of my time, skill and motivation.

Where is good USB boards worth investing my time and money in thifs dev? Good keyboards always are vintage with old protocol like PS/2, XT, ADB or proprietary! ; )

Recently Arduino guys release Leonardo with ATMega32U4 finally on which we'll be able to use most of code of Teensy.
I think Leonardo with USB shield is a good setup for this development. I guess it is fun to start over again this when I have some time and a nice USB board.

Posted: 15 Jun 2012, 10:32
by Maarten
Zomg, i haven't even heard about Leonardo yet... That's a wicked little board!! Its indeed just like teensy's physically bigger brother! Hmmm, tempting to get one of those for some playtime 8-)
Soarer wrote:x?! The good bit is the 7!!!

AT90USB647 would be fine too, but seems even more rare than the '1287.
Erm... the 7 is the host mode right? :oops:

But isnt the 1287 what youd find on the teensy++? AT90USB647 is what most USB Tipros run so if you posted a wtb here on the forum i bet you could find one pretty easy (no sorry you cant has mine lol)

Posted: 15 Jun 2012, 13:36
by Soarer
Maarten wrote:Erm... the 7 is the host mode right? :oops:

But isnt the 1287 what youd find on the teensy++? AT90USB647 is what most USB Tipros run so if you posted a wtb here on the forum i bet you could find one pretty easy (no sorry you cant has mine lol)
Teensy++ had a '646, and Teensy++ 2.0 has a '1286. The last digit is like a family number for AVRs, and in this case, yes, the 7 means host mode. :)

Trouble with the Tipro board is that I could mod one, fine, but it's not a great solution if this turns out to be something more people want to make.

I'm starting to wonder if using the cheapest Vinculum breakout, just for input, connected to a Teensy for output might be a good way to do it - apart from the two postages, it's one of the cheapest ways so far, and of course all my Teensy code for remapping and output could be used as it is. If the Teensy could also be used to program the Vinc, then even better.

Like hasu, I doubt how many people really want a USB-to-USB device for keyboards; it's a fairly small niche. But there is another very good use for it - as a hardware mouse rate booster ;)

Posted: 15 Jun 2012, 14:20
by Maarten
Well.... it would open up quite a world for DVORAK users who swap computers alot and still like to carry their fav board along (regular USB non-DVORAK board ofc). Would also make a great keystroke-logger (oh my) and like i said it adds wireless possibilities! Granted, the market would not be very huge for such a thing but it sure would be awesome ;)

When my raspberry-pi arrives ill see if that can be tricked into some fancy USB-output from its GPIO without too much additional hardware.... using a Pi for this purpose would be a bit overkill but what the heck ;)

Posted: 17 Jun 2012, 10:02
by bpiphany
Soarer wrote:Ooh, another option... I guess the shield would work fine with the Sparkfun ATmega32U4 breakout, since it has a 3.3V regulator (the Teensy doesn't, sadly).
To be fair and correct ;) I haven't done it myself but it's not too complicated adding a regulator to the Teensys.

Posted: 17 Jun 2012, 10:56
by Soarer
PrinsValium wrote:To be fair and correct ;) I haven't done it myself but it's not too complicated adding a regulator to the Teensys.
I had forgotten about that! Still, it's an extra part to buy, and the soldering is out of most people's comfort zone :evilgeek:

The shield would need to get both 3.3V and 5V. I think that would mean running the Teensy at 3.3V, and patching a wire onto the 5V pad - schematic.

Posted: 17 Jun 2012, 11:01
by Maarten
Arduino Leonardo + USB host shield would still be the easiest (aka no-soldering required) solution right?

Posted: 17 Jun 2012, 13:14
by Soarer
Yes... probably... I don't really have much idea of how much RAM it takes to run USB host code, and the '32U4 has only 2.5KB. Handling standard 6KRO keyboards shouldn't take too much, but parsing the HID descriptors and handling other keyboards is probably too much for it.

Posted: 17 Jun 2012, 23:13
by Soarer
Soarer wrote:The shield would need to get both 3.3V and 5V. I think that would mean running the Teensy at 3.3V, and patching a wire onto the 5V pad - schematic.
Heh, I hadn't seen this (since it's in the teensyduino section): teensy + usb host shield.

Posted: 23 Jun 2012, 17:48
by Soarer
These two fit together really nicely...
Teensy_with_Mini_Shield.jpg
Teensy_with_Mini_Shield.jpg (184.77 KiB) Viewed 26348 times
Note: to put that link on the back (so that one of the Vcc pins is still +5v) requires cutting the PCB track to that pin first.

USB_Host_Shield_and_Teensy2.png
USB_Host_Shield_and_Teensy2.png (357.39 KiB) Viewed 26343 times

Posted: 24 Jun 2012, 06:52
by Limmy
Wow. Do we have necessary hardware for the USB to USB converter, or is it unclear in this stage?

Posted: 24 Jun 2012, 14:22
by Soarer
No more info than before really! But yeah, it should work, if I can find time to program it. This setup is pretty much equivalent to the Leonardo + Shield setup, except that the Teensy is running at 3.3V instead of 5V. And obviously, this one is smaller, and requires some fiddly soldering!