Fix ARM Audio issues and its EEPROM persistence (#4936)

* Don't click if turning audio off

On ARM, playing the click when turning off audio causes the audio get stuck and continually play the tone

* Fix Audio EEPROM support for ARM

* Update touched files to conform to QMK Coding Conventions

* Add better check for ARM EEPROM support
This commit is contained in:
Drashna Jaelre 2019-02-14 20:12:37 -08:00 committed by MechMerlin
parent 9e4ac6cf29
commit 85022f8bb5
2 changed files with 322 additions and 316 deletions

View File

@ -273,19 +273,24 @@ static const DACConversionGroup dacgrpcfg2 = {
.trigger = DAC_TRG(0)
};
void audio_init()
{
void audio_init() {
if (audio_initialized)
if (audio_initialized) {
return;
}
// Check EEPROM
// if (!eeconfig_is_enabled())
// {
// eeconfig_init();
// }
// audio_config.raw = eeconfig_read_audio();
#if defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
audio_config.raw = eeconfig_read_audio();
#else // ARM EEPROM
audio_config.enable = true;
#ifdef AUDIO_CLICKY_ON
audio_config.clicky_enable = true;
#endif
#endif // ARM EEPROM
/*
* Starting DAC1 driver, setting up the output pin as analog as suggested
@ -316,8 +321,7 @@ void audio_init()
}
void stop_all_notes()
{
void stop_all_notes() {
dprintf("audio stop all notes");
if (!audio_initialized) {
@ -342,8 +346,7 @@ void stop_all_notes()
}
}
void stop_note(float freq)
{
void stop_note(float freq) {
dprintf("audio stop note freq=%d", (int)freq);
if (playing_note) {
@ -364,8 +367,9 @@ void stop_note(float freq)
}
}
voices--;
if (voices < 0)
if (voices < 0) {
voices = 0;
}
if (voice_place >= voices) {
voice_place = 0;
}
@ -383,8 +387,7 @@ void stop_note(float freq)
#ifdef VIBRATO_ENABLE
float mod(float a, int b)
{
float mod(float a, int b) {
float r = fmod(a, b);
return r < 0 ? r + b : r;
}
@ -602,10 +605,10 @@ void play_note(float freq, int vol) {
if (audio_config.enable && voices < 8) {
// Cancel notes if notes are playing
if (playing_notes)
if (playing_notes) {
stop_all_notes();
}
playing_note = true;
@ -625,8 +628,7 @@ void play_note(float freq, int vol) {
}
void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
{
void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat) {
if (!audio_initialized) {
audio_init();
@ -635,8 +637,9 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
if (audio_config.enable) {
// Cancel note if a note is playing
if (playing_note)
if (playing_note) {
stop_all_notes();
}
playing_notes = true;
@ -656,7 +659,6 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
RESTART_CHANNEL_1();
RESTART_CHANNEL_2();
}
}
bool is_playing_notes(void) {
@ -670,9 +672,10 @@ bool is_audio_on(void) {
void audio_toggle(void) {
audio_config.enable ^= 1;
eeconfig_update_audio(audio_config.raw);
if (audio_config.enable)
if (audio_config.enable) {
audio_on_user();
}
}
void audio_on(void) {
audio_config.enable = 1;
@ -681,6 +684,7 @@ void audio_on(void) {
}
void audio_off(void) {
stop_all_notes();
audio_config.enable = 0;
eeconfig_update_audio(audio_config.raw);
}

View File

@ -32,7 +32,7 @@ extern bool midi_activated;
void clicky_play(void) {
#ifndef NO_MUSIC_MODE
if (music_activated || midi_activated) return;
if (music_activated || midi_activated || audio_config.enable) return;
#endif // !NO_MUSIC_MODE
clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
clicky_song[1][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
@ -88,9 +88,11 @@ bool process_clicky(uint16_t keycode, keyrecord_t *record) {
if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); }
if ( audio_config.clicky_enable ) {
if (record->event.pressed) {
clicky_play();;
if (audio_config.enable && audio_config.clicky_enable) {
if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound
if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM
clicky_play();
}
}
}
return true;