Re: [PATCH RFC v2 1/4] rust: usb: add endpoint abstraction
From: Daniel Almeida
Date: Thu Oct 01 2026 - 19:35:37 EST
Hi Alexandru,
I think the typestate should go away in favor of something simpler:
#[derive(Clone, Copy)]
pub struct Endpoint(u8); <------- private constructor
Drivers ask the Rust layer for their endpoints at probe time, through a
wrapper around the C helpers, e.g. usb_find_common_endpoints()
or similar
pub fn find_bulk_endpoints(&self) -> Result<(Endpoint, Endpoint)>
Unlike your current &HostEndpoint, an Endpoint can be stored in the
driver's data, since it’s just a u8.
Also, perhaps the control endpoint should be its own type, i.e.:
/// # Invariants
///
/// The wrapped [`Endpoint`] is a control endpoint of the device.
#[derive(Clone, Copy)]
pub struct ControlEndpoint(Endpoint);
impl Deref for ControlEndpoint {
type Target = Endpoint;
fn deref(&self) -> &Endpoint {
&self.0
}
}
impl Interface<device::Bound> {
pub fn control_endpoint(&self) -> ControlEndpoint {
// INVARIANT: Endpoint 0 is always a control endpoint.
ControlEndpoint(Endpoint(0))
}
pub fn control_message_send(&self, ep: ControlEndpoint, ...) -> Result
pub fn control_message_receive(&self, ep: ControlEndpoint, ...) -> Result
}
By the way, the alternate setting accessors and making usb::Device
public don't have a user, not even a planned one, so I'd drop them.
-- Daniel