embassy-usb

Crates

git

Versions

default

Flavors

embassy_usb

Trait Handler

Source
pub trait Handler {
    // Provided methods
    fn enabled(&mut self, _enabled: bool) { ... }
    fn reset(&mut self) { ... }
    fn addressed(&mut self, _addr: u8) { ... }
    fn configured(&mut self, _configured: bool) { ... }
    fn suspended(&mut self, _suspended: bool) { ... }
    fn remote_wakeup_enabled(&mut self, _enabled: bool) { ... }
    fn set_alternate_setting(
        &mut self,
        iface: InterfaceNumber,
        alternate_setting: u8,
    ) { ... }
    fn control_out(&mut self, req: Request, data: &[u8]) -> Option<OutResponse> { ... }
    fn control_in<'a>(
        &'a mut self,
        req: Request,
        buf: &'a mut [u8],
    ) -> Option<InResponse<'a>> { ... }
    fn get_string(&mut self, index: StringIndex, lang_id: u16) -> Option<&str> { ... }
}
Expand description

Handler for device events and control requests.

All methods are optional callbacks that will be called by UsbDevice::run()

Provided Methods§

Source

fn enabled(&mut self, _enabled: bool)

Called when the USB device has been enabled or disabled.

Source

fn reset(&mut self)

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

Source

fn addressed(&mut self, _addr: u8)

Called when the host has set the address of the device to addr.

Source

fn configured(&mut self, _configured: bool)

Called when the host has enabled or disabled the configuration of the device.

Source

fn suspended(&mut self, _suspended: bool)

Called when the bus has entered or exited the suspend state.

Source

fn remote_wakeup_enabled(&mut self, _enabled: bool)

Called when remote wakeup feature is enabled or disabled.

Source

fn set_alternate_setting( &mut self, iface: InterfaceNumber, alternate_setting: u8, )

Called when a “set alternate setting” control request is done on the interface.

Source

fn control_out(&mut self, req: Request, data: &[u8]) -> Option<OutResponse>

Called when a control request is received with direction HostToDevice.

§Arguments
  • req - The request from the SETUP packet.
  • data - The data from the request.
§Returns

If you didn’t handle this request (for example if it’s for the wrong interface), return None. In this case, the the USB stack will continue calling the other handlers, to see if another handles it.

If you did, return Some with either Accepted or Rejected. This will make the USB stack respond to the control request, and stop calling other handlers.

Source

fn control_in<'a>( &'a mut self, req: Request, buf: &'a mut [u8], ) -> Option<InResponse<'a>>

Called when a control request is received with direction DeviceToHost.

You should write the response somewhere (usually to buf, but you may use another buffer owned by yourself, or a static buffer), then return InResponse::Accepted(data).

§Arguments
  • req - The request from the SETUP packet.
§Returns

If you didn’t handle this request (for example if it’s for the wrong interface), return None. In this case, the the USB stack will continue calling the other handlers, to see if another handles it.

If you did, return Some with either Accepted or Rejected. This will make the USB stack respond to the control request, and stop calling other handlers.

Source

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

Called when a GET_DESCRIPTOR STRING control request is received.

Implementors§