pub struct Device {
fd: Arc<File>,
device_descriptor_tree: DeviceDescriptorTree,
dma_buffer: Option<ManagedDmaBuffer>,
}
Expand description
Device represents a USB device.
Fields§
§fd: Arc<File>
§device_descriptor_tree: DeviceDescriptorTree
§dma_buffer: Option<ManagedDmaBuffer>
Implementations§
source§impl Device
impl Device
sourcepub fn new(fd: File) -> Result<Self>
pub fn new(fd: File) -> Result<Self>
Create a new Device
from a file descriptor.
fd
should be a file in usbdevfs (e.g. /dev/bus/usb/001/002
).
pub fn fd(&self) -> Arc<File>
unsafe fn ioctl(&self, nr: IoctlNr) -> Result<i32>
unsafe fn ioctl_with_ref<T>(&self, nr: IoctlNr, arg: &T) -> Result<i32>
unsafe fn ioctl_with_mut_ref<T>(&self, nr: IoctlNr, arg: &mut T) -> Result<i32>
unsafe fn ioctl_with_mut_ptr<T>(&self, nr: IoctlNr, arg: *mut T) -> Result<i32>
pub fn reserve_dma_buffer( &mut self, size: usize ) -> Result<Weak<Mutex<DmaBuffer>>>
pub fn release_dma_buffer( &mut self, dmabuf: Weak<Mutex<DmaBuffer>> ) -> Result<()>
sourcepub fn submit_transfer(&mut self, transfer: Transfer) -> Result<TransferHandle>
pub fn submit_transfer(&mut self, transfer: Transfer) -> Result<TransferHandle>
Submit a transfer to the device.
The transfer will be processed asynchronously by the device.
Call poll_transfers()
on this device to check for completed transfers.
sourcepub fn poll_transfers(&mut self) -> Result<()>
pub fn poll_transfers(&mut self) -> Result<()>
Check for completed asynchronous transfers submitted via submit_transfer()
.
The callback for each completed transfer will be called.
sourcepub fn claim_interface(&self, interface_number: u8) -> Result<()>
pub fn claim_interface(&self, interface_number: u8) -> Result<()>
Claim an interface on this device.
sourcepub fn release_interface(&self, interface_number: u8) -> Result<()>
pub fn release_interface(&self, interface_number: u8) -> Result<()>
Release an interface previously claimed with claim_interface()
.
sourcepub fn set_interface_alt_setting(
&self,
interface_number: u8,
alternative_setting: u8
) -> Result<()>
pub fn set_interface_alt_setting( &self, interface_number: u8, alternative_setting: u8 ) -> Result<()>
Activate an alternate setting for an interface.
sourcepub fn set_active_configuration(&mut self, config: u8) -> Result<()>
pub fn set_active_configuration(&mut self, config: u8) -> Result<()>
Set active configuration for this device.
sourcepub fn get_device_descriptor(&self) -> Result<DeviceDescriptor>
pub fn get_device_descriptor(&self) -> Result<DeviceDescriptor>
Get the device descriptor of this device.
pub fn get_device_descriptor_tree(&self) -> &DeviceDescriptorTree
sourcepub fn get_config_descriptor(&self, config: u8) -> Result<ConfigDescriptorTree>
pub fn get_config_descriptor(&self, config: u8) -> Result<ConfigDescriptorTree>
Get active config descriptor of this device.
sourcepub fn get_config_descriptor_by_index(
&self,
config_index: u8
) -> Result<ConfigDescriptorTree>
pub fn get_config_descriptor_by_index( &self, config_index: u8 ) -> Result<ConfigDescriptorTree>
Get a configuration descriptor by its index within the list of descriptors returned by the device.
sourcepub fn get_active_configuration(&self) -> Result<u8>
pub fn get_active_configuration(&self) -> Result<u8>
Get bConfigurationValue of the currently active configuration.
sourcepub fn get_num_configurations(&self) -> u8
pub fn get_num_configurations(&self) -> u8
Get the total number of configurations for this device.
sourcepub fn clear_halt(&self, ep_addr: u8) -> Result<()>
pub fn clear_halt(&self, ep_addr: u8) -> Result<()>
Clear the halt/stall condition for an endpoint.
sourcepub fn get_speed(&self) -> Result<Option<DeviceSpeed>>
pub fn get_speed(&self) -> Result<Option<DeviceSpeed>>
Get speed of this device.
sourcepub fn alloc_streams(&self, ep: u8, num_streams: u16) -> Result<()>
pub fn alloc_streams(&self, ep: u8, num_streams: u16) -> Result<()>
Allocate streams for the endpoint
sourcepub fn free_streams(&self, ep: u8) -> Result<()>
pub fn free_streams(&self, ep: u8) -> Result<()>
Free streams for the endpoint