aboutsummaryrefslogtreecommitdiff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c76
1 files changed, 24 insertions, 52 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 96760de87..a62368ded 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -225,27 +225,39 @@ static uint16_t scs_timer[2] = {0, 0};
225 */ 225 */
226static bool grave_esc_was_shifted = false; 226static bool grave_esc_was_shifted = false;
227 227
228bool process_record_quantum(keyrecord_t *record) { 228/* Convert record into usable keycode via the contained event. */
229uint16_t get_record_keycode(keyrecord_t *record) {
230 return get_event_keycode(record->event);
231}
229 232
230 /* This gets the keycode from the key pressed */ 233
231 keypos_t key = record->event.key; 234/* Convert event into usable keycode. Checks the layer cache to ensure that it
232 uint16_t keycode; 235 * retains the correct keycode after a layer change, if the key is still pressed.
236 */
237uint16_t get_event_keycode(keyevent_t event) {
233 238
234 #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) 239 #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
235 /* TODO: Use store_or_get_action() or a similar function. */ 240 /* TODO: Use store_or_get_action() or a similar function. */
236 if (!disable_action_cache) { 241 if (!disable_action_cache) {
237 uint8_t layer; 242 uint8_t layer;
238 243
239 if (record->event.pressed) { 244 if (event.pressed) {
240 layer = layer_switch_get_layer(key); 245 layer = layer_switch_get_layer(event.key);
241 update_source_layers_cache(key, layer); 246 update_source_layers_cache(event.key, layer);
242 } else { 247 } else {
243 layer = read_source_layers_cache(key); 248 layer = read_source_layers_cache(event.key);
244 } 249 }
245 keycode = keymap_key_to_keycode(layer, key); 250 return keymap_key_to_keycode(layer, event.key);
246 } else 251 } else
247 #endif 252 #endif
248 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key); 253 return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
254}
255
256/* Main keycode processing function. Hands off handling to other functions,
257 * then processes internal Quantum keycodes, then processes ACTIONs.
258 */
259bool process_record_quantum(keyrecord_t *record) {
260 uint16_t keycode = get_record_keycode(record);
249 261
250 // This is how you use actions here 262 // This is how you use actions here
251 // if (keycode == KC_LEAD) { 263 // if (keycode == KC_LEAD) {
@@ -274,10 +286,10 @@ bool process_record_quantum(keyrecord_t *record) {
274 #ifdef HAPTIC_ENABLE 286 #ifdef HAPTIC_ENABLE
275 process_haptic(keycode, record) && 287 process_haptic(keycode, record) &&
276 #endif //HAPTIC_ENABLE 288 #endif //HAPTIC_ENABLE
277 process_record_kb(keycode, record) && 289 #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYREACTIVE_ENABLED)
278 #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES)
279 process_rgb_matrix(keycode, record) && 290 process_rgb_matrix(keycode, record) &&
280 #endif 291 #endif
292 process_record_kb(keycode, record) &&
281 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED) 293 #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
282 process_midi(keycode, record) && 294 process_midi(keycode, record) &&
283 #endif 295 #endif
@@ -360,9 +372,6 @@ bool process_record_quantum(keyrecord_t *record) {
360 if (!record->event.pressed) { 372 if (!record->event.pressed) {
361 #endif 373 #endif
362 rgblight_toggle(); 374 rgblight_toggle();
363 #ifdef SPLIT_KEYBOARD
364 RGB_DIRTY = true;
365 #endif
366 } 375 }
367 return false; 376 return false;
368 case RGB_MODE_FORWARD: 377 case RGB_MODE_FORWARD:
@@ -374,9 +383,6 @@ bool process_record_quantum(keyrecord_t *record) {
374 else { 383 else {
375 rgblight_step(); 384 rgblight_step();
376 } 385 }
377 #ifdef SPLIT_KEYBOARD
378 RGB_DIRTY = true;
379 #endif
380 } 386 }
381 return false; 387 return false;
382 case RGB_MODE_REVERSE: 388 case RGB_MODE_REVERSE:
@@ -388,9 +394,6 @@ bool process_record_quantum(keyrecord_t *record) {
388 else { 394 else {
389 rgblight_step_reverse(); 395 rgblight_step_reverse();
390 } 396 }
391 #ifdef SPLIT_KEYBOARD
392 RGB_DIRTY = true;
393 #endif
394 } 397 }
395 return false; 398 return false;
396 case RGB_HUI: 399 case RGB_HUI:
@@ -401,9 +404,6 @@ bool process_record_quantum(keyrecord_t *record) {
401 if (!record->event.pressed) { 404 if (!record->event.pressed) {
402 #endif 405 #endif
403 rgblight_increase_hue(); 406 rgblight_increase_hue();
404 #ifdef SPLIT_KEYBOARD
405 RGB_DIRTY = true;
406 #endif
407 } 407 }
408 return false; 408 return false;
409 case RGB_HUD: 409 case RGB_HUD:
@@ -414,9 +414,6 @@ bool process_record_quantum(keyrecord_t *record) {
414 if (!record->event.pressed) { 414 if (!record->event.pressed) {
415 #endif 415 #endif
416 rgblight_decrease_hue(); 416 rgblight_decrease_hue();
417 #ifdef SPLIT_KEYBOARD
418 RGB_DIRTY = true;
419 #endif
420 } 417 }
421 return false; 418 return false;
422 case RGB_SAI: 419 case RGB_SAI:
@@ -427,9 +424,6 @@ bool process_record_quantum(keyrecord_t *record) {
427 if (!record->event.pressed) { 424 if (!record->event.pressed) {
428 #endif 425 #endif
429 rgblight_increase_sat(); 426 rgblight_increase_sat();
430 #ifdef SPLIT_KEYBOARD
431 RGB_DIRTY = true;
432 #endif
433 } 427 }
434 return false; 428 return false;
435 case RGB_SAD: 429 case RGB_SAD:
@@ -440,9 +434,6 @@ bool process_record_quantum(keyrecord_t *record) {
440 if (!record->event.pressed) { 434 if (!record->event.pressed) {
441 #endif 435 #endif
442 rgblight_decrease_sat(); 436 rgblight_decrease_sat();
443 #ifdef SPLIT_KEYBOARD
444 RGB_DIRTY = true;
445 #endif
446 } 437 }
447 return false; 438 return false;
448 case RGB_VAI: 439 case RGB_VAI:
@@ -453,9 +444,6 @@ bool process_record_quantum(keyrecord_t *record) {
453 if (!record->event.pressed) { 444 if (!record->event.pressed) {
454 #endif 445 #endif
455 rgblight_increase_val(); 446 rgblight_increase_val();
456 #ifdef SPLIT_KEYBOARD
457 RGB_DIRTY = true;
458 #endif
459 } 447 }
460 return false; 448 return false;
461 case RGB_VAD: 449 case RGB_VAD:
@@ -466,9 +454,6 @@ bool process_record_quantum(keyrecord_t *record) {
466 if (!record->event.pressed) { 454 if (!record->event.pressed) {
467 #endif 455 #endif
468 rgblight_decrease_val(); 456 rgblight_decrease_val();
469 #ifdef SPLIT_KEYBOARD
470 RGB_DIRTY = true;
471 #endif
472 } 457 }
473 return false; 458 return false;
474 case RGB_SPI: 459 case RGB_SPI:
@@ -484,9 +469,6 @@ bool process_record_quantum(keyrecord_t *record) {
484 case RGB_MODE_PLAIN: 469 case RGB_MODE_PLAIN:
485 if (record->event.pressed) { 470 if (record->event.pressed) {
486 rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); 471 rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
487 #ifdef SPLIT_KEYBOARD
488 RGB_DIRTY = true;
489 #endif
490 } 472 }
491 return false; 473 return false;
492 case RGB_MODE_BREATHE: 474 case RGB_MODE_BREATHE:
@@ -1079,12 +1061,6 @@ void matrix_init_quantum() {
1079 matrix_init_kb(); 1061 matrix_init_kb();
1080} 1062}
1081 1063
1082uint8_t rgb_matrix_task_counter = 0;
1083
1084#ifndef RGB_MATRIX_SKIP_FRAMES
1085 #define RGB_MATRIX_SKIP_FRAMES 1
1086#endif
1087
1088void matrix_scan_quantum() { 1064void matrix_scan_quantum() {
1089 #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE) 1065 #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
1090 matrix_scan_music(); 1066 matrix_scan_music();
@@ -1108,10 +1084,6 @@ void matrix_scan_quantum() {
1108 1084
1109 #ifdef RGB_MATRIX_ENABLE 1085 #ifdef RGB_MATRIX_ENABLE
1110 rgb_matrix_task(); 1086 rgb_matrix_task();
1111 if (rgb_matrix_task_counter == 0) {
1112 rgb_matrix_update_pwm_buffers();
1113 }
1114 rgb_matrix_task_counter = ((rgb_matrix_task_counter + 1) % (RGB_MATRIX_SKIP_FRAMES + 1));
1115 #endif 1087 #endif
1116 1088
1117 #ifdef ENCODER_ENABLE 1089 #ifdef ENCODER_ENABLE