File tree 1 file changed +9
-10
lines changed 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -172,21 +172,20 @@ func initEndpoint(ep, config uint32) {
172
172
}
173
173
174
174
func handleUSBSetAddress (setup usb.Setup ) bool {
175
+ rp .USB .SIE_STATUS .Set (rp .USB_SIE_STATUS_ACK_REC )
175
176
sendUSBPacket (0 , []byte {}, 0 )
176
177
177
- // last, set the device address to that requested by host
178
- // wait for transfer to complete
179
- timeout := 3000
180
- rp .USB .SIE_STATUS .Set (rp .USB_SIE_STATUS_ACK_REC )
181
- for (rp .USB .SIE_STATUS .Get () & rp .USB_SIE_STATUS_ACK_REC ) == 0 {
182
- timeout --
183
- if timeout == 0 {
184
- return true
185
- }
178
+ // Wait for transfer to complete with a timeout.
179
+ // Using 570μs timeout which is exactly the same as SAMD21.
180
+
181
+ if ! timer .waitUntil (func () bool {
182
+ return (rp .USB .SIE_STATUS .Get () & rp .USB_SIE_STATUS_ACK_REC ) != 0
183
+ }, 570 ) {
184
+ return false
186
185
}
187
186
187
+ // Set the device address to that requested by host.
188
188
rp .USB .ADDR_ENDP .Set (uint32 (setup .WValueL ) & rp .USB_ADDR_ENDP_ADDRESS_Msk )
189
-
190
189
return true
191
190
}
192
191
You can’t perform that action at this time.
0 commit comments