Periph-Voilier/Services/MyRF.c
2020-11-23 22:12:28 +01:00

131 lines
3.1 KiB
C

#include "MyRF.h"
#include "MyTimer.h"
#include "MyPWM.h"
#include "MyUSART.h"
#include "stm32f1xx_ll_bus.h" // Pour l'activation des horloges
#include "stm32f1xx_ll_tim.h"
#include "stm32f1xx_ll_gpio.h"
#include "stm32f1xx_ll_usart.h"
void MyRF_Conf(void) {
//RX
//Activation horloge du GPIO
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOB);
LL_GPIO_InitTypeDef My_GPIO_Init_Struct;
LL_GPIO_StructInit(&My_GPIO_Init_Struct);
//PB.6 en floating input
My_GPIO_Init_Struct.Pin = PinCH1;
LL_GPIO_Init(GPIOIn, &My_GPIO_Init_Struct);
//PB.7 en floating input
My_GPIO_Init_Struct.Pin = PinCH2;
LL_GPIO_Init(GPIOIn, &My_GPIO_Init_Struct);
//Configuration et lancment du Timer PWM Input
MyTimer_Conf(TimerCC,0xFFAD,0x15);
MyPWM_Conf_Input(TimerCC, channelCC1, channelCC2);
MyTimer_Start(TimerCC);
//TX
//Activation horloge du GPIO
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_GPIOA);
LL_GPIO_StructInit(&My_GPIO_Init_Struct);
//PA.9 en alternate output pp
My_GPIO_Init_Struct.Pin = PinOut;
My_GPIO_Init_Struct.Mode = LL_GPIO_MODE_ALTERNATE;
My_GPIO_Init_Struct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
LL_GPIO_Init(GPIOOut, &My_GPIO_Init_Struct);
//Configuration de l'USART
MyUSART_Conf(USARTOut, TransferDirTX);
//Configuration Timer (interruption à 3s, callback MyRF_Transmit_3s) et lancement
MyTimer_Conf(TimerRF,65633,3290);
MyTimer_IT_Conf(TimerRF,MyRF_Transmit_3s,3);
MyTimer_IT_Enable(TimerRF);
MyTimer_Start(TimerRF);
}
int MyRF_Input_Duty_Cycle(void) {
return (MyPWM_Duty_Cycle_Permilles(TimerCC, channelCC1, channelCC2) - 75) * 4;
}
void MyRF_Transmit_3s(void) {
//Récupérer :
char bordage[3];
char heure[2];
char min[2];
char sec[2];
int allure_ref = 0;
char allure[7][30] = {"pas (ou vent debout).",
"au plus près.",
"au près.",
"au bon plein.",
"au travers.",
"au grand largue.",
"au vent arrière."
};
char data1[23] = "\" : le voilier navigue ";
char data2[15] = " === Bordage : ";
int i;
//Heure
MyUSART_Transmit_Data_8b(USARTOut, heure[0]);
MyUSART_Transmit_Data_8b(USARTOut, heure[1]);
MyUSART_Transmit_Data_8b(USARTOut, 'h');
//Minutes
MyUSART_Transmit_Data_8b(USARTOut, min[0]);
MyUSART_Transmit_Data_8b(USARTOut, min[1]);
MyUSART_Transmit_Data_8b(USARTOut, '\'');
//Secondes
MyUSART_Transmit_Data_8b(USARTOut, sec[0]);
MyUSART_Transmit_Data_8b(USARTOut, sec[1]);
//Texte 1 (allures)
for(i=0; i<23; i++) {
MyUSART_Transmit_Data_8b(USARTOut, data1[i]);
}
//Allure
for(i=0; i<30; i++) {
MyUSART_Transmit_Data_8b(USARTOut, allure[allure_ref][i]);
}
//Texte 2 (bordage)
for(i=0; i<15; i++) {
MyUSART_Transmit_Data_8b(USARTOut, data2[i]);
}
//Bordage
for(i=0; i<3; i++) {
MyUSART_Transmit_Data_8b(USARTOut, bordage[i]);
}
MyUSART_Transmit_Data_8b(USARTOut, '%');
//Newline (fin)
MyUSART_Transmit_Data_8b(USARTOut, '\n');
}
void MyRF_Transmit_Batterie_Faible(void) {
char data[24] = "/!\\ BATTERIE FAIBLE /!\\\n";
for(int i = 0; i<24; i++) {
MyUSART_Transmit_Data_8b(USARTOut, data[i]);
}
}
void MyRF_Transmit_Limite_Roulis(void) {
char data[30] = "/!\\ RISQUE DE CHAVIREMENT /!\\\n";
for(int i = 0; i<30; i++) {
MyUSART_Transmit_Data_8b(USARTOut, data[i]);
}
}