aboutsummaryrefslogtreecommitdiff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c131
1 files changed, 111 insertions, 20 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 0ae12b583..c7a3bb197 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -25,10 +25,6 @@
25# include "backlight.h" 25# include "backlight.h"
26#endif 26#endif
27 27
28#ifdef API_ENABLE
29# include "api.h"
30#endif
31
32#ifdef MIDI_ENABLE 28#ifdef MIDI_ENABLE
33# include "process_midi.h" 29# include "process_midi.h"
34#endif 30#endif
@@ -66,15 +62,15 @@ uint8_t extract_mod_bits(uint16_t code) {
66 uint8_t mods_to_send = 0; 62 uint8_t mods_to_send = 0;
67 63
68 if (code & QK_RMODS_MIN) { // Right mod flag is set 64 if (code & QK_RMODS_MIN) { // Right mod flag is set
69 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RCTL); 65 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RIGHT_CTRL);
70 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT); 66 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RIGHT_SHIFT);
71 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT); 67 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RIGHT_ALT);
72 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI); 68 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RIGHT_GUI);
73 } else { 69 } else {
74 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL); 70 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LEFT_CTRL);
75 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT); 71 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LEFT_SHIFT);
76 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT); 72 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LEFT_ALT);
77 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI); 73 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LEFT_GUI);
78 } 74 }
79 75
80 return mods_to_send; 76 return mods_to_send;
@@ -297,6 +293,9 @@ bool process_record_quantum(keyrecord_t *record) {
297#ifdef JOYSTICK_ENABLE 293#ifdef JOYSTICK_ENABLE
298 process_joystick(keycode, record) && 294 process_joystick(keycode, record) &&
299#endif 295#endif
296#ifdef PROGRAMMABLE_BUTTON_ENABLE
297 process_programmable_button(keycode, record) &&
298#endif
300 true)) { 299 true)) {
301 return false; 300 return false;
302 } 301 }
@@ -466,14 +465,6 @@ void matrix_scan_quantum() {
466# include "hd44780.h" 465# include "hd44780.h"
467#endif 466#endif
468 467
469void api_send_unicode(uint32_t unicode) {
470#ifdef API_ENABLE
471 uint8_t chunk[4];
472 dword_to_bytes(unicode, chunk);
473 MT_SEND_DATA(DT_UNICODE, chunk, 5);
474#endif
475}
476
477//------------------------------------------------------------------------------ 468//------------------------------------------------------------------------------
478// Override these functions in your keymap file to play different tunes on 469// Override these functions in your keymap file to play different tunes on
479// different events such as startup and bootloader jump 470// different events such as startup and bootloader jump
@@ -481,3 +472,103 @@ void api_send_unicode(uint32_t unicode) {
481__attribute__((weak)) void startup_user() {} 472__attribute__((weak)) void startup_user() {}
482 473
483__attribute__((weak)) void shutdown_user() {} 474__attribute__((weak)) void shutdown_user() {}
475
476/** \brief Run keyboard level Power down
477 *
478 * FIXME: needs doc
479 */
480__attribute__((weak)) void suspend_power_down_user(void) {}
481/** \brief Run keyboard level Power down
482 *
483 * FIXME: needs doc
484 */
485__attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); }
486
487void suspend_power_down_quantum(void) {
488#ifndef NO_SUSPEND_POWER_DOWN
489// Turn off backlight
490# ifdef BACKLIGHT_ENABLE
491 backlight_set(0);
492# endif
493
494# ifdef LED_MATRIX_ENABLE
495 led_matrix_task();
496# endif
497# ifdef RGB_MATRIX_ENABLE
498 rgb_matrix_task();
499# endif
500
501 // Turn off LED indicators
502 uint8_t leds_off = 0;
503# if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
504 if (is_backlight_enabled()) {
505 // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
506 leds_off |= (1 << USB_LED_CAPS_LOCK);
507 }
508# endif
509 led_set(leds_off);
510
511// Turn off audio
512# ifdef AUDIO_ENABLE
513 stop_all_notes();
514# endif
515
516// Turn off underglow
517# if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
518 rgblight_suspend();
519# endif
520
521# if defined(LED_MATRIX_ENABLE)
522 led_matrix_set_suspend_state(true);
523# endif
524# if defined(RGB_MATRIX_ENABLE)
525 rgb_matrix_set_suspend_state(true);
526# endif
527
528# ifdef OLED_ENABLE
529 oled_off();
530# endif
531# ifdef ST7565_ENABLE
532 st7565_off();
533# endif
534# if defined(POINTING_DEVICE_ENABLE)
535 // run to ensure scanning occurs while suspended
536 pointing_device_task();
537# endif
538#endif
539}
540
541/** \brief run user level code immediately after wakeup
542 *
543 * FIXME: needs doc
544 */
545__attribute__((weak)) void suspend_wakeup_init_user(void) {}
546
547/** \brief run keyboard level code immediately after wakeup
548 *
549 * FIXME: needs doc
550 */
551__attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); }
552
553__attribute__((weak)) void suspend_wakeup_init_quantum(void) {
554// Turn on backlight
555#ifdef BACKLIGHT_ENABLE
556 backlight_init();
557#endif
558
559 // Restore LED indicators
560 led_set(host_keyboard_leds());
561
562// Wake up underglow
563#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
564 rgblight_wakeup();
565#endif
566
567#if defined(LED_MATRIX_ENABLE)
568 led_matrix_set_suspend_state(false);
569#endif
570#if defined(RGB_MATRIX_ENABLE)
571 rgb_matrix_set_suspend_state(false);
572#endif
573 suspend_wakeup_init_kb();
574}