machine/usb/descriptor: refactor HID report creation

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2023-04-28 21:22:46 +02:00
committed by Ron Evans
parent e4da35486b
commit d8ee520bdc
3 changed files with 263 additions and 116 deletions
+62 -50
View File
@@ -68,56 +68,68 @@ var ClassHIDJoystick = ClassHIDType{
data: classHIDJoystick[:],
}
var JoystickDefaultHIDReport = []byte{
0x05, 0x01, // Usage page
0x09, 0x04, // Joystick
0xa1, 0x01, // COLLECTION (Application)
0x85, 0x01, // REPORT_ID (1)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x10, // USAGE_MAXIMUM (Button 16)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x10, // REPORT_COUNT (16)
0x55, 0x00, // Unit Exponent (-16)
0x65, 0x00, // Unit (0x00)
0x81, 0x02, // INPUT (Data/Var/Abs)
0x05, 0x01, // USAGE_PAGE (Generic Desktop Controls)
0x09, 0x39, // USAGE(Hat Switch)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x07, // LOGICAL_MAXIMUM (7)
0x35, 0x00, // PHYSICAL_MINIMUM (0)
0x46, 0x3b, 0x01, // PHYSICAL_MAXIMUM(315)
0x65, 0x14, // UNIT (Eng Rot:Angular Pos)
0x75, 0x04, // REPORT_SIZE (4)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data/Var/Abs)
0x09, 0x39, // USAGE(Hat Switch)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x07, // LOGICAL_MAXIMUM (7)
0x35, 0x00, // PHYSICAL_MINIMUM (0)
0x46, 0x3b, 0x01, // PHYSICAL_MAXIMUM(315)
0x65, 0x14, // UNIT (Eng Rot:Angular Pos)
0x75, 0x04, // REPORT_SIZE (4)
0x95, 0x01, // REPORT_COUNT (1)
0x81, 0x02, // INPUT (Data/Var/Abs)
0x09, 0x01, // USAGE (Pointer)
0x16, 0x01, 0x80, // LOGICAL_MINIMUM (-32767)
0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
0x75, 0x10, // REPORT_SIZE (16bits)
0x95, 0x06, // REPORT_COUNT (6)
0xa1, 0x00, // COLLECTION (Physical)
0x09, 0x30, // USAGE(X)
0x09, 0x31, // USAGE(Y)
0x09, 0x32, // USAGE(Z)
0x09, 0x33, // USAGE(RX)
0x09, 0x34, // USAGE(RY)
0x09, 0x35, // USAGE(RZ)
0x81, 0x02, // INPUT (Data/Var/Abs)
0xc0, // END_COLLECTION
0xc0, // END_COLLECTION
}
var JoystickDefaultHIDReport = appendSlices([][]byte{
HIDUsagePageGenericDesktop,
HIDUsageDesktopJoystick,
HIDCollectionApplication,
HIDReportID(1),
HIDUsagePageButton,
HIDUsageMinimum(1),
HIDUsageMaximum(16),
HIDLogicalMinimum(0),
HIDLogicalMaximum(1),
HIDReportSize(1),
HIDReportCount(16),
HIDInputDataVarAbs,
HIDReportCount(1),
HIDReportSize(3),
[]byte{
0x55, 0x00, // Unit Exponent (-16)
0x65, 0x00, // Unit (0x00)
},
HIDInputDataVarAbs,
HIDUsagePageGenericDesktop,
HIDUsageDesktopHatSwitch,
HIDLogicalMinimum(0),
HIDLogicalMaximum(7),
[]byte{
0x35, 0x00, // PHYSICAL_MINIMUM (0)
0x46, 0x3b, 0x01, // PHYSICAL_MAXIMUM(315)
0x65, 0x14, // UNIT (Eng Rot:Angular Pos)
},
HIDReportCount(1),
HIDReportSize(4),
HIDInputDataVarAbs,
HIDUsageDesktopHatSwitch,
HIDLogicalMinimum(0),
HIDLogicalMaximum(7),
[]byte{
0x35, 0x00, // PHYSICAL_MINIMUM (0)
0x46, 0x3b, 0x01, // PHYSICAL_MAXIMUM(315)
0x65, 0x14, // UNIT (Eng Rot:Angular Pos)
},
HIDReportCount(1),
HIDReportSize(4),
HIDInputDataVarAbs,
HIDUsageDesktopPointer,
[]byte{
0x16, 0x01, 0x80, // LOGICAL_MINIMUM (-32767)
0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
},
HIDReportCount(6),
HIDReportSize(16),
HIDCollectionPhysical,
HIDUsageDesktopX,
HIDUsageDesktopY,
HIDUsageDesktopZ,
HIDUsageDesktopRx,
HIDUsageDesktopRy,
HIDUsageDesktopRz,
HIDInputDataVarAbs,
HIDEndCollection,
HIDEndCollection,
})
// CDCJoystick requires that you append the JoystickDescriptor
// to the Configuration before using. This is in order to support