pub trait UsbClass<B: UsbBus> {
    // Provided methods
    fn get_configuration_descriptors(
        &self,
        writer: &mut DescriptorWriter<'_>
    ) -> Result<()> { ... }
    fn get_bos_descriptors(&self, writer: &mut BosWriter<'_, '_>) -> Result<()> { ... }
    fn get_string(&self, index: StringIndex, lang_id: LangID) -> Option<&str> { ... }
    fn reset(&mut self) { ... }
    fn poll(&mut self) { ... }
    fn control_out(&mut self, xfer: ControlOut<'_, '_, '_, B>) { ... }
    fn control_in(&mut self, xfer: ControlIn<'_, '_, '_, B>) { ... }
    fn endpoint_setup(&mut self, addr: EndpointAddress) { ... }
    fn endpoint_out(&mut self, addr: EndpointAddress) { ... }
    fn endpoint_in_complete(&mut self, addr: EndpointAddress) { ... }
    fn get_alt_setting(&mut self, interface: InterfaceNumber) -> Option<u8> { ... }
    fn set_alt_setting(
        &mut self,
        interface: InterfaceNumber,
        alternative: u8
    ) -> bool { ... }
}
Expand description

A trait for implementing USB classes.

All methods are optional callbacks that will be called by UsbBus::poll

Provided Methods§

source

fn get_configuration_descriptors( &self, writer: &mut DescriptorWriter<'_> ) -> Result<()>

Called when a GET_DESCRIPTOR request is received for a configuration descriptor. When called, the implementation should write its interface, endpoint and any extra class descriptors into writer. The configuration descriptor itself will be written by UsbDevice and shouldn’t be written by classes.

§Errors

Generally errors returned by DescriptorWriter. Implementors should propagate any errors using ?.

source

fn get_bos_descriptors(&self, writer: &mut BosWriter<'_, '_>) -> Result<()>

Called when a GET_DESCRIPTOR request is received for a BOS descriptor. When called, the implementation should write its blobs such as capability descriptors into writer. The BOS descriptor itself will be written by UsbDevice and shouldn’t be written by classes.

source

fn get_string(&self, index: StringIndex, lang_id: LangID) -> Option<&str>

Gets a class-specific string descriptor.

Note: All string descriptor requests are passed to all classes in turn, so implementations should return None if an unknown index is requested.

§Arguments
  • index - A string index allocated earlier with UsbAllocator.
  • lang_id - The language ID for the string to retrieve. If the requested lang_id is not valid it will default to EN_US.
source

fn reset(&mut self)

Called after a USB reset after the bus reset sequence is complete.

source

fn poll(&mut self)

Called whenever the UsbDevice is polled.

source

fn control_out(&mut self, xfer: ControlOut<'_, '_, '_, B>)

Called when a control request is received with direction HostToDevice.

All requests are passed to classes in turn, which can choose to accept, ignore or report an error. Classes can even choose to override standard requests, but doing that is rarely necessary.

See ControlOut for how to respond to the transfer.

When implementing your own class, you should ignore any requests that are not meant for your class so that any other classes in the composite device can process them.

§Arguments
  • req - The request from the SETUP packet.
  • xfer - A handle to the transfer.
source

fn control_in(&mut self, xfer: ControlIn<'_, '_, '_, B>)

Called when a control request is received with direction DeviceToHost.

All requests are passed to classes in turn, which can choose to accept, ignore or report an error. Classes can even choose to override standard requests, but doing that is rarely necessary.

See ControlIn for how to respond to the transfer.

When implementing your own class, you should ignore any requests that are not meant for your class so that any other classes in the composite device can process them.

§Arguments
  • req - The request from the SETUP packet.
  • data - Data to send in the DATA stage of the control transfer.
source

fn endpoint_setup(&mut self, addr: EndpointAddress)

Called when endpoint with address addr has received a SETUP packet. Implementing this shouldn’t be necessary in most cases, but is provided for completeness’ sake.

Note: This method may be called for an endpoint address you didn’t allocate, and in that case you should ignore the event.

source

fn endpoint_out(&mut self, addr: EndpointAddress)

Called when endpoint with address addr has received data (OUT packet).

Note: This method may be called for an endpoint address you didn’t allocate, and in that case you should ignore the event.

source

fn endpoint_in_complete(&mut self, addr: EndpointAddress)

Called when endpoint with address addr has completed transmitting data (IN packet).

Note: This method may be called for an endpoint address you didn’t allocate, and in that case you should ignore the event.

source

fn get_alt_setting(&mut self, interface: InterfaceNumber) -> Option<u8>

Called when the interfaces alternate setting state is requested.

Note: This method may be called on interfaces, that are not relevant to this class. You should return None, if interface` belongs to an interface you don’t know.

source

fn set_alt_setting( &mut self, interface: InterfaceNumber, alternative: u8 ) -> bool

Called when the interfaces alternate setting state is altered.

Note: This method may be called on interfaces, that are not relevant to this class. You should return false, if interface belongs to an interface you don’t know.

Implementors§

source§

impl<B: UsbBus> UsbClass<B> for TestClass<'_, B>