Semi fix for pwm
authorJeremy Tan <[email protected]>
Wed, 25 Sep 2013 07:56:02 +0000 (15:56 +0800)
committerJeremy Tan <[email protected]>
Wed, 25 Sep 2013 07:56:02 +0000 (15:56 +0800)
server/pin_test.c
server/run.sh

index cd8c307..3ccf458 100644 (file)
  */
 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
                {
index d9cb343..18af55b 100755 (executable)
@@ -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

UCC git Repository :: git.ucc.asn.au