Skip to content

Commit df83e9d

Browse files
authored
Tidy up quantum.c now some of tmk_core has been merged (qmk#14083)
1 parent bdacb2c commit df83e9d

File tree

6 files changed

+98
-101
lines changed

6 files changed

+98
-101
lines changed

quantum/action.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,34 @@ void unregister_weak_mods(uint8_t mods) {
960960
}
961961
}
962962

963+
static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); }
964+
965+
void 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+
974+
void 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+
983+
void 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+
963991
/** \brief Utilities for actions. (FIXME: Needs better description)
964992
*
965993
* FIXME: Needs documentation.

quantum/action.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ void register_mods(uint8_t mods);
109109
void unregister_mods(uint8_t mods);
110110
void register_weak_mods(uint8_t mods);
111111
void unregister_weak_mods(uint8_t mods);
112+
void register_code16(uint16_t code);
113+
void unregister_code16(uint16_t code);
114+
void tap_code16(uint16_t code);
112115
// void set_mods(uint8_t mods);
113116
void clear_keyboard(void);
114117
void clear_keyboard_but_mods(void);
@@ -118,6 +121,8 @@ bool is_tap_key(keypos_t key);
118121
bool is_tap_record(keyrecord_t *record);
119122
bool is_tap_action(action_t action);
120123

124+
uint8_t extract_mod_bits(uint16_t code);
125+
121126
#ifndef NO_ACTION_TAPPING
122127
void process_record_tap_hint(keyrecord_t *record);
123128
#endif

quantum/action_tapping.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "action_tapping.h"
66
#include "keycode.h"
77
#include "timer.h"
8+
#include "keymap.h"
89

910
#ifdef DEBUG_ACTION
1011
# include "debug.h"
@@ -58,6 +59,40 @@ static void waiting_buffer_scan_tap(void);
5859
static void debug_tapping_key(void);
5960
static void debug_waiting_buffer(void);
6061

62+
/* Convert record into usable keycode via the contained event. */
63+
uint16_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+
*/
76+
uint16_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+
6196
/** \brief Action Tapping Process
6297
*
6398
* FIXME: Needs doc

quantum/keymap_common.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ extern keymap_config_t keymap_config;
3636

3737
#include <inttypes.h>
3838

39+
uint8_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+
3964
/* converts key to action */
4065
action_t action_for_key(uint8_t layer, keypos_t key) {
4166
// 16bit keycodes - important

quantum/quantum.c

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -51,63 +51,6 @@ float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
5151
# endif
5252
#endif
5353

54-
#ifdef AUTO_SHIFT_ENABLE
55-
# include "process_auto_shift.h"
56-
#endif
57-
58-
uint8_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-
83-
static void do_code16(uint16_t code, void (*f)(uint8_t)) { f(extract_mod_bits(code)); }
84-
85-
void 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-
94-
void 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-
103-
void 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-
11154
__attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; }
11255

11356
__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) {
14285
bootloader_jump();
14386
}
14487

145-
/* Convert record into usable keycode via the contained event. */
146-
uint16_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-
*/
160-
uint16_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-
17888
/* Get keycode, and then process pre tapping functionality */
17989
bool pre_process_record_quantum(keyrecord_t *record) {
18090
if (!(

quantum/quantum.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,23 +212,17 @@ void set_single_persistent_default_layer(uint8_t default_layer);
212212
#define IS_LAYER_ON_STATE(state, layer) layer_state_cmp(state, layer)
213213
#define IS_LAYER_OFF_STATE(state, layer) !layer_state_cmp(state, layer)
214214

215-
uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache);
216-
uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache);
217-
bool process_action_kb(keyrecord_t *record);
218-
bool process_record_kb(uint16_t keycode, keyrecord_t *record);
219-
bool process_record_user(uint16_t keycode, keyrecord_t *record);
220-
void post_process_record_kb(uint16_t keycode, keyrecord_t *record);
221-
void post_process_record_user(uint16_t keycode, keyrecord_t *record);
215+
bool process_action_kb(keyrecord_t *record);
216+
bool process_record_kb(uint16_t keycode, keyrecord_t *record);
217+
bool process_record_user(uint16_t keycode, keyrecord_t *record);
218+
void post_process_record_kb(uint16_t keycode, keyrecord_t *record);
219+
void post_process_record_user(uint16_t keycode, keyrecord_t *record);
222220

223221
void reset_keyboard(void);
224222

225223
void startup_user(void);
226224
void shutdown_user(void);
227225

228-
void register_code16(uint16_t code);
229-
void unregister_code16(uint16_t code);
230-
void tap_code16(uint16_t code);
231-
232226
void led_set_user(uint8_t usb_led);
233227
void led_set_kb(uint8_t usb_led);
234228
bool led_update_user(led_t led_state);

0 commit comments

Comments
 (0)