Skip to content

Commit 8d132e1

Browse files
committed
modify StringIndex and .iad()
impl `u8` to `StringIndex`, remove `StringIndex::new()`, pop `StringIndex` for `.iad()`
1 parent f72934f commit 8d132e1

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/bus.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ impl From<InterfaceNumber> for u8 {
334334
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
335335
pub struct StringIndex(u8);
336336

337-
impl StringIndex {
338-
pub(crate) fn new(index: u8) -> StringIndex {
339-
StringIndex(index)
337+
impl From<u8> for StringIndex {
338+
fn from(i: u8) -> StringIndex {
339+
StringIndex(i)
340340
}
341341
}
342342

src/descriptor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,14 @@ impl DescriptorWriter<'_> {
185185
function_class: u8,
186186
function_sub_class: u8,
187187
function_protocol: u8,
188+
function_string: Option<StringIndex>,
188189
) -> Result<()> {
189190
if !self.write_iads {
190191
return Ok(());
191192
}
192193

194+
let str_index = function_string.map_or(0, Into::into);
195+
193196
self.write(
194197
descriptor_type::IAD,
195198
&[
@@ -198,7 +201,7 @@ impl DescriptorWriter<'_> {
198201
function_class,
199202
function_sub_class,
200203
function_protocol,
201-
0,
204+
str_index,
202205
],
203206
)?;
204207

src/device.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::bus::{InterfaceNumber, PollResult, StringIndex, UsbBus, UsbBusAllocator};
1+
use crate::bus::{InterfaceNumber, PollResult, UsbBus, UsbBusAllocator};
22
use crate::class::{ControlIn, ControlOut, UsbClass};
33
use crate::control;
44
use crate::control_pipe::ControlPipe;
@@ -558,12 +558,12 @@ impl<B: UsbBus> UsbDevice<'_, B> {
558558
2 => config.product,
559559
3 => config.serial_number,
560560
_ => {
561-
let index = StringIndex::new(index);
561+
let str_index = index.into();
562562
let lang_id = req.index;
563563

564564
classes
565565
.iter()
566-
.filter_map(|cls| cls.get_string(index, lang_id))
566+
.filter_map(|cls| cls.get_string(str_index, lang_id))
567567
.next()
568568
}
569569
};

0 commit comments

Comments
 (0)