Skip to content

Instantly share code, notes, and snippets.

@wereii
Last active January 11, 2024 20:19
Show Gist options
  • Save wereii/b215c799a267af10154087b5d5af3a6b to your computer and use it in GitHub Desktop.
Save wereii/b215c799a267af10154087b5d5af3a6b to your computer and use it in GitHub Desktop.
Very Simple Gamepad HID Descriptor
//simple_gamepad_hid.h
#define REPORT_BYTE_LENGTH 4 // (8 + 16 + 8) / 8
char ReportDescriptor[44] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x05, // USAGE (Game Pad)
0xa1, 0x01, // COLLECTION (Application)
0xa1, 0x00, // COLLECTION (Physical)
// ReportID - 8 bits
0x85, 0x01, // REPORT_ID (1)
// X & Y - 2x8 = 16 bits
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x15, 0x81, // LOGICAL_MINIMUM (-127)
0x25, 0x7f, // LOGICAL_MAXIMUM (127)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data,Var,Abs)
// Buttons - 8 bits
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x08, // REPORT_SIZE (8)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
};
@nomadesys
Copy link

Hi, could you tell me where to find an example of gamapad for stm32F103
Thanks!!!

@CallumCottrell
Copy link

I believe the button's report size and report count should be switched - youve indicated 1 button, with 8 bytes of data. Really it should be 8 buttons over 1 byte of data

@kolaha99
Copy link

kolaha99 commented Jan 17, 2022

0x15, 0x81, // LOGICAL_MINIMUM (-127)
better:
0x15, 0x80, // LOGICAL_MINIMUM (-128)

@Ugobyte
Copy link

Ugobyte commented Sep 22, 2022

How do you make the Joystick X & Y axes output floating point values?
Your description has the minimum and maximum values at: -128 and 127. However, most games are expecting -1.00 to 1.00.

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