Embassy
embassy-usb

Crates

git

Versions

default

Flavors

Trait embassy_usb::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§