summaryrefslogtreecommitdiff
path: root/quantum/quantum.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r--quantum/quantum.c205
1 files changed, 178 insertions, 27 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 14f25597ca..5568c54703 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -26,10 +26,6 @@
# include "backlight.h"
#endif
-#ifdef API_ENABLE
-# include "api.h"
-#endif
-
#ifdef MIDI_ENABLE
# include "process_midi.h"
#endif
@@ -67,15 +63,15 @@ 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_LCTL) mods_to_send |= MOD_BIT(KC_RCTL);
- if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT);
- if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT);
- if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI);
+ 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);
+ if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RIGHT_GUI);
} else {
- if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL);
- if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT);
- if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT);
- if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI);
+ if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LEFT_CTRL);
+ if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LEFT_SHIFT);
+ if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LEFT_ALT);
+ if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LEFT_GUI);
}
return mods_to_send;
@@ -146,12 +142,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) {
#ifdef COMBO_ENABLE
- if (record->keycode) { return record->keycode; }
+ 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.
* "update_layer_cache" is to ensure that it only updates the layer cache when
@@ -180,12 +177,12 @@ uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) {
bool pre_process_record_quantum(keyrecord_t *record) {
if (!(
#ifdef COMBO_ENABLE
- process_combo(get_record_keycode(record, true), record) &&
+ process_combo(get_record_keycode(record, true), record) &&
#endif
- true)) {
+ true)) {
return false;
}
- return true; // continue processing
+ return true; // continue processing
}
/* Get keycode, and then call keyboard function */
@@ -282,6 +279,9 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef AUTO_SHIFT_ENABLE
process_auto_shift(keycode, record) &&
#endif
+#ifdef DYNAMIC_TAPPING_TERM_ENABLE
+ process_dynamic_tapping_term(keycode, record) &&
+#endif
#ifdef TERMINAL_ENABLE
process_terminal(keycode, record) &&
#endif
@@ -300,6 +300,9 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef JOYSTICK_ENABLE
process_joystick(keycode, record) &&
#endif
+#ifdef PROGRAMMABLE_BUTTON_ENABLE
+ process_programmable_button(keycode, record) &&
+#endif
true)) {
return false;
}
@@ -479,14 +482,6 @@ void matrix_scan_quantum() {
# include "hd44780.h"
#endif
-void api_send_unicode(uint32_t unicode) {
-#ifdef API_ENABLE
- uint8_t chunk[4];
- dword_to_bytes(unicode, chunk);
- MT_SEND_DATA(DT_UNICODE, chunk, 5);
-#endif
-}
-
//------------------------------------------------------------------------------
// Override these functions in your keymap file to play different tunes on
// different events such as startup and bootloader jump
@@ -500,10 +495,166 @@ __attribute__((weak)) bool webusb_receive_user(uint8_t *data, uint8_t length) {
__attribute__((weak)) bool webusb_receive_kb(uint8_t *data, uint8_t length) { return webusb_receive_user(data, length); }
bool webusb_receive_quantum(uint8_t *data, uint8_t length) {
-#ifdef ORYX_ENABLE
+# ifdef ORYX_ENABLE
return webusb_receive_oryx(data, length);
-#else
+# else
return webusb_receive_kb(data, length);
+# endif
+}
+#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(); }
+
+void suspend_power_down_quantum(void) {
+#ifndef NO_SUSPEND_POWER_DOWN
+// Turn off backlight
+# ifdef BACKLIGHT_ENABLE
+ backlight_set(0);
+# endif
+
+# ifdef LED_MATRIX_ENABLE
+ led_matrix_task();
+# endif
+# ifdef RGB_MATRIX_ENABLE
+ rgb_matrix_task();
+# 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);
+
+// Turn off audio
+# ifdef AUDIO_ENABLE
+ stop_all_notes();
+# endif
+
+// Turn off underglow
+# if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
+ rgblight_suspend();
+# endif
+
+# if defined(LED_MATRIX_ENABLE)
+ led_matrix_set_suspend_state(true);
+# endif
+# if defined(RGB_MATRIX_ENABLE)
+ rgb_matrix_set_suspend_state(true);
+# endif
+
+# ifdef OLED_ENABLE
+ oled_off();
+# endif
+# ifdef ST7565_ENABLE
+ st7565_off();
+# endif
+# if defined(POINTING_DEVICE_ENABLE)
+ // run to ensure scanning occurs while suspended
+ pointing_device_task();
+# endif
#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
+ backlight_init();
+#endif
+
+ // Restore LED indicators
+ led_set(host_keyboard_leds());
+
+// Wake up underglow
+#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
+ rgblight_wakeup();
#endif
+
+#if defined(LED_MATRIX_ENABLE)
+ led_matrix_set_suspend_state(false);
+#endif
+#if defined(RGB_MATRIX_ENABLE)
+ rgb_matrix_set_suspend_state(false);
+#endif
+ suspend_wakeup_init_kb();
+}
+
+/** \brief converts unsigned integers into char arrays
+ *
+ * Takes an unsigned integer and converts that value into an equivalent char array
+ * A padding character may be specified, ' ' for leading spaces, '0' for leading zeros.
+ */
+
+const char *get_numeric_str(char *buf, size_t buf_len, uint32_t curr_num, char curr_pad) {
+ buf[buf_len - 1] = '\0';
+ for (size_t i = 0; i < buf_len - 1; ++i) {
+ char c = '0' + curr_num % 10;
+ buf[buf_len - 2 - i] = (c == '0' && i == 0) ? '0' : (curr_num > 0 ? c : curr_pad);
+ curr_num /= 10;
+ }
+ return buf;
+}
+
+/** \brief converts uint8_t into char array
+ *
+ * Takes an uint8_t, and uses an internal static buffer to render that value into a char array
+ * A padding character may be specified, ' ' for leading spaces, '0' for leading zeros.
+ *
+ * NOTE: Subsequent invocations will reuse the same static buffer and overwrite the previous
+ * contents. Use the result immediately, instead of caching it.
+ */
+const char *get_u8_str(uint8_t curr_num, char curr_pad) {
+ static char buf[4] = {0};
+ static uint8_t last_num = 0xFF;
+ static char last_pad = '\0';
+ if (last_num == curr_num && last_pad == curr_pad) {
+ return buf;
+ }
+ last_num = curr_num;
+ last_pad = curr_pad;
+ return get_numeric_str(buf, sizeof(buf), curr_num, curr_pad);
+}
+
+/** \brief converts uint16_t into char array
+ *
+ * Takes an uint16_t, and uses an internal static buffer to render that value into a char array
+ * A padding character may be specified, ' ' for leading spaces, '0' for leading zeros.
+ *
+ * NOTE: Subsequent invocations will reuse the same static buffer and overwrite the previous
+ * contents. Use the result immediately, instead of caching it.
+ */
+const char *get_u16_str(uint16_t curr_num, char curr_pad) {
+ static char buf[6] = {0};
+ static uint16_t last_num = 0xFF;
+ static char last_pad = '\0';
+ if (last_num == curr_num && last_pad == curr_pad) {
+ return buf;
+ }
+ last_num = curr_num;
+ last_pad = curr_pad;
+ return get_numeric_str(buf, sizeof(buf), curr_num, curr_pad);
+}