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 Endpoints are dropped.
Implementations§
Source§impl Interface
impl Interface
Sourcepub fn set_alt_setting(
&self,
alt_setting: u8,
) -> impl MaybeFuture<Output = Result<(), Error>>
pub fn set_alt_setting( &self, alt_setting: u8, ) -> impl MaybeFuture<Output = 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.
You must not have any pending transfers or open Endpoints on this interface when changing
the alternate setting.
Sourcepub fn get_alt_setting(&self) -> u8
pub fn get_alt_setting(&self) -> u8
Get the current alternate setting of this interface.
Sourcepub fn control_in(
&self,
data: ControlIn,
timeout: Duration,
) -> impl MaybeFuture<Output = Result<Vec<u8>, TransferError>>
pub fn control_in( &self, data: ControlIn, timeout: Duration, ) -> impl MaybeFuture<Output = Result<Vec<u8>, TransferError>>
Submit a single IN (device-to-host) transfer on the default control endpoint.
§Example
use std::time::Duration;
use futures_lite::future::block_on;
use nusb::transfer::{ ControlIn, ControlType, Recipient };
let data: Vec<u8> = interface.control_in(ControlIn {
control_type: ControlType::Vendor,
recipient: Recipient::Device,
request: 0x30,
value: 0x0,
index: 0x0,
length: 64,
}, Duration::from_millis(100)).wait()?;§Platform-specific details
- On Windows, if the
recipientisInterface, the least significant byte ofindexmust match the interface number, orTransferError::InvalidArgumentwill be returned. This is a WinUSB limitation. - On Windows, the timeout is currently fixed to 5 seconds and the timeout argument is ignored.
Sourcepub fn control_out(
&self,
data: ControlOut<'_>,
timeout: Duration,
) -> impl MaybeFuture<Output = Result<(), TransferError>>
pub fn control_out( &self, data: ControlOut<'_>, timeout: Duration, ) -> impl MaybeFuture<Output = Result<(), TransferError>>
Submit a single OUT (host-to-device) transfer on the default control endpoint.
§Example
use std::time::Duration;
use futures_lite::future::block_on;
use nusb::transfer::{ ControlOut, ControlType, Recipient };
interface.control_out(ControlOut {
control_type: ControlType::Vendor,
recipient: Recipient::Device,
request: 0x32,
value: 0x0,
index: 0x0,
data: &[0x01, 0x02, 0x03, 0x04],
}, Duration::from_millis(100)).wait()?;§Platform-specific details
- On Windows, if the
recipientisInterface, the least significant byte ofindexmust match the interface number, orTransferError::InvalidArgumentwill be returned. This is a WinUSB limitation. - On Windows, the timeout is currently fixed to 5 seconds and the timeout argument is ignored.
Sourcepub fn interface_number(&self) -> u8
pub fn interface_number(&self) -> u8
Get the interface number.
Sourcepub fn descriptors(&self) -> impl Iterator<Item = InterfaceDescriptor<'_>>
pub fn descriptors(&self) -> impl Iterator<Item = InterfaceDescriptor<'_>>
Get the interface descriptors for the alternate settings of this interface.
This returns cached data and does not perform IO.
Sourcepub fn descriptor(&self) -> Option<InterfaceDescriptor<'_>>
pub fn descriptor(&self) -> Option<InterfaceDescriptor<'_>>
Get the interface descriptor for the current alternate setting.
Sourcepub fn endpoint<EpType: EndpointType, Dir: EndpointDirection>(
&self,
address: u8,
) -> Result<Endpoint<EpType, Dir>, Error>
pub fn endpoint<EpType: EndpointType, Dir: EndpointDirection>( &self, address: u8, ) -> Result<Endpoint<EpType, Dir>, Error>
Open an endpoint.
This claims exclusive access to the endpoint and returns an Endpoint
that can be used to submit transfers. The type-level EndpointType and
EndpointDirection parameters must match the endpoint type and
direction.