diff options
| author | Stefan Kerkmann <karlk90@pm.me> | 2023-04-03 10:33:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-03 18:33:45 +1000 |
| commit | fcf8b804ed95a98561bd4c1d6c85604be0f7cc7b (patch) | |
| tree | 6b6917d99ced027d614e7b461e1cd1939833a9cd /quantum | |
| parent | 2d9140af53e4e5bbc5cd50a2b6f3eda20ed8f71e (diff) | |
[Core] Refactor `keyevent_t` for 1ms timing resolution (#15847)
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/action_tapping.c | 116 | ||||
| -rw-r--r-- | quantum/encoder.c | 4 | ||||
| -rw-r--r-- | quantum/keyboard.c | 2 | ||||
| -rw-r--r-- | quantum/keyboard.h | 59 | ||||
| -rw-r--r-- | quantum/process_keycode/process_combo.c | 10 | ||||
| -rw-r--r-- | quantum/process_keycode/process_steno.c | 6 |
6 files changed, 106 insertions, 91 deletions
diff --git a/quantum/action_tapping.c b/quantum/action_tapping.c index dbb5b8d4e5..362b15105c 100644 --- a/quantum/action_tapping.c +++ b/quantum/action_tapping.c | |||
| @@ -15,14 +15,10 @@ | |||
| 15 | # error "IGNORE_MOD_TAP_INTERRUPT is no longer necessary as it is now the default behavior of mod-tap keys. Please remove it from your config." | 15 | # error "IGNORE_MOD_TAP_INTERRUPT is no longer necessary as it is now the default behavior of mod-tap keys. Please remove it from your config." |
| 16 | # endif | 16 | # endif |
| 17 | 17 | ||
| 18 | # define IS_TAPPING() IS_EVENT(tapping_key.event) | ||
| 19 | # define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed) | ||
| 20 | # define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) | ||
| 21 | # define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) | ||
| 22 | # ifndef COMBO_ENABLE | 18 | # ifndef COMBO_ENABLE |
| 23 | # define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key))) | 19 | # define IS_TAPPING_RECORD(r) (KEYEQ(tapping_key.event.key, (r->event.key))) |
| 24 | # else | 20 | # else |
| 25 | # define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) | 21 | # define IS_TAPPING_RECORD(r) (KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) |
| 26 | # endif | 22 | # endif |
| 27 | # 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)) | 23 | # 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)) |
| 28 | # define WITHIN_QUICK_TAP_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < GET_QUICK_TAP_TERM(get_record_keycode(&tapping_key, false), &tapping_key)) | 24 | # define WITHIN_QUICK_TAP_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < GET_QUICK_TAP_TERM(get_record_keycode(&tapping_key, false), &tapping_key)) |
| @@ -94,7 +90,7 @@ void action_tapping_process(keyrecord_t record) { | |||
| 94 | ac_dprintf("OVERFLOW: CLEAR ALL STATES\n"); | 90 | ac_dprintf("OVERFLOW: CLEAR ALL STATES\n"); |
| 95 | clear_keyboard(); | 91 | clear_keyboard(); |
| 96 | waiting_buffer_clear(); | 92 | waiting_buffer_clear(); |
| 97 | tapping_key = (keyrecord_t){}; | 93 | tapping_key = (keyrecord_t){0}; |
| 98 | } | 94 | } |
| 99 | } | 95 | } |
| 100 | 96 | ||
| @@ -121,7 +117,7 @@ void action_tapping_process(keyrecord_t record) { | |||
| 121 | * conditional uses of it are hidden inside macros named TAP_... | 117 | * conditional uses of it are hidden inside macros named TAP_... |
| 122 | */ | 118 | */ |
| 123 | # if (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) || defined(PERMISSIVE_HOLD_PER_KEY) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) | 119 | # if (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)) || defined(PERMISSIVE_HOLD_PER_KEY) || defined(HOLD_ON_OTHER_KEY_PRESS_PER_KEY) |
| 124 | # define TAP_DEFINE_KEYCODE uint16_t tapping_keycode = get_record_keycode(&tapping_key, false) | 120 | # define TAP_DEFINE_KEYCODE const uint16_t tapping_keycode = get_record_keycode(&tapping_key, false) |
| 125 | # else | 121 | # else |
| 126 | # define TAP_DEFINE_KEYCODE | 122 | # define TAP_DEFINE_KEYCODE |
| 127 | # endif | 123 | # endif |
| @@ -167,12 +163,37 @@ void action_tapping_process(keyrecord_t record) { | |||
| 167 | */ | 163 | */ |
| 168 | /* return true when key event is processed or consumed. */ | 164 | /* return true when key event is processed or consumed. */ |
| 169 | bool process_tapping(keyrecord_t *keyp) { | 165 | bool process_tapping(keyrecord_t *keyp) { |
| 170 | keyevent_t event = keyp->event; | 166 | const keyevent_t event = keyp->event; |
| 167 | |||
| 168 | // state machine is in the "reset" state, no tapping key is to be | ||
| 169 | // processed | ||
| 170 | if (IS_NOEVENT(tapping_key.event) && IS_EVENT(event)) { | ||
| 171 | if (event.pressed && is_tap_record(keyp)) { | ||
| 172 | // the currently pressed key is a tapping key, therefore transition | ||
| 173 | // into the "pressed" tapping key state | ||
| 174 | ac_dprintf("Tapping: Start(Press tap key).\n"); | ||
| 175 | tapping_key = *keyp; | ||
| 176 | process_record_tap_hint(&tapping_key); | ||
| 177 | waiting_buffer_scan_tap(); | ||
| 178 | debug_tapping_key(); | ||
| 179 | return true; | ||
| 180 | } else { | ||
| 181 | // the current key is just a regular key, pass it on for regular | ||
| 182 | // processing | ||
| 183 | process_record(keyp); | ||
| 184 | return true; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 171 | TAP_DEFINE_KEYCODE; | 188 | TAP_DEFINE_KEYCODE; |
| 172 | 189 | ||
| 173 | // if tapping | 190 | // process "pressed" tapping key state |
| 174 | if (IS_TAPPING_PRESSED()) { | 191 | if (tapping_key.event.pressed) { |
| 175 | if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event)) { | 192 | if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event)) { |
| 193 | if (IS_NOEVENT(event)) { | ||
| 194 | // early return for tick events | ||
| 195 | return true; | ||
| 196 | } | ||
| 176 | if (tapping_key.tap.count == 0) { | 197 | if (tapping_key.tap.count == 0) { |
| 177 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { | 198 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { |
| 178 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) | 199 | # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) |
| @@ -196,7 +217,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 196 | // clang-format off | 217 | // clang-format off |
| 197 | else if ( | 218 | else if ( |
| 198 | ( | 219 | ( |
| 199 | IS_RELEASED(event) && waiting_buffer_typed(event) && | 220 | !event.pressed && waiting_buffer_typed(event) && |
| 200 | TAP_GET_PERMISSIVE_HOLD | 221 | TAP_GET_PERMISSIVE_HOLD |
| 201 | ) | 222 | ) |
| 202 | // Causes nested taps to not wait past TAPPING_TERM/RETRO_SHIFT | 223 | // Causes nested taps to not wait past TAPPING_TERM/RETRO_SHIFT |
| @@ -214,7 +235,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 214 | || ( | 235 | || ( |
| 215 | TAP_IS_RETRO | 236 | TAP_IS_RETRO |
| 216 | && (event.key.col != tapping_key.event.key.col || event.key.row != tapping_key.event.key.row) | 237 | && (event.key.col != tapping_key.event.key.col || event.key.row != tapping_key.event.key.row) |
| 217 | && IS_RELEASED(event) && waiting_buffer_typed(event) | 238 | && !event.pressed && waiting_buffer_typed(event) |
| 218 | ) | 239 | ) |
| 219 | ) | 240 | ) |
| 220 | ) | 241 | ) |
| @@ -222,7 +243,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 222 | // clang-format on | 243 | // clang-format on |
| 223 | ac_dprintf("Tapping: End. No tap. Interfered by typing key\n"); | 244 | ac_dprintf("Tapping: End. No tap. Interfered by typing key\n"); |
| 224 | process_record(&tapping_key); | 245 | process_record(&tapping_key); |
| 225 | tapping_key = (keyrecord_t){}; | 246 | tapping_key = (keyrecord_t){0}; |
| 226 | debug_tapping_key(); | 247 | debug_tapping_key(); |
| 227 | // enqueue | 248 | // enqueue |
| 228 | return false; | 249 | return false; |
| @@ -231,7 +252,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 231 | * Without this unexpected repeating will occur with having fast repeating setting | 252 | * Without this unexpected repeating will occur with having fast repeating setting |
| 232 | * https://github.com/tmk/tmk_keyboard/issues/60 | 253 | * https://github.com/tmk/tmk_keyboard/issues/60 |
| 233 | */ | 254 | */ |
| 234 | else if (IS_RELEASED(event) && !waiting_buffer_typed(event)) { | 255 | else if (!event.pressed && !waiting_buffer_typed(event)) { |
| 235 | // Modifier/Layer should be retained till end of this tapping. | 256 | // Modifier/Layer should be retained till end of this tapping. |
| 236 | action_t action = layer_switch_get_action(event.key); | 257 | action_t action = layer_switch_get_action(event.key); |
| 237 | switch (action.kind.id) { | 258 | switch (action.kind.id) { |
| @@ -267,7 +288,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 267 | if (TAP_GET_HOLD_ON_OTHER_KEY_PRESS) { | 288 | if (TAP_GET_HOLD_ON_OTHER_KEY_PRESS) { |
| 268 | ac_dprintf("Tapping: End. No tap. Interfered by pressed key\n"); | 289 | ac_dprintf("Tapping: End. No tap. Interfered by pressed key\n"); |
| 269 | process_record(&tapping_key); | 290 | process_record(&tapping_key); |
| 270 | tapping_key = (keyrecord_t){}; | 291 | tapping_key = (keyrecord_t){0}; |
| 271 | debug_tapping_key(); | 292 | debug_tapping_key(); |
| 272 | // enqueue | 293 | // enqueue |
| 273 | return false; | 294 | return false; |
| @@ -295,6 +316,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 295 | .event.key = tapping_key.event.key, | 316 | .event.key = tapping_key.event.key, |
| 296 | .event.time = event.time, | 317 | .event.time = event.time, |
| 297 | .event.pressed = false, | 318 | .event.pressed = false, |
| 319 | .event.type = tapping_key.event.type, | ||
| 298 | # ifdef COMBO_ENABLE | 320 | # ifdef COMBO_ENABLE |
| 299 | .keycode = tapping_key.keycode, | 321 | .keycode = tapping_key.keycode, |
| 300 | # endif | 322 | # endif |
| @@ -307,9 +329,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 307 | debug_tapping_key(); | 329 | debug_tapping_key(); |
| 308 | return true; | 330 | return true; |
| 309 | } else { | 331 | } else { |
| 310 | if (IS_EVENT(event)) { | 332 | ac_dprintf("Tapping: key event while last tap(>0).\n"); |
| 311 | ac_dprintf("Tapping: key event while last tap(>0).\n"); | ||
| 312 | } | ||
| 313 | process_record(keyp); | 333 | process_record(keyp); |
| 314 | return true; | 334 | return true; |
| 315 | } | 335 | } |
| @@ -322,15 +342,18 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 322 | debug_event(event); | 342 | debug_event(event); |
| 323 | ac_dprintf("\n"); | 343 | ac_dprintf("\n"); |
| 324 | process_record(&tapping_key); | 344 | process_record(&tapping_key); |
| 325 | tapping_key = (keyrecord_t){}; | 345 | tapping_key = (keyrecord_t){0}; |
| 326 | debug_tapping_key(); | 346 | debug_tapping_key(); |
| 327 | return false; | 347 | return false; |
| 328 | } else { | 348 | } else { |
| 349 | if (IS_NOEVENT(event)) { | ||
| 350 | return true; | ||
| 351 | } | ||
| 329 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { | 352 | if (IS_TAPPING_RECORD(keyp) && !event.pressed) { |
| 330 | ac_dprintf("Tapping: End. last timeout tap release(>0)."); | 353 | ac_dprintf("Tapping: End. last timeout tap release(>0)."); |
| 331 | keyp->tap = tapping_key.tap; | 354 | keyp->tap = tapping_key.tap; |
| 332 | process_record(keyp); | 355 | process_record(keyp); |
| 333 | tapping_key = (keyrecord_t){}; | 356 | tapping_key = (keyrecord_t){0}; |
| 334 | return true; | 357 | return true; |
| 335 | } else if (is_tap_record(keyp) && event.pressed) { | 358 | } else if (is_tap_record(keyp) && event.pressed) { |
| 336 | if (tapping_key.tap.count > 1) { | 359 | if (tapping_key.tap.count > 1) { |
| @@ -341,6 +364,7 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 341 | .event.key = tapping_key.event.key, | 364 | .event.key = tapping_key.event.key, |
| 342 | .event.time = event.time, | 365 | .event.time = event.time, |
| 343 | .event.pressed = false, | 366 | .event.pressed = false, |
| 367 | .event.type = tapping_key.event.type, | ||
| 344 | # ifdef COMBO_ENABLE | 368 | # ifdef COMBO_ENABLE |
| 345 | .keycode = tapping_key.keycode, | 369 | .keycode = tapping_key.keycode, |
| 346 | # endif | 370 | # endif |
| @@ -353,16 +377,20 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 353 | debug_tapping_key(); | 377 | debug_tapping_key(); |
| 354 | return true; | 378 | return true; |
| 355 | } else { | 379 | } else { |
| 356 | if (IS_EVENT(event)) { | 380 | ac_dprintf("Tapping: key event while last timeout tap(>0).\n"); |
| 357 | ac_dprintf("Tapping: key event while last timeout tap(>0).\n"); | ||
| 358 | } | ||
| 359 | process_record(keyp); | 381 | process_record(keyp); |
| 360 | return true; | 382 | return true; |
| 361 | } | 383 | } |
| 362 | } | 384 | } |
| 363 | } | 385 | } |
| 364 | } else if (IS_TAPPING_RELEASED()) { | 386 | } |
| 387 | // process "released" tapping key state | ||
| 388 | else { | ||
| 365 | if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event)) { | 389 | if (WITHIN_TAPPING_TERM(event) || MAYBE_RETRO_SHIFTING(event)) { |
| 390 | if (IS_NOEVENT(event)) { | ||
| 391 | // early return for tick events | ||
| 392 | return true; | ||
| 393 | } | ||
| 366 | if (event.pressed) { | 394 | if (event.pressed) { |
| 367 | if (IS_TAPPING_RECORD(keyp)) { | 395 | if (IS_TAPPING_RECORD(keyp)) { |
| 368 | if (WITHIN_QUICK_TAP_TERM(event) && !tapping_key.tap.interrupted && tapping_key.tap.count > 0) { | 396 | if (WITHIN_QUICK_TAP_TERM(event) && !tapping_key.tap.interrupted && tapping_key.tap.count > 0) { |
| @@ -393,35 +421,20 @@ bool process_tapping(keyrecord_t *keyp) { | |||
| 393 | return true; | 421 | return true; |
| 394 | } | 422 | } |
| 395 | } else { | 423 | } else { |
| 396 | if (IS_EVENT(event)) ac_dprintf("Tapping: other key just after tap.\n"); | 424 | ac_dprintf("Tapping: other key just after tap.\n"); |
| 397 | process_record(keyp); | 425 | process_record(keyp); |
| 398 | return true; | 426 | return true; |
| 399 | } | 427 | } |
| 400 | } else { | 428 | } else { |
| 401 | // FIX: process_action here? | 429 | // Timeout - reset state machine. |
| 402 | // timeout. no sequential tap. | ||
| 403 | ac_dprintf("Tapping: End(Timeout after releasing last tap): "); | 430 | ac_dprintf("Tapping: End(Timeout after releasing last tap): "); |
| 404 | debug_event(event); | 431 | debug_event(event); |
| 405 | ac_dprintf("\n"); | 432 | ac_dprintf("\n"); |
| 406 | tapping_key = (keyrecord_t){}; | 433 | tapping_key = (keyrecord_t){0}; |
| 407 | debug_tapping_key(); | 434 | debug_tapping_key(); |
| 408 | return false; | 435 | return false; |
| 409 | } | 436 | } |
| 410 | } | 437 | } |
| 411 | // not tapping state | ||
| 412 | else { | ||
| 413 | if (event.pressed && is_tap_record(keyp)) { | ||
| 414 | ac_dprintf("Tapping: Start(Press tap key).\n"); | ||
| 415 | tapping_key = *keyp; | ||
| 416 | process_record_tap_hint(&tapping_key); | ||
| 417 | waiting_buffer_scan_tap(); | ||
| 418 | debug_tapping_key(); | ||
| 419 | return true; | ||
| 420 | } else { | ||
| 421 | process_record(keyp); | ||
| 422 | return true; | ||
| 423 | } | ||
| 424 | } | ||
| 425 | } | 438 | } |
| 426 | 439 | ||
| 427 | /** \brief Waiting buffer enq | 440 | /** \brief Waiting buffer enq |
| @@ -484,15 +497,18 @@ __attribute__((unused)) bool waiting_buffer_has_anykey_pressed(void) { | |||
| 484 | * FIXME: Needs docs | 497 | * FIXME: Needs docs |
| 485 | */ | 498 | */ |
| 486 | void waiting_buffer_scan_tap(void) { | 499 | void waiting_buffer_scan_tap(void) { |
| 487 | // tapping already is settled | 500 | // early return if: |
| 488 | if (tapping_key.tap.count > 0) return; | 501 | // - tapping already is settled |
| 489 | // invalid state: tapping_key released && tap.count == 0 | 502 | // - invalid state: tapping_key released && tap.count == 0 |
| 490 | if (!tapping_key.event.pressed) return; | 503 | if ((tapping_key.tap.count > 0) || !tapping_key.event.pressed) { |
| 504 | return; | ||
| 505 | } | ||
| 491 | 506 | ||
| 492 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { | 507 | for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) { |
| 493 | if (IS_TAPPING_KEY(waiting_buffer[i].event.key) && !waiting_buffer[i].event.pressed && WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { | 508 | keyrecord_t *candidate = &waiting_buffer[i]; |
| 494 | tapping_key.tap.count = 1; | 509 | if (IS_EVENT(candidate->event) && KEYEQ(candidate->event.key, tapping_key.event.key) && !candidate->event.pressed && WITHIN_TAPPING_TERM(candidate->event)) { |
| 495 | waiting_buffer[i].tap.count = 1; | 510 | tapping_key.tap.count = 1; |
| 511 | candidate->tap.count = 1; | ||
| 496 | process_record(&tapping_key); | 512 | process_record(&tapping_key); |
| 497 | 513 | ||
| 498 | ac_dprintf("waiting_buffer_scan_tap: found at [%u]\n", i); | 514 | ac_dprintf("waiting_buffer_scan_tap: found at [%u]\n", i); |
diff --git a/quantum/encoder.c b/quantum/encoder.c index 3aee340249..8053913e8d 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c | |||
| @@ -147,12 +147,12 @@ void encoder_init(void) { | |||
| 147 | #ifdef ENCODER_MAP_ENABLE | 147 | #ifdef ENCODER_MAP_ENABLE |
| 148 | static void encoder_exec_mapping(uint8_t index, bool clockwise) { | 148 | static void encoder_exec_mapping(uint8_t index, bool clockwise) { |
| 149 | // The delays below cater for Windows and its wonderful requirements. | 149 | // The delays below cater for Windows and its wonderful requirements. |
| 150 | action_exec(clockwise ? ENCODER_CW_EVENT(index, true) : ENCODER_CCW_EVENT(index, true)); | 150 | action_exec(clockwise ? MAKE_ENCODER_CW_EVENT(index, true) : MAKE_ENCODER_CCW_EVENT(index, true)); |
| 151 | # if ENCODER_MAP_KEY_DELAY > 0 | 151 | # if ENCODER_MAP_KEY_DELAY > 0 |
| 152 | wait_ms(ENCODER_MAP_KEY_DELAY); | 152 | wait_ms(ENCODER_MAP_KEY_DELAY); |
| 153 | # endif // ENCODER_MAP_KEY_DELAY > 0 | 153 | # endif // ENCODER_MAP_KEY_DELAY > 0 |
| 154 | 154 | ||
| 155 | action_exec(clockwise ? ENCODER_CW_EVENT(index, false) : ENCODER_CCW_EVENT(index, false)); | 155 | action_exec(clockwise ? MAKE_ENCODER_CW_EVENT(index, false) : MAKE_ENCODER_CCW_EVENT(index, false)); |
| 156 | # if ENCODER_MAP_KEY_DELAY > 0 | 156 | # if ENCODER_MAP_KEY_DELAY > 0 |
| 157 | wait_ms(ENCODER_MAP_KEY_DELAY); | 157 | wait_ms(ENCODER_MAP_KEY_DELAY); |
| 158 | # endif // ENCODER_MAP_KEY_DELAY > 0 | 158 | # endif // ENCODER_MAP_KEY_DELAY > 0 |
diff --git a/quantum/keyboard.c b/quantum/keyboard.c index 6f1ad33b61..90f6d6f8da 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c | |||
| @@ -462,7 +462,7 @@ static inline void generate_tick_event(void) { | |||
| 462 | static uint16_t last_tick = 0; | 462 | static uint16_t last_tick = 0; |
| 463 | const uint16_t now = timer_read(); | 463 | const uint16_t now = timer_read(); |
| 464 | if (TIMER_DIFF_16(now, last_tick) != 0) { | 464 | if (TIMER_DIFF_16(now, last_tick) != 0) { |
| 465 | action_exec(TICK_EVENT); | 465 | action_exec(MAKE_TICK_EVENT); |
| 466 | last_tick = now; | 466 | last_tick = now; |
| 467 | } | 467 | } |
| 468 | } | 468 | } |
diff --git a/quantum/keyboard.h b/quantum/keyboard.h index f82f2fa58a..bf1890d10b 100644 --- a/quantum/keyboard.h +++ b/quantum/keyboard.h | |||
| @@ -30,65 +30,64 @@ typedef struct { | |||
| 30 | uint8_t row; | 30 | uint8_t row; |
| 31 | } keypos_t; | 31 | } keypos_t; |
| 32 | 32 | ||
| 33 | typedef enum keyevent_type_t { TICK_EVENT = 0, KEY_EVENT = 1, ENCODER_CW_EVENT = 2, ENCODER_CCW_EVENT = 3, COMBO_EVENT = 4 } keyevent_type_t; | ||
| 34 | |||
| 33 | /* key event */ | 35 | /* key event */ |
| 34 | typedef struct { | 36 | typedef struct { |
| 35 | keypos_t key; | 37 | keypos_t key; |
| 36 | bool pressed; | 38 | uint16_t time; |
| 37 | uint16_t time; | 39 | keyevent_type_t type; |
| 40 | bool pressed; | ||
| 38 | } keyevent_t; | 41 | } keyevent_t; |
| 39 | 42 | ||
| 40 | /* equivalent test of keypos_t */ | 43 | /* equivalent test of keypos_t */ |
| 41 | #define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col) | 44 | #define KEYEQ(keya, keyb) ((keya).row == (keyb).row && (keya).col == (keyb).col) |
| 42 | 45 | ||
| 43 | /* special keypos_t entries */ | 46 | /* special keypos_t entries */ |
| 44 | #define KEYLOC_TICK 255 | ||
| 45 | #define KEYLOC_COMBO 254 | ||
| 46 | #define KEYLOC_ENCODER_CW 253 | 47 | #define KEYLOC_ENCODER_CW 253 |
| 47 | #define KEYLOC_ENCODER_CCW 252 | 48 | #define KEYLOC_ENCODER_CCW 252 |
| 48 | 49 | ||
| 49 | /* Rules for No Event: | 50 | static inline bool IS_NOEVENT(const keyevent_t event) { |
| 50 | * 1) (time == 0) to handle (keyevent_t){} as empty event | 51 | return event.type == TICK_EVENT; |
| 51 | * 2) Matrix(255, 255) to make TICK event available | ||
| 52 | */ | ||
| 53 | static inline bool IS_NOEVENT(keyevent_t event) { | ||
| 54 | return event.time == 0 || (event.key.row == KEYLOC_TICK && event.key.col == KEYLOC_TICK); | ||
| 55 | } | ||
| 56 | static inline bool IS_EVENT(keyevent_t event) { | ||
| 57 | return !IS_NOEVENT(event); | ||
| 58 | } | ||
| 59 | static inline bool IS_KEYEVENT(keyevent_t event) { | ||
| 60 | return event.key.row < MATRIX_ROWS && event.key.col < MATRIX_COLS; | ||
| 61 | } | 52 | } |
| 62 | static inline bool IS_COMBOEVENT(keyevent_t event) { | 53 | static inline bool IS_EVENT(const keyevent_t event) { |
| 63 | return event.key.row == KEYLOC_COMBO; | 54 | return event.type != TICK_EVENT; |
| 64 | } | 55 | } |
| 65 | static inline bool IS_ENCODEREVENT(keyevent_t event) { | 56 | static inline bool IS_KEYEVENT(const keyevent_t event) { |
| 66 | return event.key.row == KEYLOC_ENCODER_CW || event.key.row == KEYLOC_ENCODER_CCW; | 57 | return event.type == KEY_EVENT; |
| 67 | } | 58 | } |
| 68 | static inline bool IS_PRESSED(keyevent_t event) { | 59 | static inline bool IS_COMBOEVENT(const keyevent_t event) { |
| 69 | return IS_EVENT(event) && event.pressed; | 60 | return event.type == COMBO_EVENT; |
| 70 | } | 61 | } |
| 71 | static inline bool IS_RELEASED(keyevent_t event) { | 62 | static inline bool IS_ENCODEREVENT(const keyevent_t event) { |
| 72 | return IS_EVENT(event) && !event.pressed; | 63 | return event.type == ENCODER_CW_EVENT || event.type == ENCODER_CCW_EVENT; |
| 73 | } | 64 | } |
| 74 | 65 | ||
| 75 | /* Common keyevent object factory */ | 66 | /* Common keypos_t object factory */ |
| 76 | #define MAKE_KEYPOS(row_num, col_num) ((keypos_t){.row = (row_num), .col = (col_num)}) | 67 | #define MAKE_KEYPOS(row_num, col_num) ((keypos_t){.row = (row_num), .col = (col_num)}) |
| 77 | 68 | ||
| 69 | /* Common keyevent_t object factory */ | ||
| 70 | #define MAKE_EVENT(row_num, col_num, press, event_type) ((keyevent_t){.key = MAKE_KEYPOS((row_num), (col_num)), .pressed = (press), .time = timer_read(), .type = (event_type)}) | ||
| 71 | |||
| 78 | /** | 72 | /** |
| 79 | * @brief Constructs a key event for a pressed or released key. | 73 | * @brief Constructs a key event for a pressed or released key. |
| 80 | */ | 74 | */ |
| 81 | #define MAKE_KEYEVENT(row_num, col_num, press) ((keyevent_t){.key = MAKE_KEYPOS((row_num), (col_num)), .pressed = (press), .time = (timer_read() | 1)}) | 75 | #define MAKE_KEYEVENT(row_num, col_num, press) MAKE_EVENT((row_num), (col_num), (press), KEY_EVENT) |
| 76 | |||
| 77 | /** | ||
| 78 | * @brief Constructs a combo event. | ||
| 79 | */ | ||
| 80 | #define MAKE_COMBOEVENT(press) MAKE_EVENT(0, 0, (press), COMBO_EVENT) | ||
| 82 | 81 | ||
| 83 | /** | 82 | /** |
| 84 | * @brief Constructs a internal tick event that is used to drive the internal QMK state machine. | 83 | * @brief Constructs a internal tick event that is used to drive the internal QMK state machine. |
| 85 | */ | 84 | */ |
| 86 | #define TICK_EVENT MAKE_KEYEVENT(KEYLOC_TICK, KEYLOC_TICK, false) | 85 | #define MAKE_TICK_EVENT MAKE_EVENT(0, 0, false, TICK_EVENT) |
| 87 | 86 | ||
| 88 | #ifdef ENCODER_MAP_ENABLE | 87 | #ifdef ENCODER_MAP_ENABLE |
| 89 | /* Encoder events */ | 88 | /* Encoder events */ |
| 90 | # define ENCODER_CW_EVENT(enc_id, press) MAKE_KEYEVENT(KEYLOC_ENCODER_CW, (enc_id), (press)) | 89 | # define MAKE_ENCODER_CW_EVENT(enc_id, press) MAKE_EVENT(KEYLOC_ENCODER_CW, (enc_id), (press), ENCODER_CW_EVENT) |
| 91 | # define ENCODER_CCW_EVENT(enc_id, press) MAKE_KEYEVENT(KEYLOC_ENCODER_CCW, (enc_id), (press)) | 90 | # define MAKE_ENCODER_CCW_EVENT(enc_id, press) MAKE_EVENT(KEYLOC_ENCODER_CCW, (enc_id), (press), ENCODER_CCW_EVENT) |
| 92 | #endif // ENCODER_MAP_ENABLE | 91 | #endif // ENCODER_MAP_ENABLE |
| 93 | 92 | ||
| 94 | /* it runs once at early stage of startup before keyboard_init. */ | 93 | /* it runs once at early stage of startup before keyboard_init. */ |
diff --git a/quantum/process_keycode/process_combo.c b/quantum/process_keycode/process_combo.c index ce6725c402..b1b49d3019 100644 --- a/quantum/process_keycode/process_combo.c +++ b/quantum/process_keycode/process_combo.c | |||
| @@ -145,7 +145,7 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH]; | |||
| 145 | static inline void release_combo(uint16_t combo_index, combo_t *combo) { | 145 | static inline void release_combo(uint16_t combo_index, combo_t *combo) { |
| 146 | if (combo->keycode) { | 146 | if (combo->keycode) { |
| 147 | keyrecord_t record = { | 147 | keyrecord_t record = { |
| 148 | .event = MAKE_KEYEVENT(KEYLOC_COMBO, KEYLOC_COMBO, false), | 148 | .event = MAKE_COMBOEVENT(false), |
| 149 | .keycode = combo->keycode, | 149 | .keycode = combo->keycode, |
| 150 | }; | 150 | }; |
| 151 | #ifndef NO_ACTION_TAPPING | 151 | #ifndef NO_ACTION_TAPPING |
| @@ -233,7 +233,7 @@ static inline void dump_key_buffer(void) { | |||
| 233 | process_record(record); | 233 | process_record(record); |
| 234 | #endif | 234 | #endif |
| 235 | } | 235 | } |
| 236 | record->event.time = 0; | 236 | record->event.type = TICK_EVENT; |
| 237 | 237 | ||
| 238 | #if defined(CAPS_WORD_ENABLE) && defined(AUTO_SHIFT_ENABLE) | 238 | #if defined(CAPS_WORD_ENABLE) && defined(AUTO_SHIFT_ENABLE) |
| 239 | // Edge case: preserve the weak Left Shift mod if both Caps Word and | 239 | // Edge case: preserve the weak Left Shift mod if both Caps Word and |
| @@ -333,8 +333,8 @@ void apply_combo(uint16_t combo_index, combo_t *combo) { | |||
| 333 | KEY_STATE_DOWN(state, key_index); | 333 | KEY_STATE_DOWN(state, key_index); |
| 334 | if (ALL_COMBO_KEYS_ARE_DOWN(state, key_count)) { | 334 | if (ALL_COMBO_KEYS_ARE_DOWN(state, key_count)) { |
| 335 | // this in the end executes the combo when the key_buffer is dumped. | 335 | // this in the end executes the combo when the key_buffer is dumped. |
| 336 | record->keycode = combo->keycode; | 336 | record->keycode = combo->keycode; |
| 337 | record->event.key = MAKE_KEYPOS(KEYLOC_COMBO, KEYLOC_COMBO); | 337 | record->event.type = COMBO_EVENT; |
| 338 | 338 | ||
| 339 | qrecord->combo_index = combo_index; | 339 | qrecord->combo_index = combo_index; |
| 340 | ACTIVATE_COMBO(combo); | 340 | ACTIVATE_COMBO(combo); |
| @@ -343,7 +343,7 @@ void apply_combo(uint16_t combo_index, combo_t *combo) { | |||
| 343 | } else { | 343 | } else { |
| 344 | // key was part of the combo but not the last one, "disable" it | 344 | // key was part of the combo but not the last one, "disable" it |
| 345 | // by making it a TICK event. | 345 | // by making it a TICK event. |
| 346 | record->event.time = 0; | 346 | record->event.type = TICK_EVENT; |
| 347 | } | 347 | } |
| 348 | } | 348 | } |
| 349 | drop_combo_from_buffer(combo_index); | 349 | drop_combo_from_buffer(combo_index); |
diff --git a/quantum/process_keycode/process_steno.c b/quantum/process_keycode/process_steno.c index 8ba98bd4bb..d5ad61ba85 100644 --- a/quantum/process_keycode/process_steno.c +++ b/quantum/process_keycode/process_steno.c | |||
| @@ -173,13 +173,13 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) { | |||
| 173 | switch (keycode) { | 173 | switch (keycode) { |
| 174 | #ifdef STENO_ENABLE_ALL | 174 | #ifdef STENO_ENABLE_ALL |
| 175 | case QK_STENO_BOLT: | 175 | case QK_STENO_BOLT: |
| 176 | if (IS_PRESSED(record->event)) { | 176 | if (record->event.pressed) { |
| 177 | steno_set_mode(STENO_MODE_BOLT); | 177 | steno_set_mode(STENO_MODE_BOLT); |
| 178 | } | 178 | } |
| 179 | return false; | 179 | return false; |
| 180 | 180 | ||
| 181 | case QK_STENO_GEMINI: | 181 | case QK_STENO_GEMINI: |
| 182 | if (IS_PRESSED(record->event)) { | 182 | if (record->event.pressed) { |
| 183 | steno_set_mode(STENO_MODE_GEMINI); | 183 | steno_set_mode(STENO_MODE_GEMINI); |
| 184 | } | 184 | } |
| 185 | return false; | 185 | return false; |
| @@ -193,7 +193,7 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) { | |||
| 193 | } | 193 | } |
| 194 | #endif // STENO_COMBINEDMAP | 194 | #endif // STENO_COMBINEDMAP |
| 195 | case STN__MIN ... STN__MAX: | 195 | case STN__MIN ... STN__MAX: |
| 196 | if (IS_PRESSED(record->event)) { | 196 | if (record->event.pressed) { |
| 197 | n_pressed_keys++; | 197 | n_pressed_keys++; |
| 198 | switch (mode) { | 198 | switch (mode) { |
| 199 | #ifdef STENO_ENABLE_BOLT | 199 | #ifdef STENO_ENABLE_BOLT |
