@@ -204,6 +204,12 @@ impl<B: UsbBus> UsbDevice<'_, B> {
204204
205205 // Pending events for endpoint 0?
206206 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+ ) ;
207213 // Handle EP0-IN conditions first. When both EP0-IN and EP0-OUT have completed,
208214 // it is possible that EP0-OUT is a zero-sized out packet to complete the STATUS
209215 // phase of the control transfer. We have to process EP0-IN first to update our
@@ -230,6 +236,10 @@ impl<B: UsbBus> UsbDevice<'_, B> {
230236 None
231237 } ;
232238
239+ if let Some ( _req) = req {
240+ usb_trace ! ( "Handling EP0 request: {_req}" ) ;
241+ }
242+
233243 match req {
234244 Some ( req) if req. direction == UsbDirection :: In => {
235245 self . control_in ( classes, req)
@@ -250,18 +260,21 @@ impl<B: UsbBus> UsbDevice<'_, B> {
250260 for i in 1 ..MAX_ENDPOINTS {
251261 if ( ep_setup & bit) != 0 {
252262 for cls in classes. iter_mut ( ) {
263+ usb_trace ! ( "Handling EP{i}-SETUP" ) ;
253264 cls. endpoint_setup ( EndpointAddress :: from_parts (
254265 i,
255266 UsbDirection :: Out ,
256267 ) ) ;
257268 }
258269 } else if ( ep_out & bit) != 0 {
270+ usb_trace ! ( "Handling EP{i}-OUT" ) ;
259271 for cls in classes. iter_mut ( ) {
260272 cls. endpoint_out ( EndpointAddress :: from_parts ( i, UsbDirection :: Out ) ) ;
261273 }
262274 }
263275
264276 if ( ep_in_complete & bit) != 0 {
277+ usb_trace ! ( "Handling EP{i}-IN" ) ;
265278 for cls in classes. iter_mut ( ) {
266279 cls. endpoint_in_complete ( EndpointAddress :: from_parts (
267280 i,
@@ -289,6 +302,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
289302 }
290303 PollResult :: Resume => { }
291304 PollResult :: Suspend => {
305+ usb_debug ! ( "Suspending bus" ) ;
292306 self . bus . suspend ( ) ;
293307 self . suspended_device_state = Some ( self . device_state ) ;
294308 self . device_state = UsbDeviceState :: Suspend ;
@@ -314,6 +328,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
314328
315329 match ( req. recipient , req. request ) {
316330 ( Recipient :: Device , Request :: GET_STATUS ) => {
331+ usb_trace ! ( "Processing Device::GetStatus" ) ;
317332 let status: u16 = if self . self_powered { 0x0001 } else { 0x0000 }
318333 | if self . remote_wakeup_enabled {
319334 0x0002
@@ -325,12 +340,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
325340 }
326341
327342 ( Recipient :: Interface , Request :: GET_STATUS ) => {
343+ usb_trace ! ( "Processing Interface::GetStatus" ) ;
328344 let status: u16 = 0x0000 ;
329345
330346 let _ = xfer. accept_with ( & status. to_le_bytes ( ) ) ;
331347 }
332348
333349 ( Recipient :: Endpoint , Request :: GET_STATUS ) => {
350+ usb_trace ! ( "Processing EP::GetStatus" ) ;
334351 let ep_addr = ( ( req. index as u8 ) & 0x8f ) . into ( ) ;
335352
336353 let status: u16 = if self . bus . is_stalled ( ep_addr) {
@@ -343,10 +360,12 @@ impl<B: UsbBus> UsbDevice<'_, B> {
343360 }
344361
345362 ( Recipient :: Device , Request :: GET_DESCRIPTOR ) => {
363+ usb_trace ! ( "Processing Device::GetDescriptor" ) ;
346364 UsbDevice :: get_descriptor ( & self . config , classes, xfer)
347365 }
348366
349367 ( Recipient :: Device , Request :: GET_CONFIGURATION ) => {
368+ usb_trace ! ( "Processing Device::GetConfiguration" ) ;
350369 let config = match self . device_state {
351370 UsbDeviceState :: Configured => CONFIGURATION_VALUE ,
352371 _ => CONFIGURATION_NONE ,
@@ -356,6 +375,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
356375 }
357376
358377 ( Recipient :: Interface , Request :: GET_INTERFACE ) => {
378+ usb_trace ! ( "Processing Interface::GetInterface" ) ;
359379 // Reject interface numbers bigger than 255
360380 if req. index > core:: u8:: MAX . into ( ) {
361381 let _ = xfer. reject ( ) ;
@@ -381,6 +401,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
381401 }
382402
383403 if self . control . waiting_for_response ( ) {
404+ usb_debug ! ( "Rejecting control transfer because we were waiting for a response" ) ;
384405 let _ = self . control . reject ( ) ;
385406 }
386407 }
@@ -409,11 +430,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
409430 Request :: CLEAR_FEATURE ,
410431 Request :: FEATURE_DEVICE_REMOTE_WAKEUP ,
411432 ) => {
433+ usb_debug ! ( "Remote wakeup disabled" ) ;
412434 self . remote_wakeup_enabled = false ;
413435 let _ = xfer. accept ( ) ;
414436 }
415437
416438 ( Recipient :: Endpoint , Request :: CLEAR_FEATURE , Request :: FEATURE_ENDPOINT_HALT ) => {
439+ usb_debug ! ( "EP{} halt removed" , req. index & 0x8f ) ;
417440 self . bus
418441 . set_stalled ( ( ( req. index as u8 ) & 0x8f ) . into ( ) , false ) ;
419442 let _ = xfer. accept ( ) ;
@@ -424,17 +447,20 @@ impl<B: UsbBus> UsbDevice<'_, B> {
424447 Request :: SET_FEATURE ,
425448 Request :: FEATURE_DEVICE_REMOTE_WAKEUP ,
426449 ) => {
450+ usb_debug ! ( "Remote wakeup enabled" ) ;
427451 self . remote_wakeup_enabled = true ;
428452 let _ = xfer. accept ( ) ;
429453 }
430454
431455 ( Recipient :: Endpoint , Request :: SET_FEATURE , Request :: FEATURE_ENDPOINT_HALT ) => {
456+ usb_debug ! ( "EP{} halted" , req. index & 0x8f ) ;
432457 self . bus
433458 . set_stalled ( ( ( req. index as u8 ) & 0x8f ) . into ( ) , true ) ;
434459 let _ = xfer. accept ( ) ;
435460 }
436461
437462 ( Recipient :: Device , Request :: SET_ADDRESS , 1 ..=127 ) => {
463+ usb_debug ! ( "Setting device address to {}" , req. value) ;
438464 if B :: QUIRK_SET_ADDRESS_BEFORE_STATUS {
439465 self . bus . set_device_address ( req. value as u8 ) ;
440466 self . device_state = UsbDeviceState :: Addressed ;
@@ -445,11 +471,13 @@ impl<B: UsbBus> UsbDevice<'_, B> {
445471 }
446472
447473 ( Recipient :: Device , Request :: SET_CONFIGURATION , CONFIGURATION_VALUE_U16 ) => {
474+ usb_debug ! ( "Device configured" ) ;
448475 self . device_state = UsbDeviceState :: Configured ;
449476 let _ = xfer. accept ( ) ;
450477 }
451478
452479 ( Recipient :: Device , Request :: SET_CONFIGURATION , CONFIGURATION_NONE_U16 ) => {
480+ usb_debug ! ( "Device deconfigured" ) ;
453481 match self . device_state {
454482 UsbDeviceState :: Default => {
455483 let _ = xfer. accept ( ) ;
@@ -479,8 +507,10 @@ impl<B: UsbBus> UsbDevice<'_, B> {
479507
480508 // Default behaviour, if no class implementation accepted the alternate setting.
481509 if alt_setting == DEFAULT_ALTERNATE_SETTING_U16 {
510+ usb_debug ! ( "Accepting unused alternate settings" ) ;
482511 let _ = xfer. accept ( ) ;
483512 } else {
513+ usb_debug ! ( "Rejecting unused alternate settings" ) ;
484514 let _ = xfer. reject ( ) ;
485515 }
486516 }
@@ -493,6 +523,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
493523 }
494524
495525 if self . control . waiting_for_response ( ) {
526+ usb_debug ! ( "Rejecting control transfer due to waiting response" ) ;
496527 let _ = self . control . reject ( ) ;
497528 }
498529 }
0 commit comments