Is remapping a USB keyboard using Teensy possible?

Limmy

13 Jun 2012, 14:34

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.

User avatar
Soarer

13 Jun 2012, 16:07

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

Limmy

13 Jun 2012, 20:30

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.
Last edited by Limmy on 13 Jun 2012, 21:16, edited 1 time in total.

User avatar
Soarer

13 Jun 2012, 21:16

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.

User avatar
Icarium

14 Jun 2012, 11:14

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. :)

User avatar
Soarer

14 Jun 2012, 14:50

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:
Last edited by Soarer on 14 Jun 2012, 16:36, edited 1 time in total.

User avatar
Maarten

14 Jun 2012, 15:56

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.....

User avatar
Soarer

14 Jun 2012, 16:45

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.

User avatar
Maarten

14 Jun 2012, 17:04

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

User avatar
Soarer

14 Jun 2012, 18:09

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!!
Last edited by Soarer on 14 Jun 2012, 18:32, edited 1 time in total.

User avatar
Maarten

14 Jun 2012, 18:31

Hmmm.... this is getting interesting.. im keeping my eye on this thread ;)

User avatar
Soarer

14 Jun 2012, 18:34

Heh, didn't quite sneak my edit in in time :lol:

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

User avatar
Maarten

14 Jun 2012, 19:15

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 26662 times

User avatar
Soarer

14 Jun 2012, 20:16

Where's that from? Looks pretty good already!

User avatar
RC-1140

14 Jun 2012, 20:19

That's apparently an USB Tipro Controller board. I wish I had an USB one too. I only have two PS/2 ones.

User avatar
Soarer

14 Jun 2012, 20:26

Ah, right. Yeah, that would need some rework :ugeek:

User avatar
Maarten

14 Jun 2012, 22:26

Well yeah, would need quite a bit of work actually but at least it has something very close to your beloved AT90USB128x ;)

User avatar
Soarer

14 Jun 2012, 22:41

x?! The good bit is the 7!!!

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

User avatar
hasu

15 Jun 2012, 08:43

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.

User avatar
Maarten

15 Jun 2012, 10:32

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)

User avatar
Soarer

15 Jun 2012, 13:36

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 ;)

User avatar
Maarten

15 Jun 2012, 14:20

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 ;)

bpiphany

17 Jun 2012, 10:02

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.

User avatar
Soarer

17 Jun 2012, 10:56

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.

User avatar
Maarten

17 Jun 2012, 11:01

Arduino Leonardo + USB host shield would still be the easiest (aka no-soldering required) solution right?

User avatar
Soarer

17 Jun 2012, 13:14

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.

User avatar
Soarer

17 Jun 2012, 23:13

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.

User avatar
Soarer

23 Jun 2012, 17:48

These two fit together really nicely...
Teensy_with_Mini_Shield.jpg
Teensy_with_Mini_Shield.jpg (184.77 KiB) Viewed 26363 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 26358 times
Last edited by Soarer on 31 Oct 2012, 03:39, edited 4 times in total.

Limmy

24 Jun 2012, 06:52

Wow. Do we have necessary hardware for the USB to USB converter, or is it unclear in this stage?

User avatar
Soarer

24 Jun 2012, 14:22

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!

Post Reply

Return to “Workshop”