aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorprecondition <57645186+precondition@users.noreply.github.com>2021-11-25 20:06:50 +0000
committerGitHub <noreply@github.com>2021-11-26 07:06:50 +1100
commit4bac5f53d864a77a6f0fa8a2a046ed7748824ecc (patch)
tree75153ff862bdb0644e9d7622c1b80517e10a30f8 /quantum
parent5e9c29da0df045b03ada9278c34f37b22349a6f7 (diff)
downloadqmk_firmware-4bac5f53d864a77a6f0fa8a2a046ed7748824ecc.tar.gz
qmk_firmware-4bac5f53d864a77a6f0fa8a2a046ed7748824ecc.zip
New feature: `DYNAMIC_TAPPING_TERM_ENABLE` (#11036)
* New feature: `DYNAMIC_TAPPING_TERM_ENABLE` 3 new quantum keys to configure the tapping term on the fly. * Replace sprintf call in tapping_term_report by get_u16_str * Replace tab with 4 spaces
Diffstat (limited to 'quantum')
-rw-r--r--quantum/action_tapping.c8
-rw-r--r--quantum/action_tapping.h4
-rw-r--r--quantum/process_keycode/process_dynamic_tapping_term.c50
-rw-r--r--quantum/process_keycode/process_dynamic_tapping_term.h26
-rw-r--r--quantum/quantum.c3
-rw-r--r--quantum/quantum.h4
-rw-r--r--quantum/quantum_keycodes.h5
7 files changed, 97 insertions, 3 deletions
diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c
index 0586fad42..b64d8b710 100644
--- a/quantum/action_tapping.c
+++ b/quantum/action_tapping.c
@@ -24,12 +24,14 @@
24# define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) 24# define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode)
25# endif 25# endif
26 26
27__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return TAPPING_TERM; } 27uint16_t g_tapping_term = TAPPING_TERM;
28
29__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return g_tapping_term; }
28 30
29# ifdef TAPPING_TERM_PER_KEY 31# ifdef TAPPING_TERM_PER_KEY
30# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_record_keycode(&tapping_key, false), &tapping_key)) 32# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_record_keycode(&tapping_key, false), &tapping_key))
31# else 33# else
32# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM) 34# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < g_tapping_term)
33# endif 35# endif
34 36
35# ifdef TAPPING_FORCE_HOLD_PER_KEY 37# ifdef TAPPING_FORCE_HOLD_PER_KEY
@@ -158,7 +160,7 @@ bool process_tapping(keyrecord_t *keyp) {
158# ifdef TAPPING_TERM_PER_KEY 160# ifdef TAPPING_TERM_PER_KEY
159 get_tapping_term(tapping_keycode, keyp) 161 get_tapping_term(tapping_keycode, keyp)
160# else 162# else
161 TAPPING_TERM 163 g_tapping_term
162# endif 164# endif
163 >= 500 165 >= 500
164 ) 166 )
diff --git a/quantum/action_tapping.h b/quantum/action_tapping.h
index 7de8049c7..b2feb6850 100644
--- a/quantum/action_tapping.h
+++ b/quantum/action_tapping.h
@@ -33,10 +33,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
33uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache); 33uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache);
34uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache); 34uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache);
35void action_tapping_process(keyrecord_t record); 35void action_tapping_process(keyrecord_t record);
36#endif
36 37
37uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record); 38uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record);
38bool get_permissive_hold(uint16_t keycode, keyrecord_t *record); 39bool get_permissive_hold(uint16_t keycode, keyrecord_t *record);
39bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record); 40bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record);
40bool get_tapping_force_hold(uint16_t keycode, keyrecord_t *record); 41bool get_tapping_force_hold(uint16_t keycode, keyrecord_t *record);
41bool get_retro_tapping(uint16_t keycode, keyrecord_t *record); 42bool get_retro_tapping(uint16_t keycode, keyrecord_t *record);
43
44#ifdef DYNAMIC_TAPPING_TERM_ENABLE
45extern uint16_t g_tapping_term;
42#endif 46#endif
diff --git a/quantum/process_keycode/process_dynamic_tapping_term.c b/quantum/process_keycode/process_dynamic_tapping_term.c
new file mode 100644
index 000000000..bdc5529e3
--- /dev/null
+++ b/quantum/process_keycode/process_dynamic_tapping_term.c
@@ -0,0 +1,50 @@
1/* Copyright 2020 Vladislav Kucheriavykh
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 2 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
17#include "quantum.h"
18#include "process_dynamic_tapping_term.h"
19
20#ifndef DYNAMIC_TAPPING_TERM_INCREMENT
21# define DYNAMIC_TAPPING_TERM_INCREMENT 5
22#endif
23
24static void tapping_term_report(void) {
25 const char *tapping_term_str = get_u16_str(g_tapping_term, ' ');
26 // Skip padding spaces
27 while (*tapping_term_str == ' ') {
28 tapping_term_str++;
29 }
30 send_string(tapping_term_str);
31}
32
33bool process_dynamic_tapping_term(uint16_t keycode, keyrecord_t *record) {
34 if (record->event.pressed) {
35 switch (keycode) {
36 case DT_PRNT:
37 tapping_term_report();
38 return false;
39
40 case DT_UP:
41 g_tapping_term += DYNAMIC_TAPPING_TERM_INCREMENT;
42 return false;
43
44 case DT_DOWN:
45 g_tapping_term -= DYNAMIC_TAPPING_TERM_INCREMENT;
46 return false;
47 }
48 }
49 return true;
50}
diff --git a/quantum/process_keycode/process_dynamic_tapping_term.h b/quantum/process_keycode/process_dynamic_tapping_term.h
new file mode 100644
index 000000000..85e83ee73
--- /dev/null
+++ b/quantum/process_keycode/process_dynamic_tapping_term.h
@@ -0,0 +1,26 @@
1/* Copyright 2020 Vladislav Kucheriavykh
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 2 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
17#pragma once
18
19#include <stdbool.h>
20#include "action.h"
21
22#ifndef DYNAMIC_TAPPING_TERM_INCREMENT
23# define DYNAMIC_TAPPING_TERM_INCREMENT 5
24#endif
25
26bool process_dynamic_tapping_term(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index ba3ae0345..35b6351e9 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -275,6 +275,9 @@ bool process_record_quantum(keyrecord_t *record) {
275#ifdef AUTO_SHIFT_ENABLE 275#ifdef AUTO_SHIFT_ENABLE
276 process_auto_shift(keycode, record) && 276 process_auto_shift(keycode, record) &&
277#endif 277#endif
278#ifdef DYNAMIC_TAPPING_TERM_ENABLE
279 process_dynamic_tapping_term(keycode, record) &&
280#endif
278#ifdef TERMINAL_ENABLE 281#ifdef TERMINAL_ENABLE
279 process_terminal(keycode, record) && 282 process_terminal(keycode, record) &&
280#endif 283#endif
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 45050ac0e..6927884e2 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -125,6 +125,10 @@ extern layer_state_t layer_state;
125# include "process_auto_shift.h" 125# include "process_auto_shift.h"
126#endif 126#endif
127 127
128#ifdef DYNAMIC_TAPPING_TERM_ENABLE
129# include "process_dynamic_tapping_term.h"
130#endif
131
128#ifdef COMBO_ENABLE 132#ifdef COMBO_ENABLE
129# include "process_combo.h" 133# include "process_combo.h"
130#endif 134#endif
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index d013a6a16..e4d0167aa 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -524,6 +524,11 @@ enum quantum_keycodes {
524 // Additional magic key 524 // Additional magic key
525 MAGIC_TOGGLE_GUI, 525 MAGIC_TOGGLE_GUI,
526 526
527 // Adjust tapping term on the fly
528 DT_PRNT,
529 DT_UP,
530 DT_DOWN,
531
527 // Programmable Button 532 // Programmable Button
528 PROGRAMMABLE_BUTTON_1, 533 PROGRAMMABLE_BUTTON_1,
529 PROGRAMMABLE_BUTTON_2, 534 PROGRAMMABLE_BUTTON_2,