HID-RP Example#
This example shows how to use the
hid-rp library which is
bundled into the hid-rp component within espp.
It provides an example of a somewhat configurable HID Gamepad using the
esppp::GamepadReport<> template class.
How to use example#
Hardware Required#
This example should run on any ESP32s3 development board as it requires no peripheral connections.
Build and Flash#
Build the project and flash it to the board, then run monitor tool to view serial output:
idf.py -p PORT flash monitor
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type Ctrl-].)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
Example Output#
Generated report descriptor:
0x5, 0x1, 0x9, 0x5, 0xa1, 0x1, 0x85, 0x1, 0x9, 0x1, 0xa1, 0x0, 0x9, 0x30, 0x9, 0x31, 0x15, 0x0, 0x27, 0xff, 0xff, 0x0, 0x0, 0x95, 0x2, 0x75, 0x10, 0x81, 0x2, 0xc0, 0x9, 0x1, 0xa1, 0x0, 0x9, 0x32, 0x9, 0x35, 0x15, 0x0, 0x27, 0xff, 0xff, 0x0, 0x0, 0x95, 0x2, 0x75, 0x10, 0x81, 0x2, 0xc0, 0x5, 0x2, 0x9, 0xc5, 0x15, 0x0, 0x26, 0xff, 0x3, 0x95, 0x1, 0x75, 0xa, 0x81, 0x2, 0x15, 0x0, 0x25, 0x0, 0x95, 0x1, 0x75, 0x6, 0x81, 0x1, 0x5, 0x2, 0x9, 0xc4, 0x15, 0x0, 0x26, 0xff, 0x3, 0x95, 0x1, 0x75, 0xa, 0x81, 0x2, 0x15, 0x0, 0x25, 0x0, 0x95, 0x1, 0x75, 0x6, 0x81, 0x1, 0x5, 0x1, 0x9, 0x39, 0x15, 0x1, 0x25, 0x8, 0x35, 0x0, 0x46, 0x3b, 0x1, 0x66, 0x14, 0x0, 0x75, 0x4, 0x95, 0x1, 0x81, 0x42, 0x15, 0x0, 0x25, 0x0, 0x35, 0x0, 0x45, 0x0, 0x65, 0x0, 0x55, 0x0, 0x95, 0x1, 0x75, 0x4, 0x81, 0x1, 0x5, 0x9, 0x19, 0x1, 0x29, 0xf, 0x15, 0x0, 0x25, 0x1, 0x75, 0x1, 0x95, 0xf, 0x81, 0x2, 0x15, 0x0, 0x25, 0x0, 0x95, 0x1, 0x75, 0x1, 0x81, 0x1, 0x5, 0xc, 0xa, 0xb2, 0x0, 0x15, 0x0, 0x25, 0x1, 0x95, 0x1, 0x75, 0x1, 0x81, 0x2, 0x15, 0x0, 0x25, 0x0, 0x95, 0x1, 0x75, 0x7, 0x81, 0x1, 0x5, 0xf, 0x9, 0x21, 0x85, 0x3, 0xa1, 0x2, 0x9, 0x97, 0x15, 0x0, 0x25, 0x1, 0x75, 0x4, 0x95, 0x1, 0x91, 0x2, 0x15, 0x0, 0x25, 0x0, 0x75, 0x4, 0x95, 0x1, 0x91, 0x3, 0x9, 0x70, 0x15, 0x0, 0x25, 0x64, 0x75, 0x8, 0x95, 0x4, 0x91, 0x2, 0x9, 0x50, 0x66, 0x1, 0x10, 0x55, 0xe, 0x15, 0x0, 0x26, 0xff, 0x0, 0x75, 0x8, 0x95, 0x1, 0x91, 0x2, 0x9, 0xa7, 0x15, 0x0, 0x26, 0xff, 0x0, 0x75, 0x8, 0x95, 0x1, 0x91, 0x2, 0x65, 0x0, 0x55, 0x0, 0x9, 0x7c, 0x15, 0x0, 0x26, 0xff, 0x0, 0x75, 0x8, 0x95, 0x1, 0x91, 0x2, 0xc0, 0x85, 0x4, 0x9, 0x20, 0x85, 0x4, 0x15, 0x0, 0x26, 0xff, 0x0, 0x75, 0x8, 0x95, 0x1, 0x9, 0x20, 0x81, 0x2, 0x85, 0x2, 0x5, 0x8, 0x19, 0x61, 0x29, 0x64, 0x15, 0x0, 0x25, 0x1, 0x75, 0x1, 0x95, 0x4, 0x91, 0x2, 0x95, 0x1, 0x75, 0x4, 0x91, 0x1, 0xc0
Parsed by https://eleccelerator.com/usbdescreqparser/ :
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x05, // Usage (Game Pad)
0xA1, 0x01, // Collection (Application)
0x85, 0x01, // Report ID (1)
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65534)
0x95, 0x02, // Report Count (2)
0x75, 0x10, // Report Size (16)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x09, 0x32, // Usage (Z)
0x09, 0x35, // Usage (Rz)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xFF, 0xFF, 0x00, 0x00, // Logical Maximum (65534)
0x95, 0x02, // Report Count (2)
0x75, 0x10, // Report Size (16)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0xC0, // End Collection
0x05, 0x02, // Usage Page (Sim Ctrls)
0x09, 0xC5, // Usage (Brake)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x03, // Logical Maximum (1023)
0x95, 0x01, // Report Count (1)
0x75, 0x0A, // Report Size (10)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x00, // Logical Maximum (0)
0x95, 0x01, // Report Count (1)
0x75, 0x06, // Report Size (6)
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x05, 0x02, // Usage Page (Sim Ctrls)
0x09, 0xC4, // Usage (Accelerator)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x03, // Logical Maximum (1023)
0x95, 0x01, // Report Count (1)
0x75, 0x0A, // Report Size (10)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x00, // Logical Maximum (0)
0x95, 0x01, // Report Count (1)
0x75, 0x06, // Report Size (6)
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x39, // Usage (Hat switch)
0x15, 0x01, // Logical Minimum (1)
0x25, 0x08, // Logical Maximum (8)
0x35, 0x00, // Physical Minimum (0)
0x46, 0x3B, 0x01, // Physical Maximum (315)
0x66, 0x14, 0x00, // Unit (System: English Rotation, Length: Centimeter)
0x75, 0x04, // Report Size (4)
0x95, 0x01, // Report Count (1)
0x81, 0x42, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x00, // Logical Maximum (0)
0x35, 0x00, // Physical Minimum (0)
0x45, 0x00, // Physical Maximum (0)
0x65, 0x00, // Unit (None)
0x55, 0x00, // Unit Exponent (0)
0x95, 0x01, // Report Count (1)
0x75, 0x04, // Report Size (4)
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (0x01)
0x29, 0x0F, // Usage Maximum (0x0F)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x75, 0x01, // Report Size (1)
0x95, 0x0F, // Report Count (15)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x00, // Logical Maximum (0)
0x95, 0x01, // Report Count (1)
0x75, 0x01, // Report Size (1)
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x05, 0x0C, // Usage Page (Consumer)
0x0A, 0xB2, 0x00, // Usage (Record)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x95, 0x01, // Report Count (1)
0x75, 0x01, // Report Size (1)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x00, // Logical Maximum (0)
0x95, 0x01, // Report Count (1)
0x75, 0x07, // Report Size (7)
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x05, 0x0F, // Usage Page (PID Page)
0x09, 0x21, // Usage (0x21)
0x85, 0x03, // Report ID (3)
0xA1, 0x02, // Collection (Logical)
0x09, 0x97, // Usage (0x97)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x75, 0x04, // Report Size (4)
0x95, 0x01, // Report Count (1)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x00, // Logical Maximum (0)
0x75, 0x04, // Report Size (4)
0x95, 0x01, // Report Count (1)
0x91, 0x03, // Output (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x09, 0x70, // Usage (0x70)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x64, // Logical Maximum (100)
0x75, 0x08, // Report Size (8)
0x95, 0x04, // Report Count (4)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x09, 0x50, // Usage (0x50)
0x66, 0x01, 0x10, // Unit (System: SI Linear, Time: Seconds)
0x55, 0x0E, // Unit Exponent (-2)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x09, 0xA7, // Usage (0xA7)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x65, 0x00, // Unit (None)
0x55, 0x00, // Unit Exponent (0)
0x09, 0x7C, // Usage (0x7C)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, // End Collection
0x85, 0x04, // Report ID (4)
0x09, 0x20, // Usage (0x20)
0x85, 0x04, // Report ID (4)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x09, 0x20, // Usage (0x20)
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
0x85, 0x02, // Report ID (2)
0x05, 0x08, // Usage Page (LEDs)
0x19, 0x61, // Usage Minimum (0x61)
0x29, 0x64, // Usage Maximum (0x64)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x75, 0x01, // Report Size (1)
0x95, 0x04, // Report Count (4)
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0x95, 0x01, // Report Count (1)
0x75, 0x04, // Report Size (4)
0x91, 0x01, // Output (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
0xC0, // End Collection
// 328 bytes