blob: 3e503c4909858cc9320a18af28663a06772de5e5 [file] [log] [blame]
Chanh Nguyen2fc68eb2022-04-28 09:11:28 +00001#!/bin/bash
2
3# shellcheck disable=SC2154
4# shellcheck source=/dev/null
5
6# Configure GPIO as output and set its value
7AST2600_GPIO_BASE=(
8 816
9 780
10)
11
12function gpio_configure_output() {
13 echo "$1" > /sys/class/gpio/export
14 echo out > /sys/class/gpio/gpio"$1"/direction
15 echo "$2" > /sys/class/gpio/gpio"$1"/value
16 echo "$1" > /sys/class/gpio/unexport
17}
18
19function gpio_get_val() {
20 echo "$1" > /sys/class/gpio/export
21 cat /sys/class/gpio/gpio"$1"/value
22 echo "$1" > /sys/class/gpio/unexport
23}
24
25# Configure GPIO as input
26function gpio_configure_input() {
27 echo "$1" > /sys/class/gpio/export
28 echo "in" > /sys/class/gpio/gpio"$1"/direction
29 echo "$1" > /sys/class/gpio/unexport
30}
31
32function gpio_name_set()
33{
34 str=$(gpiofind "$1")
35 #Verify error code when run gpiofind
36 if [ "$?" == '1' ]; then
37 echo "Invalid gpio name $1"
38 else
39 gpioid=$(echo "$str"|cut -c 9)
40 offset=$(echo "$str"|cut -d " " -f 2)
41 gpioPin=$(("$offset" + ${AST2600_GPIO_BASE[$gpioid]}))
42 gpio_configure_output "$gpioPin" "$2"
43 fi
44}
45
46function gpio_name_get()
47{
48 str=$(gpiofind "$1")
49 #Verify error code when run gpiofind
50 if [ "$?" == '1' ]; then
51 echo "Invalid gpio name $1"
52 else
53 offset=$(echo "$str"|cut -d " " -f 2)
54 gpioid=$(echo "$str"|cut -c 9)
55 gpioPin=$(("$offset" + ${AST2600_GPIO_BASE[$gpioid]}))
56 gpio_get_val "$gpioPin"
57 fi
58}
59
60function gpio_name_input()
61{
62 str=$(gpiofind "$1")
63 #Verify error code when run gpiofind
64 if [ "$?" == '1' ]; then
65 echo "Invalid gpio name $1"
66 else
67 gpioid=$(echo "$str"|cut -c 9)
68 offset=$(echo "$str"|cut -d " " -f 2)
69 gpioPin=$(("$offset" + ${AST2600_GPIO_BASE[$gpioid]}))
70 gpio_configure_input "$gpioPin"
71 fi
72}