Struct nusb::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 TransferFutures and Queues are dropped.

Implementations§

source§

impl Interface

source

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.

source

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 is Interface, the WinUSB driver sends the interface number in the least significant byte of index, overriding any value passed. A warning is logged if the passed index least significant byte differs from the interface number, and this may become an error in the future.
source

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 is Interface, the WinUSB driver sends the interface number in the least significant byte of index, overriding any value passed. A warning is logged if the passed index least significant byte differs from the interface number, and this may become an error in the future.
source

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 is Interface, the WinUSB driver sends the interface number in the least significant byte of index, overriding any value passed. A warning is logged if the passed index least significant byte differs from the interface number, and this may become an error in the future.
source

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 is Interface, the WinUSB driver sends the interface number in the least significant byte of index, overriding any value passed. A warning is logged if the passed index least significant byte differs from the interface number, and this may become an error in the future.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.

Trait Implementations§

source§

impl Clone for Interface

source§

fn clone(&self) -> Interface

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. 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> 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,

§

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>,

§

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>,

§

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.