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