Create GPIO and PWM paths in SATA_HAT script

This commit is contained in:
coolneng 2021-07-28 12:48:03 +02:00
parent e4c08419bd
commit 139a79c36b
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
1 changed files with 26 additions and 22 deletions

View File

@ -1,32 +1,36 @@
#!/bin/sh #!/bin/sh
BASE_PATH=/sys/class/gpio BASE_PATH=/sys/class
GPIO_PATH="$BASE_PATH"/gpio
PWM_PATH="$BASE_PATH"/pwm
# GPIO pins # GPIO pins
SATA0=26 SATA0=26
SATA1=25 SATA1=25
# PWM pins
CPU_FAN=12 CPU_FAN=12
HDD_FAN=13
# Values # Values
LOW=0 LOW=0
HIGH=1 HIGH=1
export_pin() { export_pin() {
if [ ! -e $BASE_PATH/gpio"$1" ]; then if [ ! -e $GPIO_PATH/gpio"$1" ]; then
echo "$1" >$BASE_PATH/export echo "$1" >$GPIO_PATH/export
fi fi
} }
unexport_pin() { unexport_pin() {
if [ -e $BASE_PATH/gpio"$1" ]; then if [ -e $GPIO_PATH/gpio"$1" ]; then
echo "$1" >$BASE_PATH/unexport echo "$1" >$GPIO_PATH/unexport
fi fi
} }
set_mode() { set_mode() {
export_pin "$1" export_pin "$1"
echo "out" >$BASE_PATH/gpio"$1"/direction echo "out" >$GPIO_PATH/gpio"$1"/direction
echo "$2" >$BASE_PATH/gpio"$1"/value echo "$2" >$GPIO_PATH/gpio"$1"/value
if [ "$3" = "clean" ]; then if [ "$3" = "clean" ]; then
unexport_pin "$1" unexport_pin "$1"
fi fi
@ -36,7 +40,7 @@ turn_on() {
set_mode $SATA0 $HIGH set_mode $SATA0 $HIGH
sleep 1 sleep 1
set_mode $SATA1 $HIGH set_mode $SATA1 $HIGH
set_mode $CPU_FAN $LOW set_mode $CPU_FAN $HIGH
} }
turn_off() { turn_off() {