usb keyboard


usb mouse


usb joystick

code char JoystickReportDesc[HID_REPORT_DESCRIPTOR_SIZE_JOYSTICK] = 
{
0x05, 0x01, //Usage Page(Generic Desktop)
0x09, 0x04, //Usage (Joystick)
0xA1, 0x01, //Collection (Application)
0x09, 0x01, //Usage (Pointer)
0xA1, 0x00, //Collection (Physical)
0x05, 0x01, //Usage Page(Generic Desktop)
0x09, 0x30, //Usage (X)
0x09, 0x31, //Usage (Y)
0x09, 0x32, //Usage (Z)
0x09, 0x35, //Usage (Rz)
0x15, 0x00, //Logical Minmum (0)
0x26, 0xFF, 0x00, //Logical Maxmum (255)
0x35, 0x00, //Physical Minmum (0)
0x46, 0xFF, 0x00, //Physical Maxmum (255)
0x65, 0x00, //Unit (0)
0x75, 0x08, //Report Size (8)
0x95, 0x04, //Report Count (4)
0x81, 0x02, //Input (Data, Variable, Absolute, No Wrap, Linear, Preferred State, No Null Position, Bitfileld)

0x09, 0x39, //Usage (Hat Switch)
0x15, 0x01, //Logical Minmum (1)
0x25, 0x08, //Logical Maxmum (8)
0x35, 0x00, //Physical Minmum (0)
0x46, 0x3B, 0x01,//Physical Maxmum (315)
0x65, 0x14, //Unit (20)
0x75, 0x08, //Report Size (8)
0x95, 0x01, //Report Count(1)
0x81, 0x02, //Input (Data, Variable, Absolute, No Wrap, Linear, Preferred State, No Null Position, Bitfileld)

0x05, 0x09, //Usage Page (Button)
0x19, 0x01, //Usage Minmum (1)
0x29, 0x0C, //Usage Maxmum (12)
0x15, 0x00, //Logical Minmum (0)
0x25, 0x01, //Logical Maxmum (1)
0x35, 0x00, //Physical Minmum (0)
0x45, 0x01, //Physical Maxmum (1)
0x75, 0x01, //Report Size (1)
0x95, 0x0C, //Report Count(12)
0x81, 0x02, //Input (Data, Variable, Absolute, No Wrap, Linear, Preferred State, No Null Position, Bitfileld)

0x75, 0x01, //Report Size (1)
0x95, 0x0C, //Report Count(12)
0x81, 0x01, //Input (Constant, Array, Absolute)

0xC0, // End Collection
0xC0 //End Collection
};

上面这段report descriptor可以看出在usb endpoint上内容的字节组成
X,一个字节
Y,一个字节
Z,一个字节
Rz,一个字节
hat switch,一个字节
button,12bit
constant填充,12bit


参考文章

  1. ​Parsing USB joystick HID data​
  2. 2.