135 lines
3.3 KiB
C
135 lines
3.3 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,65533,3295);
|
|
MyTimer_IT_Conf(TimerRF,MyRF_Transmit_3s,3);
|
|
MyTimer_IT_Enable(TimerRF);
|
|
MyTimer_Start(TimerRF);
|
|
|
|
}
|
|
|
|
int MyRF_Input_Duty_Cycle(void) {
|
|
int duty_cycle_RC = MyPWM_Duty_Cycle_Permilles(TimerCC, channelCC1, channelCC2);
|
|
if (74<duty_cycle_RC && duty_cycle_RC<77) {
|
|
return 0;
|
|
}
|
|
else {
|
|
return (duty_cycle_RC - 75) * 4;
|
|
}
|
|
}
|
|
|
|
void MyRF_Transmit_3s(void) {
|
|
|
|
//Récupérer :
|
|
char bordage[3] = "";
|
|
char heure[2] = "xx";
|
|
char min[2] = "xx";
|
|
char sec[2] = "xx";
|
|
int allure_ref = 3;
|
|
|
|
char allure[7][16]= {"vent debout.",
|
|
"au plus près.",
|
|
"au près.",
|
|
"au bon plein.",
|
|
"au travers.",
|
|
"au grand largue.",
|
|
"au vent arrière."
|
|
};
|
|
char data1[14] = "\" - Bordage : ";
|
|
char data2[24] = " === Le voilier navigue ";
|
|
|
|
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 (bordage)
|
|
for(i=0; i<14; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, data1[i]);
|
|
}
|
|
//Bordage
|
|
for(i=0; i<3; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, bordage[i]);
|
|
}
|
|
MyUSART_Transmit_Data_8b(USARTOut, '%');
|
|
//Texte 2 (allure)
|
|
for(i=0; i<24; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, data2[i]);
|
|
}
|
|
//Allure
|
|
for(i=0; i<16; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, allure[allure_ref][i]);
|
|
}
|
|
//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]);
|
|
}
|
|
}
|