pub struct Device<'a, C, X>{ /* private fields */ }
Expand description
Represents Host’s view of the Device via USB bus.
Implementations§
Source§impl<'a, C, X> Device<'a, C, X>
impl<'a, C, X> Device<'a, C, X>
Sourcepub fn usb_dev(&mut self) -> &mut UsbDevice<'a, EmulatedUsbBus>
pub fn usb_dev(&mut self) -> &mut UsbDevice<'a, EmulatedUsbBus>
Provides direct access to EmulatedUsbBus
Sourcepub fn poll(&mut self, d: &mut C) -> bool
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.
Sourcepub fn ep0(
&mut self,
d: &mut C,
setup: SetupPacket,
data: Option<&[u8]>,
out: &mut [u8],
) -> Result<RWRes, AnyUsbError>
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.
Sourcepub fn ep_read(
&mut self,
cls: &mut C,
ep_index: usize,
length: u16,
) -> Result<Vec<u8>, AnyUsbError>
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.
Sourcepub fn ep_write(
&mut self,
cls: &mut C,
ep_index: usize,
data: &[u8],
) -> Result<usize, AnyUsbError>
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.
Sourcepub fn ep_raw(
&mut self,
d: &mut C,
ep_index: usize,
setup_bytes: Option<&[u8]>,
data: Option<&[u8]>,
out: &mut [u8],
) -> Result<RWRes, AnyUsbError>
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.
Sourcepub 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>
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
.
Sourcepub fn control_read(
&mut self,
cls: &mut C,
reqt: CtrRequestType,
req: u8,
value: u16,
index: u16,
length: u16,
) -> Result<Vec<u8>, AnyUsbError>
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()
.
Sourcepub fn control_write(
&mut self,
cls: &mut C,
reqt: CtrRequestType,
req: u8,
value: u16,
index: u16,
length: u16,
data: &[u8],
) -> Result<Vec<u8>, AnyUsbError>
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()
.
Sourcepub fn device_get_status(&mut self, cls: &mut C) -> Result<u16, AnyUsbError>
pub fn device_get_status(&mut self, cls: &mut C) -> Result<u16, AnyUsbError>
Standard Device Request: GET_STATUS (0x00)
Sourcepub fn device_clear_feature(
&mut self,
cls: &mut C,
feature: u16,
) -> Result<(), AnyUsbError>
pub fn device_clear_feature( &mut self, cls: &mut C, feature: u16, ) -> Result<(), AnyUsbError>
Standard Device Request: CLEAR_FEATURE (0x01)
Sourcepub fn device_set_feature(
&mut self,
cls: &mut C,
feature: u16,
) -> Result<(), AnyUsbError>
pub fn device_set_feature( &mut self, cls: &mut C, feature: u16, ) -> Result<(), AnyUsbError>
Standard Device Request: SET_FEATURE (0x03)
Sourcepub fn device_set_address(
&mut self,
cls: &mut C,
address: u8,
) -> Result<(), AnyUsbError>
pub fn device_set_address( &mut self, cls: &mut C, address: u8, ) -> Result<(), AnyUsbError>
Standard Device Request: SET_ADDRESS (0x05)
Sourcepub fn device_get_descriptor(
&mut self,
cls: &mut C,
dtype: u8,
dindex: u8,
lang_id: u16,
length: u16,
) -> Result<Vec<u8>, AnyUsbError>
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)
Sourcepub fn device_get_string(
&mut self,
cls: &mut C,
index: u8,
lang_id: u16,
) -> Result<String, AnyUsbError>
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)
Sourcepub fn device_set_descriptor(
&mut self,
cls: &mut C,
dtype: u8,
dindex: u8,
lang_id: u16,
length: u16,
data: &[u8],
) -> Result<(), AnyUsbError>
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)
Sourcepub fn device_get_configuration(
&mut self,
cls: &mut C,
) -> Result<u8, AnyUsbError>
pub fn device_get_configuration( &mut self, cls: &mut C, ) -> Result<u8, AnyUsbError>
Standard Device Request: GET_CONFIGURATION (0x08)
Sourcepub fn device_set_configuration(
&mut self,
cls: &mut C,
configuration: u8,
) -> Result<(), AnyUsbError>
pub fn device_set_configuration( &mut self, cls: &mut C, configuration: u8, ) -> Result<(), AnyUsbError>
Standard Device Request: SET_CONFIGURATION (0x09)
Sourcepub fn interface_get_status(
&mut self,
cls: &mut C,
interface: u8,
) -> Result<u16, AnyUsbError>
pub fn interface_get_status( &mut self, cls: &mut C, interface: u8, ) -> Result<u16, AnyUsbError>
Standard Interface Request: GET_STATUS (0x00)
Sourcepub fn interface_clear_feature(
&mut self,
cls: &mut C,
interface: u8,
feature: u16,
) -> Result<(), AnyUsbError>
pub fn interface_clear_feature( &mut self, cls: &mut C, interface: u8, feature: u16, ) -> Result<(), AnyUsbError>
Standard Interface Request: CLEAR_FEATURE (0x01)
Sourcepub fn interface_set_feature(
&mut self,
cls: &mut C,
interface: u8,
feature: u16,
) -> Result<(), AnyUsbError>
pub fn interface_set_feature( &mut self, cls: &mut C, interface: u8, feature: u16, ) -> Result<(), AnyUsbError>
Standard Interface Request: SET_FEATURE (0x03)
Sourcepub fn interface_get_interface(
&mut self,
cls: &mut C,
) -> Result<u8, AnyUsbError>
pub fn interface_get_interface( &mut self, cls: &mut C, ) -> Result<u8, AnyUsbError>
Standard Interface Request: GET_INTERFACE (0x0a)
Sourcepub fn interface_set_interface(
&mut self,
cls: &mut C,
interface: u8,
alt_setting: u8,
) -> Result<(), AnyUsbError>
pub fn interface_set_interface( &mut self, cls: &mut C, interface: u8, alt_setting: u8, ) -> Result<(), AnyUsbError>
Standard Interface Request: SET_INTERFACE (0x0b)
Sourcepub fn endpoint_get_status(
&mut self,
cls: &mut C,
endpoint: u8,
) -> Result<u16, AnyUsbError>
pub fn endpoint_get_status( &mut self, cls: &mut C, endpoint: u8, ) -> Result<u16, AnyUsbError>
Standard Endpoint Request: GET_STATUS (0x00)
Sourcepub fn endpoint_clear_feature(
&mut self,
cls: &mut C,
endpoint: u8,
feature: u16,
) -> Result<(), AnyUsbError>
pub fn endpoint_clear_feature( &mut self, cls: &mut C, endpoint: u8, feature: u16, ) -> Result<(), AnyUsbError>
Standard Endpoint Request: CLEAR_FEATURE (0x01)
Sourcepub fn endpoint_set_feature(
&mut self,
cls: &mut C,
endpoint: u8,
feature: u16,
) -> Result<(), AnyUsbError>
pub fn endpoint_set_feature( &mut self, cls: &mut C, endpoint: u8, feature: u16, ) -> Result<(), AnyUsbError>
Standard Endpoint Request: SET_FEATURE (0x03)
Sourcepub fn endpoint_synch_frame(
&mut self,
cls: &mut C,
endpoint: u8,
) -> Result<u16, AnyUsbError>
pub fn endpoint_synch_frame( &mut self, cls: &mut C, endpoint: u8, ) -> Result<u16, AnyUsbError>
Standard Endpoint Request: SYNCH_FRAME (0x0c)
Sourcepub fn setup(&mut self, cls: &mut C) -> Result<(), AnyUsbError>
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.