I've done a lot of googling and it's only confused me further; the old /sys/class/gpio
way is deprecated and there's a rag-tag bunch of libraries that appear to have sprung up, none of which have much of an air of officialdom about them, the Raspberry Pi site only mentions the Python GPIOZero method as being the One True Way with nothing about C or command line interfaces to GPIO.
Just for example, running down the list of eLinux Raspberry Pi GPIO code samples for C:
- Direct register access behind the kernel's back is a no-no
- WiringPi is dead
- SysFS is deprecated
- bcm2835 library is not official and is using direct register access (and I'm using CM4 so BCM2711)
- piGPIO/lgpio/rgpio appears to be unofficial / potentially doing the same naughty register access / I've read comments suggesting it should not be used for production code (although that was 50 tabs ago now) and "The C library is not conventionally accessible." which does not fill me with confidence.
- ...that's it.
There also appear to possibly be two different libraries both calling themselves libgpiod/lgpio or some variant of.
Although one libgpio appears to be part of the newer kernels and thus the "favourite" so far, it doesn't seem to get mentioned in any Raspberry Pi docs / tutorials, almost as if figuring out how it should be used on a RPi is left as an exercise for the user.
What have I missed?
Edit: libgpiod seems to be the new way but not present on my Pi4 running Bullseye (gpiodetect
etc. fails command not found
, C examples fail with <gpiod.h> no such file
) despite some suggestions online that it's been installed by default in the last few releases (since Bookworm if my reading of this thread is correct), plus a reference to using /dev/gpiochip
made by Joan in that thread, it's unclear to me (and I haven't found any good looking documentation) that suggests I could do basic GPIO through the /dev/gpiochip
filesys as a reliable & portable solution.
EDIT2: If I install libgpiod-dev from Bullseye repos I can then use the command line tools, but the installed version (1.6.2-1) is somehow too new for older examples to work but too old for the current (V2.x) examples to work... this all feels somewhat Kafka-esque.