Small keyboard HID problem

274 views
Skip to first unread message

Andrew S.

unread,
Sep 23, 2011, 11:12:06 AM9/23/11
to LUFA Library Support List
Hi!

After seeing how cheap the Minimus USB boards are, I decided to take
the plunge and buy myself an AVR USB dev board :)
Which naturally lead me to the wonderful LUFA project...

Ever since seeing http://blog.makezine.com/archive/2011/04/the-awesome-button.html
I've always wanted to make one myself, so I decided to make that my
first LUFA project. When I get it finished, I'll release the code for
inclusion in LUFA.

Andrew S.

unread,
Sep 23, 2011, 11:50:25 AM9/23/11
to LUFA Library Support List
Hi!

After seeing how cheap the Minimus USB boards are (www.ck3.co.uk), I
decided to take the plunge and buy myself an AVR USB dev board :)
Which naturally lead me to the wonderful LUFA project...

Ever since seeing http://blog.makezine.com/archive/2011/04/the-awesome-button.html
I've always wanted to make one myself, so I decided to make that my
first LUFA project. When I get it finished, I'll release the code for
inclusion in LUFA.

So I've spent the past couple of evenings working from the Demos/
Device/ClassDriver/Keyboard/ example, and I've /almost/ got it
working:
* button is asynchronously software-debounced
* 'key-repeat' is disabled
* I've limited the rate at which keypresses are sent, to prevent
overloading the host's keyboard-receive buffer
* I've written a function which converts a printable ASCII char to
it's HID scancode and modifier values (currently using a UK qwerty
keymap)
* The "string to be typed" is specified as a char*, and when the
button is pressed, it loops through the string one character at a
time, sending one HID keypress at a time

The only problem I have is that for some reason whenever I send a
HID_KEYBOARD_SC_BACKSLASH_AND_PIPE keypress, the host interprets it as
HID_KEYBOARD_SC_NON_US_HASHMARK_AND_TILDE and I can't for the life of
me figure out why! Every other keypress works 100% correctly, apart
from this one!
I've tried on Linux and Windows, and with both the stable and beta
versions of LUFA, and I always get the same results. I've got a "real"
USB keyboard, and that does send 'HID_KEYBOARD_SC_BACKSLASH_AND_PIPE'
correctly.

A bit more in-depth explanation:
On my real USB keyboard, if I press the \ key, then a \ appears on
screen (obviously!) and pressing shift and \ makes a | appear on
screen. And # produces #, and shift and # produces ~.
On my LUFA-powered-minimus board, if I send the
HID_KEYBOARD_SC_NON_US_HASHMARK_AND_TILDE keycode then # appears on
screen and if I send the HID_KEYBOARD_SC_NON_US_HASHMARK_AND_TILDE
keycode and HID_KEYBOARD_MODIFER_LEFTSHIFT modifier, then ~ appears on
the screen. So far so good. However when I send
HID_KEYBOARD_SC_BACKSLASH_AND_PIPE then # appears on screen, and if I
send HID_KEYBOARD_SC_BACKSLASH_AND_PIPE with
HID_KEYBOARD_MODIFER_LEFTSHIFT modifier then ~ appears on screen :-(
Every other keypress works correctly, and I've tried checking the
#defines in Drivers/USB/Class/Common/HID.h against the HID keyboard
specs, and everything looks fine.

If it makes any difference (probably not?) I'm compiling on 64-bit
Linux with these software versions:
gcc-avr 4.3.5-1
avr-libc 1.6.8-2
binutils-avr 2.20.1-1ubuntu2
dfu-programmer 0.5.4

Any suggestions?
I tried looking into USB sniffers, but it seems like none of the
opensource ones work on Windows7 x64, and the Linux ones are a bit
lowlevel and poorly explained so I didn't know where to start.

Andrew

Chris McClelland

unread,
Sep 24, 2011, 9:27:06 AM9/24/11
to LUFA Library Support List
Excellent, thanks for telling me about Minimus, now I don't have to
mess about making Nanduino[1] PCBs anymore!

Recently I made a PS2/USB converter[2], based on one of Dean's
examples, and I found the Linux USB sniffing to be excellent. There's
probably a much easier way to do this, but the following steps worked
for me:

1) Find out which bus your device is on:

chris@wotan$ lsusb | grep Atmel
Bus 001 Device 106: ID 03eb:2042 Atmel Corp. LUFA Keyboard Demo
Application

2) See what devices are there on bus 1:

chris@wotan$ sudo ls /sys/kernel/debug/usb/usbmon/ | grep -E ^1
1s
1t
1u

3) Just "cat" each of them in turn until you find the right one:

chris@wotan$ sleep 1;sudo cat /sys/kernel/debug/usb/usbmon/1u
ffff8801f6c90f00 1867273983 C Ii:1:106:1 0:1 8 = 00006400 00000000
ffff8801f6c90f00 1867274030 S Ii:1:106:1 -115:1 8 <
\ffff8801f6c90f00 1867360969 C Ii:1:106:1 0:1 8 = 00000000 00000000
ffff8801f6c90f00 1867361013 S Ii:1:106:1 -115:1 8 <

That's me hitting '\' and releasing it again, causing scancode 0x64
which on my keyboard is the key between l-shift and 'z'.

- Chris

