crab_usb/backend/ty/
mod.rs1use core::any::Any;
2use core::fmt::Debug;
3
4use futures::future::BoxFuture;
5use usb_if::descriptor::{ConfigurationDescriptor, DeviceDescriptor};
6
7use crate::{backend::ty::ep::EndpointControl, err::USBError};
8
9pub mod ep;
10pub mod transfer;
11
12#[derive(Debug, Clone)]
13pub enum Event {
14 Nothing,
15 PortChange { port: u8 },
16 Stopped,
17}
18
19pub(crate) trait EventHandlerOp: Send + Any + Sync + 'static {
20 fn handle_event(&self) -> Event;
21}
22
23#[allow(dead_code)]
24pub(crate) trait DeviceInfoOp: Send + Sync + Any + Debug + 'static {
25 fn id(&self) -> usize;
26 fn backend_name(&self) -> &str;
27 fn descriptor(&self) -> &DeviceDescriptor;
28 fn configuration_descriptors(&self) -> &[ConfigurationDescriptor];
29}
30
31pub(crate) trait DeviceOp: Send + Any + 'static {
33 fn id(&self) -> usize;
34 fn backend_name(&self) -> &str;
35 fn descriptor(&self) -> &DeviceDescriptor;
36 fn configuration_descriptors(&self) -> &[ConfigurationDescriptor];
37
38 fn claim_interface<'a>(
39 &'a mut self,
40 interface: u8,
41 alternate: u8,
42 ) -> BoxFuture<'a, Result<(), USBError>>;
43
44 fn ep_ctrl(&mut self) -> &mut EndpointControl;
45
46 fn set_configuration<'a>(
47 &'a mut self,
48 configuration_value: u8,
49 ) -> BoxFuture<'a, Result<(), USBError>>;
50
51 fn get_endpoint(
52 &mut self,
53 desc: &usb_if::descriptor::EndpointDescriptor,
54 ) -> Result<ep::EndpointBase, USBError>;
55
56 fn update_hub(&mut self, params: HubParams) -> BoxFuture<'_, Result<(), USBError>>;
57}
58
59#[derive(Debug, Clone)]
60pub struct HubParams {
61 pub num_ports: u8,
63
64 pub multi_tt: bool,
66
67 pub tt_think_time_ns: u16,
70
71 pub parent_hub_slot_id: u8,
73
74 pub root_hub_port_number: u8,
76}