Driver’s Ed for Linux

Frustrated by a lack of support for Linux, crescentrose wrote a custom device driver for a USB dock with flashy RGB LEDs.

Nick Bild
22 days agoHW101

A long-standing joke in the Linux community is that this year is finally the year of Linux on the desktop. As a long-time user of Linux, I find it easy to fall for this prediction year after year because of how far the user-friendliness of the interface has come. But alas, when you look just beneath that shiny veneer, Linux is still a complex beast. When the year of Linux on the desktop does finally arrive, Grandma might be able to check her AOL email on Ubuntu, but this is not that year.

A hacker that goes by the handle crescentrose is an avid Linux user that decided to dig into some of its scary complexities after picking up a new device that does not support the operating system. The device in question is a Nanoleaf Pegboard Desk Dock, which adds the flashy RGB LEDs to a system that no serious gamer can live without. But to get those LEDs flashing, the dock needs a proper USB driver. The idea of writing a device driver is enough to make most hobbyists run away screaming, but as crescentrose — who is a total novice in this area — found out, it is not necessarily that difficult.

Before writing a driver, one must first understand how the hardware works. That can be difficult to figure out when it comes to commercial hardware, but in this case Nanoleaf responded to crescentrose’s request for documentation within a matter of hours. Major kudos to Nanoleaf for being so willing to provide that information! With that documentation in hand, crescentrose next had to learn about the basics of USB devices and how they are configured.

The Linux kernel does have some built-in methods for dealing with USB status LEDs, like those found on a keyboard, but nothing for RGB LEDs. So a custom driver would definitely be needed to interface with the dock. That gave crescentrose two options: write a kernel driver and invite the wrath of the notoriously crabby Linus Torvalds, or write a userspace driver and do whatever seemed appropriate. As a novice, crescentrose wisely chose the latter option.

After digging into the official USB specifications and combining that with knowledge of how the device works, a plan was developed to send messages to the dock for LED control. A binary was developed in Rust to send the appropriate messages to the device, and handle the responses that it sends back. And since we are dealing with Linux, there was naturally also some work to be done related to device permissions.

In the end, the driver did its job of changing the LED colors on demand, and in only about 50 lines of code. It may be very bare-bones, and with a minor bug here and there, but most importantly, it worked! crescentrose goes into much greater detail about how the driver was developed in the project write-up. It is well worth the read, and might just give you the confidence you need to write your own drivers when device manufacturers fail to recognize that this is the year of Linux on the desktop.

Nick Bild
R&D, creativity, and building the next big thing you never knew you wanted are my specialties.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles