pub/scm/libs/libgpiod/libgpiod.git  about / heads / tags
C library and tools for interacting with the linux GPIO character device
$ git log --pretty=format:'%h %s (%cs)%d'
27fe101 bindings: python: tests: run the Value cast test with the rest of the suite (2024-05-23)
	(HEAD -> master)
c8e3ae0 bindings: python: tests: add test for casting line.Value to bool (2024-05-23)
5f9152b bindings: python: support casting line.Value to bool (2024-05-23)
47424e1 TODO: add a task for migrating C++ tests to Catch2 v3 (2024-05-23)
3ece522 bindings: python: tests: fix invalid syntax warnings (2024-05-22)
0a552e7 tests: add enable_debounce_then_edge_detection (2024-05-15)
4caa127 build: drop the LGPL-3.0 license file from EXTRA_DIST (2024-05-13)
35003a8 tools: tests: accept the new gpio-sim label format in test cases (2024-05-07)
c34a572 tools: add minutes as a new supported time unit (2024-04-24)
e943b14 tools: allow longer time periods (2024-04-24)

$ git cat-file blob HEAD:README
# SPDX-License-Identifier: CC-BY-SA-4.0
# SPDX-FileCopyrightText: 2017-2023 Bartosz Golaszewski <>


  libgpiod - C library and tools for interacting with the linux GPIO
             character device (gpiod stands for GPIO device)

Since linux 4.8 the GPIO sysfs interface is deprecated. User space should use
the character device instead. Version 2 of libgpiod requires GPIO character
device uAPI v2 which was first released in linux 5.10. This library
encapsulates the ioctl calls and data structures behind a straightforward API.


The new character device interface guarantees all allocated resources are
freed after closing the device file descriptor and adds several new features
that are not present in the obsolete sysfs interface (like event polling,
setting/reading multiple values at once or open-source and open-drain GPIOs).

Unfortunately interacting with the linux device file can no longer be done
using only standard command-line tools. This is the reason for creating a
library encapsulating the cumbersome, ioctl-based kernel-userspace interaction
in a set of convenient functions and opaque data structures.

Additionally this project contains a set of command-line tools that should
allow an easy conversion of user scripts to using the character device.


This is a pretty standard autotools project. The core C library does not have
any external dependencies other than the standard C library with GNU extensions.

The command-line tools optionally depend on libedit for the interactive feature.

To build the project (including command-line utilities) run:

    ./ --enable-tools=yes --prefix=<install path>
    make install

The autogen script will execute ./configure and pass all the command-line
arguments to it.

If building from release tarballs, the configure script is already provided and
there's no need to invoke

For all configure features, see: ./configure --help.


There are currently six command-line tools available:

* gpiodetect - list all gpiochips present on the system, their names, labels
               and number of GPIO lines

* gpioinfo   - list lines, their gpiochip, offset, name, and direction, and
               if in use then the consumer name and any other configured
               attributes, such as active state, bias, drive, edge detection
               and debounce period

* gpioget    - read values of specified GPIO lines

* gpioset    - set values of specified GPIO lines, holding the lines until the
               process is killed or otherwise exits

* gpiomon    - wait for edge events on GPIO lines, specify which edges to watch
               for, how many events to process before exiting, or if the events
               should be reported to the console

