Struct Device

Source
pub struct Device<'a, C, X>
where C: UsbClass<EmulatedUsbBus>, X: UsbDeviceCtx<C<'a> = C>,
{ /* private fields */ }
Expand description

Represents Host’s view of the Device via USB bus.

Implementations§

Source§

impl<'a, C, X> Device<'a, C, X>
where C: UsbClass<EmulatedUsbBus>, X: UsbDeviceCtx<C<'a> = C>,

Source

pub fn usb_dev(&mut self) -> &mut UsbDevice<'a, EmulatedUsbBus>

Provides direct access to EmulatedUsbBus

Source

pub fn poll(&mut self, d: &mut C) -> bool

Call usb-device poll().

Most Device operations call poll() automatically and this is usually enough for smaller transfers.

Must be called, for example, to gradually process emulated endpoint’s buffer if `UsbClass`` blocks and is unable to process data until some action is pefromed on it.

Source

pub fn ep0( &mut self, d: &mut C, setup: SetupPacket, data: Option<&[u8]>, out: &mut [u8], ) -> Result<RWRes, AnyUsbError>

Perform EP0 Control transfer. setup is SetupPacket. If transfer is Host-to-device and data is Some, then it’s sent after the Setup packet and Device can receive it as a payload. For Device-to-host transfers data should be None and out must have enough space to store the response.

Source

pub fn ep_read( &mut self, cls: &mut C, ep_index: usize, length: u16, ) -> Result<Vec<u8>, AnyUsbError>

Perform Endpoint Device-to-host data transfer on a given endpoint index ep_index of a maximum size length.

Returns a Vecu8 with data.

Source

pub fn ep_write( &mut self, cls: &mut C, ep_index: usize, data: &[u8], ) -> Result<usize, AnyUsbError>

Perform Endpoint Host-to-device data transfer on a given endpoint index ep_index and with data.

Returns number of bytes that was loaded into Endpoint buffer.

Source

pub fn ep_raw( &mut self, d: &mut C, ep_index: usize, setup_bytes: Option<&[u8]>, data: Option<&[u8]>, out: &mut [u8], ) -> Result<RWRes, AnyUsbError>

Perform raw EP0 Control transfer. setup_bytes is a 8-byte Setup packet. If transfer is Host-to-device and data is Some, then it’s sent after the Setup packet and Device can receive it as a payload. For Device-to-host transfers data should be None and out must have enough space to store the response.

Source

pub fn ep_io_control( &mut self, cls: &mut C, reqt: CtrRequestType, req: u8, value: u16, index: u16, length: u16, data: Option<&[u8]>, ) -> Result<Vec<u8>, AnyUsbError>

Perform EP0 Control transfer. If transfer is Host-to-device and data is Some, then it’s sent after the Setup packet and Device can receive it as a payload. For Device-to-host transfers data should be None and the response is returned in a result Vec.

Source

pub fn control_read( &mut self, cls: &mut C, reqt: CtrRequestType, req: u8, value: u16, index: u16, length: u16, ) -> Result<Vec<u8>, AnyUsbError>

Perform Device-to-host EP0 Control transfer. The response is returned in a result Vec.

reqt is passed as is. It should be to_host().

Source

pub fn control_write( &mut self, cls: &mut C, reqt: CtrRequestType, req: u8, value: u16, index: u16, length: u16, data: &[u8], ) -> Result<Vec<u8>, AnyUsbError>

Perform Host-to-device EP0 Control transfer. data is sent after the Setup packet and Device can receive it as a payload. The response is returned in a result Vec and normally it should be empty.

reqt is passed as is. It should be to_device().

Source

pub fn device_get_status(&mut self, cls: &mut C) -> Result<u16, AnyUsbError>

Standard Device Request: GET_STATUS (0x00)

Source

pub fn device_clear_feature( &mut self, cls: &mut C, feature: u16, ) -> Result<(), AnyUsbError>

Standard Device Request: CLEAR_FEATURE (0x01)

Source

pub fn device_set_feature( &mut self, cls: &mut C, feature: u16, ) -> Result<(), AnyUsbError>

Standard Device Request: SET_FEATURE (0x03)

Source

pub fn device_set_address( &mut self, cls: &mut C, address: u8, ) -> Result<(), AnyUsbError>

Standard Device Request: SET_ADDRESS (0x05)

Source

pub fn device_get_descriptor( &mut self, cls: &mut C, dtype: u8, dindex: u8, lang_id: u16, length: u16, ) -> Result<Vec<u8>, AnyUsbError>

Standard Device Request: GET_DESCRIPTOR (0x06)

Source

pub fn device_get_string( &mut self, cls: &mut C, index: u8, lang_id: u16, ) -> Result<String, AnyUsbError>

Get String descriptor from the device and return unicode string.

Standard Device Request: GET_DESCRIPTOR (0x06)

Source

pub fn device_set_descriptor( &mut self, cls: &mut C, dtype: u8, dindex: u8, lang_id: u16, length: u16, data: &[u8], ) -> Result<(), AnyUsbError>

Standard Device Request: SET_DESCRIPTOR (0x07)

Source

pub fn device_get_configuration( &mut self, cls: &mut C, ) -> Result<u8, AnyUsbError>

Standard Device Request: GET_CONFIGURATION (0x08)

Source

pub fn device_set_configuration( &mut self, cls: &mut C, configuration: u8, ) -> Result<(), AnyUsbError>

Standard Device Request: SET_CONFIGURATION (0x09)

Source

pub fn interface_get_status( &mut self, cls: &mut C, interface: u8, ) -> Result<u16, AnyUsbError>

Standard Interface Request: GET_STATUS (0x00)

Source

pub fn interface_clear_feature( &mut self, cls: &mut C, interface: u8, feature: u16, ) -> Result<(), AnyUsbError>

Standard Interface Request: CLEAR_FEATURE (0x01)

Source

pub fn interface_set_feature( &mut self, cls: &mut C, interface: u8, feature: u16, ) -> Result<(), AnyUsbError>

Standard Interface Request: SET_FEATURE (0x03)

Source

pub fn interface_get_interface( &mut self, cls: &mut C, ) -> Result<u8, AnyUsbError>

Standard Interface Request: GET_INTERFACE (0x0a)

Source

pub fn interface_set_interface( &mut self, cls: &mut C, interface: u8, alt_setting: u8, ) -> Result<(), AnyUsbError>

Standard Interface Request: SET_INTERFACE (0x0b)

Source

pub fn endpoint_get_status( &mut self, cls: &mut C, endpoint: u8, ) -> Result<u16, AnyUsbError>

Standard Endpoint Request: GET_STATUS (0x00)

Source

pub fn endpoint_clear_feature( &mut self, cls: &mut C, endpoint: u8, feature: u16, ) -> Result<(), AnyUsbError>

Standard Endpoint Request: CLEAR_FEATURE (0x01)

Source

pub fn endpoint_set_feature( &mut self, cls: &mut C, endpoint: u8, feature: u16, ) -> Result<(), AnyUsbError>

Standard Endpoint Request: SET_FEATURE (0x03)

Source

pub fn endpoint_synch_frame( &mut self, cls: &mut C, endpoint: u8, ) -> Result<u16, AnyUsbError>

Standard Endpoint Request: SYNCH_FRAME (0x0c)

Source

pub fn setup(&mut self, cls: &mut C) -> Result<(), AnyUsbError>

Setup device approximately as Host would do.

This gets some standard descriptors from the device and performs standard configuration - sets Device address and sets Device configuration to 1.

This is performed automatically unless disabled by UsbDeviceCtx.

USB reset during enumeration is not performed.

Auto Trait Implementations§

§

impl<'a, C, X> Freeze for Device<'a, C, X>
where X: Freeze,

§

impl<'a, C, X> !RefUnwindSafe for Device<'a, C, X>

§

impl<'a, C, X> !Send for Device<'a, C, X>

§

impl<'a, C, X> !Sync for Device<'a, C, X>

§

impl<'a, C, X> Unpin for Device<'a, C, X>
where X: Unpin, C: Unpin,

§

impl<'a, C, X> !UnwindSafe for Device<'a, C, X>

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.