File tree Expand file tree Collapse file tree 3 files changed +19
-16
lines changed Expand file tree Collapse file tree 3 files changed +19
-16
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ pub trait UsbClass<B: UsbBus> {
44
44
/// * `index` - A string index allocated earlier with
45
45
/// [`UsbAllocator`](crate::bus::UsbBusAllocator).
46
46
/// * `lang_id` - The language ID for the string to retrieve.
47
- fn get_string ( & self , index : StringIndex , lang_id : LangID ) -> Option < & str > {
47
+ fn get_string ( & self , index : StringIndex , lang_id : Option < LangID > ) -> Option < & str > {
48
48
let _ = ( index, lang_id) ;
49
49
None
50
50
}
Original file line number Diff line number Diff line change @@ -563,22 +563,25 @@ impl<B: UsbBus> UsbDevice<'_, B> {
563
563
564
564
// rest STRING Requests
565
565
_ => {
566
- let lang_id = match LangID :: try_from ( req. index ) {
567
- Err ( _err) => {
568
- #[ cfg( feature = "defmt" ) ]
569
- defmt:: warn!(
570
- "Receive unknown LANGID {:#06X}, reject the request" ,
571
- _err. number
572
- ) ;
573
- xfer. reject ( ) . ok ( ) ;
574
- return ;
575
- }
566
+ let lang_id = LangID :: try_from ( req. index ) ;
576
567
577
- Ok ( req_lang_id) => req_lang_id,
578
- } ;
579
568
let string = match index {
580
569
// Manufacturer, product, and serial are handled directly here.
581
570
1 ..=3 => {
571
+ let lang_id = match lang_id {
572
+ Err ( _err) => {
573
+ #[ cfg( feature = "defmt" ) ]
574
+ defmt:: warn!(
575
+ "Receive unknown LANGID {:#06X}, reject the request" ,
576
+ _err. number
577
+ ) ;
578
+ xfer. reject ( ) . ok ( ) ;
579
+ return ;
580
+ }
581
+
582
+ Ok ( req_lang_id) => req_lang_id,
583
+ } ;
584
+
582
585
let Some ( lang) = config
583
586
. string_descriptors
584
587
. iter ( )
@@ -599,7 +602,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
599
602
let index = StringIndex :: new ( index) ;
600
603
classes
601
604
. iter ( )
602
- . find_map ( |cls| cls. get_string ( index, lang_id) )
605
+ . find_map ( |cls| cls. get_string ( index, lang_id. ok ( ) ) )
603
606
}
604
607
} ;
605
608
Original file line number Diff line number Diff line change @@ -232,8 +232,8 @@ impl<B: UsbBus> UsbClass<B> for TestClass<'_, B> {
232
232
Ok ( ( ) )
233
233
}
234
234
235
- fn get_string ( & self , index : StringIndex , lang_id : LangID ) -> Option < & str > {
236
- if lang_id == LangID :: EN_US {
235
+ fn get_string ( & self , index : StringIndex , lang_id : Option < LangID > ) -> Option < & str > {
236
+ if lang_id == Some ( LangID :: EN_US ) {
237
237
if index == self . custom_string {
238
238
return Some ( CUSTOM_STRING ) ;
239
239
} else if index == self . interface_string {
You can’t perform that action at this time.
0 commit comments