chti23/soft/PjtKEIL_StepFinal/Src/principal.c

82 lines
2 KiB
C

#include "DriverJeuLaser.h"
#include "module_carre.h"
#include "GestionSon.h"
#define NB_JOUEURS 6
#define SEUIL_ACCEPT_SIGNAL 0x80
#define FREQ_TO_INT(f) (64 * f / 320)
#define TE_IN_TICKS 6552
#define PERIODE_PWM 720
short int dma_buff[64];
int module_dft[NB_JOUEURS];
// int module_dft[64];
int score_joueurs[NB_JOUEURS];
extern short LeSignal;
int freq_joueurs[NB_JOUEURS] = {FREQ_TO_INT(85), FREQ_TO_INT(90), FREQ_TO_INT(95), FREQ_TO_INT(100), FREQ_TO_INT(115), FREQ_TO_INT(120)};
extern short Sortie_son;
void systick_func() {
int module;
Start_DMA1(64);
Wait_On_End_Of_DMA1();
Stop_DMA1;
for (int i = 0; i < NB_JOUEURS; ++i) {
module = DFT_ModuleAuCarre(dma_buff, freq_joueurs[i]);
// module_dft[i] = module;
if (module > SEUIL_ACCEPT_SIGNAL) {
score_joueurs[i]++;
StartSon();
}
}
// for (int i = 0; i < 64; ++i) {
// module_dft[i] = DFT_ModuleAuCarre(dma_buff, i);
// }
}
extern short LeSignal;
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();
// 5ms = n * 1/72MHz => n = 5ms * 72MHz = 360 * 10 ^ 6
Systick_Period_ff(360000000);
Systick_Prio_IT(0, systick_func);
SysTick_On;
SysTick_Enable_IT;
Init_TimingADC_ActiveADC_ff( ADC1, 72 );
Single_Channel_ADC( ADC1, 2 );
// 320 kHz = 72MHz / n => n = 72MHz / 320kHz = 225
Init_Conversion_On_Trig_Timer_ff(ADC1, TIM2_CC2, 225);
Init_ADC1_DMA1(0, dma_buff);
// Set up interuption for the sound effect
Timer_1234_Init_ff(TIM4, TE_IN_TICKS);
Active_IT_Debordement_Timer(TIM4, 2, GestionSon);
GPIO_Configure(GPIOB, 0, OUTPUT, ALT_PPULL);
PWM_Init_ff(TIM3, 3, PERIODE_PWM);
for (int i = 0; i < NB_JOUEURS; ++i) {
score_joueurs[i] = 0;
}
//============================================================================
while (1)
{
}
}