The full name of GPIO: General Purpose Input/Output (General Purpose Input and Output), which is a general-purpose pin that can be dynamically configured and controlled during software running. On the RK platform, except for some dedicated pins (such as DDR, MIPI, etc.), if other pins are not configured for multiplexing, the default multiplexing state is GPIO. RK's GPIO driver provides a standard GPIO interface. There is a set of sysfs nodes in user mode that operate GPIO under Android. Programming of GPIO at the application layer is mainly achieved by operating these nodes.
The following takes the operation of GPIO3_A5 as an example to introduce. The location of this GPIO is as follows
“/sys/class/gpio” The following nodes require root permissions to operate. Using the command line or a program compiled in C language to operate gpio requires root permissions. First execute the following command to obtain root permissions.
sudo su
Under the general Linux framework, all GPIOs are numbered. For the chips of the RK platform, the number calculation method is:
(gpio controller number-0)*32+(port number-‘A’)*8+index number
The controller number of GPIO3_A5 is 3, the port number is A, and the index number is 5, so the number is
(3-0)32+08+5=101
Set GPIO 101 to user mode operation
echo 101 > /sys/class/gpio/export
Set GPIO 101 as output
echo out > /sys/class/gpio/gpio101/direction
In the case where GPIO 101 is output, set the level
high level
echo 1 > /sys/class/gpio/gpio101/value
low level
echo 0 > /sys/class/gpio/gpio101/value
Set GPIO 101 as input
echo in > /sys/class/gpio/gpio101/direction
When GPIO 101 is an input, read its level. 1 is high and 0 is low.
cat /sys/class/gpio/gpio101/value
Cancel GPIO 101 user mode operation
echo 101 > /sys/class/gpio/unexport
As shown in the picture