summaryrefslogtreecommitdiff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
authorDrashna Jael're <drashna@live.com>2022-03-25 16:19:22 -0700
committerDrashna Jael're <drashna@live.com>2022-03-25 16:19:22 -0700
commit53ff570bf068e04740f187163774327839dfa68b (patch)
tree5429e069fc593d484b0b479de422b51ac239be83 /quantum/quantum.c
parente8171efc7158ba4ebb24827680b19b775d366b1a (diff)
parentefc9c525b19b33c6e09057218ea64f07f45f9555 (diff)
Remerge 0.16.x' into firmware21
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c207
1 files changed, 47 insertions, 160 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 5568c54703..3dc613dc7c 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -16,7 +16,6 @@
#include <ctype.h>
#include "quantum.h"
-#include "magic.h"
#ifdef BLUETOOTH_ENABLE
# include "outputselect.h"
@@ -48,10 +47,6 @@ float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
# endif
#endif
-#ifdef AUTO_SHIFT_ENABLE
-# include "process_auto_shift.h"
-#endif
-
uint8_t extract_mod_bits(uint16_t code) {
switch (code) {
case QK_MODS ... QK_MODS_MAX:
@@ -62,7 +57,7 @@ uint8_t extract_mod_bits(uint16_t code) {
uint8_t mods_to_send = 0;
- if (code & QK_RMODS_MIN) { // Right mod flag is set
+ if (code & QK_RMODS_MIN) { // Right mod flag is set
if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RIGHT_CTRL);
if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RIGHT_SHIFT);
if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RIGHT_ALT);
@@ -77,9 +72,11 @@ uint8_t extract_mod_bits(uint16_t code) {
return mods_to_send;
}
-static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); }
+void do_code16(uint16_t code, void (*f)(uint8_t)) {
+ f(extract_mod_bits(code));
+}
-void register_code16(uint16_t code) {
+__attribute__((weak)) void register_code16(uint16_t code) {
if (IS_MOD(code) || code == KC_NO) {
do_code16(code, register_mods);
} else {
@@ -88,7 +85,7 @@ void register_code16(uint16_t code) {
register_code(code);
}
-void unregister_code16(uint16_t code) {
+__attribute__((weak)) void unregister_code16(uint16_t code) {
unregister_code(code);
if (IS_MOD(code) || code == KC_NO) {
do_code16(code, unregister_mods);
@@ -97,21 +94,31 @@ void unregister_code16(uint16_t code) {
}
}
-void tap_code16(uint16_t code) {
+__attribute__((weak)) void tap_code16(uint16_t code) {
register_code16(code);
-#if TAP_CODE_DELAY > 0
- wait_ms(TAP_CODE_DELAY);
-#endif
+ if (code == KC_CAPS_LOCK) {
+ wait_ms(TAP_HOLD_CAPS_DELAY);
+ } else if (TAP_CODE_DELAY > 0) {
+ wait_ms(TAP_CODE_DELAY);
+ }
unregister_code16(code);
}
-__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; }
+__attribute__((weak)) bool process_action_kb(keyrecord_t *record) {
+ return true;
+}
-__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); }
+__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
+ return process_record_user(keycode, record);
+}
-__attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *record) { return true; }
+__attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *record) {
+ return true;
+}
-__attribute__((weak)) void post_process_record_kb(uint16_t keycode, keyrecord_t *record) { post_process_record_user(keycode, record); }
+__attribute__((weak)) void post_process_record_kb(uint16_t keycode, keyrecord_t *record) {
+ post_process_record_user(keycode, record);
+}
__attribute__((weak)) void post_process_record_user(uint16_t keycode, keyrecord_t *record) {}
@@ -127,7 +134,8 @@ void reset_keyboard(void) {
uint16_t timer_start = timer_read();
PLAY_SONG(goodbye_song);
shutdown_user();
- while (timer_elapsed(timer_start) < 250) wait_ms(1);
+ while (timer_elapsed(timer_start) < 250)
+ wait_ms(1);
stop_all_notes();
#else
shutdown_user();
@@ -182,7 +190,7 @@ bool pre_process_record_quantum(keyrecord_t *record) {
true)) {
return false;
}
- return true; // continue processing
+ return true; // continue processing
}
/* Get keycode, and then call keyboard function */
@@ -267,7 +275,7 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef TAP_DANCE_ENABLE
process_tap_dance(keycode, record) &&
#endif
-#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
+#if defined(UNICODE_COMMON_ENABLE)
process_unicode_common(keycode, record) &&
#endif
#ifdef LEADER_ENABLE
@@ -310,12 +318,12 @@ bool process_record_quantum(keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
#ifndef NO_RESET
- case RESET:
+ case QK_BOOTLOADER:
reset_keyboard();
return false;
#endif
#ifndef NO_DEBUG
- case DEBUG:
+ case QK_DEBUG_TOGGLE:
debug_enable ^= 1;
if (debug_enable) {
print("DEBUG: enabled.\n");
@@ -324,7 +332,7 @@ bool process_record_quantum(keyrecord_t *record) {
}
#endif
return false;
- case EEPROM_RESET:
+ case QK_CLEAR_EEPROM:
eeconfig_init();
return false;
#ifdef VELOCIKEY_ENABLE
@@ -375,120 +383,18 @@ layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_
return (state & mask12) == mask12 ? (state | mask3) : (state & ~mask3);
}
-void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); }
+void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
+ layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3));
+}
+// TODO: remove legacy api
void matrix_init_quantum() {
-
- magic();
-
-#if defined(ORYX_ENABLE) && defined(DYNAMIC_KEYMAP_ENABLE)
- matrix_init_oryx();
-#endif
-
-#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
-#ifdef AUDIO_ENABLE
- audio_init();
-#endif
-#ifdef LED_MATRIX_ENABLE
- led_matrix_init();
-#endif
-#ifdef RGB_MATRIX_ENABLE
- rgb_matrix_init();
-#endif
-#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
- unicode_input_mode_init();
-#endif
-#ifdef HAPTIC_ENABLE
- haptic_init();
-#endif
-#if defined(BLUETOOTH_ENABLE) && defined(OUTPUT_AUTO_ENABLE)
- set_output(OUTPUT_AUTO);
-#endif
-
matrix_init_kb();
}
-
void matrix_scan_quantum() {
-#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
- // may still be in flux...
- //
- // At the moment the only feature that needs this is the
- // startup song.
- static bool delayed_tasks_run = false;
- static uint16_t delayed_task_timer = 0;
- if (!delayed_tasks_run) {
- if (!delayed_task_timer) {
- delayed_task_timer = timer_read();
- } else if (timer_elapsed(delayed_task_timer) > 300) {
- audio_startup();
- delayed_tasks_run = true;
- }
- }
-#endif
-
-#if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
- music_task();
-#endif
-
-#ifdef KEY_OVERRIDE_ENABLE
- key_override_task();
-#endif
-
-#ifdef SEQUENCER_ENABLE
- sequencer_task();
-#endif
-
-#ifdef TAP_DANCE_ENABLE
- tap_dance_task();
-#endif
-
-#ifdef COMBO_ENABLE
- combo_task();
-#endif
-
-#ifdef LED_MATRIX_ENABLE
- led_matrix_task();
-#endif
-
-#ifdef WPM_ENABLE
- decay_wpm();
-#endif
-
-#ifdef HAPTIC_ENABLE
- haptic_task();
-#endif
-
-#ifdef DIP_SWITCH_ENABLE
- dip_switch_read(false);
-#endif
-
-#ifdef AUTO_SHIFT_ENABLE
- autoshift_matrix_scan();
-#endif
-
matrix_scan_kb();
}
-#ifdef HD44780_ENABLED
-# include "hd44780.h"
-#endif
-
-//------------------------------------------------------------------------------
-// Override these functions in your keymap file to play different tunes on
-// different events such as startup and bootloader jump
-
-__attribute__((weak)) void startup_user() {}
-
-__attribute__((weak)) void shutdown_user() {}
#ifdef WEBUSB_ENABLE
__attribute__((weak)) bool webusb_receive_user(uint8_t *data, uint8_t length) { return false; }
@@ -503,18 +409,18 @@ bool webusb_receive_quantum(uint8_t *data, uint8_t length) {
}
#endif
-/** \brief Run keyboard level Power down
- *
- * FIXME: needs doc
- */
-__attribute__((weak)) void suspend_power_down_user(void) {}
-/** \brief Run keyboard level Power down
- *
- * FIXME: needs doc
- */
-__attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user(); }
+
+//------------------------------------------------------------------------------
+// Override these functions in your keymap file to play different tunes on
+// different events such as startup and bootloader jump
+
+__attribute__((weak)) void startup_user() {}
+
+__attribute__((weak)) void shutdown_user() {}
+
void suspend_power_down_quantum(void) {
+ suspend_power_down_kb();
#ifndef NO_SUSPEND_POWER_DOWN
// Turn off backlight
# ifdef BACKLIGHT_ENABLE
@@ -529,14 +435,7 @@ void suspend_power_down_quantum(void) {
# endif
// Turn off LED indicators
- uint8_t leds_off = 0;
-# if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
- if (is_backlight_enabled()) {
- // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
- leds_off |= (1 << USB_LED_CAPS_LOCK);
- }
-# endif
- led_set(leds_off);
+ led_suspend();
// Turn off audio
# ifdef AUDIO_ENABLE
@@ -568,18 +467,6 @@ void suspend_power_down_quantum(void) {
#endif
}
-/** \brief run user level code immediately after wakeup
- *
- * FIXME: needs doc
- */
-__attribute__((weak)) void suspend_wakeup_init_user(void) {}
-
-/** \brief run keyboard level code immediately after wakeup
- *
- * FIXME: needs doc
- */
-__attribute__((weak)) void suspend_wakeup_init_kb(void) { suspend_wakeup_init_user(); }
-
__attribute__((weak)) void suspend_wakeup_init_quantum(void) {
// Turn on backlight
#ifdef BACKLIGHT_ENABLE
@@ -587,7 +474,7 @@ __attribute__((weak)) void suspend_wakeup_init_quantum(void) {
#endif
// Restore LED indicators
- led_set(host_keyboard_leds());
+ led_wakeup();
// Wake up underglow
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)