Struct UsbFs

Source
pub struct UsbFs { /* private fields */ }

Implementations§

Source§

impl UsbFs

Source

pub fn from_device(device: &UsbDevice) -> Result<UsbFs>

Source

pub fn from_bus_device_read_only(bus: u8, dev: u8) -> Result<UsbFs>

This is used when read file descriptor strings.

Source

pub fn from_bus_device(bus: u8, dev: u8) -> Result<UsbFs>

Source

pub fn reset(&mut self) -> Result<()>

Source

pub fn clear_halt(&mut self, ep: u8) -> Result<()>

Source

pub fn handle(&self) -> &File

Source

pub fn descriptors(&mut self) -> &Option<UsbDevice>

Source

pub fn capabilities(&mut self) -> Result<u32>

Source

pub fn async_response(&mut self) -> Result<TransferKind>

Returns latest transmitted async result or an error. Example:

let mut urb = usb.new_bulk(1, 64);
// poll then
let urb = usb.async_response()
match transfer {
   Ok(transfer) => { // do stuff }
   Err(e) if e.kind() == ErrorKind::WouldBlock => {},
   Err(e) => { return Err(e); }
}

The returned Transfer can be reused after call transfer.flush()

Source

pub fn async_response_all(&mut self) -> Result<usize>

Read all URB responses if there are any pending and store it in transfers Should be called after mio poll if there is any pending usb_submit’s. The TransferKind is stored in transfers and can be read using collect_responses()

Example usage:

usb.submit_bulk(bulk);
poll.poll(&mut events, Duration::from_secs(1))?;
if !events.is_empty() {
    usb.async_response_all()?;
    for transfer in usb.collect_responses() { // Do stuff }
}
Source

pub fn collect_responses(&mut self) -> Vec<TransferKind>

Take all bulk/control responses

Source

pub fn claim_interface(&mut self, interface: u32) -> Result<()>

Claim interface

  • the interface number to claim

Examples

Basic usage:

usb.claim_interface(1)
Source

pub fn set_interface(&mut self, interface: u32, alt_setting: u32) -> Result<()>

Source

pub fn release_interface(&self, interface: u32) -> Result<()>

Release interface

  • the interface number to claim

Examples

Basic usage:

usb.release_interface(1)
Source

pub fn bulk_read( &self, ep: u8, mem: &mut [u8], timeout: TimeoutMillis, ) -> Result<u32>

Blocked bulk read Consider use @async_transfer() instead.

Source

pub fn bulk_write( &self, ep: u8, mem: &[u8], timeout: TimeoutMillis, ) -> Result<u32>

Blocked bulk write consider use @async_transfer() instead

Source

pub fn get_descriptor_string(&mut self, id: u8) -> Result<String>

Get descriptor string with id for default interface

Source

pub fn get_descriptor_string_iface( &mut self, iface: u16, id: u8, ) -> Result<String>

Get descriptor string with id for interface

Source

pub fn submit_bulk(&mut self, bulk: BulkTransfer) -> Result<i32>

Submit a new bulk transfer this will not block. One shall call mio poll and async_response(_all) after this call to get the transfer back Note that if the transfer is reused the user must call flush() and fill it with data before submit_bulk. Example:

bulk_out.flush()?;
bulk.write_all(&b"HELLO\n")?;
usb.submit_bulk(bulk);
// poll
resp = usb.async_response();
match resp { // do stuff }
Source

pub fn submit_control(&mut self, control: ControlTransfer) -> Result<i32>

Submit a new control transfer this will not block. One shall call mio poll and async_response(_all) after this call to get the transfer back Note that if the transfer is reused the user must call flush() before pass it to submit_control.

Source

pub fn control_async_wait( &mut self, ctrl: ControlTransfer, timeout_ms: TimeoutMillis, ) -> Result<ControlTransfer>

Wait for control response up to timeout ms. If it find other transfers those are stored in transfers and can be read using responses()

Trait Implementations§

Source§

impl Drop for UsbFs

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl UsbCoreDriver for UsbFs

Source§

fn new_bulk_in( &mut self, ep: u8, buffer_capacity: usize, ) -> Result<BulkTransfer>

Source§

fn new_bulk_out( &mut self, ep: u8, buffer_capacity: usize, ) -> Result<BulkTransfer>

Source§

fn new_control( &mut self, request_type: u8, request: u8, value: u16, index: u16, length: u16, ) -> Result<ControlTransfer>

Source§

fn new_control_out( &mut self, request_type: u8, request: u8, value: u16, index: u16, buffer: &[u8], ) -> Result<ControlTransfer>

Source§

fn new_control_in( &mut self, request_type: u8, request: u8, value: u16, index: u16, length: u16, ) -> Result<ControlTransfer>

Source§

fn new_control_nodata( &mut self, request_type: u8, request: u8, value: u16, index: u16, ) -> Result<ControlTransfer>

Auto Trait Implementations§

§

impl Freeze for UsbFs

§

impl !RefUnwindSafe for UsbFs

§

impl !Send for UsbFs

§

impl !Sync for UsbFs

§

impl Unpin for UsbFs

§

impl !UnwindSafe for UsbFs

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