USB HID Devices Revision 1.0: GHI Electronics, LLC
USB HID Devices Revision 1.0: GHI Electronics, LLC
Revision 1.0
To access HID:
First, this HID must be enumerated like any other USB device. We will
initialize HID which is Attached to USB port 1, to USB device handle 0 as
an example
UI 1>0
Second, HID Driver must be initialized to take care of this HID using the
registering command and USB pipe must be chosen to access the Output
Endpoint.
UH 0>3
Note: the previous initialization process is required to perform only once
after connecting HID
Then USBwiz will output Report Data size that is send by the HID which is
4 Bytes for Mice and 8 Bytes for Keyboards. Now the USBwiz is ready get
Data from HID which can be performed by Read HID Pipe. Data will be
not by translated into ASCII HEX so the data will appear as strange
characters if using Hyper terminal – which used to output incoming data
on serial port as characters - .
RH 3
If the HID has no report to send then USBwiz will return error code 0xB5
which is practically not an error.
USB Keyboard Report Structure:
Parsing Standard USB Keyboard Report data:
Report size: 8 Bytes
Key Array Bytes can be more or less than 6 bytes. And each byte represents a
pressed key. So a 6-byte Array accepts up to 6 pressed buttons at the same
time. But if the pressed keys exceeded 6, the key board will report a phantom
state index code “Error Rollover Usage ID =0x01” instead of pressed buttons
Usage ID codes.
The following example taken from HID specification that shows important cases
for 4-Byte array keyboard:
!00
UH 0>1 Register device of handle 0 as an HID and use pipe number 1 to get HID report data
!00
$08 USBwiz states that HID report size is 8 bytes which is the standard size for USB keyboards
!00
RH 1
!00
8 bytes will be sent if available – i.e. someone stroke a key or more – user
can store this data in some array and parse it according the Keyboard Report
Structure
!00
For example if the 8 bytes were:
Byte 0 Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6 Byte 7
0x03 0x04 0x06 0x00 0x00 0x00 0x00 0x00
According to USB Keyboard Report Structure stated previously in this tutorial,
Left SHIF and Left CTRL are pressed and button A and button C are down.
Byte 0 is 0x03 = 0b00000011 so the first two bits are 1s, the first one means Left
CTRL is pressed and the second one means that Left SHIF is pressed according
to Modifiers Keys Bytes table.
Byte 1 is 0x04 means button A is down
Byte 2 is 0x06 means button C is down
It more that 7 buttons apart from modifiers buttons, Report data will be all 0x01
from Byte 1 to Byte 7 stating an error.
Example 2:
Accessing USB Mouse:
After starting USBwiz and running the firmware from boot loader by R
command. GHI Electronics Header will appear followed by Firmware
version, then commands can be used to access USB mouse as following:
commands are in blue and they are always followed by Carriage return to
be executed. USBwiz output is in Red.
GHI Electronics, LLC
----------------------
USBwiz (TM) 2.08
!00
UI 0>0 Enumerate USB Device on Port 0 to USB device handle 0
!00
UH 0>1 Register device of handle 0 as an HID and use pipe number 1 to get HID report data
!00
$04 USBwiz states that HID report size is 4 bytes which is the standard size for USB keyboards
!00
RH 1
!00
4 bytes will be sent if available – i.e. someone stroke a key or more – user
can store this data in some array and parse it according the Mouse Report
Structure
!00
For example if the 4 bytes were:
Byte 0 Byte 1 Byte 2 Byte 3
0x01 0x04 0xFD 0x00
According to USB Mouse Report Structure stated previously in this tutorial, Left
mouse button is pressed, and the mouse is moved 4 dots to the left and 3 dots
down relatively to the old position and scroll wheels are not changed.
Byte 0 is 0x01 = 0b00000001 means the first one means Left button is pressed.
Byte 1 is 0x04 means movement 4 dots to right
Byte 2 is 0xFD means movement 3 dots down
References:
• USB Device Class Definition for Human Interface Devices www.usb.org
• USB HID Usage Table www.usb.org