drivers/servo: allow for overriding default parameters
This is mandatory on platforms where both settings are strongly tied (eg. lm4f120)
This commit is contained in:
parent
281b0ba46e
commit
738d05e6b1
@ -27,16 +27,21 @@
|
|||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#define FREQUENCY (100U)
|
#ifndef SERVO_FREQUENCY
|
||||||
#define RESOLUTION (SEC_IN_USEC / 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 servo_init(servo_t *dev, pwm_t pwm, int pwm_channel, unsigned int min, unsigned int max)
|
||||||
{
|
{
|
||||||
int actual_frequency;
|
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) {
|
if (actual_frequency < 0) {
|
||||||
/* PWM error */
|
/* 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.
|
* to actual hardware ticks.
|
||||||
*/
|
*/
|
||||||
dev->scale_nom = actual_frequency;
|
dev->scale_nom = actual_frequency;
|
||||||
dev->scale_den = FREQUENCY;
|
dev->scale_den = SERVO_FREQUENCY;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user