File tree 2 files changed +18
-16
lines changed 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) {
169
169
}
170
170
171
171
func 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
173
174
174
- // last, set the device address to that requested by host
175
- // wait for transfer to complete
176
- timeout := 3000
177
175
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 ()
178
180
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
182
183
}
183
184
}
184
185
186
+ // Set the device address to that requested by host.
185
187
rp .USBCTRL_REGS .ADDR_ENDP .Set (uint32 (setup .WValueL ) & rp .USBCTRL_REGS_ADDR_ENDP_ADDRESS_Msk )
186
-
187
188
return true
188
189
}
189
190
Original file line number Diff line number Diff line change @@ -172,21 +172,22 @@ func initEndpoint(ep, config uint32) {
172
172
}
173
173
174
174
func handleUSBSetAddress (setup usb.Setup ) bool {
175
- sendUSBPacket ( 0 , [] byte {}, 0 )
175
+ // Using 570μs timeout which is exactly the same as SAMD21.
176
176
177
- // last, set the device address to that requested by host
178
- // wait for transfer to complete
179
- timeout := 3000
177
+ const ackTimeout = 570
180
178
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 ()
181
183
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
185
186
}
186
187
}
187
188
189
+ // Set the device address to that requested by host.
188
190
rp .USB .ADDR_ENDP .Set (uint32 (setup .WValueL ) & rp .USB_ADDR_ENDP_ADDRESS_Msk )
189
-
190
191
return true
191
192
}
192
193
You can’t perform that action at this time.
0 commit comments