From f76e726eddeefa8808b425fb15b80989ad6119b0 Mon Sep 17 00:00:00 2001 From: Florian Didron Date: Tue, 28 May 2019 18:29:13 +0900 Subject: Fix A5 after songs --- quantum/audio/audio_arm.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'quantum/audio') diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c index b110cbedd1..e8bfe09f33 100644 --- a/quantum/audio/audio_arm.c +++ b/quantum/audio/audio_arm.c @@ -32,10 +32,12 @@ float frequency = 0; float frequency_alt = 0; int volume = 0; long position = 0; +systime_t last_note_played_at; float frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; bool sliding = false; +bool dac_on = true; float place = 0; @@ -78,6 +80,8 @@ bool glissando = true; float startup_song[][2] = STARTUP_SONG; static void gpt_cb8(GPTDriver *gptp); +static bool should_shutoff_dac(void); +static void shutoff_dac(void); #define DAC_BUFFER_SIZE 100 #ifndef DAC_SAMPLE_MAX @@ -88,16 +92,13 @@ static void gpt_cb8(GPTDriver *gptp); dacStart(&DACD2, &dac1cfg2); \ dacStartConversion(&DACD1, &dacgrpcfg1, (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE); \ dacStartConversion(&DACD2, &dacgrpcfg2, (dacsample_t *)dac_buffer_2, DAC_BUFFER_SIZE); \ + dac_on = true; \ gptStart(&GPTD6, &gpt6cfg1); \ gptStartContinuous(&GPTD6, 2U); \ palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); #define START_CHANNEL_2() gptStart(&GPTD7, &gpt7cfg1); \ gptStartContinuous(&GPTD7, 2U) -#define STOP_CHANNEL_1() gptStopTimer(&GPTD6); \ - dacStopConversion(&DACD2); \ - dacStop(&DACD2); \ - palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL ); \ - palSetPad(GPIOA, 5) +#define STOP_CHANNEL_1() gptStopTimer(&GPTD6) #define STOP_CHANNEL_2() gptStopTimer(&GPTD7) #define RESTART_CHANNEL_1() STOP_CHANNEL_1(); \ START_CHANNEL_1() @@ -416,11 +417,11 @@ float vibrato(float average_freq) { } #endif - static void gpt_cb8(GPTDriver *gptp) { float freq; if (playing_note) { + last_note_played_at = chVTGetSystemTime(); if (voices > 0) { float freq_alt = 0; @@ -530,6 +531,7 @@ static void gpt_cb8(GPTDriver *gptp) { } if (playing_notes) { + last_note_played_at = chVTGetSystemTime(); if (note_frequency > 0) { #ifdef VIBRATO_ENABLE if (vibrato_strength > 0) { @@ -606,6 +608,22 @@ static void gpt_cb8(GPTDriver *gptp) { playing_notes = false; playing_note = false; } + + if(should_shutoff_dac()) { + shutoff_dac(); + } +} + +bool should_shutoff_dac() { + return ST2MS(chVTTimeElapsedSinceX(last_note_played_at)) > 5 && dac_on; +} + +void shutoff_dac() { + dacStopConversion(&DACD2); + dacStop(&DACD2); + palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL ); + palSetPad(GPIOA, 5); + dac_on = false; } void play_note(float freq, int vol) { -- cgit v1.2.3