Embedded Linux development practice (13): GPIO interface development

Starting from version 4.8, the Linux kernel introduces a new character device-based user space API for managing and controlling GPIO (General Purpose Input/Output). Before Linux kernel 4.8, the only interface to manage GPIO in user space was sysfs Interface, pio is configured and controlled through the export file in /sys/class/gpio. Basic GPIO operations can be performed through this interface, such as:

1、Export a GPIO via /sys/class/gpio/export
2、Configure the GPIO direction (input/output) via: /sys/class/gpio/gpioX/direction
3、Read/write GPIO value via /sys/class/gpio/gpioX/value

The specific operation is as follows:

However, this interface has some shortcomings, such as the lack of batch GPIO reading and writing, limited GPIO configuration options (such as the inability to configure GPIO to low level, open drain, open source, etc.). When two or more processes access the same GPIO at the same time, Race condition problems may occur, GPIO polling events are unreliable, etc. Starting with version 4.8, the Linux kernel introduces a new user-space GPIO interface based on the character device chardev.

Guess you like

Origin blog.csdn.net/weixin_49369227/article/details/132562517