diff --git a/scripts/SATA-hat.sh b/scripts/SATA-hat.sh index 8d879e1..71822ca 100755 --- a/scripts/SATA-hat.sh +++ b/scripts/SATA-hat.sh @@ -2,14 +2,12 @@ BASE_PATH=/sys/class GPIO_PATH="$BASE_PATH"/gpio -PWM_PATH="$BASE_PATH"/pwm +PWM_PATH="$BASE_PATH"/pwm/pwmchip0 # GPIO pins SATA0=26 SATA1=25 -# PWM pins CPU_FAN=12 -HDD_FAN=13 # Values LOW=0 @@ -27,7 +25,7 @@ unexport_pin() { fi } -set_mode() { +set_gpio() { export_pin "$1" echo "out" >$GPIO_PATH/gpio"$1"/direction echo "$2" >$GPIO_PATH/gpio"$1"/value @@ -36,17 +34,33 @@ set_mode() { fi } +enable_pwm_channel() { + echo "$1" >$PWM_PATH/export + echo 40000 >$PWM_PATH/pwm"$1"/period + echo 30000 >$PWM_PATH/pwm"$1"/duty_cycle + echo 1 >$PWM_PATH/pwm"$1"/enable +} + +set_pwm() { + enable_pwm_channel 1 + if [ "$1" = "clean" ]; then + echo 0 >$PWM_PATH/unexport + fi +} + turn_on() { - set_mode $SATA0 $HIGH + set_gpio $SATA0 $HIGH sleep 1 - set_mode $SATA1 $HIGH - set_mode $CPU_FAN $HIGH + set_gpio $SATA1 $HIGH + set_gpio $CPU_FAN $HIGH + set_pwm } turn_off() { - set_mode $SATA0 $LOW clean - set_mode $SATA1 $LOW clean - set_mode $CPU_FAN $LOW clean + set_gpio $SATA0 $LOW clean + set_gpio $SATA1 $LOW clean + set_gpio $CPU_FAN $LOW clean + set_pwm clean } trap turn_off INT