Internal tools
GPIO from laptop
Ever tried to toggle a GPIO pin from your laptop? 🤔
Turns out it is (or was) much harder than you’d think.
I ran into this surprisingly awkward problem while building a test setup: I needed to toggle boot pins for the target from my laptop. But how? I first tried an Adafruit FT232H Breakout, but I had to reflash the EEPROM with special tooling, and even risked bricking the device in the process. And that cost me ~15€ for just 4 GPIOs.
This bugged me. Every micro-controller can do that with a few lines of C code and they have plenty of GPIOs! At this point I wondered if maybe someone had already written a firmware I could use for some microcontroller, that just exposes the GPIO pins via USB to the PC. But I found nothing. I assumed this may be due to hidden complexity for custom USB drivers.
Then I wondered, can’t that just use the same driver as the FT232H? I did a quick search through the Linux kernel and found out that there are some more (but very few) drivers for USB-to-GPIO devices. One caught my eye, the “dln2” driver: It not only supports GPIO, but also I2C, ADC, and SPI. It’s also well written and the interface is simple to understand.
So I took a stab at it. I chose the Raspberry Pi Pico and wrote a small firmware utilizing TinyUSB, basically just a shim to map the kernel interface to the Pico SDK interface. It was really exciting when I got the first error messages and warnings from the kernel driver, meaning the detection and loading of the driver worked! Not too much later I was able to toggle my first GPIO. 🎉
A few joyous coding sessions later, it has become a really useful tool, providing not only GPIO, but also ADC, I2C and UART. It’s also super simple to install, thanks to the factory included bootloader on all Raspberry Pi Picos. You just drag-and-drop the firmware onto the Pico. You don’t even need to open a terminal. And you don’t need to install a driver either, since it has been in the Linux kernel for multiple years now, so all current distros are shipped with it. The last, most beautiful part of it (for me) is that it works with standard tooling for GPIO (gpiod) and I2C (i2c-tools).
Of course, it has nowhere near the performance that other commercial solutions provide, but it’s cheap and easy to set up, and you probably already have it in your drawer. 😉
Would love feedback if you try it out! 🙌
/GS




