The Linux development platform implements a generic Gpio driver that allows the user to control the output of the GPIO and read its input values through a shell or system call. Its properties files are in the/sys/class/gpio/directory, the directory has export and Unexport two properties files, the rest are connection files, such as GPIOCHIPN.
Export file exports a Gpio,unexport to remove the exported gpio from/SYSFS. Write to the export file the Gpio ordinal n to be manipulated to export the corresponding GPIO device directory, for example:
#echo 68>/sys/class/gpio/export
The gpio68/directory is generated under the/sys/class/gpio/directory with the above operation. The Gpio pin can be manipulated by reading and writing the properties file under the directory. This directory has a subordinate file:
1, Active_low: Has read and write properties, determines whether the value in the values are flipped, 0 does not flip, 1 flips.
2, Edge: With Read and write properties, set Gpio interrupt or detect whether the interrupt occurs.
3, Subsystem: Symbolic link, pointing to the parent directory.
4, Value: With Read and write properties, Gpio pin level properties Read or set
5. Direction: With read/write properties for setting or viewing the GPIO pin input/output direction
6. Power: Information related to equipment and power supply
7. Uevent: Communication interface between kernel and (Udev, automatic Device Discovery program).
Input and Output settings:
#echo out>/sys/class/gpio/gpion/direction #设置输出
#echo in>/sys/class/gpio/gpion/direction #设置输入
Input read:
#echo in>/sys/class/gpio/gpion/direction #设置输入
#cat/sys/class/gpio/gpion/value #查看电平
Output control:
#echo out>/sys/class/gpio/gpion/direction
#echo 0>/sys/class/gpio/gpion/value #输出低电平
#echo 1>/sys/class/gpio/gpion/value #输出高电平
Operation of Gpio in C
int Fd_export=open ("/sys/class/gpio/export", 0_rdwr);//Open GPIO export device
Write (Fd_export, "n",, strlen ("n"));
Close (Fd_export);
int fd_direcction = open ("/sys/class/gpio/gpion/direction", O_RDWR);
Write (Fd_direction, "Out", strlen ("Out"));//Set to Output
Close (fd_direction);
int Fd_value=open ("/sys/' Class/gpio/gpion/value", O_RDWR);
Write (Fd_value, "1", strlen ("1"));
Close (Fd_value);
Linux generic Gpio Driver