pub struct DescriptorWriter<'a> { /* private fields */ }
Expand description

A writer for USB descriptors.

Implementations§

source§

impl DescriptorWriter<'_>

source

pub fn position(&self) -> usize

Gets the current position in the buffer, i.e. the number of bytes written so far.

source

pub fn write(&mut self, descriptor_type: u8, descriptor: &[u8]) -> Result<()>

Writes an arbitrary (usually class-specific) descriptor.

source

pub fn write_with( &mut self, descriptor_type: u8, f: impl FnOnce(&mut [u8]) -> Result<usize> ) -> Result<()>

Writes an arbitrary (usually class-specific) descriptor by using a callback function.

The callback function gets a reference to the remaining buffer space, and it should write the descriptor into it and return the number of bytes written. If the descriptor doesn’t fit, the function should return Err(UsbError::BufferOverflow). That and any error returned by it will be propagated up.

source

pub fn iad( &mut self, first_interface: InterfaceNumber, interface_count: u8, function_class: u8, function_sub_class: u8, function_protocol: u8, function_string: Option<StringIndex> ) -> Result<()>

Writes a interface association descriptor. Call from UsbClass::get_configuration_descriptors before writing the USB class or function’s interface descriptors if your class has more than one interface and wants to play nicely with composite devices on Windows. If the USB device hosting the class was not configured as composite with IADs enabled, calling this function does nothing, so it is safe to call from libraries.

Arguments
  • first_interface - Number of the function’s first interface, previously allocated with UsbBusAllocator::interface.
  • interface_count - Number of interfaces in the function.
  • function_class - Class code assigned by USB.org. Use 0xff for vendor-specific devices that do not conform to any class.
  • function_sub_class - Sub-class code. Depends on class.
  • function_protocol - Protocol code. Depends on class and sub-class.
  • function_string - Index of string descriptor describing this function
source

pub fn interface( &mut self, number: InterfaceNumber, interface_class: u8, interface_sub_class: u8, interface_protocol: u8 ) -> Result<()>

Writes a interface descriptor.

Arguments
  • number - Interface number previously allocated with UsbBusAllocator::interface.
  • interface_class - Class code assigned by USB.org. Use 0xff for vendor-specific devices that do not conform to any class.
  • interface_sub_class - Sub-class code. Depends on class.
  • interface_protocol - Protocol code. Depends on class and sub-class.
source

pub fn interface_alt( &mut self, number: InterfaceNumber, alternate_setting: u8, interface_class: u8, interface_sub_class: u8, interface_protocol: u8, interface_string: Option<StringIndex> ) -> Result<()>

Writes a interface descriptor with a specific alternate setting and interface string identifier.

Arguments
  • number - Interface number previously allocated with UsbBusAllocator::interface.
  • alternate_setting - Number of the alternate setting
  • interface_class - Class code assigned by USB.org. Use 0xff for vendor-specific devices that do not conform to any class.
  • interface_sub_class - Sub-class code. Depends on class.
  • interface_protocol - Protocol code. Depends on class and sub-class.
  • interface_string - Index of string descriptor describing this interface
source

pub fn endpoint<B: UsbBus, D: EndpointDirection>( &mut self, endpoint: &Endpoint<'_, B, D> ) -> Result<()>

Writes an endpoint descriptor.

Arguments
source

pub fn endpoint_ex<B: UsbBus, D: EndpointDirection>( &mut self, endpoint: &Endpoint<'_, B, D>, f: impl FnOnce(&mut [u8]) -> Result<usize> ) -> Result<()>

Writes an endpoint descriptor with extra trailing data.

This is rarely needed and shouldn’t be used except for compatibility with standard USB classes that require it. Extra data is normally written in a separate class specific descriptor.

Arguments
  • endpoint - Endpoint previously allocated with UsbBusAllocator.
  • f - Callback for the extra data. See write_with for more information.

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for DescriptorWriter<'a>

§

impl<'a> Send for DescriptorWriter<'a>

§

impl<'a> Sync for DescriptorWriter<'a>

§

impl<'a> Unpin for DescriptorWriter<'a>

§

impl<'a> !UnwindSafe for DescriptorWriter<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.