USBHost Keyboard Problem

25 Apr 2012

Edit update 24 Apr 2012: I think I have a better understanding now and will briefly update this original query. I am pretty sure the behavior I am seeing is normal. My previous experience with decoding USB keys was at a relatively low level (the "event" level, where events reported key presses and key releases etc.). I believe the data packets I am dealing with in USBHostShell are at a "lower level" and I need to process the packets to keep track of key presses and releases. I think I will be able to deal with this successfully.

----------------------------

I am trying to use USBHostShell to handle a USB keyboard. I have integrated the USBHostShell into my program and as long as I do not press multiple keys too close together in time it works correctly. I can use a single finger to poke the keys: 1234567 etc. as fast as possible with no problem. But when I try to actually type normally, any time that a single returned packet has more than one key code present, I almost always get a second or even third packet with some duplicate key codes. The data dump below is from a simultaneous, rapid, poke with two fingers on the number keys 1 and 2.

data 8: 00 00 1E 1F 00 00 00 00

data 8: 00 00 1E 00 00 00 00 00

I believe I should only get the one line that has the two key codes (1E and 1F). Perhaps it is something to do with the polling rate by the Host interface? I have not been able to find what determines the host polling rate of the keyboard.

I am using Peter Barrett's USBHostShell from Apr 2010 and will next attempt to use Ad van der Weiden's myUSBHost from July 2011, just in case there is some subtle difference that will eliminate my problem.

Unfortunately I know nothing about USB programming or C++. Although I have managed to make more progress in my project than I thought possible, this will be a killer for me if I cannot figure out why this is happening, so any hints or suggestions of things to look for will be greatly appreciated.

Chuck

23 Apr 2012

Hello Chuck,

if You check the terminal output for USB host examples with keyboard connected to mbed and You will see no data until You press or depress key that is because keyboard is not polled by mbed USB host every each time but keyboard uses interrupt method .

So keyboard sends report only when You press or depress key. If You press simultaneously one or more keys and You hold them only one report is sent. Next report is sent only when You press one more key(s) or depress any keys.

In AutoEvents.cpp is defined AutoEventCallback() which is called when USB device sends new report. Switch() determines who is sender of report based on USB device class (3 - HID), subclass and protocol (1 - keyboard, 2 - mouse)

I hope this can help You little bit.

24 Apr 2012

Hi "little llumpu",

Thanks for your comments. For some reason I was not notified of your reply and just happened to find it a moment ago. I find that both BlueUSB and USBHostShell display continuous data packets until I modify AutoEventCallback to only use printfBytes() when there is non-zero data. This is not a concern though.

I have found a posting in an Arduino forum that shows the same sort of data dumps I am seeing as a result of "key rollover" and the author makes this comment:

"Obviously, the information received this way can’t be directly used in an application. Certain actions, such as “USB to ASCII” transcoding and duplicate keys removal would have to be taken. "

The reference to "duplicate keys removal" gives me some hope that perhaps this is normal behavior and I will be able to come up with an algorithm that can recognize this situation, so there might be some hope for my project!

Thanks again for your comments.

Chuck