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.h4
-rw-r--r--quantum/keymap_common.c25
-rw-r--r--quantum/keymap_common.h19
-rw-r--r--quantum/quantum.c90
-rw-r--r--quantum/quantum.h16
8 files changed, 104 insertions, 118 deletions
diff --git a/quantum/action.c b/quantum/action.c
index ec9fcd9c9..d19fd2a04 100644
--- a/quantum/action.c
+++ b/quantum/action.c
@@ -960,34 +960,6 @@ 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
991/** \brief Utilities for actions. (FIXME: Needs better description) 963/** \brief Utilities for actions. (FIXME: Needs better description)
992 * 964 *
993 * FIXME: Needs documentation. 965 * FIXME: Needs documentation.
diff --git a/quantum/action.h b/quantum/action.h
index 4382c7ba4..3d357b33b 100644
--- a/quantum/action.h
+++ b/quantum/action.h
@@ -109,9 +109,6 @@ 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);
115// void set_mods(uint8_t mods); 112// void set_mods(uint8_t mods);
116void clear_keyboard(void); 113void clear_keyboard(void);
117void clear_keyboard_but_mods(void); 114void clear_keyboard_but_mods(void);
@@ -121,8 +118,6 @@ bool is_tap_key(keypos_t key);
121bool is_tap_record(keyrecord_t *record); 118bool is_tap_record(keyrecord_t *record);
122bool is_tap_action(action_t action); 119bool is_tap_action(action_t action);
123 120
124uint8_t extract_mod_bits(uint16_t code);
125
126#ifndef NO_ACTION_TAPPING 121#ifndef NO_ACTION_TAPPING
127void process_record_tap_hint(keyrecord_t *record); 122void process_record_tap_hint(keyrecord_t *record);
128#endif 123#endif
diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c
index 09514aa7f..36839f9fa 100644
--- a/quantum/action_tapping.c
+++ b/quantum/action_tapping.c
@@ -5,7 +5,6 @@
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_common.h"
9 8
10#ifdef DEBUG_ACTION 9#ifdef DEBUG_ACTION
11# include "debug.h" 10# include "debug.h"
@@ -59,40 +58,6 @@ static void waiting_buffer_scan_tap(void);
59static void debug_tapping_key(void); 58static void debug_tapping_key(void);
60static void debug_waiting_buffer(void); 59static void debug_waiting_buffer(void);
61 60
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
96/** \brief Action Tapping Process 61/** \brief Action Tapping Process
97 * 62 *
98 * FIXME: Needs doc 63 * FIXME: Needs doc
diff --git a/quantum/keymap.h b/quantum/keymap.h
index 6520485f7..191e81397 100644
--- a/quantum/keymap.h
+++ b/quantum/keymap.h
@@ -33,7 +33,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
33// #include "print.h" 33// #include "print.h"
34#include "debug.h" 34#include "debug.h"
35#include "keycode_config.h" 35#include "keycode_config.h"
36#include "keymap_common.h"
37 36
38// ChibiOS uses RESET in its FlagStatus enumeration 37// ChibiOS uses RESET in its FlagStatus enumeration
39// Therefore define it as QK_RESET here, to avoid name collision 38// Therefore define it as QK_RESET here, to avoid name collision
@@ -47,6 +46,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
47 46
48#include "quantum_keycodes.h" 47#include "quantum_keycodes.h"
49 48
49// translates key to keycode
50uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
51
50// translates function id to action 52// translates function id to action
51uint16_t keymap_function_id_to_action(uint16_t function_id); 53uint16_t keymap_function_id_to_action(uint16_t function_id);
52 54
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 008177bbe..780c71ab9 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -36,31 +36,6 @@ 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
64/* converts key to action */ 39/* converts key to action */
65action_t action_for_key(uint8_t layer, keypos_t key) { 40action_t action_for_key(uint8_t layer, keypos_t key) {
66 // 16bit keycodes - important 41 // 16bit keycodes - important
diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h
deleted file mode 100644
index 9ff8441e8..000000000
--- a/quantum/keymap_common.h
+++ /dev/null
@@ -1,19 +0,0 @@
1/* Copyright 2021 QMK
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#pragma once
17
18// translates key to keycode
19uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 00426c397..e60378afe 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -51,6 +51,63 @@ 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
54__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } 111__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; }
55 112
56__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); } 113__attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); }
@@ -85,6 +142,39 @@ void reset_keyboard(void) {
85 bootloader_jump(); 142 bootloader_jump();
86} 143}
87 144
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
88/* Get keycode, and then process pre tapping functionality */ 178/* Get keycode, and then process pre tapping functionality */
89bool pre_process_record_quantum(keyrecord_t *record) { 179bool pre_process_record_quantum(keyrecord_t *record) {
90 if (!( 180 if (!(
diff --git a/quantum/quantum.h b/quantum/quantum.h
index b409edef3..86b717e44 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -212,17 +212,23 @@ 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
215bool process_action_kb(keyrecord_t *record); 215uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache);
216bool process_record_kb(uint16_t keycode, keyrecord_t *record); 216uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache);
217bool process_record_user(uint16_t keycode, keyrecord_t *record); 217bool process_action_kb(keyrecord_t *record);
218void post_process_record_kb(uint16_t keycode, keyrecord_t *record); 218bool process_record_kb(uint16_t keycode, keyrecord_t *record);
219void post_process_record_user(uint16_t keycode, keyrecord_t *record); 219bool 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);
220 222
221void reset_keyboard(void); 223void reset_keyboard(void);
222 224
223void startup_user(void); 225void startup_user(void);
224void shutdown_user(void); 226void shutdown_user(void);
225 227
228void register_code16(uint16_t code);
229void unregister_code16(uint16_t code);
230void tap_code16(uint16_t code);
231
226void led_set_user(uint8_t usb_led); 232void led_set_user(uint8_t usb_led);
227void led_set_kb(uint8_t usb_led); 233void led_set_kb(uint8_t usb_led);
228bool led_update_user(led_t led_state); 234bool led_update_user(led_t led_state);