How to use GPIO
From ESS-WIKI
Revision as of 08:38, 27 April 2018 by Zhengguang.yang (talk | contribs)
Configuration/Test
Configuration
The general-purpose interface combines eight general-purpose input/output (GPIO) banks.
Each GPIO module provides 32 dedicated general-purpose pins with input and output capabilities; thus, the general-purpose interface supports up to 256 (8 × 32) pins.
The numeric value of GPIO is calculated as follows:
32 x (gpio_bank - 1) + gpio_bit
ROM-7510
GPIO Number | Linux OS(/sys/class/gpio/) | Default direction |
GPIO0 | gpio97 |
in |
GPIO1 |
gpio218 |
in |
GPIO2 |
gpio98 |
in |
GPIO3 |
gpio219 |
in |
GPIO4 |
gpio100 |
in |
GPIO5 |
gpio68 |
in |
GPIO6 |
gpio101 |
in |
GPIO7 |
gpio69 |
in |
Test
Export GPIO then you can use control GPIO from userr space through sysfs
Export GPIO0
# echo 97 > /sys/class/gpio/export
Set GPIO direction to in/out
# echo "out" > /sys/class/gpio/gpio97/direction
Set GPIO value 0/1 if GPIO pin define is output
# echo 1 > /sys/class/gpio/gpio97/value
Used as IRQ signal
Note:You have to configure GPIO to input
# echo "rising" > /sys/class/gpio/gpio97/edge
- rising: Trigger on rising edge
- falling: Trigger on falling edge
- both: Trigger on both edges
- none: Disable interrupt on both edges
Unexport GPIO0
# echo 97 > /sys/class/gpio/unexport
Test
GPIO 97 and GPIO 218 are taken as an example:
- Connect GPIO 97 and GPIO 218
- Export GPIO 97 and GPIO 218
# echo 97 > /sys/class/gpio/export # echo 218 > /sys/class/gpio/export
- Set GPIO 97 to output
# echo "out" > /sys/class/gpio/gpio97/direction
- Set GPIO 218 to input
# echo "in" > /sys/class/gpio/gpio218/direction
- Change GPIO 97 to 1 and read GPIO 218 value
# echo 1 > /sys/class/gpio/gpio97/value # cat /sys/class/gpio/gpio218/value 1
- Change GPIO 97 to 0 and read GPIO 218 value
# echo 0 > /sys/class/gpio/gpio97/value # cat /sys/class/gpio/gpio218/value 0