From 738d05e6b1845c0e417e38c4a299987229379020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= <dkm@kataplop.net> Date: Thu, 3 Dec 2015 13:10:23 +0100 Subject: [PATCH] drivers/servo: allow for overriding default parameters This is mandatory on platforms where both settings are strongly tied (eg. lm4f120) --- drivers/servo/servo.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/servo/servo.c b/drivers/servo/servo.c index 054347640d..4652424a78 100644 --- a/drivers/servo/servo.c +++ b/drivers/servo/servo.c @@ -27,16 +27,21 @@ #define ENABLE_DEBUG (0) #include "debug.h" -#define FREQUENCY (100U) -#define RESOLUTION (SEC_IN_USEC / FREQUENCY) +#ifndef SERVO_FREQUENCY +#define SERVO_FREQUENCY (100U) +#endif + +#ifndef SERVO_RESOLUTION +#define SERVO_RESOLUTION (SEC_IN_USEC / SERVO_FREQUENCY) +#endif int servo_init(servo_t *dev, pwm_t pwm, int pwm_channel, unsigned int min, unsigned int max) { int actual_frequency; - actual_frequency = pwm_init(pwm, PWM_LEFT, FREQUENCY, RESOLUTION); + actual_frequency = pwm_init(pwm, PWM_LEFT, SERVO_FREQUENCY, SERVO_RESOLUTION); - DEBUG("servo: requested %d hz, got %d hz\n", FREQUENCY, actual_frequency); + DEBUG("servo: requested %d hz, got %d hz\n", SERVO_FREQUENCY, actual_frequency); if (actual_frequency < 0) { /* PWM error */ @@ -78,7 +83,7 @@ int servo_init(servo_t *dev, pwm_t pwm, int pwm_channel, unsigned int min, unsig * to actual hardware ticks. */ dev->scale_nom = actual_frequency; - dev->scale_den = FREQUENCY; + dev->scale_den = SERVO_FREQUENCY; return 0; } -- GitLab