Skip to main content

UsbDevice

Struct UsbDevice 

Source
pub struct UsbDevice<'a> { /* private fields */ }
Expand description

The device this driver was started for, reached through its host.

Implementations§

Source§

impl<'a> UsbDevice<'a>

Source

pub fn granted(ctx: &'a ServiceContext) -> Option<UsbDevice<'a>>

The host this driver was given as its peer, or None when it was given none - it was not started for a USB device. A host spawned after this driver is named but not yet wired, so one this driver may REACQUIRE by name is taken next. The kernel mints a capability by name only for a peer this driver was spawned with (or for a holder of ACQUIRE_ANY), so this reaches no host the driver was not given, and widens nothing.

Source

pub fn host(&self) -> &'static str

The host’s name, for a log line.

Source

pub fn info(&self) -> Result<Bound, UsbError>

Who the bound device is (wire::OP_INFO).

Source

pub fn place(&self) -> Option<Place>

Where the host says the device is, or None from a host that does not say, or did not answer.

Source

pub fn control_in( &self, setup: [u8; 8], out: &mut [u8], ) -> Result<usize, UsbError>

One control transfer IN on the default endpoint: setup is the 8-byte setup packet as USB defines it, and what the device returned is copied into out. How many bytes it returned.

Source

pub fn control_out(&self, setup: [u8; 8], data: &[u8]) -> Result<(), UsbError>

One control transfer OUT on the default endpoint, with data as its data stage (at most wire::CONTROL_MAX bytes; the setup packet’s length field is the caller’s to set to match).

Source

pub fn control_out_once( &self, setup: [u8; 8], data: &[u8], ) -> Result<(), UsbError>

control_out, attempted exactly once: the host does not retry it. For a write whose effect a second attempt would repeat - a device that acts on the first copy and NAKs the rest (wire::OP_CONTROL_ONCE).

Source

pub fn replug(&self) -> Result<(), UsbError>

Ask the host to reset the device’s port and bind it afresh, as unplugging it would (wire::OP_REPLUG): for a device that has stopped answering. On Ok the host reports the device gone and then bound again, so this driver is stopped and a fresh one started. Failed is a host that has reset it as often as it may; BadRequest one that cannot reset a port (xhci, ehci).

Source

pub fn bulk_out(&self, out: u8, data: &[u8]) -> Result<(), UsbError>

One bulk OUT transfer to the device’s outth bulk OUT endpoint, counted in the order its configuration descriptor lists them, from 0. At most wire::BULK_OUT_MAX bytes.

Source

pub fn bulk_in(&self, out: &mut [u8]) -> Result<usize, UsbError>

The bulk IN transfer the host holds from the device, copied into out: how many bytes, 0 when it holds none. The host keeps one IN armed and arms it again as each is collected, so the first call is what starts receiving; it sends wire::NOTE_BULK_IN when one is held, for a driver that waits rather than asks (xhci, dwc2). ehci holds nothing and sends no notice: each call waits up to 20 ms for the device and returns what came, so a driver there asks again rather than waiting to be told.

Auto Trait Implementations§

§

impl<'a> Freeze for UsbDevice<'a>

§

impl<'a> RefUnwindSafe for UsbDevice<'a>

§

impl<'a> Send for UsbDevice<'a>

§

impl<'a> Sync for UsbDevice<'a>

§

impl<'a> Unpin for UsbDevice<'a>

§

impl<'a> UnsafeUnpin for UsbDevice<'a>

§

impl<'a> UnwindSafe for UsbDevice<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.