blob: fcc2d5411f75ce3cb025d9e8426658c92dcc8758 [file] [log] [blame]
ThuBaNguyen7b452822021-06-06 14:36:07 +07001#!/bin/bash
2
3function 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
9function 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
17function 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
25function 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}