* gpionotify - wait for changed to the info for GPIO lines, specify which
               changes to watch for, how many events to process before exiting,
               or if the events should be reported to the console


    (using a Raspberry Pi 4B)

    # Detect the available gpiochips.
    $ gpiodetect
    gpiochip0 [pinctrl-bcm2711] (58 lines)
    gpiochip1 [raspberrypi-exp-gpio] (8 lines)

    # Read the info for all the lines on a gpiochip.
    $ gpioinfo -c 1
    gpiochip1 - 8 lines:
     line   0: "BT_ON"          output
     line   1: "WL_ON"          output
     line   2: "PWR_LED_OFF"    output active-low consumer="led1"
     line   3: "GLOBAL_RESET"   output
     line   4: "VDD_SD_IO_SEL"  output consumer="vdd-sd-io"
     line   5: "CAM_GPIO"       output consumer="cam1_regulator"
     line   6: "SD_PWR_ON"      output consumer="sd_vcc_reg"
     line   7: "SD_OC_N"        input

    # Read the info for particular lines.
    gpiochip0 42 "STATUS_LED_G_CLK" output consumer="led0"
    gpiochip1 2 "PWR_LED_OFF"    output active-low consumer="led1"
    gpiochip1 3 "GLOBAL_RESET"   output

    # Read the value of a single GPIO line by name.
    $ gpioget RXD1

    # Read the value of a single GPIO line by chip and offset.
    $ gpioget -c 0 15

    # Read the value of a single GPIO line as a numeric value.
    $ gpioget --numeric RXD1

    # Read two values at the same time. Set the active state of the lines
    # to low and without quoted names.
    $ gpioget --active-low --unquoted GPIO23 GPIO24
    GPIO23=active GPIO24=active

    # Set the value of a line and hold the line until killed.
    $ gpioset GPIO23=1

    # Set values of two lines, then daemonize and hold the lines.
    $ gpioset --daemonize GPIO23=1 GPIO24=0

    # Set the value of a single line, hold it for 20ms, then exit.
    $ gpioset --hold-period 20ms -t0 GPIO23=1

    # Blink an LED on GPIO22 at 1Hz
    $ gpioset -t500ms GPIO22=1

    # Blink an LED on GPIO22 at 1Hz with a 20% duty cycle
    $ gpioset -t200ms,800ms GPIO22=1

    # Set some lines interactively (requires --enable-gpioset-interactive)
    $ gpioset --interactive --unquoted GPIO23=inactive GPIO24=active
    gpioset> get
    GPIO23=inactive GPIO24=active
    gpioset> toggle
    gpioset> get
    GPIO23=active GPIO24=inactive
    gpioset> set GPIO24=1
    gpioset> get
    GPIO23=active GPIO24=active
    gpioset> toggle
    gpioset> get
    GPIO23=inactive GPIO24=inactive
    gpioset> toggle GPIO23
    gpioset> get
    GPIO23=active GPIO24=inactive
    gpioset> exit

    # Wait for three rising edge events on a single GPIO line, then exit.
    $ gpiomon --num-events=3 --edges=rising GPIO22
    10002.907638045	rising	"GPIO22"
    10037.132562259	rising	"GPIO22"
    10047.179790748	rising	"GPIO22"

    # Wait for three edge events on a single GPIO line, with time in local time
    # and with unquoted line name, then exit.
    $ gpiomon --num-events=3 --edges=both --localtime --unquoted GPIO22
    2022-11-15T10:36:59.109615508	rising	GPIO22
    2022-11-15T10:36:59.129681898	falling	GPIO22
    2022-11-15T10:36:59.698971886	rising	GPIO22

    # Wait for falling edge events with a custom output format.
    $ gpiomon --format="%e %c %o %l %S" --edges=falling -c gpiochip0 22
    2 gpiochip0 22 GPIO22 10946.693481859
    2 gpiochip0 22 GPIO22 10947.025347604
    2 gpiochip0 22 GPIO22 10947.283716669
    2 gpiochip0 22 GPIO22 10947.570109430

    # Block until an edge event occurs. Don't print anything.
    $ gpiomon --num-events=1 --quiet GPIO22

    # Monitor multiple lines, exit after the first edge event.
    $ gpiomon --quiet --num-events=1 GPIO5 GPIO6 GPIO12 GPIO17

    # Monitor a line for changes to info.
    $ gpionotify GPIO23
    11571.816473718	requested	"GPIO23"
    11571.816535124	released	"GPIO23"
    11572.722894029	requested	"GPIO23"
    11572.722932843	released	"GPIO23"
    11573.222998598	requested	"GPIO23"

    # Monitor a line for requests, reporting UTC time and unquoted line name.
     $ gpionotify --utc --unquoted GPIO23
    2022-11-15T03:05:23.807090687Z	requested	GPIO23
    2022-11-15T03:05:23.807151390Z	released	GPIO23
    2022-11-15T03:05:24.784984280Z	requested	GPIO23
    2022-11-15T03:05:24.785023873Z	released	GPIO23

    # Monitor multiple lines, exit after the first is requested.
    $ gpionotify --quiet --num-events=1 --event=requested GPIO5 GPIO6 GPIO12 GPIO17

    # Block until a line is released.
    $ gpionotify --quiet --num-events=1 --event=released GPIO6


