Linux provides two APIs for user space programs to interact with GPIO lines, a legacy
sysfs based API and a newer character device based API using
ioctl. The legacy
sysfs API is documented to be removed soon:
This ABI is deprecated and will be removed after 2020. It is replaced with the GPIO character device.
The newer character device is controlled with
ioctl calls and has a complementary library called
libgpiod. It provides C library with C++ and Python bindings to manipulate GPIO via the newer API. The library also ships with a few utility command line tools like
gpiodetect which expose basic functionality of
libgpiod over the CLI.
Unfortunately on Ubuntu 21.10 (Impish)
libgpiod is not usable at all. For example the
gpioinfo tool fails with the following error when trying to look up the details for a GPIO line.
gpiofind will fail as well with the same error.
The root cause of this is that there are two
ioctl based APIs. The first one was introduced in Linux v4.6 and the second was introduced in Linux v5.10. The first one is behind a configuration flag which is called
Unfortunately Ubuntu 21.10 ships with
libpgiod 1.6.2 which uses the v1
ioctl API. The V1 API is disabled in the Ubuntu 21.10 generic arm64 kernel.
As a consequence all of the
ioctl calls that
libgpiod makes will result in an “Invalid Argument” error, because the
ioctl is not available.
There are two possible solutions:
Build your own kernel with
Use another library like
gpiodwhich uses the newer