@@ -204,6 +204,12 @@ impl<B: UsbBus> UsbDevice<'_, B> {
204
204
205
205
// Pending events for endpoint 0?
206
206
if ( eps & 1 ) != 0 {
207
+ usb_debug ! (
208
+ "EP0: setup={}, in={}, out={}" ,
209
+ ep_setup & 1 ,
210
+ ep_in_complete & 1 ,
211
+ ep_out & 1
212
+ ) ;
207
213
// Handle EP0-IN conditions first. When both EP0-IN and EP0-OUT have completed,
208
214
// it is possible that EP0-OUT is a zero-sized out packet to complete the STATUS
209
215
// phase of the control transfer. We have to process EP0-IN first to update our
@@ -230,6 +236,10 @@ impl<B: UsbBus> UsbDevice<'_, B> {
230
236
None
231
237
} ;
232
238
239
+ if let Some ( _req) = req {
240
+ usb_trace ! ( "Handling EP0 request: {_req}" ) ;
241
+ }
242
+
233
243
match req {
234
244
Some ( req) if req. direction == UsbDirection :: In => {
235
245
self . control_in ( classes, req)
@@ -250,18 +260,21 @@ impl<B: UsbBus> UsbDevice<'_, B> {
250
260
for i in 1 ..MAX_ENDPOINTS {
251
261
if ( ep_setup & bit) != 0 {
252
262
for cls in classes. iter_mut ( ) {
263
+ usb_trace ! ( "Handling EP{i}-SETUP" ) ;
253
264
cls. endpoint_setup ( EndpointAddress :: from_parts (
254
265
i,
255
266
UsbDirection :: Out ,
256
267
) ) ;
257
268
}
258
269
} else if ( ep_out & bit) != 0 {
270
+ usb_trace ! ( "Handling EP{i}-OUT" ) ;
259
271
for cls in classes. iter_mut ( ) {
260
272
cls. endpoint_out ( EndpointAddress :: from_parts ( i, UsbDirection :: Out ) ) ;
261
273
}
262
274
}
263
275
264
276
if ( ep_in_complete & bit) != 0 {
277
+ usb_trace ! ( "Handling EP{i}-IN" ) ;
265
278
for cls in classes. iter_mut ( ) {
266
279
cls. endpoint_in_complete ( EndpointAddress :: from_parts (
267
280
i,
@@ -289,6 +302,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
289
302
}
290
303
PollResult :: Resume => { }
291
304
PollResult :: Suspend => {
305
+ usb_debug ! ( "Suspending bus" ) ;
292
306
self . bus . suspend ( ) ;
293
307
self . suspended_device_state = Some ( self . device_state ) ;
294
308
self . device_state = UsbDeviceState :: Suspend ;
@@ -314,6 +328,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
314
328
315
329
match ( req. recipient , req. request ) {
316
330
( Recipient :: Device , Request :: GET_STATUS ) => {
331
+ usb_trace ! ( "Processing Device::GetStatus" ) ;
317
332
let status: u16 = if self . self_powered { 0x0001 } else { 0x0000 }
318
333
| if self . remote_wakeup_enabled {
319
334
0x0002
@@ -325,12 +340,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
325
340
}
326
341
327
342
( Recipient :: Interface , Request :: GET_STATUS ) => {
343
+ usb_trace ! ( "Processing Interface::GetStatus" ) ;
328
344
let status: u16 = 0x0000 ;
329
345
330
346
let _ = xfer. accept_with ( & status. to_le_bytes ( ) ) ;
331
347
}
332
348
333
349
( Recipient :: Endpoint , Request :: GET_STATUS ) => {
350
+ usb_trace ! ( "Processing EP::GetStatus" ) ;
334
351
let ep_addr = ( ( req. index as u8 ) & 0x8f ) . into ( ) ;
335
352
336
353
let status: u16 = if self . bus . is_stalled ( ep_addr) {
@@ -343,10 +360,12 @@ impl<B: UsbBus> UsbDevice<'_, B> {
343
360
}
344
361
345
362
( Recipient :: Device , Request :: GET_DESCRIPTOR ) => {
363
+ usb_trace ! ( "Processing Device::GetDescriptor" ) ;
346
364
UsbDevice :: get_descriptor ( & self . config , classes, xfer)
347
365
}
348
366
349
367
( Recipient :: Device , Request :: GET_CONFIGURATION ) => {
368
+ usb_trace ! ( "Processing Device::GetConfiguration" ) ;
350
369
let config = match self . device_state {
351
370
UsbDeviceState :: Configured => CONFIGURATION_VALUE ,
352
371
_ => CONFIGURATION_NONE ,
@@ -356,6 +375,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
356
375
}
357
376
358
377
( Recipient :: Interface , Request :: GET_INTERFACE ) => {
378
+ usb_trace ! ( "Processing Interface::GetInterface" ) ;
359
379
// Reject interface numbers bigger than 255
360
380
if req. index > core:: u8:: MAX . into ( ) {
361
381
let _ = xfer. reject ( ) ;
@@ -381,6 +401,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
381
401
}
382
402
383
403
if self . control . waiting_for_response ( ) {
404
+ usb_debug ! ( "Rejecting control transfer because we were waiting for a response" ) ;
384
405
let _ = self . control . reject ( ) ;
385
406
}
386
407
}
@@ -409,11 +430,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
409
430
Request :: CLEAR_FEATURE ,
410
431
Request :: FEATURE_DEVICE_REMOTE_WAKEUP ,
411
432
) => {
433
+ usb_debug ! ( "Remote wakeup disabled" ) ;
412
434
self . remote_wakeup_enabled = false ;
413
435
let _ = xfer. accept ( ) ;
414
436
}
415
437
416
438
( Recipient :: Endpoint , Request :: CLEAR_FEATURE , Request :: FEATURE_ENDPOINT_HALT ) => {
439
+ usb_debug ! ( "EP{} halt removed" , req. index & 0x8f ) ;
417
440
self . bus
418
441
. set_stalled ( ( ( req. index as u8 ) & 0x8f ) . into ( ) , false ) ;
419
442
let _ = xfer. accept ( ) ;
@@ -424,17 +447,20 @@ impl<B: UsbBus> UsbDevice<'_, B> {
424
447
Request :: SET_FEATURE ,
425
448
Request :: FEATURE_DEVICE_REMOTE_WAKEUP ,
426
449
) => {
450
+ usb_debug ! ( "Remote wakeup enabled" ) ;
427
451
self . remote_wakeup_enabled = true ;
428
452
let _ = xfer. accept ( ) ;
429
453
}
430
454
431
455
( Recipient :: Endpoint , Request :: SET_FEATURE , Request :: FEATURE_ENDPOINT_HALT ) => {
456
+ usb_debug ! ( "EP{} halted" , req. index & 0x8f ) ;
432
457
self . bus
433
458
. set_stalled ( ( ( req. index as u8 ) & 0x8f ) . into ( ) , true ) ;
434
459
let _ = xfer. accept ( ) ;
435
460
}
436
461
437
462
( Recipient :: Device , Request :: SET_ADDRESS , 1 ..=127 ) => {
463
+ usb_debug ! ( "Setting device address to {}" , req. value) ;
438
464
if B :: QUIRK_SET_ADDRESS_BEFORE_STATUS {
439
465
self . bus . set_device_address ( req. value as u8 ) ;
440
466
self . device_state = UsbDeviceState :: Addressed ;
@@ -445,11 +471,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
445
471
}
446
472
447
473
( Recipient :: Device , Request :: SET_CONFIGURATION , CONFIGURATION_VALUE_U16 ) => {
474
+ usb_debug ! ( "Device configured" ) ;
448
475
self . device_state = UsbDeviceState :: Configured ;
449
476
let _ = xfer. accept ( ) ;
450
477
}
451
478
452
479
( Recipient :: Device , Request :: SET_CONFIGURATION , CONFIGURATION_NONE_U16 ) => {
480
+ usb_debug ! ( "Device deconfigured" ) ;
453
481
match self . device_state {
454
482
UsbDeviceState :: Default => {
455
483
let _ = xfer. accept ( ) ;
@@ -479,8 +507,10 @@ impl<B: UsbBus> UsbDevice<'_, B> {
479
507
480
508
// Default behaviour, if no class implementation accepted the alternate setting.
481
509
if alt_setting == DEFAULT_ALTERNATE_SETTING_U16 {
510
+ usb_debug ! ( "Accepting unused alternate settings" ) ;
482
511
let _ = xfer. accept ( ) ;
483
512
} else {
513
+ usb_debug ! ( "Rejecting unused alternate settings" ) ;
484
514
let _ = xfer. reject ( ) ;
485
515
}
486
516
}
@@ -493,6 +523,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
493
523
}
494
524
495
525
if self . control . waiting_for_response ( ) {
526
+ usb_debug ! ( "Rejecting control transfer due to waiting response" ) ;
496
527
let _ = self . control . reject ( ) ;
497
528
}
498
529
}
0 commit comments