High-level, object-oriented bindings for C++, python3 and Rust are provided.
They can be enabled by passing --enable-bindings-cxx, --enable-bindings-python
and --enable-bindings-rust arguments respectively to configure.

C++ bindings require C++11 support and autoconf-archive collection if building
from git.

Python bindings require python3 support and libpython development files. Please
refer to bindings/python/ for more information.

Rust bindings require cargo support. When building the Rust bindings along the
C library using make, they will be automatically configured to build against the
build results of the C library. Please refer to bindings/rust/libgpiod/
for more information.


A comprehensive testing framework is included with the library and can be
used to test both the core library code as well as the kernel-to-user-space

The minimum kernel version required to run the tests can be checked in the
tests/gpiod-test.c source file (it's subject to change if new features are
added to the kernel). The tests work together with the gpio-sim kernel module
which must either be built-in or available for loading using kmod. A helper
library - libgpiosim - is included to enable straightforward interaction with
the module.

To build the testing executable add the '--enable-tests' option when running
the configure script. If enabled, the tests will be installed next to

As opposed to standard autotools projects, libgpiod doesn't execute any tests
when invoking 'make check'. Instead the user must run them manually with
superuser privileges.

The testing framework uses the GLib unit testing library so development package
for GLib must be installed.

The gpio-tools programs can be tested separately using the gpio-tools-test.bash
script. It requires shunit2[1] to run and assumes that the tested executables are
in the same directory as the script.

C++, Rust and Python bindings also include their own test-suites. All three
reuse the libgpiosim library to avoid code duplication when interacting with

Python test-suite uses the standard unittest package. C++ tests use an external
testing framework - Catch2 - which must be installed in the system. Rust
bindings use the standard tests module layout and the #[test] attribute.


All API symbols exposed by the core C API and C++ bindings are documented with
doxygen markup blocks. Doxygen documentation can be generated by executing
'make doc' given that the doxygen executable is available in the system.

Python bindings contain help strings that can be accessed with the help

Rust bindings use rustdoc.

Man pages for command-line programs are generated automatically if gpio-tools
were selected and help2man is available in the system.


Contributions are welcome - please send questions, patches and bug reports
to the linux-gpio mailing list[2] by e-mailing to
(add the [libgpiod] prefix to the e-mail subject line).
Note that the mailing list quietly drops HTML formatted e-mail, so be sure
to send plain text[3].

Code submissions should stick to the linux kernel coding style[4] and
follow the kernel patch submission process[5] as applied to the libgpiod
source tree.

The mailing list archive[6] contains all the historical mails to the list,
and is the place to check to ensure your e-mail has been received.
Search for "libgpiod" to filter the list down to relevant messages.
Those also provide examples of the expected formatting.
Allow some time for your e-mail to propagate to the list before retrying,
particularly if there are no e-mails in the list more recent than yours.

There is a libgpiod github page[7] available for reporting bugs and general
discussions and although PRs can be submitted and discussed, upstreambound
patches need to go through the mailing list nevertheless while release
tarballs should be fetched from[8].

For more information, refer to in this repository.


# heads (aka `branches'):
$ git for-each-ref --sort=-creatordate refs/heads \
	--format='%(HEAD) %(refname:short) %(subject) (%(creatordate:short))'
