Linux kernel Gpio Port programming entry __ Block chain

Source: Internet
Author: User

1. API interface

Request Gpio Port

int gpio_request (unsigned gpio, const char *label) free Gpio port

void Gpio_free (unsigned gpio)
Determine if the GPIO index number is valid (Gpio port exists)

int gpio_is_valid (int number);


Set Output: int gpio_direction_output (unsigned gpio, int value)


Set Input:

int gpio_direction_input (unsigned gpio)


Converts the Gpio port to the corresponding interrupt number

int Gpio_to_irq (unsigned gpio);


Interrupt Request REQUEST_IRQ


2. Code path:
2.1 DRIVERS/GPIO/GPIOLIB.C


3. Debugging Gpio Port

Perform:

echo >/sys/class/gpio/export


Subdirectories are generated under the/sys/class/gpio directory: gpio100, which has the following files:

Active_low direction
Power
Subsystem
Uevent
Value


cd/sys/class/gpio/gpio100


Gpio Port set to output: Echo out > Direction


Output High Level: Echo 1 > Value


Output low Level: Echo 0 > value


In addition, there is a LUA kernel porting project that already contains the read and write capabilities of the Gpio port, and the code path is as follows:

Https://github.com/negtise/luak-arm

Use the method to see the HowTo.txt in the Code root directory


In addition, you can view the information of the Gpio port through Cat/sys/kernel/debug/gpio.

4. Reference Documentation:
Linux/documentation/gpio.txt

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.