github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/usb/descriptor/joystick.go (about) 1 package descriptor 2 3 var deviceJoystick = [deviceTypeLen]byte{ 4 deviceTypeLen, 5 TypeDevice, 6 0x00, 0x02, // USB version 7 0xef, // device class 8 0x02, // subclass 9 0x01, // protocol 10 0x40, // maxpacketsize 11 0x41, 0x23, // vendor id 12 0x36, 0x80, // product id 13 0x00, 0x01, // device 14 0x01, // manufacturer 15 0x02, // product 16 0x03, // SerialNumber 17 0x01, // NumConfigurations 18 } 19 20 var DeviceJoystick = DeviceType{ 21 data: deviceJoystick[:], 22 } 23 24 var configurationCDCJoystick = [configurationTypeLen]byte{ 25 configurationTypeLen, 26 TypeConfiguration, 27 0x6b, 0x00, // adjust length as needed 28 0x03, // number of interfaces 29 0x01, // configuration value 30 0x00, // index to string description 31 0xa0, // attributes 32 0xfa, // maxpower 33 } 34 35 var ConfigurationCDCJoystick = ConfigurationType{ 36 data: configurationCDCJoystick[:], 37 } 38 39 var interfaceHIDJoystick = [interfaceTypeLen]byte{ 40 interfaceTypeLen, 41 TypeInterface, 42 0x02, // InterfaceNumber 43 0x00, // AlternateSetting 44 0x02, // NumEndpoints 45 0x03, // InterfaceClass 46 0x00, // InterfaceSubClass 47 0x00, // InterfaceProtocol 48 0x00, // Interface 49 } 50 51 var InterfaceHIDJoystick = InterfaceType{ 52 data: interfaceHIDJoystick[:], 53 } 54 55 var classHIDJoystick = [ClassHIDTypeLen]byte{ 56 ClassHIDTypeLen, 57 TypeClassHID, 58 0x11, // HID version L 59 0x01, // HID version H 60 0x00, // CountryCode 61 0x01, // NumDescriptors 62 0x22, // ClassType 63 0x00, // ClassLength L 64 0x00, // ClassLength H 65 } 66 67 var ClassHIDJoystick = ClassHIDType{ 68 data: classHIDJoystick[:], 69 } 70 71 var JoystickDefaultHIDReport = Append([][]byte{ 72 HIDUsagePageGenericDesktop, 73 HIDUsageDesktopJoystick, 74 HIDCollectionApplication, 75 HIDReportID(1), 76 HIDUsagePageButton, 77 HIDUsageMinimum(1), 78 HIDUsageMaximum(16), 79 HIDLogicalMinimum(0), 80 HIDLogicalMaximum(1), 81 HIDReportSize(1), 82 HIDReportCount(16), 83 HIDUnitExponent(0), 84 HIDUnit(0), 85 HIDInputDataVarAbs, 86 87 HIDUsagePageGenericDesktop, 88 HIDUsageDesktopHatSwitch, 89 HIDLogicalMinimum(0), 90 HIDLogicalMaximum(7), 91 HIDPhysicalMinimum(0), 92 HIDPhysicalMaximum(315), 93 HIDUnit(0x14), 94 HIDReportCount(1), 95 HIDReportSize(4), 96 HIDInputDataVarAbs, 97 HIDUsageDesktopHatSwitch, 98 HIDLogicalMinimum(0), 99 HIDLogicalMaximum(7), 100 HIDPhysicalMinimum(0), 101 HIDPhysicalMaximum(315), 102 HIDUnit(0x14), 103 HIDReportCount(1), 104 HIDReportSize(4), 105 HIDInputDataVarAbs, 106 HIDUsageDesktopPointer, 107 HIDLogicalMinimum(-32767), 108 HIDLogicalMaximum(32767), 109 HIDReportCount(6), 110 HIDReportSize(16), 111 HIDCollectionPhysical, 112 HIDUsageDesktopX, 113 HIDUsageDesktopY, 114 HIDUsageDesktopZ, 115 HIDUsageDesktopRx, 116 HIDUsageDesktopRy, 117 HIDUsageDesktopRz, 118 HIDInputDataVarAbs, 119 HIDCollectionEnd, 120 HIDCollectionEnd, 121 }) 122 123 // CDCJoystick requires that you append the JoystickDescriptor 124 // to the Configuration before using. This is in order to support 125 // custom configurations. 126 var CDCJoystick = Descriptor{ 127 Device: DeviceJoystick.Bytes(), 128 Configuration: Append([][]byte{ 129 ConfigurationCDCJoystick.Bytes(), 130 InterfaceAssociationCDC.Bytes(), 131 InterfaceCDCControl.Bytes(), 132 ClassSpecificCDCHeader.Bytes(), 133 ClassSpecificCDCACM.Bytes(), 134 ClassSpecificCDCUnion.Bytes(), 135 ClassSpecificCDCCallManagement.Bytes(), 136 EndpointEP1IN.Bytes(), 137 InterfaceCDCData.Bytes(), 138 EndpointEP2OUT.Bytes(), 139 EndpointEP3IN.Bytes(), 140 InterfaceHIDJoystick.Bytes(), 141 ClassHIDJoystick.Bytes(), 142 EndpointEP4IN.Bytes(), 143 EndpointEP5OUT.Bytes(), 144 }), 145 HID: map[uint16][]byte{}, 146 }