* master       bindings: python: tests: run the Value cast test with the rest of the suite (2024-05-23)
  v2.1.x       libgpiod v2.1.2 (2024-05-13)
  v2.0.x       libgpiod v2.0.2 (2023-08-25)
  v1.6.x       tests: mockup: unbind mockup devices before unloading the module (2023-08-24)
  v1.4.x       libgpiod v1.4.5 (2020-10-30)
  v1.5.x       libgpiod v1.5.3 (2020-09-25)
  v1.3.x       man: fix out of source build (2019-04-15)
  v1.2.x       core: ctxless: bail-out if num_lines == 0 (2019-03-06)
  v1.1.x       libgpiod v1.1.2 (2018-11-09)
  v1.0.x       libgpiod v1.0.2 (2018-06-07)

# tags:
$ git for-each-ref --sort=-creatordate refs/tags \
	--format='%(refname:short) %(subject) (%(creatordate:short))'
v2.1.2       libgpiod v2.1.2 (2024-05-13) tar.gz
v2.1.1       libgpiod v2.1.1 (2024-03-10) tar.gz
v2.1         libgpiod v2.1 (2023-11-03) tar.gz
v2.0.2       libgpiod v2.0.2 (2023-08-25) tar.gz
v2.0.1       libgpiod v2.0.1 (2023-04-11) tar.gz
v2.0         libgpiod v2.0 (2023-03-02) tar.gz
v2.0-rc3     libgpiod v2.0-rc3 (2023-02-23) tar.gz
v2.0-rc2     libgpiod v2.0-rc2 (2023-02-15) tar.gz
v1.6.4       libgpiod v1.6.4 (2023-02-08) tar.gz
v2.0-rc1     libgpiod v2.0-rc1 (2023-02-08) tar.gz

