File tree Expand file tree Collapse file tree 2 files changed +18
-16
lines changed Expand file tree Collapse file tree 2 files changed +18
-16
lines changed Original file line number Diff line number Diff line change @@ -169,21 +169,22 @@ func initEndpoint(ep, config uint32) {
169169}
170170
171171func handleUSBSetAddress (setup usb.Setup ) bool {
172- sendUSBPacket (0 , []byte {}, 0 )
172+ // Using 570μs timeout which is exactly the same as SAMD21.
173+ const ackTimeout = 570
173174
174- // last, set the device address to that requested by host
175- // wait for transfer to complete
176- timeout := 3000
177175 rp .USBCTRL_REGS .SIE_STATUS .Set (rp .USBCTRL_REGS_SIE_STATUS_ACK_REC )
176+ sendUSBPacket (0 , []byte {}, 0 )
177+
178+ // Wait for transfer to complete with a timeout.
179+ t := timer .timeElapsed ()
178180 for (rp .USBCTRL_REGS .SIE_STATUS .Get () & rp .USBCTRL_REGS_SIE_STATUS_ACK_REC ) == 0 {
179- timeout --
180- if timeout == 0 {
181- return true
181+ if dt := timer .timeElapsed () - t ; dt >= ackTimeout {
182+ return false
182183 }
183184 }
184185
186+ // Set the device address to that requested by host.
185187 rp .USBCTRL_REGS .ADDR_ENDP .Set (uint32 (setup .WValueL ) & rp .USBCTRL_REGS_ADDR_ENDP_ADDRESS_Msk )
186-
187188 return true
188189}
189190
Original file line number Diff line number Diff line change @@ -172,21 +172,22 @@ func initEndpoint(ep, config uint32) {
172172}
173173
174174func handleUSBSetAddress (setup usb.Setup ) bool {
175- sendUSBPacket ( 0 , [] byte {}, 0 )
175+ // Using 570μs timeout which is exactly the same as SAMD21.
176176
177- // last, set the device address to that requested by host
178- // wait for transfer to complete
179- timeout := 3000
177+ const ackTimeout = 570
180178 rp .USB .SIE_STATUS .Set (rp .USB_SIE_STATUS_ACK_REC )
179+ sendUSBPacket (0 , []byte {}, 0 )
180+
181+ // Wait for transfer to complete with a timeout.
182+ t := timer .timeElapsed ()
181183 for (rp .USB .SIE_STATUS .Get () & rp .USB_SIE_STATUS_ACK_REC ) == 0 {
182- timeout --
183- if timeout == 0 {
184- return true
184+ if dt := timer .timeElapsed () - t ; dt >= ackTimeout {
185+ return false
185186 }
186187 }
187188
189+ // Set the device address to that requested by host.
188190 rp .USB .ADDR_ENDP .Set (uint32 (setup .WValueL ) & rp .USB_ADDR_ENDP_ADDRESS_Msk )
189-
190191 return true
191192}
192193
You can’t perform that action at this time.
0 commit comments