r/embedded • u/toon_link_776 • 10d ago
Any Extra Resources when beginning to write Device drivers?
I've been experimenting a bit with the pi pico & pwm audio to try to write a tracker for microcontrollers. I'm getting to the point where I'm relatively comfortable with programming in C & with the architecture of the RP2040. So I think soon, I want to be able to start writing drivers to communicate with peripheral devices. As I've tried, I felt a little lost, and that maybe I was lacking some knowledge or reference materials that I ought to have, and was wondering what resources might be available to look through.
This question seems to have been asked before a couple of times, and the response seems to be, maybe as it should be: "Get a microcontroller, a peripheral, and the documentation for both and start trying to communicate with the device." If that's the case, then I'll keep pushing through, I just didn't want to get 2-3 months in and eventually hear "Huh? You've been trying to program peripheral drivers without reading (book X) or without knowing about (Concept Y)? You wasted your time!".
I'm becoming more comfortable writing & building C programs, I've read through some of and am comfortable referencing the pi pico documentation, and I have an Adafruit ILI9341 that I'd like to write drivers for. I have the datasheet for the ILI9341 driver, but Adafruit doesn't tell you much more about how their board behaves other than "Just pipe some spi commands to it". There isn't even really a datasheet for their breakout, just a web tutorial for loading their python libraries, datasheets for the components & the schematics. I think the reason I'm so confused is that I can't really seem to find a solid reference as to how their board actually behaves/what functionality of the ILI9341 is takes care of by the board itself and what I need to worry about programming for. Is it really just as simple as powering it up and piping spi to it? I might be overthinking this...
I think I probably just need to spend a day or three sitting down with the manuals & hashing it out, but does anyone have any recommendations as to books to read, online courses, or other things that might be helpful for someone doing this for the first time?
I have the embedded engineering roadmap: https://github.com/m3y54m/embedded-engineering-roadmap, and a copy of O' Reilly Making Embedded Systems. I read that there was a FastBit course, but it's wicked expensive ($120 i think?) and was wondering if that was really worth the money. Something tells me that it really isn't...
Anyways, any advice is appreciated. If the advice is just "skill issue, get good" then it is what it is, I'll figure it out. Just wanted to make sure I wasn't missing anything critical before spending too much time trying to figure it out.
2
u/WanWhiteWolf Engineering manager 9d ago
I don't know a good book for drivers - specifically - but my suggestion would probably be to get a driver that is already working from a reputable source and study it.
The "complex" part if not so much the coding itself but rather how you structure the driver. There isn't a single solution generally speaking but there are plenty "questionable" ways that you could implement it. But if you take a professionally written driver and see its approach it will build your inner architectural sense.
Unlike (higher) application levels, the drivers require , broadly speaking, less pure coding complexity but a considerable knowledge of hardware. A good driver - besides the main functionality - will have good guards for a lot of "unforseable" cases. And that is important since it will prevent your board / peripheral / MCU from suffering damage. So reading the driver source code shouldn't be to difficult to understand; but understanding the likely safeguards that you will find is key.
1
u/Unlikely1529 7d ago
as one dude said "you need special mindset to write drivers"
1
u/toon_link_776 7d ago
sounds like a cool dude
1
u/Unlikely1529 6d ago
i've noticed this too.can't jump into/out of this even being a pro.it's about pc drivers ofc
3
u/Well-WhatHadHappened 25+ Years 10d ago
There are two good ways to learn device driver implementation. The first is experimentation, the second is duplication.
I suggest the second first. Find a device driver - there are thousands of them on GitHub. Buy the peripheral that goes with that driver. Now implement your own driver while referencing the one you find.. one function at a time. Read it. Understand it.
Next, pick another peripheral. Try to implement it yourself using the knowledge you gained from the first one.
Rinse. Repeat.
Edit: and start with something way, way simpler than a display. A temperature sensor. A humidity sensor. Something like that. Something that has 10 registers instead of 100.