# associated public inboxes:
# (number on the left is used for dev purposes)
       1298 linux-gpio
         36 lkml
         14 netdev
          9 qemu-devel
          9 stable
          8 linux-arm-kernel
          8 dpdk-dev
          8 u-boot
          6 linux-media
          5 git
          4 linux-xfs
          4 bpf
          4 linux-acpi
          4 linux-devicetree
          4 xen-devel
          4 linux-input
          4 linux-scsi
          4 linux-rdma
          3 linux-wireless
          3 linux-block
          3 linux-cifs
          3 linux-arm-msm
          3 alsa-devel
          3 linux-btrfs
          3 linuxppc-dev
          3 dri-devel
          3 linux-omap
          3 buildroot
          3 openembedded-core
          3 linux-patches
          2 linux-nfs
          2 linux-crypto
          2 netfilter-devel
          2 linux-fsdevel
          2 linux-mm
          2 linux-nvdimm
          2 linux-kselftest
          2 selinux
          2 kernel-hardening
          2 linux-iio
          2 linux-pci
          2 kvm
          2 linux-ide
          2 linux-watchdog
          2 linux-trace-devel
          2 linux-m68k
          2 util-linux
          2 linux-doc
          2 linux-man
          2 amd-gfx
          2 linux-spi
          2 linux-i2c
          2 linux-pwm
          2 linux-tegra
          2 linux-raid
          2 platform-driver-x86
          2 openbmc
          2 linux-hardening
          2 dm-devel
          2 linux-fbdev
          2 linux-cxl
          2 nvdimm
          2 fio
          2 ofono
          2 openembedded-devel
          2 yocto-meta-virtualization
          2 openrisc
          2 kexec
          2 poky
          2 grub-devel
          2 autofs
          2 reiserfs-devel
          2 ../../../../../igt-dev
          1 linux-samsung-soc
          1 linux-fscrypt
          1 linux-mtd
          1 cocci
          1 linux-riscv
          1 linux-nvme
          1 live-patching
          1 linux-mediatek
          1 linux-efi
          1 linux-integrity
          1 linux-edac
          1 linux-amlogic
          1 linux-erofs
          1 linux-iommu
          1 linux-snps-arc
          1 linux-mips
          1 fstests
          1 linux-pm
          1 linux-hwmon
          1 linux-rtc
          1 kvmarm
          1 driverdev-devel
          1 linux-usb
          1 linux-renesas-soc
          1 linux-clk
          1 dmaengine
          1 linux-next
          1 linux-parisc
          1 linux-ext4
          1 linux-leds
          1 linux-security-module
          1 linux-f2fs-devel
          1 linux-modules
          1 kernelnewbies
          1 linux-rt-users
          1 linux-bluetooth
          1 linux-sgx
          1 linux-serial
          1 linux-hyperv
          1 workflows
          1 rcu
          1 linux-i3c
          1 linux-spdx
          1 linux-wpan
          1 ksummit-discuss
          1 wireguard
          1 backports
          1 io-uring
          1 linux-kernel-mentees
          1 linux-csky
          1 linux-mmc
          1 intel-gfx
          1 tpmdd-devel
          1 linux-unionfs
          1 linux-firmware
          1 linux-api
          1 cip-dev
          1 linux-audit
          1 linux-remoteproc
          1 linux-dash
          1 linux-bcache
          1 linux-sparse
          1 mm-commits
          1 lttng-dev
          1 virtualization
          1 linux-kbuild
          1 linux-fpga
          1 ceph-devel
          1 linux-arch
          1 linux-can
          1 containers
          1 linux-rockchip
          1 xdp-newbies
          1 phone-devel
          1 dash
          1 keyrings
          1 linux-sctp
          1 linux-perf-users
          1 target-devel
          1 lustre-devel
          1 linux-sh
          1 soc
          1 ocfs2-devel
          1 rust-for-linux
          1 ath10k
          1 ath11k
          1 nouveau
          1 linux-phy
          1 linux-s390
          1 kernel-janitors
          1 sparclinux
          1 linux-staging
          1 linux-sunxi
          1 mptcp
          1 linux-coco
          1 regressions
          1 ksummit
          1 b43-dev
          1 linux-nfc
          1 linux-bcachefs
          1 ath9k-devel
          1 ntfs3
          1 llvm
          1 iwd
          1 ell
          1 ltp
          1 yocto
          1 yocto-meta-freescale
          1 yocto-toaster
          1 yocto-meta-arm
          1 yocto-docs
          1 bitbake-devel
          1 chrome-platform
          1 ntb
          1 yocto-meta-ti
          1 yocto-meta-arago
          1 outreachy
          1 xenomai
          1 damon
          1 asahi
          1 intel-wired-lan
          1 loongarch
          1 imx
          1 ath12k
          1 b4-sent
          1 linux-trace-kernel
          1 oe-linux-nfc
          1 oe-kbuild-all
          1 oe-chipsec
          1 batman
          1 intel-xe
          1 linux-um
          1 virtio-dev
          1 virtio-comment
          1 v9fs
          1 ecryptfs
          1 qemu-riscv
          1 linux-ia64
          1 cluster-devel
          1 kbd
          1 cpufreq
          1 dccp
          1 cgroups
          1 devicetree-spec
          1 devicetree-compiler
          1 initramfs
          1 kvm-ppc
          1 hail-devel
          1 kvm-ia64
          1 linux-8086
          1 kernel-testers
          1 linux-alpha
          1 linux-btrace
          1 linux-embedded
          1 linux-hams
          1 linux-hexagon
          1 linux-hotplug
          1 linux-laptop
          1 linux-sound
          1 trinity
          1 linux-metag
          1 linux-x25
          1 linux-nilfs
          1 lvs-devel
          1 netfilter
          1 linux-oxnas
          1 u-boot-amlogic
          1 lm-sensors
          1 lvm-devel
          1 acpica-devel
          1 perfbook
          1 virtio-fs
          1 smatch
          1 ../../../../../fuego
          1 ../../../../../wireless-regdb
          1 ../../../../../powertop

git clone