pub struct DescriptorWriter<'a> { /* private fields */ }Expand description
Cursor-based USB descriptor builder.
Wraps a &mut [u8] buffer and advances a position pointer as descriptors
are appended. The configuration-descriptor wTotalLength and bNumInterfaces
fields are back-patched when end_configuration
is called.
Implementations§
Source§impl<'a> DescriptorWriter<'a>
impl<'a> DescriptorWriter<'a>
Sourcepub fn write_with(
&mut self,
descriptor_type: u8,
f: impl FnOnce(&mut [u8]) -> UsbResult<usize>,
) -> UsbResult<()>
pub fn write_with( &mut self, descriptor_type: u8, f: impl FnOnce(&mut [u8]) -> UsbResult<usize>, ) -> UsbResult<()>
Append a raw byte sequence preceded by a 2-byte header (bLength, bDescriptorType).
f receives a mutable slice of up to 254 bytes (max descriptor body size)
and should write the descriptor body, returning the body length.
Sourcepub fn write(&mut self, descriptor_type: u8, body: &[u8]) -> UsbResult<()>
pub fn write(&mut self, descriptor_type: u8, body: &[u8]) -> UsbResult<()>
Append a descriptor with a fixed body slice.
Sourcepub fn configuration(
&mut self,
attributes: u8,
max_power_ma: u8,
) -> UsbResult<()>
pub fn configuration( &mut self, attributes: u8, max_power_ma: u8, ) -> UsbResult<()>
Begin a configuration descriptor. Must be paired with
end_configuration.
Sourcepub fn end_configuration(&mut self)
pub fn end_configuration(&mut self)
Finalise the open configuration descriptor (patch wTotalLength and bNumInterfaces).
Sourcepub fn iad(
&mut self,
first_interface: InterfaceNumber,
interface_count: u8,
function_class: u8,
function_subclass: u8,
function_protocol: u8,
) -> UsbResult<()>
pub fn iad( &mut self, first_interface: InterfaceNumber, interface_count: u8, function_class: u8, function_subclass: u8, function_protocol: u8, ) -> UsbResult<()>
Write an Interface Association Descriptor (IAD), if the configuration was
built with composite_with_iads = true.
Always safe to call — if the outer device was not configured for IADs the call is a no-op.
Sourcepub fn interface(
&mut self,
number: InterfaceNumber,
num_endpoints: u8,
class: u8,
subclass: u8,
protocol: u8,
) -> UsbResult<()>
pub fn interface( &mut self, number: InterfaceNumber, num_endpoints: u8, class: u8, subclass: u8, protocol: u8, ) -> UsbResult<()>
Write an Interface descriptor and increment the interface count.
Sourcepub fn interface_with_string(
&mut self,
number: InterfaceNumber,
num_endpoints: u8,
class: u8,
subclass: u8,
protocol: u8,
string: StringIndex,
) -> UsbResult<()>
pub fn interface_with_string( &mut self, number: InterfaceNumber, num_endpoints: u8, class: u8, subclass: u8, protocol: u8, string: StringIndex, ) -> UsbResult<()>
Write an Interface descriptor with a string index.
Sourcepub fn interface_alt(
&mut self,
number: InterfaceNumber,
alternate_setting: u8,
num_endpoints: u8,
class: u8,
subclass: u8,
protocol: u8,
) -> UsbResult<()>
pub fn interface_alt( &mut self, number: InterfaceNumber, alternate_setting: u8, num_endpoints: u8, class: u8, subclass: u8, protocol: u8, ) -> UsbResult<()>
Write an Interface descriptor with a non-zero alternate setting.
Does not increment bNumInterfaces — alternate settings share the
same interface number and are not counted separately.
Sourcepub fn endpoint(
&mut self,
addr: EndpointAddress,
ep_type: EndpointType,
max_packet_size: u16,
interval: u8,
) -> UsbResult<()>
pub fn endpoint( &mut self, addr: EndpointAddress, ep_type: EndpointType, max_packet_size: u16, interval: u8, ) -> UsbResult<()>
Write an Endpoint descriptor.