From 96147e03e8b6dc29a0f04bac37a0f231bbf2f580 Mon Sep 17 00:00:00 2001 From: Florian Didron Date: Tue, 28 May 2019 17:29:01 +0900 Subject: Fixes the A5 HIGH consistently with weird noise output --- quantum/audio/audio_arm.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c index e5164f2abb..b110cbedd1 100644 --- a/quantum/audio/audio_arm.c +++ b/quantum/audio/audio_arm.c @@ -84,14 +84,20 @@ static void gpt_cb8(GPTDriver *gptp); #define DAC_SAMPLE_MAX 65535U #endif -#define START_CHANNEL_1() gptStart(&GPTD6, &gpt6cfg1); \ - gptStartContinuous(&GPTD6, 2U); \ - palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); +#define START_CHANNEL_1() dacStart(&DACD1, &dac1cfg1); \ + dacStart(&DACD2, &dac1cfg2); \ + dacStartConversion(&DACD1, &dacgrpcfg1, (dacsample_t *)dac_buffer, DAC_BUFFER_SIZE); \ + dacStartConversion(&DACD2, &dacgrpcfg2, (dacsample_t *)dac_buffer_2, DAC_BUFFER_SIZE); \ + 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); \ - palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL); \ - palSetPad(GPIOA, 5); + dacStopConversion(&DACD2); \ + dacStop(&DACD2); \ + palSetPadMode(GPIOA, 5, PAL_MODE_OUTPUT_PUSHPULL ); \ + palSetPad(GPIOA, 5) #define STOP_CHANNEL_2() gptStopTimer(&GPTD7) #define RESTART_CHANNEL_1() STOP_CHANNEL_1(); \ START_CHANNEL_1() -- cgit v1.2.3 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(-) 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 From 4b6c1b8c2c58d117090c7f1dce20effdf61a5c13 Mon Sep 17 00:00:00 2001 From: Florian Didron Date: Tue, 28 May 2019 19:35:51 +0900 Subject: And fix the A5 Play note too ! --- quantum/audio/audio_arm.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/quantum/audio/audio_arm.c b/quantum/audio/audio_arm.c index e8bfe09f33..5a9d03686a 100644 --- a/quantum/audio/audio_arm.c +++ b/quantum/audio/audio_arm.c @@ -33,6 +33,7 @@ float frequency_alt = 0; int volume = 0; long position = 0; systime_t last_note_played_at; +virtual_timer_t play_note_timer; float frequencies[8] = {0, 0, 0, 0, 0, 0, 0, 0}; int volumes[8] = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -82,7 +83,9 @@ float startup_song[][2] = STARTUP_SONG; static void gpt_cb8(GPTDriver *gptp); static bool should_shutoff_dac(void); static void shutoff_dac(void); +static void shutoff_dac_callback(void *arg); +#define PLAY_NOTE_TIMEOUT MS2ST(5) #define DAC_BUFFER_SIZE 100 #ifndef DAC_SAMPLE_MAX #define DAC_SAMPLE_MAX 65535U @@ -422,6 +425,8 @@ static void gpt_cb8(GPTDriver *gptp) { if (playing_note) { last_note_played_at = chVTGetSystemTime(); + chVTReset(&play_note_timer); + chVTSet(&play_note_timer, PLAY_NOTE_TIMEOUT, shutoff_dac_callback, NULL); if (voices > 0) { float freq_alt = 0; @@ -626,6 +631,12 @@ void shutoff_dac() { dac_on = false; } +void shutoff_dac_callback(void *args) { + if(!playing_note) { + shutoff_dac(); + } +} + void play_note(float freq, int vol) { dprintf("audio play note freq=%d vol=%d", (int)freq, vol); @@ -655,6 +666,8 @@ void play_note(float freq, int vol) { gptStartContinuous(&GPTD8, 2U); RESTART_CHANNEL_1(); RESTART_CHANNEL_2(); + chVTReset(&play_note_timer); + chVTSet(&play_note_timer, PLAY_NOTE_TIMEOUT, shutoff_dac_callback, NULL); } } -- cgit v1.2.3