From b824faca71e1db86c158a0e09f225410c1e7e0a8 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 24 Dec 2023 06:52:41 +0000 Subject: [PATCH 1/2] Align location of tap dance keycode (#22742) --- docs/feature_tap_dance.md | 2 +- quantum/process_keycode/process_tap_dance.c | 6 +++--- quantum/process_keycode/process_tap_dance.h | 4 ++-- quantum/quantum_keycodes.h | 4 ++++ tests/tap_dance/examples.c | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/feature_tap_dance.md b/docs/feature_tap_dance.md index 42ea2339623..bb1c2c80346 100644 --- a/docs/feature_tap_dance.md +++ b/docs/feature_tap_dance.md @@ -173,7 +173,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case TD(CT_CLN): // list all tap dance keycodes with tap-hold configurations - action = &tap_dance_actions[TD_INDEX(keycode)]; + action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)]; if (!record->event.pressed && action->state.count && !action->state.finished) { tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data; tap_code16(tap_hold->tap); diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c index b8a8d32f350..ce3b8fc81f7 100644 --- a/quantum/process_keycode/process_tap_dance.c +++ b/quantum/process_keycode/process_tap_dance.c @@ -133,7 +133,7 @@ bool preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) { if (!active_td || keycode == active_td) return false; - action = &tap_dance_actions[TD_INDEX(active_td)]; + action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(active_td)]; action->state.interrupted = true; action->state.interrupting_keycode = keycode; process_tap_dance_action_on_dance_finished(action); @@ -154,7 +154,7 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: - action = &tap_dance_actions[TD_INDEX(keycode)]; + action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)]; action->state.pressed = record->event.pressed; if (record->event.pressed) { @@ -182,7 +182,7 @@ void tap_dance_task(void) { if (!active_td || timer_elapsed(last_tap_time) <= GET_TAPPING_TERM(active_td, &(keyrecord_t){})) return; - action = &tap_dance_actions[TD_INDEX(active_td)]; + action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(active_td)]; if (!action->state.interrupted) { process_tap_dance_action_on_dance_finished(action); } diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h index 2b114dabd36..c0137c14a33 100644 --- a/quantum/process_keycode/process_tap_dance.h +++ b/quantum/process_keycode/process_tap_dance.h @@ -19,6 +19,7 @@ #include #include #include "action.h" +#include "quantum_keycodes.h" typedef struct { uint16_t interrupting_keycode; @@ -74,8 +75,7 @@ typedef struct { #define ACTION_TAP_DANCE_FN_ADVANCED_WITH_RELEASE(user_fn_on_each_tap, user_fn_on_each_release, user_fn_on_dance_finished, user_fn_on_dance_reset) \ { .fn = {user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_dance_reset, user_fn_on_each_release}, .user_data = NULL, } -#define TD(n) (QK_TAP_DANCE | TD_INDEX(n)) -#define TD_INDEX(code) ((code)&0xFF) +#define TD_INDEX(code) QK_TAP_DANCE_GET_INDEX(code) #define TAP_DANCE_KEYCODE(state) TD(((tap_dance_action_t *)state) - tap_dance_actions) extern tap_dance_action_t tap_dance_actions[]; diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index d3249bd4555..882e1d07aec 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -190,6 +190,10 @@ #define SH_T(kc) (QK_SWAP_HANDS | ((kc)&0xFF)) #define QK_SWAP_HANDS_GET_TAP_KEYCODE(kc) ((kc)&0xFF) +// Tap dance +#define TD(i) (QK_TAP_DANCE | ((i)&0xFF)) +#define QK_TAP_DANCE_GET_INDEX(kc) ((kc)&0xFF) + // MIDI aliases #define MIDI_TONE_MIN QK_MIDI_NOTE_C_0 #define MIDI_TONE_MAX QK_MIDI_NOTE_B_5 diff --git a/tests/tap_dance/examples.c b/tests/tap_dance/examples.c index 13086bbb4bb..5377b397d3c 100644 --- a/tests/tap_dance/examples.c +++ b/tests/tap_dance/examples.c @@ -83,7 +83,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case TD(CT_CLN): - action = &tap_dance_actions[TD_INDEX(keycode)]; + action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)]; if (!record->event.pressed && action->state.count && !action->state.finished) { tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data; tap_code16(tap_hold->tap); From b24bd2351a8536b85422db4157b06ee65cc9e90f Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 24 Dec 2023 06:52:58 +0000 Subject: [PATCH 2/2] Remove redundant audio eeconfig init (#22736) --- data/mappings/info_config.hjson | 2 ++ data/schemas/keyboard.jsonschema | 8 +++++++ docs/reference_info_json.md | 7 ++++++ quantum/audio/audio.c | 37 +++++++++++++++++++------------- quantum/audio/audio.h | 3 ++- quantum/eeconfig.c | 2 +- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/data/mappings/info_config.hjson b/data/mappings/info_config.hjson index 45c50a92424..7930eed642a 100644 --- a/data/mappings/info_config.hjson +++ b/data/mappings/info_config.hjson @@ -17,6 +17,8 @@ "APA102_DI_PIN": {"info_key": "apa102.data_pin"}, // Audio + "AUDIO_DEFAULT_ON": {"info_key": "audio.default.on", "value_type": "bool"}, + "AUDIO_DEFAULT_CLICKY_ON": {"info_key": "audio.default.clicky", "value_type": "bool"}, "AUDIO_VOICES": {"info_key": "audio.voices", "value_type": "bool"}, "SENDSTRING_BELL": {"info_key": "audio.macro_beep", "value_type": "bool"}, diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index 32d737a1d87..4836cf1fcae 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema @@ -123,6 +123,14 @@ "type": "object", "additionalProperties": false, "properties": { + "default": { + "type": "object", + "additionalProperties": false, + "properties": { + "on": {"type": "boolean"}, + "clicky": {"type": "boolean"} + } + }, "macro_beep": {"type": "boolean"}, "pins": {"$ref": "qmk.definitions.v1#/mcu_pin_array"}, "voices": {"type": "boolean"} diff --git a/docs/reference_info_json.md b/docs/reference_info_json.md index e102b9bfb94..1f73ec8faec 100644 --- a/docs/reference_info_json.md +++ b/docs/reference_info_json.md @@ -111,6 +111,13 @@ Configures the [APA102](apa102_driver.md) driver. Configures the [Audio](feature_audio.md) feature. * `audio` + * `default` + * `on` + * The default audio enabled state. + * Default: `true` + * `clicky` + * The default audio clicky enabled state. + * Default: `true` * `macro_beep` * Play a short beep for `\a` (ASCII `BEL`) characters in Send String macros. * Default: `false` diff --git a/quantum/audio/audio.c b/quantum/audio/audio.c index 28c82675172..c1a15004930 100644 --- a/quantum/audio/audio.c +++ b/quantum/audio/audio.c @@ -17,6 +17,7 @@ #include "audio.h" #include "eeconfig.h" #include "timer.h" +#include "debug.h" #include "wait.h" #include "util.h" @@ -62,6 +63,13 @@ * the internal state of the audio system does its calculations with the later - ms */ +#ifndef AUDIO_DEFAULT_ON +# define AUDIO_DEFAULT_ON true +#endif +#ifndef AUDIO_DEFAULT_CLICKY_ON +# define AUDIO_DEFAULT_CLICKY_ON true +#endif + #ifndef AUDIO_TONE_STACKSIZE # define AUDIO_TONE_STACKSIZE 8 #endif @@ -117,32 +125,31 @@ void eeconfig_update_audio_current(void) { eeconfig_update_audio(audio_config.raw); } +void eeconfig_update_audio_default(void) { + audio_config.valid = true; + audio_config.enable = AUDIO_DEFAULT_ON; + audio_config.clicky_enable = AUDIO_DEFAULT_CLICKY_ON; + eeconfig_update_audio(audio_config.raw); +} + void audio_init(void) { if (audio_initialized) { return; } - // Check EEPROM -#ifdef EEPROM_ENABLE - if (!eeconfig_is_enabled()) { - eeconfig_init(); - } audio_config.raw = eeconfig_read_audio(); -#else // EEPROM settings - audio_config.enable = true; -# ifdef AUDIO_CLICKY_ON - audio_config.clicky_enable = true; -# endif -#endif // EEPROM settings + if (!audio_config.valid) { + dprintf("audio_init audio_config.valid = 0. Write default values to EEPROM.\n"); + eeconfig_update_audio_default(); + } for (uint8_t i = 0; i < AUDIO_TONE_STACKSIZE; i++) { tones[i] = (musical_tone_t){.time_started = 0, .pitch = -1.0f, .duration = 0}; } - if (!audio_initialized) { - audio_driver_initialize(); - audio_initialized = true; - } + audio_driver_initialize(); + audio_initialized = true; + stop_all_notes(); #ifndef AUDIO_INIT_DELAY audio_startup(); diff --git a/quantum/audio/audio.h b/quantum/audio/audio.h index a4a908b43c5..eb0bedc6f9f 100644 --- a/quantum/audio/audio.h +++ b/quantum/audio/audio.h @@ -33,7 +33,8 @@ typedef union { struct { bool enable : 1; bool clicky_enable : 1; - uint8_t level : 6; + bool valid : 1; + uint8_t reserved : 5; }; } audio_config_t; diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index d9eea13758e..2d2180b4b44 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -54,7 +54,7 @@ void eeconfig_init_quantum(void) { // Enable oneshot and autocorrect by default: 0b0001 0100 0000 0000 eeprom_update_word(EECONFIG_KEYMAP, 0x1400); eeprom_update_byte(EECONFIG_BACKLIGHT, 0); - eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default + eeprom_update_byte(EECONFIG_AUDIO, 0); eeprom_update_dword(EECONFIG_RGBLIGHT, 0); eeprom_update_byte(EECONFIG_RGBLIGHT_EXTENDED, 0); eeprom_update_byte(EECONFIG_UNUSED, 0);