#!/bin/sh
SLOTS=/sys/devices/bone_capemgr.9/slots
PWM=/sys/devices/ocp.3/
green=pwm_test_P8_19.13
yellow=pwm_test_P8_13.12
red=pwm_test_P8_34.14
duty_grn=500000 # initial
duty_ylw=250000 # initial
duty_red=0 # initial
install_cap() {
cap=$1
if ! grep $cap $SLOTS >/dev/null; then
echo $cap > $SLOTS
fi
}
install_cap am33xx_pwm
install_cap bone_pwm_P8_13
install_cap bone_pwm_P8_19
install_cap bone_pwm_P8_34
maxduty=`cat /sys/devices/ocp.3/$green/period`
duty=$maxduty
step=`expr $maxduty / 50`
led_setup() {
echo 0 > /sys/devices/ocp.3/$2/polarity
echo $1 > /sys/devices/ocp.3/$2/duty
}
led_loop() {
pin=$1
cd $PWM/$pin
duty=`cat duty`
duty=`expr $duty - $step`
if [ $duty -lt 0 ]; then
duty=$maxduty
pol=`cat polarity`
echo `expr 1 - $pol` > polarity && echo $duty > duty
fi
echo $duty > duty
}
led_setup $duty_grn $green
led_setup $duty_ylw $yellow
led_setup $duty_red $red
while true; do
led_loop $green
led_loop $yellow
led_loop $red
done
SLOTS=/sys/devices/bone_capemgr.9/slots
PWM=/sys/devices/ocp.3/
green=pwm_test_P8_19.13
yellow=pwm_test_P8_13.12
red=pwm_test_P8_34.14
duty_grn=500000 # initial
duty_ylw=250000 # initial
duty_red=0 # initial
install_cap() {
cap=$1
if ! grep $cap $SLOTS >/dev/null; then
echo $cap > $SLOTS
fi
}
install_cap am33xx_pwm
install_cap bone_pwm_P8_13
install_cap bone_pwm_P8_19
install_cap bone_pwm_P8_34
maxduty=`cat /sys/devices/ocp.3/$green/period`
duty=$maxduty
step=`expr $maxduty / 50`
led_setup() {
echo 0 > /sys/devices/ocp.3/$2/polarity
echo $1 > /sys/devices/ocp.3/$2/duty
}
led_loop() {
pin=$1
cd $PWM/$pin
duty=`cat duty`
duty=`expr $duty - $step`
if [ $duty -lt 0 ]; then
duty=$maxduty
pol=`cat polarity`
echo `expr 1 - $pol` > polarity && echo $duty > duty
fi
echo $duty > duty
}
led_setup $duty_grn $green
led_setup $duty_ylw $yellow
led_setup $duty_red $red
while true; do
led_loop $green
led_loop $yellow
led_loop $red
done