pub struct UsbFs { /* private fields */ }
Implementations§
Source§impl UsbFs
impl UsbFs
pub fn from_device(device: &UsbDevice) -> Result<UsbFs>
Sourcepub fn from_bus_device_read_only(bus: u8, dev: u8) -> Result<UsbFs>
pub fn from_bus_device_read_only(bus: u8, dev: u8) -> Result<UsbFs>
This is used when read file descriptor strings.
pub fn from_bus_device(bus: u8, dev: u8) -> Result<UsbFs>
pub fn reset(&mut self) -> Result<()>
pub fn clear_halt(&mut self, ep: u8) -> Result<()>
pub fn handle(&self) -> &File
pub fn descriptors(&mut self) -> &Option<UsbDevice>
pub fn capabilities(&mut self) -> Result<u32>
Sourcepub fn async_response(&mut self) -> Result<TransferKind>
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()
Sourcepub fn async_response_all(&mut self) -> Result<usize>
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 }
}
Sourcepub fn collect_responses(&mut self) -> Vec<TransferKind>
pub fn collect_responses(&mut self) -> Vec<TransferKind>
Take all bulk/control responses
Sourcepub fn claim_interface(&mut self, interface: u32) -> Result<()>
pub fn claim_interface(&mut self, interface: u32) -> Result<()>
Claim interface
- the
interface
number to claim
Examples
Basic usage:
usb.claim_interface(1)
pub fn set_interface(&mut self, interface: u32, alt_setting: u32) -> Result<()>
Sourcepub fn release_interface(&self, interface: u32) -> Result<()>
pub fn release_interface(&self, interface: u32) -> Result<()>
Release interface
- the
interface
number to claim
Examples
Basic usage:
usb.release_interface(1)
Sourcepub fn bulk_read(
&self,
ep: u8,
mem: &mut [u8],
timeout: TimeoutMillis,
) -> Result<u32>
pub fn bulk_read( &self, ep: u8, mem: &mut [u8], timeout: TimeoutMillis, ) -> Result<u32>
Blocked bulk read Consider use @async_transfer() instead.
Sourcepub fn bulk_write(
&self,
ep: u8,
mem: &[u8],
timeout: TimeoutMillis,
) -> Result<u32>
pub fn bulk_write( &self, ep: u8, mem: &[u8], timeout: TimeoutMillis, ) -> Result<u32>
Blocked bulk write consider use @async_transfer() instead
Sourcepub fn get_descriptor_string(&mut self, id: u8) -> Result<String>
pub fn get_descriptor_string(&mut self, id: u8) -> Result<String>
Get descriptor string with id for default interface
Sourcepub fn get_descriptor_string_iface(
&mut self,
iface: u16,
id: u8,
) -> Result<String>
pub fn get_descriptor_string_iface( &mut self, iface: u16, id: u8, ) -> Result<String>
Get descriptor string with id for interface
Sourcepub fn submit_bulk(&mut self, bulk: BulkTransfer) -> Result<i32>
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 }
Sourcepub fn submit_control(&mut self, control: ControlTransfer) -> Result<i32>
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.
Sourcepub fn control_async_wait(
&mut self,
ctrl: ControlTransfer,
timeout_ms: TimeoutMillis,
) -> Result<ControlTransfer>
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()