Writing a basic Linux device driver when you know nothing about Linux drivers or USB

submitted by

crescentro.se/posts/writing-drivers/

16
453

Log in to comment

16 Comments

Found this to be an interesting read, and well written. Thanks for sharing it.

A very nice, simple webpage too.

I opened it and was immediately taken aback at how refreshing it feels to open a page that is entirely (mostly) just HTML/CSS.

Then i'm sure you'll like this: https://no-js.club/members/
There's also no css and no html clubs.
Last but not least, take a look at gemini protocol, which is a bit like gopher: lightweight and textbased only

Yeah, came to the comments to say exactly this! The writer has an RSS feed as well - added to my reader!! 😃 cheers, op - what a find!

Great read, with some amusing asides.

Shots fired!

Trivia you can use to woo potential partners
Here’s 443 pages on generic HID implementations.

My pants!

This is amazing. I love discovering new/interesting developer blogs like this one, which is a challenge considering they’re all buried by SEO bullshit.

Interesting read. I wonder where OP got the specs for the device itself, i.E. what it expects in terms of data and what the response (interrupt) values mean?

To my surprise, Nanoleaf tech support responded to me within 4 hours, with a full description of the protocol that’s used both by the Desk Dock as well as their RGB strips. The docs mostly confirmed what I had already discovered independently, but there were a couple of other minor features as well (like power and brightness management) that I did not know about, which was helpful.

Combo of investigating and a foot up from the manufacturer.

When I've done this in the past for game controllers I've not received such an emphatic response (other than when I was working for the vendor).

Did get some via FOI for a few other products though.

Yeah, props to the Nanoleaf team for helping the author out. Win-win. The author says at the end that they intend on sharing it around more once it has more polish, so I hope they upstream it properly and demonstrate to Nanoleaf that helping out volunteers helps their product reach more customers. (I know it's iffy to suggest it's ok to neglect Linux and let us sort it out ourselves, but if we get open-source drivers in the process with the help of the company, I think that's a net win)

Over the past few posts I’ve set up a Windows VM with USB passthrough, and attempted to reverse-engineer the official drivers, As I was doing that, I also thought I’d message the vendor and ask them if they could share any specifications or docs regarding their protocol. To my surprise, Nanoleaf tech support responded to me within 4 hours, with a full description of the protocol that’s used both by the Desk Dock as well as their RGB strips.

Deleted by author

 reply
2

This is a great write up, not only in content, but also in spirit and tone. An enjoyable read beginning to end and inspires me to try more stuff.

Shit... kind of makes me want to learn Rust now!

Anyway, wonderful write up. No BS, both shortcuts if you just want to the code and in depth links e.g. https://www.beyondlogic.org/usbnutshell/usb1.shtml all written with a fun tone. Plenty of actually useful content showing us all that sure, it is not trivial to write a (USB) driver but it is also probably not as hard as we imagine. Particularly enjoyed the :

  • userspace driver, namely being able to tinker locally without feel the pressure to push back the work to Linux the kernel itself
  • libusb and other drivers, namely that there is a myriad of points to start from already, not just writing reverse engineering bits in memory to the new device and hoping it'll work

I would try doing this for my Intel WiFi/Bluetooth card that doesn't support Linux (WiFi works anyway though). Since the CTRL key is dead (again) and the whole build of it is not to my liking I think I'll get an old Windows 10 laptop to replace the whole system instead.

When I installed Ubuntu on an HP laptop recently, I got a message that I didn't have the drivers for my internal Intel wireless chip. It was at this point that I realized the laptop also didn't have an Ethernet port. The installer told me to put the drivers on a flashdrive. Thankfully the error spelled out enough for me to find the drivers online. There were a few different versions and I put them all on the stick.

Bluetooth didn't work, but I realized that was fixed by just enabling the service with systemctl.

Comments from other communities

I read this on hacker news awhile back, and enjoyed it quite a bit. The unrelated trivia part about USB keyboards needing at least 103 keys or they're just a keypad especially stuck with me, and has been cited in discussions of a certain meme:

And I went past full sized keyboard with that 110% sh#t with extra programmable buttons and color profile modes (aka going back into mental disorder territory)

I guess laptop keyboards are out.

I think you mean laptop keypads

(Actually the 103+ keys thing is specifically USB standard stuff, so if it doesn't connect via USB I don't know if it counts)

I'm so mentally disordered that I'm not even pictured on the graph...

Prime_E and Southpaw Candybar 4 lyf. I'm not even that deep in the water compared to some.

Ortho-linear 40% reporting for service

This totally custom or did you buy the kit from somewhere? I picked up a hot swappable plank to mitigate the need for soldering but stuff like this makes me feel like I need to dive back in. What is this? 30%?

Soldering is zen. It's slow and careful, but satisfying. Like coloring with a 350°C iron. You gently heat the pad with the iron, and slowly introduce the solder. Flux will guide solder to the pads. Don't worry if you mess up a couple, by the 72nd pad, it's becomes second nature. Micro controllers are a little trickier, but planning and slow pace really takes care of it. You might burn off a pad if you keep the iron too hot for too long, but not long enough and you might get a cold joint that isn't complete. Look up tutorials for a beetter idea.

I went for handwired initially, but didn't have a great seat for the knobs or board. Hot glue got annoying, so I got splitkb aurora corne and snapped off columns.

I used QMK to do stuff. You can use python pip to install qmk.

python3 -m pip install qmk

qmk setup # after installing

Then config with

qmk config compile.keyboard=splitkb/aurora/corne/rev1 compile.keymap=default

Flash to each half with

qmk flash # double click reset to flash

There is a ton of amazing customization options. I have layers and combos for passwords, pins, shortcuts, macros, gaming, etc...

https://splitkb.com/collections/keyboard-kits/products/aurora-corne

https://www.littlekeyboards.com/collections/corne-cases/products/mini-corne-technician-keyboard-case?variant=40212013449283

This is great and I appreciate it being posted.

I really want to figure out how to get into at least some linux development, purely for my own greedy purposes of wanting to have a working machine.

This is a delightful article. Parts of it had me giggling to myself, and I honestly learned more about some linux basics than I expected.

Trivial! The tricky part is to make this driver to work correctly :)

As I was doing that, I also thought I’d message the vendor and ask them if they could share any specifications or docs regarding their protocol. To my surprise, Nanoleaf tech support responded to me within 4 hours, with a full description of the protocol that’s used both by the Desk Dock as well as their RGB strips.

Now that is cool.

Whatever Nanoleaf is, now I need to go and check it out.

Ill have to give them a try!

Neat. I have a wireless usb headset(Lucidsound ls50x) that I'm trying to do the same for but have zero Linux experience. This is a good read for me. Thanks for sharing!

Very enjoyable writing style

Very cool! Added the RSS.

Great writeup, great read!

Nice. Now what do I do if I have ~0 device driver experience^[not fully 0, because I might have used setpci a few times and built some drivers from source]?
Oh and I also have 0 devices to make a driver for :P, so need to fix that too.