-
Notifications
You must be signed in to change notification settings - Fork 1
/
svxlink_gpio_up
89 lines (74 loc) · 2.73 KB
/
svxlink_gpio_up
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
##############################################################################
#
# GPIO setup script for SvxLink server. Run this script to set up the GPIO
# configuration specified in the GPIO specific configuration file
# /etc/svxlink/gpio.conf
#
##############################################################################
GPIO_CONF="/etc/svxlink/gpio.conf"
[ -r "$GPIO_CONF" ] && . "$GPIO_CONF"
# Set up the given GPIO input pin.
# Enable the given GPIO pin, set direction to input and set active state
# (active low or active high). Also set user, group and mode for the pin.
gpio_in_setup()
{
local PIN="$1"
local ACTIVE_LEVEL="$2"
if [ "$ACTIVE_LEVEL" = "low" ]; then
local ACTIVE_LOW="1"
else
local ACTIVE_LOW="0"
fi
if [ -n "$PIN" -a ! -e /sys/class/gpio/gpio$PIN ]; then
# Extract pinnumber from the full pin name (e.g. gpio4_pd0 -> 4)
local pinnum=$(echo "$PIN" | sed 's/^[^0-9]*\([0-9][0-9]*\).*$/\1/')
echo $pinnum > $GPIO_PATH/export && \
echo "in" > $GPIO_PATH/gpio$PIN/direction && \
echo "$ACTIVE_LOW" > $GPIO_PATH/gpio$PIN/active_low
[ -n "$GPIO_USER" ] && chown "$GPIO_USER" $GPIO_PATH/gpio$PIN/value
[ -n "$GPIO_GROUP" ] && chgrp "$GPIO_GROUP" $GPIO_PATH/gpio$PIN/value
[ -n "$GPIO_MODE" ] && chmod "$GPIO_MODE" $GPIO_PATH/gpio$PIN/value
fi
}
# Set up the given GPIO output pin.
# Enable the given GPIO pin, set direction to output, set active state (active
# low or active high) and reset to OFF value. Also set user, group and mode for
# the pin.
gpio_out_setup()
{
local PIN="$1"
local ACTIVE_LEVEL="$2"
if [ "$ACTIVE_LEVEL" = "low" ]; then
local ACTIVE_LOW="1"
else
local ACTIVE_LOW="0"
fi
if [ -n "$PIN" -a ! -e $GPIO_PATH/$PIN ]; then
# Extract pinnumber from the full pin name (e.g. gpio4_pd0 -> 4)
local pinnum=$(echo "$PIN" | sed 's/^[^0-9]*\([0-9][0-9]*\).*$/\1/')
echo $pinnum > $GPIO_PATH/export && \
echo "out" > $GPIO_PATH/gpio$PIN/direction && \
echo "$ACTIVE_LOW" > $GPIO_PATH/gpio$PIN/active_low && \
echo 0 > $GPIO_PATH/gpio$PIN/value
[ -n "$GPIO_USER" ] && chown "$GPIO_USER" $GPIO_PATH/gpio$PIN/value
[ -n "$GPIO_GROUP" ] && chgrp "$GPIO_GROUP" $GPIO_PATH/gpio$PIN/value
[ -n "$GPIO_MODE" ] && chmod "$GPIO_MODE" $GPIO_PATH/gpio$PIN/value
fi
}
## Set up GPIO input pins that should be active high
for pin in $GPIO_IN_HIGH; do
gpio_in_setup "$pin" high
done
## Set up GPIO input pins that should be active low
for pin in $GPIO_IN_LOW; do
gpio_in_setup "$pin" low
done
## Set up GPIO output pins that should be active high
for pin in $GPIO_OUT_HIGH; do
gpio_out_setup "$pin" high
done
## Set up GPIO output pins that should be active low
for pin in $GPIO_OUT_LOW; do
gpio_out_setup "$pin" low
done