8

I'm new to the hardware field in general. For one project I'm trying to create a custom keyboard that will have some extra keys, say 20-25 more than a standard keyboard. I've read about scan codes and scan code sets. I've also read about keyboard encoders, controllers etc. at pages like these:

http://retired.beyondlogic.org/keyboard/keybrd.htm

http://www.computer-engineering.org/ps2keyboard

But still I'm not clear which encoder will allow me to generate a custom scan code that is not defined in any standard scan code sets. Also will the standard keyboard controller (8042 compatible) in a PC process these non-standard scan codes?

PeterJ
  • 17,131
  • 37
  • 56
  • 91
Vivek
  • 181
  • 3
  • Most keyboards are USB HID devices these days so it is just a case of putting the codes you want into the keyboard input report... – John Burton Jul 26 '10 at 20:39
  • Well, I say "just", it requires quite a lot of knowledge and software to make it all work – John Burton Jul 26 '10 at 20:40
  • I'm not able to find any good article that describes how USB HID keyboard works, how exactly it communicates with host/PC, etc (the way above 2 sites describe the PS/2 protocol). If you know any site can you please give me the URL? – Vivek Jul 27 '10 at 18:40
  • @Vivek: There probably wont be a site describing only USB HID, you need to understand USB itself, of which HID is a subset. – davr Jul 28 '10 at 16:21

3 Answers3

5

Atmel (and Microchip too I think) has a generic HID driver for their MCUs available, with full sourcecode at each end available (Client test software, and embedded HID stack).

Browsing Atmel's offering, they even have a full-blown keyboard demo board, again with source code.

It's not the simplest example (They've written their own task scheduler!), but I think it should be pretty easy to mod to do what you want.

Look in keyboard_task.c on the above links keyboard demo (or here). It seems to be exactly what you want. A great big array of scancodes, being used to write a message to the computer by emulating a keyboard into any text editor.

The actual HID keystroke values are abstracted away using #define into a file called usb_commun_hid.h, which seems to be not(!) included in the above download (I guess it comes with the compiler?), but they just map to plain old single byte values, so you should be able to add more all you want. (See the a00102.html file in the above link.)

I would image Microchip has something similar, but I don't feel too much like digging through their implementation right now. If you want, I may be able to do so later.

Of course, this doesn't really do anything about how you're decoding these scancodes at the computer end, but again, Atmel does have .Net examples of how to talk to their HID devices, so something hackable should be available.

Connor Wolf
  • 31,938
  • 6
  • 77
  • 137
1

I was recently educated in this question about two options for USB development:

  • The teensy USB development board (uses ATMEGA32U4 or AT90USB1286 USB enabled AVR microcontroller)
  • The inputattach utility (Linux) for registering serial devices (like an FT232) as input devices

Would one of these work for you? Either way, you're going to have to write your own driver for it, because your OS isn't going to like your sending of nonstandard scancodes.

The advantage of having standard scancodes is that every keyboard you plug in "just works" (In theory). If you don't mind some configuration, why bother trying to emulate the scancodes?

Kevin Vermeer
  • 19,989
  • 8
  • 57
  • 102
0

It should work fine, isn't that how those "Multimedia" keyboards work? With the play/pause/volume/etc keys on them?

davr
  • 6,802
  • 2
  • 25
  • 37
  • "Multimedia" keys are part of the standard itself, IMO. If you check http://www.computer-engineering.org/ps2keyboard/scancodes2.html you can find that all the multimedia keys have a specific scan code assigned to them. And I'm talking about how to use non-standard scan codes (the ones that are not associated with any specific key in the standard). As per my understanding there are around 150 scan codes that are not getting used. (Continued in next comment...) – Vivek Jul 27 '10 at 18:04
  • Even if we consider there are around 30 odd values that are used as commands, still there are quite a few scan codes that are "undefined". I want to utilize those. Say in the range of 85h - DFh. Can we do that? – Vivek Jul 27 '10 at 18:06