aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2016-05-15 00:47:25 -0400
committerJack Humbert <jack.humb@gmail.com>2016-05-15 00:47:25 -0400
commitbf5c2ccee5497523c214dae7aacdc27fdbb0f235 (patch)
tree0bd27929ab759c0b7fd454e9a684bb1618330af6
parent15719f3574c6274ee0f3ec87431927c5a523aa3e (diff)
downloadqmk_firmware-bf5c2ccee5497523c214dae7aacdc27fdbb0f235.tar.gz
qmk_firmware-bf5c2ccee5497523c214dae7aacdc27fdbb0f235.zip
splits process_action up to handle records separately (#329)
* implements leader key for planck experimental * allows override of leader timeout * adds ability to use the leader key in seq * fixes leader keycode * adds chording prototype * fixes keycode detection * moves music mode to quantum.c * disables chording by default * adds music sequencer functionality * implements audio/music functions in quantum.c * splits up process_action to allow independent processing of actions * merging?
-rw-r--r--quantum/keymap_common.h3
-rw-r--r--quantum/quantum.c11
-rw-r--r--tmk_core/common/action.c47
-rw-r--r--tmk_core/common/action.h7
-rw-r--r--tmk_core/common/action_tapping.c30
5 files changed, 58 insertions, 40 deletions
diff --git a/quantum/keymap_common.h b/quantum/keymap_common.h
index 4107d575b..0074ab164 100644
--- a/quantum/keymap_common.h
+++ b/quantum/keymap_common.h
@@ -191,6 +191,9 @@ extern const uint16_t fn_actions[];
191 191
192#define RESET 0x5000 192#define RESET 0x5000
193#define DEBUG 0x5001 193#define DEBUG 0x5001
194#define KC_LEAD 0x5014
195
196
194 197
195// MAGIC keycodes 198// MAGIC keycodes
196#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002 199#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002
diff --git a/quantum/quantum.c b/quantum/quantum.c
index cd7fdbb7f..dd5d84f82 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -70,7 +70,7 @@ static uint8_t music_sequence_position = 0;
70static uint16_t music_sequence_timer = 0; 70static uint16_t music_sequence_timer = 0;
71static uint16_t music_sequence_interval = 100; 71static uint16_t music_sequence_interval = 100;
72 72
73bool process_action_quantum(keyrecord_t *record) { 73bool process_record_quantum(keyrecord_t *record) {
74 74
75 /* This gets the keycode from the key pressed */ 75 /* This gets the keycode from the key pressed */
76 keypos_t key = record->event.key; 76 keypos_t key = record->event.key;
@@ -90,6 +90,14 @@ bool process_action_quantum(keyrecord_t *record) {
90 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key); 90 keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
91 #endif 91 #endif
92 92
93 // This is how you use actions here
94 // if (keycode == KC_LEAD) {
95 // action_t action;
96 // action.code = ACTION_DEFAULT_LAYER_SET(0);
97 // process_action(record, action);
98 // return false;
99 // }
100
93 #ifdef AUDIO_ENABLE 101 #ifdef AUDIO_ENABLE
94 if (keycode == AU_ON && record->event.pressed) { 102 if (keycode == AU_ON && record->event.pressed) {
95 audio_on(); 103 audio_on();
@@ -259,5 +267,6 @@ void matrix_scan_quantum() {
259 } 267 }
260 268
261 #endif 269 #endif
270
262 matrix_scan_kb(); 271 matrix_scan_kb();
263} \ No newline at end of file 272} \ No newline at end of file
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index c026b96d9..be6dea2b7 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -46,7 +46,7 @@ void action_exec(keyevent_t event)
46#ifndef NO_ACTION_TAPPING 46#ifndef NO_ACTION_TAPPING
47 action_tapping_process(record); 47 action_tapping_process(record);
48#else 48#else
49 process_action(&record); 49 process_record(&record);
50 if (!IS_NOEVENT(record.event)) { 50 if (!IS_NOEVENT(record.event)) {
51 dprint("processed: "); debug_record(record); dprintln(); 51 dprint("processed: "); debug_record(record); dprintln();
52 } 52 }
@@ -56,25 +56,43 @@ void action_exec(keyevent_t event)
56#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) 56#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
57bool disable_action_cache = false; 57bool disable_action_cache = false;
58 58
59void process_action_nocache(keyrecord_t *record) 59void process_record_nocache(keyrecord_t *record)
60{ 60{
61 disable_action_cache = true; 61 disable_action_cache = true;
62 process_action(record); 62 process_record(record);
63 disable_action_cache = false; 63 disable_action_cache = false;
64} 64}
65#else 65#else
66void process_action_nocache(keyrecord_t *record) 66void process_record_nocache(keyrecord_t *record)
67{ 67{
68 process_action(record); 68 process_record(record);
69} 69}
70#endif 70#endif
71 71
72__attribute__ ((weak)) 72__attribute__ ((weak))
73bool process_action_quantum(keyrecord_t *record) { 73bool process_record_quantum(keyrecord_t *record) {
74 return true; 74 return true;
75} 75}
76 76
77void process_action(keyrecord_t *record) 77void process_record(keyrecord_t *record)
78{
79 if (IS_NOEVENT(record->event)) { return; }
80
81 if(!process_record_quantum(record))
82 return;
83
84 action_t action = store_or_get_action(record->event.pressed, record->event.key);
85 dprint("ACTION: "); debug_action(action);
86#ifndef NO_ACTION_LAYER
87 dprint(" layer_state: "); layer_debug();
88 dprint(" default_layer_state: "); default_layer_debug();
89#endif
90 dprintln();
91
92 process_action(record, action);
93}
94
95void process_action(keyrecord_t *record, action_t action)
78{ 96{
79 bool do_release_oneshot = false; 97 bool do_release_oneshot = false;
80 keyevent_t event = record->event; 98 keyevent_t event = record->event;
@@ -82,8 +100,6 @@ void process_action(keyrecord_t *record)
82 uint8_t tap_count = record->tap.count; 100 uint8_t tap_count = record->tap.count;
83#endif 101#endif
84 102
85 if (IS_NOEVENT(event)) { return; }
86
87#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) 103#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
88 if (has_oneshot_layer_timed_out()) { 104 if (has_oneshot_layer_timed_out()) {
89 dprintf("Oneshot layer: timeout\n"); 105 dprintf("Oneshot layer: timeout\n");
@@ -91,17 +107,6 @@ void process_action(keyrecord_t *record)
91 } 107 }
92#endif 108#endif
93 109
94 if (!process_action_quantum(record))
95 return;
96
97 action_t action = store_or_get_action(event.pressed, event.key);
98 dprint("ACTION: "); debug_action(action);
99#ifndef NO_ACTION_LAYER
100 dprint(" layer_state: "); layer_debug();
101 dprint(" default_layer_state: "); default_layer_debug();
102#endif
103 dprintln();
104
105 if (event.pressed) { 110 if (event.pressed) {
106 // clear the potential weak mods left by previously pressed keys 111 // clear the potential weak mods left by previously pressed keys
107 clear_weak_mods(); 112 clear_weak_mods();
@@ -451,7 +456,7 @@ void process_action(keyrecord_t *record)
451 if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED ) ) { 456 if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED ) ) {
452 record->event.pressed = false; 457 record->event.pressed = false;
453 layer_on(get_oneshot_layer()); 458 layer_on(get_oneshot_layer());
454 process_action(record); 459 process_record(record);
455 layer_off(get_oneshot_layer()); 460 layer_off(get_oneshot_layer());
456 } 461 }
457#endif 462#endif
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h
index 7d1cbafe9..e8aa12a7c 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -59,14 +59,15 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
59void action_function(keyrecord_t *record, uint8_t id, uint8_t opt); 59void action_function(keyrecord_t *record, uint8_t id, uint8_t opt);
60 60
61/* keyboard-specific key event (pre)processing */ 61/* keyboard-specific key event (pre)processing */
62bool process_action_quantum(keyrecord_t *record); 62bool process_record_quantum(keyrecord_t *record);
63 63
64/* Utilities for actions. */ 64/* Utilities for actions. */
65#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) 65#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
66extern bool disable_action_cache; 66extern bool disable_action_cache;
67#endif 67#endif
68void process_action_nocache(keyrecord_t *record); 68void process_record_nocache(keyrecord_t *record);
69void process_action(keyrecord_t *record); 69void process_record(keyrecord_t *record);
70void process_action(keyrecord_t *record, action_t action);
70void register_code(uint8_t code); 71void register_code(uint8_t code);
71void unregister_code(uint8_t code); 72void unregister_code(uint8_t code);
72void register_mods(uint8_t mods); 73void register_mods(uint8_t mods);
diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c
index e6343e6da..ff78d7f2a 100644
--- a/tmk_core/common/action_tapping.c
+++ b/tmk_core/common/action_tapping.c
@@ -89,7 +89,7 @@ bool process_tapping(keyrecord_t *keyp)
89 debug("Tapping: First tap(0->1).\n"); 89 debug("Tapping: First tap(0->1).\n");
90 tapping_key.tap.count = 1; 90 tapping_key.tap.count = 1;
91 debug_tapping_key(); 91 debug_tapping_key();
92 process_action(&tapping_key); 92 process_record(&tapping_key);
93 93
94 // copy tapping state 94 // copy tapping state
95 keyp->tap = tapping_key.tap; 95 keyp->tap = tapping_key.tap;
@@ -103,7 +103,7 @@ bool process_tapping(keyrecord_t *keyp)
103 */ 103 */
104 else if (IS_RELEASED(event) && waiting_buffer_typed(event)) { 104 else if (IS_RELEASED(event) && waiting_buffer_typed(event)) {
105 debug("Tapping: End. No tap. Interfered by typing key\n"); 105 debug("Tapping: End. No tap. Interfered by typing key\n");
106 process_action(&tapping_key); 106 process_record(&tapping_key);
107 tapping_key = (keyrecord_t){}; 107 tapping_key = (keyrecord_t){};
108 debug_tapping_key(); 108 debug_tapping_key();
109 // enqueue 109 // enqueue
@@ -131,7 +131,7 @@ bool process_tapping(keyrecord_t *keyp)
131 } 131 }
132 // Release of key should be process immediately. 132 // Release of key should be process immediately.
133 debug("Tapping: release event of a key pressed before tapping\n"); 133 debug("Tapping: release event of a key pressed before tapping\n");
134 process_action(keyp); 134 process_record(keyp);
135 return true; 135 return true;
136 } 136 }
137 else { 137 else {
@@ -148,7 +148,7 @@ bool process_tapping(keyrecord_t *keyp)
148 if (IS_TAPPING_KEY(event.key) && !event.pressed) { 148 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
149 debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n"); 149 debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n");
150 keyp->tap = tapping_key.tap; 150 keyp->tap = tapping_key.tap;
151 process_action(keyp); 151 process_record(keyp);
152 tapping_key = *keyp; 152 tapping_key = *keyp;
153 debug_tapping_key(); 153 debug_tapping_key();
154 return true; 154 return true;
@@ -157,7 +157,7 @@ bool process_tapping(keyrecord_t *keyp)
157 if (tapping_key.tap.count > 1) { 157 if (tapping_key.tap.count > 1) {
158 debug("Tapping: Start new tap with releasing last tap(>1).\n"); 158 debug("Tapping: Start new tap with releasing last tap(>1).\n");
159 // unregister key 159 // unregister key
160 process_action(&(keyrecord_t){ 160 process_record(&(keyrecord_t){
161 .tap = tapping_key.tap, 161 .tap = tapping_key.tap,
162 .event.key = tapping_key.event.key, 162 .event.key = tapping_key.event.key,
163 .event.time = event.time, 163 .event.time = event.time,
@@ -175,7 +175,7 @@ bool process_tapping(keyrecord_t *keyp)
175 if (!IS_NOEVENT(event)) { 175 if (!IS_NOEVENT(event)) {
176 debug("Tapping: key event while last tap(>0).\n"); 176 debug("Tapping: key event while last tap(>0).\n");
177 } 177 }
178 process_action(keyp); 178 process_record(keyp);
179 return true; 179 return true;
180 } 180 }
181 } 181 }
@@ -185,7 +185,7 @@ bool process_tapping(keyrecord_t *keyp)
185 if (tapping_key.tap.count == 0) { 185 if (tapping_key.tap.count == 0) {
186 debug("Tapping: End. Timeout. Not tap(0): "); 186 debug("Tapping: End. Timeout. Not tap(0): ");
187 debug_event(event); debug("\n"); 187 debug_event(event); debug("\n");
188 process_action(&tapping_key); 188 process_record(&tapping_key);
189 tapping_key = (keyrecord_t){}; 189 tapping_key = (keyrecord_t){};
190 debug_tapping_key(); 190 debug_tapping_key();
191 return false; 191 return false;
@@ -193,7 +193,7 @@ bool process_tapping(keyrecord_t *keyp)
193 if (IS_TAPPING_KEY(event.key) && !event.pressed) { 193 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
194 debug("Tapping: End. last timeout tap release(>0)."); 194 debug("Tapping: End. last timeout tap release(>0).");
195 keyp->tap = tapping_key.tap; 195 keyp->tap = tapping_key.tap;
196 process_action(keyp); 196 process_record(keyp);
197 tapping_key = (keyrecord_t){}; 197 tapping_key = (keyrecord_t){};
198 return true; 198 return true;
199 } 199 }
@@ -201,7 +201,7 @@ bool process_tapping(keyrecord_t *keyp)
201 if (tapping_key.tap.count > 1) { 201 if (tapping_key.tap.count > 1) {
202 debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); 202 debug("Tapping: Start new tap with releasing last timeout tap(>1).\n");
203 // unregister key 203 // unregister key
204 process_action(&(keyrecord_t){ 204 process_record(&(keyrecord_t){
205 .tap = tapping_key.tap, 205 .tap = tapping_key.tap,
206 .event.key = tapping_key.event.key, 206 .event.key = tapping_key.event.key,
207 .event.time = event.time, 207 .event.time = event.time,
@@ -219,7 +219,7 @@ bool process_tapping(keyrecord_t *keyp)
219 if (!IS_NOEVENT(event)) { 219 if (!IS_NOEVENT(event)) {
220 debug("Tapping: key event while last timeout tap(>0).\n"); 220 debug("Tapping: key event while last timeout tap(>0).\n");
221 } 221 }
222 process_action(keyp); 222 process_record(keyp);
223 return true; 223 return true;
224 } 224 }
225 } 225 }
@@ -233,7 +233,7 @@ bool process_tapping(keyrecord_t *keyp)
233 keyp->tap = tapping_key.tap; 233 keyp->tap = tapping_key.tap;
234 if (keyp->tap.count < 15) keyp->tap.count += 1; 234 if (keyp->tap.count < 15) keyp->tap.count += 1;
235 debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n"); 235 debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n");
236 process_action(keyp); 236 process_record(keyp);
237 tapping_key = *keyp; 237 tapping_key = *keyp;
238 debug_tapping_key(); 238 debug_tapping_key();
239 return true; 239 return true;
@@ -253,12 +253,12 @@ bool process_tapping(keyrecord_t *keyp)
253 // should none in buffer 253 // should none in buffer
254 // FIX: interrupted when other key is pressed 254 // FIX: interrupted when other key is pressed
255 tapping_key.tap.interrupted = true; 255 tapping_key.tap.interrupted = true;
256 process_action(keyp); 256 process_record(keyp);
257 return true; 257 return true;
258 } 258 }
259 } else { 259 } else {
260 if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n"); 260 if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n");
261 process_action(keyp); 261 process_record(keyp);
262 return true; 262 return true;
263 } 263 }
264 } else { 264 } else {
@@ -280,7 +280,7 @@ bool process_tapping(keyrecord_t *keyp)
280 debug_tapping_key(); 280 debug_tapping_key();
281 return true; 281 return true;
282 } else { 282 } else {
283 process_action(keyp); 283 process_record(keyp);
284 return true; 284 return true;
285 } 285 }
286 } 286 }
@@ -347,7 +347,7 @@ void waiting_buffer_scan_tap(void)
347 WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { 347 WITHIN_TAPPING_TERM(waiting_buffer[i].event)) {
348 tapping_key.tap.count = 1; 348 tapping_key.tap.count = 1;
349 waiting_buffer[i].tap.count = 1; 349 waiting_buffer[i].tap.count = 1;
350 process_action(&tapping_key); 350 process_record(&tapping_key);
351 351
352 debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); 352 debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n");
353 debug_waiting_buffer(); 353 debug_waiting_buffer();