@@ -14,9 +14,21 @@ type USBDevice struct {
1414 InitEndpointComplete bool
1515}
1616
17+ type usbEndpointEntry struct {
18+ Endpoint uint32
19+ Config uint32
20+ }
21+
1722var (
1823 USBDev = & USBDevice {}
1924 USBCDC Serialer
25+
26+ endPoints = []usbEndpointEntry {
27+ {
28+ Endpoint : usb .CONTROL_ENDPOINT ,
29+ Config : usb .ENDPOINT_TYPE_CONTROL ,
30+ },
31+ }
2032)
2133
2234func initUSB () {
@@ -277,8 +289,11 @@ func handleStandardSetup(setup usb.Setup) bool {
277289
278290 case usb .SET_CONFIGURATION :
279291 if setup .BmRequestType & usb .REQUEST_RECIPIENT == usb .REQUEST_DEVICE {
280- for i := 1 ; i < len (endPoints ); i ++ {
281- initEndpoint (uint32 (i ), endPoints [i ])
292+ for _ , entry := range endPoints {
293+ if entry .Endpoint == usb .CONTROL_ENDPOINT {
294+ continue
295+ }
296+ initEndpoint (uint32 (entry .Endpoint ), entry .Config )
282297 }
283298
284299 usbConfiguration = setup .WValueL
@@ -359,12 +374,18 @@ func ConfigureUSBEndpoint(desc descriptor.Descriptor, epSettings []usb.EndpointC
359374
360375 for _ , ep := range epSettings {
361376 if ep .IsIn {
362- endPoints [ep .Index ] = uint32 (ep .Type | usb .EndpointIn )
377+ endPoints = append (endPoints , usbEndpointEntry {
378+ Endpoint : uint32 (ep .Index ),
379+ Config : uint32 (ep .Type | usb .EndpointIn ),
380+ })
363381 if ep .TxHandler != nil {
364382 usbTxHandler [ep .Index ] = ep .TxHandler
365383 }
366384 } else {
367- endPoints [ep .Index ] = uint32 (ep .Type | usb .EndpointOut )
385+ endPoints = append (endPoints , usbEndpointEntry {
386+ Endpoint : uint32 (ep .Index ),
387+ Config : uint32 (ep .Type | usb .EndpointOut ),
388+ })
368389 if ep .RxHandler != nil {
369390 usbRxHandler [ep .Index ] = func (b []byte ) bool {
370391 ep .RxHandler (b )
0 commit comments