@@ -230,11 +230,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
230
230
Some ( req) if req. direction == UsbDirection :: In => {
231
231
if let Err ( _err) = self . control_in ( classes, req) {
232
232
// TODO: Propagate error out of `poll()`
233
- usb_debug ! ( "Failed to handle control request: {:?}" , _err) ;
233
+ usb_debug ! ( "Failed to handle input control request: {:?}" , _err) ;
234
234
}
235
235
}
236
236
Some ( req) if req. direction == UsbDirection :: Out => {
237
- self . control_out ( classes, req)
237
+ if let Err ( _err) = self . control_out ( classes, req) {
238
+ // TODO: Propagate error out of `poll()`
239
+ usb_debug ! ( "Failed to handle output control request: {:?}" , _err) ;
240
+ }
238
241
}
239
242
240
243
None if ( ( ep_in_complete & 1 ) != 0 ) => {
@@ -380,7 +383,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
380
383
381
384
( Recipient :: Device , Request :: GET_DESCRIPTOR ) => {
382
385
usb_trace ! ( "Processing Device::GetDescriptor" ) ;
383
- UsbDevice :: get_descriptor ( & self . config , classes, xfer)
386
+ UsbDevice :: get_descriptor ( & self . config , classes, xfer) ? ;
384
387
}
385
388
386
389
( Recipient :: Device , Request :: GET_CONFIGURATION ) => {
@@ -425,14 +428,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
425
428
Ok ( ( ) )
426
429
}
427
430
428
- fn control_out ( & mut self , classes : & mut ClassList < ' _ , B > , req : control:: Request ) {
431
+ fn control_out ( & mut self , classes : & mut ClassList < ' _ , B > , req : control:: Request ) -> Result < ( ) > {
429
432
use crate :: control:: { Recipient , Request } ;
430
433
431
434
for cls in classes. iter_mut ( ) {
432
435
cls. control_out ( ControlOut :: new ( & mut self . control , & req) ) ;
433
436
434
437
if !self . control . waiting_for_response ( ) {
435
- return ;
438
+ return Ok ( ( ) ) ;
436
439
}
437
440
}
438
441
@@ -451,14 +454,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
451
454
) => {
452
455
usb_debug ! ( "Remote wakeup disabled" ) ;
453
456
self . remote_wakeup_enabled = false ;
454
- let _ = xfer. accept ( ) ;
457
+ xfer. accept ( ) ? ;
455
458
}
456
459
457
460
( Recipient :: Endpoint , Request :: CLEAR_FEATURE , Request :: FEATURE_ENDPOINT_HALT ) => {
458
461
usb_debug ! ( "EP{} halt removed" , req. index & 0x8f ) ;
459
462
self . bus
460
463
. set_stalled ( ( ( req. index as u8 ) & 0x8f ) . into ( ) , false ) ;
461
- let _ = xfer. accept ( ) ;
464
+ xfer. accept ( ) ? ;
462
465
}
463
466
464
467
(
@@ -468,14 +471,14 @@ impl<B: UsbBus> UsbDevice<'_, B> {
468
471
) => {
469
472
usb_debug ! ( "Remote wakeup enabled" ) ;
470
473
self . remote_wakeup_enabled = true ;
471
- let _ = xfer. accept ( ) ;
474
+ xfer. accept ( ) ? ;
472
475
}
473
476
474
477
( Recipient :: Endpoint , Request :: SET_FEATURE , Request :: FEATURE_ENDPOINT_HALT ) => {
475
478
usb_debug ! ( "EP{} halted" , req. index & 0x8f ) ;
476
479
self . bus
477
480
. set_stalled ( ( ( req. index as u8 ) & 0x8f ) . into ( ) , true ) ;
478
- let _ = xfer. accept ( ) ;
481
+ xfer. accept ( ) ? ;
479
482
}
480
483
481
484
( Recipient :: Device , Request :: SET_ADDRESS , 1 ..=127 ) => {
@@ -486,81 +489,89 @@ impl<B: UsbBus> UsbDevice<'_, B> {
486
489
} else {
487
490
self . pending_address = req. value as u8 ;
488
491
}
489
- let _ = xfer. accept ( ) ;
492
+ xfer. accept ( ) ? ;
490
493
}
491
494
492
495
( Recipient :: Device , Request :: SET_CONFIGURATION , CONFIGURATION_VALUE_U16 ) => {
493
496
usb_debug ! ( "Device configured" ) ;
494
497
self . device_state = UsbDeviceState :: Configured ;
495
- let _ = xfer. accept ( ) ;
498
+ xfer. accept ( ) ? ;
496
499
}
497
500
498
501
( Recipient :: Device , Request :: SET_CONFIGURATION , CONFIGURATION_NONE_U16 ) => {
499
502
usb_debug ! ( "Device deconfigured" ) ;
500
503
match self . device_state {
501
504
UsbDeviceState :: Default => {
502
- let _ = xfer. accept ( ) ;
505
+ xfer. accept ( ) ? ;
503
506
}
504
507
_ => {
505
508
self . device_state = UsbDeviceState :: Addressed ;
506
- let _ = xfer. accept ( ) ;
509
+ xfer. accept ( ) ? ;
507
510
}
508
511
}
509
512
}
510
513
511
514
( Recipient :: Interface , Request :: SET_INTERFACE , alt_setting) => {
512
515
// Reject interface numbers and alt settings bigger than 255
513
516
if req. index > core:: u8:: MAX . into ( ) || alt_setting > core:: u8:: MAX . into ( ) {
514
- let _ = xfer. reject ( ) ;
515
- return ;
517
+ xfer. reject ( ) ? ;
518
+ return Ok ( ( ) ) ;
516
519
}
517
520
518
521
// Ask class implementations, whether they accept the alternate interface setting.
519
522
for cls in classes {
520
523
if cls. set_alt_setting ( InterfaceNumber ( req. index as u8 ) , alt_setting as u8 )
521
524
{
522
- let _ = xfer. accept ( ) ;
523
- return ;
525
+ xfer. accept ( ) ? ;
526
+ return Ok ( ( ) ) ;
524
527
}
525
528
}
526
529
527
530
// Default behaviour, if no class implementation accepted the alternate setting.
528
531
if alt_setting == DEFAULT_ALTERNATE_SETTING_U16 {
529
532
usb_debug ! ( "Accepting unused alternate settings" ) ;
530
- let _ = xfer. accept ( ) ;
533
+ xfer. accept ( ) ? ;
531
534
} else {
532
535
usb_debug ! ( "Rejecting unused alternate settings" ) ;
533
- let _ = xfer. reject ( ) ;
536
+ xfer. reject ( ) ? ;
534
537
}
535
538
}
536
539
537
540
_ => {
538
- let _ = xfer. reject ( ) ;
539
- return ;
541
+ xfer. reject ( ) ? ;
542
+ return Ok ( ( ) ) ;
540
543
}
541
544
}
542
545
}
543
546
544
547
if self . control . waiting_for_response ( ) {
545
548
usb_debug ! ( "Rejecting control transfer due to waiting response" ) ;
546
- let _ = self . control . reject ( ) ;
549
+ self . control . reject ( ) ? ;
547
550
}
551
+
552
+ Ok ( ( ) )
548
553
}
549
554
550
- fn get_descriptor ( config : & Config , classes : & mut ClassList < ' _ , B > , xfer : ControlIn < B > ) {
555
+ fn get_descriptor (
556
+ config : & Config ,
557
+ classes : & mut ClassList < ' _ , B > ,
558
+ xfer : ControlIn < B > ,
559
+ ) -> Result < ( ) > {
551
560
let req = * xfer. request ( ) ;
552
561
553
562
let ( dtype, index) = req. descriptor_type_index ( ) ;
554
563
555
564
fn accept_writer < B : UsbBus > (
556
565
xfer : ControlIn < B > ,
557
566
f : impl FnOnce ( & mut DescriptorWriter ) -> Result < ( ) > ,
558
- ) {
559
- let _ = xfer. accept ( |buf| {
567
+ ) -> Result < ( ) > {
568
+ xfer. accept ( |buf| {
560
569
let mut writer = DescriptorWriter :: new ( buf) ;
561
570
f ( & mut writer) ?;
562
571
Ok ( writer. position ( ) )
563
- } ) ;
572
+ } ) ?;
573
+
574
+ Ok ( ( ) )
564
575
}
565
576
566
577
match dtype {
@@ -575,9 +586,9 @@ impl<B: UsbBus> UsbDevice<'_, B> {
575
586
bw. end_bos ( ) ;
576
587
577
588
Ok ( ( ) )
578
- } ) ,
589
+ } ) ? ,
579
590
580
- descriptor_type:: DEVICE => accept_writer ( xfer, |w| w. device ( config) ) ,
591
+ descriptor_type:: DEVICE => accept_writer ( xfer, |w| w. device ( config) ) ? ,
581
592
582
593
descriptor_type:: CONFIGURATION => accept_writer ( xfer, |w| {
583
594
w. configuration ( config) ?;
@@ -590,7 +601,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
590
601
w. end_configuration ( ) ;
591
602
592
603
Ok ( ( ) )
593
- } ) ,
604
+ } ) ? ,
594
605
595
606
descriptor_type:: STRING => match index {
596
607
// first STRING Request
@@ -608,7 +619,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
608
619
descriptor_type:: STRING ,
609
620
& lang_id_bytes[ ..config. string_descriptors . len ( ) * 2 ] ,
610
621
)
611
- } )
622
+ } ) ? ;
612
623
}
613
624
614
625
// rest STRING Requests
@@ -623,8 +634,8 @@ impl<B: UsbBus> UsbDevice<'_, B> {
623
634
. iter ( )
624
635
. find ( |lang| lang. id == lang_id)
625
636
else {
626
- xfer. reject ( ) . ok ( ) ;
627
- return ;
637
+ xfer. reject ( ) ? ;
638
+ return Ok ( ( ) ) ;
628
639
} ;
629
640
630
641
match index {
@@ -643,17 +654,19 @@ impl<B: UsbBus> UsbDevice<'_, B> {
643
654
} ;
644
655
645
656
if let Some ( string_descriptor) = string {
646
- accept_writer ( xfer, |w| w. string ( string_descriptor) ) ;
657
+ accept_writer ( xfer, |w| w. string ( string_descriptor) ) ? ;
647
658
} else {
648
- let _ = xfer. reject ( ) ;
659
+ xfer. reject ( ) ? ;
649
660
}
650
661
}
651
662
} ,
652
663
653
664
_ => {
654
- let _ = xfer. reject ( ) ;
665
+ xfer. reject ( ) ? ;
655
666
}
656
- }
667
+ } ;
668
+
669
+ Ok ( ( ) )
657
670
}
658
671
659
672
fn reset ( & mut self , classes : & mut ClassList < ' _ , B > ) {
0 commit comments