Thanks to visit codestin.com
Credit goes to docs.rs

Skip to main content

Interface

Struct Interface 

Source
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

Source

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.

Source

pub fn get_alt_setting(&self) -> u8

Get the current alternate setting of this interface.

Source

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 recipient is Interface, the least significant byte of index must match the interface number, or TransferError::InvalidArgument will be returned. This is a WinUSB limitation.
  • On Windows, the timeout is currently fixed to 5 seconds and the timeout argument is ignored.
Source

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 recipient is Interface, the least significant byte of index must match the interface number, or TransferError::InvalidArgument will be returned. This is a WinUSB limitation.
  • On Windows, the timeout is currently fixed to 5 seconds and the timeout argument is ignored.
Source

pub fn interface_number(&self) -> u8

Get the interface number.

Source

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.

Source

pub fn descriptor(&self) -> Option<InterfaceDescriptor<'_>>

Get the interface descriptor for the current alternate setting.

Source

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.

Trait Implementations§

Source§

impl Clone for Interface

Source§

fn clone(&self) -> Interface

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Interface

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.