pub struct Interface { /* private fields */ }
Expand description
An opened interface of a USB device.
Obtain an Interface
with the Device::claim_interface
method.
This type is reference-counted with an Arc
internally, and can be cloned cheaply for
use in multiple places in your program. The interface is released when all clones, and all
associated TransferFuture
s and Queue
s are dropped.
Implementations§
source§impl Interface
impl Interface
sourcepub fn set_alt_setting(&self, alt_setting: u8) -> Result<(), Error>
pub fn set_alt_setting(&self, alt_setting: u8) -> Result<(), Error>
Select the alternate setting of this interface.
An alternate setting is a mode of the interface that makes particular endpoints available and may enable or disable functionality of the device. The OS resets the device to the default alternate setting when the interface is released or the program exits.
sourcepub fn control_in_blocking(
&self,
control: Control,
data: &mut [u8],
timeout: Duration
) -> Result<usize, TransferError>
pub fn control_in_blocking( &self, control: Control, data: &mut [u8], timeout: Duration ) -> Result<usize, TransferError>
Synchronously perform a single IN (device-to-host) transfer on the default control endpoint.
§Platform-specific notes
- On Linux, this takes a device-wide lock, so if you have multiple threads, you are better off using the async methods.
- On Windows, if the
recipient
isInterface
, the WinUSB driver sends the interface number in the least significant byte ofindex
, overriding any value passed. A warning is logged if the passedindex
least significant byte differs from the interface number, and this may become an error in the future.
sourcepub fn control_out_blocking(
&self,
control: Control,
data: &[u8],
timeout: Duration
) -> Result<usize, TransferError>
pub fn control_out_blocking( &self, control: Control, data: &[u8], timeout: Duration ) -> Result<usize, TransferError>
Synchronously perform a single OUT (host-to-device) transfer on the default control endpoint.
§Platform-specific notes
- On Linux, this takes a device-wide lock, so if you have multiple threads, you are better off using the async methods.
- On Windows, if the
recipient
isInterface
, the WinUSB driver sends the interface number in the least significant byte ofindex
, overriding any value passed. A warning is logged if the passedindex
least significant byte differs from the interface number, and this may become an error in the future.
sourcepub fn control_in(&self, data: ControlIn) -> TransferFuture<ControlIn> ⓘ
pub fn control_in(&self, data: ControlIn) -> TransferFuture<ControlIn> ⓘ
Submit a single IN (device-to-host) transfer on the default control endpoint.
§Example
use futures_lite::future::block_on;
use nusb::transfer::{ ControlIn, ControlType, Recipient };
let data: Vec<u8> = block_on(interface.control_in(ControlIn {
control_type: ControlType::Vendor,
recipient: Recipient::Device,
request: 0x30,
value: 0x0,
index: 0x0,
length: 64,
})).into_result()?;
§Platform-specific notes
- On Windows, if the
recipient
isInterface
, the WinUSB driver sends the interface number in the least significant byte ofindex
, overriding any value passed. A warning is logged if the passedindex
least significant byte differs from the interface number, and this may become an error in the future.
sourcepub fn control_out(
&self,
data: ControlOut<'_>
) -> TransferFuture<ControlOut<'_>> ⓘ
pub fn control_out( &self, data: ControlOut<'_> ) -> TransferFuture<ControlOut<'_>> ⓘ
Submit a single OUT (host-to-device) transfer on the default control endpoint.
§Example
use futures_lite::future::block_on;
use nusb::transfer::{ ControlOut, ControlType, Recipient };
block_on(interface.control_out(ControlOut {
control_type: ControlType::Vendor,
recipient: Recipient::Device,
request: 0x32,
value: 0x0,
index: 0x0,
data: &[0x01, 0x02, 0x03, 0x04],
})).into_result()?;
§Platform-specific notes
- On Windows, if the
recipient
isInterface
, the WinUSB driver sends the interface number in the least significant byte ofindex
, overriding any value passed. A warning is logged if the passedindex
least significant byte differs from the interface number, and this may become an error in the future.
sourcepub fn bulk_in(
&self,
endpoint: u8,
buf: RequestBuffer
) -> TransferFuture<RequestBuffer> ⓘ
pub fn bulk_in( &self, endpoint: u8, buf: RequestBuffer ) -> TransferFuture<RequestBuffer> ⓘ
Submit a single IN (device-to-host) transfer on the specified bulk endpoint.
- The requested length must be a multiple of the endpoint’s maximum packet size
- An IN endpoint address must have the top (
0x80
) bit set.
sourcepub fn bulk_out(&self, endpoint: u8, buf: Vec<u8>) -> TransferFuture<Vec<u8>> ⓘ
pub fn bulk_out(&self, endpoint: u8, buf: Vec<u8>) -> TransferFuture<Vec<u8>> ⓘ
Submit a single OUT (host-to-device) transfer on the specified bulk endpoint.
- An OUT endpoint address must have the top (
0x80
) bit clear.
sourcepub fn bulk_in_queue(&self, endpoint: u8) -> Queue<RequestBuffer>
pub fn bulk_in_queue(&self, endpoint: u8) -> Queue<RequestBuffer>
Create a queue for managing multiple IN (device-to-host) transfers on a bulk endpoint.
- An IN endpoint address must have the top (
0x80
) bit set.
sourcepub fn bulk_out_queue(&self, endpoint: u8) -> Queue<Vec<u8>>
pub fn bulk_out_queue(&self, endpoint: u8) -> Queue<Vec<u8>>
Create a queue for managing multiple OUT (device-to-host) transfers on a bulk endpoint.
- An OUT endpoint address must have the top (
0x80
) bit clear.
sourcepub fn interrupt_in(
&self,
endpoint: u8,
buf: RequestBuffer
) -> TransferFuture<RequestBuffer> ⓘ
pub fn interrupt_in( &self, endpoint: u8, buf: RequestBuffer ) -> TransferFuture<RequestBuffer> ⓘ
Submit a single IN (device-to-host) transfer on the specified interrupt endpoint.
- The requested length must be a multiple of the endpoint’s maximum packet size
- An IN endpoint address must have the top (
0x80
) bit set.
sourcepub fn interrupt_out(
&self,
endpoint: u8,
buf: Vec<u8>
) -> TransferFuture<Vec<u8>> ⓘ
pub fn interrupt_out( &self, endpoint: u8, buf: Vec<u8> ) -> TransferFuture<Vec<u8>> ⓘ
Submit a single OUT (host-to-device) transfer on the specified interrupt endpoint.
- An OUT endpoint address must have the top (
0x80
) bit clear.
sourcepub fn interrupt_in_queue(&self, endpoint: u8) -> Queue<RequestBuffer>
pub fn interrupt_in_queue(&self, endpoint: u8) -> Queue<RequestBuffer>
Create a queue for managing multiple IN (device-to-host) transfers on an interrupt endpoint.
- An IN endpoint address must have the top (
0x80
) bit set.
sourcepub fn interrupt_out_queue(&self, endpoint: u8) -> Queue<Vec<u8>>
pub fn interrupt_out_queue(&self, endpoint: u8) -> Queue<Vec<u8>>
Create a queue for managing multiple OUT (device-to-host) transfers on an interrupt endpoint.
- An OUT endpoint address must have the top (
0x80
) bit clear.
sourcepub fn clear_halt(&self, endpoint: u8) -> Result<(), Error>
pub fn clear_halt(&self, endpoint: u8) -> Result<(), Error>
Clear a bulk or interrupt endpoint’s halt / stall condition.
Sends a CLEAR_FEATURE
ENDPOINT_HALT
control transfer to tell the
device to reset the endpoint’s data toggle and clear the halt / stall
condition, and resets the host-side data toggle.
Use this after receiving TransferError::Stall
to clear the error and
resume use of the endpoint.
This should not be called when transfers are pending on the endpoint.