
How to Control GPIO on OK3568-C Using libgpiod (Buildroot Linux 4.19.206)
This guide introduces how to control GPIOs using the libgpiod library under Buildroot (Linux 4.19.206). Based on the Rockchip RK3568 processor, the board supports modern GPIO management through character device interfaces, replacing the deprecated sysfs method.
1. GPIOD Description
Libgpiod is a user-space API for the Linux kernel GPIO (General-Purpose Input/Output) driver library. It provides a simple way to control GPIO lines in Linux systems, which are usually connected to digital input/output ports on hardware devices, such as LEDs, buttons, etc. With libgpiod, applications can easily open, read, write, and configure the state of the GPIO line to operate hardware devices and support cross-platform programming. Since Linux 4.8, the GPIO sysfs interface has been deprecated. User space should use libgpiod to interact with the GPIO character device instead.
2. Open GPIOD Function
Open Buildroot's graphical configuration interface and check the following options.
After regenerating and flashing the new filesystem, open the development board debugging tool.
The development board has created the node **/dev/gpioN**.
[root@ok3568:/dev]# ls gpio* gpiochip0 gpiochip1 gpiochip2 gpiochip3 gpiochip4 gpiochip5
At this point, the development board supports the **gpiod** dynamic library.
[root@ok3568:/usr/lib]# ls libgpiod.so* libgpiod.so libgpiod.so.0 libgpiod.so.0.3.2
3. Commonly Used GPIOD Commands
3.1 gpiodetect lists all GPIO controllers in the system.
[root@ok3568:/]# gpiodetect gpiochip5 [rk817-gpio] (1 lines) gpiochip4 [gpio4] (32 lines) gpiochip3 [gpio3] (32 lines) gpiochip2 [gpio2] (32 lines) gpiochip1 [gpio1] (32 lines) gpiochip0 [gpio0] (32 lines)
3.2 gpioinfo: Displays information about the GPIO device.
[root@ok3568:/]# gpioinfo gpiochip5 - 1 lines: line 0: unnamed unused input active-high gpiochip4 - 32 lines: line 0: unnamed unused input active-high line 1: unnamed unused input active-high line 2: unnamed unused input active-high line 3: unnamed unused input active-high line 4: unnamed unused input active-high line 5: unnamed unused input active-high line 6: unnamed unused input active-high line 7: unnamed unused input active-high line 8: unnamed unused input active-high line 9: unnamed unused input active-high line 10: unnamed unused output active-high line 11: unnamed unused input active-high line 12: unnamed unused input active-high line 13: unnamed unused input active-high line 14: unnamed unused input active-high line 15: unnamed unused input active-high line 16: unnamed unused input active-high ...... //Select part of the printing information
3.3 gpioget: Reads GPIO input:
[root@ok3568:/]# gpioget gpiochip4 0 1
3.4 gpioset: Sets the GPIO level
Command operation test using GPIO3\_A7 as an example.
Output:
[root@ok3568:/sys/class/gpio]# gpioset gpiochip3 7=0 //Set the pin to low level; at this time, the D6 LED on the development board is ON. [root@ok3568:/sys/class/gpio]# gpioset gpiochip3 7=1 //Set the pin to high level; at this time, the D6 LED on the development board is Off.
Note: Unlike the traditional sysfs, by default, **gpioset** exits immediately after setting the level. The GPIO state at this time is defined by the hardware and may behave differently across different products.
If a persistent output level is required, specify the working mode as **signal**, as shown in the following example.
[root@ok3568:/]# gpioset -m signal gpiochip0 0=1 //(Press Ctrl+C to stop)
3.5 gpiomon: Monitors GPIO events:
Test pin GPIO3\_C1.
[root@ok3568:/]# gpiomon gpiochip3 17 event: RISING EDGE offset: 17 timestamp: [1722306410.568497882] // The pin is connected to a 3.3V power supply. event: FALLING EDGE offset: 17 timestamp: [1722306410.568556216] //The pin is disconnected from the 3.3V power supply. //(Press Ctrl+C to stop)
This article provides a detailed introduction to the libgpiod-based GPIO control process on the OK3568 development board running the Buildroot system, covering environment setup, command usage, and important notes. The purpose is to provide a verified practical guide that enables engineers to quickly apply libgpiod for controlling hardware GPIO lines in real-world development.