usb: add support for custom string descriptors.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use heapless::Vec;
|
||||
|
||||
use crate::Interface;
|
||||
use crate::{Interface, STRING_INDEX_CUSTOM_START};
|
||||
|
||||
use super::control::ControlHandler;
|
||||
use super::descriptor::{BosWriter, DescriptorWriter};
|
||||
@@ -181,7 +181,7 @@ impl<'d, D: Driver<'d>> Builder<'d, D> {
|
||||
config,
|
||||
interfaces: Vec::new(),
|
||||
control_buf,
|
||||
next_string_index: 4,
|
||||
next_string_index: STRING_INDEX_CUSTOM_START,
|
||||
|
||||
device_descriptor,
|
||||
config_descriptor,
|
||||
@@ -212,14 +212,6 @@ impl<'d, D: Driver<'d>> Builder<'d, D> {
|
||||
self.control_buf.len()
|
||||
}
|
||||
|
||||
/// Allocates a new string index.
|
||||
pub fn alloc_string(&mut self) -> StringIndex {
|
||||
let index = self.next_string_index;
|
||||
self.next_string_index += 1;
|
||||
|
||||
StringIndex::new(index)
|
||||
}
|
||||
|
||||
/// Add an USB function.
|
||||
///
|
||||
/// If [`Config::composite_with_iads`] is set, this will add an IAD descriptor
|
||||
@@ -277,6 +269,7 @@ impl<'a, 'd, D: Driver<'d>> FunctionBuilder<'a, 'd, D> {
|
||||
handler: None,
|
||||
current_alt_setting: 0,
|
||||
num_alt_settings: 0,
|
||||
num_strings: 0,
|
||||
};
|
||||
|
||||
if self.builder.interfaces.push(iface).is_err() {
|
||||
@@ -308,6 +301,15 @@ impl<'a, 'd, D: Driver<'d>> InterfaceBuilder<'a, 'd, D> {
|
||||
self.builder.interfaces[self.interface_number.0 as usize].handler = Some(handler);
|
||||
}
|
||||
|
||||
/// Allocates a new string index.
|
||||
pub fn string(&mut self) -> StringIndex {
|
||||
let index = self.builder.next_string_index;
|
||||
self.builder.next_string_index += 1;
|
||||
self.builder.interfaces[self.interface_number.0 as usize].num_strings += 1;
|
||||
|
||||
StringIndex::new(index)
|
||||
}
|
||||
|
||||
/// Add an alternate setting to the interface and write its descriptor.
|
||||
///
|
||||
/// Alternate setting numbers are guaranteed to be allocated consecutively, starting from 0.
|
||||
|
Reference in New Issue
Block a user