TP_Voilier/FileInclude/Plateau.c
2022-11-25 18:02:41 +01:00

59 lines
1.3 KiB
C

#include "MyTimer.h"
#include "stm32f10x.h"
#include "Driver_GPIO.h"
#include "Plateau.h"
/* Declarations */
char channel = 4 ;
MyTimer_Struct_TypeDef TIMPlateau;
MyTimer_Struct_TypeDef * DataPlateau = &TIMPlateau;
MyGPIO_Struct_TypeDef GPIOC9; // pin direction
MyGPIO_Struct_TypeDef GPIOB1; // pin moteur
void Init_Plateau (void) {
/* Configuration du Timer */
DataPlateau->Timer = TIM3;
DataPlateau->ARR = 300;
DataPlateau->PSC = 11;
MyTimer_Base_Init(DataPlateau);
/* Configuration des GPIOs */
GPIOC9.GPIO = GPIOC;
GPIOC9.GPIO_Pin = 9;
GPIOC9.GPIO_Conf = Out_Ppull;
MyGPIO_Init(&GPIOC9);
GPIOB1.GPIO = GPIOB;
GPIOB1.GPIO_Pin = 1;
GPIOB1.GPIO_Conf = AltOut_Ppull;
MyGPIO_Init(&GPIOB1);
MyTimer_Base_Start(TIM3);
MyTimer_PWM(DataPlateau->Timer,channel);
}
void Set_Direction (char sens) {
/* Rotation */
if (sens == ANTI_HORRAIRE){
MyGPIO_Reset(GPIOC9.GPIO, GPIOC9.GPIO_Pin); // on met à 0
}
else if (sens == HORRAIRE) {
MyGPIO_Set(GPIOC9.GPIO, GPIOC9.GPIO_Pin); // on met à 1
}
}
void Set_Vitesse (char vitesse) {
Set_PWM_PRCT(DataPlateau->Timer, channel, vitesse);
}
/* Permet de diriger le plateau du voilier */
void Set_Moteur_Plateau(char sens, char vitesse){ // -1 gauche et 1 droite
Init_Plateau();
Set_Direction(sens);
Set_Vitesse(vitesse);
}