pub struct UsbDevice<'a, B: UsbBus> { /* private fields */ }
Expand description

A USB device consisting of one or more device classes.

Implementations§

source§

impl<B: UsbBus> UsbDevice<'_, B>

source

pub fn bus(&self) -> &B

Gets a reference to the UsbBus implementation used by this UsbDevice. You can use this to call platform-specific methods on the UsbBus.

While it is also possible to call the standard UsbBus trait methods through this reference, this is not recommended as it can cause the device to misbehave.

source

pub fn state(&self) -> UsbDeviceState

Gets the current state of the device.

In general class traffic is only possible in the Configured state.

source

pub fn remote_wakeup_enabled(&self) -> bool

Gets whether host remote wakeup has been enabled by the host.

source

pub fn self_powered(&self) -> bool

Gets whether the device is currently self powered.

source

pub fn set_self_powered(&mut self, is_self_powered: bool)

Sets whether the device is currently self powered.

source

pub fn force_reset(&mut self) -> Result<()>

Simulates a disconnect from the USB bus, causing the host to reset and re-enumerate the device.

Mostly useful for development. Calling this at the start of your program ensures that the host re-enumerates your device after a new program has been flashed.

source

pub fn poll(&mut self, classes: &mut [&'_ mut dyn UsbClass<B>]) -> bool

Polls the UsbBus for new events and dispatches them to the provided classes. Returns true if one of the classes may have data available for reading or be ready for writing, false otherwise. This should be called periodically as often as possible for the best data rate, or preferably from an interrupt handler. Must be called at least once every 10 milliseconds while connected to the USB host to be USB compliant.

Note: The list of classes passed in must be the same classes in the same order for every call while the device is configured, or the device may enumerate incorrectly or otherwise misbehave. The easiest way to do this is to call the poll method in only one place in your code, as follows:

usb_dev.poll(&mut [&mut class1, &mut class2]);

Strictly speaking the list of classes is allowed to change between polls if the device has been reset, which is indicated by state being equal to UsbDeviceState::Default.

Auto Trait Implementations§

§

impl<'a, B> RefUnwindSafe for UsbDevice<'a, B>
where B: RefUnwindSafe,

§

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

§

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

§

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

§

impl<'a, B> UnwindSafe for UsbDevice<'a, B>
where B: RefUnwindSafe,

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>,

§

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>,

§

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.