Userspace operation GPIO

Userspace means after the system starts.
First of all, it is necessary to set the GPIO mode in Infinity2M-SSC011A-S01A-PADMUX-XXX. DTSI (refer to drivers to use GPIO) and load the GPIO SYSFS Interface module:

# ARCH=arm make menuconfig

With this configuration, we will see the /sys/class/ GPIO directory when the system starts up. In this directory, we can operate the input and output of GPIO.

output mode:

# echo 12 > /sys/class/gpio/export            //Apply for GPIO
# echo out > /sys/class/gpio/gpio12/direction //Set to output mode
# echo 1 > /sys/class/gpio/gpio12/value       //Output high level
# echo 0 > /sys/class/gpio/gpio12/value       //Output low level
# echo 12 > /sys/class/gpio/unexport          //Uninstall the GPIO

input mode:

# echo 12 > /sys/class/gpio/export           //Apply for GPIO
# echo in > /sys/class/gpio/gpio12/direction //Set to input mode
# cat /sys/class/gpio/gpio12/value           //Gets the input level
文档更新时间: 2022-11-07 16:32   作者:Aeeditor