@@ -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 () {
@@ -276,8 +288,11 @@ func handleStandardSetup(setup usb.Setup) bool {
276288
277289 case usb .SET_CONFIGURATION :
278290 if setup .BmRequestType & usb .REQUEST_RECIPIENT == usb .REQUEST_DEVICE {
279- for i := 1 ; i < len (endPoints ); i ++ {
280- initEndpoint (uint32 (i ), endPoints [i ])
291+ for _ , entry := range endPoints {
292+ if entry .Endpoint == usb .CONTROL_ENDPOINT {
293+ continue
294+ }
295+ initEndpoint (uint32 (entry .Endpoint ), entry .Config )
281296 }
282297
283298 usbConfiguration = setup .WValueL
@@ -358,12 +373,18 @@ func ConfigureUSBEndpoint(desc descriptor.Descriptor, epSettings []usb.EndpointC
358373
359374 for _ , ep := range epSettings {
360375 if ep .IsIn {
361- endPoints [ep .Index ] = uint32 (ep .Type | usb .EndpointIn )
376+ endPoints = append (endPoints , usbEndpointEntry {
377+ Endpoint : uint32 (ep .Index ),
378+ Config : uint32 (ep .Type | usb .EndpointIn ),
379+ })
362380 if ep .TxHandler != nil {
363381 usbTxHandler [ep .Index ] = ep .TxHandler
364382 }
365383 } else {
366- endPoints [ep .Index ] = uint32 (ep .Type | usb .EndpointOut )
384+ endPoints = append (endPoints , usbEndpointEntry {
385+ Endpoint : uint32 (ep .Index ),
386+ Config : uint32 (ep .Type | usb .EndpointOut ),
387+ })
367388 if ep .RxHandler != nil {
368389 usbRxHandler [ep .Index ] = func (b []byte ) bool {
369390 ep .RxHandler (b )
0 commit comments