summary refs log tree commit diff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2021-08-29 08:20:25 +1000
committerNick Brassel <nick@tzarc.org>2021-08-29 08:20:25 +1000
commitf061ca497464fe85284906fb163a33eaee7a91ef (patch)
tree33ef1bfb529aed382e8526c607c4e18717f92571 /quantum/quantum.c
parentff65185dec6f97be1eb49f17cea526a0d0bbf3d6 (diff)
parent4bad375d7c09d949a9dcdd4feba147c9c7a67ec6 (diff)
Breaking changes develop merge to master, 2021Q3 edition. (#14196)
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c66
1 files changed, 42 insertions, 24 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 8ccdb774bd..e60378afe4 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -49,21 +49,18 @@ float goodbye_song[][2] = GOODBYE_SONG;
 #    ifdef DEFAULT_LAYER_SONGS
 float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
 #    endif
-#    ifdef SENDSTRING_BELL
-float bell_song[][2] = SONG(TERMINAL_SOUND);
-#    endif
 #endif
 
 #ifdef AUTO_SHIFT_ENABLE
 #    include "process_auto_shift.h"
 #endif
 
-static void do_code16(uint16_t code, void (*f)(uint8_t)) {
+uint8_t extract_mod_bits(uint16_t code) {
     switch (code) {
         case QK_MODS ... QK_MODS_MAX:
             break;
         default:
-            return;
+            return 0;
     }
 
     uint8_t mods_to_send = 0;
@@ -80,9 +77,11 @@ static void do_code16(uint16_t code, void (*f)(uint8_t)) {
         if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI);
     }
 
-    f(mods_to_send);
+    return mods_to_send;
 }
 
+static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); }
+
 void register_code16(uint16_t code) {
     if (IS_MOD(code) || code == KC_NO) {
         do_code16(code, register_mods);
@@ -144,7 +143,13 @@ void reset_keyboard(void) {
 }
 
 /* Convert record into usable keycode via the contained event. */
-uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) { return get_event_keycode(record->event, update_layer_cache); }
+uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) {
+#ifdef COMBO_ENABLE
+    if (record->keycode) { return record->keycode; }
+#endif
+    return get_event_keycode(record->event, update_layer_cache);
+}
+
 
 /* Convert event into usable keycode. Checks the layer cache to ensure that it
  * retains the correct keycode after a layer change, if the key is still pressed.
@@ -170,6 +175,18 @@ uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) {
         return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
 }
 
+/* Get keycode, and then process pre tapping functionality */
+bool pre_process_record_quantum(keyrecord_t *record) {
+    if (!(
+#ifdef COMBO_ENABLE
+        process_combo(get_record_keycode(record, true), record) &&
+#endif
+        true)) {
+        return false;
+    }
+    return true; // continue processing
+}
+
 /* Get keycode, and then call keyboard function */
 void post_process_record_quantum(keyrecord_t *record) {
     uint16_t keycode = get_record_keycode(record, false);
@@ -217,10 +234,10 @@ bool process_record_quantum(keyrecord_t *record) {
 #endif
 #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
             process_clicky(keycode, record) &&
-#endif  // AUDIO_CLICKY
+#endif
 #ifdef HAPTIC_ENABLE
             process_haptic(keycode, record) &&
-#endif  // HAPTIC_ENABLE
+#endif
 #if defined(VIA_ENABLE)
             process_record_via(keycode, record) &&
 #endif
@@ -243,6 +260,9 @@ bool process_record_quantum(keyrecord_t *record) {
 #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
             process_music(keycode, record) &&
 #endif
+#ifdef KEY_OVERRIDE_ENABLE
+            process_key_override(keycode, record) &&
+#endif
 #ifdef TAP_DANCE_ENABLE
             process_tap_dance(keycode, record) &&
 #endif
@@ -252,9 +272,6 @@ bool process_record_quantum(keyrecord_t *record) {
 #ifdef LEADER_ENABLE
             process_leader(keycode, record) &&
 #endif
-#ifdef COMBO_ENABLE
-            process_combo(keycode, record) &&
-#endif
 #ifdef PRINTING_ENABLE
             process_printer(keycode, record) &&
 #endif
@@ -340,13 +357,13 @@ void set_single_persistent_default_layer(uint8_t default_layer) {
 #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS)
     PLAY_SONG(default_layer_songs[default_layer]);
 #endif
-    eeconfig_update_default_layer(1U << default_layer);
-    default_layer_set(1U << default_layer);
+    eeconfig_update_default_layer((layer_state_t)1 << default_layer);
+    default_layer_set((layer_state_t)1 << default_layer);
 }
 
 layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) {
-    layer_state_t mask12 = (1UL << layer1) | (1UL << layer2);
-    layer_state_t mask3  = 1UL << layer3;
+    layer_state_t mask12 = ((layer_state_t)1 << layer1) | ((layer_state_t)1 << layer2);
+    layer_state_t mask3  = (layer_state_t)1 << layer3;
     return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3);
 }
 
@@ -354,10 +371,7 @@ void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_st
 
 void matrix_init_quantum() {
     magic();
-#if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN)
-    // TODO: remove calls to led_init_ports from keyboards and remove ifdef
     led_init_ports();
-#endif
 #ifdef BACKLIGHT_ENABLE
     backlight_init_ports();
 #endif
@@ -384,7 +398,7 @@ void matrix_init_quantum() {
 }
 
 void matrix_scan_quantum() {
-#if defined(AUDIO_ENABLE)
+#if defined(AUDIO_ENABLE) && defined(AUDIO_INIT_DELAY)
     // There are some tasks that need to be run a little bit
     // after keyboard startup, or else they will not work correctly
     // because of interaction with the USB device state, which
@@ -405,19 +419,23 @@ void matrix_scan_quantum() {
 #endif
 
 #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
-    matrix_scan_music();
+    music_task();
+#endif
+
+#ifdef KEY_OVERRIDE_ENABLE
+    key_override_task();
 #endif
 
 #ifdef SEQUENCER_ENABLE
-    matrix_scan_sequencer();
+    sequencer_task();
 #endif
 
 #ifdef TAP_DANCE_ENABLE
-    matrix_scan_tap_dance();
+    tap_dance_task();
 #endif
 
 #ifdef COMBO_ENABLE
-    matrix_scan_combo();
+    combo_task();
 #endif
 
 #ifdef LED_MATRIX_ENABLE