projet_voilier/Services/ServoMotor.c
2020-11-07 15:50:57 +01:00

25 lines
652 B
C

#include "ServoMotor.h"
#define SERVO_MOTO_FREQ 50
void ServoMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin)
{
Timer_pwmo_conf(timer, channel, SERVO_MOTO_FREQ, 0.5);
GPIO_conf(gpio, pin, LL_GPIO_MODE_ALTERNATE, LL_GPIO_OUTPUT_PUSHPULL, LL_GPIO_PULL_UP);
}
void ServoMotor_start(TIM_TypeDef * timer)
{
Timer_start(timer);
}
void ServoMotor_setAngle(TIM_TypeDef * timer, int channel, int angle)
{
Timer_pwmo_setDutyCycle(timer, channel, ((float) angle) / 359.0);
}
int ServoMotor_getAngle(TIM_TypeDef * timer, int channel)
{
const float dutyCycle = Timer_pwmo_getDutyCycle(timer, channel);
return 359 * dutyCycle;
}