Replies: 1 comment
-
Correct, this is primarily for vendor-defined USB devices with microcontrollers programmed to implement a custom USB protocol. Look at everything using libusb -- this is basically libusb rewritten in Rust. You can transfer data on control, bulk and interrupt endpoints. Isochronous is not currently implemented, but within scope if someone wanted to implement it. Bit rates and packet sizes are at a lower level -- nusb just passes transfer requests to the kernel and it's up to the host controller driver to split them up into packets and schedule them on the bus. It should support anything the hardware does there. Linux and Windows will let you detach the kernel driver for HID, MSC or other standard classes, and you could implement those with nusb if you wanted to. macOS makes that difficult, though. I wrote that recommendation in the docs because in prior work on a libusb wrapper for Node.js, I got lots of questions like "How do I use it to read a file from a flash drive?", and while technically you could implement Mass Storage, and then implement the FAT filesystem or whatever on top of that and read a file, you probably want to just use the kernel driver and filesystem for that. |
Beta Was this translation helpful? Give feedback.
-
Sorry if this is a silly question...
I have spent a few hours reading about USB and pouring over the nusb code, and I am left wondering what nusb use cases might look like.
The docs say:
Use nusb to write user-space drivers in Rust for non-standard USB devices or those without kernel support.
The docs go on to say what NOT to use nusb for:
For devices implementing a standard USB class such as Mass Storage, CDC (Serial), HID, Audio, or Video, this is probably not the library you’re looking for – use something built on the existing kernel driver instead.
So i'm thinking that nusb is designed to run in userland across the various OS platforms with the goal of communicating with USB connected hardware devices such as microcontrollers that have their own serial protocol.
That assumed... and since HID is on the "not to use" list, what packet sizes and bit rates would nusb be capable of handling? Would it work for example with the 1 ms interrupt 64 byte packet? Or does bulk.rs mean any packet size?
Thanks in advance for any comments.
Beta Was this translation helpful? Give feedback.
All reactions