pub trait HostController {
// Required methods
fn port_status(&self) -> PortStatus;
fn reset_port(&self) -> HostResult<PortStatus>;
fn alloc_channel(&self) -> HostResult<Channel>;
fn free_channel(&self, channel: Channel);
fn configure(
&self,
channel: Channel,
device: DeviceAddress,
endpoint: &EndpointConfig,
) -> HostResult<()>;
fn setup(&self, channel: Channel, packet: &[u8]) -> HostResult<()>;
fn transfer_in(
&self,
channel: Channel,
toggle: Toggle,
buffer: &mut [u8],
) -> HostResult<usize>;
fn transfer_out(
&self,
channel: Channel,
toggle: Toggle,
data: &[u8],
) -> HostResult<()>;
fn wait_millis(&self, millis: u32);
}Expand description
The peripheral side of the host stack.
Every method takes &self, because pipes and the device handle are handed
out by reference; implementations use interior mutability for the registers
and the channel table.
The interface is transaction oriented: one call moves at most one packet. The protocol layer splits transfers into packets, which keeps controllers simple and makes the FIFO requirements predictable.
Required Methods§
Sourcefn port_status(&self) -> PortStatus
fn port_status(&self) -> PortStatus
Read the root port.
Sourcefn reset_port(&self) -> HostResult<PortStatus>
fn reset_port(&self) -> HostResult<PortStatus>
Drive a bus reset on the root port, wait for the device to be enabled and report the negotiated speed.
Sourcefn alloc_channel(&self) -> HostResult<Channel>
fn alloc_channel(&self) -> HostResult<Channel>
Take a free channel.
Sourcefn free_channel(&self, channel: Channel)
fn free_channel(&self, channel: Channel)
Give a channel back.
Sourcefn configure(
&self,
channel: Channel,
device: DeviceAddress,
endpoint: &EndpointConfig,
) -> HostResult<()>
fn configure( &self, channel: Channel, device: DeviceAddress, endpoint: &EndpointConfig, ) -> HostResult<()>
Program a channel for one endpoint of device.
Called once before the first transfer and again whenever the device
address or the packet size changes. endpoint.speed and
endpoint.route describe the link the device sits on: a low-speed
device behind a full-speed hub needs different signalling from one on
the root port, and a FS/LS device behind a high-speed hub needs split
transactions. Controllers that cannot do either return
HostError::Unsupported.
Sourcefn setup(&self, channel: Channel, packet: &[u8]) -> HostResult<()>
fn setup(&self, channel: Channel, packet: &[u8]) -> HostResult<()>
Send an eight-byte SETUP packet.
Sourcefn transfer_in(
&self,
channel: Channel,
toggle: Toggle,
buffer: &mut [u8],
) -> HostResult<usize>
fn transfer_in( &self, channel: Channel, toggle: Toggle, buffer: &mut [u8], ) -> HostResult<usize>
Receive one packet into buffer, which must hold
endpoint.max_packet bytes at most.
Returns the number of bytes the device sent; that is zero for a zero-length packet.
Sourcefn transfer_out(
&self,
channel: Channel,
toggle: Toggle,
data: &[u8],
) -> HostResult<()>
fn transfer_out( &self, channel: Channel, toggle: Toggle, data: &[u8], ) -> HostResult<()>
Send one packet from data, which must hold endpoint.max_packet bytes
at most.
Sourcefn wait_millis(&self, millis: u32)
fn wait_millis(&self, millis: u32)
Wait for at least millis milliseconds.
The protocol layer needs the delays the USB specification mandates (2 ms
after SET_ADDRESS, for example) but has no time base of its own.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".