File tree 1 file changed +6
-8
lines changed 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -169,21 +169,19 @@ func initEndpoint(ep, config uint32) {
169
169
}
170
170
171
171
func handleUSBSetAddress (setup usb.Setup ) bool {
172
+ rp .USBCTRL_REGS .SIE_STATUS .Set (rp .USBCTRL_REGS_SIE_STATUS_ACK_REC )
172
173
sendUSBPacket (0 , []byte {}, 0 )
173
-
174
174
// last, set the device address to that requested by host
175
175
// wait for transfer to complete
176
- timeout := 3000
177
- rp .USBCTRL_REGS .SIE_STATUS .Set (rp .USBCTRL_REGS_SIE_STATUS_ACK_REC )
176
+ start := rp .TIMER .TIMERAWL .Get ()
178
177
for (rp .USBCTRL_REGS .SIE_STATUS .Get () & rp .USBCTRL_REGS_SIE_STATUS_ACK_REC ) == 0 {
179
- timeout --
180
- if timeout == 0 {
181
- return true
178
+ current := rp .TIMER .TIMERAWL .Get ()
179
+ elapsed := current - start //Avoiding overflow in unsigned integer subtraction.
180
+ if elapsed >= 570 {//exactly the same time as SAMD21.
181
+ return false
182
182
}
183
183
}
184
-
185
184
rp .USBCTRL_REGS .ADDR_ENDP .Set (uint32 (setup .WValueL ) & rp .USBCTRL_REGS_ADDR_ENDP_ADDRESS_Msk )
186
-
187
185
return true
188
186
}
189
187
You can’t perform that action at this time.
0 commit comments