summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/action.c149
-rw-r--r--quantum/action_code.h6
-rw-r--r--quantum/backlight/backlight_chibios.c51
-rw-r--r--quantum/backlight/backlight_driver_common.c2
-rw-r--r--quantum/backlight/backlight_software.c2
-rw-r--r--quantum/config_common.h4
-rw-r--r--quantum/dip_switch.c4
-rw-r--r--quantum/dynamic_keymap.c29
-rw-r--r--quantum/eeconfig.c13
-rw-r--r--quantum/encoder.c8
-rw-r--r--quantum/encoder.h8
-rw-r--r--quantum/joystick.c98
-rw-r--r--quantum/joystick.h28
-rw-r--r--quantum/keyboard.c24
-rw-r--r--quantum/keycode.h16
-rw-r--r--quantum/keycode_config.h1
-rw-r--r--quantum/keycode_legacy.h53
-rw-r--r--quantum/keymap.h25
-rw-r--r--quantum/keymap_common.c10
-rw-r--r--quantum/keymap_extras/keymap_colemak.h2
-rw-r--r--quantum/keymap_extras/keymap_us.h72
-rw-r--r--quantum/keymap_introspection.c22
-rw-r--r--quantum/keymap_introspection.h10
-rw-r--r--quantum/led.c48
-rw-r--r--quantum/led.h1
-rw-r--r--quantum/led_matrix/led_matrix.c54
-rw-r--r--quantum/led_matrix/led_matrix.h24
-rw-r--r--quantum/led_matrix/led_matrix_drivers.c2
-rw-r--r--quantum/led_matrix/led_matrix_types.h4
-rw-r--r--quantum/mousekey.c147
-rw-r--r--quantum/mousekey.h39
-rw-r--r--quantum/painter/qp.h4
-rw-r--r--quantum/painter/qp_draw_image.c43
-rw-r--r--quantum/painter/qp_draw_text.c49
-rw-r--r--quantum/painter/qp_stream.c47
-rw-r--r--quantum/painter/qp_stream.h5
-rw-r--r--quantum/painter/rules.mk34
-rw-r--r--quantum/pointing_device/pointing_device.c28
-rw-r--r--quantum/pointing_device/pointing_device.h11
-rw-r--r--quantum/pointing_device/pointing_device_auto_mouse.c384
-rw-r--r--quantum/pointing_device/pointing_device_auto_mouse.h87
-rw-r--r--quantum/pointing_device/pointing_device_drivers.c38
-rw-r--r--quantum/pointing_device_internal.h14
-rw-r--r--quantum/process_keycode/autocorrect_data_default.h85
-rw-r--r--quantum/process_keycode/process_auto_shift.c24
-rw-r--r--quantum/process_keycode/process_autocorrect.c292
-rw-r--r--quantum/process_keycode/process_autocorrect.h17
-rw-r--r--quantum/process_keycode/process_caps_word.c2
-rw-r--r--quantum/process_keycode/process_combo.c6
-rw-r--r--quantum/process_keycode/process_dynamic_macro.c22
-rw-r--r--quantum/process_keycode/process_joystick.c158
-rw-r--r--quantum/process_keycode/process_joystick.h21
-rw-r--r--quantum/process_keycode/process_key_lock.c8
-rw-r--r--quantum/process_keycode/process_key_override.c6
-rw-r--r--quantum/process_keycode/process_leader.c4
-rw-r--r--quantum/process_keycode/process_magic.c4
-rw-r--r--quantum/process_keycode/process_programmable_button.c8
-rw-r--r--quantum/process_keycode/process_secure.c8
-rw-r--r--quantum/process_keycode/process_space_cadet.c14
-rw-r--r--quantum/process_keycode/process_tap_dance.c12
-rw-r--r--quantum/process_keycode/process_tap_dance.h2
-rw-r--r--quantum/process_keycode/process_ucis.c17
-rw-r--r--quantum/process_keycode/process_ucis.h6
-rw-r--r--quantum/process_keycode/process_unicode.c12
-rw-r--r--quantum/process_keycode/process_unicode.h5
-rw-r--r--quantum/process_keycode/process_unicode_common.c298
-rw-r--r--quantum/process_keycode/process_unicode_common.h184
-rw-r--r--quantum/process_keycode/process_unicodemap.c5
-rw-r--r--quantum/process_keycode/process_unicodemap.h6
-rw-r--r--quantum/programmable_button.c27
-rw-r--r--quantum/programmable_button.h75
-rw-r--r--quantum/quantum.c30
-rw-r--r--quantum/quantum.h5
-rw-r--r--quantum/quantum_keycodes.h422
-rw-r--r--quantum/quantum_keycodes_legacy.h111
-rw-r--r--quantum/rgb_matrix/animations/jellybean_raindrops_anim.h2
-rw-r--r--quantum/rgb_matrix/animations/pixel_flow_anim.h4
-rw-r--r--quantum/rgb_matrix/animations/pixel_rain_anim.h2
-rw-r--r--quantum/rgb_matrix/animations/raindrops_anim.h2
-rw-r--r--quantum/rgb_matrix/rgb_matrix.c56
-rw-r--r--quantum/rgb_matrix/rgb_matrix.h28
-rw-r--r--quantum/rgb_matrix/rgb_matrix_drivers.c26
-rw-r--r--quantum/rgb_matrix/rgb_matrix_types.h4
-rw-r--r--quantum/rgblight/rgblight.c22
-rw-r--r--quantum/rgblight/rgblight.h1
-rw-r--r--quantum/rgblight/rgblight_list.h136
-rw-r--r--quantum/secure.c3
-rw-r--r--quantum/send_string/send_string_keycodes.h568
-rw-r--r--quantum/sequencer/tests/rules.mk2
-rw-r--r--quantum/split_common/split_util.c57
-rw-r--r--quantum/split_common/split_util.h4
-rw-r--r--quantum/split_common/transaction_id_define.h4
-rw-r--r--quantum/split_common/transactions.c152
-rw-r--r--quantum/split_common/transport.h4
-rw-r--r--quantum/unicode/unicode.c386
-rw-r--r--quantum/unicode/unicode.h165
-rw-r--r--quantum/unicode/utf8.c (renamed from quantum/utf8.c)0
-rw-r--r--quantum/unicode/utf8.h (renamed from quantum/utf8.h)2
-rw-r--r--quantum/util.h52
-rw-r--r--quantum/via_ensure_keycode.h16
100 files changed, 3455 insertions, 1839 deletions
diff --git a/quantum/action.c b/quantum/action.c
index 6b2e9104e0..abf9834d2f 100644
--- a/quantum/action.c
+++ b/quantum/action.c
@@ -293,19 +293,56 @@ void process_record_handler(keyrecord_t *record) {
process_action(record, action);
}
-#if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
-void register_button(bool pressed, enum mouse_buttons button) {
-# ifdef PS2_MOUSE_ENABLE
- tp_buttons = pressed ? tp_buttons | button : tp_buttons & ~button;
-# endif
-# ifdef POINTING_DEVICE_ENABLE
- report_mouse_t currentReport = pointing_device_get_report();
- currentReport.buttons = pressed ? currentReport.buttons | button : currentReport.buttons & ~button;
- pointing_device_set_report(currentReport);
+/**
+ * @brief handles all the messy mouse stuff
+ *
+ * Handles all the edgecases and special stuff that is needed for coexistense
+ * of the multiple mouse subsystems.
+ *
+ * @param mouse_keycode[in] uint8_t mouse keycode
+ * @param pressed[in] bool
+ */
+
+void register_mouse(uint8_t mouse_keycode, bool pressed) {
+#ifdef MOUSEKEY_ENABLE
+ // if mousekeys is enabled, let it do the brunt of the work
+ if (pressed) {
+ mousekey_on(mouse_keycode);
+ } else {
+ mousekey_off(mouse_keycode);
+ }
+ // should mousekeys send report, or does something else handle this?
+ switch (mouse_keycode) {
+# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
+ case KC_MS_BTN1 ... KC_MS_BTN8:
+ // let pointing device handle the buttons
+ // expand if/when it handles more of the code
+# if defined(POINTING_DEVICE_ENABLE)
+ pointing_device_keycode_handler(mouse_keycode, pressed);
+# endif
+ break;
# endif
-}
+ default:
+ mousekey_send();
+ break;
+ }
+#elif defined(POINTING_DEVICE_ENABLE)
+ // if mousekeys isn't enabled, and pointing device is enabled, then
+ // let pointing device do all the heavy lifting, then
+ if IS_MOUSEKEY (mouse_keycode) {
+ pointing_device_keycode_handler(mouse_keycode, pressed);
+ }
#endif
+#ifdef PS2_MOUSE_ENABLE
+ // make sure that ps2 mouse has button report synced
+ if (KC_MS_BTN1 <= mouse_keycode && mouse_keycode <= KC_MS_BTN3) {
+ uint8_t tmp_button_msk = MOUSE_BTN_MASK(mouse_keycode - KC_MS_BTN1);
+ tp_buttons = pressed ? tp_buttons | tmp_button_msk : tp_buttons & ~tmp_button_msk;
+ }
+#endif
+}
+
/** \brief Take an action and processes it.
*
* FIXME: Needs documentation.
@@ -403,9 +440,9 @@ void process_action(keyrecord_t *record, action_t action) {
# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
} else if (tap_count == ONESHOT_TAP_TOGGLE) {
dprint("MODS_TAP: Toggling oneshot");
+ register_mods(mods);
clear_oneshot_mods();
set_oneshot_locked_mods(mods | get_oneshot_locked_mods());
- register_mods(mods);
# endif
} else {
register_mods(mods | get_oneshot_mods());
@@ -418,16 +455,16 @@ void process_action(keyrecord_t *record, action_t action) {
// Retain Oneshot mods
# if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
if (mods & get_mods()) {
+ unregister_mods(mods);
clear_oneshot_mods();
set_oneshot_locked_mods(~mods & get_oneshot_locked_mods());
- unregister_mods(mods);
}
} else if (tap_count == ONESHOT_TAP_TOGGLE) {
// Toggle Oneshot Layer
# endif
} else {
- clear_oneshot_mods();
unregister_mods(mods);
+ clear_oneshot_mods();
}
}
}
@@ -490,46 +527,18 @@ void process_action(keyrecord_t *record, action_t action) {
case ACT_USAGE:
switch (action.usage.page) {
case PAGE_SYSTEM:
- if (event.pressed) {
- host_system_send(action.usage.code);
- } else {
- host_system_send(0);
- }
+ host_system_send(event.pressed ? action.usage.code : 0);
break;
case PAGE_CONSUMER:
- if (event.pressed) {
- host_consumer_send(action.usage.code);
- } else {
- host_consumer_send(0);
- }
+ host_consumer_send(event.pressed ? action.usage.code : 0);
break;
}
break;
#endif
-#ifdef MOUSEKEY_ENABLE
/* Mouse key */
case ACT_MOUSEKEY:
- if (event.pressed) {
- mousekey_on(action.key.code);
- } else {
- mousekey_off(action.key.code);
- }
- switch (action.key.code) {
-# if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
-# ifdef POINTING_DEVICE_ENABLE
- case KC_MS_BTN1 ... KC_MS_BTN8:
-# else
- case KC_MS_BTN1 ... KC_MS_BTN3:
-# endif
- register_button(event.pressed, MOUSE_BTN_MASK(action.key.code - KC_MS_BTN1));
- break;
-# endif
- default:
- mousekey_send();
- break;
- }
+ register_mouse(action.key.code, event.pressed);
break;
-#endif
#ifndef NO_ACTION_LAYER
case ACT_LAYER:
if (action.layer_bitop.on == 0) {
@@ -835,9 +844,9 @@ void process_action(keyrecord_t *record, action_t action) {
__attribute__((weak)) void register_code(uint8_t code) {
if (code == KC_NO) {
return;
- }
+
#ifdef LOCKING_SUPPORT_ENABLE
- else if (KC_LOCKING_CAPS_LOCK == code) {
+ } else if (KC_LOCKING_CAPS_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
// Resync: ignore if caps lock already is on
if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return;
@@ -847,9 +856,8 @@ __attribute__((weak)) void register_code(uint8_t code) {
wait_ms(TAP_HOLD_CAPS_DELAY);
del_key(KC_CAPS_LOCK);
send_keyboard_report();
- }
- else if (KC_LOCKING_NUM_LOCK == code) {
+ } else if (KC_LOCKING_NUM_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return;
# endif
@@ -858,9 +866,8 @@ __attribute__((weak)) void register_code(uint8_t code) {
wait_ms(100);
del_key(KC_NUM_LOCK);
send_keyboard_report();
- }
- else if (KC_LOCKING_SCROLL_LOCK == code) {
+ } else if (KC_LOCKING_SCROLL_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return;
# endif
@@ -869,10 +876,9 @@ __attribute__((weak)) void register_code(uint8_t code) {
wait_ms(100);
del_key(KC_SCROLL_LOCK);
send_keyboard_report();
- }
#endif
- else if IS_KEY (code) {
+ } else if IS_KEY (code) {
// TODO: should push command_proc out of this block?
if (command_proc(code)) return;
@@ -905,20 +911,17 @@ __attribute__((weak)) void register_code(uint8_t code) {
} else if IS_MOD (code) {
add_mods(MOD_BIT(code));
send_keyboard_report();
- }
+
#ifdef EXTRAKEY_ENABLE
- else if IS_SYSTEM (code) {
+ } else if IS_SYSTEM (code) {
host_system_send(KEYCODE2SYSTEM(code));
} else if IS_CONSUMER (code) {
host_consumer_send(KEYCODE2CONSUMER(code));
- }
#endif
-#ifdef MOUSEKEY_ENABLE
- else if IS_MOUSEKEY (code) {
- mousekey_on(code);
- mousekey_send();
+
+ } else if IS_MOUSEKEY (code) {
+ register_mouse(code, true);
}
-#endif
}
/** \brief Utilities for actions. (FIXME: Needs better description)
@@ -928,9 +931,9 @@ __attribute__((weak)) void register_code(uint8_t code) {
__attribute__((weak)) void unregister_code(uint8_t code) {
if (code == KC_NO) {
return;
- }
+
#ifdef LOCKING_SUPPORT_ENABLE
- else if (KC_LOCKING_CAPS_LOCK == code) {
+ } else if (KC_LOCKING_CAPS_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
// Resync: ignore if caps lock already is off
if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return;
@@ -939,9 +942,8 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
send_keyboard_report();
del_key(KC_CAPS_LOCK);
send_keyboard_report();
- }
- else if (KC_LOCKING_NUM_LOCK == code) {
+ } else if (KC_LOCKING_NUM_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return;
# endif
@@ -949,9 +951,8 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
send_keyboard_report();
del_key(KC_NUM_LOCK);
send_keyboard_report();
- }
- else if (KC_LOCKING_SCROLL_LOCK == code) {
+ } else if (KC_LOCKING_SCROLL_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return;
# endif
@@ -959,26 +960,25 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
send_keyboard_report();
del_key(KC_SCROLL_LOCK);
send_keyboard_report();
- }
#endif
- else if IS_KEY (code) {
+ } else if IS_KEY (code) {
del_key(code);
send_keyboard_report();
} else if IS_MOD (code) {
del_mods(MOD_BIT(code));
send_keyboard_report();
+
+#ifdef EXTRAKEY_ENABLE
} else if IS_SYSTEM (code) {
host_system_send(0);
} else if IS_CONSUMER (code) {
host_consumer_send(0);
- }
-#ifdef MOUSEKEY_ENABLE
- else if IS_MOUSEKEY (code) {
- mousekey_off(code);
- mousekey_send();
- }
#endif
+
+ } else if IS_MOUSEKEY (code) {
+ register_mouse(code, false);
+ }
}
/** \brief Tap a keycode with a delay.
@@ -1081,7 +1081,6 @@ void clear_keyboard_but_mods_and_keys() {
#endif
#ifdef PROGRAMMABLE_BUTTON_ENABLE
programmable_button_clear();
- programmable_button_send();
#endif
}
diff --git a/quantum/action_code.h b/quantum/action_code.h
index e107f0a740..14cfd025f1 100644
--- a/quantum/action_code.h
+++ b/quantum/action_code.h
@@ -192,7 +192,11 @@ enum mods_codes {
/** \brief Other Keys
*/
-enum usage_pages { PAGE_SYSTEM, PAGE_CONSUMER };
+enum usage_pages {
+ PAGE_SYSTEM,
+ PAGE_CONSUMER,
+};
+
#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM << 10 | (id))
#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER << 10 | (id))
#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)
diff --git a/quantum/backlight/backlight_chibios.c b/quantum/backlight/backlight_chibios.c
index e8f9e70f78..30e95bd5c8 100644
--- a/quantum/backlight/backlight_chibios.c
+++ b/quantum/backlight/backlight_chibios.c
@@ -40,16 +40,22 @@
# endif
#endif
-static PWMConfig pwmCFG = {0xFFFF, /* PWM clock frequency */
- 256, /* PWM period (in ticks) 1S (1/10kHz=0.1mS 0.1ms*10000 ticks=1S) */
- NULL, /* Breathing Callback */
- { /* Default all channels to disabled - Channels will be configured durring init */
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_DISABLED, NULL},
- {PWM_OUTPUT_DISABLED, NULL}},
- 0, /* HW dependent part.*/
- 0};
+#ifndef BACKLIGHT_PWM_COUNTER_FREQUENCY
+# define BACKLIGHT_PWM_COUNTER_FREQUENCY 0xFFFF
+#endif
+
+#ifndef BACKLIGHT_PWM_PERIOD
+# define BACKLIGHT_PWM_PERIOD 256
+#endif
+
+static PWMConfig pwmCFG = {
+ .frequency = BACKLIGHT_PWM_COUNTER_FREQUENCY, /* PWM clock frequency */
+ .period = BACKLIGHT_PWM_PERIOD, /* PWM period in counter ticks. e.g. clock frequency is 10KHz, period is 256 ticks then t_period is 25.6ms */
+};
+
+#ifdef BACKLIGHT_BREATHING
+static virtual_timer_t breathing_vt;
+#endif
// See http://jared.geek.nz/2013/feb/linear-led-pwm
static uint16_t cie_lightness(uint16_t v) {
@@ -60,10 +66,11 @@ static uint16_t cie_lightness(uint16_t v) {
// to get a useful result with integer division, we shift left in the expression above
// and revert what we've done again after squaring.
y = y * y * y >> 8;
- if (y > 0xFFFFUL) // prevent overflow
+ if (y > 0xFFFFUL) { // prevent overflow
return 0xFFFFU;
- else
+ } else {
return (uint16_t)y;
+ }
}
}
@@ -85,6 +92,7 @@ void backlight_init_ports(void) {
backlight_set(get_backlight_level());
#ifdef BACKLIGHT_BREATHING
+ chVTObjectInit(&breathing_vt);
if (is_backlight_breathing()) {
breathing_enable();
}
@@ -92,7 +100,9 @@ void backlight_init_ports(void) {
}
void backlight_set(uint8_t level) {
- if (level > BACKLIGHT_LEVELS) level = BACKLIGHT_LEVELS;
+ if (level > BACKLIGHT_LEVELS) {
+ level = BACKLIGHT_LEVELS;
+ }
if (level == 0) {
// Turn backlight off
@@ -115,20 +125,19 @@ void backlight_task(void) {}
*/
static const uint8_t breathing_table[BREATHING_STEPS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-void breathing_callback(PWMDriver *pwmp);
+static void breathing_callback(virtual_timer_t *vtp, void *p);
bool is_breathing(void) {
- return pwmCFG.callback != NULL;
+ return chVTIsArmed(&breathing_vt);
}
void breathing_enable(void) {
- pwmCFG.callback = breathing_callback;
- pwmEnablePeriodicNotification(&BACKLIGHT_PWM_DRIVER);
+ /* Update frequency is 256Hz -> 3906us intervals */
+ chVTSetContinuous(&breathing_vt, TIME_US2I(3906), breathing_callback, NULL);
}
void breathing_disable(void) {
- pwmCFG.callback = NULL;
- pwmDisablePeriodicNotification(&BACKLIGHT_PWM_DRIVER);
+ chVTReset(&breathing_vt);
// Restore backlight level
backlight_set(get_backlight_level());
@@ -139,7 +148,7 @@ static inline uint16_t scale_backlight(uint16_t v) {
return v / BACKLIGHT_LEVELS * get_backlight_level();
}
-void breathing_callback(PWMDriver *pwmp) {
+static void breathing_callback(virtual_timer_t *vtp, void *p) {
uint8_t breathing_period = get_breathing_period();
uint16_t interval = (uint16_t)breathing_period * 256 / BREATHING_STEPS;
@@ -150,7 +159,7 @@ void breathing_callback(PWMDriver *pwmp) {
uint32_t duty = cie_lightness(rescale_limit_val(scale_backlight(breathing_table[index] * 256)));
chSysLockFromISR();
- pwmEnableChannelI(pwmp, BACKLIGHT_PWM_CHANNEL - 1, PWM_FRACTION_TO_WIDTH(&BACKLIGHT_PWM_DRIVER, 0xFFFF, duty));
+ pwmEnableChannelI(&BACKLIGHT_PWM_DRIVER, BACKLIGHT_PWM_CHANNEL - 1, PWM_FRACTION_TO_WIDTH(&BACKLIGHT_PWM_DRIVER, 0xFFFF, duty));
chSysUnlockFromISR();
}
diff --git a/quantum/backlight/backlight_driver_common.c b/quantum/backlight/backlight_driver_common.c
index e4c2e90b5f..1eb8969084 100644
--- a/quantum/backlight/backlight_driver_common.c
+++ b/quantum/backlight/backlight_driver_common.c
@@ -9,7 +9,7 @@
#if defined(BACKLIGHT_PINS)
static const pin_t backlight_pins[] = BACKLIGHT_PINS;
# ifndef BACKLIGHT_LED_COUNT
-# define BACKLIGHT_LED_COUNT (sizeof(backlight_pins) / sizeof(pin_t))
+# define BACKLIGHT_LED_COUNT ARRAY_SIZE(backlight_pins)
# endif
# define FOR_EACH_LED(x) \
diff --git a/quantum/backlight/backlight_software.c b/quantum/backlight/backlight_software.c
index 3d412cab52..27ccbd2c9f 100644
--- a/quantum/backlight/backlight_software.c
+++ b/quantum/backlight/backlight_software.c
@@ -26,7 +26,7 @@ static const uint16_t backlight_duty_table[] = {
0b1110111011101110,
0b1111111111111111,
};
-#define backlight_duty_table_size (sizeof(backlight_duty_table) / sizeof(backlight_duty_table[0]))
+#define backlight_duty_table_size ARRAY_SIZE(backlight_duty_table)
// clang-format on
diff --git a/quantum/config_common.h b/quantum/config_common.h
index d93477b27e..6ab8a2aa7d 100644
--- a/quantum/config_common.h
+++ b/quantum/config_common.h
@@ -24,4 +24,6 @@
#define COL2ROW 0
#define ROW2COL 1
-#include "song_list.h"
+#ifdef AUDIO_ENABLE
+# include "song_list.h"
+#endif
diff --git a/quantum/dip_switch.c b/quantum/dip_switch.c
index eee29aaf91..e180cfccdf 100644
--- a/quantum/dip_switch.c
+++ b/quantum/dip_switch.c
@@ -33,7 +33,7 @@
#endif
#ifdef DIP_SWITCH_PINS
-# define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(pin_t))
+# define NUMBER_OF_DIP_SWITCHES (ARRAY_SIZE(dip_switch_pad))
static pin_t dip_switch_pad[] = DIP_SWITCH_PINS;
#endif
@@ -43,7 +43,7 @@ typedef struct matrix_index_t {
uint8_t col;
} matrix_index_t;
-# define NUMBER_OF_DIP_SWITCHES (sizeof(dip_switch_pad) / sizeof(matrix_index_t))
+# define NUMBER_OF_DIP_SWITCHES (ARRAY_SIZE(dip_switch_pad))
static matrix_index_t dip_switch_pad[] = DIP_SWITCH_MATRIX_GRID;
extern bool peek_matrix(uint8_t row_index, uint8_t col_index, bool read_raw);
static uint16_t scan_count;
diff --git a/quantum/dynamic_keymap.c b/quantum/dynamic_keymap.c
index 01be9806e4..d800bbab84 100644
--- a/quantum/dynamic_keymap.c
+++ b/quantum/dynamic_keymap.c
@@ -24,7 +24,9 @@
# include "via.h" // for VIA_EEPROM_CONFIG_END
# define DYNAMIC_KEYMAP_EEPROM_START (VIA_EEPROM_CONFIG_END)
#else
-# define DYNAMIC_KEYMAP_EEPROM_START (EECONFIG_SIZE)
+# ifndef DYNAMIC_KEYMAP_EEPROM_START
+# define DYNAMIC_KEYMAP_EEPROM_START (EECONFIG_SIZE)
+# endif
#endif
#ifdef ENCODER_ENABLE
@@ -153,7 +155,7 @@ void dynamic_keymap_reset(void) {
for (int row = 0; row < MATRIX_ROWS; row++) {
for (int column = 0; column < MATRIX_COLS; column++) {
if (layer < keymap_layer_count()) {
- dynamic_keymap_set_keycode(layer, row, column, pgm_read_word(&keymaps[layer][row][column]));
+ dynamic_keymap_set_keycode(layer, row, column, keycode_at_keymap_location_raw(layer, row, column));
} else {
dynamic_keymap_set_keycode(layer, row, column, KC_TRANSPARENT);
}
@@ -162,8 +164,8 @@ void dynamic_keymap_reset(void) {
#ifdef ENCODER_MAP_ENABLE
for (int encoder = 0; encoder < NUM_ENCODERS; encoder++) {
if (layer < encodermap_layer_count()) {
- dynamic_keymap_set_encoder(layer, encoder, true, pgm_read_word(&encoder_map[layer][encoder][0]));
- dynamic_keymap_set_encoder(layer, encoder, false, pgm_read_word(&encoder_map[layer][encoder][1]));
+ dynamic_keymap_set_encoder(layer, encoder, true, keycode_at_encodermap_location_raw(layer, encoder, true));
+ dynamic_keymap_set_encoder(layer, encoder, false, keycode_at_encodermap_location_raw(layer, encoder, false));
} else {
dynamic_keymap_set_encoder(layer, encoder, true, KC_TRANSPARENT);
dynamic_keymap_set_encoder(layer, encoder, false, KC_TRANSPARENT);
@@ -201,20 +203,21 @@ void dynamic_keymap_set_buffer(uint16_t offset, uint16_t size, uint8_t *data) {
}
}
-// This overrides the one in quantum/keymap_common.c
-uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
- if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
- return dynamic_keymap_get_keycode(layer, key.row, key.col);
+uint16_t keycode_at_keymap_location(uint8_t layer_num, uint8_t row, uint8_t column) {
+ if (layer_num < DYNAMIC_KEYMAP_LAYER_COUNT && row < MATRIX_ROWS && column < MATRIX_COLS) {
+ return dynamic_keymap_get_keycode(layer_num, row, column);
}
+ return KC_NO;
+}
+
#ifdef ENCODER_MAP_ENABLE
- else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) {
- return dynamic_keymap_get_encoder(layer, key.col, true);
- } else if (layer < DYNAMIC_KEYMAP_LAYER_COUNT && key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) {
- return dynamic_keymap_get_encoder(layer, key.col, false);
+uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
+ if (layer_num < DYNAMIC_KEYMAP_LAYER_COUNT && encoder_idx < NUM_ENCODERS) {
+ return dynamic_keymap_get_encoder(layer_num, encoder_idx, clockwise);
}
-#endif // ENCODER_MAP_ENABLE
return KC_NO;
}
+#endif // ENCODER_MAP_ENABLE
uint8_t dynamic_keymap_macro_get_count(void) {
return DYNAMIC_KEYMAP_MACRO_COUNT;
diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c
index 0ff9996ca4..27a0f6d48f 100644
--- a/quantum/eeconfig.c
+++ b/quantum/eeconfig.c
@@ -46,7 +46,8 @@ void eeconfig_init_quantum(void) {
eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
default_layer_state = 0;
eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0);
- eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0x4);
+ // Enable oneshot and autocorrect by default: 0b0001 0100
+ eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0x14);
eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default
@@ -57,16 +58,6 @@ void eeconfig_init_quantum(void) {
eeprom_update_dword(EECONFIG_RGB_MATRIX, 0);
eeprom_update_word(EECONFIG_RGB_MATRIX_EXTENDED, 0);
- // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS
- // within the emulated eeprom via dfu-util or another tool
-#if defined INIT_EE_HANDS_LEFT
-# pragma message "Faking EE_HANDS for left hand"
- eeprom_update_byte(EECONFIG_HANDEDNESS, 1);
-#elif defined INIT_EE_HANDS_RIGHT
-# pragma message "Faking EE_HANDS for right hand"
- eeprom_update_byte(EECONFIG_HANDEDNESS, 0);
-#endif
-
#if defined(HAPTIC_ENABLE)
haptic_reset();
#else
diff --git a/quantum/encoder.c b/quantum/encoder.c
index 5f8a7ce080..1393e34868 100644
--- a/quantum/encoder.c
+++ b/quantum/encoder.c
@@ -24,7 +24,8 @@
#include <string.h>
#ifndef ENCODER_MAP_KEY_DELAY
-# define ENCODER_MAP_KEY_DELAY 2
+# include "action.h"
+# define ENCODER_MAP_KEY_DELAY TAP_CODE_DELAY
#endif
#if !defined(ENCODER_RESOLUTIONS) && !defined(ENCODER_RESOLUTION)
@@ -143,9 +144,14 @@ void encoder_init(void) {
static void encoder_exec_mapping(uint8_t index, bool clockwise) {
// The delays below cater for Windows and its wonderful requirements.
action_exec(clockwise ? ENCODER_CW_EVENT(index, true) : ENCODER_CCW_EVENT(index, true));
+# if ENCODER_MAP_KEY_DELAY > 0
wait_ms(ENCODER_MAP_KEY_DELAY);
+# endif // ENCODER_MAP_KEY_DELAY > 0
+
action_exec(clockwise ? ENCODER_CW_EVENT(index, false) : ENCODER_CCW_EVENT(index, false));
+# if ENCODER_MAP_KEY_DELAY > 0
wait_ms(ENCODER_MAP_KEY_DELAY);
+# endif // ENCODER_MAP_KEY_DELAY > 0
}
#endif // ENCODER_MAP_ENABLE
diff --git a/quantum/encoder.h b/quantum/encoder.h
index 82f95b4931..4eb67fa25d 100644
--- a/quantum/encoder.h
+++ b/quantum/encoder.h
@@ -32,17 +32,17 @@ void encoder_state_raw(uint8_t* slave_state);
void encoder_update_raw(uint8_t* slave_state);
# if defined(ENCODERS_PAD_A_RIGHT)
-# define NUM_ENCODERS_LEFT (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t))
-# define NUM_ENCODERS_RIGHT (sizeof(((pin_t[])ENCODERS_PAD_A_RIGHT)) / sizeof(pin_t))
+# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
+# define NUM_ENCODERS_RIGHT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A_RIGHT))
# else
-# define NUM_ENCODERS_LEFT (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t))
+# define NUM_ENCODERS_LEFT ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
# define NUM_ENCODERS_RIGHT NUM_ENCODERS_LEFT
# endif
# define NUM_ENCODERS (NUM_ENCODERS_LEFT + NUM_ENCODERS_RIGHT)
#else // SPLIT_KEYBOARD
-# define NUM_ENCODERS (sizeof(((pin_t[])ENCODERS_PAD_A)) / sizeof(pin_t))
+# define NUM_ENCODERS ARRAY_SIZE(((pin_t[])ENCODERS_PAD_A))
# define NUM_ENCODERS_LEFT NUM_ENCODERS
# define NUM_ENCODERS_RIGHT 0
diff --git a/quantum/joystick.c b/quantum/joystick.c
index 86b2c64036..d285dcdb5e 100644
--- a/quantum/joystick.c
+++ b/quantum/joystick.c
@@ -1,5 +1,24 @@
+/* Copyright 2022
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#include "joystick.h"
+#include "analog.h"
+#include "wait.h"
+
// clang-format off
joystick_t joystick_status = {
.buttons = {0},
@@ -15,12 +34,13 @@ joystick_t joystick_status = {
// array defining the reading of analog values for each axis
__attribute__((weak)) joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT] = {};
-// to be implemented in the hid protocol library
-void send_joystick_packet(joystick_t *joystick);
+__attribute__((weak)) void joystick_task(void) {
+ joystick_read_axes();
+}
void joystick_flush(void) {
if ((joystick_status.status & JS_UPDATED) > 0) {
- send_joystick_packet(&joystick_status);
+ host_joystick_send(&joystick_status);
joystick_status.status &= ~JS_UPDATED;
}
}
@@ -36,3 +56,75 @@ void unregister_joystick_button(uint8_t button) {
joystick_status.status |= JS_UPDATED;
joystick_flush();
}
+
+int16_t joystick_read_axis(uint8_t axis) {
+ // disable pull-up resistor
+ writePinLow(joystick_axes[axis].input_pin);
+
+ // if pin was a pull-up input, we need to uncharge it by turning it low
+ // before making it a low input
+ setPinOutput(joystick_axes[axis].input_pin);
+
+ wait_us(10);
+
+ if (joystick_axes[axis].output_pin != JS_VIRTUAL_AXIS) {
+ setPinOutput(joystick_axes[axis].output_pin);
+ writePinHigh(joystick_axes[axis].output_pin);
+ }
+
+ if (joystick_axes[axis].ground_pin != JS_VIRTUAL_AXIS) {
+ setPinOutput(joystick_axes[axis].ground_pin);
+ writePinLow(joystick_axes[axis].ground_pin);
+ }
+
+ wait_us(10);
+
+ setPinInput(joystick_axes[axis].input_pin);
+
+ wait_us(10);
+
+#if defined(ANALOG_JOYSTICK_ENABLE) && (defined(__AVR__) || defined(PROTOCOL_CHIBIOS))
+ int16_t axis_val = analogReadPin(joystick_axes[axis].input_pin);
+#else
+ // default to resting position
+ int16_t axis_val = joystick_axes[axis].mid_digit;
+#endif
+
+ // test the converted value against the lower range
+ int32_t ref = joystick_axes[axis].mid_digit;
+ int32_t range = joystick_axes[axis].min_digit;
+ int32_t ranged_val = ((axis_val - ref) * -JOYSTICK_RESOLUTION) / (range - ref);
+
+ if (ranged_val > 0) {
+ // the value is in the higher range
+ range = joystick_axes[axis].max_digit;
+ ranged_val = ((axis_val - ref) * JOYSTICK_RESOLUTION) / (range - ref);
+ }
+
+ // clamp the result in the valid range
+ ranged_val = ranged_val < -JOYSTICK_RESOLUTION ? -JOYSTICK_RESOLUTION : ranged_val;
+ ranged_val = ranged_val > JOYSTICK_RESOLUTION ? JOYSTICK_RESOLUTION : ranged_val;
+
+ return ranged_val;
+}
+
+void joystick_read_axes() {
+#if JOYSTICK_AXES_COUNT > 0
+ for (int i = 0; i < JOYSTICK_AXES_COUNT; ++i) {
+ if (joystick_axes[i].input_pin == JS_VIRTUAL_AXIS) {
+ continue;
+ }
+
+ joystick_set_axis(i, joystick_read_axis(i));
+ }
+
+ joystick_flush();
+#endif
+}
+
+void joystick_set_axis(uint8_t axis, int16_t value) {
+ if (value != joystick_status.axes[axis]) {
+ joystick_status.axes[axis] = value;
+ joystick_status.status |= JS_UPDATED;
+ }
+}
diff --git a/quantum/joystick.h b/quantum/joystick.h
index 5d81b14ef2..ee966fdb1a 100644
--- a/quantum/joystick.h
+++ b/quantum/joystick.h
@@ -1,3 +1,19 @@
+/* Copyright 2022
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#pragma once
#include <stdint.h>
@@ -54,7 +70,10 @@ typedef struct {
extern joystick_config_t joystick_axes[JOYSTICK_AXES_COUNT];
-enum joystick_status { JS_INITIALIZED = 1, JS_UPDATED = 2 };
+enum joystick_status {
+ JS_INITIALIZED = 1,
+ JS_UPDATED,
+};
typedef struct {
uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1];
@@ -65,7 +84,14 @@ typedef struct {
extern joystick_t joystick_status;
+void joystick_task(void);
void joystick_flush(void);
void register_joystick_button(uint8_t button);
void unregister_joystick_button(uint8_t button);
+
+int16_t joystick_read_axis(uint8_t axis);
+void joystick_read_axes(void);
+void joystick_set_axis(uint8_t axis, int16_t value);
+
+void host_joystick_send(joystick_t *joystick);
diff --git a/quantum/keyboard.c b/quantum/keyboard.c
index 1c62a43d9d..eb5e4b583a 100644
--- a/quantum/keyboard.c
+++ b/quantum/keyboard.c
@@ -66,9 +66,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef JOYSTICK_ENABLE
# include "process_joystick.h"
#endif
-#ifdef PROGRAMMABLE_BUTTON_ENABLE
-# include "programmable_button.h"
-#endif
#ifdef HD44780_ENABLE
# include "hd44780.h"
#endif
@@ -106,7 +103,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "split_util.h"
#endif
#ifdef BLUETOOTH_ENABLE
-# include "outputselect.h"
+# include "bluetooth.h"
#endif
#ifdef CAPS_WORD_ENABLE
# include "caps_word.h"
@@ -170,12 +167,11 @@ uint32_t get_matrix_scan_rate(void) {
#endif
#ifdef MATRIX_HAS_GHOST
-extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
-static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata) {
+static matrix_row_t get_real_keys(uint8_t row, matrix_row_t rowdata) {
matrix_row_t out = 0;
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
// read each key in the row data and check if the keymap defines it as a real key
- if (pgm_read_byte(&keymaps[0][row][col]) && (rowdata & (1 << col))) {
+ if (keycode_at_keymap_location(0, row, col) && (rowdata & (1 << col))) {
// this creates new row data, if a key is defined in the keymap, it will be set here
out |= 1 << col;
}
@@ -346,9 +342,6 @@ void quantum_init(void) {
#ifdef HAPTIC_ENABLE
haptic_init();
#endif
-#if defined(BLUETOOTH_ENABLE) && defined(OUTPUT_AUTO_ENABLE)
- set_output(OUTPUT_AUTO);
-#endif
}
/** \brief keyboard_init
@@ -410,6 +403,9 @@ void keyboard_init(void) {
// init after split init
pointing_device_init();
#endif
+#ifdef BLUETOOTH_ENABLE
+ bluetooth_init();
+#endif
#if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE)
debug_enable = true;
@@ -587,6 +583,10 @@ void keyboard_task(void) {
quantum_task();
+#if defined(SPLIT_WATCHDOG_ENABLE)
+ split_watchdog_task();
+#endif
+
#if defined(RGBLIGHT_ENABLE)
rgblight_task();
#endif
@@ -666,8 +666,8 @@ void keyboard_task(void) {
digitizer_task();
#endif
-#ifdef PROGRAMMABLE_BUTTON_ENABLE
- programmable_button_send();
+#ifdef BLUETOOTH_ENABLE
+ bluetooth_task();
#endif
led_task();
diff --git a/quantum/keycode.h b/quantum/keycode.h
index 3c80a386d1..2e9a85ee66 100644
--- a/quantum/keycode.h
+++ b/quantum/keycode.h
@@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
#define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE)
-#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID)
+#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_ASST)
#define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2)
#define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT)
@@ -205,6 +205,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define KC_MRWD KC_MEDIA_REWIND
#define KC_BRIU KC_BRIGHTNESS_UP
#define KC_BRID KC_BRIGHTNESS_DOWN
+#define KC_CPNL KC_CONTROL_PANEL
+#define KC_ASST KC_ASSISTANT
/* System Specific */
#define KC_BRMU KC_PAUSE
@@ -502,7 +504,9 @@ enum internal_special_keycodes {
KC_MEDIA_FAST_FORWARD,
KC_MEDIA_REWIND,
KC_BRIGHTNESS_UP,
- KC_BRIGHTNESS_DOWN
+ KC_BRIGHTNESS_DOWN,
+ KC_CONTROL_PANEL,
+ KC_ASSISTANT // 0xC0
};
enum mouse_keys {
@@ -510,11 +514,11 @@ enum mouse_keys {
#ifdef VIA_ENABLE
KC_MS_UP = 0xF0,
#else
- KC_MS_UP = 0xED,
+ KC_MS_UP = 0xCD,
#endif
KC_MS_DOWN,
KC_MS_LEFT,
- KC_MS_RIGHT, // 0xF0
+ KC_MS_RIGHT,
KC_MS_BTN1,
KC_MS_BTN2,
KC_MS_BTN3,
@@ -539,7 +543,5 @@ enum mouse_keys {
/* Acceleration */
KC_MS_ACCEL0,
KC_MS_ACCEL1,
- KC_MS_ACCEL2 // 0xFF
+ KC_MS_ACCEL2 // 0xDF, or 0xFF if via enabled
};
-
-#include "keycode_legacy.h"
diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h
index 81a8e61471..eef048d95c 100644
--- a/quantum/keycode_config.h
+++ b/quantum/keycode_config.h
@@ -39,6 +39,7 @@ typedef union {
bool swap_rctl_rgui : 1;
bool oneshot_enable : 1;
bool swap_escape_capslock : 1;
+ bool autocorrect_enable : 1;
};
} keymap_config_t;
diff --git a/quantum/keycode_legacy.h b/quantum/keycode_legacy.h
deleted file mode 100644
index 0317a05534..0000000000
--- a/quantum/keycode_legacy.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#pragma once
-
-// clang-format off
-
-// These keycode names have been deprecated
-
-#define KC_BSPACE KC_BACKSPACE
-#define KC_LBRACKET KC_LEFT_BRACKET
-#define KC_RBRACKET KC_RIGHT_BRACKET
-#define KC_BSLASH KC_BACKSLASH
-#define KC_SCOLON KC_SEMICOLON
-#define KC_CAPSLOCK KC_CAPS_LOCK
-#define KC_PSCREEN KC_PRINT_SCREEN
-#define KC_SCROLLLOCK KC_SCROLL_LOCK
-#define KC_PGDOWN KC_PAGE_DOWN
-#define KC_NUMLOCK KC_NUM_LOCK
-#define KC_NONUS_BSLASH KC_NONUS_BACKSLASH
-#define KC_POWER KC_KB_POWER
-#define KC__MUTE KC_KB_MUTE
-#define KC__VOLUP KC_KB_VOLUME_UP
-#define KC__VOLDOWN KC_KB_VOLUME_DOWN
-#define KC_LOCKING_CAPS KC_LOCKING_CAPS_LOCK
-#define KC_LOCKING_NUM KC_LOCKING_NUM_LOCK
-#define KC_LOCKING_SCROLL KC_LOCKING_SCROLL_LOCK
-#define KC_LANG1 KC_LANGUAGE_1
-#define KC_LANG2 KC_LANGUAGE_2
-#define KC_LANG3 KC_LANGUAGE_3
-#define KC_LANG4 KC_LANGUAGE_4
-#define KC_LANG5 KC_LANGUAGE_5
-#define KC_LANG6 KC_LANGUAGE_6
-#define KC_LANG7 KC_LANGUAGE_7
-#define KC_LANG8 KC_LANGUAGE_8
-#define KC_LANG9 KC_LANGUAGE_9
-#define KC_ALT_ERASE KC_ALTERNATE_ERASE
-#define KC_SYSREQ KC_SYSTEM_REQUEST
-
-#define KC_LCTRL KC_LEFT_CTRL
-#define KC_LSHIFT KC_LEFT_SHIFT
-#define KC_RCTRL KC_RIGHT_CTRL
-#define KC_RSHIFT KC_RIGHT_SHIFT
-
-#define KC_ZKHK KC_GRAVE
-#define KC_RO KC_INTERNATIONAL_1
-#define KC_KANA KC_INTERNATIONAL_2
-#define KC_JYEN KC_INTERNATIONAL_3
-#define KC_HENK KC_INTERNATIONAL_4
-#define KC_MHEN KC_INTERNATIONAL_5
-#define KC_HAEN KC_LANGUAGE_1
-#define KC_HANJ KC_LANGUAGE_2
-
-#define KC_CLCK KC_CAPS_LOCK
-#define KC_SLCK KC_SCROLL_LOCK
-#define KC_NLCK KC_NUM_LOCK
diff --git a/quantum/keymap.h b/quantum/keymap.h
index edff484129..0225f53362 100644
--- a/quantum/keymap.h
+++ b/quantum/keymap.h
@@ -19,43 +19,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include <stdbool.h>
+#include "platform_deps.h"
#include "action.h"
-#if defined(__AVR__)
-# include <avr/pgmspace.h>
-#elif defined PROTOCOL_CHIBIOS
-// We need to ensure that chibios is include before redefining reset
-# include <ch.h>
-#endif
#include "keycode.h"
#include "report.h"
#include "host.h"
-// #include "print.h"
#include "debug.h"
#include "keycode_config.h"
#include "gpio.h" // for pin_t
-// ChibiOS uses RESET in its FlagStatus enumeration
-// Therefore define it as QK_BOOTLOADER here, to avoid name collision
-#if defined(PROTOCOL_CHIBIOS)
-# define RESET QK_BOOTLOADER
-#endif
-// Gross hack, remove me and change RESET keycode to QK_BOOT
-#if defined(__AVR_AT90USB647__) || defined(__AVR_AT90USB1287__)
-# undef RESET
-#endif
-
#include "quantum_keycodes.h"
-// Gross hack, remove me and change RESET keycode to QK_BOOT
-#if defined(MCU_RP)
-# undef RESET
-#endif
-
// translates key to keycode
uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
-extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
-
#ifdef ENCODER_MAP_ENABLE
// Ensure we have a forward declaration for the encoder map
# include "encoder.h"
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 8d7a8bda9a..50e581cd87 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -61,15 +61,13 @@ action_t action_for_keycode(uint16_t keycode) {
case KC_SYSTEM_POWER ... KC_SYSTEM_WAKE:
action.code = ACTION_USAGE_SYSTEM(KEYCODE2SYSTEM(keycode));
break;
- case KC_AUDIO_MUTE ... KC_BRIGHTNESS_DOWN:
+ case KC_AUDIO_MUTE ... KC_ASSISTANT:
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
break;
#endif
-#ifdef MOUSEKEY_ENABLE
case KC_MS_UP ... KC_MS_ACCEL2:
action.code = ACTION_MOUSEKEY(keycode);
break;
-#endif
case KC_TRANSPARENT:
action.code = ACTION_TRANSPARENT;
break;
@@ -147,13 +145,13 @@ action_t action_for_keycode(uint16_t keycode) {
// translates key to keycode
__attribute__((weak)) uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key) {
if (key.row < MATRIX_ROWS && key.col < MATRIX_COLS) {
- return pgm_read_word(&keymaps[layer][key.row][key.col]);
+ return keycode_at_keymap_location(layer, key.row, key.col);
}
#ifdef ENCODER_MAP_ENABLE
else if (key.row == KEYLOC_ENCODER_CW && key.col < NUM_ENCODERS) {
- return pgm_read_word(&encoder_map[layer][key.col][0]);
+ return keycode_at_encodermap_location(layer, key.col, true);
} else if (key.row == KEYLOC_ENCODER_CCW && key.col < NUM_ENCODERS) {
- return pgm_read_word(&encoder_map[layer][key.col][1]);
+ return keycode_at_encodermap_location(layer, key.col, false);
}
#endif // ENCODER_MAP_ENABLE
return KC_NO;
diff --git a/quantum/keymap_extras/keymap_colemak.h b/quantum/keymap_extras/keymap_colemak.h
index 6658cc1301..e7b5c97ccb 100644
--- a/quantum/keymap_extras/keymap_colemak.h
+++ b/quantum/keymap_extras/keymap_colemak.h
@@ -122,4 +122,4 @@
// Row 4
#define CM_LABK S(CM_COMM) // <
#define CM_RABK S(CM_DOT) // >
-#define CM_QUES S(CM_SLSH) // /
+#define CM_QUES S(CM_SLSH) // ?
diff --git a/quantum/keymap_extras/keymap_us.h b/quantum/keymap_extras/keymap_us.h
new file mode 100644
index 0000000000..b18c701679
--- /dev/null
+++ b/quantum/keymap_extras/keymap_us.h
@@ -0,0 +1,72 @@
+// Copyright 2022 QMK
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "keymap.h"
+
+// clang-format off
+
+/* Shifted symbols
+ * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐
+ * │ ~ │ ! │ @ │ # │ $ │ % │ ^ │ & │ * │ ( │ ) │ _ │ + │ │
+ * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤
+ * │ │ │ │ │ │ │ │ │ │ │ │ { │ } │ | │
+ * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤
+ * │ │ │ │ │ │ │ │ │ │ │ : │ " │ │
+ * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤
+ * │ │ │ │ │ │ │ │ │ < │ > │ ? │ │
+ * ├────┬───┴┬──┴─┬─┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤
+ * │ │ │ │ │ │ │ │ │
+ * └────┴────┴────┴────────────────────────┴────┴────┴────┴────┘
+ */
+// Row 1
+#define KC_TILD S(KC_GRAVE) // ~
+#define KC_EXLM S(KC_1) // !
+#define KC_AT S(KC_2) // @
+#define KC_HASH S(KC_3) // #
+#define KC_DLR S(KC_4) // $
+#define KC_PERC S(KC_5) // %
+#define KC_CIRC S(KC_6) // ^
+#define KC_AMPR S(KC_7) // &
+#define KC_ASTR S(KC_8) // *
+#define KC_LPRN S(KC_9) // (
+#define KC_RPRN S(KC_0) // )
+#define KC_UNDS S(KC_MINUS) // _
+#define KC_PLUS S(KC_EQUAL) // +
+// Row 2
+#define KC_LCBR S(KC_LEFT_BRACKET) // {
+#define KC_RCBR S(KC_RIGHT_BRACKET) // }
+#define KC_PIPE S(KC_BACKSLASH) // |
+// Row 3
+#define KC_COLN S(KC_SEMICOLON) // :
+#define KC_DQUO S(KC_QUOTE) // "
+// Row 4
+#define KC_LABK S(KC_COMMA) // <
+#define KC_RABK S(KC_DOT) // >
+#define KC_QUES S(KC_SLASH) // ?
+
+// alias stuff
+#define KC_TILDE KC_TILD
+#define KC_EXCLAIM KC_EXLM
+#define KC_DOLLAR KC_DLR
+#define KC_PERCENT KC_PERC
+#define KC_CIRCUMFLEX KC_CIRC
+#define KC_AMPERSAND KC_AMPR
+#define KC_ASTERISK KC_ASTR
+#define KC_LEFT_PAREN KC_LPRN
+#define KC_RIGHT_PAREN KC_RPRN
+#define KC_UNDERSCORE KC_UNDS
+
+#define KC_LEFT_CURLY_BRACE KC_LCBR
+#define KC_RIGHT_CURLY_BRACE KC_RCBR
+
+#define KC_COLON KC_COLN
+#define KC_DOUBLE_QUOTE KC_DQUO
+#define KC_DQT KC_DQUO
+
+#define KC_LEFT_ANGLE_BRACKET KC_LABK
+#define KC_LT KC_LABK
+#define KC_RIGHT_ANGLE_BRACKET KC_RABK
+#define KC_GT KC_RABK
+#define KC_QUESTION KC_QUES
diff --git a/quantum/keymap_introspection.c b/quantum/keymap_introspection.c
index 179b5eb037..93aab82fcc 100644
--- a/quantum/keymap_introspection.c
+++ b/quantum/keymap_introspection.c
@@ -19,6 +19,17 @@ uint8_t keymap_layer_count(void) {
_Static_assert(NUM_KEYMAP_LAYERS <= MAX_LAYER, "Number of keymap layers exceeds maximum set by LAYER_STATE_(8|16|32)BIT");
+uint16_t keycode_at_keymap_location_raw(uint8_t layer_num, uint8_t row, uint8_t column) {
+ if (layer_num < NUM_KEYMAP_LAYERS && row < MATRIX_ROWS && column < MATRIX_COLS) {
+ return pgm_read_word(&keymaps[layer_num][row][column]);
+ }
+ return KC_NO;
+}
+
+__attribute__((weak)) uint16_t keycode_at_keymap_location(uint8_t layer_num, uint8_t row, uint8_t column) {
+ return keycode_at_keymap_location_raw(layer_num, row, column);
+}
+
#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
# define NUM_ENCODERMAP_LAYERS ((uint8_t)(sizeof(encoder_map) / ((NUM_ENCODERS) * (2) * sizeof(uint16_t))))
@@ -29,4 +40,15 @@ uint8_t encodermap_layer_count(void) {
_Static_assert(NUM_KEYMAP_LAYERS == NUM_ENCODERMAP_LAYERS, "Number of encoder_map layers doesn't match the number of keymap layers");
+uint16_t keycode_at_encodermap_location_raw(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
+ if (layer_num < NUM_ENCODERMAP_LAYERS && encoder_idx < NUM_ENCODERS) {
+ return pgm_read_word(&encoder_map[layer_num][encoder_idx][clockwise ? 0 : 1]);
+ }
+ return KC_NO;
+}
+
+__attribute__((weak)) uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise) {
+ return keycode_at_encodermap_location_raw(layer_num, encoder_idx, clockwise);
+}
+
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
diff --git a/quantum/keymap_introspection.h b/quantum/keymap_introspection.h
index 23f6f2016f..9de706a021 100644
--- a/quantum/keymap_introspection.h
+++ b/quantum/keymap_introspection.h
@@ -7,9 +7,19 @@
// Get the number of layers defined in the keymap
uint8_t keymap_layer_count(void);
+// Get the keycode for the keymap location, stored in firmware rather than any other persistent storage
+uint16_t keycode_at_keymap_location_raw(uint8_t layer_num, uint8_t row, uint8_t column);
+// Get the keycode for the keymap location, potentially stored dynamically
+uint16_t keycode_at_keymap_location(uint8_t layer_num, uint8_t row, uint8_t column);
+
#if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
// Get the number of layers defined in the encoder map
uint8_t encodermap_layer_count(void);
+// Get the keycode for the encoder mapping location, stored in firmware rather than any other persistent storage
+uint16_t keycode_at_encodermap_location_raw(uint8_t layer_num, uint8_t encoder_idx, bool clockwise);
+// Get the keycode for the encoder mapping location, potentially stored dynamically
+uint16_t keycode_at_encodermap_location(uint8_t layer_num, uint8_t encoder_idx, bool clockwise);
+
#endif // defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE)
diff --git a/quantum/led.c b/quantum/led.c
index 444d38f751..7db38bb88c 100644
--- a/quantum/led.c
+++ b/quantum/led.c
@@ -92,32 +92,36 @@ __attribute__((weak)) bool led_update_user(led_t led_state) {
__attribute__((weak)) bool led_update_kb(led_t led_state) {
bool res = led_update_user(led_state);
if (res) {
-#if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN)
-# if LED_PIN_ON_STATE == 0
- // invert the whole thing to avoid having to conditionally !led_state.x later
- led_state.raw = ~led_state.raw;
-# endif
-
-# ifdef LED_NUM_LOCK_PIN
- writePin(LED_NUM_LOCK_PIN, led_state.num_lock);
-# endif
-# ifdef LED_CAPS_LOCK_PIN
- writePin(LED_CAPS_LOCK_PIN, led_state.caps_lock);
-# endif
-# ifdef LED_SCROLL_LOCK_PIN
- writePin(LED_SCROLL_LOCK_PIN, led_state.scroll_lock);
-# endif
-# ifdef LED_COMPOSE_PIN
- writePin(LED_COMPOSE_PIN, led_state.compose);
-# endif
-# ifdef LED_KANA_PIN
- writePin(LED_KANA_PIN, led_state.kana);
-# endif
-#endif
+ led_update_ports(led_state);
}
return res;
}
+/** \brief Write LED state to hardware
+ */
+__attribute__((weak)) void led_update_ports(led_t led_state) {
+#if LED_PIN_ON_STATE == 0
+ // invert the whole thing to avoid having to conditionally !led_state.x later
+ led_state.raw = ~led_state.raw;
+#endif
+
+#ifdef LED_NUM_LOCK_PIN
+ writePin(LED_NUM_LOCK_PIN, led_state.num_lock);
+#endif
+#ifdef LED_CAPS_LOCK_PIN
+ writePin(LED_CAPS_LOCK_PIN, led_state.caps_lock);
+#endif
+#ifdef LED_SCROLL_LOCK_PIN
+ writePin(LED_SCROLL_LOCK_PIN, led_state.scroll_lock);
+#endif
+#ifdef LED_COMPOSE_PIN
+ writePin(LED_COMPOSE_PIN, led_state.compose);
+#endif
+#ifdef LED_KANA_PIN
+ writePin(LED_KANA_PIN, led_state.kana);
+#endif
+}
+
/** \brief Initialise any LED related hardware and/or state
*/
__attribute__((weak)) void led_init_ports(void) {
diff --git a/quantum/led.h b/quantum/led.h
index b8262cbd8e..d12e519ea2 100644
--- a/quantum/led.h
+++ b/quantum/led.h
@@ -60,6 +60,7 @@ void led_set_user(uint8_t usb_led);
void led_set_kb(uint8_t usb_led);
bool led_update_user(led_t led_state);
bool led_update_kb(led_t led_state);
+void led_update_ports(led_t led_state);
uint32_t last_led_activity_time(void); // Timestamp of the LED activity
uint32_t last_led_activity_elapsed(void); // Number of milliseconds since the last LED activity
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c
index 14dd0dd48a..e215c2c2c3 100644
--- a/quantum/led_matrix/led_matrix.c
+++ b/quantum/led_matrix/led_matrix.c
@@ -54,12 +54,8 @@ const led_point_t k_led_matrix_center = LED_MATRIX_CENTER;
// -----End led effect includes macros-------
// ------------------------------------------
-#if defined(LED_DISABLE_AFTER_TIMEOUT) && !defined(LED_DISABLE_TIMEOUT)
-# define LED_DISABLE_TIMEOUT (LED_DISABLE_AFTER_TIMEOUT * 1200UL)
-#endif
-
-#ifndef LED_DISABLE_TIMEOUT
-# define LED_DISABLE_TIMEOUT 0
+#ifndef LED_MATRIX_TIMEOUT
+# define LED_MATRIX_TIMEOUT 0
#endif
#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
@@ -103,9 +99,9 @@ static uint8_t led_last_enable = UINT8_MAX;
static uint8_t led_last_effect = UINT8_MAX;
static effect_params_t led_effect_params = {0, LED_FLAG_ALL, false};
static led_task_states led_task_state = SYNCING;
-#if LED_DISABLE_TIMEOUT > 0
+#if LED_MATRIX_TIMEOUT > 0
static uint32_t led_anykey_timer;
-#endif // LED_DISABLE_TIMEOUT > 0
+#endif // LED_MATRIX_TIMEOUT > 0
// double buffers
static uint32_t led_timer_buffer;
@@ -170,7 +166,7 @@ void led_matrix_set_value(int index, uint8_t value) {
void led_matrix_set_value_all(uint8_t value) {
#if defined(LED_MATRIX_ENABLE) && defined(LED_MATRIX_SPLIT)
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++)
+ for (uint8_t i = 0; i < LED_MATRIX_LED_COUNT; i++)
led_matrix_set_value(i, value);
#else
# ifdef USE_CIE1931_CURVE
@@ -185,9 +181,9 @@ void process_led_matrix(uint8_t row, uint8_t col, bool pressed) {
#ifndef LED_MATRIX_SPLIT
if (!is_keyboard_master()) return;
#endif
-#if LED_DISABLE_TIMEOUT > 0
+#if LED_MATRIX_TIMEOUT > 0
led_anykey_timer = 0;
-#endif // LED_DISABLE_TIMEOUT > 0
+#endif // LED_MATRIX_TIMEOUT > 0
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
uint8_t led[LED_HITS_TO_REMEMBER];
@@ -237,13 +233,13 @@ static bool led_matrix_none(effect_params_t *params) {
}
static void led_task_timers(void) {
-#if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0
+#if defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_MATRIX_TIMEOUT > 0
uint32_t deltaTime = sync_timer_elapsed32(led_timer_buffer);
-#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_DISABLE_TIMEOUT > 0
+#endif // defined(LED_MATRIX_KEYREACTIVE_ENABLED) || LED_MATRIX_TIMEOUT > 0
led_timer_buffer = sync_timer_read32();
// Update double buffer timers
-#if LED_DISABLE_TIMEOUT > 0
+#if LED_MATRIX_TIMEOUT > 0
if (led_anykey_timer < UINT32_MAX) {
if (UINT32_MAX - deltaTime < led_anykey_timer) {
led_anykey_timer = UINT32_MAX;
@@ -251,7 +247,7 @@ static void led_task_timers(void) {
led_anykey_timer += deltaTime;
}
}
-#endif // LED_DISABLE_TIMEOUT > 0
+#endif // LED_MATRIX_TIMEOUT > 0
// Update double buffer last hit timers
#ifdef LED_MATRIX_KEYREACTIVE_ENABLED
@@ -357,9 +353,9 @@ void led_matrix_task(void) {
// Ideally we would also stop sending zeros to the LED driver PWM buffers
// while suspended and just do a software shutdown. This is a cheap hack for now.
bool suspend_backlight = suspend_state ||
-#if LED_DISABLE_TIMEOUT > 0
- (led_anykey_timer > (uint32_t)LED_DISABLE_TIMEOUT) ||
-#endif // LED_DISABLE_TIMEOUT > 0
+#if LED_MATRIX_TIMEOUT > 0
+ (led_anykey_timer > (uint32_t)LED_MATRIX_TIMEOUT) ||
+#endif // LED_MATRIX_TIMEOUT > 0
false;
uint8_t effect = suspend_backlight || !led_matrix_eeconfig.enable ? 0 : led_matrix_eeconfig.mode;
@@ -389,9 +385,13 @@ void led_matrix_indicators(void) {
led_matrix_indicators_user();
}
-__attribute__((weak)) void led_matrix_indicators_kb(void) {}
+__attribute__((weak)) bool led_matrix_indicators_kb(void) {
+ return led_matrix_indicators_user();
+}
-__attribute__((weak)) void led_matrix_indicators_user(void) {}
+__attribute__((weak)) bool led_matrix_indicators_user(void) {
+ return true;
+}
void led_matrix_indicators_advanced(effect_params_t *params) {
/* special handling is needed for "params->iter", since it's already been incremented.
@@ -399,21 +399,25 @@ void led_matrix_indicators_advanced(effect_params_t *params) {
* and not sure which would be better. Otherwise, this should be called from
* led_task_render, right before the iter++ line.
*/
-#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
+#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < LED_MATRIX_LED_COUNT
uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1);
uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT;
- if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
+ if (max > LED_MATRIX_LED_COUNT) max = LED_MATRIX_LED_COUNT;
#else
uint8_t min = 0;
- uint8_t max = DRIVER_LED_TOTAL;
+ uint8_t max = LED_MATRIX_LED_COUNT;
#endif
led_matrix_indicators_advanced_kb(min, max);
led_matrix_indicators_advanced_user(min, max);
}
-__attribute__((weak)) void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {}
+__attribute__((weak)) bool led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
+ return led_matrix_indicators_advanced_user(led_min, led_max);
+}
-__attribute__((weak)) void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {}
+__attribute__((weak)) bool led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
+ return true;
+}
void led_matrix_init(void) {
led_matrix_driver.init();
diff --git a/quantum/led_matrix/led_matrix.h b/quantum/led_matrix/led_matrix.h
index 446f293c78..c7d360f366 100644
--- a/quantum/led_matrix/led_matrix.h
+++ b/quantum/led_matrix/led_matrix.h
@@ -42,15 +42,15 @@
#endif
#ifndef LED_MATRIX_LED_PROCESS_LIMIT
-# define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
+# define LED_MATRIX_LED_PROCESS_LIMIT (LED_MATRIX_LED_COUNT + 4) / 5
#endif
-#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
+#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < LED_MATRIX_LED_COUNT
# if defined(LED_MATRIX_SPLIT)
# define LED_MATRIX_USE_LIMITS(min, max) \
uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
- if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; \
+ if (max > LED_MATRIX_LED_COUNT) max = LED_MATRIX_LED_COUNT; \
uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \
if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \
if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0];
@@ -58,20 +58,20 @@
# define LED_MATRIX_USE_LIMITS(min, max) \
uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
- if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
+ if (max > LED_MATRIX_LED_COUNT) max = LED_MATRIX_LED_COUNT;
# endif
#else
# if defined(LED_MATRIX_SPLIT)
# define LED_MATRIX_USE_LIMITS(min, max) \
uint8_t min = 0; \
- uint8_t max = DRIVER_LED_TOTAL; \
+ uint8_t max = LED_MATRIX_LED_COUNT; \
const uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT; \
if (is_keyboard_left() && (max > k_led_matrix_split[0])) max = k_led_matrix_split[0]; \
if (!(is_keyboard_left()) && (min < k_led_matrix_split[0])) min = k_led_matrix_split[0];
# else
# define LED_MATRIX_USE_LIMITS(min, max) \
uint8_t min = 0; \
- uint8_t max = DRIVER_LED_TOTAL;
+ uint8_t max = LED_MATRIX_LED_COUNT;
# endif
#endif
@@ -120,12 +120,12 @@ void led_matrix_task(void);
// This runs after another backlight effect and replaces
// values already set
void led_matrix_indicators(void);
-void led_matrix_indicators_kb(void);
-void led_matrix_indicators_user(void);
+bool led_matrix_indicators_kb(void);
+bool led_matrix_indicators_user(void);
void led_matrix_indicators_advanced(effect_params_t *params);
-void led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
-void led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
+bool led_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
+bool led_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
void led_matrix_init(void);
@@ -181,9 +181,9 @@ static inline bool led_matrix_check_finished_leds(uint8_t led_idx) {
uint8_t k_led_matrix_split[2] = LED_MATRIX_SPLIT;
return led_idx < k_led_matrix_split[0];
} else
- return led_idx < DRIVER_LED_TOTAL;
+ return led_idx < LED_MATRIX_LED_COUNT;
#else
- return led_idx < DRIVER_LED_TOTAL;
+ return led_idx < LED_MATRIX_LED_COUNT;
#endif
}
diff --git a/quantum/led_matrix/led_matrix_drivers.c b/quantum/led_matrix/led_matrix_drivers.c
index f01b395c15..2c09ba82b1 100644
--- a/quantum/led_matrix/led_matrix_drivers.c
+++ b/quantum/led_matrix/led_matrix_drivers.c
@@ -96,7 +96,7 @@ static void init(void) {
# endif
# endif
- for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
+ for (int index = 0; index < LED_MATRIX_LED_COUNT; index++) {
# if defined(IS31FL3731)
IS31FL3731_set_led_control_register(index, true);
# elif defined(IS31FL3733)
diff --git a/quantum/led_matrix/led_matrix_types.h b/quantum/led_matrix/led_matrix_types.h
index 3dc533100f..6d79a3592d 100644
--- a/quantum/led_matrix/led_matrix_types.h
+++ b/quantum/led_matrix/led_matrix_types.h
@@ -76,8 +76,8 @@ typedef struct PACKED {
typedef struct PACKED {
uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS];
- led_point_t point[DRIVER_LED_TOTAL];
- uint8_t flags[DRIVER_LED_TOTAL];
+ led_point_t point[LED_MATRIX_LED_COUNT];
+ uint8_t flags[LED_MATRIX_LED_COUNT];
} led_config_t;
typedef union {
diff --git a/quantum/mousekey.c b/quantum/mousekey.c
index 25a89bdba7..b91db80de6 100644
--- a/quantum/mousekey.c
+++ b/quantum/mousekey.c
@@ -37,6 +37,13 @@ static void mousekey_debug(void);
static uint8_t mousekey_accel = 0;
static uint8_t mousekey_repeat = 0;
static uint8_t mousekey_wheel_repeat = 0;
+#ifdef MOUSEKEY_INERTIA
+static uint8_t mousekey_frame = 0; // track whether gesture is inactive, first frame, or repeating
+static int8_t mousekey_x_dir = 0; // -1 / 0 / 1 = left / neutral / right
+static int8_t mousekey_y_dir = 0; // -1 / 0 / 0 = up / neutral / down
+static int8_t mousekey_x_inertia = 0; // current velocity, limit +/- MOUSEKEY_TIME_TO_MAX
+static int8_t mousekey_y_inertia = 0; // ...
+#endif
#ifdef MK_KINETIC_SPEED
static uint16_t mouse_timer = 0;
#endif
@@ -76,6 +83,7 @@ uint8_t mk_wheel_time_to_max = MOUSEKEY_WHEEL_TIME_TO_MAX;
# ifndef MK_COMBINED
# ifndef MK_KINETIC_SPEED
+# ifndef MOUSEKEY_INERTIA
/* Default accelerated mode */
@@ -97,6 +105,53 @@ static uint8_t move_unit(void) {
return (unit > MOUSEKEY_MOVE_MAX ? MOUSEKEY_MOVE_MAX : (unit == 0 ? 1 : unit));
}
+# else // MOUSEKEY_INERTIA mode
+
+static int8_t move_unit(uint8_t axis) {
+ int16_t unit;
+
+ // handle X or Y axis
+ int8_t inertia, dir;
+ if (axis) {
+ inertia = mousekey_y_inertia;
+ dir = mousekey_y_dir;
+ } else {
+ inertia = mousekey_x_inertia;
+ dir = mousekey_x_dir;
+ }
+
+ if (mousekey_frame < 2) { // first frame(s): initial keypress moves one pixel
+ mousekey_frame = 1;
+ unit = dir * MOUSEKEY_MOVE_DELTA;
+ } else { // acceleration
+ // linear acceleration (is here for reference, but doesn't feel as good during use)
+ // unit = (MOUSEKEY_MOVE_DELTA * mk_max_speed * inertia) / mk_time_to_max;
+
+ // x**2 acceleration (quadratic, more precise for short movements)
+ int16_t percent = (inertia << 8) / mk_time_to_max;
+ percent = (percent * percent) >> 8;
+ if (inertia < 0) percent = -percent;
+
+ // unit = sign(inertia) + (percent of max speed)
+ if (inertia > 0)
+ unit = 1;
+ else if (inertia < 0)
+ unit = -1;
+ else
+ unit = 0;
+
+ unit = unit + ((mk_max_speed * percent) >> 8);
+ }
+
+ if (unit > MOUSEKEY_MOVE_MAX)
+ unit = MOUSEKEY_MOVE_MAX;
+ else if (unit < -MOUSEKEY_MOVE_MAX)
+ unit = -MOUSEKEY_MOVE_MAX;
+ return unit;
+}
+
+# endif // end MOUSEKEY_INERTIA mode
+
static uint8_t wheel_unit(void) {
uint16_t unit;
if (mousekey_accel & (1 << 0)) {
@@ -213,6 +268,28 @@ static uint8_t wheel_unit(void) {
# endif /* #ifndef MK_COMBINED */
+# ifdef MOUSEKEY_INERTIA
+
+static int8_t calc_inertia(int8_t direction, int8_t velocity) {
+ // simulate acceleration and deceleration
+
+ // deceleration
+ if ((direction > -1) && (velocity < 0))
+ velocity = (velocity + 1) * (256 - MOUSEKEY_FRICTION) / 256;
+ else if ((direction < 1) && (velocity > 0))
+ velocity = velocity * (256 - MOUSEKEY_FRICTION) / 256;
+
+ // acceleration
+ if ((direction > 0) && (velocity < mk_time_to_max))
+ velocity++;
+ else if ((direction < 0) && (velocity > -mk_time_to_max))
+ velocity--;
+
+ return velocity;
+}
+
+# endif
+
void mousekey_task(void) {
// report cursor and scroll movement independently
report_mouse_t tmpmr = mouse_report;
@@ -222,6 +299,32 @@ void mousekey_task(void) {
mouse_report.v = 0;
mouse_report.h = 0;
+# ifdef MOUSEKEY_INERTIA
+
+ // if an animation is in progress and it's time for the next frame
+ if ((mousekey_frame) && timer_elapsed(last_timer_c) > ((mousekey_frame > 1) ? mk_interval : mk_delay * 10)) {
+ mousekey_x_inertia = calc_inertia(mousekey_x_dir, mousekey_x_inertia);
+ mousekey_y_inertia = calc_inertia(mousekey_y_dir, mousekey_y_inertia);
+
+ mouse_report.x = move_unit(0);
+ mouse_report.y = move_unit(1);
+
+ // prevent sticky "drift"
+ if ((!mousekey_x_dir) && (!mousekey_x_inertia)) tmpmr.x = 0;
+ if ((!mousekey_y_dir) && (!mousekey_y_inertia)) tmpmr.y = 0;
+
+ if (mousekey_frame < 2) mousekey_frame++;
+ }
+
+ // reset if not moving and no movement keys are held
+ if ((!mousekey_x_dir) && (!mousekey_y_dir) && (!mousekey_x_inertia) && (!mousekey_y_inertia)) {
+ mousekey_frame = 0;
+ tmpmr.x = 0;
+ tmpmr.y = 0;
+ }
+
+# else // default acceleration
+
if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
if (tmpmr.x != 0) mouse_report.x = move_unit() * ((tmpmr.x > 0) ? 1 : -1);
@@ -239,6 +342,9 @@ void mousekey_task(void) {
}
}
}
+
+# endif // MOUSEKEY_INERTIA or not
+
if ((tmpmr.v || tmpmr.h) && timer_elapsed(last_timer_w) > (mousekey_wheel_repeat ? mk_wheel_interval : mk_wheel_delay * 10)) {
if (mousekey_wheel_repeat != UINT8_MAX) mousekey_wheel_repeat++;
if (tmpmr.v != 0) mouse_report.v = wheel_unit() * ((tmpmr.v > 0) ? 1 : -1);
@@ -260,6 +366,7 @@ void mousekey_task(void) {
if (has_mouse_report_changed(&mouse_report, &tmpmr) || should_mousekey_report_send(&mouse_report)) {
mousekey_send();
}
+ // save the state for later
memcpy(&mouse_report, &tmpmr, sizeof(tmpmr));
}
@@ -270,6 +377,19 @@ void mousekey_on(uint8_t code) {
}
# endif /* #ifdef MK_KINETIC_SPEED */
+# ifdef MOUSEKEY_INERTIA
+
+ // initial keypress sets impulse and activates first frame of movement
+ if ((code == KC_MS_UP) || (code == KC_MS_DOWN)) {
+ mousekey_y_dir = (code == KC_MS_DOWN) ? 1 : -1;
+ if (mousekey_frame < 2) mouse_report.y = move_unit(1);
+ } else if ((code == KC_MS_LEFT) || (code == KC_MS_RIGHT)) {
+ mousekey_x_dir = (code == KC_MS_RIGHT) ? 1 : -1;
+ if (mousekey_frame < 2) mouse_report.x = move_unit(0);
+ }
+
+# else // no inertia
+
if (code == KC_MS_UP)
mouse_report.y = move_unit() * -1;
else if (code == KC_MS_DOWN)
@@ -278,6 +398,9 @@ void mousekey_on(uint8_t code) {
mouse_report.x = move_unit() * -1;
else if (code == KC_MS_RIGHT)
mouse_report.x = move_unit();
+
+# endif // inertia or not
+
else if (code == KC_MS_WH_UP)
mouse_report.v = wheel_unit();
else if (code == KC_MS_WH_DOWN)
@@ -297,6 +420,20 @@ void mousekey_on(uint8_t code) {
}
void mousekey_off(uint8_t code) {
+# ifdef MOUSEKEY_INERTIA
+
+ // key release clears impulse unless opposite direction is held
+ if ((code == KC_MS_UP) && (mousekey_y_dir < 1))
+ mousekey_y_dir = 0;
+ else if ((code == KC_MS_DOWN) && (mousekey_y_dir > -1))
+ mousekey_y_dir = 0;
+ else if ((code == KC_MS_LEFT) && (mousekey_x_dir < 1))
+ mousekey_x_dir = 0;
+ else if ((code == KC_MS_RIGHT) && (mousekey_x_dir > -1))
+ mousekey_x_dir = 0;
+
+# else // no inertia
+
if (code == KC_MS_UP && mouse_report.y < 0)
mouse_report.y = 0;
else if (code == KC_MS_DOWN && mouse_report.y > 0)
@@ -305,6 +442,9 @@ void mousekey_off(uint8_t code) {
mouse_report.x = 0;
else if (code == KC_MS_RIGHT && mouse_report.x > 0)
mouse_report.x = 0;
+
+# endif // inertia or not
+
else if (code == KC_MS_WH_UP && mouse_report.v > 0)
mouse_report.v = 0;
else if (code == KC_MS_WH_DOWN && mouse_report.v < 0)
@@ -476,6 +616,13 @@ void mousekey_clear(void) {
mousekey_repeat = 0;
mousekey_wheel_repeat = 0;
mousekey_accel = 0;
+#ifdef MOUSEKEY_INERTIA
+ mousekey_frame = 0;
+ mousekey_x_inertia = 0;
+ mousekey_y_inertia = 0;
+ mousekey_x_dir = 0;
+ mousekey_y_dir = 0;
+#endif
}
static void mousekey_debug(void) {
diff --git a/quantum/mousekey.h b/quantum/mousekey.h
index da2edb481a..e968e000c0 100644
--- a/quantum/mousekey.h
+++ b/quantum/mousekey.h
@@ -36,34 +36,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# endif
# ifndef MOUSEKEY_MOVE_DELTA
-# ifndef MK_KINETIC_SPEED
-# define MOUSEKEY_MOVE_DELTA 8
-# else
+# if defined(MK_KINETIC_SPEED)
# define MOUSEKEY_MOVE_DELTA 16
+# elif defined(MOUSEKEY_INERTIA)
+# define MOUSEKEY_MOVE_DELTA 1
+# else
+# define MOUSEKEY_MOVE_DELTA 8
# endif
# endif
# ifndef MOUSEKEY_WHEEL_DELTA
# define MOUSEKEY_WHEEL_DELTA 1
# endif
# ifndef MOUSEKEY_DELAY
-# ifndef MK_KINETIC_SPEED
-# define MOUSEKEY_DELAY 10
-# else
+# if defined(MK_KINETIC_SPEED)
# define MOUSEKEY_DELAY 5
+# elif defined(MOUSEKEY_INERTIA)
+# define MOUSEKEY_DELAY 150 // allow single-pixel movements before repeat activates
+# else
+# define MOUSEKEY_DELAY 10
# endif
# endif
# ifndef MOUSEKEY_INTERVAL
-# ifndef MK_KINETIC_SPEED
-# define MOUSEKEY_INTERVAL 20
-# else
+# if defined(MK_KINETIC_SPEED)
# define MOUSEKEY_INTERVAL 10
+# elif defined(MOUSEKEY_INERTIA)
+# define MOUSEKEY_INTERVAL 16 // 60 fps
+# else
+# define MOUSEKEY_INTERVAL 20
# endif
# endif
# ifndef MOUSEKEY_MAX_SPEED
-# define MOUSEKEY_MAX_SPEED 10
+# if defined(MOUSEKEY_INERTIA)
+# define MOUSEKEY_MAX_SPEED 32
+# else
+# define MOUSEKEY_MAX_SPEED 10
+# endif
# endif
# ifndef MOUSEKEY_TIME_TO_MAX
-# define MOUSEKEY_TIME_TO_MAX 30
+# if defined(MOUSEKEY_INERTIA)
+# define MOUSEKEY_TIME_TO_MAX 32
+# else
+# define MOUSEKEY_TIME_TO_MAX 30
+# endif
# endif
# ifndef MOUSEKEY_WHEEL_DELAY
# define MOUSEKEY_WHEEL_DELAY 10
@@ -78,6 +92,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define MOUSEKEY_WHEEL_TIME_TO_MAX 40
# endif
+# ifndef MOUSEKEY_FRICTION
+# define MOUSEKEY_FRICTION 24 // 0 to 255
+# endif
# ifndef MOUSEKEY_INITIAL_SPEED
# define MOUSEKEY_INITIAL_SPEED 100
# endif
diff --git a/quantum/painter/qp.h b/quantum/painter/qp.h
index fb6904de22..69bc435961 100644
--- a/quantum/painter/qp.h
+++ b/quantum/painter/qp.h
@@ -432,6 +432,10 @@ int16_t qp_drawtext_recolor(painter_device_t device, uint16_t x, uint16_t y, pai
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter Drivers
+#ifdef QUANTUM_PAINTER_RGB565_SURFACE_ENABLE
+# include "qp_rgb565_surface.h"
+#endif // QUANTUM_PAINTER_RGB565_SURFACE_ENABLE
+
#ifdef QUANTUM_PAINTER_ILI9163_ENABLE
# include "qp_ili9163.h"
#endif // QUANTUM_PAINTER_ILI9163_ENABLE
diff --git a/quantum/painter/qp_draw_image.c b/quantum/painter/qp_draw_image.c
index 5822758dce..e9b975f23a 100644
--- a/quantum/painter/qp_draw_image.c
+++ b/quantum/painter/qp_draw_image.c
@@ -25,10 +25,10 @@ typedef struct qgf_image_handle_t {
static qgf_image_handle_t image_descriptors[QUANTUM_PAINTER_NUM_IMAGES] = {0};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Quantum Painter External API: qp_load_image_mem
+// Helper: load image from stream
-painter_image_handle_t qp_load_image_mem(const void *buffer) {
- qp_dprintf("qp_load_image_mem: entry\n");
+static painter_image_handle_t qp_load_image_internal(bool (*stream_factory)(qgf_image_handle_t *image, void *arg), void *arg) {
+ qp_dprintf("qp_load_image: entry\n");
qgf_image_handle_t *image = NULL;
// Find a free slot
@@ -41,20 +41,18 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) {
// Drop out if not found
if (!image) {
- qp_dprintf("qp_load_image_mem: fail (no free slot)\n");
+ qp_dprintf("qp_load_image: fail (no free slot)\n");
return NULL;
}
- // Assume we can read the graphics descriptor
- image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t));
-
- // Update the length of the stream to match, and rewind to the start
- image->mem_stream.length = qgf_get_total_size(&image->stream);
- image->mem_stream.position = 0;
+ if (!stream_factory(image, arg)) {
+ qp_dprintf("qp_load_image: fail (could not create stream)\n");
+ return NULL;
+ }
// Now that we know the length, validate the input data
if (!qgf_validate_stream(&image->stream)) {
- qp_dprintf("qp_load_image_mem: fail (failed validation)\n");
+ qp_dprintf("qp_load_image: fail (failed validation)\n");
return NULL;
}
@@ -63,11 +61,31 @@ painter_image_handle_t qp_load_image_mem(const void *buffer) {
// Validation success, we can return the handle
image->validate_ok = true;
- qp_dprintf("qp_load_image_mem: ok\n");
+ qp_dprintf("qp_load_image: ok\n");
return (painter_image_handle_t)image;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Quantum Painter External API: qp_load_image_mem
+
+static inline bool image_mem_stream_factory(qgf_image_handle_t *image, void *arg) {
+ void *buffer = arg;
+
+ // Assume we can read the graphics descriptor
+ image->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qgf_graphics_descriptor_v1_t));
+
+ // Update the length of the stream to match, and rewind to the start
+ image->mem_stream.length = qgf_get_total_size(&image->stream);
+ image->mem_stream.position = 0;
+
+ return true;
+}
+
+painter_image_handle_t qp_load_image_mem(const void *buffer) {
+ return qp_load_image_internal(image_mem_stream_factory, (void *)buffer);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter External API: qp_close_image
bool qp_close_image(painter_image_handle_t image) {
@@ -79,6 +97,7 @@ bool qp_close_image(painter_image_handle_t image) {
// Free up this image for use elsewhere.
qgf_image->validate_ok = false;
+ qp_stream_close(&qgf_image->stream);
return true;
}
diff --git a/quantum/painter/qp_draw_text.c b/quantum/painter/qp_draw_text.c
index f99e082cad..0f5473abd0 100644
--- a/quantum/painter/qp_draw_text.c
+++ b/quantum/painter/qp_draw_text.c
@@ -36,10 +36,10 @@ typedef struct qff_font_handle_t {
static qff_font_handle_t font_descriptors[QUANTUM_PAINTER_NUM_FONTS] = {0};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Quantum Painter External API: qp_load_font_mem
+// Helper: load font from stream
-painter_font_handle_t qp_load_font_mem(const void *buffer) {
- qp_dprintf("qp_load_font_mem: entry\n");
+static painter_font_handle_t qp_load_font_internal(bool (*stream_factory)(qff_font_handle_t *font, void *arg), void *arg) {
+ qp_dprintf("qp_load_font: entry\n");
qff_font_handle_t *font = NULL;
// Find a free slot
@@ -52,20 +52,18 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
// Drop out if not found
if (!font) {
- qp_dprintf("qp_load_font_mem: fail (no free slot)\n");
+ qp_dprintf("qp_load_font: fail (no free slot)\n");
return NULL;
}
- // Assume we can read the graphics descriptor
- font->mem_stream = qp_make_memory_stream((void *)buffer, sizeof(qff_font_descriptor_v1_t));
-
- // Update the length of the stream to match, and rewind to the start
- font->mem_stream.length = qff_get_total_size(&font->stream);
- font->mem_stream.position = 0;
+ if (!stream_factory(font, arg)) {
+ qp_dprintf("qp_load_font: fail (could not create stream)\n");
+ return NULL;
+ }
// Now that we know the length, validate the input data
if (!qff_validate_stream(&font->stream)) {
- qp_dprintf("qp_load_font_mem: fail (failed validation)\n");
+ qp_dprintf("qp_load_font: fail (failed validation)\n");
return NULL;
}
@@ -76,12 +74,12 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
void *ram_buffer = malloc(font->mem_stream.length);
if (ram_buffer == NULL) {
- qp_dprintf("qp_load_font_mem: could not allocate enough RAM for font, falling back to original\n");
+ qp_dprintf("qp_load_font: could not allocate enough RAM for font, falling back to original\n");
} else {
do {
// Copy the data into RAM
if (qp_stream_read(ram_buffer, 1, font->mem_stream.length, &font->mem_stream) != font->mem_stream.length) {
- qp_dprintf("qp_load_font_mem: could not copy from flash to RAM, falling back to original\n");
+ qp_dprintf("qp_load_font: could not copy from flash to RAM, falling back to original\n");
break;
}
@@ -102,18 +100,38 @@ painter_font_handle_t qp_load_font_mem(const void *buffer) {
qff_read_font_descriptor(&font->stream, &font->base.line_height, &font->has_ascii_table, &font->num_unicode_glyphs, &font->bpp, &font->has_palette, &font->compression_scheme, NULL);
if (!qp_internal_bpp_capable(font->bpp)) {
- qp_dprintf("qp_load_font_mem: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)font->bpp);
+ qp_dprintf("qp_load_font: fail (image bpp too high (%d), check QUANTUM_PAINTER_SUPPORTS_256_PALETTE)\n", (int)font->bpp);
qp_close_font((painter_font_handle_t)font);
return NULL;
}
// Validation success, we can return the handle
font->validate_ok = true;
- qp_dprintf("qp_load_font_mem: ok\n");
+ qp_dprintf("qp_load_font: ok\n");
return (painter_font_handle_t)font;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Quantum Painter External API: qp_load_font_mem
+
+static inline bool font_mem_stream_factory(qff_font_handle_t *font, void *arg) {
+ void *buffer = arg;
+
+ // Assume we can read the graphics descriptor
+ font->mem_stream = qp_make_memory_stream(buffer, sizeof(qff_font_descriptor_v1_t));
+
+ // Update the length of the stream to match, and rewind to the start
+ font->mem_stream.length = qff_get_total_size(&font->stream);
+ font->mem_stream.position = 0;
+
+ return true;
+}
+
+painter_font_handle_t qp_load_font_mem(const void *buffer) {
+ return qp_load_font_internal(font_mem_stream_factory, (void *)buffer);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Quantum Painter External API: qp_close_font
bool qp_close_font(painter_font_handle_t font) {
@@ -133,6 +151,7 @@ bool qp_close_font(painter_font_handle_t font) {
#endif // QUANTUM_PAINTER_LOAD_FONTS_TO_RAM
// Free up this font for use elsewhere.
+ qp_stream_close(&qff_font->stream);
qff_font->validate_ok = false;
return true;
}
diff --git a/quantum/painter/qp_stream.c b/quantum/painter/qp_stream.c
index f00ae5ed38..1198cf793d 100644
--- a/quantum/painter/qp_stream.c
+++ b/quantum/painter/qp_stream.c
@@ -38,7 +38,7 @@ uint32_t qp_stream_write_impl(const void *input_buf, uint32_t member_size, uint3
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Memory streams
-int16_t mem_get(qp_stream_t *stream) {
+static inline int16_t mem_get(qp_stream_t *stream) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
if (s->position >= s->length) {
s->is_eof = true;
@@ -47,7 +47,7 @@ int16_t mem_get(qp_stream_t *stream) {
return s->buffer[s->position++];
}
-bool mem_put(qp_stream_t *stream, uint8_t c) {
+static inline bool mem_put(qp_stream_t *stream, uint8_t c) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
if (s->position >= s->length) {
s->is_eof = true;
@@ -57,7 +57,7 @@ bool mem_put(qp_stream_t *stream, uint8_t c) {
return true;
}
-int mem_seek(qp_stream_t *stream, int32_t offset, int origin) {
+static inline int mem_seek(qp_stream_t *stream, int32_t offset, int origin) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
// Handle as per fseek
@@ -95,26 +95,23 @@ int mem_seek(qp_stream_t *stream, int32_t offset, int origin) {
return 0;
}
-int32_t mem_tell(qp_stream_t *stream) {
+static inline int32_t mem_tell(qp_stream_t *stream) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
return s->position;
}
-bool mem_is_eof(qp_stream_t *stream) {
+static inline bool mem_is_eof(qp_stream_t *stream) {
qp_memory_stream_t *s = (qp_memory_stream_t *)stream;
return s->is_eof;
}
+static inline void mem_close(qp_stream_t *stream) {
+ // No-op.
+}
+
qp_memory_stream_t qp_make_memory_stream(void *buffer, int32_t length) {
qp_memory_stream_t stream = {
- .base =
- {
- .get = mem_get,
- .put = mem_put,
- .seek = mem_seek,
- .tell = mem_tell,
- .is_eof = mem_is_eof,
- },
+ .base = {.get = mem_get, .put = mem_put, .seek = mem_seek, .tell = mem_tell, .is_eof = mem_is_eof, .close = mem_close},
.buffer = (uint8_t *)buffer,
.length = length,
.position = 0,
@@ -127,43 +124,41 @@ qp_memory_stream_t qp_make_memory_stream(void *buffer, int32_t length) {
#ifdef QP_STREAM_HAS_FILE_IO
-int16_t file_get(qp_stream_t *stream) {
+static inline int16_t file_get(qp_stream_t *stream) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
int c = fgetc(s->file);
if (c < 0 || feof(s->file)) return STREAM_EOF;
return (uint16_t)c;
}
-bool file_put(qp_stream_t *stream, uint8_t c) {
+static inline bool file_put(qp_stream_t *stream, uint8_t c) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return fputc(c, s->file) == c;
}
-int file_seek(qp_stream_t *stream, int32_t offset, int origin) {
+static inline int file_seek(qp_stream_t *stream, int32_t offset, int origin) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return fseek(s->file, offset, origin);
}
-int32_t file_tell(qp_stream_t *stream) {
+static inline int32_t file_tell(qp_stream_t *stream) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return (int32_t)ftell(s->file);
}
-bool file_is_eof(qp_stream_t *stream) {
+static inline bool file_is_eof(qp_stream_t *stream) {
qp_file_stream_t *s = (qp_file_stream_t *)stream;
return (bool)feof(s->file);
}
+static inline void file_close(qp_stream_t *stream) {
+ qp_file_stream_t *s = (qp_file_stream_t *)stream;
+ fclose(s->file);
+}
+
qp_file_stream_t qp_make_file_stream(FILE *f) {
qp_file_stream_t stream = {
- .base =
- {
- .get = file_get,
- .put = file_put,
- .seek = file_seek,
- .tell = file_tell,
- .is_eof = file_is_eof,
- },
+ .base = {.get = file_get, .put = file_put, .seek = file_seek, .tell = file_tell, .is_eof = file_is_eof, .close = file_close},
.file = f,
};
return stream;
diff --git a/quantum/painter/qp_stream.h b/quantum/painter/qp_stream.h
index 878b9bf530..c0e745adc1 100644
--- a/quantum/painter/qp_stream.h
+++ b/quantum/painter/qp_stream.h
@@ -41,6 +41,8 @@ typedef struct qp_stream_t qp_stream_t;
uint32_t qp_stream_read_impl(void *output_buf, uint32_t member_size, uint32_t num_members, qp_stream_t *stream);
uint32_t qp_stream_write_impl(const void *input_buf, uint32_t member_size, uint32_t num_members, qp_stream_t *stream);
+#define qp_stream_close(stream_ptr) (((qp_stream_t *)(stream_ptr))->close((qp_stream_t *)(stream_ptr)))
+
#define STREAM_EOF ((int16_t)(-1))
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -52,6 +54,7 @@ struct qp_stream_t {
int (*seek)(qp_stream_t *stream, int32_t offset, int origin);
int32_t (*tell)(qp_stream_t *stream);
bool (*is_eof)(qp_stream_t *stream);
+ void (*close)(qp_stream_t *stream);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -77,6 +80,6 @@ typedef struct qp_file_stream_t {
FILE * file;
} qp_file_stream_t;
-qp_file_stream_t qo_make_file_stream(FILE *f);
+qp_file_stream_t qp_make_file_stream(FILE *f);
#endif // QP_STREAM_HAS_FILE_IO
diff --git a/quantum/painter/rules.mk b/quantum/painter/rules.mk
index 91787dfe0e..5ac374a96e 100644
--- a/quantum/painter/rules.mk
+++ b/quantum/painter/rules.mk
@@ -3,14 +3,23 @@ QUANTUM_PAINTER_DRIVERS ?=
QUANTUM_PAINTER_ANIMATIONS_ENABLE ?= yes
# The list of permissible drivers that can be listed in QUANTUM_PAINTER_DRIVERS
-VALID_QUANTUM_PAINTER_DRIVERS := ili9163_spi ili9341_spi ili9488_spi st7789_spi st7735_spi gc9a01_spi ssd1351_spi
+VALID_QUANTUM_PAINTER_DRIVERS := \
+ rgb565_surface \
+ ili9163_spi \
+ ili9341_spi \
+ ili9488_spi \
+ st7735_spi \
+ st7789_spi \
+ gc9a01_spi \
+ ssd1351_spi
#-------------------------------------------------------------------------------
OPT_DEFS += -DQUANTUM_PAINTER_ENABLE
-COMMON_VPATH += $(QUANTUM_DIR)/painter
+COMMON_VPATH += $(QUANTUM_DIR)/painter \
+ $(QUANTUM_DIR)/unicode
SRC += \
- $(QUANTUM_DIR)/utf8.c \
+ $(QUANTUM_DIR)/unicode/utf8.c \
$(QUANTUM_DIR)/color.c \
$(QUANTUM_DIR)/painter/qp.c \
$(QUANTUM_DIR)/painter/qp_stream.c \
@@ -39,6 +48,13 @@ define handle_quantum_painter_driver
ifeq ($$(filter $$(strip $$(CURRENT_PAINTER_DRIVER)),$$(VALID_QUANTUM_PAINTER_DRIVERS)),)
$$(error "$$(CURRENT_PAINTER_DRIVER)" is not a valid Quantum Painter driver)
+ else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),rgb565_surface)
+ OPT_DEFS += -DQUANTUM_PAINTER_RGB565_SURFACE_ENABLE
+ COMMON_VPATH += \
+ $(DRIVER_PATH)/painter/generic
+ SRC += \
+ $(DRIVER_PATH)/painter/generic/qp_rgb565_surface.c \
+
else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),ili9163_spi)
QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes
QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes
@@ -72,27 +88,27 @@ define handle_quantum_painter_driver
$(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \
$(DRIVER_PATH)/painter/ili9xxx/qp_ili9488.c \
- else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7789_spi)
+ else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7735_spi)
QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes
QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes
- OPT_DEFS += -DQUANTUM_PAINTER_ST7789_ENABLE -DQUANTUM_PAINTER_ST7789_SPI_ENABLE
+ OPT_DEFS += -DQUANTUM_PAINTER_ST7735_ENABLE -DQUANTUM_PAINTER_ST7735_SPI_ENABLE
COMMON_VPATH += \
$(DRIVER_PATH)/painter/tft_panel \
$(DRIVER_PATH)/painter/st77xx
SRC += \
$(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \
- $(DRIVER_PATH)/painter/st77xx/qp_st7789.c
+ $(DRIVER_PATH)/painter/st77xx/qp_st7735.c
- else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7735_spi)
+ else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),st7789_spi)
QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes
QUANTUM_PAINTER_NEEDS_COMMS_SPI_DC_RESET := yes
- OPT_DEFS += -DQUANTUM_PAINTER_ST7735_ENABLE -DQUANTUM_PAINTER_ST7735_SPI_ENABLE
+ OPT_DEFS += -DQUANTUM_PAINTER_ST7789_ENABLE -DQUANTUM_PAINTER_ST7789_SPI_ENABLE
COMMON_VPATH += \
$(DRIVER_PATH)/painter/tft_panel \
$(DRIVER_PATH)/painter/st77xx
SRC += \
$(DRIVER_PATH)/painter/tft_panel/qp_tft_panel.c \
- $(DRIVER_PATH)/painter/st77xx/qp_st7735.c
+ $(DRIVER_PATH)/painter/st77xx/qp_st7789.c
else ifeq ($$(strip $$(CURRENT_PAINTER_DRIVER)),gc9a01_spi)
QUANTUM_PAINTER_NEEDS_COMMS_SPI := yes
diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c
index 505a7a6ffd..75bb5f81fc 100644
--- a/quantum/pointing_device/pointing_device.c
+++ b/quantum/pointing_device/pointing_device.c
@@ -22,6 +22,7 @@
#ifdef MOUSEKEY_ENABLE
# include "mousekey.h"
#endif
+
#if (defined(POINTING_DEVICE_ROTATION_90) + defined(POINTING_DEVICE_ROTATION_180) + defined(POINTING_DEVICE_ROTATION_270)) > 1
# error More than one rotation selected. This is not supported.
#endif
@@ -144,7 +145,11 @@ __attribute__((weak)) void pointing_device_init(void) {
{
pointing_device_driver.init();
#ifdef POINTING_DEVICE_MOTION_PIN
+# ifdef POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
setPinInputHigh(POINTING_DEVICE_MOTION_PIN);
+# else
+ setPinInput(POINTING_DEVICE_MOTION_PIN);
+# endif
#endif
}
@@ -166,11 +171,9 @@ __attribute__((weak)) void pointing_device_send(void) {
host_mouse_send(&local_mouse_report);
}
// send it and 0 it out except for buttons, so those stay until they are explicity over-ridden using update_pointing_device
- local_mouse_report.x = 0;
- local_mouse_report.y = 0;
- local_mouse_report.v = 0;
- local_mouse_report.h = 0;
-
+ uint8_t buttons = local_mouse_report.buttons;
+ memset(&local_mouse_report, 0, sizeof(local_mouse_report));
+ local_mouse_report.buttons = buttons;
memcpy(&old_report, &local_mouse_report, sizeof(local_mouse_report));
}
@@ -238,7 +241,11 @@ __attribute__((weak)) void pointing_device_task(void) {
# if defined(SPLIT_POINTING_ENABLE)
# error POINTING_DEVICE_MOTION_PIN not supported when sharing the pointing device report between sides.
# endif
+# ifdef POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
if (!readPin(POINTING_DEVICE_MOTION_PIN))
+# else
+ if (readPin(POINTING_DEVICE_MOTION_PIN))
+# endif
#endif
#if defined(SPLIT_POINTING_ENABLE)
@@ -270,6 +277,10 @@ __attribute__((weak)) void pointing_device_task(void) {
local_mouse_report = pointing_device_adjust_by_defines(local_mouse_report);
local_mouse_report = pointing_device_task_kb(local_mouse_report);
#endif
+ // automatic mouse layer function
+#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
+ pointing_device_task_auto_mouse(local_mouse_report);
+#endif
// combine with mouse report to ensure that the combined is sent correctly
#ifdef MOUSEKEY_ENABLE
report_mouse_t mousekey_report = mousekey_get_report();
@@ -469,3 +480,10 @@ __attribute__((weak)) report_mouse_t pointing_device_task_combined_user(report_m
return pointing_device_combine_reports(left_report, right_report);
}
#endif
+
+__attribute__((weak)) void pointing_device_keycode_handler(uint16_t keycode, bool pressed) {
+ if IS_MOUSEKEY_BUTTON (keycode) {
+ local_mouse_report.buttons = pointing_device_handle_buttons(local_mouse_report.buttons, pressed, keycode - KC_MS_BTN1);
+ pointing_device_send();
+ }
+}
diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h
index 77db5471ea..d430e6cfa4 100644
--- a/quantum/pointing_device/pointing_device.h
+++ b/quantum/pointing_device/pointing_device.h
@@ -21,20 +21,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "host.h"
#include "report.h"
+#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
+# include "pointing_device_auto_mouse.h"
+#endif
+
#if defined(POINTING_DEVICE_DRIVER_adns5050)
# include "drivers/sensors/adns5050.h"
+# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
#elif defined(POINTING_DEVICE_DRIVER_adns9800)
# include "spi_master.h"
# include "drivers/sensors/adns9800.h"
+# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
#elif defined(POINTING_DEVICE_DRIVER_analog_joystick)
# include "analog.h"
# include "drivers/sensors/analog_joystick.h"
+# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
#elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
# include "drivers/sensors/cirque_pinnacle.h"
# include "drivers/sensors/cirque_pinnacle_gestures.h"
# include "pointing_device_gestures.h"
#elif defined(POINTING_DEVICE_DRIVER_paw3204)
# include "drivers/sensors/paw3204.h"
+# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
#elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball)
# include "i2c_master.h"
# include "drivers/sensors/pimoroni_trackball.h"
@@ -48,9 +56,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# ifdef PIMORONI_TRACKBALL_ROTATE
# define POINTING_DEVICE_ROTATION_90
# endif
+# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
#elif defined(POINTING_DEVICE_DRIVER_pmw3360) || defined(POINTING_DEVICE_DRIVER_pmw3389)
# include "spi_master.h"
# include "drivers/sensors/pmw33xx_common.h"
+# define POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
#else
void pointing_device_driver_init(void);
report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report);
@@ -100,6 +110,7 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report);
report_mouse_t pointing_device_task_user(report_mouse_t mouse_report);
uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button);
report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report);
+void pointing_device_keycode_handler(uint16_t keycode, bool pressed);
#if defined(SPLIT_POINTING_ENABLE)
void pointing_device_set_shared_report(report_mouse_t report);
diff --git a/quantum/pointing_device/pointing_device_auto_mouse.c b/quantum/pointing_device/pointing_device_auto_mouse.c
new file mode 100644
index 0000000000..edffd44787
--- /dev/null
+++ b/quantum/pointing_device/pointing_device_auto_mouse.c
@@ -0,0 +1,384 @@
+/* Copyright 2021 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+ * Copyright 2022 Alabastard
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
+
+# include "pointing_device_auto_mouse.h"
+
+/* local data structure for tracking auto mouse */
+static auto_mouse_context_t auto_mouse_context = {.config.layer = (uint8_t)AUTO_MOUSE_DEFAULT_LAYER};
+
+/* local functions */
+static bool is_mouse_record(uint16_t keycode, keyrecord_t* record);
+static void auto_mouse_reset(void);
+
+/* check for target layer deactivation overrides */
+static inline bool layer_hold_check(void) {
+ return get_auto_mouse_toggle() ||
+# ifndef NO_ACTION_ONESHOT
+ get_oneshot_layer() == (AUTO_MOUSE_TARGET_LAYER) ||
+# endif
+ false;
+}
+
+/* check all layer activation criteria */
+static inline bool is_auto_mouse_active(void) {
+ return auto_mouse_context.status.is_activated || auto_mouse_context.status.mouse_key_tracker || layer_hold_check();
+}
+
+/**
+ * @brief Get auto mouse enable state
+ *
+ * Return is_enabled value
+ *
+ * @return bool true: auto mouse enabled false: auto mouse disabled
+ */
+bool get_auto_mouse_enable(void) {
+ return auto_mouse_context.config.is_enabled;
+}
+
+/**
+ * @brief get current target layer index
+ *
+ * NOTE: (AUTO_MOUSE_TARGET_LAYER) is an alias for this function
+ *
+ * @return uint8_t target layer index
+ */
+uint8_t get_auto_mouse_layer(void) {
+ return auto_mouse_context.config.layer;
+}
+
+/**
+ * @brief get layer_toggled value
+ *
+ * @return bool of current layer_toggled state
+ */
+bool get_auto_mouse_toggle(void) {
+ return auto_mouse_context.status.is_toggled;
+}
+
+/**
+ * @brief Reset auto mouse context
+ *
+ * Clear timers and status
+ *
+ * NOTE: this will set is_toggled to false so careful when using it
+ */
+static void auto_mouse_reset(void) {
+ memset(&auto_mouse_context.status, 0, sizeof(auto_mouse_context.status));
+ memset(&auto_mouse_context.timer, 0, sizeof(auto_mouse_context.timer));
+}
+
+/**
+ * @brief Set auto mouse enable state
+ *
+ * Set local auto mouse enabled state
+ *
+ * @param[in] state bool
+ */
+void set_auto_mouse_enable(bool enable) {
+ // skip if unchanged
+ if (auto_mouse_context.config.is_enabled == enable) return;
+ auto_mouse_context.config.is_enabled = enable;
+ auto_mouse_reset();
+}
+
+/**
+ * @brief Change target layer for auto mouse
+ *
+ * Sets input as the new target layer if different from current and resets auto mouse
+ *
+ * NOTE: remove_auto_mouse_layer(state, false) or auto_mouse_layer_off should be called
+ * before this function to avoid issues with layers getting stuck
+ *
+ * @param[in] layer uint8_t
+ */
+void set_auto_mouse_layer(uint8_t layer) {
+ // skip if unchanged
+ if (auto_mouse_context.config.layer == layer) return;
+ auto_mouse_context.config.layer = layer;
+ auto_mouse_reset();
+}
+
+/**
+ * @brief toggle mouse layer setting
+ *
+ * Change state of local layer_toggled bool meant to track when the mouse layer is toggled on by other means
+ *
+ * NOTE: While is_toggled is true it will prevent deactiving target layer (but not activation)
+ */
+void auto_mouse_toggle(void) {
+ auto_mouse_context.status.is_toggled ^= 1;
+ auto_mouse_context.timer.delay = 0;
+}
+
+/**
+ * @brief Remove current auto mouse target layer from layer state
+ *
+ * Will remove auto mouse target layer from given layer state if appropriate.
+ *
+ * NOTE: Removal can be forced, ignoring appropriate critera
+ *
+ * @params state[in] layer_state_t original layer state
+ * @params force[in] bool force removal
+ *
+ * @return layer_state_t modified layer state
+ */
+layer_state_t remove_auto_mouse_layer(layer_state_t state, bool force) {
+ if (force || ((AUTO_MOUSE_ENABLED) && !layer_hold_check())) {
+ state &= ~((layer_state_t)1 << (AUTO_MOUSE_TARGET_LAYER));
+ }
+ return state;
+}
+
+/**
+ * @brief Disable target layer
+ *
+ * Will disable target layer if appropriate.
+ * NOTE: NOT TO BE USED in layer_state_set stack!!!
+ */
+void auto_mouse_layer_off(void) {
+ if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && (AUTO_MOUSE_ENABLED) && !layer_hold_check()) {
+ layer_off((AUTO_MOUSE_TARGET_LAYER));
+ }
+}
+
+/**
+ * @brief Weak function to handel testing if pointing_device is active
+ *
+ * Will trigger target layer activation(if delay timer has expired) and prevent deactivation when true.
+ * May be replaced by bool in report_mouse_t in future
+ *
+ * NOTE: defined weakly to allow for changing and adding conditions for specific hardware/customization
+ *
+ * @param[in] mouse_report report_mouse_t
+ * @return bool of pointing_device activation
+ */
+__attribute__((weak)) bool auto_mouse_activation(report_mouse_t mouse_report) {
+ return mouse_report.x != 0 || mouse_report.y != 0 || mouse_report.h != 0 || mouse_report.v != 0 || mouse_report.buttons;
+}
+
+/**
+ * @brief Update the auto mouse based on mouse_report
+ *
+ * Handel activation/deactivation of target layer based on auto_mouse_activation and state timers and local key/layer tracking data
+ *
+ * @param[in] mouse_report report_mouse_t
+ */
+void pointing_device_task_auto_mouse(report_mouse_t mouse_report) {
+ // skip if disabled, delay timer running, or debounce
+ if (!(AUTO_MOUSE_ENABLED) || timer_elapsed(auto_mouse_context.timer.active) <= AUTO_MOUSE_DEBOUNCE || timer_elapsed(auto_mouse_context.timer.delay) <= AUTO_MOUSE_DELAY) {
+ return;
+ }
+ // update activation and reset debounce
+ auto_mouse_context.status.is_activated = auto_mouse_activation(mouse_report);
+ if (is_auto_mouse_active()) {
+ auto_mouse_context.timer.active = timer_read();
+ auto_mouse_context.timer.delay = 0;
+ if (!layer_state_is((AUTO_MOUSE_TARGET_LAYER))) {
+ layer_on((AUTO_MOUSE_TARGET_LAYER));
+ }
+ } else if (layer_state_is((AUTO_MOUSE_TARGET_LAYER)) && timer_elapsed(auto_mouse_context.timer.active) > AUTO_MOUSE_TIME) {
+ layer_off((AUTO_MOUSE_TARGET_LAYER));
+ auto_mouse_context.timer.active = 0;
+ }
+}
+
+/**
+ * @brief Handle mouskey event
+ *
+ * Increments/decrements mouse_key_tracker and restart active timer
+ *
+ * @param[in] pressed bool
+ */
+void auto_mouse_keyevent(bool pressed) {
+ if (pressed) {
+ auto_mouse_context.status.mouse_key_tracker++;
+ } else {
+ auto_mouse_context.status.mouse_key_tracker--;
+ }
+ auto_mouse_context.timer.delay = 0;
+}
+
+/**
+ * @brief Handle auto mouse non mousekey reset
+ *
+ * Start/restart delay timer and reset auto mouse on keydown as well as turn the
+ * target layer off if on and reset toggle status
+ *
+ * NOTE: NOT TO BE USED in layer_state_set stack!!!
+ *
+ * @param[in] pressed bool
+ */
+void auto_mouse_reset_trigger(bool pressed) {
+ if (pressed) {
+ if (layer_state_is((AUTO_MOUSE_TARGET_LAYER))) {
+ layer_off((AUTO_MOUSE_TARGET_LAYER));
+ };
+ auto_mouse_reset();
+ }
+ auto_mouse_context.timer.delay = timer_read();
+}
+
+/**
+ * @brief handle key events processing for auto mouse
+ *
+ * Will process keys differently depending on if key is defined as mousekey or not.
+ * Some keys have built in behaviour(not overwritable):
+ * mouse buttons : auto_mouse_keyevent()
+ * non-mouse keys : auto_mouse_reset_trigger()
+ * mod keys : skip auto mouse key processing
+ * mod tap : skip on hold (mod keys)
+ * QK mods e.g. LCTL(kc): default to non-mouse key, add at kb/user level as needed
+ * non target layer keys: skip auto mouse key processing (same as mod keys)
+ * MO(target layer) : auto_mouse_keyevent()
+ * target layer toggles : auto_mouse_toggle() (on both key up and keydown)
+ * target layer tap : default processing on tap mouse key on hold
+ * all other keycodes : default to non-mouse key, add at kb/user level as needed
+ *
+ * Will deactivate target layer once a non mouse key is pressed if nothing is holding the layer active
+ * such as held mousekey, toggled current target layer, or auto_mouse_activation is true
+ *
+ * @params keycode[in] uint16_t
+ * @params record[in] keyrecord_t pointer
+ */
+bool process_auto_mouse(uint16_t keycode, keyrecord_t* record) {
+ // skip if not enabled or mouse_layer not set
+ if (!(AUTO_MOUSE_ENABLED)) return true;
+
+ switch (keycode) {
+ // Skip Mod keys to avoid layer reset
+ case KC_LEFT_CTRL ... KC_RIGHT_GUI:
+ case QK_MODS ... QK_MODS_MAX:
+ break;
+ // TO((AUTO_MOUSE_TARGET_LAYER))-------------------------------------------------------------------------------
+ case QK_TO ... QK_TO_MAX: // same proccessing as next
+ // TG((AUTO_MOUSE_TARGET_LAYER))-------------------------------------------------------------------------------
+ case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:
+ if ((keycode & 0xff) == (AUTO_MOUSE_TARGET_LAYER)) {
+ if (!(record->event.pressed)) auto_mouse_toggle();
+ }
+ break;
+ // MO((AUTO_MOUSE_TARGET_LAYER))-------------------------------------------------------------------------------
+ case QK_MOMENTARY ... QK_MOMENTARY_MAX:
+ if ((keycode & 0xff) == (AUTO_MOUSE_TARGET_LAYER)) {
+ auto_mouse_keyevent(record->event.pressed);
+ }
+ // DF ---------------------------------------------------------------------------------------------------------
+ case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:
+# ifndef NO_ACTION_ONESHOT
+ // OSL((AUTO_MOUSE_TARGET_LAYER))------------------------------------------------------------------------------
+ case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
+ case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:
+# endif
+ break;
+ // LM((AUTO_MOUSE_TARGET_LAYER), mod)--------------------------------------------------------------------------
+ case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
+ if (((keycode >> 8) & 0x0f) == (AUTO_MOUSE_TARGET_LAYER)) {
+ auto_mouse_keyevent(record->event.pressed);
+ }
+ break;
+ // TT((AUTO_MOUSE_TARGET_LAYER))---------------------------------------------------------------------------
+# ifndef NO_ACTION_TAPPING
+ case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
+ if ((keycode & 0xff) == (AUTO_MOUSE_TARGET_LAYER)) {
+ auto_mouse_keyevent(record->event.pressed);
+# if TAPPING_TOGGLE != 0
+ if (record->tap.count == TAPPING_TOGGLE) {
+ if (record->event.pressed) {
+ auto_mouse_context.status.mouse_key_tracker--;
+ } else {
+ auto_mouse_toggle();
+ auto_mouse_context.status.mouse_key_tracker++;
+ }
+ }
+# endif
+ }
+ break;
+ // LT((AUTO_MOUSE_TARGET_LAYER), kc)---------------------------------------------------------------------------
+ case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
+ if (!record->tap.count) {
+ if (((keycode >> 8) & 0x0f) == (AUTO_MOUSE_TARGET_LAYER)) {
+ auto_mouse_keyevent(record->event.pressed);
+ }
+ break;
+ }
+ // MT(kc) only skip on hold
+ case QK_MOD_TAP ... QK_MOD_TAP_MAX:
+ if (!record->tap.count) break;
+# endif
+ // QK_MODS goes to default
+ default:
+ // skip on no event
+ if (IS_NOEVENT(record->event)) break;
+ // check if keyrecord is mousekey
+ if (is_mouse_record(keycode, record)) {
+ auto_mouse_keyevent(record->event.pressed);
+ } else if (!is_auto_mouse_active()) {
+ // all non-mousekey presses restart delay timer and reset status
+ auto_mouse_reset_trigger(record->event.pressed);
+ }
+ }
+ if (auto_mouse_context.status.mouse_key_tracker < 0) {
+ auto_mouse_context.status.mouse_key_tracker = 0;
+ dprintf("key tracker error (<0) \n");
+ }
+ return true;
+}
+
+/**
+ * @brief Local function to handle checking if a keycode is a mouse button
+ *
+ * Starts code stack for checking keyrecord if defined as mousekey
+ *
+ * @params keycode[in] uint16_t
+ * @params record[in] keyrecord_t pointer
+ * @return bool true: keyrecord is mousekey false: keyrecord is not mousekey
+ */
+static bool is_mouse_record(uint16_t keycode, keyrecord_t* record) {
+ // allow for keyboard to hook in and override if need be
+ if (is_mouse_record_kb(keycode, record) || IS_MOUSEKEY(keycode)) return true;
+ return false;
+}
+
+/**
+ * @brief Weakly defined keyboard level callback for adding keyrecords as mouse keys
+ *
+ * Meant for redefinition at keyboard level and should return is_mouse_record_user by default at end of function
+ *
+ * @params keycode[in] uint16_t
+ * @params record[in] keyrecord_t pointer
+ * @return bool true: keyrecord is defined as mouse key false: keyrecord is not defined as mouse key
+ */
+__attribute__((weak)) bool is_mouse_record_kb(uint16_t keycode, keyrecord_t* record) {
+ return is_mouse_record_user(keycode, record);
+}
+
+/**
+ * @brief Weakly defined keymap/user level callback for adding keyrecords as mouse keys
+ *
+ * Meant for redefinition at keymap/user level and should return false by default at end of function
+ *
+ * @params keycode[in] uint16_t
+ * @params record[in] keyrecord_t pointer
+ * @return bool true: keyrecord is defined as mouse key false: keyrecord is not defined as mouse key
+ */
+__attribute__((weak)) bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record) {
+ return false;
+}
+
+#endif // POINTING_DEVICE_AUTO_MOUSE_ENABLE
diff --git a/quantum/pointing_device/pointing_device_auto_mouse.h b/quantum/pointing_device/pointing_device_auto_mouse.h
new file mode 100644
index 0000000000..0f26af79e6
--- /dev/null
+++ b/quantum/pointing_device/pointing_device_auto_mouse.h
@@ -0,0 +1,87 @@
+/* Copyright 2022 Alabastard
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <string.h>
+
+#include "quantum.h"
+#include "pointing_device.h"
+#include "print.h"
+
+/* check settings and set defaults */
+#ifndef POINTING_DEVICE_AUTO_MOUSE_ENABLE
+# error "POINTING_DEVICE_AUTO_MOUSE_ENABLE not defined! check config settings"
+#endif
+
+#ifndef AUTO_MOUSE_DEFAULT_LAYER
+# define AUTO_MOUSE_DEFAULT_LAYER 1
+#endif
+#ifndef AUTO_MOUSE_TIME
+# define AUTO_MOUSE_TIME 650
+#endif
+#ifndef AUTO_MOUSE_DELAY
+# define AUTO_MOUSE_DELAY GET_TAPPING_TERM(KC_MS_BTN1, &(keyrecord_t){})
+#endif
+#ifndef AUTO_MOUSE_DEBOUNCE
+# define AUTO_MOUSE_DEBOUNCE 25
+#endif
+
+/* data structure */
+typedef struct {
+ struct {
+ bool is_enabled;
+ uint8_t layer;
+ } config;
+ struct {
+ uint16_t active;
+ uint16_t delay;
+ } timer;
+ struct {
+ bool is_activated;
+ bool is_toggled;
+ int8_t mouse_key_tracker;
+ } status;
+} auto_mouse_context_t;
+
+/* ----------Set up and control------------------------------------------------------------------------------ */
+void set_auto_mouse_enable(bool enable); // enable/disable auto mouse feature
+bool get_auto_mouse_enable(void); // get auto_mouse_enable
+void set_auto_mouse_layer(uint8_t layer); // set target layer by index
+uint8_t get_auto_mouse_layer(void); // get target layer index
+void auto_mouse_layer_off(void); // disable target layer if appropriate (DO NOT USE in layer_state_set stack!!)
+layer_state_t remove_auto_mouse_layer(layer_state_t state, bool force); // remove auto mouse target layer from state if appropriate (can be forced)
+
+/* ----------For custom pointing device activation----------------------------------------------------------- */
+bool auto_mouse_activation(report_mouse_t mouse_report); // handles pointing device trigger conditions for target layer activation (overwritable)
+
+/* ----------Handling keyevents------------------------------------------------------------------------------ */
+void auto_mouse_keyevent(bool pressed); // trigger auto mouse keyevent: mouse_keytracker increment/decrement on press/release
+void auto_mouse_reset_trigger(bool pressed); // trigger non mouse keyevent: reset and start delay timer (DO NOT USE in layer_state_set stack!!)
+void auto_mouse_toggle(void); // toggle mouse layer flag disables mouse layer deactivation while on (meant for tap toggle or toggle of target)
+bool get_auto_mouse_toggle(void); // get toggle mouse layer flag value
+
+/* ----------Callbacks for adding keycodes to mouse record checking------------------------------------------ */
+bool is_mouse_record_kb(uint16_t keycode, keyrecord_t* record);
+bool is_mouse_record_user(uint16_t keycode, keyrecord_t* record);
+
+/* ----------Core functions (only used in custom pointing devices or key processing)------------------------- */
+void pointing_device_task_auto_mouse(report_mouse_t mouse_report); // add to pointing_device_task_*
+bool process_auto_mouse(uint16_t keycode, keyrecord_t* record); // add to process_record_*
+
+/* ----------Macros/Aliases---------------------------------------------------------------------------------- */
+#define AUTO_MOUSE_TARGET_LAYER get_auto_mouse_layer()
+#define AUTO_MOUSE_ENABLED get_auto_mouse_enable()
diff --git a/quantum/pointing_device/pointing_device_drivers.c b/quantum/pointing_device/pointing_device_drivers.c
index b96f8ff4b3..172c9f36d7 100644
--- a/quantum/pointing_device/pointing_device_drivers.c
+++ b/quantum/pointing_device/pointing_device_drivers.c
@@ -17,6 +17,7 @@
*/
#include "pointing_device.h"
+#include "pointing_device_internal.h"
#include "debug.h"
#include "wait.h"
#include "timer.h"
@@ -32,10 +33,7 @@ report_mouse_t adns5050_get_report(report_mouse_t mouse_report) {
report_adns5050_t data = adns5050_read_burst();
if (data.dx != 0 || data.dy != 0) {
-# ifdef CONSOLE_ENABLE
- if (debug_mouse) dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
-# endif
-
+ pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
mouse_report.x = (mouse_xy_report_t)data.dx;
mouse_report.y = (mouse_xy_report_t)data.dy;
}
@@ -76,9 +74,7 @@ const pointing_device_driver_t pointing_device_driver = {
report_mouse_t analog_joystick_get_report(report_mouse_t mouse_report) {
report_analog_joystick_t data = analog_joystick_read();
-# ifdef CONSOLE_ENABLE
- if (debug_mouse) dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
-# endif
+ pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
mouse_report.x = data.x;
mouse_report.y = data.y;
@@ -117,12 +113,24 @@ void cirque_pinnacle_configure_cursor_glide(float trigger_px) {
# endif
# if CIRQUE_PINNACLE_POSITION_MODE
+
+# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
+static bool is_touch_down;
+
+bool auto_mouse_activation(report_mouse_t mouse_report) {
+ return is_touch_down || mouse_report.x != 0 || mouse_report.y != 0 || mouse_report.h != 0 || mouse_report.v != 0 || mouse_report.buttons;
+}
+# endif
+
report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
pinnacle_data_t touchData = cirque_pinnacle_read_data();
mouse_xy_report_t report_x = 0, report_y = 0;
static uint16_t x = 0, y = 0;
+# if defined(CIRQUE_PINNACLE_TAP_ENABLE)
+ mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1);
+# endif
# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
- cursor_glide_t glide_report = {0};
+ cursor_glide_t glide_report = {0};
if (cursor_glide_enable) {
glide_report = cursor_glide_check(&glide);
@@ -140,10 +148,12 @@ report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
return mouse_report;
}
-# if CONSOLE_ENABLE
- if (debug_mouse && touchData.touchDown) {
- dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue);
+ if (touchData.touchDown) {
+ pd_dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue);
}
+
+# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
+ is_touch_down = touchData.touchDown;
# endif
// Scale coordinates to arbitrary X, Y resolution
@@ -227,9 +237,7 @@ const pointing_device_driver_t pointing_device_driver = {
report_mouse_t paw3204_get_report(report_mouse_t mouse_report) {
report_paw3204_t data = paw3204_read();
if (data.isMotion) {
-# ifdef CONSOLE_ENABLE
- dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
-# endif
+ pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
mouse_report.x = data.x;
mouse_report.y = data.y;
@@ -329,7 +337,7 @@ report_mouse_t pmw33xx_get_report(report_mouse_t mouse_report) {
if (!in_motion) {
in_motion = true;
- dprintf("PWM3360 (0): starting motion\n");
+ pd_dprintf("PWM3360 (0): starting motion\n");
}
mouse_report.x = CONSTRAIN_HID_XY(report.delta_x);
diff --git a/quantum/pointing_device_internal.h b/quantum/pointing_device_internal.h
new file mode 100644
index 0000000000..ef649407ca
--- /dev/null
+++ b/quantum/pointing_device_internal.h
@@ -0,0 +1,14 @@
+// Copyright 2022 Stefan Kerkmann
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#ifdef POINTING_DEVICE_DEBUG
+# include "debug.h"
+# include "print.h"
+# define pd_dprintf(...) dprintf(__VA_ARGS__)
+#else
+# define pd_dprintf(...) \
+ do { \
+ } while (0)
+#endif
diff --git a/quantum/process_keycode/autocorrect_data_default.h b/quantum/process_keycode/autocorrect_data_default.h
new file mode 100644
index 0000000000..bfc29666df
--- /dev/null
+++ b/quantum/process_keycode/autocorrect_data_default.h
@@ -0,0 +1,85 @@
+// Generated code.
+
+// Autocorrection dictionary (70 entries):
+// :guage -> gauge
+// :the:the: -> the
+// :thier -> their
+// :ture -> true
+// accomodate -> accommodate
+// acommodate -> accommodate
+// aparent -> apparent
+// aparrent -> apparent
+// apparant -> apparent
+// apparrent -> apparent
+// aquire -> acquire
+// becuase -> because
+// cauhgt -> caught
+// cheif -> chief
+// choosen -> chosen
+// cieling -> ceiling
+// collegue -> colleague
+// concensus -> consensus
+// contians -> contains
+// cosnt -> const
+// dervied -> derived
+// fales -> false
+// fasle -> false
+// fitler -> filter
+// flase -> false
+// foward -> forward
+// frequecy -> frequency
+// gaurantee -> guarantee
+// guaratee -> guarantee
+// heigth -> height
+// heirarchy -> hierarchy
+// inclued -> include
+// interator -> iterator
+// intput -> input
+// invliad -> invalid
+// lenght -> length
+// liasion -> liaison
+// libary -> library
+// listner -> listener
+// looses: -> loses
+// looup -> lookup
+// manefist -> manifest
+// namesapce -> namespace
+// namespcae -> namespace
+// occassion -> occasion
+// occured -> occurred
+// ouptut -> output
+// ouput -> output
+// overide -> override
+// postion -> position
+// priviledge -> privilege
+// psuedo -> pseudo
+// recieve -> receive
+// refered -> referred
+// relevent -> relevant
+// repitition -> repetition
+// retrun -> return
+// retun -> return
+// reuslt -> result
+// reutrn -> return
+// saftey -> safety
+// seperate -> separate
+// singed -> signed
+// stirng -> string
+// strign -> string
+// swithc -> switch
+// swtich -> switch
+// thresold -> threshold
+// udpate -> update
+// widht -> width
+
+#define AUTOCORRECT_MIN_LENGTH 5 // ":ture"
+#define AUTOCORRECT_MAX_LENGTH 10 // "accomodate"
+
+#define DICTIONARY_SIZE 1104
+
+static const uint8_t autocorrect_data[DICTIONARY_SIZE] PROGMEM = {108, 43, 0, 6, 71, 0, 7, 81, 0, 8, 199, 0, 9, 240, 1, 10, 250, 1, 11, 26, 2, 17, 53, 2, 18, 190, 2, 19, 202, 2, 21, 212, 2, 22, 20, 3, 23, 67, 3, 28, 16, 4, 0, 72, 50, 0, 22, 60, 0, 0, 11, 23, 44, 8, 11, 23, 44, 0, 132, 0, 8, 22, 18, 18, 15, 0, 132, 115, 101, 115, 0, 11, 23, 12, 26, 22, 0, 129, 99, 104, 0, 68, 94, 0, 8, 106, 0, 15, 174, 0, 21, 187, 0, 0, 12, 15, 25, 17, 12, 0, 131, 97, 108, 105, 100, 0, 74, 119, 0, 12, 129, 0, 21, 140, 0, 24, 165, 0, 0, 17, 12, 22, 0, 131, 103, 110, 101, 100, 0, 25, 21, 8, 7, 0, 131, 105, 118, 101, 100, 0, 72, 147, 0, 24, 156, 0, 0, 9, 8, 21, 0, 129, 114, 101, 100, 0, 6, 6, 18, 0, 129, 114, 101, 100, 0, 15, 6, 17, 12, 0, 129, 100, 101, 0, 18, 22, 8, 21, 11, 23, 0, 130, 104, 111,
+ 108, 100, 0, 4, 26, 18, 9, 0, 131, 114, 119, 97, 114, 100, 0, 68, 233, 0, 6, 246, 0, 7, 4, 1, 8, 16, 1, 10, 52, 1, 15, 81, 1, 21, 90, 1, 22, 117, 1, 23, 144, 1, 24, 215, 1, 25, 228, 1, 0, 6, 19, 22, 8, 16, 4, 17, 0, 130, 97, 99, 101, 0, 19, 4, 22, 8, 16, 4, 17, 0, 131, 112, 97, 99, 101, 0, 12, 21, 8, 25, 18, 0, 130, 114, 105, 100, 101, 0, 23, 0, 68, 25, 1, 17, 36, 1, 0, 21, 4, 24, 10, 0, 130, 110, 116, 101, 101, 0, 4, 21, 24, 4, 10, 0, 135, 117, 97, 114, 97, 110, 116, 101, 101, 0, 68, 59, 1, 7, 69, 1, 0, 24, 10, 44, 0, 131, 97, 117, 103, 101, 0, 8, 15, 12, 25, 12, 21, 19, 0, 130, 103, 101, 0, 22, 4, 9, 0, 130, 108, 115, 101, 0, 76, 97, 1, 24, 109, 1, 0, 24, 20, 4, 0, 132, 99, 113, 117, 105, 114, 101, 0, 23, 44, 0,
+ 130, 114, 117, 101, 0, 4, 0, 79, 126, 1, 24, 134, 1, 0, 9, 0, 131, 97, 108, 115, 101, 0, 6, 8, 5, 0, 131, 97, 117, 115, 101, 0, 4, 0, 71, 156, 1, 19, 193, 1, 21, 203, 1, 0, 18, 16, 0, 80, 166, 1, 18, 181, 1, 0, 18, 6, 4, 0, 135, 99, 111, 109, 109, 111, 100, 97, 116, 101, 0, 6, 6, 4, 0, 132, 109, 111, 100, 97, 116, 101, 0, 7, 24, 0, 132, 112, 100, 97, 116, 101, 0, 8, 19, 8, 22, 0, 132, 97, 114, 97, 116, 101, 0, 10, 8, 15, 15, 18, 6, 0, 130, 97, 103, 117, 101, 0, 8, 12, 6, 8, 21, 0, 131, 101, 105, 118, 101, 0, 12, 8, 11, 6, 0, 130, 105, 101, 102, 0, 17, 0, 76, 3, 2, 21, 16, 2, 0, 15, 8, 12, 6, 0, 133, 101, 105, 108, 105, 110, 103, 0, 12, 23, 22, 0, 131, 114, 105, 110, 103, 0, 70, 33, 2, 23, 44, 2, 0, 12, 23, 26, 22, 0, 131, 105,
+ 116, 99, 104, 0, 10, 12, 8, 11, 0, 129, 104, 116, 0, 72, 69, 2, 10, 80, 2, 18, 89, 2, 21, 156, 2, 24, 167, 2, 0, 22, 18, 18, 11, 6, 0, 131, 115, 101, 110, 0, 12, 21, 23, 22, 0, 129, 110, 103, 0, 12, 0, 86, 98, 2, 23, 124, 2, 0, 68, 105, 2, 22, 114, 2, 0, 12, 15, 0, 131, 105, 115, 111, 110, 0, 4, 6, 6, 18, 0, 131, 105, 111, 110, 0, 76, 131, 2, 22, 146, 2, 0, 23, 12, 19, 8, 21, 0, 134, 101, 116, 105, 116, 105, 111, 110, 0, 18, 19, 0, 131, 105, 116, 105, 111, 110, 0, 23, 24, 8, 21, 0, 131, 116, 117, 114, 110, 0, 85, 174, 2, 23, 183, 2, 0, 23, 8, 21, 0, 130, 117, 114, 110, 0, 8, 21, 0, 128, 114, 110, 0, 7, 8, 24, 22, 19, 0, 131, 101, 117, 100, 111, 0, 24, 18, 18, 15, 0, 129, 107, 117, 112, 0, 72, 219, 2, 18, 3, 3, 0, 76, 229, 2, 15, 238,
+ 2, 17, 248, 2, 0, 11, 23, 44, 0, 130, 101, 105, 114, 0, 23, 12, 9, 0, 131, 108, 116, 101, 114, 0, 23, 22, 12, 15, 0, 130, 101, 110, 101, 114, 0, 23, 4, 21, 8, 23, 17, 12, 0, 135, 116, 101, 114, 97, 116, 111, 114, 0, 72, 30, 3, 17, 38, 3, 24, 51, 3, 0, 15, 4, 9, 0, 129, 115, 101, 0, 4, 12, 23, 17, 18, 6, 0, 131, 97, 105, 110, 115, 0, 22, 17, 8, 6, 17, 18, 6, 0, 133, 115, 101, 110, 115, 117, 115, 0, 74, 86, 3, 11, 96, 3, 15, 118, 3, 17, 129, 3, 22, 218, 3, 24, 232, 3, 0, 11, 24, 4, 6, 0, 130, 103, 104, 116, 0, 71, 103, 3, 10, 110, 3, 0, 12, 26, 0, 129, 116, 104, 0, 17, 8, 15, 0, 129, 116, 104, 0, 22, 24, 8, 21, 0, 131, 115, 117, 108, 116, 0, 68, 139, 3, 8, 150, 3, 22, 210, 3, 0, 21, 4, 19, 19, 4, 0, 130, 101, 110, 116, 0, 85, 157,
+ 3, 25, 200, 3, 0, 68, 164, 3, 21, 175, 3, 0, 19, 4, 0, 132, 112, 97, 114, 101, 110, 116, 0, 4, 19, 0, 68, 185, 3, 19, 193, 3, 0, 133, 112, 97, 114, 101, 110, 116, 0, 4, 0, 131, 101, 110, 116, 0, 8, 15, 8, 21, 0, 130, 97, 110, 116, 0, 18, 6, 0, 130, 110, 115, 116, 0, 12, 9, 8, 17, 4, 16, 0, 132, 105, 102, 101, 115, 116, 0, 83, 239, 3, 23, 6, 4, 0, 87, 246, 3, 24, 254, 3, 0, 17, 12, 0, 131, 112, 117, 116, 0, 18, 0, 130, 116, 112, 117, 116, 0, 19, 24, 18, 0, 131, 116, 112, 117, 116, 0, 70, 29, 4, 8, 41, 4, 11, 51, 4, 21, 69, 4, 0, 8, 24, 20, 8, 21, 9, 0, 129, 110, 99, 121, 0, 23, 9, 4, 22, 0, 130, 101, 116, 121, 0, 6, 21, 4, 21, 12, 8, 11, 0, 135, 105, 101, 114, 97, 114, 99, 104, 121, 0, 4, 5, 12, 15, 0, 130, 114, 97, 114, 121, 0};
diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c
index 3ff188ba7e..35d4851ee5 100644
--- a/quantum/process_keycode/process_auto_shift.c
+++ b/quantum/process_keycode/process_auto_shift.c
@@ -17,7 +17,6 @@
#ifdef AUTO_SHIFT_ENABLE
# include <stdbool.h>
-# include <stdio.h>
# include "process_auto_shift.h"
# ifndef AUTO_SHIFT_DISABLED_AT_STARTUP
@@ -331,11 +330,12 @@ void autoshift_disable(void) {
# ifndef AUTO_SHIFT_NO_SETUP
void autoshift_timer_report(void) {
# ifdef SEND_STRING_ENABLE
- char display[8];
-
- snprintf(display, 8, "\n%d\n", autoshift_timeout);
-
- send_string((const char *)display);
+ const char *autoshift_timeout_str = get_u16_str(autoshift_timeout, ' ');
+ // Skip padding spaces
+ while (*autoshift_timeout_str == ' ') {
+ autoshift_timeout_str++;
+ }
+ send_string(autoshift_timeout_str);
# endif
}
# endif
@@ -375,24 +375,24 @@ bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
}
switch (keycode) {
- case KC_ASTG:
+ case AS_TOGG:
autoshift_toggle();
break;
- case KC_ASON:
+ case AS_ON:
autoshift_enable();
break;
- case KC_ASOFF:
+ case AS_OFF:
autoshift_disable();
break;
# ifndef AUTO_SHIFT_NO_SETUP
- case KC_ASUP:
+ case AS_UP:
autoshift_timeout += 5;
break;
- case KC_ASDN:
+ case AS_DOWN:
autoshift_timeout -= 5;
break;
- case KC_ASRP:
+ case AS_RPT:
autoshift_timer_report();
break;
# endif
diff --git a/quantum/process_keycode/process_autocorrect.c b/quantum/process_keycode/process_autocorrect.c
new file mode 100644
index 0000000000..e3fcbc34ae
--- /dev/null
+++ b/quantum/process_keycode/process_autocorrect.c
@@ -0,0 +1,292 @@
+// Copyright 2021 Google LLC
+// Copyright 2021 @filterpaper
+// SPDX-License-Identifier: Apache-2.0
+// Original source: https://getreuer.info/posts/keyboards/autocorrection
+
+#include "process_autocorrect.h"
+#include <string.h>
+#include "keycode_config.h"
+
+#if __has_include("autocorrect_data.h")
+# include "autocorrect_data.h"
+#else
+# pragma message "Autocorrect is using the default library."
+# include "autocorrect_data_default.h"
+#endif
+
+static uint8_t typo_buffer[AUTOCORRECT_MAX_LENGTH] = {KC_SPC};
+static uint8_t typo_buffer_size = 1;
+
+/**
+ * @brief function for querying the enabled state of autocorrect
+ *
+ * @return true if enabled
+ * @return false if disabled
+ */
+bool autocorrect_is_enabled(void) {
+ return keymap_config.autocorrect_enable;
+}
+
+/**
+ * @brief Enables autocorrect and saves state to eeprom
+ *
+ */
+void autocorrect_enable(void) {
+ keymap_config.autocorrect_enable = true;
+ eeconfig_update_keymap(keymap_config.raw);
+}
+
+/**
+ * @brief Disables autocorrect and saves state to eeprom
+ *
+ */
+void autocorrect_disable(void) {
+ keymap_config.autocorrect_enable = false;
+ typo_buffer_size = 0;
+ eeconfig_update_keymap(keymap_config.raw);
+}
+
+/**
+ * @brief Toggles autocorrect's status and save state to eeprom
+ *
+ */
+void autocorrect_toggle(void) {
+ keymap_config.autocorrect_enable = !keymap_config.autocorrect_enable;
+ typo_buffer_size = 0;
+ eeconfig_update_keymap(keymap_config.raw);
+}
+
+/**
+ * @brief handler for determining if autocorrect should process keypress
+ *
+ * @param keycode Keycode registered by matrix press, per keymap
+ * @param record keyrecord_t structure
+ * @param typo_buffer_size passed along to allow resetting of autocorrect buffer
+ * @param mods allow processing of mod status
+ * @return true Allow autocorection
+ * @return false Stop processing and escape from autocorrect.
+ */
+__attribute__((weak)) bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods) {
+ // See quantum_keycodes.h for reference on these matched ranges.
+ switch (*keycode) {
+ // Exclude these keycodes from processing.
+ case KC_LSFT:
+ case KC_RSFT:
+ case KC_CAPS:
+ case QK_TO ... QK_TO_MAX:
+ case QK_MOMENTARY ... QK_MOMENTARY_MAX:
+ case QK_DEF_LAYER ... QK_DEF_LAYER_MAX:
+ case QK_TOGGLE_LAYER ... QK_TOGGLE_LAYER_MAX:
+ case QK_ONE_SHOT_LAYER ... QK_ONE_SHOT_LAYER_MAX:
+ case QK_LAYER_TAP_TOGGLE ... QK_LAYER_TAP_TOGGLE_MAX:
+ case QK_LAYER_MOD ... QK_LAYER_MOD_MAX:
+ case QK_ONE_SHOT_MOD ... QK_ONE_SHOT_MOD_MAX:
+ return false;
+
+ // Mask for base keycode from shifted keys.
+ case QK_LSFT ... QK_LSFT + 255:
+ case QK_RSFT ... QK_RSFT + 255:
+ if (*keycode >= QK_LSFT && *keycode <= (QK_LSFT + 255)) {
+ *mods |= MOD_LSFT;
+ } else {
+ *mods |= MOD_RSFT;
+ }
+ *keycode &= 0xFF; // Get the basic keycode.
+ return true;
+#ifndef NO_ACTION_TAPPING
+ // Exclude tap-hold keys when they are held down
+ // and mask for base keycode when they are tapped.
+ case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
+# ifdef NO_ACTION_LAYER
+ // Exclude Layer Tap, if layers are disabled
+ // but action tapping is still enabled.
+ return false;
+# endif
+ case QK_MOD_TAP ... QK_MOD_TAP_MAX:
+ // Exclude hold keycode
+ if (!record->tap.count) {
+ return false;
+ }
+ *keycode &= 0xFF;
+ break;
+#else
+ case QK_MOD_TAP ... QK_MOD_TAP_MAX:
+ case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
+ // Exclude if disabled
+ return false;
+#endif
+ // Exclude swap hands keys when they are held down
+ // and mask for base keycode when they are tapped.
+ case QK_SWAP_HANDS ... QK_SWAP_HANDS_MAX:
+#ifdef SWAP_HANDS_ENABLE
+ if (*keycode >= 0x56F0 || !record->tap.count) {
+ return false;
+ }
+ *keycode &= 0xFF;
+ break;
+#else
+ // Exclude if disabled
+ return false;
+#endif
+ }
+
+ // Disable autocorrect while a mod other than shift is active.
+ if ((*mods & ~MOD_MASK_SHIFT) != 0) {
+ *typo_buffer_size = 0;
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * @brief handling for when autocorrection has been triggered
+ *
+ * @param backspaces number of characters to remove
+ * @param str pointer to PROGMEM string to replace mistyped seletion with
+ * @return true apply correction
+ * @return false user handled replacement
+ */
+__attribute__((weak)) bool apply_autocorrect(uint8_t backspaces, const char *str) {
+ return true;
+}
+
+/**
+ * @brief Process handler for autocorrect feature
+ *
+ * @param keycode Keycode registered by matrix press, per keymap
+ * @param record keyrecord_t structure
+ * @return true Continue processing keycodes, and send to host
+ * @return false Stop processing keycodes, and don't send to host
+ */
+bool process_autocorrect(uint16_t keycode, keyrecord_t *record) {
+ uint8_t mods = get_mods();
+#ifndef NO_ACTION_ONESHOT
+ mods |= get_oneshot_mods();
+#endif
+
+ if ((keycode >= QK_AUTOCORRECT_ON && keycode <= QK_AUTOCORRECT_TOGGLE) && record->event.pressed) {
+ if (keycode == QK_AUTOCORRECT_ON) {
+ autocorrect_enable();
+ } else if (keycode == QK_AUTOCORRECT_OFF) {
+ autocorrect_disable();
+ } else if (keycode == QK_AUTOCORRECT_TOGGLE) {
+ autocorrect_toggle();
+ } else {
+ return true;
+ }
+
+ return false;
+ }
+
+ if (!keymap_config.autocorrect_enable) {
+ typo_buffer_size = 0;
+ return true;
+ }
+
+ if (!record->event.pressed) {
+ return true;
+ }
+
+ // autocorrect keycode verification and extraction
+ if (!process_autocorrect_user(&keycode, record, &typo_buffer_size, &mods)) {
+ return true;
+ }
+
+ // keycode buffer check
+ switch (keycode) {
+ case KC_A ... KC_Z:
+ // process normally
+ break;
+ case KC_1 ... KC_0:
+ case KC_TAB ... KC_SEMICOLON:
+ case KC_GRAVE ... KC_SLASH:
+ // Set a word boundary if space, period, digit, etc. is pressed.
+ keycode = KC_SPC;
+ break;
+ case KC_ENTER:
+ // Behave more conservatively for the enter key. Reset, so that enter
+ // can't be used on a word ending.
+ typo_buffer_size = 0;
+ keycode = KC_SPC;
+ break;
+ case KC_BSPC:
+ // Remove last character from the buffer.
+ if (typo_buffer_size > 0) {
+ --typo_buffer_size;
+ }
+ return true;
+ case KC_QUOTE:
+ // Treat " (shifted ') as a word boundary.
+ if ((mods & MOD_MASK_SHIFT) != 0) {
+ keycode = KC_SPC;
+ }
+ break;
+ default:
+ // Clear state if some other non-alpha key is pressed.
+ typo_buffer_size = 0;
+ return true;
+ }
+
+ // Rotate oldest character if buffer is full.
+ if (typo_buffer_size >= AUTOCORRECT_MAX_LENGTH) {
+ memmove(typo_buffer, typo_buffer + 1, AUTOCORRECT_MAX_LENGTH - 1);
+ typo_buffer_size = AUTOCORRECT_MAX_LENGTH - 1;
+ }
+
+ // Append `keycode` to buffer.
+ typo_buffer[typo_buffer_size++] = keycode;
+ // Return if buffer is smaller than the shortest word.
+ if (typo_buffer_size < AUTOCORRECT_MIN_LENGTH) {
+ return true;
+ }
+
+ // Check for typo in buffer using a trie stored in `autocorrect_data`.
+ uint16_t state = 0;
+ uint8_t code = pgm_read_byte(autocorrect_data + state);
+ for (int8_t i = typo_buffer_size - 1; i >= 0; --i) {
+ uint8_t const key_i = typo_buffer[i];
+
+ if (code & 64) { // Check for match in node with multiple children.
+ code &= 63;
+ for (; code != key_i; code = pgm_read_byte(autocorrect_data + (state += 3))) {
+ if (!code) return true;
+ }
+ // Follow link to child node.
+ state = (pgm_read_byte(autocorrect_data + state + 1) | pgm_read_byte(autocorrect_data + state + 2) << 8);
+ // Check for match in node with single child.
+ } else if (code != key_i) {
+ return true;
+ } else if (!(code = pgm_read_byte(autocorrect_data + (++state)))) {
+ ++state;
+ }
+
+ // Stop if `state` becomes an invalid index. This should not normally
+ // happen, it is a safeguard in case of a bug, data corruption, etc.
+ if (state >= DICTIONARY_SIZE) {
+ return true;
+ }
+
+ code = pgm_read_byte(autocorrect_data + state);
+
+ if (code & 128) { // A typo was found! Apply autocorrect.
+ const uint8_t backspaces = (code & 63) + !record->event.pressed;
+ if (apply_autocorrect(backspaces, (char const *)(autocorrect_data + state + 1))) {
+ for (uint8_t i = 0; i < backspaces; ++i) {
+ tap_code(KC_BSPC);
+ }
+ send_string_P((char const *)(autocorrect_data + state + 1));
+ }
+
+ if (keycode == KC_SPC) {
+ typo_buffer[0] = KC_SPC;
+ typo_buffer_size = 1;
+ return true;
+ } else {
+ typo_buffer_size = 0;
+ return false;
+ }
+ }
+ }
+ return true;
+}
diff --git a/quantum/process_keycode/process_autocorrect.h b/quantum/process_keycode/process_autocorrect.h
new file mode 100644
index 0000000000..c7596107e5
--- /dev/null
+++ b/quantum/process_keycode/process_autocorrect.h
@@ -0,0 +1,17 @@
+// Copyright 2021 Google LLC
+// Copyright 2021 @filterpaper
+// SPDX-License-Identifier: Apache-2.0
+// Original source: https://getreuer.info/posts/keyboards/autocorrection
+
+#pragma once
+
+#include "quantum.h"
+
+bool process_autocorrect(uint16_t keycode, keyrecord_t *record);
+bool process_autocorrect_user(uint16_t *keycode, keyrecord_t *record, uint8_t *typo_buffer_size, uint8_t *mods);
+bool apply_autocorrect(uint8_t backspaces, const char *str);
+
+bool autocorrect_is_enabled(void);
+void autocorrect_enable(void);
+void autocorrect_disable(void);
+void autocorrect_toggle(void);
diff --git a/quantum/process_keycode/process_caps_word.c b/quantum/process_keycode/process_caps_word.c
index 1b9583196d..7a83f7bf49 100644
--- a/quantum/process_keycode/process_caps_word.c
+++ b/quantum/process_keycode/process_caps_word.c
@@ -15,7 +15,7 @@
#include "process_caps_word.h"
bool process_caps_word(uint16_t keycode, keyrecord_t* record) {
- if (keycode == CAPSWRD) { // Pressing CAPSWRD toggles Caps Word.
+ if (keycode == QK_CAPS_WORD_TOGGLE) {
if (record->event.pressed) {
caps_word_toggle();
}
diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c
index e5135e5a64..d8b089db16 100644
--- a/quantum/process_keycode/process_combo.c
+++ b/quantum/process_keycode/process_combo.c
@@ -531,17 +531,17 @@ bool process_combo(uint16_t keycode, keyrecord_t *record) {
bool is_combo_key = false;
bool no_combo_keys_pressed = true;
- if (keycode == CMB_ON && record->event.pressed) {
+ if (keycode == QK_COMBO_ON && record->event.pressed) {
combo_enable();
return true;
}
- if (keycode == CMB_OFF && record->event.pressed) {
+ if (keycode == QK_COMBO_OFF && record->event.pressed) {
combo_disable();
return true;
}
- if (keycode == CMB_TOG && record->event.pressed) {
+ if (keycode == QK_COMBO_TOGGLE && record->event.pressed) {
combo_toggle();
return true;
}
diff --git a/quantum/process_keycode/process_dynamic_macro.c b/quantum/process_keycode/process_dynamic_macro.c
index a7555fdd40..41207092a9 100644
--- a/quantum/process_keycode/process_dynamic_macro.c
+++ b/quantum/process_keycode/process_dynamic_macro.c
@@ -45,6 +45,10 @@ __attribute__((weak)) void dynamic_macro_record_end_user(int8_t direction) {
dynamic_macro_led_blink();
}
+__attribute__((weak)) bool dynamic_macro_valid_key_user(uint16_t keycode, keyrecord_t *record) {
+ return true;
+}
+
/* Convenience macros used for retrieving the debug info. All of them
* need a `direction` variable accessible at the call site.
*/
@@ -252,14 +256,16 @@ bool process_dynamic_macro(uint16_t keycode, keyrecord_t *record) {
return false;
#endif
default:
- /* Store the key in the macro buffer and process it normally. */
- switch (macro_id) {
- case 1:
- dynamic_macro_record_key(macro_buffer, &macro_pointer, r_macro_end, +1, record);
- break;
- case 2:
- dynamic_macro_record_key(r_macro_buffer, &macro_pointer, macro_end, -1, record);
- break;
+ if (dynamic_macro_valid_key_user(keycode, record)) {
+ /* Store the key in the macro buffer and process it normally. */
+ switch (macro_id) {
+ case 1:
+ dynamic_macro_record_key(macro_buffer, &macro_pointer, r_macro_end, +1, record);
+ break;
+ case 2:
+ dynamic_macro_record_key(r_macro_buffer, &macro_pointer, macro_end, -1, record);
+ break;
+ }
}
return true;
break;
diff --git a/quantum/process_keycode/process_joystick.c b/quantum/process_keycode/process_joystick.c
index e867606074..c4c6fb59a8 100644
--- a/quantum/process_keycode/process_joystick.c
+++ b/quantum/process_keycode/process_joystick.c
@@ -1,149 +1,31 @@
-#include "joystick.h"
-#include "process_joystick.h"
-
-#include "analog.h"
+/* Copyright 2022
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
-#include <string.h>
-#include <math.h>
+#include "process_joystick.h"
+#include "joystick.h"
bool process_joystick(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
- case JS_BUTTON0 ... JS_BUTTON_MAX:
+ case QK_JOYSTICK_BUTTON_MIN ... QK_JOYSTICK_BUTTON_MAX:
if (record->event.pressed) {
- register_joystick_button(keycode - JS_BUTTON0);
+ register_joystick_button(keycode - QK_JOYSTICK_BUTTON_MIN);
} else {
- unregister_joystick_button(keycode - JS_BUTTON0);
+ unregister_joystick_button(keycode - QK_JOYSTICK_BUTTON_MIN);
}
return false;
}
return true;
}
-
-__attribute__((weak)) void joystick_task(void) {
- if (process_joystick_analogread()) {
- joystick_flush();
- }
-}
-
-uint16_t savePinState(pin_t pin) {
-#ifdef __AVR__
- uint8_t pinNumber = pin & 0xF;
- return ((PORTx_ADDRESS(pin) >> pinNumber) & 0x1) << 1 | ((DDRx_ADDRESS(pin) >> pinNumber) & 0x1);
-#elif defined(PROTOCOL_CHIBIOS)
- /*
- The pin configuration is backed up in the following format :
- bit 15 9 8 7 6 5 4 3 2 1 0
- |unused|ODR|IDR|PUPDR|OSPEEDR|OTYPER|MODER|
- */
- return ((PAL_PORT(pin)->MODER >> (2 * PAL_PAD(pin))) & 0x3) | (((PAL_PORT(pin)->OTYPER >> (1 * PAL_PAD(pin))) & 0x1) << 2) | (((PAL_PORT(pin)->OSPEEDR >> (2 * PAL_PAD(pin))) & 0x3) << 3) | (((PAL_PORT(pin)->PUPDR >> (2 * PAL_PAD(pin))) & 0x3) << 5) | (((PAL_PORT(pin)->IDR >> (1 * PAL_PAD(pin))) & 0x1) << 7) | (((PAL_PORT(pin)->ODR >> (1 * PAL_PAD(pin))) & 0x1) << 8);
-#else
- return 0;
-#endif
-}
-
-void restorePinState(pin_t pin, uint16_t restoreState) {
-#if defined(PROTOCOL_LUFA)
- uint8_t pinNumber = pin & 0xF;
- PORTx_ADDRESS(pin) = (PORTx_ADDRESS(pin) & ~_BV(pinNumber)) | (((restoreState >> 1) & 0x1) << pinNumber);
- DDRx_ADDRESS(pin) = (DDRx_ADDRESS(pin) & ~_BV(pinNumber)) | ((restoreState & 0x1) << pinNumber);
-#elif defined(PROTOCOL_CHIBIOS)
- PAL_PORT(pin)->MODER = (PAL_PORT(pin)->MODER & ~(0x3 << (2 * PAL_PAD(pin)))) | (restoreState & 0x3) << (2 * PAL_PAD(pin));
- PAL_PORT(pin)->OTYPER = (PAL_PORT(pin)->OTYPER & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 2) & 0x1) << (1 * PAL_PAD(pin));
- PAL_PORT(pin)->OSPEEDR = (PAL_PORT(pin)->OSPEEDR & ~(0x3 << (2 * PAL_PAD(pin)))) | ((restoreState >> 3) & 0x3) << (2 * PAL_PAD(pin));
- PAL_PORT(pin)->PUPDR = (PAL_PORT(pin)->PUPDR & ~(0x3 << (2 * PAL_PAD(pin)))) | ((restoreState >> 5) & 0x3) << (2 * PAL_PAD(pin));
- PAL_PORT(pin)->IDR = (PAL_PORT(pin)->IDR & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 7) & 0x1) << (1 * PAL_PAD(pin));
- PAL_PORT(pin)->ODR = (PAL_PORT(pin)->ODR & ~(0x1 << (1 * PAL_PAD(pin)))) | ((restoreState >> 8) & 0x1) << (1 * PAL_PAD(pin));
-#else
- return;
-#endif
-}
-
-__attribute__((weak)) bool process_joystick_analogread() {
- return process_joystick_analogread_quantum();
-}
-
-bool process_joystick_analogread_quantum() {
-#if JOYSTICK_AXES_COUNT > 0
- for (int axis_index = 0; axis_index < JOYSTICK_AXES_COUNT; ++axis_index) {
- if (joystick_axes[axis_index].input_pin == JS_VIRTUAL_AXIS) {
- continue;
- }
-
- // save previous input pin status as well
- uint16_t inputSavedState = savePinState(joystick_axes[axis_index].input_pin);
-
- // disable pull-up resistor
- writePinLow(joystick_axes[axis_index].input_pin);
-
- // if pin was a pull-up input, we need to uncharge it by turning it low
- // before making it a low input
- setPinOutput(joystick_axes[axis_index].input_pin);
-
- wait_us(10);
-
- // save and apply output pin status
- uint16_t outputSavedState = 0;
- if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) {
- // save previous output pin status
- outputSavedState = savePinState(joystick_axes[axis_index].output_pin);
-
- setPinOutput(joystick_axes[axis_index].output_pin);
- writePinHigh(joystick_axes[axis_index].output_pin);
- }
-
- uint16_t groundSavedState = 0;
- if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) {
- // save previous output pin status
- groundSavedState = savePinState(joystick_axes[axis_index].ground_pin);
-
- setPinOutput(joystick_axes[axis_index].ground_pin);
- writePinLow(joystick_axes[axis_index].ground_pin);
- }
-
- wait_us(10);
-
- setPinInput(joystick_axes[axis_index].input_pin);
-
- wait_us(10);
-
-# if defined(ANALOG_JOYSTICK_ENABLE) && (defined(__AVR__) || defined(PROTOCOL_CHIBIOS))
- int16_t axis_val = analogReadPin(joystick_axes[axis_index].input_pin);
-# else
- // default to resting position
- int16_t axis_val = joystick_axes[axis_index].mid_digit;
-# endif
-
- // test the converted value against the lower range
- int32_t ref = joystick_axes[axis_index].mid_digit;
- int32_t range = joystick_axes[axis_index].min_digit;
- int32_t ranged_val = ((axis_val - ref) * -JOYSTICK_RESOLUTION) / (range - ref);
-
- if (ranged_val > 0) {
- // the value is in the higher range
- range = joystick_axes[axis_index].max_digit;
- ranged_val = ((axis_val - ref) * JOYSTICK_RESOLUTION) / (range - ref);
- }
-
- // clamp the result in the valid range
- ranged_val = ranged_val < -JOYSTICK_RESOLUTION ? -JOYSTICK_RESOLUTION : ranged_val;
- ranged_val = ranged_val > JOYSTICK_RESOLUTION ? JOYSTICK_RESOLUTION : ranged_val;
-
- if (ranged_val != joystick_status.axes[axis_index]) {
- joystick_status.axes[axis_index] = ranged_val;
- joystick_status.status |= JS_UPDATED;
- }
-
- // restore output, ground and input status
- if (joystick_axes[axis_index].output_pin != JS_VIRTUAL_AXIS) {
- restorePinState(joystick_axes[axis_index].output_pin, outputSavedState);
- }
- if (joystick_axes[axis_index].ground_pin != JS_VIRTUAL_AXIS) {
- restorePinState(joystick_axes[axis_index].ground_pin, groundSavedState);
- }
-
- restorePinState(joystick_axes[axis_index].input_pin, inputSavedState);
- }
-
-#endif
- return true;
-}
diff --git a/quantum/process_keycode/process_joystick.h b/quantum/process_keycode/process_joystick.h
index 7a8b82913a..1fb8757708 100644
--- a/quantum/process_keycode/process_joystick.h
+++ b/quantum/process_keycode/process_joystick.h
@@ -1,11 +1,22 @@
+/* Copyright 2022
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
#pragma once
#include <stdint.h>
#include "quantum.h"
bool process_joystick(uint16_t keycode, keyrecord_t *record);
-
-void joystick_task(void);
-
-bool process_joystick_analogread(void);
-bool process_joystick_analogread_quantum(void);
diff --git a/quantum/process_keycode/process_key_lock.c b/quantum/process_keycode/process_key_lock.c
index 941a2c5780..2542e32ec2 100644
--- a/quantum/process_keycode/process_key_lock.c
+++ b/quantum/process_keycode/process_key_lock.c
@@ -70,7 +70,7 @@ bool process_key_lock(uint16_t *keycode, keyrecord_t *record) {
// reset the state in our map and return false. When the user releases the
// key, the up event will no longer be masked and the OS will observe the
// released key.
- // 3. KC_LOCK was just pressed. In this case, we set up the state machine
+ // 3. QK_LOCK was just pressed. In this case, we set up the state machine
// to watch for the next key down event, and finish processing
// 4. The keycode is below 0xFF, and we are watching for new keys. In this case,
// we will send the key down event to the os, and set the key_state for that
@@ -95,20 +95,20 @@ bool process_key_lock(uint16_t *keycode, keyrecord_t *record) {
if (record->event.pressed) {
// Non-standard keycode, reset and return
- if (!(IS_STANDARD_KEYCODE(translated_keycode) || translated_keycode == KC_LOCK)) {
+ if (!(IS_STANDARD_KEYCODE(translated_keycode) || translated_keycode == QK_LOCK)) {
watching = false;
return true;
}
// If we're already watching, turn off the watch.
- if (translated_keycode == KC_LOCK) {
+ if (translated_keycode == QK_LOCK) {
watching = !watching;
return false;
}
if (IS_STANDARD_KEYCODE(translated_keycode)) {
// We check watching first. This is so that in the following scenario, we continue to
- // hold the key: KC_LOCK, KC_F, KC_LOCK, KC_F
+ // hold the key: QK_LOCK, KC_F, QK_LOCK, KC_F
// If we checked in reverse order, we'd end up holding the key pressed after the second
// KC_F press is registered, when the user likely meant to hold F
if (watching) {
diff --git a/quantum/process_keycode/process_key_override.c b/quantum/process_keycode/process_key_override.c
index ad9683d106..9c5abccd4f 100644
--- a/quantum/process_keycode/process_key_override.c
+++ b/quantum/process_keycode/process_key_override.c
@@ -406,15 +406,15 @@ bool process_key_override(const uint16_t keycode, const keyrecord_t *const recor
if (key_down) {
switch (keycode) {
- case KEY_OVERRIDE_TOGGLE:
+ case QK_KEY_OVERRIDE_TOGGLE:
key_override_toggle();
return false;
- case KEY_OVERRIDE_ON:
+ case QK_KEY_OVERRIDE_ON:
key_override_on();
return false;
- case KEY_OVERRIDE_OFF:
+ case QK_KEY_OVERRIDE_OFF:
key_override_off();
return false;
diff --git a/quantum/process_keycode/process_leader.c b/quantum/process_keycode/process_leader.c
index ae00b3227a..7e6f3ad73c 100644
--- a/quantum/process_keycode/process_leader.c
+++ b/quantum/process_keycode/process_leader.c
@@ -58,7 +58,7 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) {
keycode = keycode & 0xFF;
}
# endif // LEADER_KEY_STRICT_KEY_PROCESSING
- if (leader_sequence_size < (sizeof(leader_sequence) / sizeof(leader_sequence[0]))) {
+ if (leader_sequence_size < ARRAY_SIZE(leader_sequence)) {
leader_sequence[leader_sequence_size] = keycode;
leader_sequence_size++;
} else {
@@ -72,7 +72,7 @@ bool process_leader(uint16_t keycode, keyrecord_t *record) {
return false;
}
} else {
- if (keycode == KC_LEAD) {
+ if (keycode == QK_LEADER) {
qk_leader_start();
}
}
diff --git a/quantum/process_keycode/process_magic.c b/quantum/process_keycode/process_magic.c
index ae60f29bf5..50816c5261 100644
--- a/quantum/process_keycode/process_magic.c
+++ b/quantum/process_keycode/process_magic.c
@@ -45,6 +45,7 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) {
case MAGIC_SWAP_LCTL_LGUI ... MAGIC_EE_HANDS_RIGHT:
case MAGIC_TOGGLE_GUI:
case MAGIC_TOGGLE_CONTROL_CAPSLOCK:
+ case MAGIC_TOGGLE_BACKSLASH_BACKSPACE:
case MAGIC_SWAP_ESCAPE_CAPSLOCK ... MAGIC_TOGGLE_ESCAPE_CAPSLOCK:
/* keymap config */
keymap_config.raw = eeconfig_read_keymap();
@@ -163,6 +164,9 @@ bool process_magic(uint16_t keycode, keyrecord_t *record) {
}
#endif
break;
+ case MAGIC_TOGGLE_BACKSLASH_BACKSPACE:
+ keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
+ break;
case MAGIC_TOGGLE_NKRO:
clear_keyboard(); // clear first buffer to prevent stuck keys
keymap_config.nkro = !keymap_config.nkro;
diff --git a/quantum/process_keycode/process_programmable_button.c b/quantum/process_keycode/process_programmable_button.c
index c6e77faacc..d6a14e120c 100644
--- a/quantum/process_keycode/process_programmable_button.c
+++ b/quantum/process_keycode/process_programmable_button.c
@@ -19,12 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "programmable_button.h"
bool process_programmable_button(uint16_t keycode, keyrecord_t *record) {
- if (keycode >= PROGRAMMABLE_BUTTON_MIN && keycode <= PROGRAMMABLE_BUTTON_MAX) {
- uint8_t button = keycode - PROGRAMMABLE_BUTTON_MIN + 1;
+ if (keycode >= QK_PROGRAMMABLE_BUTTON_MIN && keycode <= QK_PROGRAMMABLE_BUTTON_MAX) {
+ uint8_t button = keycode - QK_PROGRAMMABLE_BUTTON_MIN + 1;
if (record->event.pressed) {
- programmable_button_on(button);
+ programmable_button_register(button);
} else {
- programmable_button_off(button);
+ programmable_button_unregister(button);
}
}
return true;
diff --git a/quantum/process_keycode/process_secure.c b/quantum/process_keycode/process_secure.c
index 3224104c99..894051fb33 100644
--- a/quantum/process_keycode/process_secure.c
+++ b/quantum/process_keycode/process_secure.c
@@ -23,19 +23,19 @@ bool preprocess_secure(uint16_t keycode, keyrecord_t *record) {
bool process_secure(uint16_t keycode, keyrecord_t *record) {
#ifndef SECURE_DISABLE_KEYCODES
if (!record->event.pressed) {
- if (keycode == SECURE_LOCK) {
+ if (keycode == QK_SECURE_LOCK) {
secure_lock();
return false;
}
- if (keycode == SECURE_UNLOCK) {
+ if (keycode == QK_SECURE_UNLOCK) {
secure_unlock();
return false;
}
- if (keycode == SECURE_TOGGLE) {
+ if (keycode == QK_SECURE_TOGGLE) {
secure_is_locked() ? secure_unlock() : secure_lock();
return false;
}
- if (keycode == SECURE_REQUEST) {
+ if (keycode == QK_SECURE_REQUEST) {
secure_request_unlock();
return false;
}
diff --git a/quantum/process_keycode/process_space_cadet.c b/quantum/process_keycode/process_space_cadet.c
index 0997e7b7f3..a62cd60a70 100644
--- a/quantum/process_keycode/process_space_cadet.c
+++ b/quantum/process_keycode/process_space_cadet.c
@@ -122,31 +122,31 @@ void perform_space_cadet(keyrecord_t *record, uint16_t sc_keycode, uint8_t holdM
bool process_space_cadet(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
- case KC_LSPO: {
+ case QK_SPACE_CADET_LEFT_SHIFT_PARENTHESIS_OPEN: {
perform_space_cadet(record, keycode, LSPO_KEYS);
return false;
}
- case KC_RSPC: {
+ case QK_SPACE_CADET_RIGHT_SHIFT_PARENTHESIS_CLOSE: {
perform_space_cadet(record, keycode, RSPC_KEYS);
return false;
}
- case KC_LCPO: {
+ case QK_SPACE_CADET_LEFT_CTRL_PARENTHESIS_OPEN: {
perform_space_cadet(record, keycode, LCPO_KEYS);
return false;
}
- case KC_RCPC: {
+ case QK_SPACE_CADET_RIGHT_CTRL_PARENTHESIS_CLOSE: {
perform_space_cadet(record, keycode, RCPC_KEYS);
return false;
}
- case KC_LAPO: {
+ case QK_SPACE_CADET_LEFT_ALT_PARENTHESIS_OPEN: {
perform_space_cadet(record, keycode, LAPO_KEYS);
return false;
}
- case KC_RAPC: {
+ case QK_SPACE_CADET_RIGHT_ALT_PARENTHESIS_CLOSE: {
perform_space_cadet(record, keycode, RAPC_KEYS);
return false;
}
- case KC_SFTENT: {
+ case QK_SPACE_CADET_RIGHT_SHIFT_ENTER: {
perform_space_cadet(record, keycode, SFTENT_KEYS);
return false;
}
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c
index 3270a1b000..6e8e596673 100644
--- a/quantum/process_keycode/process_tap_dance.c
+++ b/quantum/process_keycode/process_tap_dance.c
@@ -115,12 +115,12 @@ static inline void process_tap_dance_action_on_dance_finished(qk_tap_dance_actio
}
}
-void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
+bool preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
qk_tap_dance_action_t *action;
- if (!record->event.pressed) return;
+ if (!record->event.pressed) return false;
- if (!active_td || keycode == active_td) return;
+ if (!active_td || keycode == active_td) return false;
action = &tap_dance_actions[TD_INDEX(active_td)];
action->state.interrupted = true;
@@ -130,6 +130,12 @@ void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
// Tap dance actions can leave some weak mods active (e.g., if the tap dance is mapped to a keycode with
// modifiers), but these weak mods should not affect the keypress which interrupted the tap dance.
clear_weak_mods();
+
+ // Signal that a tap dance has been finished due to being interrupted,
+ // therefore the keymap lookup for the currently processed event needs to
+ // be repeated with the current layer state that might have been updated by
+ // the finished tap dance.
+ return true;
}
bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h
index d97900d96b..d6d6c136dc 100644
--- a/quantum/process_keycode/process_tap_dance.h
+++ b/quantum/process_keycode/process_tap_dance.h
@@ -81,7 +81,7 @@ void reset_tap_dance(qk_tap_dance_state_t *state);
/* To be used internally */
-void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record);
+bool preprocess_tap_dance(uint16_t keycode, keyrecord_t *record);
bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
void tap_dance_task(void);
diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c
index 6a8d8f0ff6..646471bc4d 100644
--- a/quantum/process_keycode/process_ucis.c
+++ b/quantum/process_keycode/process_ucis.c
@@ -15,6 +15,9 @@
*/
#include "process_ucis.h"
+#include "unicode.h"
+#include "keycode.h"
+#include "wait.h"
qk_ucis_state_t qk_ucis_state;
@@ -26,9 +29,7 @@ void qk_ucis_start(void) {
}
__attribute__((weak)) void qk_ucis_start_user(void) {
- unicode_input_start();
- register_hex(0x2328); // ⌨
- unicode_input_finish();
+ register_unicode(0x2328); // ⌨
}
__attribute__((weak)) void qk_ucis_success(uint8_t symbol_index) {}
@@ -51,10 +52,7 @@ static bool is_uni_seq(char *seq) {
__attribute__((weak)) void qk_ucis_symbol_fallback(void) {
for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
- uint8_t keycode = qk_ucis_state.codes[i];
- register_code(keycode);
- unregister_code(keycode);
- wait_ms(UNICODE_TYPE_DELAY);
+ tap_code(qk_ucis_state.codes[i]);
}
}
@@ -63,7 +61,6 @@ __attribute__((weak)) void qk_ucis_cancel(void) {}
void register_ucis(const uint32_t *code_points) {
for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) {
register_unicode(code_points[i]);
- wait_ms(UNICODE_TYPE_DELAY);
}
}
@@ -94,9 +91,7 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) {
case KC_ENTER:
case KC_ESCAPE:
for (uint8_t i = 0; i < qk_ucis_state.count; i++) {
- register_code(KC_BACKSPACE);
- unregister_code(KC_BACKSPACE);
- wait_ms(UNICODE_TYPE_DELAY);
+ tap_code(KC_BACKSPACE);
}
if (keycode == KC_ESCAPE) {
diff --git a/quantum/process_keycode/process_ucis.h b/quantum/process_keycode/process_ucis.h
index a667430bda..3de0707762 100644
--- a/quantum/process_keycode/process_ucis.h
+++ b/quantum/process_keycode/process_ucis.h
@@ -16,8 +16,10 @@
#pragma once
-#include "quantum.h"
-#include "process_unicode_common.h"
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "action.h"
#ifndef UCIS_MAX_SYMBOL_LENGTH
# define UCIS_MAX_SYMBOL_LENGTH 32
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c
index 18a1d8bc1f..99cc2f5f26 100644
--- a/quantum/process_keycode/process_unicode.c
+++ b/quantum/process_keycode/process_unicode.c
@@ -15,14 +15,14 @@
*/
#include "process_unicode.h"
-#include "action_util.h"
-#include "eeprom.h"
+#include "unicode.h"
+#include "quantum_keycodes.h"
bool process_unicode(uint16_t keycode, keyrecord_t *record) {
- if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX && record->event.pressed) {
- unicode_input_start();
- register_hex(keycode & 0x7FFF);
- unicode_input_finish();
+ if (record->event.pressed) {
+ if (keycode >= QK_UNICODE && keycode <= QK_UNICODE_MAX) {
+ register_unicode(keycode & 0x7FFF);
+ }
}
return true;
}
diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h
index 22765ad560..341bc8d861 100644
--- a/quantum/process_keycode/process_unicode.h
+++ b/quantum/process_keycode/process_unicode.h
@@ -16,6 +16,9 @@
#pragma once
-#include "process_unicode_common.h"
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "action.h"
bool process_unicode(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c
index 8de31c055c..bd5fc560f3 100644
--- a/quantum/process_keycode/process_unicode_common.c
+++ b/quantum/process_keycode/process_unicode_common.c
@@ -15,289 +15,17 @@
*/
#include "process_unicode_common.h"
-#include "eeprom.h"
-#include "utf8.h"
+#include "unicode.h"
+#include "action_util.h"
+#include "keycode.h"
-unicode_config_t unicode_config;
-uint8_t unicode_saved_mods;
-bool unicode_saved_caps_lock;
-bool unicode_saved_num_lock;
-
-#if UNICODE_SELECTED_MODES != -1
-static uint8_t selected[] = {UNICODE_SELECTED_MODES};
-static int8_t selected_count = sizeof selected / sizeof *selected;
-static int8_t selected_index;
-#endif
-
-void unicode_input_mode_init(void) {
- unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
-#if UNICODE_SELECTED_MODES != -1
-# if UNICODE_CYCLE_PERSIST
- // Find input_mode in selected modes
- int8_t i;
- for (i = 0; i < selected_count; i++) {
- if (selected[i] == unicode_config.input_mode) {
- selected_index = i;
- break;
- }
- }
- if (i == selected_count) {
- // Not found: input_mode isn't selected, change to one that is
- unicode_config.input_mode = selected[selected_index = 0];
- }
-# else
- // Always change to the first selected input mode
- unicode_config.input_mode = selected[selected_index = 0];
-# endif
-#endif
- dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode);
-}
-
-uint8_t get_unicode_input_mode(void) {
- return unicode_config.input_mode;
-}
-
-void set_unicode_input_mode(uint8_t mode) {
- unicode_config.input_mode = mode;
- persist_unicode_input_mode();
- dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode);
-}
-
-void cycle_unicode_input_mode(int8_t offset) {
-#if UNICODE_SELECTED_MODES != -1
- selected_index = (selected_index + offset) % selected_count;
- if (selected_index < 0) {
- selected_index += selected_count;
- }
- unicode_config.input_mode = selected[selected_index];
-# if UNICODE_CYCLE_PERSIST
- persist_unicode_input_mode();
-# endif
- dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode);
-#endif
-}
-
-void persist_unicode_input_mode(void) {
- eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode);
-}
-
-__attribute__((weak)) void unicode_input_start(void) {
- unicode_saved_caps_lock = host_keyboard_led_state().caps_lock;
- unicode_saved_num_lock = host_keyboard_led_state().num_lock;
-
- // Note the order matters here!
- // Need to do this before we mess around with the mods, or else
- // UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work
- // correctly in the shifted case.
- if (unicode_config.input_mode == UC_LNX && unicode_saved_caps_lock) {
- tap_code(KC_CAPS_LOCK);
- }
-
- unicode_saved_mods = get_mods(); // Save current mods
- clear_mods(); // Unregister mods to start from a clean state
- clear_weak_mods();
-
- switch (unicode_config.input_mode) {
- case UC_MAC:
- register_code(UNICODE_KEY_MAC);
- break;
- case UC_LNX:
- tap_code16(UNICODE_KEY_LNX);
- break;
- case UC_WIN:
- // For increased reliability, use numpad keys for inputting digits
- if (!unicode_saved_num_lock) {
- tap_code(KC_NUM_LOCK);
- }
- register_code(KC_LEFT_ALT);
- wait_ms(UNICODE_TYPE_DELAY);
- tap_code(KC_KP_PLUS);
- break;
- case UC_WINC:
- tap_code(UNICODE_KEY_WINC);
- tap_code(KC_U);
- break;
- case UC_EMACS:
- // The usual way to type unicode in emacs is C-x-8 <RET> then the unicode number in hex
- tap_code16(LCTL(KC_X));
- tap_code16(KC_8);
- tap_code16(KC_ENTER);
- break;
- }
-
- wait_ms(UNICODE_TYPE_DELAY);
-}
-
-__attribute__((weak)) void unicode_input_finish(void) {
- switch (unicode_config.input_mode) {
- case UC_MAC:
- unregister_code(UNICODE_KEY_MAC);
- break;
- case UC_LNX:
- tap_code(KC_SPACE);
- if (unicode_saved_caps_lock) {
- tap_code(KC_CAPS_LOCK);
- }
- break;
- case UC_WIN:
- unregister_code(KC_LEFT_ALT);
- if (!unicode_saved_num_lock) {
- tap_code(KC_NUM_LOCK);
- }
- break;
- case UC_WINC:
- tap_code(KC_ENTER);
- break;
- case UC_EMACS:
- tap_code16(KC_ENTER);
- break;
- }
-
- set_mods(unicode_saved_mods); // Reregister previously set mods
-}
-
-__attribute__((weak)) void unicode_input_cancel(void) {
- switch (unicode_config.input_mode) {
- case UC_MAC:
- unregister_code(UNICODE_KEY_MAC);
- break;
- case UC_LNX:
- tap_code(KC_ESCAPE);
- if (unicode_saved_caps_lock) {
- tap_code(KC_CAPS_LOCK);
- }
- break;
- case UC_WINC:
- tap_code(KC_ESCAPE);
- break;
- case UC_WIN:
- unregister_code(KC_LEFT_ALT);
- if (!unicode_saved_num_lock) {
- tap_code(KC_NUM_LOCK);
- }
- break;
- case UC_EMACS:
- tap_code16(LCTL(KC_G)); // C-g cancels
- break;
- }
-
- set_mods(unicode_saved_mods); // Reregister previously set mods
-}
-
-// clang-format off
-
-static void send_nibble_wrapper(uint8_t digit) {
- if (unicode_config.input_mode == UC_WIN) {
- uint8_t kc = digit < 10
- ? KC_KP_1 + (10 + digit - 1) % 10
- : KC_A + (digit - 10);
- tap_code(kc);
- return;
- }
- send_nibble(digit);
-}
-
-// clang-format on
-
-void register_hex(uint16_t hex) {
- for (int i = 3; i >= 0; i--) {
- uint8_t digit = ((hex >> (i * 4)) & 0xF);
- send_nibble_wrapper(digit);
- }
-}
-
-void register_hex32(uint32_t hex) {
- bool onzerostart = true;
- for (int i = 7; i >= 0; i--) {
- if (i <= 3) {
- onzerostart = false;
- }
- uint8_t digit = ((hex >> (i * 4)) & 0xF);
- if (digit == 0) {
- if (!onzerostart) {
- send_nibble_wrapper(digit);
- }
- } else {
- send_nibble_wrapper(digit);
- onzerostart = false;
- }
- }
-}
-
-void register_unicode(uint32_t code_point) {
- if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UC_WIN)) {
- // Code point out of range, do nothing
- return;
- }
-
- unicode_input_start();
- if (code_point > 0xFFFF && unicode_config.input_mode == UC_MAC) {
- // Convert code point to UTF-16 surrogate pair on macOS
- code_point -= 0x10000;
- uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10;
- register_hex32(hi + 0xD800);
- register_hex32(lo + 0xDC00);
- } else {
- register_hex32(code_point);
- }
- unicode_input_finish();
-}
-
-void send_unicode_string(const char *str) {
- if (!str) {
- return;
- }
-
- while (*str) {
- int32_t code_point = 0;
- str = decode_utf8(str, &code_point);
-
- if (code_point >= 0) {
- register_unicode(code_point);
- }
- }
-}
-
-// clang-format off
-
-static void audio_helper(void) {
-#ifdef AUDIO_ENABLE
- switch (get_unicode_input_mode()) {
-# ifdef UNICODE_SONG_MAC
- static float song_mac[][2] = UNICODE_SONG_MAC;
- case UC_MAC:
- PLAY_SONG(song_mac);
- break;
-# endif
-# ifdef UNICODE_SONG_LNX
- static float song_lnx[][2] = UNICODE_SONG_LNX;
- case UC_LNX:
- PLAY_SONG(song_lnx);
- break;
-# endif
-# ifdef UNICODE_SONG_WIN
- static float song_win[][2] = UNICODE_SONG_WIN;
- case UC_WIN:
- PLAY_SONG(song_win);
- break;
-# endif
-# ifdef UNICODE_SONG_BSD
- static float song_bsd[][2] = UNICODE_SONG_BSD;
- case UC_BSD:
- PLAY_SONG(song_bsd);
- break;
-# endif
-# ifdef UNICODE_SONG_WINC
- static float song_winc[][2] = UNICODE_SONG_WINC;
- case UC_WINC:
- PLAY_SONG(song_winc);
- break;
-# endif
- }
+#if defined(UNICODE_ENABLE)
+# include "process_unicode.h"
+#elif defined(UNICODEMAP_ENABLE)
+# include "process_unicodemap.h"
+#elif defined(UCIS_ENABLE)
+# include "process_ucis.h"
#endif
-}
-
-// clang-format on
bool process_unicode_common(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
@@ -305,35 +33,27 @@ bool process_unicode_common(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case UNICODE_MODE_FORWARD:
cycle_unicode_input_mode(shifted ? -1 : +1);
- audio_helper();
break;
case UNICODE_MODE_REVERSE:
cycle_unicode_input_mode(shifted ? +1 : -1);
- audio_helper();
break;
case UNICODE_MODE_MAC:
set_unicode_input_mode(UC_MAC);
- audio_helper();
break;
case UNICODE_MODE_LNX:
set_unicode_input_mode(UC_LNX);
- audio_helper();
break;
case UNICODE_MODE_WIN:
set_unicode_input_mode(UC_WIN);
- audio_helper();
break;
case UNICODE_MODE_BSD:
set_unicode_input_mode(UC_BSD);
- audio_helper();
break;
case UNICODE_MODE_WINC:
set_unicode_input_mode(UC_WINC);
- audio_helper();
break;
case UNICODE_MODE_EMACS:
set_unicode_input_mode(UC_EMACS);
- audio_helper();
break;
}
}
diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h
index 15e798dbb3..fd09a41818 100644
--- a/quantum/process_keycode/process_unicode_common.h
+++ b/quantum/process_keycode/process_unicode_common.h
@@ -16,187 +16,9 @@
#pragma once
-#include "quantum.h"
+#include <stdbool.h>
+#include <stdint.h>
-#if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1
-# error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time"
-#endif
-
-// Keycodes used for starting Unicode input on different platforms
-#ifndef UNICODE_KEY_MAC
-# define UNICODE_KEY_MAC KC_LEFT_ALT
-#endif
-#ifndef UNICODE_KEY_LNX
-# define UNICODE_KEY_LNX LCTL(LSFT(KC_U))
-#endif
-#ifndef UNICODE_KEY_WINC
-# define UNICODE_KEY_WINC KC_RIGHT_ALT
-#endif
-
-// Comma-delimited, ordered list of input modes selected for use (e.g. in cycle)
-// Example: #define UNICODE_SELECTED_MODES UC_WINC, UC_LNX
-#ifndef UNICODE_SELECTED_MODES
-# define UNICODE_SELECTED_MODES -1
-#endif
-
-// Whether input mode changes in cycle should be written to EEPROM
-#ifndef UNICODE_CYCLE_PERSIST
-# define UNICODE_CYCLE_PERSIST true
-#endif
-
-// Delay between starting Unicode input and sending a sequence, in ms
-#ifndef UNICODE_TYPE_DELAY
-# define UNICODE_TYPE_DELAY 10
-#endif
-
-// Deprecated aliases
-#if !defined(UNICODE_KEY_MAC) && defined(UNICODE_KEY_OSX)
-# define UNICODE_KEY_MAC UNICODE_KEY_OSX
-#endif
-#if !defined(UNICODE_SONG_MAC) && defined(UNICODE_SONG_OSX)
-# define UNICODE_SONG_MAC UNICODE_SONG_OSX
-#endif
-#define UC_OSX UC_MAC
-
-enum unicode_input_modes {
- UC_MAC, // macOS using Unicode Hex Input
- UC_LNX, // Linux using IBus
- UC_WIN, // Windows using EnableHexNumpad
- UC_BSD, // BSD (not implemented)
- UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose)
- UC_EMACS, // Emacs is an operating system in search of a good text editor
- UC__COUNT // Number of available input modes (always leave at the end)
-};
-
-typedef union {
- uint32_t raw;
- struct {
- uint8_t input_mode : 8;
- };
-} unicode_config_t;
-
-extern unicode_config_t unicode_config;
-
-void unicode_input_mode_init(void);
-uint8_t get_unicode_input_mode(void);
-void set_unicode_input_mode(uint8_t mode);
-void cycle_unicode_input_mode(int8_t offset);
-void persist_unicode_input_mode(void);
-
-void unicode_input_start(void);
-void unicode_input_finish(void);
-void unicode_input_cancel(void);
-
-void register_hex(uint16_t hex);
-void register_hex32(uint32_t hex);
-void register_unicode(uint32_t code_point);
-
-void send_unicode_string(const char *str);
+#include "action.h"
bool process_unicode_common(uint16_t keycode, keyrecord_t *record);
-
-#define UC_BSPC UC(0x0008)
-#define UC_SPC UC(0x0020)
-
-#define UC_EXLM UC(0x0021)
-#define UC_DQUT UC(0x0022)
-#define UC_HASH UC(0x0023)
-#define UC_DLR UC(0x0024)
-#define UC_PERC UC(0x0025)
-#define UC_AMPR UC(0x0026)
-#define UC_QUOT UC(0x0027)
-#define UC_LPRN UC(0x0028)
-#define UC_RPRN UC(0x0029)
-#define UC_ASTR UC(0x002A)
-#define UC_PLUS UC(0x002B)
-#define UC_COMM UC(0x002C)
-#define UC_DASH UC(0x002D)
-#define UC_DOT UC(0x002E)
-#define UC_SLSH UC(0x002F)
-
-#define UC_0 UC(0x0030)
-#define UC_1 UC(0x0031)
-#define UC_2 UC(0x0032)
-#define UC_3 UC(0x0033)
-#define UC_4 UC(0x0034)
-#define UC_5 UC(0x0035)
-#define UC_6 UC(0x0036)
-#define UC_7 UC(0x0037)
-#define UC_8 UC(0x0038)
-#define UC_9 UC(0x0039)
-
-#define UC_COLN UC(0x003A)
-#define UC_SCLN UC(0x003B)
-#define UC_LT UC(0x003C)
-#define UC_EQL UC(0x003D)
-#define UC_GT UC(0x003E)
-#define UC_QUES UC(0x003F)
-#define UC_AT UC(0x0040)
-
-#define UC_A UC(0x0041)
-#define UC_B UC(0x0042)
-#define UC_C UC(0x0043)
-#define UC_D UC(0x0044)
-#define UC_E UC(0x0045)
-#define UC_F UC(0x0046)
-#define UC_G UC(0x0047)
-#define UC_H UC(0x0048)
-#define UC_I UC(0x0049)
-#define UC_J UC(0x004A)
-#define UC_K UC(0x004B)
-#define UC_L UC(0x004C)
-#define UC_M UC(0x004D)
-#define UC_N UC(0x004E)
-#define UC_O UC(0x004F)
-#define UC_P UC(0x0050)
-#define UC_Q UC(0x0051)
-#define UC_R UC(0x0052)
-#define UC_S UC(0x0053)
-#define UC_T UC(0x0054)
-#define UC_U UC(0x0055)
-#define UC_V UC(0x0056)
-#define UC_W UC(0x0057)
-#define UC_X UC(0x0058)
-#define UC_Y UC(0x0059)
-#define UC_Z UC(0x005A)
-
-#define UC_LBRC UC(0x005B)
-#define UC_BSLS UC(0x005C)
-#define UC_RBRC UC(0x005D)
-#define UC_CIRM UC(0x005E)
-#define UC_UNDR UC(0x005F)
-
-#define UC_GRV UC(0x0060)
-
-#define UC_a UC(0x0061)
-#define UC_b UC(0x0062)
-#define UC_c UC(0x0063)
-#define UC_d UC(0x0064)
-#define UC_e UC(0x0065)
-#define UC_f UC(0x0066)
-#define UC_g UC(0x0067)
-#define UC_h UC(0x0068)
-#define UC_i UC(0x0069)
-#define UC_j UC(0x006A)
-#define UC_k UC(0x006B)
-#define UC_l UC(0x006C)
-#define UC_m UC(0x006D)
-#define UC_n UC(0x006E)
-#define UC_o UC(0x006F)
-#define UC_p UC(0x0070)
-#define UC_q UC(0x0071)
-#define UC_r UC(0x0072)
-#define UC_s UC(0x0073)
-#define UC_t UC(0x0074)
-#define UC_u UC(0x0075)
-#define UC_v UC(0x0076)
-#define UC_w UC(0x0077)
-#define UC_x UC(0x0078)
-#define UC_y UC(0x0079)
-#define UC_z UC(0x007A)
-
-#define UC_LCBR UC(0x007B)
-#define UC_PIPE UC(0x007C)
-#define UC_RCBR UC(0x007D)
-#define UC_TILD UC(0x007E)
-#define UC_DEL UC(0x007F)
diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c
index 459397014d..979d773b05 100644
--- a/quantum/process_keycode/process_unicodemap.c
+++ b/quantum/process_keycode/process_unicodemap.c
@@ -15,6 +15,11 @@
*/
#include "process_unicodemap.h"
+#include "unicode.h"
+#include "quantum_keycodes.h"
+#include "keycode.h"
+#include "action_util.h"
+#include "host.h"
__attribute__((weak)) uint16_t unicodemap_index(uint16_t keycode) {
if (keycode >= QK_UNICODEMAP_PAIR) {
diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h
index c429859bbb..73f5449864 100644
--- a/quantum/process_keycode/process_unicodemap.h
+++ b/quantum/process_keycode/process_unicodemap.h
@@ -16,7 +16,11 @@
#pragma once
-#include "process_unicode_common.h"
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "action.h"
+#include "progmem.h"
extern const uint32_t PROGMEM unicode_map[];
diff --git a/quantum/programmable_button.c b/quantum/programmable_button.c
index a3ef42d82b..b6c9ad3189 100644
--- a/quantum/programmable_button.c
+++ b/quantum/programmable_button.c
@@ -24,27 +24,38 @@ static uint32_t programmable_button_report = 0;
void programmable_button_clear(void) {
programmable_button_report = 0;
+ programmable_button_flush();
}
-void programmable_button_send(void) {
- host_programmable_button_send(programmable_button_report);
-}
-
-void programmable_button_on(uint8_t index) {
+void programmable_button_add(uint8_t index) {
programmable_button_report |= REPORT_BIT(index);
}
-void programmable_button_off(uint8_t index) {
+void programmable_button_remove(uint8_t index) {
programmable_button_report &= ~REPORT_BIT(index);
}
+void programmable_button_register(uint8_t index) {
+ programmable_button_add(index);
+ programmable_button_flush();
+}
+
+void programmable_button_unregister(uint8_t index) {
+ programmable_button_remove(index);
+ programmable_button_flush();
+}
+
bool programmable_button_is_on(uint8_t index) {
return !!(programmable_button_report & REPORT_BIT(index));
-};
+}
+
+void programmable_button_flush(void) {
+ host_programmable_button_send(programmable_button_report);
+}
uint32_t programmable_button_get_report(void) {
return programmable_button_report;
-};
+}
void programmable_button_set_report(uint32_t report) {
programmable_button_report = report;
diff --git a/quantum/programmable_button.h b/quantum/programmable_button.h
index e89b8b9fd6..e8c916d75c 100644
--- a/quantum/programmable_button.h
+++ b/quantum/programmable_button.h
@@ -19,12 +19,73 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdint.h>
#include <stdbool.h>
-#include "report.h"
-void programmable_button_clear(void);
-void programmable_button_send(void);
-void programmable_button_on(uint8_t index);
-void programmable_button_off(uint8_t index);
-bool programmable_button_is_on(uint8_t index);
+/**
+ * \defgroup programmable_button
+ *
+ * HID Programmable Buttons
+ * \{
+ */
+
+/**
+ * \brief Clear the programmable button report.
+ */
+void programmable_button_clear(void);
+
+/**
+ * \brief Set the state of a button.
+ *
+ * \param index The index of the button to press, from 0 to 31.
+ */
+void programmable_button_add(uint8_t index);
+
+/**
+ * \brief Reset the state of a button.
+ *
+ * \param index The index of the button to release, from 0 to 31.
+ */
+void programmable_button_remove(uint8_t index);
+
+/**
+ * \brief Set the state of a button, and flush the report.
+ *
+ * \param index The index of the button to press, from 0 to 31.
+ */
+void programmable_button_register(uint8_t index);
+
+/**
+ * \brief Reset the state of a button, and flush the report.
+ *
+ * \param index The index of the button to release, from 0 to 31.
+ */
+void programmable_button_unregister(uint8_t index);
+
+/**
+ * \brief Get the state of a button.
+ *
+ * \param index The index of the button to check, from 0 to 31.
+ *
+ * \return `true` if the button is pressed.
+ */
+bool programmable_button_is_on(uint8_t index);
+
+/**
+ * \brief Send the programmable button report to the host.
+ */
+void programmable_button_flush(void);
+
+/**
+ * \brief Get the programmable button report.
+ *
+ * \return The bitmask of programmable button states.
+ */
uint32_t programmable_button_get_report(void);
-void programmable_button_set_report(uint32_t report);
+
+/**
+ * \brief Set the programmable button report.
+ *
+ * \param report A bitmask of programmable button states.
+ */
+void programmable_button_set_report(uint32_t report);
+
+/** \} */
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 9a0016b150..2333357be1 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -225,7 +225,7 @@ bool process_record_quantum(keyrecord_t *record) {
uint16_t keycode = get_record_keycode(record, true);
// This is how you use actions here
- // if (keycode == KC_LEAD) {
+ // if (keycode == QK_LEADER) {
// action_t action;
// action.code = ACTION_DEFAULT_LAYER_SET(0);
// process_action(record, action);
@@ -251,7 +251,11 @@ bool process_record_quantum(keyrecord_t *record) {
#endif
#ifdef TAP_DANCE_ENABLE
- preprocess_tap_dance(keycode, record);
+ if (preprocess_tap_dance(keycode, record)) {
+ // The tap dance might have updated the layer state, therefore the
+ // result of the keycode lookup might change.
+ keycode = get_record_keycode(record, true);
+ }
#endif
if (!(
@@ -272,6 +276,9 @@ bool process_record_quantum(keyrecord_t *record) {
#if defined(VIA_ENABLE)
process_record_via(keycode, record) &&
#endif
+#if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE)
+ process_auto_mouse(keycode, record) &&
+#endif
process_record_kb(keycode, record) &&
#if defined(SECURE_ENABLE)
process_secure(keycode, record) &&
@@ -336,6 +343,9 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef PROGRAMMABLE_BUTTON_ENABLE
process_programmable_button(keycode, record) &&
#endif
+#ifdef AUTOCORRECT_ENABLE
+ process_autocorrect(keycode, record) &&
+#endif
true)) {
return false;
}
@@ -361,13 +371,15 @@ bool process_record_quantum(keyrecord_t *record) {
#endif
return false;
case QK_CLEAR_EEPROM:
+#ifdef NO_RESET
eeconfig_init();
-#ifndef NO_RESET
+#else
+ eeconfig_disable();
soft_reset_keyboard();
#endif
return false;
#ifdef VELOCIKEY_ENABLE
- case VLK_TOG:
+ case QK_VELOCIKEY_TOGGLE:
velocikey_toggle();
return false;
#endif
@@ -383,13 +395,13 @@ bool process_record_quantum(keyrecord_t *record) {
return false;
#endif
#ifndef NO_ACTION_ONESHOT
- case ONESHOT_TOGGLE:
+ case QK_ONE_SHOT_TOGGLE:
oneshot_toggle();
break;
- case ONESHOT_ENABLE:
+ case QK_ONE_SHOT_ON:
oneshot_enable();
break;
- case ONESHOT_DISABLE:
+ case QK_ONE_SHOT_OFF:
oneshot_disable();
break;
#endif
@@ -410,7 +422,11 @@ bool process_record_quantum(keyrecord_t *record) {
} else {
SEND_STRING_DELAY(" compile ", TAP_CODE_DELAY);
}
+# if defined(CONVERTER_ENABLED)
+ SEND_STRING_DELAY("-kb " QMK_KEYBOARD " -km " QMK_KEYMAP " -e CONVERT_TO=" CONVERTER_TARGET SS_TAP(X_ENTER), TAP_CODE_DELAY);
+# else
SEND_STRING_DELAY("-kb " QMK_KEYBOARD " -km " QMK_KEYMAP SS_TAP(X_ENTER), TAP_CODE_DELAY);
+# endif
if (temp_mod & MOD_MASK_SHIFT && temp_mod & MOD_MASK_CTRL) {
reset_keyboard();
}
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 8d74f2be38..9c1b9952b8 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -109,6 +109,7 @@ extern layer_state_t layer_state;
#endif
#ifdef UNICODE_COMMON_ENABLE
+# include "unicode.h"
# include "process_unicode_common.h"
#endif
@@ -235,6 +236,10 @@ extern layer_state_t layer_state;
# include "process_caps_word.h"
#endif
+#ifdef AUTOCORRECT_ENABLE
+# include "process_autocorrect.h"
+#endif
+
// For tri-layer
void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index c8f03fa1ce..6c9a262484 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -105,12 +105,12 @@ enum quantum_keycodes {
QK_GRAVE_ESCAPE, // 5C16
// Auto Shift
- KC_ASUP, // 5C17
- KC_ASDN, // 5C18
- KC_ASRP, // 5C19
- KC_ASTG, // 5C1A
- KC_ASON, // 5C1B
- KC_ASOFF, // 5C1C
+ QK_AUTO_SHIFT_UP, // 5C17
+ QK_AUTO_SHIFT_DOWN, // 5C18
+ QK_AUTO_SHIFT_REPORT, // 5C19
+ QK_AUTO_SHIFT_TOGGLE, // 5C1A
+ QK_AUTO_SHIFT_ON, // 5C1B
+ QK_AUTO_SHIFT_OFF, // 5C1C
// Audio
AU_ON, // 5C1D
@@ -359,12 +359,12 @@ enum quantum_keycodes {
RGB_MODE_RGBTEST, // 5CD6
// Velocikey
- VLK_TOG, // 5CD7
+ QK_VELOCIKEY_TOGGLE, // 5CD7
// Space Cadet
- KC_LSPO, // 5CD8
- KC_RSPC, // 5CD9
- KC_SFTENT, // 5CDA
+ QK_SPACE_CADET_LEFT_SHIFT_PARENTHESIS_OPEN, // 5CD8
+ QK_SPACE_CADET_RIGHT_SHIFT_PARENTHESIS_CLOSE, // 5CD9
+ QK_SPACE_CADET_RIGHT_SHIFT_ENTER, // 5CDA
// Thermal Printer
PRINT_ON, // 5CDB
@@ -402,15 +402,15 @@ enum quantum_keycodes {
HPT_DWLD, // 5CF3
// Space Cadet (continued)
- KC_LCPO, // 5CF4
- KC_RCPC, // 5CF5
- KC_LAPO, // 5CF6
- KC_RAPC, // 5CF7
+ QK_SPACE_CADET_LEFT_CTRL_PARENTHESIS_OPEN, // 5CF4
+ QK_SPACE_CADET_RIGHT_CTRL_PARENTHESIS_CLOSE, // 5CF5
+ QK_SPACE_CADET_LEFT_ALT_PARENTHESIS_OPEN, // 5CF6
+ QK_SPACE_CADET_RIGHT_ALT_PARENTHESIS_CLOSE, // 5CF7
// Combos
- CMB_ON, // 5CF8
- CMB_OFF, // 5CF9
- CMB_TOG, // 5CFA
+ QK_COMBO_ON, // 5CF8
+ QK_COMBO_OFF, // 5CF9
+ QK_COMBO_TOGGLE, // 5CFA
// Magic (continued)
MAGIC_SWAP_LCTL_LGUI, // 5CFB
@@ -431,47 +431,47 @@ enum quantum_keycodes {
DYN_MACRO_PLAY2, // 5D08
// Joystick
- JS_BUTTON0, // 5D09
- JS_BUTTON1, // 5D0A
- JS_BUTTON2, // 5D0B
- JS_BUTTON3, // 5D0C
- JS_BUTTON4, // 5D0D
- JS_BUTTON5, // 5D0E
- JS_BUTTON6, // 5D0F
- JS_BUTTON7, // 5D10
- JS_BUTTON8, // 5D11
- JS_BUTTON9, // 5D12
- JS_BUTTON10, // 5D13
- JS_BUTTON11, // 5D14
- JS_BUTTON12, // 5D15
- JS_BUTTON13, // 5D16
- JS_BUTTON14, // 5D17
- JS_BUTTON15, // 5D18
- JS_BUTTON16, // 5D19
- JS_BUTTON17, // 5D1A
- JS_BUTTON18, // 5D1B
- JS_BUTTON19, // 5D1C
- JS_BUTTON20, // 5D1D
- JS_BUTTON21, // 5D1E
- JS_BUTTON22, // 5D1F
- JS_BUTTON23, // 5D20
- JS_BUTTON24, // 5D21
- JS_BUTTON25, // 5D22
- JS_BUTTON26, // 5D23
- JS_BUTTON27, // 5D24
- JS_BUTTON28, // 5D25
- JS_BUTTON29, // 5D26
- JS_BUTTON30, // 5D27
- JS_BUTTON31, // 5D28
+ QK_JOYSTICK_BUTTON_0, // 5D09
+ QK_JOYSTICK_BUTTON_1, // 5D0A
+ QK_JOYSTICK_BUTTON_2, // 5D0B
+ QK_JOYSTICK_BUTTON_3, // 5D0C
+ QK_JOYSTICK_BUTTON_4, // 5D0D
+ QK_JOYSTICK_BUTTON_5, // 5D0E
+ QK_JOYSTICK_BUTTON_6, // 5D0F
+ QK_JOYSTICK_BUTTON_7, // 5D10
+ QK_JOYSTICK_BUTTON_8, // 5D11
+ QK_JOYSTICK_BUTTON_9, // 5D12
+ QK_JOYSTICK_BUTTON_10, // 5D13
+ QK_JOYSTICK_BUTTON_11, // 5D14
+ QK_JOYSTICK_BUTTON_12, // 5D15
+ QK_JOYSTICK_BUTTON_13, // 5D16
+ QK_JOYSTICK_BUTTON_14, // 5D17
+ QK_JOYSTICK_BUTTON_15, // 5D18
+ QK_JOYSTICK_BUTTON_16, // 5D19
+ QK_JOYSTICK_BUTTON_17, // 5D1A
+ QK_JOYSTICK_BUTTON_18, // 5D1B
+ QK_JOYSTICK_BUTTON_19, // 5D1C
+ QK_JOYSTICK_BUTTON_20, // 5D1D
+ QK_JOYSTICK_BUTTON_21, // 5D1E
+ QK_JOYSTICK_BUTTON_22, // 5D1F
+ QK_JOYSTICK_BUTTON_23, // 5D20
+ QK_JOYSTICK_BUTTON_24, // 5D21
+ QK_JOYSTICK_BUTTON_25, // 5D22
+ QK_JOYSTICK_BUTTON_26, // 5D23
+ QK_JOYSTICK_BUTTON_27, // 5D24
+ QK_JOYSTICK_BUTTON_28, // 5D25
+ QK_JOYSTICK_BUTTON_29, // 5D26
+ QK_JOYSTICK_BUTTON_30, // 5D27
+ QK_JOYSTICK_BUTTON_31, // 5D28
// Leader Key
- KC_LEAD, // 5D29
+ QK_LEADER, // 5D29
// Bluetooth: output selection (continued)
OUT_BT, // 5D2A
// Lock Key
- KC_LOCK, // 5D2B
+ QK_LOCK, // 5D2B
// Unused slots
UNUSED_000, // 5D2C
@@ -505,17 +505,17 @@ enum quantum_keycodes {
#define SQ_T(n) (n < SEQUENCER_TRACKS ? SEQUENCER_TRACK_MIN + n : KC_NO)
// One Shot
- ONESHOT_ENABLE,
- ONESHOT_DISABLE,
- ONESHOT_TOGGLE,
+ QK_ONE_SHOT_ON,
+ QK_ONE_SHOT_OFF,
+ QK_ONE_SHOT_TOGGLE,
// RGB underglow/matrix (continued)
RGB_MODE_TWINKLE,
// Key Overrides
- KEY_OVERRIDE_TOGGLE,
- KEY_OVERRIDE_ON,
- KEY_OVERRIDE_OFF,
+ QK_KEY_OVERRIDE_TOGGLE,
+ QK_KEY_OVERRIDE_ON,
+ QK_KEY_OVERRIDE_OFF,
// Additional magic key
MAGIC_TOGGLE_GUI,
@@ -526,38 +526,38 @@ enum quantum_keycodes {
DT_DOWN,
// Programmable Button
- PROGRAMMABLE_BUTTON_1,
- PROGRAMMABLE_BUTTON_2,
- PROGRAMMABLE_BUTTON_3,
- PROGRAMMABLE_BUTTON_4,
- PROGRAMMABLE_BUTTON_5,
- PROGRAMMABLE_BUTTON_6,
- PROGRAMMABLE_BUTTON_7,
- PROGRAMMABLE_BUTTON_8,
- PROGRAMMABLE_BUTTON_9,
- PROGRAMMABLE_BUTTON_10,
- PROGRAMMABLE_BUTTON_11,
- PROGRAMMABLE_BUTTON_12,
- PROGRAMMABLE_BUTTON_13,
- PROGRAMMABLE_BUTTON_14,
- PROGRAMMABLE_BUTTON_15,
- PROGRAMMABLE_BUTTON_16,
- PROGRAMMABLE_BUTTON_17,
- PROGRAMMABLE_BUTTON_18,
- PROGRAMMABLE_BUTTON_19,
- PROGRAMMABLE_BUTTON_20,
- PROGRAMMABLE_BUTTON_21,
- PROGRAMMABLE_BUTTON_22,
- PROGRAMMABLE_BUTTON_23,
- PROGRAMMABLE_BUTTON_24,
- PROGRAMMABLE_BUTTON_25,
- PROGRAMMABLE_BUTTON_26,
- PROGRAMMABLE_BUTTON_27,
- PROGRAMMABLE_BUTTON_28,
- PROGRAMMABLE_BUTTON_29,
- PROGRAMMABLE_BUTTON_30,
- PROGRAMMABLE_BUTTON_31,
- PROGRAMMABLE_BUTTON_32,
+ QK_PROGRAMMABLE_BUTTON_1,
+ QK_PROGRAMMABLE_BUTTON_2,
+ QK_PROGRAMMABLE_BUTTON_3,
+ QK_PROGRAMMABLE_BUTTON_4,
+ QK_PROGRAMMABLE_BUTTON_5,
+ QK_PROGRAMMABLE_BUTTON_6,
+ QK_PROGRAMMABLE_BUTTON_7,
+ QK_PROGRAMMABLE_BUTTON_8,
+ QK_PROGRAMMABLE_BUTTON_9,
+ QK_PROGRAMMABLE_BUTTON_10,
+ QK_PROGRAMMABLE_BUTTON_11,
+ QK_PROGRAMMABLE_BUTTON_12,
+ QK_PROGRAMMABLE_BUTTON_13,
+ QK_PROGRAMMABLE_BUTTON_14,
+ QK_PROGRAMMABLE_BUTTON_15,
+ QK_PROGRAMMABLE_BUTTON_16,
+ QK_PROGRAMMABLE_BUTTON_17,
+ QK_PROGRAMMABLE_BUTTON_18,
+ QK_PROGRAMMABLE_BUTTON_19,
+ QK_PROGRAMMABLE_BUTTON_20,
+ QK_PROGRAMMABLE_BUTTON_21,
+ QK_PROGRAMMABLE_BUTTON_22,
+ QK_PROGRAMMABLE_BUTTON_23,
+ QK_PROGRAMMABLE_BUTTON_24,
+ QK_PROGRAMMABLE_BUTTON_25,
+ QK_PROGRAMMABLE_BUTTON_26,
+ QK_PROGRAMMABLE_BUTTON_27,
+ QK_PROGRAMMABLE_BUTTON_28,
+ QK_PROGRAMMABLE_BUTTON_29,
+ QK_PROGRAMMABLE_BUTTON_30,
+ QK_PROGRAMMABLE_BUTTON_31,
+ QK_PROGRAMMABLE_BUTTON_32,
// Dedicated macro keys for Configurator and VIA
MACRO_0,
@@ -598,12 +598,12 @@ enum quantum_keycodes {
QK_MAKE,
QK_REBOOT,
- SECURE_LOCK,
- SECURE_UNLOCK,
- SECURE_TOGGLE,
- SECURE_REQUEST,
+ QK_SECURE_LOCK,
+ QK_SECURE_UNLOCK,
+ QK_SECURE_TOGGLE,
+ QK_SECURE_REQUEST,
- CAPS_WORD,
+ QK_CAPS_WORD_TOGGLE,
MAGIC_SWAP_ESCAPE_CAPSLOCK,
MAGIC_UNSWAP_ESCAPE_CAPSLOCK,
@@ -611,6 +611,12 @@ enum quantum_keycodes {
UNICODE_MODE_EMACS,
+ QK_AUTOCORRECT_ON,
+ QK_AUTOCORRECT_OFF,
+ QK_AUTOCORRECT_TOGGLE,
+
+ MAGIC_TOGGLE_BACKSLASH_BACKSPACE,
+
// Start of custom keycode range for keyboards and keymaps - always leave at the end
SAFE_RANGE
};
@@ -652,69 +658,7 @@ enum quantum_keycodes {
#define MOD_MEH 0x7
// US ANSI shifted keycode aliases
-#define KC_TILDE LSFT(KC_GRAVE) // ~
-#define KC_TILD KC_TILDE
-
-#define KC_EXCLAIM LSFT(KC_1) // !
-#define KC_EXLM KC_EXCLAIM
-
-#define KC_AT LSFT(KC_2) // @
-
-#define KC_HASH LSFT(KC_3) // #
-
-#define KC_DOLLAR LSFT(KC_4) // $
-#define KC_DLR KC_DOLLAR
-
-#define KC_PERCENT LSFT(KC_5) // %
-#define KC_PERC KC_PERCENT
-
-#define KC_CIRCUMFLEX LSFT(KC_6) // ^
-#define KC_CIRC KC_CIRCUMFLEX
-
-#define KC_AMPERSAND LSFT(KC_7) // &
-#define KC_AMPR KC_AMPERSAND
-
-#define KC_ASTERISK LSFT(KC_8) // *
-#define KC_ASTR KC_ASTERISK
-
-#define KC_LEFT_PAREN LSFT(KC_9) // (
-#define KC_LPRN KC_LEFT_PAREN
-
-#define KC_RIGHT_PAREN LSFT(KC_0) // )
-#define KC_RPRN KC_RIGHT_PAREN
-
-#define KC_UNDERSCORE LSFT(KC_MINUS) // _
-#define KC_UNDS KC_UNDERSCORE
-
-#define KC_PLUS LSFT(KC_EQUAL) // +
-
-#define KC_LEFT_CURLY_BRACE LSFT(KC_LEFT_BRACKET) // {
-#define KC_LCBR KC_LEFT_CURLY_BRACE
-
-#define KC_RIGHT_CURLY_BRACE LSFT(KC_RIGHT_BRACKET) // }
-#define KC_RCBR KC_RIGHT_CURLY_BRACE
-
-#define KC_LEFT_ANGLE_BRACKET LSFT(KC_COMMA) // <
-#define KC_LABK KC_LEFT_ANGLE_BRACKET
-#define KC_LT KC_LEFT_ANGLE_BRACKET
-
-#define KC_RIGHT_ANGLE_BRACKET LSFT(KC_DOT) // >
-#define KC_RABK KC_RIGHT_ANGLE_BRACKET
-#define KC_GT KC_RIGHT_ANGLE_BRACKET
-
-#define KC_COLON LSFT(KC_SEMICOLON) // :
-#define KC_COLN KC_COLON
-
-#define KC_PIPE LSFT(KC_BACKSLASH) // |
-
-#define KC_QUESTION LSFT(KC_SLASH) // ?
-#define KC_QUES KC_QUESTION
-
-#define KC_DOUBLE_QUOTE LSFT(KC_QUOTE) // "
-#define KC_DQUO KC_DOUBLE_QUOTE
-#define KC_DQT KC_DOUBLE_QUOTE
-
-#define KC_DELT KC_DELETE // Del key (four letter code)
+#include "keymap_us.h"
// Modified keycode aliases
#define C(kc) LCTL(kc)
@@ -736,10 +680,6 @@ enum quantum_keycodes {
#define CK_DOWN CLICKY_DOWN
#define CK_ON CLICKY_ENABLE
#define CK_OFF CLICKY_DISABLE
-// Fauxclicky (deprecated) redirects to Audio Clicky
-#define FC_ON CLICKY_ENABLE
-#define FC_OFF CLICKY_DISABLE
-#define FC_TOGG CLICKY_TOGGLE
// RGB aliases
#define RGB_MOD RGB_MODE_FORWARD
@@ -791,6 +731,7 @@ enum quantum_keycodes {
#define BS_SWAP MAGIC_SWAP_BACKSLASH_BACKSPACE
#define BS_NORM MAGIC_UNSWAP_BACKSLASH_BACKSPACE
+#define BS_TOGG MAGIC_TOGGLE_BACKSLASH_BACKSPACE
#define NK_ON MAGIC_HOST_NKRO
#define NK_OFF MAGIC_UNHOST_NKRO
@@ -799,6 +740,13 @@ enum quantum_keycodes {
#define EH_LEFT MAGIC_EE_HANDS_LEFT
#define EH_RGHT MAGIC_EE_HANDS_RIGHT
+#define AC_ON QK_AUTOCORRECT_ON
+#define AC_OFF QK_AUTOCORRECT_OFF
+#define AC_TOGG QK_AUTOCORRECT_TOGGLE
+
+// Velocikey
+#define VK_TOGG QK_VELOCIKEY_TOGGLE
+
// GOTO layer - 256 layer max
#define TO(layer) (QK_TO | ((layer)&0xFF))
@@ -890,14 +838,51 @@ enum quantum_keycodes {
#define UC_RMOD UNICODE_MODE_REVERSE
#define UC_M_MA UNICODE_MODE_MAC
-#define UNICODE_MODE_OSX UNICODE_MODE_MAC // Deprecated alias
-#define UC_M_OS UNICODE_MODE_MAC // Deprecated alias
#define UC_M_LN UNICODE_MODE_LNX
#define UC_M_WI UNICODE_MODE_WIN
#define UC_M_BS UNICODE_MODE_BSD
#define UC_M_WC UNICODE_MODE_WINC
#define UC_M_EM UNICODE_MODE_EMACS
+// Auto Shift
+#define AS_UP QK_AUTO_SHIFT_UP
+#define AS_DOWN QK_AUTO_SHIFT_DOWN
+#define AS_RPT QK_AUTO_SHIFT_REPORT
+#define AS_TOGG QK_AUTO_SHIFT_TOGGLE
+#define AS_ON QK_AUTO_SHIFT_ON
+#define AS_OFF QK_AUTO_SHIFT_OFF
+
+// Leader key
+#define QK_LEAD QK_LEADER
+
+// Caps Word
+#define CW_TOGG QK_CAPS_WORD_TOGGLE
+
+// Key Overrides
+#define KO_TOGG QK_KEY_OVERRIDE_TOGGLE
+#define KO_ON QK_KEY_OVERRIDE_ON
+#define KO_OFF QK_KEY_OVERRIDE_OFF
+
+// Secure
+#define SE_LOCK QK_SECURE_LOCK
+#define SE_UNLK QK_SECURE_UNLOCK
+#define SE_TOGG QK_SECURE_TOGGLE
+#define SE_REQ QK_SECURE_REQUEST
+
+// Space Cadet
+#define SC_LSPO QK_SPACE_CADET_LEFT_SHIFT_PARENTHESIS_OPEN
+#define SC_RSPC QK_SPACE_CADET_RIGHT_SHIFT_PARENTHESIS_CLOSE
+#define SC_LCPO QK_SPACE_CADET_LEFT_CTRL_PARENTHESIS_OPEN
+#define SC_RCPC QK_SPACE_CADET_RIGHT_CTRL_PARENTHESIS_CLOSE
+#define SC_LAPO QK_SPACE_CADET_LEFT_ALT_PARENTHESIS_OPEN
+#define SC_RAPC QK_SPACE_CADET_RIGHT_ALT_PARENTHESIS_CLOSE
+#define SC_SENT QK_SPACE_CADET_RIGHT_SHIFT_ENTER
+
+// Combos
+#define CM_ON QK_COMBO_ON
+#define CM_OFF QK_COMBO_OFF
+#define CM_TOGG QK_COMBO_TOGGLE
+
// Swap Hands
#define SH_T(kc) (QK_SWAP_HANDS | (kc))
#define SH_TG (QK_SWAP_HANDS | OP_SH_TOGGLE)
@@ -928,49 +913,80 @@ enum quantum_keycodes {
#define DM_PLY2 DYN_MACRO_PLAY2
// Joystick aliases
-#define JS_BUTTON_MIN JS_BUTTON0
-#define JS_BUTTON_MAX JS_BUTTON31
+#define JS_0 QK_JOYSTICK_BUTTON_0
+#define JS_1 QK_JOYSTICK_BUTTON_1
+#define JS_2 QK_JOYSTICK_BUTTON_2
+#define JS_3 QK_JOYSTICK_BUTTON_3
+#define JS_4 QK_JOYSTICK_BUTTON_4
+#define JS_5 QK_JOYSTICK_BUTTON_5
+#define JS_6 QK_JOYSTICK_BUTTON_6
+#define JS_7 QK_JOYSTICK_BUTTON_7
+#define JS_8 QK_JOYSTICK_BUTTON_8
+#define JS_9 QK_JOYSTICK_BUTTON_9
+#define JS_10 QK_JOYSTICK_BUTTON_10
+#define JS_11 QK_JOYSTICK_BUTTON_11
+#define JS_12 QK_JOYSTICK_BUTTON_12
+#define JS_13 QK_JOYSTICK_BUTTON_13
+#define JS_14 QK_JOYSTICK_BUTTON_14
+#define JS_15 QK_JOYSTICK_BUTTON_15
+#define JS_16 QK_JOYSTICK_BUTTON_16
+#define JS_17 QK_JOYSTICK_BUTTON_17
+#define JS_18 QK_JOYSTICK_BUTTON_18
+#define JS_19 QK_JOYSTICK_BUTTON_19
+#define JS_20 QK_JOYSTICK_BUTTON_20
+#define JS_21 QK_JOYSTICK_BUTTON_21
+#define JS_22 QK_JOYSTICK_BUTTON_22
+#define JS_23 QK_JOYSTICK_BUTTON_23
+#define JS_24 QK_JOYSTICK_BUTTON_24
+#define JS_25 QK_JOYSTICK_BUTTON_25
+#define JS_26 QK_JOYSTICK_BUTTON_26
+#define JS_27 QK_JOYSTICK_BUTTON_27
+#define JS_28 QK_JOYSTICK_BUTTON_28
+#define JS_29 QK_JOYSTICK_BUTTON_29
+#define JS_30 QK_JOYSTICK_BUTTON_30
+#define JS_31 QK_JOYSTICK_BUTTON_31
+#define QK_JOYSTICK_BUTTON_MIN QK_JOYSTICK_BUTTON_0
+#define QK_JOYSTICK_BUTTON_MAX QK_JOYSTICK_BUTTON_31
// One Shot aliases
-#define OS_TOGG ONESHOT_TOGGLE
-#define OS_ON ONESHOT_ENABLE
-#define OS_OFF ONESHOT_DISABLE
+#define OS_TOGG QK_ONE_SHOT_TOGGLE
+#define OS_ON QK_ONE_SHOT_ON
+#define OS_OFF QK_ONE_SHOT_OFF
// Programmable Button aliases
-#define PB_1 PROGRAMMABLE_BUTTON_1
-#define PB_2 PROGRAMMABLE_BUTTON_2
-#define PB_3 PROGRAMMABLE_BUTTON_3
-#define PB_4 PROGRAMMABLE_BUTTON_4
-#define PB_5 PROGRAMMABLE_BUTTON_5
-#define PB_6 PROGRAMMABLE_BUTTON_6
-#define PB_7 PROGRAMMABLE_BUTTON_7
-#define PB_8 PROGRAMMABLE_BUTTON_8
-#define PB_9 PROGRAMMABLE_BUTTON_9
-#define PB_10 PROGRAMMABLE_BUTTON_10
-#define PB_11 PROGRAMMABLE_BUTTON_11
-#define PB_12 PROGRAMMABLE_BUTTON_12
-#define PB_13 PROGRAMMABLE_BUTTON_13
-#define PB_14 PROGRAMMABLE_BUTTON_14
-#define PB_15 PROGRAMMABLE_BUTTON_15
-#define PB_16 PROGRAMMABLE_BUTTON_16
-#define PB_17 PROGRAMMABLE_BUTTON_17
-#define PB_18 PROGRAMMABLE_BUTTON_18
-#define PB_19 PROGRAMMABLE_BUTTON_19
-#define PB_20 PROGRAMMABLE_BUTTON_20
-#define PB_21 PROGRAMMABLE_BUTTON_21
-#define PB_22 PROGRAMMABLE_BUTTON_22
-#define PB_23 PROGRAMMABLE_BUTTON_23
-#define PB_24 PROGRAMMABLE_BUTTON_24
-#define PB_25 PROGRAMMABLE_BUTTON_25
-#define PB_26 PROGRAMMABLE_BUTTON_26
-#define PB_27 PROGRAMMABLE_BUTTON_27
-#define PB_28 PROGRAMMABLE_BUTTON_28
-#define PB_29 PROGRAMMABLE_BUTTON_29
-#define PB_30 PROGRAMMABLE_BUTTON_30
-#define PB_31 PROGRAMMABLE_BUTTON_31
-#define PB_32 PROGRAMMABLE_BUTTON_32
-#define PROGRAMMABLE_BUTTON_MIN PROGRAMMABLE_BUTTON_1
-#define PROGRAMMABLE_BUTTON_MAX PROGRAMMABLE_BUTTON_32
-#define CAPSWRD CAPS_WORD
+#define PB_1 QK_PROGRAMMABLE_BUTTON_1
+#define PB_2 QK_PROGRAMMABLE_BUTTON_2
+#define PB_3 QK_PROGRAMMABLE_BUTTON_3
+#define PB_4 QK_PROGRAMMABLE_BUTTON_4
+#define PB_5 QK_PROGRAMMABLE_BUTTON_5
+#define PB_6 QK_PROGRAMMABLE_BUTTON_6
+#define PB_7 QK_PROGRAMMABLE_BUTTON_7
+#define PB_8 QK_PROGRAMMABLE_BUTTON_8
+#define PB_9 QK_PROGRAMMABLE_BUTTON_9
+#define PB_10 QK_PROGRAMMABLE_BUTTON_10
+#define PB_11 QK_PROGRAMMABLE_BUTTON_11
+#define PB_12 QK_PROGRAMMABLE_BUTTON_12
+#define PB_13 QK_PROGRAMMABLE_BUTTON_13
+#define PB_14 QK_PROGRAMMABLE_BUTTON_14
+#define PB_15 QK_PROGRAMMABLE_BUTTON_15
+#define PB_16 QK_PROGRAMMABLE_BUTTON_16
+#define PB_17 QK_PROGRAMMABLE_BUTTON_17
+#define PB_18 QK_PROGRAMMABLE_BUTTON_18
+#define PB_19 QK_PROGRAMMABLE_BUTTON_19
+#define PB_20 QK_PROGRAMMABLE_BUTTON_20
+#define PB_21 QK_PROGRAMMABLE_BUTTON_21
+#define PB_22 QK_PROGRAMMABLE_BUTTON_22
+#define PB_23 QK_PROGRAMMABLE_BUTTON_23
+#define PB_24 QK_PROGRAMMABLE_BUTTON_24
+#define PB_25 QK_PROGRAMMABLE_BUTTON_25
+#define PB_26 QK_PROGRAMMABLE_BUTTON_26
+#define PB_27 QK_PROGRAMMABLE_BUTTON_27
+#define PB_28 QK_PROGRAMMABLE_BUTTON_28
+#define PB_29 QK_PROGRAMMABLE_BUTTON_29
+#define PB_30 QK_PROGRAMMABLE_BUTTON_30
+#define PB_31 QK_PROGRAMMABLE_BUTTON_31
+#define PB_32 QK_PROGRAMMABLE_BUTTON_32
+#define QK_PROGRAMMABLE_BUTTON_MIN QK_PROGRAMMABLE_BUTTON_1
+#define QK_PROGRAMMABLE_BUTTON_MAX QK_PROGRAMMABLE_BUTTON_32
#include "quantum_keycodes_legacy.h"
diff --git a/quantum/quantum_keycodes_legacy.h b/quantum/quantum_keycodes_legacy.h
index 51380d9c50..3baf37d378 100644
--- a/quantum/quantum_keycodes_legacy.h
+++ b/quantum/quantum_keycodes_legacy.h
@@ -3,14 +3,111 @@
// clang-format off
// Deprecated Quantum keycodes
+#define KC_LEAD QK_LEADER
+#define KC_LOCK QK_LOCK
-#define RESET QK_BOOTLOADER
-#define DEBUG QK_DEBUG_TOGGLE
-#define GRAVE_ESC QK_GRAVE_ESCAPE
-#define EEPROM_RESET QK_CLEAR_EEPROM
+#define KC_ASUP QK_AUTO_SHIFT_UP
+#define KC_ASDN QK_AUTO_SHIFT_DOWN
+#define KC_ASRP QK_AUTO_SHIFT_REPORT
+#define KC_ASTG QK_AUTO_SHIFT_TOGGLE
+#define KC_ASON QK_AUTO_SHIFT_ON
+#define KC_ASOFF QK_AUTO_SHIFT_OFF
-#define KC_GESC QK_GRAVE_ESCAPE
-#define EEP_RST QK_CLEAR_EEPROM
+#define VLK_TOG QK_VELOCIKEY_TOGGLE
+#define CAPSWRD QK_CAPS_WORD_TOGGLE
+#define CAPS_WORD QK_CAPS_WORD_TOGGLE
+
+#define KEY_OVERRIDE_TOGGLE QK_KEY_OVERRIDE_TOGGLE
+#define KEY_OVERRIDE_ON QK_KEY_OVERRIDE_ON
+#define KEY_OVERRIDE_OFF QK_KEY_OVERRIDE_OFF
+
+#define ONESHOT_ENABLE QK_ONE_SHOT_ON
+#define ONESHOT_DISABLE QK_ONE_SHOT_OFF
+#define ONESHOT_TOGGLE QK_ONE_SHOT_TOGGLE
+
+#define CMB_ON QK_COMBO_ON
+#define CMB_OFF QK_COMBO_OFF
+#define CMB_TOG QK_COMBO_TOGGLE
+
+#define PROGRAMMABLE_BUTTON_1 QK_PROGRAMMABLE_BUTTON_1
+#define PROGRAMMABLE_BUTTON_2 QK_PROGRAMMABLE_BUTTON_2
+#define PROGRAMMABLE_BUTTON_3 QK_PROGRAMMABLE_BUTTON_3
+#define PROGRAMMABLE_BUTTON_4 QK_PROGRAMMABLE_BUTTON_4
+#define PROGRAMMABLE_BUTTON_5 QK_PROGRAMMABLE_BUTTON_5
+#define PROGRAMMABLE_BUTTON_6 QK_PROGRAMMABLE_BUTTON_6
+#define PROGRAMMABLE_BUTTON_7 QK_PROGRAMMABLE_BUTTON_7
+#define PROGRAMMABLE_BUTTON_8 QK_PROGRAMMABLE_BUTTON_8
+#define PROGRAMMABLE_BUTTON_9 QK_PROGRAMMABLE_BUTTON_9
+#define PROGRAMMABLE_BUTTON_10 QK_PROGRAMMABLE_BUTTON_10
+#define PROGRAMMABLE_BUTTON_11 QK_PROGRAMMABLE_BUTTON_11
+#define PROGRAMMABLE_BUTTON_12 QK_PROGRAMMABLE_BUTTON_12
+#define PROGRAMMABLE_BUTTON_13 QK_PROGRAMMABLE_BUTTON_13
+#define PROGRAMMABLE_BUTTON_14 QK_PROGRAMMABLE_BUTTON_14
+#define PROGRAMMABLE_BUTTON_15 QK_PROGRAMMABLE_BUTTON_15
+#define PROGRAMMABLE_BUTTON_16 QK_PROGRAMMABLE_BUTTON_16
+#define PROGRAMMABLE_BUTTON_17 QK_PROGRAMMABLE_BUTTON_17
+#define PROGRAMMABLE_BUTTON_18 QK_PROGRAMMABLE_BUTTON_18
+#define PROGRAMMABLE_BUTTON_19 QK_PROGRAMMABLE_BUTTON_19
+#define PROGRAMMABLE_BUTTON_20 QK_PROGRAMMABLE_BUTTON_20
+#define PROGRAMMABLE_BUTTON_21 QK_PROGRAMMABLE_BUTTON_21
+#define PROGRAMMABLE_BUTTON_22 QK_PROGRAMMABLE_BUTTON_22
+#define PROGRAMMABLE_BUTTON_23 QK_PROGRAMMABLE_BUTTON_23
+#define PROGRAMMABLE_BUTTON_24 QK_PROGRAMMABLE_BUTTON_24
+#define PROGRAMMABLE_BUTTON_25 QK_PROGRAMMABLE_BUTTON_25
+#define PROGRAMMABLE_BUTTON_26 QK_PROGRAMMABLE_BUTTON_26
+#define PROGRAMMABLE_BUTTON_27 QK_PROGRAMMABLE_BUTTON_27
+#define PROGRAMMABLE_BUTTON_28 QK_PROGRAMMABLE_BUTTON_28
+#define PROGRAMMABLE_BUTTON_29 QK_PROGRAMMABLE_BUTTON_29
+#define PROGRAMMABLE_BUTTON_30 QK_PROGRAMMABLE_BUTTON_30
+#define PROGRAMMABLE_BUTTON_31 QK_PROGRAMMABLE_BUTTON_31
+#define PROGRAMMABLE_BUTTON_32 QK_PROGRAMMABLE_BUTTON_32
+
+#define JS_BUTTON0 QK_JOYSTICK_BUTTON_0
+#define JS_BUTTON1 QK_JOYSTICK_BUTTON_1
+#define JS_BUTTON2 QK_JOYSTICK_BUTTON_2
+#define JS_BUTTON3 QK_JOYSTICK_BUTTON_3
+#define JS_BUTTON4 QK_JOYSTICK_BUTTON_4
+#define JS_BUTTON5 QK_JOYSTICK_BUTTON_5
+#define JS_BUTTON6 QK_JOYSTICK_BUTTON_6
+#define JS_BUTTON7 QK_JOYSTICK_BUTTON_7
+#define JS_BUTTON8 QK_JOYSTICK_BUTTON_8
+#define JS_BUTTON9 QK_JOYSTICK_BUTTON_9
+#define JS_BUTTON10 QK_JOYSTICK_BUTTON_10
+#define JS_BUTTON11 QK_JOYSTICK_BUTTON_11
+#define JS_BUTTON12 QK_JOYSTICK_BUTTON_12
+#define JS_BUTTON13 QK_JOYSTICK_BUTTON_13
+#define JS_BUTTON14 QK_JOYSTICK_BUTTON_14
+#define JS_BUTTON15 QK_JOYSTICK_BUTTON_15
+#define JS_BUTTON16 QK_JOYSTICK_BUTTON_16
+#define JS_BUTTON17 QK_JOYSTICK_BUTTON_17
+#define JS_BUTTON18 QK_JOYSTICK_BUTTON_18
+#define JS_BUTTON19 QK_JOYSTICK_BUTTON_19
+#define JS_BUTTON20 QK_JOYSTICK_BUTTON_20
+#define JS_BUTTON21 QK_JOYSTICK_BUTTON_21
+#define JS_BUTTON22 QK_JOYSTICK_BUTTON_22
+#define JS_BUTTON23 QK_JOYSTICK_BUTTON_23
+#define JS_BUTTON24 QK_JOYSTICK_BUTTON_24
+#define JS_BUTTON25 QK_JOYSTICK_BUTTON_25
+#define JS_BUTTON26 QK_JOYSTICK_BUTTON_26
+#define JS_BUTTON27 QK_JOYSTICK_BUTTON_27
+#define JS_BUTTON28 QK_JOYSTICK_BUTTON_28
+#define JS_BUTTON29 QK_JOYSTICK_BUTTON_29
+#define JS_BUTTON30 QK_JOYSTICK_BUTTON_30
+#define JS_BUTTON31 QK_JOYSTICK_BUTTON_31
+
+#define SECURE_LOCK QK_SECURE_LOCK
+#define SECURE_UNLOCK QK_SECURE_UNLOCK
+#define SECURE_TOGGLE QK_SECURE_TOGGLE
+#define SECURE_REQUEST QK_SECURE_REQUEST
+
+#define KC_LSPO QK_SPACE_CADET_LEFT_SHIFT_PARENTHESIS_OPEN
+#define KC_RSPC QK_SPACE_CADET_RIGHT_SHIFT_PARENTHESIS_CLOSE
+#define KC_LCPO QK_SPACE_CADET_LEFT_CTRL_PARENTHESIS_OPEN
+#define KC_RCPC QK_SPACE_CADET_RIGHT_CTRL_PARENTHESIS_CLOSE
+#define KC_LAPO QK_SPACE_CADET_LEFT_ALT_PARENTHESIS_OPEN
+#define KC_RAPC QK_SPACE_CADET_RIGHT_ALT_PARENTHESIS_CLOSE
+#define KC_SFTENT QK_SPACE_CADET_RIGHT_SHIFT_ENTER
#define TERM_ON _Static_assert(false, "The Terminal feature has been removed from QMK. Please remove use of TERM_ON/TERM_OFF from your keymap.")
-#define TERM_OFF _Static_assert(false, "The Terminal feature has been removed from QMK.. Please remove use of TERM_ON/TERM_OFF from your keymap.") \ No newline at end of file
+#define TERM_OFF _Static_assert(false, "The Terminal feature has been removed from QMK.. Please remove use of TERM_ON/TERM_OFF from your keymap.")
+// #define RESET _Static_assert(false, "The RESET keycode has been removed from QMK.. Please remove use from your keymap.")
diff --git a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h
index 31dffcbc5a..69bf265d14 100644
--- a/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h
+++ b/quantum/rgb_matrix/animations/jellybean_raindrops_anim.h
@@ -13,7 +13,7 @@ bool JELLYBEAN_RAINDROPS(effect_params_t* params) {
if (!params->init) {
// Change one LED every tick, make sure speed is not 0
if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 5 == 0) {
- jellybean_raindrops_set_color(rand() % DRIVER_LED_TOTAL, params);
+ jellybean_raindrops_set_color(rand() % RGB_MATRIX_LED_COUNT, params);
}
return false;
}
diff --git a/quantum/rgb_matrix/animations/pixel_flow_anim.h b/quantum/rgb_matrix/animations/pixel_flow_anim.h
index 714f5d174e..8628c3c2ec 100644
--- a/quantum/rgb_matrix/animations/pixel_flow_anim.h
+++ b/quantum/rgb_matrix/animations/pixel_flow_anim.h
@@ -7,7 +7,7 @@ RGB_MATRIX_EFFECT(PIXEL_FLOW)
static bool PIXEL_FLOW(effect_params_t* params) {
// LED state array
- static RGB led[DRIVER_LED_TOTAL];
+ static RGB led[RGB_MATRIX_LED_COUNT];
static uint32_t wait_timer = 0;
if (wait_timer > g_rgb_timer) {
@@ -21,7 +21,7 @@ static bool PIXEL_FLOW(effect_params_t* params) {
if (params->init) {
// Clear LEDs and fill the state array
rgb_matrix_set_color_all(0, 0, 0);
- for (uint8_t j = 0; j < DRIVER_LED_TOTAL; ++j) {
+ for (uint8_t j = 0; j < RGB_MATRIX_LED_COUNT; ++j) {
led[j] = (random8() & 2) ? (RGB){0, 0, 0} : hsv_to_rgb((HSV){random8(), qadd8(random8() >> 1, 127), rgb_matrix_config.hsv.v});
}
}
diff --git a/quantum/rgb_matrix/animations/pixel_rain_anim.h b/quantum/rgb_matrix/animations/pixel_rain_anim.h
index ce2528a26d..fded60340f 100644
--- a/quantum/rgb_matrix/animations/pixel_rain_anim.h
+++ b/quantum/rgb_matrix/animations/pixel_rain_anim.h
@@ -41,7 +41,7 @@ static bool PIXEL_RAIN(effect_params_t* params) {
RGB_MATRIX_USE_LIMITS(led_min, led_max);
if (g_rgb_timer > wait_timer) {
- rain_pixel(mod8(random8(), DRIVER_LED_TOTAL), params, random8() & 2);
+ rain_pixel(mod8(random8(), RGB_MATRIX_LED_COUNT), params, random8() & 2);
}
return rgb_matrix_check_finished_leds(led_max);
}
diff --git a/quantum/rgb_matrix/animations/raindrops_anim.h b/quantum/rgb_matrix/animations/raindrops_anim.h
index a508e51183..6b92d649ad 100644
--- a/quantum/rgb_matrix/animations/raindrops_anim.h
+++ b/quantum/rgb_matrix/animations/raindrops_anim.h
@@ -24,7 +24,7 @@ bool RAINDROPS(effect_params_t* params) {
if (!params->init) {
// Change one LED every tick, make sure speed is not 0
if (scale16by8(g_rgb_timer, qadd8(rgb_matrix_config.speed, 16)) % 10 == 0) {
- raindrops_set_color(random8() % DRIVER_LED_TOTAL, params);
+ raindrops_set_color(random8() % RGB_MATRIX_LED_COUNT, params);
}
} else {
for (int i = led_min; i < led_max; i++) {
diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c
index 2730686839..539ca0e100 100644
--- a/quantum/rgb_matrix/rgb_matrix.c
+++ b/quantum/rgb_matrix/rgb_matrix.c
@@ -56,12 +56,8 @@ __attribute__((weak)) RGB rgb_matrix_hsv_to_rgb(HSV hsv) {
// -----End rgb effect includes macros-------
// ------------------------------------------
-#if defined(RGB_DISABLE_AFTER_TIMEOUT) && !defined(RGB_DISABLE_TIMEOUT)
-# define RGB_DISABLE_TIMEOUT (RGB_DISABLE_AFTER_TIMEOUT * 1200UL)
-#endif
-
-#ifndef RGB_DISABLE_TIMEOUT
-# define RGB_DISABLE_TIMEOUT 0
+#ifndef RGB_MATRIX_TIMEOUT
+# define RGB_MATRIX_TIMEOUT 0
#endif
#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
@@ -126,9 +122,9 @@ static uint8_t rgb_last_enable = UINT8_MAX;
static uint8_t rgb_last_effect = UINT8_MAX;
static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false};
static rgb_task_states rgb_task_state = SYNCING;
-#if RGB_DISABLE_TIMEOUT > 0
+#if RGB_MATRIX_TIMEOUT > 0
static uint32_t rgb_anykey_timer;
-#endif // RGB_DISABLE_TIMEOUT > 0
+#endif // RGB_MATRIX_TIMEOUT > 0
// double buffers
static uint32_t rgb_timer_buffer;
@@ -202,7 +198,7 @@ void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
- for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++)
+ for (uint8_t i = 0; i < RGB_MATRIX_LED_COUNT; i++)
rgb_matrix_set_color(i, red, green, blue);
#else
rgb_matrix_driver.set_color_all(red, green, blue);
@@ -213,9 +209,9 @@ void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) {
#ifndef RGB_MATRIX_SPLIT
if (!is_keyboard_master()) return;
#endif
-#if RGB_DISABLE_TIMEOUT > 0
+#if RGB_MATRIX_TIMEOUT > 0
rgb_anykey_timer = 0;
-#endif // RGB_DISABLE_TIMEOUT > 0
+#endif // RGB_MATRIX_TIMEOUT > 0
#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
uint8_t led[LED_HITS_TO_REMEMBER];
@@ -296,17 +292,17 @@ static bool rgb_matrix_none(effect_params_t *params) {
}
static void rgb_task_timers(void) {
-#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0
+#if defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_MATRIX_TIMEOUT > 0
uint32_t deltaTime = sync_timer_elapsed32(rgb_timer_buffer);
-#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_DISABLE_TIMEOUT > 0
+#endif // defined(RGB_MATRIX_KEYREACTIVE_ENABLED) || RGB_MATRIX_TIMEOUT > 0
rgb_timer_buffer = sync_timer_read32();
// Update double buffer timers
-#if RGB_DISABLE_TIMEOUT > 0
+#if RGB_MATRIX_TIMEOUT > 0
if (rgb_anykey_timer + deltaTime <= UINT32_MAX) {
rgb_anykey_timer += deltaTime;
}
-#endif // RGB_DISABLE_TIMEOUT > 0
+#endif // RGB_MATRIX_TIMEOUT > 0
// Update double buffer last hit timers
#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
@@ -419,9 +415,9 @@ void rgb_matrix_task(void) {
// Ideally we would also stop sending zeros to the LED driver PWM buffers
// while suspended and just do a software shutdown. This is a cheap hack for now.
bool suspend_backlight = suspend_state ||
-#if RGB_DISABLE_TIMEOUT > 0
- (rgb_anykey_timer > (uint32_t)RGB_DISABLE_TIMEOUT) ||
-#endif // RGB_DISABLE_TIMEOUT > 0
+#if RGB_MATRIX_TIMEOUT > 0
+ (rgb_anykey_timer > (uint32_t)RGB_MATRIX_TIMEOUT) ||
+#endif // RGB_MATRIX_TIMEOUT > 0
false;
uint8_t effect = suspend_backlight || !rgb_matrix_config.enable ? 0 : rgb_matrix_config.mode;
@@ -448,12 +444,15 @@ void rgb_matrix_task(void) {
void rgb_matrix_indicators(void) {
rgb_matrix_indicators_kb();
- rgb_matrix_indicators_user();
}
-__attribute__((weak)) void rgb_matrix_indicators_kb(void) {}
+__attribute__((weak)) bool rgb_matrix_indicators_kb(void) {
+ return rgb_matrix_indicators_user();
+}
-__attribute__((weak)) void rgb_matrix_indicators_user(void) {}
+__attribute__((weak)) bool rgb_matrix_indicators_user(void) {
+ return true;
+}
void rgb_matrix_indicators_advanced(effect_params_t *params) {
/* special handling is needed for "params->iter", since it's already been incremented.
@@ -461,21 +460,24 @@ void rgb_matrix_indicators_advanced(effect_params_t *params) {
* and not sure which would be better. Otherwise, this should be called from
* rgb_task_render, right before the iter++ line.
*/
-#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
+#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT
uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * (params->iter - 1);
uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT;
- if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
+ if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT;
#else
uint8_t min = 0;
- uint8_t max = DRIVER_LED_TOTAL;
+ uint8_t max = RGB_MATRIX_LED_COUNT;
#endif
rgb_matrix_indicators_advanced_kb(min, max);
- rgb_matrix_indicators_advanced_user(min, max);
}
-__attribute__((weak)) void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {}
+__attribute__((weak)) bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max) {
+ return rgb_matrix_indicators_advanced_user(led_min, led_max);
+}
-__attribute__((weak)) void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {}
+__attribute__((weak)) bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
+ return true;
+}
void rgb_matrix_init(void) {
rgb_matrix_driver.init();
diff --git a/quantum/rgb_matrix/rgb_matrix.h b/quantum/rgb_matrix/rgb_matrix.h
index fc9fc3e020..62078f6e60 100644
--- a/quantum/rgb_matrix/rgb_matrix.h
+++ b/quantum/rgb_matrix/rgb_matrix.h
@@ -47,15 +47,15 @@
#endif
#ifndef RGB_MATRIX_LED_PROCESS_LIMIT
-# define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
+# define RGB_MATRIX_LED_PROCESS_LIMIT (RGB_MATRIX_LED_COUNT + 4) / 5
#endif
-#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
+#if defined(RGB_MATRIX_LED_PROCESS_LIMIT) && RGB_MATRIX_LED_PROCESS_LIMIT > 0 && RGB_MATRIX_LED_PROCESS_LIMIT < RGB_MATRIX_LED_COUNT
# if defined(RGB_MATRIX_SPLIT)
# define RGB_MATRIX_USE_LIMITS(min, max) \
uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \
- if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL; \
+ if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT; \
uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \
if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \
if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0];
@@ -63,25 +63,25 @@
# define RGB_MATRIX_USE_LIMITS(min, max) \
uint8_t min = RGB_MATRIX_LED_PROCESS_LIMIT * params->iter; \
uint8_t max = min + RGB_MATRIX_LED_PROCESS_LIMIT; \
- if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
+ if (max > RGB_MATRIX_LED_COUNT) max = RGB_MATRIX_LED_COUNT;
# endif
#else
# if defined(RGB_MATRIX_SPLIT)
# define RGB_MATRIX_USE_LIMITS(min, max) \
uint8_t min = 0; \
- uint8_t max = DRIVER_LED_TOTAL; \
+ uint8_t max = RGB_MATRIX_LED_COUNT; \
const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT; \
if (is_keyboard_left() && (max > k_rgb_matrix_split[0])) max = k_rgb_matrix_split[0]; \
if (!(is_keyboard_left()) && (min < k_rgb_matrix_split[0])) min = k_rgb_matrix_split[0];
# else
# define RGB_MATRIX_USE_LIMITS(min, max) \
uint8_t min = 0; \
- uint8_t max = DRIVER_LED_TOTAL;
+ uint8_t max = RGB_MATRIX_LED_COUNT;
# endif
#endif
#define RGB_MATRIX_INDICATOR_SET_COLOR(i, r, g, b) \
- if (i >= led_min && i <= led_max) { \
+ if (i >= led_min && i < led_max) { \
rgb_matrix_set_color(i, r, g, b); \
}
@@ -129,12 +129,12 @@ void rgb_matrix_task(void);
// This runs after another backlight effect and replaces
// colors already set
void rgb_matrix_indicators(void);
-void rgb_matrix_indicators_kb(void);
-void rgb_matrix_indicators_user(void);
+bool rgb_matrix_indicators_kb(void);
+bool rgb_matrix_indicators_user(void);
void rgb_matrix_indicators_advanced(effect_params_t *params);
-void rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
-void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
+bool rgb_matrix_indicators_advanced_kb(uint8_t led_min, uint8_t led_max);
+bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max);
void rgb_matrix_init(void);
@@ -182,8 +182,8 @@ void rgb_matrix_increase_speed_noeeprom(void);
void rgb_matrix_decrease_speed(void);
void rgb_matrix_decrease_speed_noeeprom(void);
led_flags_t rgb_matrix_get_flags(void);
-led_flags_t rgb_matrix_get_flags_noeeprom(void);
void rgb_matrix_set_flags(led_flags_t flags);
+void rgb_matrix_set_flags_noeeprom(led_flags_t flags);
#ifndef RGBLIGHT_ENABLE
# define eeconfig_update_rgblight_current eeconfig_update_rgb_matrix
@@ -246,9 +246,9 @@ static inline bool rgb_matrix_check_finished_leds(uint8_t led_idx) {
uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT;
return led_idx < k_rgb_matrix_split[0];
} else
- return led_idx < DRIVER_LED_TOTAL;
+ return led_idx < RGB_MATRIX_LED_COUNT;
#else
- return led_idx < DRIVER_LED_TOTAL;
+ return led_idx < RGB_MATRIX_LED_COUNT;
#endif
}
diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c
index 27fa7369bf..5b81915845 100644
--- a/quantum/rgb_matrix/rgb_matrix_drivers.c
+++ b/quantum/rgb_matrix/rgb_matrix_drivers.c
@@ -76,6 +76,12 @@ static void init(void) {
IS31FL3737_init(DRIVER_ADDR_1);
# if defined(DRIVER_ADDR_2)
IS31FL3737_init(DRIVER_ADDR_2);
+# if defined(DRIVER_ADDR_3)
+ IS31FL3737_init(DRIVER_ADDR_3);
+# if defined(DRIVER_ADDR_4)
+ IS31FL3737_init(DRIVER_ADDR_4);
+# endif
+# endif
# endif
# elif defined(IS31FL3741)
@@ -106,7 +112,7 @@ static void init(void) {
# endif
# endif
- for (int index = 0; index < DRIVER_LED_TOTAL; index++) {
+ for (int index = 0; index < RGB_MATRIX_LED_COUNT; index++) {
bool enabled = true;
// This only caches it for later
@@ -154,6 +160,12 @@ static void init(void) {
IS31FL3737_update_led_control_registers(DRIVER_ADDR_1, 0);
# if defined(DRIVER_ADDR_2)
IS31FL3737_update_led_control_registers(DRIVER_ADDR_2, 1);
+# if defined(DRIVER_ADDR_3)
+ IS31FL3737_update_led_control_registers(DRIVER_ADDR_3, 2);
+# if defined(DRIVER_ADDR_4)
+ IS31FL3737_update_led_control_registers(DRIVER_ADDR_4, 3);
+# endif
+# endif
# endif
# elif defined(IS31FL3741)
@@ -235,6 +247,12 @@ static void flush(void) {
IS31FL3737_update_pwm_buffers(DRIVER_ADDR_1, 0);
# if defined(DRIVER_ADDR_2)
IS31FL3737_update_pwm_buffers(DRIVER_ADDR_2, 1);
+# if defined(DRIVER_ADDR_3)
+ IS31FL3737_update_pwm_buffers(DRIVER_ADDR_3, 2);
+# if defined(DRIVER_ADDR_4)
+ IS31FL3737_update_pwm_buffers(DRIVER_ADDR_4, 3);
+# endif
+# endif
# endif
}
@@ -336,13 +354,13 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
# endif
// LED color buffer
-LED_TYPE rgb_matrix_ws2812_array[DRIVER_LED_TOTAL];
+LED_TYPE rgb_matrix_ws2812_array[RGB_MATRIX_LED_COUNT];
static void init(void) {}
static void flush(void) {
// Assumes use of RGB_DI_PIN
- ws2812_setleds(rgb_matrix_ws2812_array, DRIVER_LED_TOTAL);
+ ws2812_setleds(rgb_matrix_ws2812_array, RGB_MATRIX_LED_COUNT);
}
// Set an led in the buffer to a color
@@ -369,7 +387,7 @@ static inline void setled(int i, uint8_t r, uint8_t g, uint8_t b) {
}
static void setled_all(uint8_t r, uint8_t g, uint8_t b) {
- for (int i = 0; i < sizeof(rgb_matrix_ws2812_array) / sizeof(rgb_matrix_ws2812_array[0]); i++) {
+ for (int i = 0; i < ARRAY_SIZE(rgb_matrix_ws2812_array); i++) {
setled(i, r, g, b);
}
}
diff --git a/quantum/rgb_matrix/rgb_matrix_types.h b/quantum/rgb_matrix/rgb_matrix_types.h
index d0ac4e4466..eea603c41c 100644
--- a/quantum/rgb_matrix/rgb_matrix_types.h
+++ b/quantum/rgb_matrix/rgb_matrix_types.h
@@ -78,8 +78,8 @@ typedef struct PACKED {
typedef struct PACKED {
uint8_t matrix_co[MATRIX_ROWS][MATRIX_COLS];
- led_point_t point[DRIVER_LED_TOTAL];
- uint8_t flags[DRIVER_LED_TOTAL];
+ led_point_t point[RGB_MATRIX_LED_COUNT];
+ uint8_t flags[RGB_MATRIX_LED_COUNT];
} led_config_t;
typedef union {
diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c
index e5d3a98bea..37cd7a66ab 100644
--- a/quantum/rgblight/rgblight.c
+++ b/quantum/rgblight/rgblight.c
@@ -16,7 +16,6 @@
#include <math.h>
#include <string.h>
#include <stdlib.h>
-#include "wait.h"
#include "progmem.h"
#include "sync_timer.h"
#include "rgblight.h"
@@ -410,7 +409,6 @@ void rgblight_disable(void) {
dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
rgblight_timer_disable();
RGBLIGHT_SPLIT_SET_CHANGE_MODE;
- wait_ms(50);
rgblight_set();
}
@@ -419,7 +417,6 @@ void rgblight_disable_noeeprom(void) {
dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
rgblight_timer_disable();
RGBLIGHT_SPLIT_SET_CHANGE_MODE;
- wait_ms(50);
rgblight_set();
}
@@ -526,10 +523,19 @@ void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) {
void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) {
if (rgblight_config.enable) {
+#ifdef RGBLIGHT_SPLIT
+ if (rgblight_config.hue != hue || rgblight_config.sat != sat || rgblight_config.val != val) {
+ RGBLIGHT_SPLIT_SET_CHANGE_HSVS;
+ }
+#endif
rgblight_status.base_mode = mode_base_table[rgblight_config.mode];
if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) {
// same static color
LED_TYPE tmp_led;
+#ifdef RGBLIGHT_LAYERS_RETAIN_VAL
+ // needed for rgblight_layers_write() to get the new val, since it reads rgblight_config.val
+ rgblight_config.val = val;
+#endif
sethsv(hue, sat, val, &tmp_led);
rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
} else {
@@ -571,15 +577,14 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w
dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range);
sethsv(_hue, sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]);
}
+# ifdef RGBLIGHT_LAYERS_RETAIN_VAL
+ // needed for rgblight_layers_write() to get the new val, since it reads rgblight_config.val
+ rgblight_config.val = val;
+# endif
rgblight_set();
}
#endif
}
-#ifdef RGBLIGHT_SPLIT
- if (rgblight_config.hue != hue || rgblight_config.sat != sat || rgblight_config.val != val) {
- RGBLIGHT_SPLIT_SET_CHANGE_HSVS;
- }
-#endif
rgblight_config.hue = hue;
rgblight_config.sat = sat;
rgblight_config.val = val;
@@ -704,7 +709,6 @@ void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8
#endif
}
rgblight_set();
- wait_ms(1);
}
void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
diff --git a/quantum/rgblight/rgblight.h b/quantum/rgblight/rgblight.h
index a08b9a7b6b..46e8e07212 100644
--- a/quantum/rgblight/rgblight.h
+++ b/quantum/rgblight/rgblight.h
@@ -181,7 +181,6 @@ enum RGBLIGHT_EFFECT_MODE {
#include "eeconfig.h"
#include "ws2812.h"
#include "color.h"
-#include "rgblight_list.h"
#ifdef RGBLIGHT_LAYERS
typedef struct {
diff --git a/quantum/rgblight/rgblight_list.h b/quantum/rgblight/rgblight_list.h
deleted file mode 100644
index 0fd68b75f3..0000000000
--- a/quantum/rgblight/rgblight_list.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/* Copyright 2018 Jack Humbert
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-#pragma once
-
-#include "color.h"
-
-/*
-########################################################################################
-## ##
-## ##
-## ##
-## The functions below have been deprecated and may be removed in a future release. ##
-## ##
-## Please use the values in color.h with the RGB functions. ##
-## ##
-## ##
-## ##
-########################################################################################
-*/
-
-/* SET RGB List */
-#define rgblight_setrgb_white() rgblight_setrgb(RGB_WHITE)
-#define rgblight_setrgb_red() rgblight_setrgb(RGB_RED)
-#define rgblight_setrgb_coral() rgblight_setrgb(RGB_CORAL)
-#define rgblight_setrgb_orange() rgblight_setrgb(RGB_ORANGE)
-#define rgblight_setrgb_goldenrod() rgblight_setrgb(RGB_GOLDENROD)
-#define rgblight_setrgb_gold() rgblight_setrgb(RGB_GOLD)
-#define rgblight_setrgb_yellow() rgblight_setrgb(RGB_YELLOW)
-#define rgblight_setrgb_chartreuse() rgblight_setrgb(RGB_CHARTREUSE)
-#define rgblight_setrgb_green() rgblight_setrgb(RGB_GREEN)
-#define rgblight_setrgb_springgreen() rgblight_setrgb(RGB_SPRINGGREEN)
-#define rgblight_setrgb_turquoise() rgblight_setrgb(RGB_TURQUOISE)
-#define rgblight_setrgb_teal() rgblight_setrgb(RGB_TEAL)
-#define rgblight_setrgb_cyan() rgblight_setrgb(RGB_CYAN)
-#define rgblight_setrgb_azure() rgblight_setrgb(RGB_AZURE)
-#define rgblight_setrgb_blue() rgblight_setrgb(RGB_BLUE)
-#define rgblight_setrgb_purple() rgblight_setrgb(RGB_PURPLE)
-#define rgblight_setrgb_magenta() rgblight_setrgb(RGB_MAGENTA)
-#define rgblight_setrgb_pink() rgblight_setrgb(RGB_PINK)
-
-/* SET RGB List */
-#define rgblight_setrgb_white_at(at) rgblight_setrgb_at(RGB_WHITE, at)
-#define rgblight_setrgb_red_at(at) rgblight_setrgb_at(RGB_RED, at)
-#define rgblight_setrgb_coral_at(at) rgblight_setrgb_at(RGB_CORAL, at)
-#define rgblight_setrgb_orange_at(at) rgblight_setrgb_at(RGB_ORANGE at)
-#define rgblight_setrgb_goldenrod_at(at) rgblight_setrgb_at(RGB_GOLDENROD, at)
-#define rgblight_setrgb_gold_at(at) rgblight_setrgb_at(RGB_GOLD, at)
-#define rgblight_setrgb_yellow_at(at) rgblight_setrgb_at(RGB_YELLOW, at)
-#define rgblight_setrgb_chartreuse_at(at) rgblight_setrgb_at(RGB_CHARTREUSE, at)
-#define rgblight_setrgb_green_at(at) rgblight_setrgb_at(RGB_GREEN, at)
-#define rgblight_setrgb_springgreen_at(at) rgblight_setrgb_at(RGB_SPRINGGREEN, at)
-#define rgblight_setrgb_turquoise_at(at) rgblight_setrgb_at(RGB_TURQUOISE, at)
-#define rgblight_setrgb_teal_at(at) rgblight_setrgb_at(RGB_TEAL, at)
-#define rgblight_setrgb_cyan_at(at) rgblight_setrgb_at(RGB_CYAN, at)
-#define rgblight_setrgb_azure_at(at) rgblight_setrgb_at(RGB_AZURE, at)
-#define rgblight_setrgb_blue_at(at) rgblight_setrgb_at(RGB_BLUE, at)
-#define rgblight_setrgb_purple_at(at) rgblight_setrgb_at(RGB_PURPLE, at)
-#define rgblight_setrgb_magenta_at(at) rgblight_setrgb_at(RGB_MAGENTA, at)
-#define rgblight_setrgb_pink_at(at) rgblight_setrgb_at(RGB_PINK, at)
-
-/* SET HSV List */
-#define rgblight_sethsv_white() rgblight_sethsv(HSV_WHITE)
-#define rgblight_sethsv_red() rgblight_sethsv(HSV_RED)
-#define rgblight_sethsv_coral() rgblight_sethsv(HSV_CORAL)
-#define rgblight_sethsv_orange() rgblight_sethsv(HSV_ORANGE)
-#define rgblight_sethsv_goldenrod() rgblight_sethsv(HSV_GOLDENROD)
-#define rgblight_sethsv_gold() rgblight_sethsv(HSV_GOLD)
-#define rgblight_sethsv_yellow() rgblight_sethsv(HSV_YELLOW)
-#define rgblight_sethsv_chartreuse() rgblight_sethsv(HSV_CHARTREUSE)
-#define rgblight_sethsv_green() rgblight_sethsv(HSV_GREEN)
-#define rgblight_sethsv_springgreen() rgblight_sethsv(HSV_SPRINGGREEN)
-#define rgblight_sethsv_turquoise() rgblight_sethsv(HSV_TURQUOISE)
-#define rgblight_sethsv_teal() rgblight_sethsv(HSV_TEAL)
-#define rgblight_sethsv_cyan() rgblight_sethsv(HSV_CYAN)
-#define rgblight_sethsv_azure() rgblight_sethsv(HSV_AZURE)
-#define rgblight_sethsv_blue() rgblight_sethsv(HSV_BLUE)
-#define rgblight_sethsv_purple() rgblight_sethsv(HSV_PURPLE)
-#define rgblight_sethsv_magenta() rgblight_sethsv(HSV_MAGENTA)
-#define rgblight_sethsv_pink() rgblight_sethsv(HSV_PINK)
-
-/* SET HSV List */
-/* If you're doing layer indication, this is best, as it won't */
-/* write to the eeprom, since it's limited (very high value). */
-/* If you want to use modes with this (since you can), then you */
-/* want to use rgblight_mode_noeeprom(x) instead. */
-#define rgblight_sethsv_noeeprom_white() rgblight_sethsv_noeeprom(HSV_WHITE)
-#define rgblight_sethsv_noeeprom_red() rgblight_sethsv_noeeprom(HSV_RED)
-#define rgblight_sethsv_noeeprom_coral() rgblight_sethsv_noeeprom(HSV_CORAL)
-#define rgblight_sethsv_noeeprom_orange() rgblight_sethsv_noeeprom(HSV_ORANGE)
-#define rgblight_sethsv_noeeprom_goldenrod() rgblight_sethsv_noeeprom(HSV_GOLDENROD)
-#define rgblight_sethsv_noeeprom_gold() rgblight_sethsv_noeeprom(HSV_GOLD)
-#define rgblight_sethsv_noeeprom_yellow() rgblight_sethsv_noeeprom(HSV_YELLOW)
-#define rgblight_sethsv_noeeprom_chartreuse() rgblight_sethsv_noeeprom(HSV_CHARTREUSE)
-#define rgblight_sethsv_noeeprom_green() rgblight_sethsv_noeeprom(HSV_GREEN)
-#define rgblight_sethsv_noeeprom_springgreen() rgblight_sethsv_noeeprom(HSV_SPRINGGREEN)
-#define rgblight_sethsv_noeeprom_turquoise() rgblight_sethsv_noeeprom(HSV_TURQUOISE)
-#define rgblight_sethsv_noeeprom_teal() rgblight_sethsv_noeeprom(HSV_TEAL)
-#define rgblight_sethsv_noeeprom_cyan() rgblight_sethsv_noeeprom(HSV_CYAN)
-#define rgblight_sethsv_noeeprom_azure() rgblight_sethsv_noeeprom(HSV_AZURE)
-#define rgblight_sethsv_noeeprom_blue() rgblight_sethsv_noeeprom(HSV_BLUE)
-#define rgblight_sethsv_noeeprom_purple() rgblight_sethsv_noeeprom(HSV_PURPLE)
-#define rgblight_sethsv_noeeprom_magenta() rgblight_sethsv_noeeprom(HSV_MAGENTA)
-#define rgblight_sethsv_noeeprom_pink() rgblight_sethsv_noeeprom(HSV_PINK)
-
-/* SET HSV List */
-#define rgblight_sethsv_white_at(at) rgblight_sethsv_at(HSV_WHITE, at)
-#define rgblight_sethsv_red_at(at) rgblight_sethsv_at(HSV_RED, at)
-#define rgblight_sethsv_coral_at(at) rgblight_sethsv_at(HSV_CORAL, at)
-#define rgblight_sethsv_orange_at(at) rgblight_sethsv_at(HSV_ORANGE, at)
-#define rgblight_sethsv_goldenrod_at(at) rgblight_sethsv_at(HSV_GOLDENROD, at)
-#define rgblight_sethsv_gold_at(at) rgblight_sethsv_at(HSV_GOLD, at)
-#define rgblight_sethsv_yellow_at(at) rgblight_sethsv_at(HSV_YELLOW, at)
-#define rgblight_sethsv_chartreuse_at(at) rgblight_sethsv_at(HSV_CHARTREUSE, at)
-#define rgblight_sethsv_green_at(at) rgblight_sethsv_at(HSV_GREEN, at)
-#define rgblight_sethsv_springgreen_at(at) rgblight_sethsv_at(HSV_SPRINGGREEN, at)
-#define rgblight_sethsv_turquoise_at(at) rgblight_sethsv_at(HSV_TURQUOISE, at)
-#define rgblight_sethsv_teal_at(at) rgblight_sethsv_at(HSV_TEAL, at)
-#define rgblight_sethsv_cyan_at(at) rgblight_sethsv_at(HSV_CYAN, at)
-#define rgblight_sethsv_azure_at(at) rgblight_sethsv_at(HSV_AZURE, at)
-#define rgblight_sethsv_blue_at(at) rgblight_sethsv_at(HSV_BLUE, at)
-#define rgblight_sethsv_purple_at(at) rgblight_sethsv_at(HSV_PURPLE, at)
-#define rgblight_sethsv_magenta_at(at) rgblight_sethsv_at(HSV_MAGENTA, at)
-#define rgblight_sethsv_pink_at(at) rgblight_sethsv_at(HSV_PINK, at)
diff --git a/quantum/secure.c b/quantum/secure.c
index f07f6af2cb..f2a567f31d 100644
--- a/quantum/secure.c
+++ b/quantum/secure.c
@@ -3,6 +3,7 @@
#include "secure.h"
#include "timer.h"
+#include "util.h"
#ifndef SECURE_UNLOCK_TIMEOUT
# define SECURE_UNLOCK_TIMEOUT 5000
@@ -59,7 +60,7 @@ void secure_activity_event(void) {
void secure_keypress_event(uint8_t row, uint8_t col) {
static const uint8_t sequence[][2] = SECURE_UNLOCK_SEQUENCE;
- static const uint8_t sequence_len = sizeof(sequence) / sizeof(sequence[0]);
+ static const uint8_t sequence_len = ARRAY_SIZE(sequence);
static uint8_t offset = 0;
if ((sequence[offset][0] == row) && (sequence[offset][1] == col)) {
diff --git a/quantum/send_string/send_string_keycodes.h b/quantum/send_string/send_string_keycodes.h
index 802d9a8240..f9e1c101ff 100644
--- a/quantum/send_string/send_string_keycodes.h
+++ b/quantum/send_string/send_string_keycodes.h
@@ -21,45 +21,53 @@
/* Punctuation */
#define X_ENT X_ENTER
#define X_ESC X_ESCAPE
-#define X_BSPC X_BSPACE
+#define X_BSPC X_BACKSPACE
#define X_SPC X_SPACE
#define X_MINS X_MINUS
#define X_EQL X_EQUAL
-#define X_LBRC X_LBRACKET
-#define X_RBRC X_RBRACKET
-#define X_BSLS X_BSLASH
+#define X_LBRC X_LEFT_BRACKET
+#define X_RBRC X_RIGHT_BRACKET
+#define X_BSLS X_BACKSLASH
#define X_NUHS X_NONUS_HASH
-#define X_SCLN X_SCOLON
+#define X_SCLN X_SEMICOLON
#define X_QUOT X_QUOTE
#define X_GRV X_GRAVE
#define X_COMM X_COMMA
#define X_SLSH X_SLASH
-#define X_NUBS X_NONUS_BSLASH
+#define X_NUBS X_NONUS_BACKSLASH
/* Lock Keys */
-#define X_CLCK X_CAPSLOCK
-#define X_CAPS X_CAPSLOCK
-#define X_SLCK X_SCROLLLOCK
-#define X_NLCK X_NUMLOCK
-#define X_LCAP X_LOCKING_CAPS
-#define X_LNUM X_LOCKING_NUM
-#define X_LSCR X_LOCKING_SCROLL
+#define X_CAPS X_CAPS_LOCK
+#define X_SCRL X_SCROLL_LOCK
+#define X_NUM X_NUM_LOCK
+#define X_LCAP X_LOCKING_CAPS_LOCK
+#define X_LNUM X_LOCKING_NUM_LOCK
+#define X_LSCR X_LOCKING_SCROLL_LOCK
/* Commands */
-#define X_PSCR X_PSCREEN
+#define X_PSCR X_PRINT_SCREEN
#define X_PAUS X_PAUSE
#define X_BRK X_PAUSE
#define X_INS X_INSERT
+#define X_PGUP X_PAGE_UP
#define X_DEL X_DELETE
-#define X_PGDN X_PGDOWN
+#define X_PGDN X_PAGE_DOWN
#define X_RGHT X_RIGHT
#define X_APP X_APPLICATION
#define X_EXEC X_EXECUTE
#define X_SLCT X_SELECT
#define X_AGIN X_AGAIN
#define X_PSTE X_PASTE
-#define X_ERAS X_ALT_ERASE
+#define X_ERAS X_ALTERNATE_ERASE
+#define X_SYRQ X_SYSTEM_REQUEST
+#define X_CNCL X_CANCEL
#define X_CLR X_CLEAR
+#define X_PRIR X_PRIOR
+#define X_RETN X_RETURN
+#define X_SEPR X_SEPARATOR
+#define X_CLAG X_CLEAR_AGAIN
+#define X_CRSL X_CRSEL
+#define X_EXSL X_EXSEL
/* Keypad */
#define X_PSLS X_KP_SLASH
@@ -81,30 +89,42 @@
#define X_PEQL X_KP_EQUAL
#define X_PCMM X_KP_COMMA
-/* Japanese specific */
-#define X_ZKHK X_GRAVE
-#define X_RO X_INT1
-#define X_KANA X_INT2
-#define X_JYEN X_INT3
-#define X_HENK X_INT4
-#define X_MHEN X_INT5
-
-/* Korean specific */
-#define X_HAEN X_LANG1
-#define X_HANJ X_LANG2
+/* Language Specific */
+#define X_INT1 X_INTERNATIONAL_1
+#define X_INT2 X_INTERNATIONAL_2
+#define X_INT3 X_INTERNATIONAL_3
+#define X_INT4 X_INTERNATIONAL_4
+#define X_INT5 X_INTERNATIONAL_5
+#define X_INT6 X_INTERNATIONAL_6
+#define X_INT7 X_INTERNATIONAL_7
+#define X_INT8 X_INTERNATIONAL_8
+#define X_INT9 X_INTERNATIONAL_9
+#define X_LNG1 X_LANGUAGE_1
+#define X_LNG2 X_LANGUAGE_2
+#define X_LNG3 X_LANGUAGE_3
+#define X_LNG4 X_LANGUAGE_4
+#define X_LNG5 X_LANGUAGE_5
+#define X_LNG6 X_LANGUAGE_6
+#define X_LNG7 X_LANGUAGE_7
+#define X_LNG8 X_LANGUAGE_8
+#define X_LNG9 X_LANGUAGE_9
/* Modifiers */
-#define X_LCTL X_LCTRL
-#define X_LSFT X_LSHIFT
-#define X_LOPT X_LALT
-#define X_LCMD X_LGUI
-#define X_LWIN X_LGUI
-#define X_RCTL X_RCTRL
-#define X_RSFT X_RSHIFT
-#define X_ALGR X_RALT
-#define X_ROPT X_RALT
-#define X_RCMD X_RGUI
-#define X_RWIN X_RGUI
+#define X_LCTL X_LEFT_CTRL
+#define X_LSFT X_LEFT_SHIFT
+#define X_LALT X_LEFT_ALT
+#define X_LOPT X_LEFT_ALT
+#define X_LGUI X_LEFT_GUI
+#define X_LCMD X_LEFT_GUI
+#define X_LWIN X_LEFT_GUI
+#define X_RCTL X_RIGHT_CTRL
+#define X_RSFT X_RIGHT_SHIFT
+#define X_RALT X_RIGHT_ALT
+#define X_ALGR X_RIGHT_ALT
+#define X_ROPT X_RIGHT_ALT
+#define X_RGUI X_RIGHT_GUI
+#define X_RCMD X_RIGHT_GUI
+#define X_RWIN X_RIGHT_GUI
/* Generic Desktop Page (0x01) */
#define X_PWR X_SYSTEM_POWER
@@ -134,10 +154,12 @@
#define X_MRWD X_MEDIA_REWIND
#define X_BRIU X_BRIGHTNESS_UP
#define X_BRID X_BRIGHTNESS_DOWN
+#define X_CPNL X_CONTROL_PANEL
+#define X_ASST X_ASSISTANT
/* System Specific */
#define X_BRMU X_PAUSE
-#define X_BRMD X_SCROLLLOCK
+#define X_BRMD X_SCROLL_LOCK
/* Mouse Keys */
#define X_MS_U X_MS_UP
@@ -149,6 +171,9 @@
#define X_BTN3 X_MS_BTN3
#define X_BTN4 X_MS_BTN4
#define X_BTN5 X_MS_BTN5
+#define X_BTN6 X_MS_BTN6
+#define X_BTN7 X_MS_BTN7
+#define X_BTN8 X_MS_BTN8
#define X_WH_U X_MS_WH_UP
#define X_WH_D X_MS_WH_DOWN
#define X_WH_L X_MS_WH_LEFT
@@ -158,244 +183,254 @@
#define X_ACL2 X_MS_ACCEL2
/* Keyboard/Keypad Page (0x07) */
-#define X_A 04
-#define X_B 05
-#define X_C 06
-#define X_D 07
-#define X_E 08
-#define X_F 09
-#define X_G 0a
-#define X_H 0b
-#define X_I 0c
-#define X_J 0d
-#define X_K 0e
-#define X_L 0f
-#define X_M 10
-#define X_N 11
-#define X_O 12
-#define X_P 13
-#define X_Q 14
-#define X_R 15
-#define X_S 16
-#define X_T 17
-#define X_U 18
-#define X_V 19
-#define X_W 1a
-#define X_X 1b
-#define X_Y 1c
-#define X_Z 1d
-#define X_1 1e
-#define X_2 1f
-#define X_3 20
-#define X_4 21
-#define X_5 22
-#define X_6 23
-#define X_7 24
-#define X_8 25
-#define X_9 26
-#define X_0 27
-#define X_ENTER 28
-#define X_ESCAPE 29
-#define X_BSPACE 2a
-#define X_TAB 2b
-#define X_SPACE 2c
-#define X_MINUS 2d
-#define X_EQUAL 2e
-#define X_LBRACKET 2f
-#define X_RBRACKET 30
-#define X_BSLASH 31
-#define X_NONUS_HASH 32
-#define X_SCOLON 33
-#define X_QUOTE 34
-#define X_GRAVE 35
-#define X_COMMA 36
-#define X_DOT 37
-#define X_SLASH 38
-#define X_CAPSLOCK 39
-#define X_F1 3a
-#define X_F2 3b
-#define X_F3 3c
-#define X_F4 3d
-#define X_F5 3e
-#define X_F6 3f
-#define X_F7 40
-#define X_F8 41
-#define X_F9 42
-#define X_F10 43
-#define X_F11 44
-#define X_F12 45
-#define X_PSCREEN 46
-#define X_SCROLLLOCK 47
-#define X_PAUSE 48
-#define X_INSERT 49
-#define X_HOME 4a
-#define X_PGUP 4b
-#define X_DELETE 4c
-#define X_END 4d
-#define X_PGDOWN 4e
-#define X_RIGHT 4f
-#define X_LEFT 50
-#define X_DOWN 51
-#define X_UP 52
-#define X_NUMLOCK 53
-#define X_KP_SLASH 54
-#define X_KP_ASTERISK 55
-#define X_KP_MINUS 56
-#define X_KP_PLUS 57
-#define X_KP_ENTER 58
-#define X_KP_1 59
-#define X_KP_2 5a
-#define X_KP_3 5b
-#define X_KP_4 5c
-#define X_KP_5 5d
-#define X_KP_6 5e
-#define X_KP_7 5f
-#define X_KP_8 60
-#define X_KP_9 61
-#define X_KP_0 62
-#define X_KP_DOT 63
-#define X_NONUS_BSLASH 64
-#define X_APPLICATION 65
-#define X_POWER 66
-#define X_KP_EQUAL 67
-#define X_F13 68
-#define X_F14 69
-#define X_F15 6a
-#define X_F16 6b
-#define X_F17 6c
-#define X_F18 6d
-#define X_F19 6e
-#define X_F20 6f
-#define X_F21 70
-#define X_F22 71
-#define X_F23 72
-#define X_F24 73
-#define X_EXECUTE 74
-#define X_HELP 75
-#define X_MENU 76
-#define X_SELECT 77
-#define X_STOP 78
-#define X_AGAIN 79
-#define X_UNDO 7a
-#define X_CUT 7b
-#define X_COPY 7c
-#define X_PASTE 7d
-#define X_FIND 7e
-#define X__MUTE 7f
-#define X__VOLUP 80
-#define X__VOLDOWN 81
-#define X_LOCKING_CAPS 82
-#define X_LOCKING_NUM 83
-#define X_LOCKING_SCROLL 84
-#define X_KP_COMMA 85
-#define X_KP_EQUAL_AS400 86
-#define X_INT1 87
-#define X_INT2 88
-#define X_INT3 89
-#define X_INT4 8a
-#define X_INT5 8b
-#define X_INT6 8c
-#define X_INT7 8d
-#define X_INT8 8e
-#define X_INT9 8f
-#define X_LANG1 90
-#define X_LANG2 91
-#define X_LANG3 92
-#define X_LANG4 93
-#define X_LANG5 94
-#define X_LANG6 95
-#define X_LANG7 96
-#define X_LANG8 97
-#define X_LANG9 98
-#define X_ALT_ERASE 99
-#define X_SYSREQ 9a
-#define X_CANCEL 9b
-#define X_CLEAR 9c
-#define X_PRIOR 9d
-#define X_RETURN 9e
-#define X_SEPARATOR 9f
-#define X_OUT a0
-#define X_OPER a1
-#define X_CLEAR_AGAIN a2
-#define X_CRSEL a3
-#define X_EXSEL a4
+#define X_A 04
+#define X_B 05
+#define X_C 06
+#define X_D 07
+#define X_E 08
+#define X_F 09
+#define X_G 0a
+#define X_H 0b
+#define X_I 0c
+#define X_J 0d
+#define X_K 0e
+#define X_L 0f
+#define X_M 10
+#define X_N 11
+#define X_O 12
+#define X_P 13
+#define X_Q 14
+#define X_R 15
+#define X_S 16
+#define X_T 17
+#define X_U 18
+#define X_V 19
+#define X_W 1a
+#define X_X 1b
+#define X_Y 1c
+#define X_Z 1d
+#define X_1 1e
+#define X_2 1f
+#define X_3 20
+#define X_4 21
+#define X_5 22
+#define X_6 23
+#define X_7 24
+#define X_8 25
+#define X_9 26
+#define X_0 27
+#define X_ENTER 28
+#define X_ESCAPE 29
+#define X_BACKSPACE 2a
+#define X_TAB 2b
+#define X_SPACE 2c
+#define X_MINUS 2d
+#define X_EQUAL 2e
+#define X_LEFT_BRACKET 2f
+#define X_RIGHT_BRACKET 30
+#define X_BACKSLASH 31
+#define X_NONUS_HASH 32
+#define X_SEMICOLON 33
+#define X_QUOTE 34
+#define X_GRAVE 35
+#define X_COMMA 36
+#define X_DOT 37
+#define X_SLASH 38
+#define X_CAPS_LOCK 39
+#define X_F1 3a
+#define X_F2 3b
+#define X_F3 3c
+#define X_F4 3d
+#define X_F5 3e
+#define X_F6 3f
+#define X_F7 40
+#define X_F8 41
+#define X_F9 42
+#define X_F10 43
+#define X_F11 44
+#define X_F12 45
+#define X_PRINT_SCREEN 46
+#define X_SCROLL_LOCK 47
+#define X_PAUSE 48
+#define X_INSERT 49
+#define X_HOME 4a
+#define X_PAGE_UP 4b
+#define X_DELETE 4c
+#define X_END 4d
+#define X_PAGE_DOWN 4e
+#define X_RIGHT 4f
+#define X_LEFT 50
+#define X_DOWN 51
+#define X_UP 52
+#define X_NUM_LOCK 53
+#define X_KP_SLASH 54
+#define X_KP_ASTERISK 55
+#define X_KP_MINUS 56
+#define X_KP_PLUS 57
+#define X_KP_ENTER 58
+#define X_KP_1 59
+#define X_KP_2 5a
+#define X_KP_3 5b
+#define X_KP_4 5c
+#define X_KP_5 5d
+#define X_KP_6 5e
+#define X_KP_7 5f
+#define X_KP_8 60
+#define X_KP_9 61
+#define X_KP_0 62
+#define X_KP_DOT 63
+#define X_NONUS_BACKSLASH 64
+#define X_APPLICATION 65
+#define X_KB_POWER 66
+#define X_KP_EQUAL 67
+#define X_F13 68
+#define X_F14 69
+#define X_F15 6a
+#define X_F16 6b
+#define X_F17 6c
+#define X_F18 6d
+#define X_F19 6e
+#define X_F20 6f
+#define X_F21 70
+#define X_F22 71
+#define X_F23 72
+#define X_F24 73
+#define X_EXECUTE 74
+#define X_HELP 75
+#define X_MENU 76
+#define X_SELECT 77
+#define X_STOP 78
+#define X_AGAIN 79
+#define X_UNDO 7a
+#define X_CUT 7b
+#define X_COPY 7c
+#define X_PASTE 7d
+#define X_FIND 7e
+#define X_KB_MUTE 7f
+#define X_KB_VOLUME_UP 80
+#define X_KB_VOLUME_DOWN 81
+#define X_LOCKING_CAPS_LOCK 82
+#define X_LOCKING_NUM_LOCK 83
+#define X_LOCKING_SCROLL_LOCK 84
+#define X_KP_COMMA 85
+#define X_KP_EQUAL_AS400 86
+#define X_INTERNATIONAL_1 87
+#define X_INTERNATIONAL_2 88
+#define X_INTERNATIONAL_3 89
+#define X_INTERNATIONAL_4 8a
+#define X_INTERNATIONAL_5 8b
+#define X_INTERNATIONAL_6 8c
+#define X_INTERNATIONAL_7 8d
+#define X_INTERNATIONAL_8 8e
+#define X_INTERNATIONAL_9 8f
+#define X_LANGUAGE_1 90
+#define X_LANGUAGE_2 91
+#define X_LANGUAGE_3 92
+#define X_LANGUAGE_4 93
+#define X_LANGUAGE_5 94
+#define X_LANGUAGE_6 95
+#define X_LANGUAGE_7 96
+#define X_LANGUAGE_8 97
+#define X_LANGUAGE_9 98
+#define X_ALTERNATE_ERASE 99
+#define X_SYSTEM_REQUEST 9a
+#define X_CANCEL 9b
+#define X_CLEAR 9c
+#define X_PRIOR 9d
+#define X_RETURN 9e
+#define X_SEPARATOR 9f
+#define X_OUT a0
+#define X_OPER a1
+#define X_CLEAR_AGAIN a2
+#define X_CRSEL a3
+#define X_EXSEL a4
/* Modifiers */
-#define X_LCTRL e0
-#define X_LSHIFT e1
-#define X_LALT e2
-#define X_LGUI e3
-#define X_RCTRL e4
-#define X_RSHIFT e5
-#define X_RALT e6
-#define X_RGUI e7
+#define X_LEFT_CTRL e0
+#define X_LEFT_SHIFT e1
+#define X_LEFT_ALT e2
+#define X_LEFT_GUI e3
+#define X_RIGHT_CTRL e4
+#define X_RIGHT_SHIFT e5
+#define X_RIGHT_ALT e6
+#define X_RIGHT_GUI e7
/* Media and Function keys */
/* Generic Desktop Page (0x01) */
-#define X_SYSTEM_POWER a5
-#define X_SYSTEM_SLEEP a6
-#define X_SYSTEM_WAKE a7
+#define X_SYSTEM_POWER a5
+#define X_SYSTEM_SLEEP a6
+#define X_SYSTEM_WAKE a7
/* Consumer Page (0x0C) */
-#define X_AUDIO_MUTE a8
-#define X_AUDIO_VOL_UP a9
-#define X_AUDIO_VOL_DOWN aa
-#define X_MEDIA_NEXT_TRACK ab
-#define X_MEDIA_PREV_TRACK ac
-#define X_MEDIA_STOP ad
-#define X_MEDIA_PLAY_PAUSE ae
-#define X_MEDIA_SELECT af
-#define X_MEDIA_EJECT b0
-#define X_MAIL b1
-#define X_CALCULATOR b2
-#define X_MY_COMPUTER b3
-#define X_WWW_SEARCH b4
-#define X_WWW_HOME b5
-#define X_WWW_BACK b6
-#define X_WWW_FORWARD b7
-#define X_WWW_STOP b8
-#define X_WWW_REFRESH b9
-#define X_WWW_FAVORITES ba
-#define X_MEDIA_FAST_FORWARD bb
-#define X_MEDIA_REWIND bc
-#define X_BRIGHTNESS_UP bd
-#define X_BRIGHTNESS_DOWN be
+#define X_AUDIO_MUTE a8
+#define X_AUDIO_VOL_UP a9
+#define X_AUDIO_VOL_DOWN aa
+#define X_MEDIA_NEXT_TRACK ab
+#define X_MEDIA_PREV_TRACK ac
+#define X_MEDIA_STOP ad
+#define X_MEDIA_PLAY_PAUSE ae
+#define X_MEDIA_SELECT af
+#define X_MEDIA_EJECT b0
+#define X_MAIL b1
+#define X_CALCULATOR b2
+#define X_MY_COMPUTER b3
+#define X_WWW_SEARCH b4
+#define X_WWW_HOME b5
+#define X_WWW_BACK b6
+#define X_WWW_FORWARD b7
+#define X_WWW_STOP b8
+#define X_WWW_REFRESH b9
+#define X_WWW_FAVORITES ba
+#define X_MEDIA_FAST_FORWARD bb
+#define X_MEDIA_REWIND bc
+#define X_BRIGHTNESS_UP bd
+#define X_BRIGHTNESS_DOWN be
+#define X_CONTROL_PANEL bf
+#define X_ASSISTANT c0
/* Mouse Buttons (unallocated range in HID spec) */
#ifdef VIA_ENABLE
-#define X_MS_UP f0
-#define X_MS_DOWN f1
-#define X_MS_LEFT f2
-#define X_MS_RIGHT f3
-#define X_MS_BTN1 f4
-#define X_MS_BTN2 f5
-#define X_MS_BTN3 f6
-#define X_MS_BTN4 f7
-#define X_MS_BTN5 f8
-#define X_MS_BTN6 f8
-#define X_MS_BTN7 f8
-#define X_MS_BTN8 f8
+#define X_MS_UP f0
+#define X_MS_DOWN f1
+#define X_MS_LEFT f2
+#define X_MS_RIGHT f3
+#define X_MS_BTN1 f4
+#define X_MS_BTN2 f5
+#define X_MS_BTN3 f6
+#define X_MS_BTN4 f7
+#define X_MS_BTN5 f8
+#define X_MS_BTN6 f8
+#define X_MS_BTN7 f8
+#define X_MS_BTN8 f8
+#define X_MS_WH_UP f9
+#define X_MS_WH_DOWN fa
+#define X_MS_WH_LEFT fb
+#define X_MS_WH_RIGHT fc
+#define X_MS_ACCEL0 fd
+#define X_MS_ACCEL1 fe
+#define X_MS_ACCEL2 ff
#else
-#define X_MS_UP ed
-#define X_MS_DOWN ee
-#define X_MS_LEFT ef
-#define X_MS_RIGHT f0
-#define X_MS_BTN1 f1
-#define X_MS_BTN2 f2
-#define X_MS_BTN3 f3
-#define X_MS_BTN4 f4
-#define X_MS_BTN5 f5
-#define X_MS_BTN6 f6
-#define X_MS_BTN7 f7
-#define X_MS_BTN8 f8
+#define X_MS_UP cd
+#define X_MS_DOWN ce
+#define X_MS_LEFT cf
+#define X_MS_RIGHT d0
+#define X_MS_BTN1 d1
+#define X_MS_BTN2 d2
+#define X_MS_BTN3 d3
+#define X_MS_BTN4 d4
+#define X_MS_BTN5 d5
+#define X_MS_BTN6 d6
+#define X_MS_BTN7 d7
+#define X_MS_BTN8 d8
+#define X_MS_WH_UP d9
+#define X_MS_WH_DOWN da
+#define X_MS_WH_LEFT db
+#define X_MS_WH_RIGHT dc
+#define X_MS_ACCEL0 dd
+#define X_MS_ACCEL1 de
+#define X_MS_ACCEL2 df
#endif
-#define X_MS_WH_UP f9
-#define X_MS_WH_DOWN fa
-#define X_MS_WH_LEFT fb
-#define X_MS_WH_RIGHT fc
-#define X_MS_ACCEL0 fd
-#define X_MS_ACCEL1 fe
-#define X_MS_ACCEL2 ff
+
// Send string macros
#define STRINGIZE(z) #z
@@ -431,6 +466,3 @@
#define SS_ROPT(string) SS_RALT(string)
#define SS_RCMD(string) SS_RGUI(string)
#define SS_RWIN(string) SS_RGUI(string)
-
-// DEPRECATED
-#define SS_LCTRL(string) SS_LCTL(string)
diff --git a/quantum/sequencer/tests/rules.mk b/quantum/sequencer/tests/rules.mk
index a3bbd80513..611459e060 100644
--- a/quantum/sequencer/tests/rules.mk
+++ b/quantum/sequencer/tests/rules.mk
@@ -2,7 +2,7 @@
# - it is consistent with the example that is used as a reference in the Unit Testing article (https://docs.qmk.fm/#/unit_testing?id=adding-tests-for-new-or-existing-features)
# - Neither `make test:sequencer` or `make test:SEQUENCER` work when using SCREAMING_SNAKE_CASE
-sequencer_DEFS := -DNO_DEBUG -DMIDI_MOCKED
+sequencer_DEFS := -DMATRIX_ROWS=1 -DMATRIX_COLS=1 -DNO_DEBUG -DMIDI_MOCKED
sequencer_SRC := \
$(QUANTUM_PATH)/sequencer/tests/midi_mock.c \
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index 4892b7f8d8..9f57c7b9fc 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -74,6 +74,46 @@ static inline bool usbIsActive(void) {
}
#endif
+#if defined(SPLIT_WATCHDOG_ENABLE)
+# if !defined(SPLIT_WATCHDOG_TIMEOUT)
+# if defined(SPLIT_USB_TIMEOUT)
+# define SPLIT_WATCHDOG_TIMEOUT (SPLIT_USB_TIMEOUT + 100)
+# else
+# define SPLIT_WATCHDOG_TIMEOUT 3000
+# endif
+# endif
+# if defined(SPLIT_USB_DETECT)
+_Static_assert(SPLIT_USB_TIMEOUT < SPLIT_WATCHDOG_TIMEOUT, "SPLIT_WATCHDOG_TIMEOUT should not be below SPLIT_USB_TIMEOUT.");
+# endif
+_Static_assert(SPLIT_MAX_CONNECTION_ERRORS > 0, "SPLIT_WATCHDOG_ENABLE requires SPLIT_MAX_CONNECTION_ERRORS be above 0 for a functioning disconnection check.");
+
+static uint32_t split_watchdog_started = 0;
+static bool split_watchdog_done = false;
+
+void split_watchdog_init(void) {
+ split_watchdog_started = timer_read32();
+}
+
+void split_watchdog_update(bool done) {
+ split_watchdog_done = done;
+}
+
+bool split_watchdog_check(void) {
+ if (!is_transport_connected()) {
+ split_watchdog_done = false;
+ }
+ return split_watchdog_done;
+}
+
+void split_watchdog_task(void) {
+ if (!split_watchdog_done && !is_keyboard_master()) {
+ if (timer_elapsed32(split_watchdog_started) > SPLIT_WATCHDOG_TIMEOUT) {
+ mcu_reset();
+ }
+ }
+}
+#endif // defined(SPLIT_WATCHDOG_ENABLE)
+
#ifdef SPLIT_HAND_MATRIX_GRID
void matrix_io_delay(void);
@@ -139,6 +179,20 @@ void split_pre_init(void) {
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
+ // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS within the emulated eeprom via dfu-util or another tool
+# if defined(INIT_EE_HANDS_LEFT) || defined(INIT_EE_HANDS_RIGHT)
+# if defined(INIT_EE_HANDS_LEFT)
+# pragma message "Faking EE_HANDS for left hand"
+ const bool should_be_left = true;
+# else
+# pragma message "Faking EE_HANDS for right hand"
+ const bool should_be_left = false;
+# endif
+ bool is_left = eeconfig_read_handedness();
+ if (is_left != should_be_left) {
+ eeconfig_update_handedness(should_be_left);
+ }
+# endif // defined(INIT_EE_HANDS_LEFT) || defined(INIT_EE_HANDS_RIGHT)
#endif
isLeftHand = is_keyboard_left();
@@ -165,6 +219,9 @@ void split_pre_init(void) {
void split_post_init(void) {
if (!is_keyboard_master()) {
transport_slave_init();
+#if defined(SPLIT_WATCHDOG_ENABLE)
+ split_watchdog_init();
+#endif
}
}
diff --git a/quantum/split_common/split_util.h b/quantum/split_common/split_util.h
index c7eabea233..5c9a260a14 100644
--- a/quantum/split_common/split_util.h
+++ b/quantum/split_common/split_util.h
@@ -14,3 +14,7 @@ void split_post_init(void);
bool transport_master_if_connected(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]);
bool is_transport_connected(void);
+
+void split_watchdog_update(bool done);
+void split_watchdog_task(void);
+bool split_watchdog_check(void); \ No newline at end of file
diff --git a/quantum/split_common/transaction_id_define.h b/quantum/split_common/transaction_id_define.h
index 761a8884f4..8c19948107 100644
--- a/quantum/split_common/transaction_id_define.h
+++ b/quantum/split_common/transaction_id_define.h
@@ -84,6 +84,10 @@ enum serial_transaction_id {
PUT_POINTING_CPI,
#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
+#if defined(SPLIT_WATCHDOG_ENABLE)
+ PUT_WATCHDOG,
+#endif // defined(SPLIT_WATCHDOG_ENABLE)
+
#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
PUT_RPC_INFO,
PUT_RPC_REQ_DATA,
diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c
index 719068908f..527b2f4caf 100644
--- a/quantum/split_common/transactions.c
+++ b/quantum/split_common/transactions.c
@@ -76,8 +76,27 @@ static bool transaction_handler_master(matrix_row_t master_matrix[], matrix_row_
if (!transaction_handler_master(master_matrix, slave_matrix, #prefix, &prefix##_handlers_master)) return false; \
} while (0)
+/**
+ * @brief Constructs a transaction handler that doesn't acquire a lock to the
+ * split shared memory. Therefore the locking and unlocking has to be done
+ * manually inside the handler. Use this macro only if the handler is
+ * non-deterministic in runtime and thus needs a manual lock unlock
+ * implementation to hold the lock for the shortest possible time.
+ */
#define TRANSACTION_HANDLER_SLAVE(prefix) \
do { \
+ prefix##_handlers_slave(master_matrix, slave_matrix); \
+ } while (0)
+
+/**
+ * @brief Constructs a transaction handler that automatically acquires a lock to
+ * safely access the split shared memory and releases the lock again after
+ * processing the handler. Use this macro if the handler is fast and
+ * deterministic in runtime and thus holds the lock only for a very short time.
+ * If not fallback to manually locking and unlocking inside the handler.
+ */
+#define TRANSACTION_HANDLER_SLAVE_AUTOLOCK(prefix) \
+ do { \
split_shared_memory_lock(); \
prefix##_handlers_slave(master_matrix, slave_matrix); \
split_shared_memory_unlock(); \
@@ -139,7 +158,7 @@ static void slave_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row
// clang-format off
#define TRANSACTIONS_SLAVE_MATRIX_MASTER() TRANSACTION_HANDLER_MASTER(slave_matrix)
-#define TRANSACTIONS_SLAVE_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(slave_matrix)
+#define TRANSACTIONS_SLAVE_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(slave_matrix)
#define TRANSACTIONS_SLAVE_MATRIX_REGISTRATIONS \
[GET_SLAVE_MATRIX_CHECKSUM] = trans_target2initiator_initializer(smatrix.checksum), \
[GET_SLAVE_MATRIX_DATA] = trans_target2initiator_initializer(smatrix.matrix),
@@ -161,7 +180,7 @@ static void master_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_ro
}
# define TRANSACTIONS_MASTER_MATRIX_MASTER() TRANSACTION_HANDLER_MASTER(master_matrix)
-# define TRANSACTIONS_MASTER_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE(master_matrix)
+# define TRANSACTIONS_MASTER_MATRIX_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(master_matrix)
# define TRANSACTIONS_MASTER_MATRIX_REGISTRATIONS [PUT_MASTER_MATRIX] = trans_initiator2target_initializer(mmatrix.matrix),
#else // SPLIT_TRANSPORT_MIRROR
@@ -197,7 +216,7 @@ static void encoder_handlers_slave(matrix_row_t master_matrix[], matrix_row_t sl
// clang-format off
# define TRANSACTIONS_ENCODERS_MASTER() TRANSACTION_HANDLER_MASTER(encoder)
-# define TRANSACTIONS_ENCODERS_SLAVE() TRANSACTION_HANDLER_SLAVE(encoder)
+# define TRANSACTIONS_ENCODERS_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(encoder)
# define TRANSACTIONS_ENCODERS_REGISTRATIONS \
[GET_ENCODERS_CHECKSUM] = trans_target2initiator_initializer(encoders.checksum), \
[GET_ENCODERS_DATA] = trans_target2initiator_initializer(encoders.state),
@@ -239,7 +258,7 @@ static void sync_timer_handlers_slave(matrix_row_t master_matrix[], matrix_row_t
}
# define TRANSACTIONS_SYNC_TIMER_MASTER() TRANSACTION_HANDLER_MASTER(sync_timer)
-# define TRANSACTIONS_SYNC_TIMER_SLAVE() TRANSACTION_HANDLER_SLAVE(sync_timer)
+# define TRANSACTIONS_SYNC_TIMER_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(sync_timer)
# define TRANSACTIONS_SYNC_TIMER_REGISTRATIONS [PUT_SYNC_TIMER] = trans_initiator2target_initializer(sync_timer),
#else // DISABLE_SYNC_TIMER
@@ -273,7 +292,7 @@ static void layer_state_handlers_slave(matrix_row_t master_matrix[], matrix_row_
// clang-format off
# define TRANSACTIONS_LAYER_STATE_MASTER() TRANSACTION_HANDLER_MASTER(layer_state)
-# define TRANSACTIONS_LAYER_STATE_SLAVE() TRANSACTION_HANDLER_SLAVE(layer_state)
+# define TRANSACTIONS_LAYER_STATE_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(layer_state)
# define TRANSACTIONS_LAYER_STATE_REGISTRATIONS \
[PUT_LAYER_STATE] = trans_initiator2target_initializer(layers.layer_state), \
[PUT_DEFAULT_LAYER_STATE] = trans_initiator2target_initializer(layers.default_layer_state),
@@ -304,7 +323,7 @@ static void led_state_handlers_slave(matrix_row_t master_matrix[], matrix_row_t
}
# define TRANSACTIONS_LED_STATE_MASTER() TRANSACTION_HANDLER_MASTER(led_state)
-# define TRANSACTIONS_LED_STATE_SLAVE() TRANSACTION_HANDLER_SLAVE(led_state)
+# define TRANSACTIONS_LED_STATE_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(led_state)
# define TRANSACTIONS_LED_STATE_REGISTRATIONS [PUT_LED_STATE] = trans_initiator2target_initializer(led_state),
#else // SPLIT_LED_STATE_ENABLE
@@ -353,10 +372,15 @@ static bool mods_handlers_master(matrix_row_t master_matrix[], matrix_row_t slav
}
static void mods_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
- set_mods(split_shmem->mods.real_mods);
- set_weak_mods(split_shmem->mods.weak_mods);
+ split_shared_memory_lock();
+ split_mods_sync_t mods;
+ memcpy(&mods, &split_shmem->mods, sizeof(split_mods_sync_t));
+ split_shared_memory_unlock();
+
+ set_mods(mods.real_mods);
+ set_weak_mods(mods.weak_mods);
# ifndef NO_ACTION_ONESHOT
- set_oneshot_mods(split_shmem->mods.oneshot_mods);
+ set_oneshot_mods(mods.oneshot_mods);
# endif
}
@@ -384,7 +408,11 @@ static bool backlight_handlers_master(matrix_row_t master_matrix[], matrix_row_t
}
static void backlight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
- backlight_set(split_shmem->backlight_level);
+ split_shared_memory_lock();
+ uint8_t backlight_level = split_shmem->backlight_level;
+ split_shared_memory_unlock();
+
+ backlight_set(backlight_level);
}
# define TRANSACTIONS_BACKLIGHT_MASTER() TRANSACTION_HANDLER_MASTER(backlight)
@@ -417,10 +445,15 @@ static bool rgblight_handlers_master(matrix_row_t master_matrix[], matrix_row_t
}
static void rgblight_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ split_shared_memory_lock();
// Update the RGB with the new data
- if (split_shmem->rgblight_sync.status.change_flags != 0) {
- rgblight_update_sync(&split_shmem->rgblight_sync, false);
- split_shmem->rgblight_sync.status.change_flags = 0;
+ rgblight_syncinfo_t rgblight_sync;
+ memcpy(&rgblight_sync, &split_shmem->rgblight_sync, sizeof(rgblight_syncinfo_t));
+ split_shmem->rgblight_sync.status.change_flags = 0;
+ split_shared_memory_unlock();
+
+ if (rgblight_sync.status.change_flags != 0) {
+ rgblight_update_sync(&rgblight_sync, false);
}
}
@@ -450,8 +483,12 @@ static bool led_matrix_handlers_master(matrix_row_t master_matrix[], matrix_row_
}
static void led_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ split_shared_memory_lock();
memcpy(&led_matrix_eeconfig, &split_shmem->led_matrix_sync.led_matrix, sizeof(led_eeconfig_t));
- led_matrix_set_suspend_state(split_shmem->led_matrix_sync.led_suspend_state);
+ bool led_suspend_state = split_shmem->led_matrix_sync.led_suspend_state;
+ split_shared_memory_unlock();
+
+ led_matrix_set_suspend_state(led_suspend_state);
}
# define TRANSACTIONS_LED_MATRIX_MASTER() TRANSACTION_HANDLER_MASTER(led_matrix)
@@ -480,8 +517,12 @@ static bool rgb_matrix_handlers_master(matrix_row_t master_matrix[], matrix_row_
}
static void rgb_matrix_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ split_shared_memory_lock();
memcpy(&rgb_matrix_config, &split_shmem->rgb_matrix_sync.rgb_matrix, sizeof(rgb_config_t));
- rgb_matrix_set_suspend_state(split_shmem->rgb_matrix_sync.rgb_suspend_state);
+ bool rgb_suspend_state = split_shmem->rgb_matrix_sync.rgb_suspend_state;
+ split_shared_memory_unlock();
+
+ rgb_matrix_set_suspend_state(rgb_suspend_state);
}
# define TRANSACTIONS_RGB_MATRIX_MASTER() TRANSACTION_HANDLER_MASTER(rgb_matrix)
@@ -512,7 +553,7 @@ static void wpm_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_
}
# define TRANSACTIONS_WPM_MASTER() TRANSACTION_HANDLER_MASTER(wpm)
-# define TRANSACTIONS_WPM_SLAVE() TRANSACTION_HANDLER_SLAVE(wpm)
+# define TRANSACTIONS_WPM_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(wpm)
# define TRANSACTIONS_WPM_REGISTRATIONS [PUT_WPM] = trans_initiator2target_initializer(current_wpm),
#else // defined(WPM_ENABLE) && defined(SPLIT_WPM_ENABLE)
@@ -535,7 +576,11 @@ static bool oled_handlers_master(matrix_row_t master_matrix[], matrix_row_t slav
}
static void oled_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
- if (split_shmem->current_oled_state) {
+ split_shared_memory_lock();
+ uint8_t current_oled_state = split_shmem->current_oled_state;
+ split_shared_memory_unlock();
+
+ if (current_oled_state) {
oled_on();
} else {
oled_off();
@@ -566,7 +611,11 @@ static bool st7565_handlers_master(matrix_row_t master_matrix[], matrix_row_t sl
}
static void st7565_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
- if (split_shmem->current_st7565_state) {
+ split_shared_memory_lock();
+ uint8_t current_st7565_state = split_shmem->current_st7565_state;
+ split_shared_memory_unlock();
+
+ if (current_st7565_state) {
st7565_on();
} else {
st7565_off();
@@ -607,9 +656,9 @@ static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t
bool okay = read_if_checksum_mismatch(GET_POINTING_CHECKSUM, GET_POINTING_DATA, &last_update, &temp_state, &split_shmem->pointing.report, sizeof(temp_state));
if (okay) pointing_device_set_shared_report(temp_state);
temp_cpi = pointing_device_get_shared_cpi();
- if (temp_cpi && memcmp(&last_cpi, &temp_cpi, sizeof(temp_cpi)) != 0) {
- memcpy(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi));
- okay = transport_write(PUT_POINTING_CPI, &split_shmem->pointing.cpi, sizeof(split_shmem->pointing.cpi));
+ if (temp_cpi && last_cpi != temp_cpi) {
+ split_shmem->pointing.cpi = temp_cpi;
+ okay = transport_write(PUT_POINTING_CPI, &split_shmem->pointing.cpi, sizeof(split_shmem->pointing.cpi));
if (okay) {
last_cpi = temp_cpi;
}
@@ -629,8 +678,6 @@ static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s
return;
}
# endif
- report_mouse_t temp_report;
- uint16_t temp_cpi;
# if (POINTING_DEVICE_TASK_THROTTLE_MS > 0)
static uint32_t last_exec = 0;
if (timer_elapsed32(last_exec) < POINTING_DEVICE_TASK_THROTTLE_MS) {
@@ -638,17 +685,25 @@ static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s
}
last_exec = timer_read32();
# endif
- temp_cpi = !pointing_device_driver.get_cpi ? 0 : pointing_device_driver.get_cpi(); // check for NULL
- if (split_shmem->pointing.cpi && memcmp(&split_shmem->pointing.cpi, &temp_cpi, sizeof(temp_cpi)) != 0) {
- if (pointing_device_driver.set_cpi) {
- pointing_device_driver.set_cpi(split_shmem->pointing.cpi);
- }
+
+ uint16_t temp_cpi = !pointing_device_driver.get_cpi ? 0 : pointing_device_driver.get_cpi(); // check for NULL
+
+ split_shared_memory_lock();
+ split_slave_pointing_sync_t pointing;
+ memcpy(&pointing, &split_shmem->pointing, sizeof(split_slave_pointing_sync_t));
+ split_shared_memory_unlock();
+
+ if (pointing.cpi && pointing.cpi != temp_cpi && pointing_device_driver.set_cpi) {
+ pointing_device_driver.set_cpi(pointing.cpi);
}
- memset(&temp_report, 0, sizeof(temp_report));
- temp_report = pointing_device_driver.get_report(temp_report);
- memcpy(&split_shmem->pointing.report, &temp_report, sizeof(temp_report));
+
+ pointing.report = pointing_device_driver.get_report((report_mouse_t){0});
// Now update the checksum given that the pointing has been written to
- split_shmem->pointing.checksum = crc8(&temp_report, sizeof(temp_report));
+ pointing.checksum = crc8(&pointing.report, sizeof(report_mouse_t));
+
+ split_shared_memory_lock();
+ memcpy(&split_shmem->pointing, &pointing, sizeof(split_slave_pointing_sync_t));
+ split_shared_memory_unlock();
}
# define TRANSACTIONS_POINTING_MASTER() TRANSACTION_HANDLER_MASTER(pointing)
@@ -664,6 +719,36 @@ static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s
#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
////////////////////////////////////////////////////
+// WATCHDOG
+
+#if defined(SPLIT_WATCHDOG_ENABLE)
+
+static bool watchdog_handlers_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ bool okay = true;
+ if (!split_watchdog_check()) {
+ okay = transport_write(PUT_WATCHDOG, &okay, sizeof(okay));
+ split_watchdog_update(okay);
+ }
+ return okay;
+}
+
+static void watchdog_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
+ split_watchdog_update(split_shmem->watchdog_pinged);
+}
+
+# define TRANSACTIONS_WATCHDOG_MASTER() TRANSACTION_HANDLER_MASTER(watchdog)
+# define TRANSACTIONS_WATCHDOG_SLAVE() TRANSACTION_HANDLER_SLAVE_AUTOLOCK(watchdog)
+# define TRANSACTIONS_WATCHDOG_REGISTRATIONS [PUT_WATCHDOG] = trans_initiator2target_initializer(watchdog_pinged),
+
+#else // defined(SPLIT_WATCHDOG_ENABLE)
+
+# define TRANSACTIONS_WATCHDOG_MASTER()
+# define TRANSACTIONS_WATCHDOG_SLAVE()
+# define TRANSACTIONS_WATCHDOG_REGISTRATIONS
+
+#endif // defined(SPLIT_WATCHDOG_ENABLE)
+
+////////////////////////////////////////////////////
split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = {
// Set defaults
@@ -689,6 +774,7 @@ split_transaction_desc_t split_transaction_table[NUM_TOTAL_TRANSACTIONS] = {
TRANSACTIONS_OLED_REGISTRATIONS
TRANSACTIONS_ST7565_REGISTRATIONS
TRANSACTIONS_POINTING_REGISTRATIONS
+ TRANSACTIONS_WATCHDOG_REGISTRATIONS
// clang-format on
#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
@@ -715,6 +801,7 @@ bool transactions_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix
TRANSACTIONS_OLED_MASTER();
TRANSACTIONS_ST7565_MASTER();
TRANSACTIONS_POINTING_MASTER();
+ TRANSACTIONS_WATCHDOG_MASTER();
return true;
}
@@ -734,6 +821,7 @@ void transactions_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[
TRANSACTIONS_OLED_SLAVE();
TRANSACTIONS_ST7565_SLAVE();
TRANSACTIONS_POINTING_SLAVE();
+ TRANSACTIONS_WATCHDOG_SLAVE();
}
#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
diff --git a/quantum/split_common/transport.h b/quantum/split_common/transport.h
index 06778ad14a..833633edc2 100644
--- a/quantum/split_common/transport.h
+++ b/quantum/split_common/transport.h
@@ -188,6 +188,10 @@ typedef struct _split_shared_memory_t {
split_slave_pointing_sync_t pointing;
#endif // defined(POINTING_DEVICE_ENABLE) && defined(SPLIT_POINTING_ENABLE)
+#if defined(SPLIT_WATCHDOG_ENABLE)
+ bool watchdog_pinged;
+#endif // defined(SPLIT_WATCHDOG_ENABLE)
+
#if defined(SPLIT_TRANSACTION_IDS_KB) || defined(SPLIT_TRANSACTION_IDS_USER)
rpc_sync_info_t rpc_info;
uint8_t rpc_m2s_buffer[RPC_M2S_BUFFER_SIZE];
diff --git a/quantum/unicode/unicode.c b/quantum/unicode/unicode.c
new file mode 100644
index 0000000000..e2bfd68a3a
--- /dev/null
+++ b/quantum/unicode/unicode.c
@@ -0,0 +1,386 @@
+/* Copyright 2022
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "unicode.h"
+
+#include "eeprom.h"
+#include "eeconfig.h"
+#include "action.h"
+#include "action_util.h"
+#include "host.h"
+#include "keycode.h"
+#include "wait.h"
+#include "send_string.h"
+#include "utf8.h"
+
+#if defined(AUDIO_ENABLE)
+# include "audio.h"
+#endif
+
+#if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1
+# error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time"
+#endif
+
+// Keycodes used for starting Unicode input on different platforms
+#ifndef UNICODE_KEY_MAC
+# define UNICODE_KEY_MAC KC_LEFT_ALT
+#endif
+#ifndef UNICODE_KEY_LNX
+# define UNICODE_KEY_LNX LCTL(LSFT(KC_U))
+#endif
+#ifndef UNICODE_KEY_WINC
+# define UNICODE_KEY_WINC KC_RIGHT_ALT
+#endif
+
+// Comma-delimited, ordered list of input modes selected for use (e.g. in cycle)
+// Example: #define UNICODE_SELECTED_MODES UC_WINC, UC_LNX
+#ifndef UNICODE_SELECTED_MODES
+# define UNICODE_SELECTED_MODES -1
+#endif
+
+// Whether input mode changes in cycle should be written to EEPROM
+#ifndef UNICODE_CYCLE_PERSIST
+# define UNICODE_CYCLE_PERSIST true
+#endif
+
+// Delay between starting Unicode input and sending a sequence, in ms
+#ifndef UNICODE_TYPE_DELAY
+# define UNICODE_TYPE_DELAY 10
+#endif
+
+unicode_config_t unicode_config;
+uint8_t unicode_saved_mods;
+led_t unicode_saved_led_state;
+
+#if UNICODE_SELECTED_MODES != -1
+static uint8_t selected[] = {UNICODE_SELECTED_MODES};
+static int8_t selected_count = ARRAY_SIZE(selected);
+static int8_t selected_index;
+#endif
+
+/** \brief unicode input mode set at user level
+ *
+ * Run user code on unicode input mode change
+ */
+__attribute__((weak)) void unicode_input_mode_set_user(uint8_t input_mode) {}
+
+/** \brief unicode input mode set at keyboard level
+ *
+ * Run keyboard code on unicode input mode change
+ */
+__attribute__((weak)) void unicode_input_mode_set_kb(uint8_t input_mode) {
+ unicode_input_mode_set_user(input_mode);
+}
+
+#ifdef AUDIO_ENABLE
+# ifdef UNICODE_SONG_MAC
+static float song_mac[][2] = UNICODE_SONG_MAC;
+# endif
+# ifdef UNICODE_SONG_LNX
+static float song_lnx[][2] = UNICODE_SONG_LNX;
+# endif
+# ifdef UNICODE_SONG_WIN
+static float song_win[][2] = UNICODE_SONG_WIN;
+# endif
+# ifdef UNICODE_SONG_BSD
+static float song_bsd[][2] = UNICODE_SONG_BSD;
+# endif
+# ifdef UNICODE_SONG_WINC
+static float song_winc[][2] = UNICODE_SONG_WINC;
+# endif
+# ifdef UNICODE_SONG_EMACS
+static float song_emacs[][2] = UNICODE_SONG_EMACS;
+# endif
+
+static void unicode_play_song(uint8_t mode) {
+ switch (mode) {
+# ifdef UNICODE_SONG_MAC
+ case UC_MAC:
+ PLAY_SONG(song_mac);
+ break;
+# endif
+# ifdef UNICODE_SONG_LNX
+ case UC_LNX:
+ PLAY_SONG(song_lnx);
+ break;
+# endif
+# ifdef UNICODE_SONG_WIN
+ case UC_WIN:
+ PLAY_SONG(song_win);
+ break;
+# endif
+# ifdef UNICODE_SONG_BSD
+ case UC_BSD:
+ PLAY_SONG(song_bsd);
+ break;
+# endif
+# ifdef UNICODE_SONG_WINC
+ case UC_WINC:
+ PLAY_SONG(song_winc);
+ break;
+# endif
+# ifdef UNICODE_SONG_EMACS
+ case UC_EMACS:
+ PLAY_SONG(song_emacs);
+ break;
+# endif
+ }
+}
+#endif
+
+void unicode_input_mode_init(void) {
+ unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
+#if UNICODE_SELECTED_MODES != -1
+# if UNICODE_CYCLE_PERSIST
+ // Find input_mode in selected modes
+ int8_t i;
+ for (i = 0; i < selected_count; i++) {
+ if (selected[i] == unicode_config.input_mode) {
+ selected_index = i;
+ break;
+ }
+ }
+ if (i == selected_count) {
+ // Not found: input_mode isn't selected, change to one that is
+ unicode_config.input_mode = selected[selected_index = 0];
+ }
+# else
+ // Always change to the first selected input mode
+ unicode_config.input_mode = selected[selected_index = 0];
+# endif
+#endif
+ unicode_input_mode_set_kb(unicode_config.input_mode);
+ dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode);
+}
+
+uint8_t get_unicode_input_mode(void) {
+ return unicode_config.input_mode;
+}
+
+void set_unicode_input_mode(uint8_t mode) {
+ unicode_config.input_mode = mode;
+ persist_unicode_input_mode();
+#ifdef AUDIO_ENABLE
+ unicode_play_song(mode);
+#endif
+ unicode_input_mode_set_kb(mode);
+ dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode);
+}
+
+void cycle_unicode_input_mode(int8_t offset) {
+#if UNICODE_SELECTED_MODES != -1
+ selected_index = (selected_index + offset) % selected_count;
+ if (selected_index < 0) {
+ selected_index += selected_count;
+ }
+ unicode_config.input_mode = selected[selected_index];
+# if UNICODE_CYCLE_PERSIST
+ persist_unicode_input_mode();
+# endif
+# ifdef AUDIO_ENABLE
+ unicode_play_song(unicode_config.input_mode);
+# endif
+ unicode_input_mode_set_kb(unicode_config.input_mode);
+ dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode);
+#endif
+}
+
+void persist_unicode_input_mode(void) {
+ eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode);
+}
+
+__attribute__((weak)) void unicode_input_start(void) {
+ unicode_saved_led_state = host_keyboard_led_state();
+
+ // Note the order matters here!
+ // Need to do this before we mess around with the mods, or else
+ // UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work
+ // correctly in the shifted case.
+ if (unicode_config.input_mode == UC_LNX && unicode_saved_led_state.caps_lock) {
+ tap_code(KC_CAPS_LOCK);
+ }
+
+ unicode_saved_mods = get_mods(); // Save current mods
+ clear_mods(); // Unregister mods to start from a clean state
+ clear_weak_mods();
+
+ switch (unicode_config.input_mode) {
+ case UC_MAC:
+ register_code(UNICODE_KEY_MAC);
+ break;
+ case UC_LNX:
+ tap_code16(UNICODE_KEY_LNX);
+ break;
+ case UC_WIN:
+ // For increased reliability, use numpad keys for inputting digits
+ if (!unicode_saved_led_state.num_lock) {
+ tap_code(KC_NUM_LOCK);
+ }
+ register_code(KC_LEFT_ALT);
+ wait_ms(UNICODE_TYPE_DELAY);
+ tap_code(KC_KP_PLUS);
+ break;
+ case UC_WINC:
+ tap_code(UNICODE_KEY_WINC);
+ tap_code(KC_U);
+ break;
+ case UC_EMACS:
+ // The usual way to type unicode in emacs is C-x-8 <RET> then the unicode number in hex
+ tap_code16(LCTL(KC_X));
+ tap_code16(KC_8);
+ tap_code16(KC_ENTER);
+ break;
+ }
+
+ wait_ms(UNICODE_TYPE_DELAY);
+}
+
+__attribute__((weak)) void unicode_input_finish(void) {
+ switch (unicode_config.input_mode) {
+ case UC_MAC:
+ unregister_code(UNICODE_KEY_MAC);
+ break;
+ case UC_LNX:
+ tap_code(KC_SPACE);
+ if (unicode_saved_led_state.caps_lock) {
+ tap_code(KC_CAPS_LOCK);
+ }
+ break;
+ case UC_WIN:
+ unregister_code(KC_LEFT_ALT);
+ if (!unicode_saved_led_state.num_lock) {
+ tap_code(KC_NUM_LOCK);
+ }
+ break;
+ case UC_WINC:
+ tap_code(KC_ENTER);
+ break;
+ case UC_EMACS:
+ tap_code16(KC_ENTER);
+ break;
+ }
+
+ set_mods(unicode_saved_mods); // Reregister previously set mods
+}
+
+__attribute__((weak)) void unicode_input_cancel(void) {
+ switch (unicode_config.input_mode) {
+ case UC_MAC:
+ unregister_code(UNICODE_KEY_MAC);
+ break;
+ case UC_LNX:
+ tap_code(KC_ESCAPE);
+ if (unicode_saved_led_state.caps_lock) {
+ tap_code(KC_CAPS_LOCK);
+ }
+ break;
+ case UC_WINC:
+ tap_code(KC_ESCAPE);
+ break;
+ case UC_WIN:
+ unregister_code(KC_LEFT_ALT);
+ if (!unicode_saved_led_state.num_lock) {
+ tap_code(KC_NUM_LOCK);
+ }
+ break;
+ case UC_EMACS:
+ tap_code16(LCTL(KC_G)); // C-g cancels
+ break;
+ }
+
+ set_mods(unicode_saved_mods); // Reregister previously set mods
+}
+
+// clang-format off
+
+static void send_nibble_wrapper(uint8_t digit) {
+ if (unicode_config.input_mode == UC_WIN) {
+ uint8_t kc = digit < 10
+ ? KC_KP_1 + (10 + digit - 1) % 10
+ : KC_A + (digit - 10);
+ tap_code(kc);
+ return;
+ }
+ send_nibble(digit);
+}
+
+// clang-format on
+
+void register_hex(uint16_t hex) {
+ for (int i = 3; i >= 0; i--) {
+ uint8_t digit = ((hex >> (i * 4)) & 0xF);
+ send_nibble_wrapper(digit);
+ }
+}
+
+void register_hex32(uint32_t hex) {
+ bool first_digit = true;
+ bool needs_leading_zero = (unicode_config.input_mode == UC_WINC);
+ for (int i = 7; i >= 0; i--) {
+ // Work out the digit we're going to transmit
+ uint8_t digit = ((hex >> (i * 4)) & 0xF);
+
+ // If we're still searching for the first digit, and found one
+ // that needs a leading zero sent out, send the zero.
+ if (first_digit && needs_leading_zero && digit > 9) {
+ send_nibble_wrapper(0);
+ }
+
+ // Always send digits (including zero) if we're down to the last
+ // two bytes of nibbles.
+ bool must_send = i < 4;
+
+ // If we've found a digit worth transmitting, do so.
+ if (digit != 0 || !first_digit || must_send) {
+ send_nibble_wrapper(digit);
+ first_digit = false;
+ }
+ }
+}
+
+void register_unicode(uint32_t code_point) {
+ if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UC_WIN)) {
+ // Code point out of range, do nothing
+ return;
+ }
+
+ unicode_input_start();
+ if (code_point > 0xFFFF && unicode_config.input_mode == UC_MAC) {
+ // Convert code point to UTF-16 surrogate pair on macOS
+ code_point -= 0x10000;
+ uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10;
+ register_hex32(hi + 0xD800);
+ register_hex32(lo + 0xDC00);
+ } else {
+ register_hex32(code_point);
+ }
+ unicode_input_finish();
+}
+
+void send_unicode_string(const char *str) {
+ if (!str) {
+ return;
+ }
+
+ while (*str) {
+ int32_t code_point = 0;
+ str = decode_utf8(str, &code_point);
+
+ if (code_point >= 0) {
+ register_unicode(code_point);
+ }
+ }
+}
diff --git a/quantum/unicode/unicode.h b/quantum/unicode/unicode.h
new file mode 100644
index 0000000000..b3e43799ff
--- /dev/null
+++ b/quantum/unicode/unicode.h
@@ -0,0 +1,165 @@
+/* Copyright 2022
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+#include "quantum.h"
+
+typedef union {
+ uint32_t raw;
+ struct {
+ uint8_t input_mode : 8;
+ };
+} unicode_config_t;
+
+extern unicode_config_t unicode_config;
+
+enum unicode_input_modes {
+ UC_MAC, // macOS using Unicode Hex Input
+ UC_LNX, // Linux using IBus
+ UC_WIN, // Windows using EnableHexNumpad
+ UC_BSD, // BSD (not implemented)
+ UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose)
+ UC_EMACS, // Emacs is an operating system in search of a good text editor
+ UC__COUNT // Number of available input modes (always leave at the end)
+};
+
+void unicode_input_mode_init(void);
+uint8_t get_unicode_input_mode(void);
+void set_unicode_input_mode(uint8_t mode);
+void cycle_unicode_input_mode(int8_t offset);
+void persist_unicode_input_mode(void);
+
+void unicode_input_mode_set_user(uint8_t input_mode);
+void unicode_input_mode_set_kb(uint8_t input_mode);
+
+void unicode_input_start(void);
+void unicode_input_finish(void);
+void unicode_input_cancel(void);
+
+void register_hex(uint16_t hex);
+void register_hex32(uint32_t hex);
+void register_unicode(uint32_t code_point);
+
+void send_unicode_string(const char *str);
+
+// clang-format off
+
+#define UC_BSPC UC(0x0008) // (backspace)
+
+#define UC_SPC UC(0x0020) // (space)
+#define UC_EXLM UC(0x0021) // !
+#define UC_DQUT UC(0x0022) // "
+#define UC_HASH UC(0x0023) // #
+#define UC_DLR UC(0x0024) // $
+#define UC_PERC UC(0x0025) // %
+#define UC_AMPR UC(0x0026) // &
+#define UC_QUOT UC(0x0027) // '
+#define UC_LPRN UC(0x0028) // (
+#define UC_RPRN UC(0x0029) // )
+#define UC_ASTR UC(0x002A) // *
+#define UC_PLUS UC(0x002B) // +
+#define UC_COMM UC(0x002C) // ,
+#define UC_DASH UC(0x002D) // -
+#define UC_DOT UC(0x002E) // .
+#define UC_SLSH UC(0x002F) // /
+
+#define UC_0 UC(0x0030) // 0
+#define UC_1 UC(0x0031) // 1
+#define UC_2 UC(0x0032) // 2
+#define UC_3 UC(0x0033) // 3
+#define UC_4 UC(0x0034) // 4
+#define UC_5 UC(0x0035) // 5
+#define UC_6 UC(0x0036) // 6
+#define UC_7 UC(0x0037) // 7
+#define UC_8 UC(0x0038) // 8
+#define UC_9 UC(0x0039) // 9
+#define UC_COLN UC(0x003A) // :
+#define UC_SCLN UC(0x003B) // ;
+#define UC_LT UC(0x003C) // <
+#define UC_EQL UC(0x003D) // =
+#define UC_GT UC(0x003E) // >
+#define UC_QUES UC(0x003F) // ?
+
+#define UC_AT UC(0x0040) // @
+#define UC_A UC(0x0041) // A
+#define UC_B UC(0x0042) // B
+#define UC_C UC(0x0043) // C
+#define UC_D UC(0x0044) // D
+#define UC_E UC(0x0045) // E
+#define UC_F UC(0x0046) // F
+#define UC_G UC(0x0047) // G
+#define UC_H UC(0x0048) // H
+#define UC_I UC(0x0049) // I
+#define UC_J UC(0x004A) // J
+#define UC_K UC(0x004B) // K
+#define UC_L UC(0x004C) // L
+#define UC_M UC(0x004D) // M
+#define UC_N UC(0x004E) // N
+#define UC_O UC(0x004F) // O
+
+#define UC_P UC(0x0050) // P
+#define UC_Q UC(0x0051) // Q
+#define UC_R UC(0x0052) // R
+#define UC_S UC(0x0053) // S
+#define UC_T UC(0x0054) // T
+#define UC_U UC(0x0055) // U
+#define UC_V UC(0x0056) // V
+#define UC_W UC(0x0057) // W
+#define UC_X UC(0x0058) // X
+#define UC_Y UC(0x0059) // Y
+#define UC_Z UC(0x005A) // Z
+#define UC_LBRC UC(0x005B) // [
+#define UC_BSLS UC(0x005C) // (backslash)
+#define UC_RBRC UC(0x005D) // ]
+#define UC_CIRM UC(0x005E) // ^
+#define UC_UNDR UC(0x005F) // _
+
+#define UC_GRV UC(0x0060) // `
+#define UC_a UC(0x0061) // a
+#define UC_b UC(0x0062) // b
+#define UC_c UC(0x0063) // c
+#define UC_d UC(0x0064) // d
+#define UC_e UC(0x0065) // e
+#define UC_f UC(0x0066) // f
+#define UC_g UC(0x0067) // g
+#define UC_h UC(0x0068) // h
+#define UC_i UC(0x0069) // i
+#define UC_j UC(0x006A) // j
+#define UC_k UC(0x006B) // k
+#define UC_l UC(0x006C) // l
+#define UC_m UC(0x006D) // m
+#define UC_n UC(0x006E) // n
+#define UC_o UC(0x006F) // o
+
+#define UC_p UC(0x0070) // p
+#define UC_q UC(0x0071) // q
+#define UC_r UC(0x0072) // r
+#define UC_s UC(0x0073) // s
+#define UC_t UC(0x0074) // t
+#define UC_u UC(0x0075) // u
+#define UC_v UC(0x0076) // v
+#define UC_w UC(0x0077) // w
+#define UC_x UC(0x0078) // x
+#define UC_y UC(0x0079) // y
+#define UC_z UC(0x007A) // z
+#define UC_LCBR UC(0x007B) // {
+#define UC_PIPE UC(0x007C) // |
+#define UC_RCBR UC(0x007D) // }
+#define UC_TILD UC(0x007E) // ~
+#define UC_DEL UC(0x007F) // (delete)
diff --git a/quantum/utf8.c b/quantum/unicode/utf8.c
index 4b2cd4d8d4..4b2cd4d8d4 100644
--- a/quantum/utf8.c
+++ b/quantum/unicode/utf8.c
diff --git a/quantum/utf8.h b/quantum/unicode/utf8.h
index fb10910944..521dd1918c 100644
--- a/quantum/utf8.h
+++ b/quantum/unicode/utf8.h
@@ -18,4 +18,4 @@
#include <stdint.h>
-const char *decode_utf8(const char *str, int32_t *code_point); \ No newline at end of file
+const char *decode_utf8(const char *str, int32_t *code_point);
diff --git a/quantum/util.h b/quantum/util.h
index ab96ce4bde..9c034cc404 100644
--- a/quantum/util.h
+++ b/quantum/util.h
@@ -1,26 +1,11 @@
-/*
-Copyright 2011 Jun Wako <wakojun@gmail.com>
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
+// Copyright 2022 Stefan Kerkmann (KarlK90)
+// Copyright 2011 Jun Wako <wakojun@gmail.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
#pragma once
#include "bitwise.h"
-// convert to L string
-#define LSTR(s) XLSTR(s)
-#define XLSTR(s) L## #s
// convert to string
#define STR(s) XSTR(s)
#define XSTR(s) #s
@@ -32,3 +17,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#if !defined(MAX)
# define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif
+
+#if !defined(CEILING)
+/**
+ * @brief Computes the rounded up result of a division of two integers at
+ * compile time.
+ */
+# define CEILING(dividend, divisor) (((dividend) + (divisor)-1) / (divisor))
+#endif
+
+#if !defined(IS_ARRAY)
+/**
+ * @brief Returns true if the value is an array, false if it's a pointer.
+ *
+ * This macro is ill-formed for scalars, which is OK for its intended use in
+ * ARRAY_SIZE.
+ */
+# define IS_ARRAY(value) (!__builtin_types_compatible_p(typeof((value)), typeof(&(value)[0])))
+#endif
+
+#if !defined(ARRAY_SIZE)
+/**
+ * @brief Computes the number of elements of the given array at compile time.
+ *
+ * This Macro can only be used for statically allocated arrays that have not
+ * been decayed into a pointer. This is detected at compile time, though the
+ * error message for scalar values is poor.
+ */
+# define ARRAY_SIZE(array) (__builtin_choose_expr(IS_ARRAY((array)), sizeof((array)) / sizeof((array)[0]), (void)0))
+#endif
diff --git a/quantum/via_ensure_keycode.h b/quantum/via_ensure_keycode.h
index 75f816b560..48e611d0fa 100644
--- a/quantum/via_ensure_keycode.h
+++ b/quantum/via_ensure_keycode.h
@@ -195,6 +195,8 @@ _Static_assert(KC_MFFD == 0x00BB, "");
_Static_assert(KC_MRWD == 0x00BC, "");
_Static_assert(KC_BRIU == 0x00BD, "");
_Static_assert(KC_BRID == 0x00BE, "");
+_Static_assert(KC_CPNL == 0x00BF, "");
+_Static_assert(KC_ASST == 0x00C0, "");
_Static_assert(KC_LEFT_CTRL == 0x00E0, "");
_Static_assert(KC_LEFT_SHIFT == 0x00E1, "");
@@ -294,14 +296,14 @@ _Static_assert(RGB_M_X == 0x5CD3, "");
_Static_assert(RGB_M_G == 0x5CD4, "");
_Static_assert(RGB_M_T == 0x5CD5, "");
-_Static_assert(KC_LSPO == 0x5CD7, "");
-_Static_assert(KC_RSPC == 0x5CD8, "");
-_Static_assert(KC_SFTENT == 0x5CD9, "");
+_Static_assert(SC_LSPO == 0x5CD7, "");
+_Static_assert(SC_RSPC == 0x5CD8, "");
+_Static_assert(SC_SENT == 0x5CD9, "");
-_Static_assert(KC_LCPO == 0x5CF3, "");
-_Static_assert(KC_RCPC == 0x5CF4, "");
-_Static_assert(KC_LAPO == 0x5CF5, "");
-_Static_assert(KC_RAPC == 0x5CF6, "");
+_Static_assert(SC_LCPO == 0x5CF3, "");
+_Static_assert(SC_RCPC == 0x5CF4, "");
+_Static_assert(SC_LAPO == 0x5CF5, "");
+_Static_assert(SC_RAPC == 0x5CF6, "");
_Static_assert(FN_MO13 == 0x5F10, "");
_Static_assert(FN_MO23 == 0x5F11, "");