cancel
Showing results for 
Search instead for 
Did you mean: 

USB Device HID Keyboard example

AlexSmart
Senior
Posted on September 24, 2016 at 12:00

Does anyone USB Device HID Keyboard example? I'm struggling to modify USB mouse example into keyboard. Read some literature, tried to modify descriptors, but no luck...

#hid #hid #hid #usb-device #device #keyboard #keyboard #usb-hid #consumer
13 REPLIES 13
Kraal
Senior III
Posted on September 29, 2016 at 13:52

Hi Tsuneo,

Thank you for your valuable input !

Kraal

tsuneo
Senior
Posted on September 29, 2016 at 14:22

Hi Alex,

> Now I'm struggling to make multimedia keys work. 'Multimedia' keys belong to HID consumer device, apart from other keys (HID keyboard). - To send these keys, you have to modify your report descriptor completely for HID consumer device. - If you would like to have 'multimedia' keys with ordinary keys, you should make a composite device, HID keyboard + HID consumer, because Windows don't like merged keyboard with other HID device(s) using TLCs (Top-Level Collections). In this reason, all of PC keyboards are composite devices. The support of 'multimedia' keys depend on OS. Windows support is described on keyboard-support-windows-8.docx, downloaded from this MS page,

https://msdn.microsoft.com/en-us/library/windows/hardware/Dn613956%28v=vs.85%aspx

0690X00000604vjQAA.png The keys are assigned to bits on the input report one by one. For example,

//
// Report descriptor for media remote controller
//
// This descriptor defines ONE byte report, of this bitmap
// bit
// 0 : Next
// 1 : Previous
// 2 : Stop
// 3 : Play/Pause
// 4 : Mute
// 5 : Volume Up
// 6 : Volume Down
// 7 : --- (padding)
//
static u8 usbHidReportDescriptor[39] = { /* USB report descriptor */
0x05, 0x0c, // USAGE_PAGE (Consumer Devices)
0x09, 0x01, // USAGE (Consumer Control)
0xa1, 0x01, // COLLECTION (Application)
// -------------------- common global items
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1) - each field occupies 1 bit
// -------------------- misc bits
0x95, 0x05, // REPORT_COUNT (5)
0x09, 0xb5, // USAGE (Scan Next Track)
0x09, 0xb6, // USAGE (Scan Previous Track)
0x09, 0xb7, // USAGE (Stop)
0x09, 0xcd, // USAGE (Play/Pause)
0x09, 0xe2, // USAGE (Mute)
0x81, 0x06, // INPUT (Data,Var,Rel) - relative inputs
// -------------------- volume up/down bits
0x95, 0x02, // REPORT_COUNT (2)
0x09, 0xe9, // USAGE (Volume Up)
0x09, 0xea, // USAGE (Volume Down)
0x81, 0x02, // INPUT (Data,Var,Abs) - absolute inputs
// -------------------- padding bit
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x01, // INPUT (Cnst,Ary,Abs)
0xc0 // END_COLLECTION
};

Tsuneo
tsuneo
Senior
Posted on September 29, 2016 at 15:26

Ah I remember,

Volume up/down usages are RTC (Re-Trigger Control) type.

To up/down volume stepwise, your device should send two contiguous reports,

the first report holds 1 at volume up/down bit field

- user presses volume up or down key

the second report keeps 0

- user releases above key

If your device would send just the first 1 report without the second 0, the OS could interpret this behavior as ''volume up key is continuously pressed.'' And then, it should maximize the volume.

Please take care, so that it wouldn't break your PC speaker (or your ears 😉

Tsuneo

AlexSmart
Senior
Posted on October 01, 2016 at 14:25

Thank you so much!

It worked 🙂