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§
Sourcefn addressed(&mut self, _addr: u8)
fn addressed(&mut self, _addr: u8)
Called when the host has set the address of the device to addr.
Sourcefn configured(&mut self, _configured: bool)
fn configured(&mut self, _configured: bool)
Called when the host has enabled or disabled the configuration of the device.
Sourcefn suspended(&mut self, _suspended: bool)
fn suspended(&mut self, _suspended: bool)
Called when the bus has entered or exited the suspend state.
Sourcefn remote_wakeup_enabled(&mut self, _enabled: bool)
fn remote_wakeup_enabled(&mut self, _enabled: bool)
Called when remote wakeup feature is enabled or disabled.
Sourcefn set_alternate_setting(
&mut self,
iface: InterfaceNumber,
alternate_setting: u8,
)
fn set_alternate_setting( &mut self, iface: InterfaceNumber, alternate_setting: u8, )
Called when a “set alternate setting” control request is done on the interface.
Sourcefn control_out(&mut self, req: Request, data: &[u8]) -> Option<OutResponse>
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.
Sourcefn control_in<'a>(
&'a mut self,
req: Request,
buf: &'a mut [u8],
) -> Option<InResponse<'a>>
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.
Sourcefn get_string(&mut self, index: StringIndex, lang_id: u16) -> Option<&str>
fn get_string(&mut self, index: StringIndex, lang_id: u16) -> Option<&str>
Called when a GET_DESCRIPTOR STRING control request is received.