aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quantum/action.c28
-rw-r--r--quantum/action.h5
-rw-r--r--quantum/action_tapping.c35
-rw-r--r--quantum/keymap_common.c25
-rw-r--r--quantum/quantum.c90
-rw-r--r--quantum/quantum.h16
6 files changed, 98 insertions, 101 deletions
diff --git a/quantum/action.c b/quantum/action.c
index d19fd2a04..ec9fcd9c9 100644
--- a/quantum/action.c
+++ b/quantum/action.c
@@ -960,6 +960,34 @@ void unregister_weak_mods(uint8_t mods) {
960 } 960 }
961} 961}
962 962
963static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); }
964
965void register_code16(uint16_t code) {
966 if (IS_MOD(code) || code == KC_NO) {
967 do_code16(code, register_mods);
968 } else {
969 do_code16(code, register_weak_mods);
970 }
971 register_code(code);
972}
973
974void unregister_code16(uint16_t code) {
975 unregister_code(code);
976 if (IS_MOD(code) || code == KC_NO) {
977 do_code16(code, unregister_mods);
978 } else {
979 do_code16(code, unregister_weak_mods);
980 }
981}
982
983void tap_code16(uint16_t code) {
984 register_code16(code);
985#if TAP_CODE_DELAY > 0
986 wait_ms(TAP_CODE_DELAY);
987#endif
988 unregister_code16(code);
989}
990
963/** \brief Utilities for actions. (FIXME: Needs better description) 991/** \brief Utilities for actions. (FIXME: Needs better description)
964 * 992 *
965 * FIXME: Needs documentation. 993 * FIXME: Needs documentation.
diff --git a/quantum/action.h b/quantum/action.h
index 3d357b33b..4382c7ba4 100644
--- a/quantum/action.h
+++ b/quantum/action.h
@@ -109,6 +109,9 @@ void register_mods(uint8_t mods);
109void unregister_mods(uint8_t mods); 109void unregister_mods(uint8_t mods);
110void register_weak_mods(uint8_t mods); 110void register_weak_mods(uint8_t mods);
111void unregister_weak_mods(uint8_t mods); 111void unregister_weak_mods(uint8_t mods);
112void register_code16(uint16_t code);
113void unregister_code16(uint16_t code);
114void tap_code16(uint16_t code);
112// void set_mods(uint8_t mods); 115// void set_mods(uint8_t mods);
113void clear_keyboard(void); 116void clear_keyboard(void);
114void clear_keyboard_but_mods(void); 117void clear_keyboard_but_mods(void);
@@ -118,6 +121,8 @@ bool is_tap_key(keypos_t key);
118bool is_tap_record(keyrecord_t *record); 121bool is_tap_record(keyrecord_t *record);
119bool is_tap_action(action_t action); 122bool is_tap_action(action_t action);
120 123
124uint8_t extract_mod_bits(uint16_t code);
125
121#ifndef NO_ACTION_TAPPING 126#ifndef NO_ACTION_TAPPING
122void process_record_tap_hint(keyrecord_t *record); 127void process_record_tap_hint(keyrecord_t *record);
123#endif 128#endif
diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c
index 36839f9fa..eef6ed1b7 100644
--- a/quantum/action_tapping.c
+++ b/quantum/action_tapping.c
@@ -5,6 +5,7 @@
5#include "action_tapping.h" 5#include "action_tapping.h"
6#include "keycode.h" 6#include "keycode.h"
7#include "timer.h" 7#include "timer.h"
8#include "keymap.h"
8 9
9#ifdef DEBUG_ACTION 10#ifdef DEBUG_ACTION
10# include "debug.h" 11# include "debug.h"
@@ -58,6 +59,40 @@ static void waiting_buffer_scan_tap(void);
58static void debug_tapping_key(void); 59static void debug_tapping_key(void);
59static void debug_waiting_buffer(void); 60static void debug_waiting_buffer(void);
60 61
62/* Convert record into usable keycode via the contained event. */
63uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) {
64#ifdef COMBO_ENABLE
65 if (record->keycode) { return record->keycode; }
66#endif
67 return get_event_keycode(record->event, update_layer_cache);
68}
69
70/* Convert event into usable keycode. Checks the layer cache to ensure that it
71 * retains the correct keycode after a layer change, if the key is still pressed.
72 * "update_layer_cache" is to ensure that it only updates the layer cache when
73 * appropriate, otherwise, it will update it and cause layer tap (and other keys)
74 * from triggering properly.
75 */
76uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) {
77 const keypos_t key = event.key;
78
79#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
80 /* TODO: Use store_or_get_action() or a similar function. */
81 if (!disable_action_cache) {
82 uint8_t layer;
83
84 if (event.pressed && update_layer_cache) {
85 layer = layer_switch_get_layer(key);
86 update_source_layers_cache(key, layer);
87 } else {
88 layer = read_source_layers_cache(key);
89 }
90 return keymap_key_to_keycode(layer, key);
91 }
92#endif
93 return keymap_key_to_keycode(layer_switch_get_layer(key), key);
94}
95
61/** \brief Action Tapping Process 96/** \brief Action Tapping Process
62 * 97 *
63 * FIXME: Needs doc 98 * FIXME: Needs doc
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 780c71ab9..008177bbe 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -36,6 +36,31 @@ extern keymap_config_t keymap_config;
36 36
37#include <inttypes.h> 37#include <inttypes.h>
38 38
39uint8_t extract_mod_bits(uint16_t code) {
40 switch (code) {
41 case QK_MODS ... QK_MODS_MAX:
42 break;
43 default:
44 return 0;
45 }
46
47 uint8_t mods_to_send = 0;
48
49 if (code & QK_RMODS_MIN) { // Right mod flag is set
50 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RCTL);
51 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT);
52 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT);
53 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI);
54 } else {
55 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL);
56 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT);
57 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT);
58 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI);
59 }
60
61 return mods_to_send;
62}
63
39/* converts key to action */ 64/* converts key to action */
40action_t action_for_key(uint8_t layer, keypos_t key) { 65action_t action_for_key(uint8_t layer, keypos_t key) {
41 // 16bit keycodes - important 66 // 16bit keycodes - important
diff --git a/quantum/quantum.c b/quantum/quantum.c
index e60378afe..00426c397 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -51,63 +51,6 @@ float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
51# endif 51# endif
52#endif 52#endif
53 53
54#ifdef AUTO_SHIFT_ENABLE
55# include "process_auto_shift.h"
56#endif
57
58uint8_t extract_mod_bits(uint16_t code) {
59 switch (code) {
60 case QK_MODS ... QK_MODS_MAX:
61 break;
62 default:
63 return 0;
64 }
65
66 uint8_t mods_to_send = 0;
67
68 if (code & QK_RMODS_MIN) { // Right mod flag is set
69 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_RCTL);
70 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_RSFT);
71 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_RALT);
72 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_RGUI);
73 } else {
74 if (code & QK_LCTL) mods_to_send |= MOD_BIT(KC_LCTL);
75 if (code & QK_LSFT) mods_to_send |= MOD_BIT(KC_LSFT);
76 if (code & QK_LALT) mods_to_send |= MOD_BIT(KC_LALT);
77 if (code & QK_LGUI) mods_to_send |= MOD_BIT(KC_LGUI);
78 }
79
80 return mods_to_send;
81}
82
83static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); }
84
85void register_code16(uint16_t code) {
86 if (IS_MOD(code) || code == KC_NO) {
87 do_code16(code, register_mods);
88 } else {
89 do_code16(code, register_weak_mods);
90 }
91 register_code(code);
92}
93
94void unregister_code16(uint16_t code) {
95 unregister_code(code);
96 if (IS_MOD(code) || code == KC_NO) {
97 do_code16(code, unregister_mods);
98 } else {
99 do_code16(code, unregister_weak_mods);
100 }
101}
102
103void tap_code16(uint16_t code) {
104 register_code16(code);
105#if TAP_CODE_DELAY > 0
106 wait_ms(TAP_CODE_DELAY);
107#endif
108 unregister_code16(code);
109}
110
111__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } 54__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; }
112 55
113__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); } 56__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); }
@@ -142,39 +85,6 @@ void reset_keyboard(void) {
142 bootloader_jump(); 85 bootloader_jump();
143} 86}
144 87
145/* Convert record into usable keycode via the contained event. */
146uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) {
147#ifdef COMBO_ENABLE
148 if (record->keycode) { return record->keycode; }
149#endif
150 return get_event_keycode(record->event, update_layer_cache);
151}
152
153
154/* Convert event into usable keycode. Checks the layer cache to ensure that it
155 * retains the correct keycode after a layer change, if the key is still pressed.
156 * "update_layer_cache" is to ensure that it only updates the layer cache when
157 * appropriate, otherwise, it will update it and cause layer tap (and other keys)
158 * from triggering properly.
159 */
160uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) {
161#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
162 /* TODO: Use store_or_get_action() or a similar function. */
163 if (!disable_action_cache) {
164 uint8_t layer;
165
166 if (event.pressed && update_layer_cache) {
167 layer = layer_switch_get_layer(event.key);
168 update_source_layers_cache(event.key, layer);
169 } else {
170 layer = read_source_layers_cache(event.key);
171 }
172 return keymap_key_to_keycode(layer, event.key);
173 } else
174#endif
175 return keymap_key_to_keycode(layer_switch_get_layer(event.key), event.key);
176}
177
178/* Get keycode, and then process pre tapping functionality */ 88/* Get keycode, and then process pre tapping functionality */
179bool pre_process_record_quantum(keyrecord_t *record) { 89bool pre_process_record_quantum(keyrecord_t *record) {
180 if (!( 90 if (!(
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 86b717e44..b409edef3 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -212,23 +212,17 @@ void set_single_persistent_default_layer(uint8_t default_layer);
212#define IS_LAYER_ON_STATE(state, layer) layer_state_cmp(state, layer) 212#define IS_LAYER_ON_STATE(state, layer) layer_state_cmp(state, layer)
213#define IS_LAYER_OFF_STATE(state, layer) !layer_state_cmp(state, layer) 213#define IS_LAYER_OFF_STATE(state, layer) !layer_state_cmp(state, layer)
214 214
215uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache); 215bool process_action_kb(keyrecord_t *record);
216uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache); 216bool process_record_kb(uint16_t keycode, keyrecord_t *record);
217bool process_action_kb(keyrecord_t *record); 217bool process_record_user(uint16_t keycode, keyrecord_t *record);
218bool process_record_kb(uint16_t keycode, keyrecord_t *record); 218void post_process_record_kb(uint16_t keycode, keyrecord_t *record);
219bool process_record_user(uint16_t keycode, keyrecord_t *record); 219void post_process_record_user(uint16_t keycode, keyrecord_t *record);
220void post_process_record_kb(uint16_t keycode, keyrecord_t *record);
221void post_process_record_user(uint16_t keycode, keyrecord_t *record);
222 220
223void reset_keyboard(void); 221void reset_keyboard(void);
224 222
225void startup_user(void); 223void startup_user(void);
226void shutdown_user(void); 224void shutdown_user(void);
227 225
228void register_code16(uint16_t code);
229void unregister_code16(uint16_t code);
230void tap_code16(uint16_t code);
231
232void led_set_user(uint8_t usb_led); 226void led_set_user(uint8_t usb_led);
233void led_set_kb(uint8_t usb_led); 227void led_set_kb(uint8_t usb_led);
234bool led_update_user(led_t led_state); 228bool led_update_user(led_t led_state);