File tree Expand file tree Collapse file tree 3 files changed +17
-20
lines changed Expand file tree Collapse file tree 3 files changed +17
-20
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,9 @@ pub trait UsbClass<B: UsbBus> {
43
43
///
44
44
/// * `index` - A string index allocated earlier with
45
45
/// [`UsbAllocator`](crate::bus::UsbBusAllocator).
46
- /// * `lang_id` - The language ID for the string to retrieve.
47
- fn get_string ( & self , index : StringIndex , lang_id : Option < LangID > ) -> Option < & str > {
46
+ /// * `lang_id` - The language ID for the string to retrieve. If the requested lang_id is not
47
+ /// valid it will default to EN_US.
48
+ fn get_string ( & self , index : StringIndex , lang_id : LangID ) -> Option < & str > {
48
49
let _ = ( index, lang_id) ;
49
50
None
50
51
}
Original file line number Diff line number Diff line change @@ -563,25 +563,21 @@ impl<B: UsbBus> UsbDevice<'_, B> {
563
563
564
564
// rest STRING Requests
565
565
_ => {
566
- let lang_id = LangID :: try_from ( req. index ) ;
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}, default to EN_US" ,
571
+ _err. number
572
+ ) ;
573
+ LangID :: EN_US
574
+ }
567
575
576
+ Ok ( req_lang_id) => req_lang_id,
577
+ } ;
568
578
let string = match index {
569
579
// Manufacturer, product, and serial are handled directly here.
570
580
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
-
585
581
let Some ( lang) = config
586
582
. string_descriptors
587
583
. iter ( )
@@ -602,7 +598,7 @@ impl<B: UsbBus> UsbDevice<'_, B> {
602
598
let index = StringIndex :: new ( index) ;
603
599
classes
604
600
. iter ( )
605
- . find_map ( |cls| cls. get_string ( index, lang_id. ok ( ) ) )
601
+ . find_map ( |cls| cls. get_string ( index, lang_id) )
606
602
}
607
603
} ;
608
604
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 : Option < LangID > ) -> Option < & str > {
236
- if lang_id == Some ( LangID :: EN_US ) {
235
+ fn get_string ( & self , index : StringIndex , lang_id : LangID ) -> Option < & str > {
236
+ if lang_id == 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