3 #define _TWR_SERVO_PERIOD_CYCLES 50000
4 #define _TWR_SERVO_RESOLUTION 1
8 self->_channel = channel;
9 self->_angle = TWR_SERVO_NO_ANGLE;
10 self->_min = TWR_SERVO_DEFAULT_MIN;
11 self->_max = TWR_SERVO_DEFAULT_MAX;
15 if ((channel == TWR_PWM_P0) || (channel == TWR_PWM_P1) || (channel == TWR_PWM_P2) || (channel == TWR_PWM_P3))
19 else if ((channel == TWR_PWM_P6) || (channel == TWR_PWM_P7) || (channel == TWR_PWM_P8))
23 else if ((channel == TWR_PWM_P12) || (channel == TWR_PWM_P14))
36 uint16_t pwm_value = ((
self->_max -
self->_min) * ((
float) angle / 180.f)) +
self->_min;
40 if (self->_angle == TWR_SERVO_NO_ANGLE)
64 if (self->_angle == TWR_SERVO_NO_ANGLE)
69 self->_angle = TWR_SERVO_UNKNOWN_ANGLE;
void twr_pwm_enable(twr_pwm_channel_t channel)
Enable PWM output on GPIO pin.
void twr_pwm_set(twr_pwm_channel_t channel, uint16_t pwm_value)
Set PWM value for GPIO pin.
void twr_pwm_tim_configure(twr_pwm_tim_t tim, uint32_t resolution_us, uint32_t period_cycles)
Reconfigure TIM3.
void twr_pwm_init(twr_pwm_channel_t channel)
Initialize PWM timers based on GPIO pin.
twr_pwm_channel_t
PWM channels.
void twr_servo_set_angle(twr_servo_t *self, uint8_t angle)
Set angle.
void twr_servo_set_microseconds(twr_servo_t *self, uint16_t us)
Set Microseconds.
void twr_servo_set_pulse_limits(twr_servo_t *self, uint16_t min_us, uint16_t max_us)
Set pulse limits.
void twr_servo_init(twr_servo_t *self, twr_pwm_channel_t channel)
Initialize Servo.
uint8_t twr_servo_get_angle(twr_servo_t *self)
Get angle.