blob: 8d1aa61d7730cc71e8a620f4b45eefdeccf952cb [file] [log] [blame]
ThuBaNguyen7b452822021-06-06 14:36:07 +07001#!/bin/bash
ThuBaNguyen33109172021-07-02 15:39:57 +07002source /usr/sbin/gpio-defs.sh
ThuBaNguyen7b452822021-06-06 14:36:07 +07003
4function gpio_number() {
ThuBaNguyen33109172021-07-02 15:39:57 +07005 GPIO_BASE=$(cat /sys/class/gpio/gpiochip$GPIO_CHIP0_BASE/base)
ThuBaNguyen7b452822021-06-06 14:36:07 +07006 echo $((${GPIO_BASE} + $1))
7}
8
9# Configure GPIO as output and set its value
10function gpio_configure_output() {
11 gpioId=$(gpio_number $1)
12 echo $gpioId > /sys/class/gpio/export
13 echo out > /sys/class/gpio/gpio${gpioId}/direction
14 echo $2 > /sys/class/gpio/gpio${gpioId}/value
15 echo $gpioId > /sys/class/gpio/unexport
16}
17
18function gpio_get_val() {
19 gpioId=$(gpio_number $1)
20 echo $gpioId > /sys/class/gpio/export
21 echo $(cat /sys/class/gpio/gpio$gpioId/value)
22 echo $gpioId > /sys/class/gpio/unexport
23}
24
25# Configure GPIO as input
26function gpio_configure_input() {
27 gpioId=$(gpio_number $1)
28 echo $gpioId > /sys/class/gpio/export
29 echo "in" > /sys/class/gpio/gpio${gpioId}/direction
30 echo $gpioId > /sys/class/gpio/unexport
31}