Skip to content

Instantly share code, notes, and snippets.

@rockavoldy
Created October 27, 2024 03:23
Show Gist options
  • Save rockavoldy/5de48f8d0a1cb781f3197d6a2633bb0a to your computer and use it in GitHub Desktop.
Save rockavoldy/5de48f8d0a1cb781f3197d6a2633bb0a to your computer and use it in GitHub Desktop.
HID Report Descriptor, usage and usage page and some examples. From chatgpt

Certainly! HID descriptors can be a bit complex, but here’s a breakdown of common Usage Pages and Usages, along with their options. This will help when designing HID devices like gamepads, joysticks, keyboards, and more.

1. Usage Pages

  • Usage Pages group related Usages (specific controls) together.
  • Usage Pages are defined by a 16-bit identifier.
Usage Page Name ID (Hex) Description
Generic Desktop Controls 0x01 Basic controls like joysticks, mice, keyboards, etc.
Simulation Controls 0x02 Controls for simulation devices, such as flight controls and vehicles.
VR Controls 0x03 Virtual reality devices and controls.
Sports Controls 0x04 Controls for sports equipment and games.
Game Controls 0x05 Controls for gamepads and gaming devices.
Keyboard/Keypad 0x07 Standard keyboard keys and related inputs.
LEDS 0x08 LED indicators, often used in keyboards (e.g., Caps Lock, Num Lock).
Button 0x09 Generic buttons (used by gamepads, mice, etc.).
Consumer 0x0C Consumer devices (like volume controls, media buttons).
Digitizer 0x0D Controls for digitizers, touch screens, and stylus devices.
Alphanumeric Display 0x14 Controls for alphanumeric displays.

2. Common Usages

  • Usages define specific controls within a Usage Page.
  • Each Usage has an associated ID within its Usage Page.

Generic Desktop (0x01)

Usage ID (Hex) Description
Pointer 0x01 General pointer device, often a mouse.
Mouse 0x02 Mouse device.
Joystick 0x04 Joystick controller.
Gamepad 0x05 Gamepad or controller.
Keyboard 0x06 Keyboard device.
X 0x30 X-axis of a joystick or mouse.
Y 0x31 Y-axis of a joystick or mouse.
Z 0x32 Z-axis (forward/backward)
Rx 0x33 Rotation around X-axis (tilt)
Ry 0x34 Rotation around Y-axis (turning)
Rz 0x35 Rotation around Z-axis (twisting)
Slider 0x36 Linear movement (e.g., throttle).
Dial 0x37 Rotation for dials (continuous).
Wheel 0x38 Wheel rotation (e.g., steering wheel).
Hat switch 0x39 Directional hat switch

Button (0x09)

  • This Usage Page is straightforward and represents individual button presses, typically used for game controllers, mice, and other devices with buttons.
  • Each button has an ID like 0x01, 0x02, etc., up to the number of buttons needed.

Consumer (0x0C)

  • This Usage Page includes controls for media and consumer electronics.
Usage ID (Hex) Description
Volume Up 0xE9 Increase volume
Volume Down 0xEA Decrease volume
Mute 0xE2 Mute audio
Play/Pause 0xCD Play/pause toggle
Stop 0xB7 Stop playback
Next Track 0xB5 Skip to the next track
Previous Track 0xB6 Go to the previous track

Simulation Controls (0x02)

Usage ID (Hex) Description
Flight Control Stick 0x20 Basic flight control stick.
Auto-Pilot Enable 0x44 Auto-pilot toggle.
Throttle 0xBB Throttle control.

3. HID Report Descriptor Examples

Here’s how you might define some of these usages in your descriptor:

  • Gamepad with X, Y, Z Axes:

    0x05, 0x01,       // Usage Page (Generic Desktop)
    0x09, 0x04,       // Usage (Joystick)
    0xA1, 0x01,       // Collection (Application)
      0x15, 0x81,     // Logical Minimum (-127)
      0x25, 0x7F,     // Logical Maximum (127)
      0x75, 0x08,     // Report Size (8 bits)
      0x95, 0x03,     // Report Count (3)
      0x09, 0x30,     // Usage (X)
      0x09, 0x31,     // Usage (Y)
      0x09, 0x32,     // Usage (Z)
      0x81, 0x02,     // Input (Data, Variable, Absolute)
    0xC0              // End Collection
  • Gamepad with Rx, Ry, Rz Axes for Rotation:

    0x05, 0x01,       // Usage Page (Generic Desktop)
    0x09, 0x05,       // Usage (Gamepad)
    0xA1, 0x01,       // Collection (Application)
      0x15, 0x81,     // Logical Minimum (-127)
      0x25, 0x7F,     // Logical Maximum (127)
      0x75, 0x08,     // Report Size (8 bits)
      0x95, 0x03,     // Report Count (3)
      0x09, 0x33,     // Usage (Rx)
      0x09, 0x34,     // Usage (Ry)
      0x09, 0x35,     // Usage (Rz)
      0x81, 0x02,     // Input (Data, Variable, Absolute)
    0xC0              // End Collection

These descriptors should give you a lot of flexibility in defining a wide variety of controls. Let me know if you need help with specific configurations!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment