ThuBaNguyen | 7b45282 | 2021-06-06 14:36:07 +0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | function gpio_number() { |
| 4 | GPIO_BASE=$(cat /sys/class/gpio/gpio*/base) |
| 5 | echo $((${GPIO_BASE} + $1)) |
| 6 | } |
| 7 | |
| 8 | # Configure GPIO as output and set its value |
| 9 | function gpio_configure_output() { |
| 10 | gpioId=$(gpio_number $1) |
| 11 | echo $gpioId > /sys/class/gpio/export |
| 12 | echo out > /sys/class/gpio/gpio${gpioId}/direction |
| 13 | echo $2 > /sys/class/gpio/gpio${gpioId}/value |
| 14 | echo $gpioId > /sys/class/gpio/unexport |
| 15 | } |
| 16 | |
| 17 | function gpio_get_val() { |
| 18 | gpioId=$(gpio_number $1) |
| 19 | echo $gpioId > /sys/class/gpio/export |
| 20 | echo $(cat /sys/class/gpio/gpio$gpioId/value) |
| 21 | echo $gpioId > /sys/class/gpio/unexport |
| 22 | } |
| 23 | |
| 24 | # Configure GPIO as input |
| 25 | function gpio_configure_input() { |
| 26 | gpioId=$(gpio_number $1) |
| 27 | echo $gpioId > /sys/class/gpio/export |
| 28 | echo "in" > /sys/class/gpio/gpio${gpioId}/direction |
| 29 | echo $gpioId > /sys/class/gpio/unexport |
| 30 | } |