Cross USB
A USB library which works seamlessly across most native and WASM targets.
[!NOTE] Web USB only works in Chromium based browsers for now.
[!NOTE] Web USB has certain interaction requirements in browsers, along with requiring a Secure context. Please read more about this on the mdn web docs
[!IMPORTANT] When compiling this crate on a WASM target, you must use either the rustflags
RUSTFLAGS=--cfg=web_sys_unstable_apisor by passing the argument in a.cargo/config.tomlfile. Read more here: https://rustwasm.github.io/wasm-bindgen/web-sys/unstable-apis.html
Dependencies
For native USB, the crate utilizies nusb,
a pure rust library similar to the very popular libusb. If you don't need WASM
support, just using nusb is the way to go!
For WASM, this crate utilizes web-sys which gives access to browser API calls, and in this case is used to interact with WebUSB.
Example
To learn about how USB communciations work, check out USB in a NutShell.
use *;
use ;
use device_filter;
// Obtain a device descriptor using a DeviceFilter,
// in this case with its VendorID and ProductID
let filters = vec!;
let dev_descriptor = get_device.await.expect;
// Open the device that the descriptor is describing
let dev = dev_descriptor.open.await.expect;
// Obtain an interface of the device
let interface = dev.open_interface.await.expect;
// Send a Control transfer to the device, obtaining
// the result and storing it in `result`
let result = interface.control_in
.await
.expect;
Check out the documentation as well!
TODO
- Add choice for native backend between
libusbwrapper and pure rustnusb - Allow platform-specific operations if the user requires them
- Hot plug support... requires either using
libusbas an optional backend or fornusbto implement it