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

Modules

Structs

Enums

Traits

  • 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

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

Type Aliases

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