Linux generic Gpio Driver

Source: Internet
Author: User
Tags parent directory

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.