From f24d419c1b7ed0ec7c983642792b698bea837d30 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sat, 7 Nov 2020 15:50:57 +0100 Subject: [PATCH] add sail start and conf functions --- MyDrivers/Timer.c | 2 +- Services/ServoMotor.c | 6 +++--- Services/ServoMotor.h | 6 +++++- Src/Sail.c | 27 +++++++++++++++++++++++++++ Src/Sail.h | 8 ++++---- Src/main.c | 15 ++++++--------- 6 files changed, 46 insertions(+), 18 deletions(-) diff --git a/MyDrivers/Timer.c b/MyDrivers/Timer.c index 55bf6d8..b0b5cad 100644 --- a/MyDrivers/Timer.c +++ b/MyDrivers/Timer.c @@ -173,7 +173,7 @@ void Timer_conf(TIM_TypeDef * timer, int arr, int psc) int getArrFromFreq(float freq) { - return (72000000 / freq) - 1; + return (72000 / freq) - 1; } void Timer_pwmo_conf(TIM_TypeDef * timer, int channel, float freq, float dutyCycle) diff --git a/Services/ServoMotor.c b/Services/ServoMotor.c index d006b26..70e636c 100644 --- a/Services/ServoMotor.c +++ b/Services/ServoMotor.c @@ -1,11 +1,11 @@ #include "ServoMotor.h" -#include "Timer.h" #define SERVO_MOTO_FREQ 50 -void ServoMotor_conf(TIM_TypeDef * timer, int channel) +void ServoMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin) { - Timer_pwmo_conf(timer, channel, SERVO_MOTO_FREQ, 0); + 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) diff --git a/Services/ServoMotor.h b/Services/ServoMotor.h index 65561b8..794dbdf 100644 --- a/Services/ServoMotor.h +++ b/Services/ServoMotor.h @@ -2,15 +2,19 @@ #define SERVO_MOTOR_H #include "stm32f103xb.h" +#include "Timer.h" +#include "GPIO.h" /** * @brief Configure le servo moteur associé au timer donné * @note * @param TIM_TypeDef Timer : indique le timer à utiliser : TIM1, TIM2, TIM3 ou TIM4 * int channel : Le channel utilisé par le servo moteur + * GPIO_TypeDef gpio : Le GPIO à utiliser pour la sortie de la PWM + * int pin : Le PIN associé au GPIO * @retval None */ -void ServoMotor_conf(TIM_TypeDef * timer, int channel); +void ServoMotor_conf(TIM_TypeDef * timer, int channel, GPIO_TypeDef * gpio, int pin); /** * @brief Démarre les servo moteurs associés au timer donné diff --git a/Src/Sail.c b/Src/Sail.c index 250165b..76c5198 100644 --- a/Src/Sail.c +++ b/Src/Sail.c @@ -1 +1,28 @@ #include "Sail.h" +#include "ServoMotor.h" + +TIM_TypeDef * SAIL_TIMER = TIM4; +const int SAIL_CHANNEL = LL_TIM_CHANNEL_CH3; +GPIO_TypeDef * SAIL_GPIO = GPIOB; +const int SAIL_PIN = LL_GPIO_PIN_8; + +void Sail_conf() +{ + ServoMotor_conf(SAIL_TIMER, SAIL_CHANNEL, SAIL_GPIO, SAIL_PIN); +} + +void Sail_background() +{ + +} + +void Sail_reset() +{ + +} + + +void Sail_start() +{ + Timer_start(SAIL_TIMER); +} diff --git a/Src/Sail.h b/Src/Sail.h index a847a15..cc49ef0 100644 --- a/Src/Sail.h +++ b/Src/Sail.h @@ -7,7 +7,7 @@ * @param None * @retval None */ -void Sail_conf(); +void Sail_conf(void); /** * @brief Execute la tache de fond des voiles en fonction des valeurs récupérées par les drivers @@ -15,7 +15,7 @@ void Sail_conf(); * @param None * @retval None */ -void Sail_background(); +void Sail_background(void); /** * @brief Mets la voile à 90 degres @@ -23,7 +23,7 @@ void Sail_background(); * @param None * @retval None */ -void Sail_reset(); +void Sail_reset(void); /** * @brief Réinitialise la voile à sa position initiale @@ -31,6 +31,6 @@ void Sail_reset(); * @param None * @retval None */ -void Sail_start(); +void Sail_start(void); #endif diff --git a/Src/main.c b/Src/main.c index c78ee5f..c440ba6 100644 --- a/Src/main.c +++ b/Src/main.c @@ -20,7 +20,7 @@ #include "stm32f1xx_ll_utils.h" // utile dans la fonction SystemClock_Config #include "stm32f1xx_ll_system.h" // utile dans la fonction SystemClock_Config -#include "Chrono.h" +#include "Sail.h" void SystemClock_Config(void); @@ -31,8 +31,6 @@ void SystemClock_Config(void); * @param None * @retval None */ - -Time * time; int main(void) { @@ -41,14 +39,13 @@ int main(void) /* Add your application code here */ // Configuration chronomètre - Chrono_Conf(TIM3); - + // Chrono_Conf(TIM3); // Lancement chronomètre - Chrono_Start(); - - time = Chrono_Read(); + // Chrono_Start(); + // time = Chrono_Read(); - /* Infinite loop */ + Sail_conf(); + Sail_start(); while (1) { }