From 4d4dd5fe26e40418c9ca04dc31e661be9d22f7d7 Mon Sep 17 00:00:00 2001 From: Jeremy Tan Date: Wed, 25 Sep 2013 15:56:02 +0800 Subject: [PATCH] Semi fix for pwm --- server/pin_test.c | 13 ++++++++----- server/run.sh | 13 +++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/server/pin_test.c b/server/pin_test.c index cd8c307..3ccf458 100644 --- a/server/pin_test.c +++ b/server/pin_test.c @@ -12,12 +12,12 @@ */ void Pin_Init() { - for (int i = 0; i < GPIO_NUM_PINS; ++i) +/* for (int i = 0; i < GPIO_NUM_PINS; ++i) GPIO_Export(i); for (int i = 0; i < ADC_NUM_PINS; ++i) ADC_Export(); - +*/ for (int i = 0; i < PWM_NUM_PINS; ++i) PWM_Export(i); } @@ -57,8 +57,8 @@ void Pin_Handler(FCGIContext *context, char * params) FCGIValue values[] = { {"type", &type, FCGI_REQUIRED(FCGI_STRING_T)}, {"num", &num, FCGI_REQUIRED(FCGI_INT_T)}, - {"set", &set, FCGI_INT_T}, - {"pol", &pol, FCGI_INT_T}, + {"set", &set, FCGI_BOOL_T}, + {"pol", &pol, FCGI_BOOL_T}, {"freq", &freq, FCGI_DOUBLE_T}, {"duty", &duty, FCGI_DOUBLE_T} }; @@ -68,6 +68,7 @@ void Pin_Handler(FCGIContext *context, char * params) TYPE, NUM, SET, + POL, FREQ, DUTY } SensorParams; @@ -131,10 +132,12 @@ void Pin_Handler(FCGIContext *context, char * params) if (set) { Log(LOGDEBUG, "Setting PWM%d", num); + duty = duty < 0 ? 0 : duty > 1 ? 1 : duty; long period_ns = (long)(1e9 / freq); long duty_ns = (long)(duty * period_ns); PWM_Set(num, pol, period_ns, duty_ns); - FCGI_PrintRaw("PWM%d set to period_ns = %lu (%f Hz), duty_ns = %lu (%d), polarity = %d", num, period_ns, freq, duty_ns, duty*100, pol); + FCGI_PrintRaw("PWM%d set to period_ns = %lu (%f Hz), duty_ns = %lu (%f), polarity = %d", + num, period_ns, freq, duty_ns, duty*100, (int)pol); } else { diff --git a/server/run.sh b/server/run.sh index d9cb343..18af55b 100755 --- a/server/run.sh +++ b/server/run.sh @@ -18,13 +18,18 @@ fi # Identify cape-manager slots slot=$(echo /sys/devices/bone_capemgr.*/slots | awk '{print $1}') +pwm=/sys/class/pwm/ # Load PWM module -modprobe pwm_test +#modprobe pwm_test (echo am33xx_pwm > $slot) 1>&2 >> /dev/null -for port in P9_21 P9_22 P9_14 P9_16 P9_29 P9_31 P9_42 P8_13 P8_19 P8_34 P8_36 P8_45 P8_46; do - echo bone_pwm_$port > $slot -done +#for port in P9_21 P9_22 P9_14 P9_16 P9_29 P9_31 P9_42 P8_13 P8_19 P8_34 P8_36 P8_45 P8_46; do +# echo bone_pwm_$port > $slot +#done +echo 0 > $pwm/export +echo 1 > $pwm/export +echo bone_pwm_P9_21 > $slot +echo bone_pwm_P9_22 > $slot # Load ADCs (echo cape-bone-iio > $slot) 1>&2 >> /dev/null -- 2.20.1