Crate yusb

Source
Expand description

This crate provides a safe wrapper around the native libusb library.

Yet another fork of a fork of a Rust libusb wrapper!

This is a fork of Ilya Averyanov’s rusb crate, which itself is a fork of David Cuddeback’s libusb crate.

The initial version of this crate differs from rusb in a number of ways:

  • Removes the UsbContext trait
    • Consolidates Context and GenericContext types into a single, concrete Context type.
    • Now the generic context is just an instance of Context with a null inner pointer.
  • The Device<T> and DeviceList<T> no longer need to be generic over the Context type (since there is now only a single context type), and are now just Device and DeviceList, respectively.
  • There is a new Port type which uniquely identified the physical USB port to which a device in the system is attached.
    • It is a combination of the bus number and ordered list of hub ports
    • This helps to uniquely identify a device when multiple ones are attached with the same VID:PID and no serial number or other distinguishing feature.
    • Individual ports are comparable and can be converted to/from strings that use the Linux syspath format, like 2-1.4.3.
  • The Speed type is updated:
    • It can be converted to floating-point speed in Mbps, and directly displayed as such.
    • It is ordered and comparable like:
    if (device.speed() < Speed::Super) { println!("Plug the device into a faster port");
  • Some general cleanup and modernization of the code base.

Re-exports§

pub use libusb1_sys as ffi;

Modules§

constants

Structs§

ConfigDescriptor
Describes a configuration.
Context
A libusb context.
Device
A reference to a USB device.
DeviceDescriptor
Describes a device.
DeviceHandle
A handle to an open USB device.
DeviceList
A list of detected USB devices.
Devices
Iterator over detected USB devices.
EndpointDescriptor
Describes an endpoint.
EndpointDescriptors
Iterator over an interface’s endpoint descriptors.
HotplugBuilder
Builds hotplug Registration with custom configuration values.
Interface
A device interface.
InterfaceDescriptor
Describes an alternate setting for an interface.
InterfaceDescriptors
Iterator over an interface’s descriptors.
Interfaces
Iterator over a configuration’s interfaces.
Language
A language used to read string descriptors from USB devices.
LibraryVersion
A structure that describes the version of the underlying libusb library.
Port
The unique port for a USB device.
Registration
Registration object for hotplug callbacks.
UsbOption
A libusb runtime option that can be enabled for a context.
Version
A three-part version consisting of major, minor, and sub minor components.

Enums§

Direction
Transfer and endpoint directions.
Error
Errors returned by the libusb library.
IsoSyncType
Isochronous synchronization mode.
IsoUsageType
Usage type for isochronous endpoints. Values for bits 4:5 of the bmAttributes field in the endpoint descriptor.
LogLevel
Library logging levels.
PrimaryLanguage
Primary language families.
Recipient
Recipients of control transfers.
RequestType
Types of control transfers.
Speed
Device speeds.
SubLanguage
Language dialects and writing systems.
TransferType
An endpoint’s transfer type.

Traits§

Hotplug
When handling a Hotplug::device_arrived event it is considered safe to call any yusb function that takes a Device. It also safe to open a device and submit asynchronous transfers. However, most other functions that take a DeviceHandle are not safe to call. Examples of such functions are any of the synchronous API functions or the blocking functions that retrieve various USB descriptors. These functions must be used outside of the context of the Hotplug functions.

Functions§

devices
Returns a list of the current USB devices. Using global context
disable_device_discovery
Disable device scanning in libusb init.
has_capability
Tests whether the running libusb library supports capability API.
has_hid_access
Tests whether the running libusb library has HID access.
has_hotplug
Tests whether the running libusb library supports hotplug.
open_device_with_vid_pid
Convenience function to open a device by its vendor ID and product ID. Using global context
request_type
Builds a value for the bmRequestType field of a control transfer setup packet.
set_log_level
Sets the log level of a libusb global context.
supports_detach_kernel_driver
Tests whether the running libusb library supports detaching the kernel driver.
version
Returns a structure with the version of the running libusb library.

Type Aliases§

Result
A result of a function that may return a USB Error.