Ubuntu 16.04
$ echo “4”>/sys/class/gpio/export | 建立 gpio4 node |
$ echo “in”>/sys/class/gpio/gpio4/direction | 設 gpio4 為 input |
$ echo “out”>/sys/class/gpio/gpio4/direction | 設 gpio4 為 output |
$ echo “1”>/sys/class/gpio/gpio4/value | output High to gpio4 |
$ echo “0”>/sys/class/gpio/gpio4/value | output Low to gpio4 |
$ echo “4”>/sys/class/gpio/unexport | 取消 gpio4 node |
查看系統 GPIOs 狀態 (FP5 platform):
$ sudo cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 256-511, parent: platform/AMDI0030:00, AMDI0030:00:
GPIO bank0 pin0 interrupt is disabled| interrupt is masked| disable wakeup in S0i3 state| disable wakeup in S3 state| disable wakeup in S4/S5 state| input is high| 4k pull-up| pull-up is enabled| Pull-down is disabled| output is disabled| 0x150000
pin1 interrupt is disabled| interrupt is masked| disable wakeup in S0i3 state| disable wakeup in S3 state| disable wakeup in S4/S5 state| input is high| 4k pull-up| pull-up is enabled| Pull-down is disabled| output is disabled| 0x150000
pin2 interrupt is disabled| interrupt is masked| disable wakeup in S0i3 state| disable wakeup in S3 state| disable wakeup in S4/S5 state| input is high| 4k pull-up| pull-up is enabled| Pull-down is disabled| output is disabled| 0x150000
GPIO number shift 到 256 開始, 也就是說如果要 access gpio84, 必需使用 “340” (256+84) 來 access.
例如: echo “340”>/sys/class/gpio/export