[1] http://www.makestuff.eu/wordpress/?page_id=569
[2] http://vimeo.com/makestuff/ps2usb

Andrew S.

unread,
Sep 24, 2011, 11:33:34 AM9/24/11
to LUFA Library Support List
> Excellent, thanks for telling me about Minimus, now I don't have to
> mess about making Nanduino[1] PCBs anymore!

Yeah, given how *much* cheaper Minimus seems to be than any other USB
AVR board, I'm surprised there's not loads of online recommendations/
tutorials about them.
Maybe the price has only become so cheap fairly recently, because they
can't be used to hack PS3s (which looks like the primary focus of
their creation) any more? *shrug*
Or are such cut-down boards frowned upon by the AVR community for not
having more built-in peripherals?

> Recently I made a PS2/USB converter[2], based on one of Dean's

Interesting that your pre-built PS2->USB adaptor has problems with the
same backslash key I'm having problems with - possibly we're sharing
the same bug ;)

> examples, and I found the Linux USB sniffing to be excellent. There's
> probably a much easier way to do this, but the following steps worked
[snip]
Oh cool, that was easy, thanks! :)

> That's me hitting '\' and releasing it again, causing scancode 0x64
> which on my keyboard is the key between l-shift and 'z'.

Yup, I got the same, and that revealed the problem - I was sending
HID_KEYBOARD_SC_BACKSLASH_AND_PIPE (0x31) and not
HID_KEYBOARD_SC_NON_US_BACKSLASH_AND_PIPE (0x64).
So now my code works properly for _every_ printable character, yay!

Thanks to Chris for the sniffing help, and huge thanks to Dean for
LUFA.

Andrew

Chris McClelland

unread,
Sep 24, 2011, 11:54:21 AM9/24/11
to LUFA Library Support List
Peripherals? You've got two buttons and two LEDs, what more do you
want? :-)

Anyway, I ordered ten of them, and will definitely be doing some
tutorials, so keep an eye on makestuff.eu!

Chris

Andrew S.

unread,
Sep 24, 2011, 12:59:54 PM9/24/11
to LUFA Library Support List
> Anyway, I ordered ten of them, and will definitely be doing some
> tutorials, so keep an eye on makestuff.eu!

Will do! :-)

In case anyone else is interested in cheap tiny hardware... ;) I was
recommended the MinimusUSB by someone on the BifferBoard
( www.bifferos.co.uk ) mailing list as a cheap way of adding lots more
GPIO lines.
Apologies in advance if I've caused any offence by mentioning non-AVR
hardware!

Andrew

Paul Stoffregen

unread,
Sep 24, 2011, 1:58:26 PM9/24/11
to lufa-s...@googlegroups.com

> Anyway, I ordered ten of them, and will definitely be doing some
> tutorials, so keep an eye on makestuff.eu!

Before you put a lot of work into tutorials, you might consider what
will happen when the supply of Minimus boards runs out? Minimum will
almost certainly be discontinued. All the web pages and
www.minimususb.com website are likely to vanish.

It easy to see the people behind Minimus only ever intended it to be
used for hacking gaming consoles. The only Minimus tutorial ever
published was how to load a pre-compiled .hex file. The only examples
they've ever published are stolen from Olimex.

At about this time last year, they were selling Minimus at an insane
price! It was merely an unscrupulous attempt to take advantage of the
scarcity of AVR chips and boards at a time of huge demand from gaming
console users. They probably did make quite a lot of money, selling
Minimum for over $50, but that was only temporary. As Asian companies
produced lots of clones, and gaming consoles updated, prices and demand
quickly fell.

Instead of actually writing any tutorials, or commissioning any hardware
enthusiasts like you to create anything, they simply slashed prices.
Clearly their greed to take advantage of the temporary AVR scarcity
backfired, at least to some degree (they probably made plenty of money
selling '162's at $50), and they are left with many boards that don't
sell even at such low prices.

Well, at least some do sell, and if you write tutorials, you'll help the
unload the rest of those boards. If your tutorials are a big success,
I'm sure they will raise the price again on the remaining boards. But
then what will happen? They only ever intended to sell this at
massively inflated prices, and they've invested almost no work into the
platform since October 2010 - and even back then, only a minimum effort
(bad pun). Once they are all sold, unless they can fetch a high price
with little effort or investment, it's almost certain Minimus will never
be made again.

How useful will your tutorials be once this specific hardware is gone?
Especially if the main point of your effort is to help fellow hobbyists
save some money, that benefit is likely to be short lived.

If you do write tutorials, even tutorials where the main point is to
help people save money, I hope you'll invest in teaching techniques with
lasting value. There's so much need for good tutorials. It seems
wasteful to put a bunch of work into a dead platform that will only vanish.

Chris McClelland

unread,
Sep 24, 2011, 2:39:08 PM9/24/11
to LUFA Library Support List
To be honest I don't care what it was designed to be used for; what it
*is* is an AT90USB162 soldered to a bit of PCB. If it's discontinued,
then I'll just buy a similar board from someone else, or go back to
making my own boards.

If I spend time writing up something I've been working on, I do so
primarily because (shocking I know!) I enjoy doing so, and because
since I make use of information on the Internet every day, and feel it
only right to put some little thing back in from time to time. If
someone finds it useful or interesting, great. If not, *shrug*.

Chris
Reply all
Reply to author
Forward
0 new messages