aboutsummaryrefslogtreecommitdiff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
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 8ccdb774b..e60378afe 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -49,21 +49,18 @@ float goodbye_song[][2] = GOODBYE_SONG;
49# ifdef DEFAULT_LAYER_SONGS 49# ifdef DEFAULT_LAYER_SONGS
50float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS; 50float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
51# endif 51# endif
52# ifdef SENDSTRING_BELL
53float bell_song[][2] = SONG(TERMINAL_SOUND);
54# endif
55#endif 52#endif
56 53
57#ifdef AUTO_SHIFT_ENABLE 54#ifdef AUTO_SHIFT_ENABLE
58# include "process_auto_shift.h" 55# include "process_auto_shift.h"
59#endif 56#endif
60 57
61static void do_code16(uint16_t code, void (*f)(uint8_t)) { 58uint8_t extract_mod_bits(uint16_t code) {
62 switch (code) { 59 switch (code) {
63 case QK_MODS ... QK_MODS_MAX: 60 case QK_MODS ... QK_MODS_MAX:
64 break; 61 break;
65 default: 62 default:
66 return; 63 return 0;
67 } 64 }
68 65
69 uint8_t mods_to_send = 0; 66 uint8_t mods_to_send = 0;
@@ -80,9 +77,11 @@ static void do_code16(uint16_t code, void (*f)(uint8_t)) {
80 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI); 77 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI);
81 } 78 }
82 79
83 f(mods_to_send); 80 return mods_to_send;
84} 81}
85 82
83static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); }
84
86void register_code16(uint16_t code) { 85void register_code16(uint16_t code) {
87 if (IS_MOD(code) || code == KC_NO) { 86 if (IS_MOD(code) || code == KC_NO) {
88 do_code16(code, register_mods); 87 do_code16(code, register_mods);
@@ -144,7 +143,13 @@ void reset_keyboard(void) {
144} 143}
145 144
146/* Convert record into usable keycode via the contained event. */ 145/* Convert record into usable keycode via the contained event. */
147uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) { return get_event_keycode(record->event, update_layer_cache); } 146uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) {
147#ifdef COMBO_ENABLE
148 if (record->keycode) { return record->keycode; }
149#endif
150 return get_event_keycode(record->event, update_layer_cache);
151}
152
148 153
149/* Convert event into usable keycode. Checks the layer cache to ensure that it 154/* Convert event into usable keycode. Checks the layer cache to ensure that it
150 * retains the correct keycode after a layer change, if the key is still pressed. 155 * 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) {
170 return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key); 175 return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
171} 176}
172 177
178/* Get keycode, and then process pre tapping functionality */
179bool pre_process_record_quantum(keyrecord_t *record) {
180 if (!(
181#ifdef COMBO_ENABLE
182 process_combo(get_record_keycode(record, true), record) &&
183#endif
184 true)) {
185 return false;
186 }
187 return true; // continue processing
188}
189
173/* Get keycode, and then call keyboard function */ 190/* Get keycode, and then call keyboard function */
174void post_process_record_quantum(keyrecord_t *record) { 191void post_process_record_quantum(keyrecord_t *record) {
175 uint16_t keycode = get_record_keycode(record, false); 192 uint16_t keycode = get_record_keycode(record, false);
@@ -217,10 +234,10 @@ bool process_record_quantum(keyrecord_t *record) {
217#endif 234#endif
218#if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) 235#if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
219 process_clicky(keycode, record) && 236 process_clicky(keycode, record) &&
220#endif // AUDIO_CLICKY 237#endif
221#ifdef HAPTIC_ENABLE 238#ifdef HAPTIC_ENABLE
222 process_haptic(keycode, record) && 239 process_haptic(keycode, record) &&
223#endif // HAPTIC_ENABLE 240#endif
224#if defined(VIA_ENABLE) 241#if defined(VIA_ENABLE)
225 process_record_via(keycode, record) && 242 process_record_via(keycode, record) &&
226#endif 243#endif
@@ -243,6 +260,9 @@ bool process_record_quantum(keyrecord_t *record) {
243#if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) 260#if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
244 process_music(keycode, record) && 261 process_music(keycode, record) &&
245#endif 262#endif
263#ifdef KEY_OVERRIDE_ENABLE
264 process_key_override(keycode, record) &&
265#endif
246#ifdef TAP_DANCE_ENABLE 266#ifdef TAP_DANCE_ENABLE
247 process_tap_dance(keycode, record) && 267 process_tap_dance(keycode, record) &&
248#endif 268#endif
@@ -252,9 +272,6 @@ bool process_record_quantum(keyrecord_t *record) {
252#ifdef LEADER_ENABLE 272#ifdef LEADER_ENABLE
253 process_leader(keycode, record) && 273 process_leader(keycode, record) &&
254#endif 274#endif
255#ifdef COMBO_ENABLE
256 process_combo(keycode, record) &&
257#endif
258#ifdef PRINTING_ENABLE 275#ifdef PRINTING_ENABLE
259 process_printer(keycode, record) && 276 process_printer(keycode, record) &&
260#endif 277#endif
@@ -340,13 +357,13 @@ void set_single_persistent_default_layer(uint8_t default_layer) {
340#if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS) 357#if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS)
341 PLAY_SONG(default_layer_songs[default_layer]); 358 PLAY_SONG(default_layer_songs[default_layer]);
342#endif 359#endif
343 eeconfig_update_default_layer(1U << default_layer); 360 eeconfig_update_default_layer((layer_state_t)1 << default_layer);
344 default_layer_set(1U << default_layer); 361 default_layer_set((layer_state_t)1 << default_layer);
345} 362}
346 363
347layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) { 364layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3) {
348 layer_state_t mask12 = (1UL << layer1) | (1UL << layer2); 365 layer_state_t mask12 = ((layer_state_t)1 << layer1) | ((layer_state_t)1 << layer2);
349 layer_state_t mask3 = 1UL << layer3; 366 layer_state_t mask3 = (layer_state_t)1 << layer3;
350 return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3); 367 return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3);
351} 368}
352 369
@@ -354,10 +371,7 @@ void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_st
354 371
355void matrix_init_quantum() { 372void matrix_init_quantum() {
356 magic(); 373 magic();
357#if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN)
358 // TODO: remove calls to led_init_ports from keyboards and remove ifdef
359 led_init_ports(); 374 led_init_ports();
360#endif
361#ifdef BACKLIGHT_ENABLE 375#ifdef BACKLIGHT_ENABLE
362 backlight_init_ports(); 376 backlight_init_ports();
363#endif 377#endif
@@ -384,7 +398,7 @@ void matrix_init_quantum() {
384} 398}
385 399
386void matrix_scan_quantum() { 400void matrix_scan_quantum() {
387#if defined(AUDIO_ENABLE) 401#if defined(AUDIO_ENABLE) && defined(AUDIO_INIT_DELAY)
388 // There are some tasks that need to be run a little bit 402 // There are some tasks that need to be run a little bit
389 // after keyboard startup, or else they will not work correctly 403 // after keyboard startup, or else they will not work correctly
390 // because of interaction with the USB device state, which 404 // because of interaction with the USB device state, which
@@ -405,19 +419,23 @@ void matrix_scan_quantum() {
405#endif 419#endif
406 420
407#if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) 421#if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
408 matrix_scan_music(); 422 music_task();
423#endif
424
425#ifdef KEY_OVERRIDE_ENABLE
426 key_override_task();
409#endif 427#endif
410 428
411#ifdef SEQUENCER_ENABLE 429#ifdef SEQUENCER_ENABLE
412 matrix_scan_sequencer(); 430 sequencer_task();
413#endif 431#endif
414 432
415#ifdef TAP_DANCE_ENABLE 433#ifdef TAP_DANCE_ENABLE
416 matrix_scan_tap_dance(); 434 tap_dance_task();
417#endif 435#endif
418 436
419#ifdef COMBO_ENABLE 437#ifdef COMBO_ENABLE
420 matrix_scan_combo(); 438 combo_task();
421#endif 439#endif
422 440
423#ifdef LED_MATRIX_ENABLE 441#ifdef LED_MATRIX_ENABLE