be_chti/PjtKEIL_StepFinal/Src/principal.c
2021-08-22 13:23:14 +02:00

116 lines
2.4 KiB
C
Executable file

#include "DriverJeuLaser.h"
#include "GestionSon.h"
#include "Affichage_Valise.h"
#define TIMEOUT 100
int DFT_ModuleAuCarre( short int * Signal64ech, char k);
extern short int LeSignal;
short int dma_buf[64];
int dft[64];
int dft_joueur[6];
int tab_score[6];
int timeout[6];
int n_led = 0;
int n_cible = 1;
void Maj_Cible() {
Prepare_Clear_LED(n_led);
n_led++;
n_cible++;
if (n_cible > 4) {
n_cible = 1;
}
if (n_led > 3) {
n_led = 0;
}
Prepare_Set_LED(n_led);
Choix_Capteur(n_cible);
}
void Manage_Tick() {
Start_DMA1(64);
Wait_On_End_Of_DMA1();
dft_joueur[0] = DFT_ModuleAuCarre((short *)&dma_buf, 17);
dft_joueur[1] = DFT_ModuleAuCarre((short *)&dma_buf, 18);
dft_joueur[2] = DFT_ModuleAuCarre((short *)&dma_buf, 19);
dft_joueur[3] = DFT_ModuleAuCarre((short *)&dma_buf, 20);
dft_joueur[4] = DFT_ModuleAuCarre((short *)&dma_buf, 23);
dft_joueur[5] = DFT_ModuleAuCarre((short *)&dma_buf, 24);
Stop_DMA1;
Mise_A_Jour_Afficheurs_LED();
for (int j = 0; j < 4; ++j) {
if (timeout[j] > 0){
timeout[j]--;
}
else if (dft_joueur[j] >= 0x0100000) {
tab_score[j]++;
timeout[j] = TIMEOUT;
StartSon();
Prepare_Afficheur(j+1,tab_score[j]);
Maj_Cible();
}
}
}
int main(void)
{
// ===========================================================================
// ============= INIT PERIPH (faites qu'une seule fois) =====================
// ===========================================================================
// Après exécution : le coeur CPU est clocké à 72MHz ainsi que tous les timers
CLOCK_Configure();
// SysTick (tick tt les 5 ms avec un clock à 72MHz)
Systick_Period_ff( 360000 );
Systick_Prio_IT( 9, Manage_Tick );
//Systick_Prio_IT( , Manage_Aff );
SysTick_On;
SysTick_Enable_IT;
// ADC
Init_TimingADC_ActiveADC_ff( ADC1, 72 );
Single_Channel_ADC( ADC1, 2 );
Init_Conversion_On_Trig_Timer_ff( ADC1, TIM2_CC2, 225 );
Init_ADC1_DMA1( 0, dma_buf );
// Config Son
GPIO_Configure(GPIOB, 0, OUTPUT, ALT_PPULL);
Timer_1234_Init_ff(TIM4, 6552);
Active_IT_Debordement_Timer( TIM4, 2, CallbackSon);
PWM_Init_ff( TIM3, 3, 720);
// Config affichage
Init_Affichage();
// Config score
for (int j = 0; j < 6; ++j) {
tab_score[j] = 0;
timeout[j] = TIMEOUT;
}
Prepare_Set_LED(0);
Choix_Capteur(1);
//============================================================================
while (1)
{
}
}