Skip to content

Commit 8e08a40

Browse files
committed
move pwm_set_polarity() after period is set
1 parent 73ea172 commit 8e08a40

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

source/c_pwm.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,6 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
581581
return BBIO_GEN;
582582
}
583583

584-
err = pwm_set_polarity(key, polarity);
585-
if (err != BBIO_OK) {
586-
syslog(LOG_ERR, "pwm_start: %s couldn't set polarity: %i", key, err);
587-
return err;
588-
}
589-
590584
// Read out current period_ns from the file, in order for it to behave
591585
// properly
592586
memset(buffer, 0, sizeof(buffer)); // Initialize buffer
@@ -625,23 +619,33 @@ BBIO_err pwm_start(const char *key, float duty, float freq, int polarity)
625619

626620
// Initialize pwm->duty to avoid weirdness
627621
pwm->duty = duty;
622+
fprintf(stderr, "pwm_set_frequency()\n");
628623
err = pwm_set_frequency(key, freq);
629624
if (err != BBIO_OK) {
630625
syslog(LOG_ERR, "Adafruit_BBIO: pwm_start: %s couldn't set duty frequency: %i", key, err);
631626
return err;
632627
}
633628

629+
fprintf(stderr, "pwm_set_duty_cycle()\n");
634630
err = pwm_set_duty_cycle(key, duty);
635631
if (err != BBIO_OK) {
636632
syslog(LOG_ERR, "Adafruit_BBIO: pwm_start: %s couldn't set duty cycle: %i", key, err);
637633
return err;
638634
}
639635

636+
fprintf(stderr, "pwm_set_polarity()\n");
637+
err = pwm_set_polarity(key, polarity);
638+
if (err != BBIO_OK) {
639+
syslog(LOG_ERR, "pwm_start: %s couldn't set polarity: %i", key, err);
640+
return err;
641+
}
642+
640643
#ifdef BBBVERSION41 // Enable the PWM (don't think it's necessary before 4.1+)
641644
if (pwm == NULL) {
642645
return BBIO_GEN;
643646
}
644647
len = snprintf(buffer, sizeof(buffer), "1");
648+
fprintf(stderr, "write 1 to pwm->enable_fd\n");
645649
lseek(pwm->enable_fd, 0, SEEK_SET);
646650
if (write(pwm->enable_fd, buffer, len) < 0) {
647651
syslog(LOG_ERR, "Adafruit_BBIO: pwm_start: %s couldn't write enable: %i-%s",

0 commit comments

Comments
 (0)