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 supportmaster
parent
9e4ac6cf29
commit
85022f8bb5
|
@ -273,19 +273,24 @@ static const DACConversionGroup dacgrpcfg2 = {
|
||||||
.trigger = DAC_TRG(0)
|
.trigger = DAC_TRG(0)
|
||||||
};
|
};
|
||||||
|
|
||||||
void audio_init()
|
void audio_init() {
|
||||||
{
|
|
||||||
|
|
||||||
if (audio_initialized)
|
if (audio_initialized) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Check EEPROM
|
// Check EEPROM
|
||||||
// if (!eeconfig_is_enabled())
|
#if defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE)
|
||||||
// {
|
if (!eeconfig_is_enabled()) {
|
||||||
// eeconfig_init();
|
eeconfig_init();
|
||||||
// }
|
}
|
||||||
// audio_config.raw = eeconfig_read_audio();
|
audio_config.raw = eeconfig_read_audio();
|
||||||
|
#else // ARM EEPROM
|
||||||
audio_config.enable = true;
|
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
|
* 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");
|
dprintf("audio stop all notes");
|
||||||
|
|
||||||
if (!audio_initialized) {
|
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);
|
dprintf("audio stop note freq=%d", (int)freq);
|
||||||
|
|
||||||
if (playing_note) {
|
if (playing_note) {
|
||||||
|
@ -364,8 +367,9 @@ void stop_note(float freq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
voices--;
|
voices--;
|
||||||
if (voices < 0)
|
if (voices < 0) {
|
||||||
voices = 0;
|
voices = 0;
|
||||||
|
}
|
||||||
if (voice_place >= voices) {
|
if (voice_place >= voices) {
|
||||||
voice_place = 0;
|
voice_place = 0;
|
||||||
}
|
}
|
||||||
|
@ -383,8 +387,7 @@ void stop_note(float freq)
|
||||||
|
|
||||||
#ifdef VIBRATO_ENABLE
|
#ifdef VIBRATO_ENABLE
|
||||||
|
|
||||||
float mod(float a, int b)
|
float mod(float a, int b) {
|
||||||
{
|
|
||||||
float r = fmod(a, b);
|
float r = fmod(a, b);
|
||||||
return r < 0 ? r + b : r;
|
return r < 0 ? r + b : r;
|
||||||
}
|
}
|
||||||
|
@ -602,10 +605,10 @@ void play_note(float freq, int vol) {
|
||||||
|
|
||||||
if (audio_config.enable && voices < 8) {
|
if (audio_config.enable && voices < 8) {
|
||||||
|
|
||||||
|
|
||||||
// Cancel notes if notes are playing
|
// Cancel notes if notes are playing
|
||||||
if (playing_notes)
|
if (playing_notes) {
|
||||||
stop_all_notes();
|
stop_all_notes();
|
||||||
|
}
|
||||||
|
|
||||||
playing_note = true;
|
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) {
|
if (!audio_initialized) {
|
||||||
audio_init();
|
audio_init();
|
||||||
|
@ -635,8 +637,9 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat)
|
||||||
if (audio_config.enable) {
|
if (audio_config.enable) {
|
||||||
|
|
||||||
// Cancel note if a note is playing
|
// Cancel note if a note is playing
|
||||||
if (playing_note)
|
if (playing_note) {
|
||||||
stop_all_notes();
|
stop_all_notes();
|
||||||
|
}
|
||||||
|
|
||||||
playing_notes = true;
|
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_1();
|
||||||
RESTART_CHANNEL_2();
|
RESTART_CHANNEL_2();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_playing_notes(void) {
|
bool is_playing_notes(void) {
|
||||||
|
@ -670,8 +672,9 @@ bool is_audio_on(void) {
|
||||||
void audio_toggle(void) {
|
void audio_toggle(void) {
|
||||||
audio_config.enable ^= 1;
|
audio_config.enable ^= 1;
|
||||||
eeconfig_update_audio(audio_config.raw);
|
eeconfig_update_audio(audio_config.raw);
|
||||||
if (audio_config.enable)
|
if (audio_config.enable) {
|
||||||
audio_on_user();
|
audio_on_user();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_on(void) {
|
void audio_on(void) {
|
||||||
|
@ -681,6 +684,7 @@ void audio_on(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio_off(void) {
|
void audio_off(void) {
|
||||||
|
stop_all_notes();
|
||||||
audio_config.enable = 0;
|
audio_config.enable = 0;
|
||||||
eeconfig_update_audio(audio_config.raw);
|
eeconfig_update_audio(audio_config.raw);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ extern bool midi_activated;
|
||||||
|
|
||||||
void clicky_play(void) {
|
void clicky_play(void) {
|
||||||
#ifndef NO_MUSIC_MODE
|
#ifndef NO_MUSIC_MODE
|
||||||
if (music_activated || midi_activated) return;
|
if (music_activated || midi_activated || audio_config.enable) return;
|
||||||
#endif // !NO_MUSIC_MODE
|
#endif // !NO_MUSIC_MODE
|
||||||
clicky_song[0][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
|
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)) ) );
|
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 (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); }
|
||||||
|
|
||||||
|
|
||||||
if ( audio_config.clicky_enable ) {
|
if (audio_config.enable && audio_config.clicky_enable) {
|
||||||
if (record->event.pressed) {
|
if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound
|
||||||
clicky_play();;
|
if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM
|
||||||
|
clicky_play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue