In theory, writing a Linux device driver shouldn’t be that hard, but it is harder than it looks. However, using libusb, you can easily deal with USB devices from user space, which, for many purposes, is fine. [Crescentrose] didn’t know anything about writing user-space USB drivers until they wrote one and documented it for us. Oh, the code is in Rust, for which there aren’t as many examples.
The device in question was a USB hub with some extra lights and gadgets. So the real issue, it seems to us, wasn’t the code, but figuring out the protocol and the USB stack. The post covers that, too, explaining configurations, interfaces, and endpoints.
There are other ancillary topics, too, like setting up udev. This lets you load things when a USB device (or something else) plugs in.
Of course, you came for the main code. The Rust program is fairly straightforward once you have the preliminaries out of the way. The libusb library helps a lot. By the end, the code kicks off some threads, handles interrupts, and does other device-driver-like things.
So if you like Rust and you ever thought about a user space device driver for a USB device, this is your chance to see it done. It didn’t take years. However, you can do a lot in user space.
Oh, okay. For a sec I thought Linux was ported to run on an USB hub.
And there is still people that insists on that Linux is monolitic… 😝
https://en.wikipedia.org/wiki/Linux_kernel?useskin=vector
Saying the Linux kernel isn’t monolithic seems even more wrong?!
Reminds me of the diagnostic tool Nvidia uses for all of its testing and debugging. It is called MODS which either stands for “MOdular Diagnostic System” or “MOnolithic Diagnostic System” depending on who you ask.
I consider it an hybrid kernel, because it allows to create device drivers in user space too (you can create character and block devices, use FUSE for file systems, libusb for usb devices… And what is more important: they are being used a lot). Also, the trend is to move to user space as much as possible.
A quick read, looks pretty easy, I like it!
I’ve had great experiences with the
nusb
create which, unlikerusb
mentioned in the article, does not use libusb. This frees one from having to manage distribution of the libusb shared library.