diff options
| author | tmk <nobody@nowhere> | 2013-01-23 23:53:51 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-01-23 23:53:51 +0900 |
| commit | 28b5f69ce5c8b35d40725b490e7a2d4bfe922ad4 (patch) | |
| tree | 1a427f0e0d410fee5f57bfc170e31ef2d7050ac9 /common | |
| parent | 1fe820a8654b69576875a8173e22b47b365c2460 (diff) | |
| download | qmk_firmware-28b5f69ce5c8b35d40725b490e7a2d4bfe922ad4.tar.gz qmk_firmware-28b5f69ce5c8b35d40725b490e7a2d4bfe922ad4.zip | |
Add prototype of Action Function.
Diffstat (limited to 'common')
| -rw-r--r-- | common/action.c | 190 | ||||
| -rw-r--r-- | common/action.h | 38 | ||||
| -rw-r--r-- | common/keyboard.c | 3 | ||||
| -rw-r--r-- | common/keyboard.h | 4 |
4 files changed, 167 insertions, 68 deletions
diff --git a/common/action.c b/common/action.c index 3a504a45f..88f8186c3 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -11,47 +11,26 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | static void process(keyevent_t event); | 13 | static void process(keyevent_t event); |
| 14 | static void register_code(uint8_t code); | 14 | |
| 15 | static void unregister_code(uint8_t code); | 15 | void test_func(keyevent_t event, uint8_t opt) |
| 16 | static void add_mods(uint8_t mods); | ||
| 17 | static void del_mods(uint8_t mods); | ||
| 18 | static void set_mods(uint8_t mods); | ||
| 19 | static void clear_keyboard(void); | ||
| 20 | static void clear_keyboard_but_mods(void); | ||
| 21 | static bool sending_anykey(void); | ||
| 22 | static void layer_switch(uint8_t new_layer); | ||
| 23 | |||
| 24 | |||
| 25 | /* tap */ | ||
| 26 | #define TAP_TIME 300 | ||
| 27 | /* This counts up when tap occurs */ | ||
| 28 | static uint8_t tap_count = 0; | ||
| 29 | static bool is_tap_key(keyevent_t event) | ||
| 30 | { | 16 | { |
| 31 | action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col); | 17 | if (event.pressed) { |
| 32 | switch (action.kind.id) { | 18 | debug("test_func:pressed: "); debug_hex(opt); debug("\n"); |
| 33 | case ACT_LMODS_TAP: | 19 | } else { |
| 34 | case ACT_RMODS_TAP: | 20 | debug("test_func:released: "); debug_hex(opt); debug("\n"); |
| 35 | return true; | ||
| 36 | case ACT_LAYER_PRESSED: | ||
| 37 | case ACT_LAYER_BIT: | ||
| 38 | switch (action.layer.code) { | ||
| 39 | case 0x00: | ||
| 40 | case 0xF1 ... 0xFF: | ||
| 41 | return false; | ||
| 42 | case 0xF0: | ||
| 43 | default: | ||
| 44 | return true; | ||
| 45 | } | ||
| 46 | return false; | ||
| 47 | } | 21 | } |
| 48 | return false; | ||
| 49 | } | 22 | } |
| 50 | 23 | ||
| 51 | /* layer */ | 24 | /* layer */ |
| 52 | uint8_t default_layer = 0; | 25 | uint8_t default_layer = 0; |
| 53 | uint8_t current_layer = 0; | 26 | uint8_t current_layer = 0; |
| 54 | static keyevent_t tapping_event = {}; | 27 | |
| 28 | /* tap term(ms) */ | ||
| 29 | #define TAP_TIME 200 | ||
| 30 | |||
| 31 | /* This counts up when tap occurs */ | ||
| 32 | uint8_t tap_count = 0; | ||
| 33 | keyevent_t tapping_event = {}; | ||
| 55 | 34 | ||
| 56 | /* TAPPING: This indicates that whether tap or not is not decided yet. */ | 35 | /* TAPPING: This indicates that whether tap or not is not decided yet. */ |
| 57 | // NOTE: keyevent_t.time 0 means no event. | 36 | // NOTE: keyevent_t.time 0 means no event. |
| @@ -61,26 +40,41 @@ static keyevent_t tapping_event = {}; | |||
| 61 | #define WAITING_KEYS_BUFFER 8 | 40 | #define WAITING_KEYS_BUFFER 8 |
| 62 | static keyevent_t waiting_events[WAITING_KEYS_BUFFER] = {}; | 41 | static keyevent_t waiting_events[WAITING_KEYS_BUFFER] = {}; |
| 63 | static uint8_t waiting_events_head = 0; | 42 | static uint8_t waiting_events_head = 0; |
| 43 | static uint8_t waiting_events_tail = 0; | ||
| 44 | |||
| 64 | static bool waiting_events_enqueue(keyevent_t event) | 45 | static bool waiting_events_enqueue(keyevent_t event) |
| 65 | { | 46 | { |
| 66 | if (IS_NOEVENT(event)) { return true; } | 47 | if (IS_NOEVENT(event)) { return true; } |
| 67 | 48 | ||
| 68 | if (waiting_events_head < WAITING_KEYS_BUFFER) { | 49 | if ((waiting_events_head + 1) % WAITING_KEYS_BUFFER == waiting_events_tail) { |
| 69 | debug("waiting_events["); debug_dec(waiting_events_head); debug("] = "); | 50 | debug("waiting_events_enqueue: Over flow.\n"); |
| 70 | debug_hex16(event.key.raw); debug("\n"); | 51 | return false; |
| 71 | waiting_events[waiting_events_head++] = event; | ||
| 72 | return true; | ||
| 73 | } | 52 | } |
| 74 | debug("waiting_events_enqueue: Over flow.\n"); | 53 | |
| 75 | return false; | 54 | debug("waiting_events["); debug_dec(waiting_events_head); debug("] = "); |
| 55 | debug_hex16(event.key.raw); debug("\n"); | ||
| 56 | |||
| 57 | waiting_events[waiting_events_head] = event; | ||
| 58 | waiting_events_head = (waiting_events_head + 1)% WAITING_KEYS_BUFFER; | ||
| 59 | return true; | ||
| 60 | } | ||
| 61 | static keyevent_t waiting_events_dequeue(void) | ||
| 62 | { | ||
| 63 | if (waiting_events_head == waiting_events_tail) { | ||
| 64 | return (keyevent_t){}; | ||
| 65 | } | ||
| 66 | uint8_t tail = waiting_events_tail; | ||
| 67 | waiting_events_tail = waiting_events_tail + 1 % WAITING_KEYS_BUFFER; | ||
| 68 | return waiting_events[tail]; | ||
| 76 | } | 69 | } |
| 77 | static void waiting_events_clear(void) | 70 | static void waiting_events_clear(void) |
| 78 | { | 71 | { |
| 79 | waiting_events_head = 0; | 72 | waiting_events_head = 0; |
| 73 | waiting_events_tail = 0; | ||
| 80 | } | 74 | } |
| 81 | static bool waiting_events_has(key_t key) | 75 | static bool waiting_events_has(key_t key) |
| 82 | { | 76 | { |
| 83 | for (uint8_t i = 0; i < waiting_events_head; i++) { | 77 | for (uint8_t i = waiting_events_tail; i != waiting_events_head; i = (i + 1) % WAITING_KEYS_BUFFER) { |
| 84 | if KEYEQ(key, waiting_events[i].key) return true; | 78 | if KEYEQ(key, waiting_events[i].key) return true; |
| 85 | } | 79 | } |
| 86 | return false; | 80 | return false; |
| @@ -88,7 +82,7 @@ static bool waiting_events_has(key_t key) | |||
| 88 | static void waiting_events_process_in_current_layer(void) | 82 | static void waiting_events_process_in_current_layer(void) |
| 89 | { | 83 | { |
| 90 | // TODO: in case of including tap key in waiting keys | 84 | // TODO: in case of including tap key in waiting keys |
| 91 | for (uint8_t i = 0; i < waiting_events_head; i++) { | 85 | for (uint8_t i = waiting_events_tail; i != waiting_events_head; i = (i + 1) % WAITING_KEYS_BUFFER) { |
| 92 | debug("waiting_events_process_in_current_layer["); debug_dec(i); debug("]\n"); | 86 | debug("waiting_events_process_in_current_layer["); debug_dec(i); debug("]\n"); |
| 93 | process(waiting_events[i]); | 87 | process(waiting_events[i]); |
| 94 | } | 88 | } |
| @@ -96,7 +90,7 @@ static void waiting_events_process_in_current_layer(void) | |||
| 96 | } | 90 | } |
| 97 | static bool waiting_events_has_anykey_pressed(void) | 91 | static bool waiting_events_has_anykey_pressed(void) |
| 98 | { | 92 | { |
| 99 | for (uint8_t i = 0; i < waiting_events_head; i++) { | 93 | for (uint8_t i = waiting_events_tail; i != waiting_events_head; i = (i + 1) % WAITING_KEYS_BUFFER) { |
| 100 | if (waiting_events[i].pressed) return true; | 94 | if (waiting_events[i].pressed) return true; |
| 101 | } | 95 | } |
| 102 | return false; | 96 | return false; |
| @@ -137,7 +131,7 @@ void action_exec(keyevent_t event) | |||
| 137 | tap_count = 0; | 131 | tap_count = 0; |
| 138 | tapping_event = (keyevent_t){}; | 132 | tapping_event = (keyevent_t){}; |
| 139 | } else { | 133 | } else { |
| 140 | //debug("Tapping: pressing tap key.\n"); | 134 | if (!IS_NOEVENT(event)) debug("Tapping: other key while tapping.\n"); |
| 141 | if (tap_count == 0) { | 135 | if (tap_count == 0) { |
| 142 | // store event | 136 | // store event |
| 143 | waiting_events_enqueue(event); | 137 | waiting_events_enqueue(event); |
| @@ -146,14 +140,22 @@ void action_exec(keyevent_t event) | |||
| 146 | process(event); | 140 | process(event); |
| 147 | } | 141 | } |
| 148 | } else { | 142 | } else { |
| 149 | //debug("Tapping after releasing tap.\n"); | 143 | // Waiting for sequential tap |
| 150 | // Sequential tap | ||
| 151 | if (tap_count && event.pressed && KEYEQ(tapping_event.key, event.key)) { | 144 | if (tap_count && event.pressed && KEYEQ(tapping_event.key, event.key)) { |
| 152 | tap_count++; | 145 | tap_count++; |
| 153 | tapping_event = event; | 146 | tapping_event = event; |
| 154 | debug("Tapping: Sequential tap("); debug_hex(tap_count); debug(")\n"); | 147 | debug("Tapping: Sequential tap("); debug_hex(tap_count); debug(")\n"); |
| 148 | process(event); | ||
| 149 | } else if (event.pressed && is_tap_key(event)) { | ||
| 150 | // Sequential tap can be interfered with other tap key. | ||
| 151 | debug("Tapping: Start with interfering other tap.\n"); | ||
| 152 | tapping_event = event; | ||
| 153 | tap_count = 0; | ||
| 154 | waiting_events_clear(); | ||
| 155 | } else { | ||
| 156 | if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n"); | ||
| 157 | process(event); | ||
| 155 | } | 158 | } |
| 156 | process(event); | ||
| 157 | } | 159 | } |
| 158 | } | 160 | } |
| 159 | // Not in tapping term | 161 | // Not in tapping term |
| @@ -162,7 +164,7 @@ void action_exec(keyevent_t event) | |||
| 162 | if (tapping_event.pressed) { | 164 | if (tapping_event.pressed) { |
| 163 | if (tap_count == 0) { | 165 | if (tap_count == 0) { |
| 164 | // Not tap, holding down normal key. | 166 | // Not tap, holding down normal key. |
| 165 | debug("Not tap.\n"); | 167 | debug("Tapping: End. Not tap(time out).\n"); |
| 166 | process(tapping_event); | 168 | process(tapping_event); |
| 167 | waiting_events_process_in_current_layer(); | 169 | waiting_events_process_in_current_layer(); |
| 168 | 170 | ||
| @@ -170,15 +172,27 @@ void action_exec(keyevent_t event) | |||
| 170 | tapping_event = (keyevent_t){}; | 172 | tapping_event = (keyevent_t){}; |
| 171 | process(event); | 173 | process(event); |
| 172 | } else { | 174 | } else { |
| 173 | // Holding down last tap key. | 175 | // Holding down last tap key. waiting for releasing last tap key. |
| 174 | //debug("Time out with holding last tap.\n"); | ||
| 175 | process(event); | ||
| 176 | if (!event.pressed && KEYEQ(tapping_event.key, event.key)) { | 176 | if (!event.pressed && KEYEQ(tapping_event.key, event.key)) { |
| 177 | debug("Tapping: End(Release holding last tap).\n"); | 177 | debug("Tapping: End. Release holding last tap(time out).\n"); |
| 178 | process(event); | ||
| 178 | // clear after release last tap key | 179 | // clear after release last tap key |
| 179 | tap_count = 0; | 180 | tap_count = 0; |
| 180 | tapping_event = (keyevent_t){}; | 181 | tapping_event = (keyevent_t){}; |
| 181 | waiting_events_clear(); | 182 | waiting_events_clear(); |
| 183 | } else if (event.pressed && is_tap_key(event)) { | ||
| 184 | debug("Tapping: Start with forcing to release last tap(time out).\n"); | ||
| 185 | process((keyevent_t){ | ||
| 186 | .key = tapping_event.key, | ||
| 187 | .time = event.time, | ||
| 188 | .pressed = false }); | ||
| 189 | |||
| 190 | tap_count = 0; | ||
| 191 | tapping_event = event; | ||
| 192 | waiting_events_clear(); | ||
| 193 | } else { | ||
| 194 | if (!IS_NOEVENT(event)) debug("Tapping: other key while waiting for release of last tap(time out).\n"); | ||
| 195 | process(event); | ||
| 182 | } | 196 | } |
| 183 | } | 197 | } |
| 184 | } else { | 198 | } else { |
| @@ -206,7 +220,6 @@ void action_exec(keyevent_t event) | |||
| 206 | } | 220 | } |
| 207 | } | 221 | } |
| 208 | 222 | ||
| 209 | |||
| 210 | static void process(keyevent_t event) | 223 | static void process(keyevent_t event) |
| 211 | { | 224 | { |
| 212 | if (IS_NOEVENT(event)) { return; } | 225 | if (IS_NOEVENT(event)) { return; } |
| @@ -354,6 +367,20 @@ static void process(keyevent_t event) | |||
| 354 | default: | 367 | default: |
| 355 | // with tap key | 368 | // with tap key |
| 356 | if (event.pressed) { | 369 | if (event.pressed) { |
| 370 | if (IS_TAPPING(event.key)) { | ||
| 371 | if (tap_count > 0) { | ||
| 372 | debug("LAYER_PRESSED: Tap: register_code\n"); | ||
| 373 | register_code(action.layer.code); | ||
| 374 | } else { | ||
| 375 | debug("LAYER_PRESSED: No tap: layer_switch\n"); | ||
| 376 | layer_switch(action.layer.opt); | ||
| 377 | } | ||
| 378 | } else { | ||
| 379 | // TODO: while other key tapping | ||
| 380 | debug("LAYER_PRESSED: No tap: layer_switch\n"); | ||
| 381 | layer_switch(action.layer.opt); | ||
| 382 | } | ||
| 383 | /* | ||
| 357 | if (IS_TAPPING(event.key) && tap_count > 0) { | 384 | if (IS_TAPPING(event.key) && tap_count > 0) { |
| 358 | debug("LAYER_PRESSED: Tap: register_code\n"); | 385 | debug("LAYER_PRESSED: Tap: register_code\n"); |
| 359 | register_code(action.layer.code); | 386 | register_code(action.layer.code); |
| @@ -361,6 +388,7 @@ static void process(keyevent_t event) | |||
| 361 | debug("LAYER_PRESSED: No tap: layer_switch\n"); | 388 | debug("LAYER_PRESSED: No tap: layer_switch\n"); |
| 362 | layer_switch(action.layer.opt); | 389 | layer_switch(action.layer.opt); |
| 363 | } | 390 | } |
| 391 | */ | ||
| 364 | } else { | 392 | } else { |
| 365 | if (IS_TAPPING(event.key) && tap_count > 0) { | 393 | if (IS_TAPPING(event.key) && tap_count > 0) { |
| 366 | debug("LAYER_PRESSED: Tap: unregister_code\n"); | 394 | debug("LAYER_PRESSED: Tap: unregister_code\n"); |
| @@ -488,14 +516,23 @@ static void process(keyevent_t event) | |||
| 488 | 516 | ||
| 489 | /* Extentions */ | 517 | /* Extentions */ |
| 490 | case ACT_MACRO: | 518 | case ACT_MACRO: |
| 519 | break; | ||
| 491 | case ACT_COMMAND: | 520 | case ACT_COMMAND: |
| 521 | break; | ||
| 492 | case ACT_FUNCTION: | 522 | case ACT_FUNCTION: |
| 523 | action_call_function(event, action.func.id); | ||
| 524 | //test_func(event, action.func.opt); | ||
| 525 | break; | ||
| 493 | default: | 526 | default: |
| 494 | break; | 527 | break; |
| 495 | } | 528 | } |
| 496 | } | 529 | } |
| 497 | 530 | ||
| 498 | static void register_code(uint8_t code) | 531 | |
| 532 | /* | ||
| 533 | * Utilities for actions. | ||
| 534 | */ | ||
| 535 | void register_code(uint8_t code) | ||
| 499 | { | 536 | { |
| 500 | if (code == KC_NO) { | 537 | if (code == KC_NO) { |
| 501 | return; | 538 | return; |
| @@ -513,7 +550,7 @@ static void register_code(uint8_t code) | |||
| 513 | } | 550 | } |
| 514 | } | 551 | } |
| 515 | 552 | ||
| 516 | static void unregister_code(uint8_t code) | 553 | void unregister_code(uint8_t code) |
| 517 | { | 554 | { |
| 518 | if IS_KEY(code) { | 555 | if IS_KEY(code) { |
| 519 | host_del_key(code); | 556 | host_del_key(code); |
| @@ -525,7 +562,7 @@ static void unregister_code(uint8_t code) | |||
| 525 | } | 562 | } |
| 526 | } | 563 | } |
| 527 | 564 | ||
| 528 | static void add_mods(uint8_t mods) | 565 | void add_mods(uint8_t mods) |
| 529 | { | 566 | { |
| 530 | if (mods) { | 567 | if (mods) { |
| 531 | host_add_mods(mods); | 568 | host_add_mods(mods); |
| @@ -533,7 +570,7 @@ static void add_mods(uint8_t mods) | |||
| 533 | } | 570 | } |
| 534 | } | 571 | } |
| 535 | 572 | ||
| 536 | static void del_mods(uint8_t mods) | 573 | void del_mods(uint8_t mods) |
| 537 | { | 574 | { |
| 538 | if (mods) { | 575 | if (mods) { |
| 539 | host_del_mods(mods); | 576 | host_del_mods(mods); |
| @@ -541,19 +578,19 @@ static void del_mods(uint8_t mods) | |||
| 541 | } | 578 | } |
| 542 | } | 579 | } |
| 543 | 580 | ||
| 544 | static void set_mods(uint8_t mods) | 581 | void set_mods(uint8_t mods) |
| 545 | { | 582 | { |
| 546 | host_set_mods(mods); | 583 | host_set_mods(mods); |
| 547 | host_send_keyboard_report(); | 584 | host_send_keyboard_report(); |
| 548 | } | 585 | } |
| 549 | 586 | ||
| 550 | static void clear_keyboard(void) | 587 | void clear_keyboard(void) |
| 551 | { | 588 | { |
| 552 | host_clear_mods(); | 589 | host_clear_mods(); |
| 553 | clear_keyboard_but_mods(); | 590 | clear_keyboard_but_mods(); |
| 554 | } | 591 | } |
| 555 | 592 | ||
| 556 | static void clear_keyboard_but_mods(void) | 593 | void clear_keyboard_but_mods(void) |
| 557 | { | 594 | { |
| 558 | host_clear_keys(); | 595 | host_clear_keys(); |
| 559 | host_send_keyboard_report(); | 596 | host_send_keyboard_report(); |
| @@ -567,13 +604,13 @@ static void clear_keyboard_but_mods(void) | |||
| 567 | #endif | 604 | #endif |
| 568 | } | 605 | } |
| 569 | 606 | ||
| 570 | static bool sending_anykey(void) | 607 | bool sending_anykey(void) |
| 571 | { | 608 | { |
| 572 | return (host_has_anykey() || host_mouse_in_use() || | 609 | return (host_has_anykey() || host_mouse_in_use() || |
| 573 | host_last_sysytem_report() || host_last_consumer_report()); | 610 | host_last_sysytem_report() || host_last_consumer_report()); |
| 574 | } | 611 | } |
| 575 | 612 | ||
| 576 | static void layer_switch(uint8_t new_layer) | 613 | void layer_switch(uint8_t new_layer) |
| 577 | { | 614 | { |
| 578 | if (current_layer != new_layer) { | 615 | if (current_layer != new_layer) { |
| 579 | debug("Layer Switch: "); debug_hex(current_layer); | 616 | debug("Layer Switch: "); debug_hex(current_layer); |
| @@ -584,3 +621,30 @@ static void layer_switch(uint8_t new_layer) | |||
| 584 | // TODO: update mods with full scan of matrix? if modifier changes between layers | 621 | // TODO: update mods with full scan of matrix? if modifier changes between layers |
| 585 | } | 622 | } |
| 586 | } | 623 | } |
| 624 | |||
| 625 | bool is_tap_key(keyevent_t event) | ||
| 626 | { | ||
| 627 | action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col); | ||
| 628 | switch (action.kind.id) { | ||
| 629 | case ACT_LMODS_TAP: | ||
| 630 | case ACT_RMODS_TAP: | ||
| 631 | return true; | ||
| 632 | case ACT_LAYER_PRESSED: | ||
| 633 | case ACT_LAYER_BIT: | ||
| 634 | switch (action.layer.code) { | ||
| 635 | case 0x00: | ||
| 636 | case 0xF1 ... 0xFF: | ||
| 637 | return false; | ||
| 638 | case 0xF0: | ||
| 639 | default: | ||
| 640 | return true; | ||
| 641 | } | ||
| 642 | return false; | ||
| 643 | case ACT_FUNCTION: | ||
| 644 | if (action.func.opt & 0x1) { | ||
| 645 | return true; | ||
| 646 | } | ||
| 647 | return false; | ||
| 648 | } | ||
| 649 | return false; | ||
| 650 | } | ||
diff --git a/common/action.h b/common/action.h index 3115c67f4..9aa1d78e9 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -3,8 +3,30 @@ | |||
| 3 | 3 | ||
| 4 | #include "keyboard.h" | 4 | #include "keyboard.h" |
| 5 | 5 | ||
| 6 | extern uint8_t tap_count; | ||
| 7 | extern keyevent_t tapping_event; | ||
| 6 | 8 | ||
| 7 | /* Key Action(16bit code) | 9 | |
| 10 | /* | ||
| 11 | * Utilities for actions. | ||
| 12 | */ | ||
| 13 | void register_code(uint8_t code); | ||
| 14 | void unregister_code(uint8_t code); | ||
| 15 | void add_mods(uint8_t mods); | ||
| 16 | void del_mods(uint8_t mods); | ||
| 17 | void set_mods(uint8_t mods); | ||
| 18 | void clear_keyboard(void); | ||
| 19 | void clear_keyboard_but_mods(void); | ||
| 20 | bool sending_anykey(void); | ||
| 21 | void layer_switch(uint8_t new_layer); | ||
| 22 | bool is_tap_key(keyevent_t event); | ||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | |||
| 27 | /* | ||
| 28 | Action codes | ||
| 29 | 16bit code: action_kind(4bit) + action_parameter(12bit) | ||
| 8 | 30 | ||
| 9 | Keyboard Keys | 31 | Keyboard Keys |
| 10 | ------------- | 32 | ------------- |
| @@ -94,6 +116,7 @@ ACT_COMMAND(1110): | |||
| 94 | 116 | ||
| 95 | ACT_FUNCTION(1111): | 117 | ACT_FUNCTION(1111): |
| 96 | 1111| address(12) Function | 118 | 1111| address(12) Function |
| 119 | 1111|opt | id(8) Function | ||
| 97 | Macro record(dynamicly) | 120 | Macro record(dynamicly) |
| 98 | Macro play(dynamicly) | 121 | Macro play(dynamicly) |
| 99 | TODO: modifier + [tap key /w mod] | 122 | TODO: modifier + [tap key /w mod] |
| @@ -160,6 +183,11 @@ typedef union { | |||
| 160 | uint16_t option :4; | 183 | uint16_t option :4; |
| 161 | uint16_t kind :4; | 184 | uint16_t kind :4; |
| 162 | } command; | 185 | } command; |
| 186 | struct action_function { | ||
| 187 | uint8_t id :8; | ||
| 188 | uint8_t opt :4; | ||
| 189 | uint8_t kind :4; | ||
| 190 | } func; | ||
| 163 | } action_t; | 191 | } action_t; |
| 164 | 192 | ||
| 165 | 193 | ||
| @@ -169,14 +197,20 @@ enum stroke_cmd { | |||
| 169 | STROKE_ALLUP, /* release all keys in reverse order */ | 197 | STROKE_ALLUP, /* release all keys in reverse order */ |
| 170 | }; | 198 | }; |
| 171 | 199 | ||
| 200 | // TODO: not needed? | ||
| 172 | typedef struct { | 201 | typedef struct { |
| 173 | keyevent_t event; | 202 | keyevent_t event; |
| 174 | action_t action; | 203 | action_t action; |
| 175 | uint8_t mods; | 204 | uint8_t mods; |
| 176 | } keyrecord_t; | 205 | } keyrecord_t; |
| 177 | 206 | ||
| 207 | /* action function */ | ||
| 208 | typedef void (*action_func_t)(keyevent_t event, uint8_t opt); | ||
| 209 | |||
| 178 | 210 | ||
| 211 | // TODO: legacy keymap support | ||
| 179 | void action_exec(keyevent_t event); | 212 | void action_exec(keyevent_t event); |
| 213 | void action_call_function(keyevent_t event, uint8_t id); | ||
| 180 | 214 | ||
| 181 | 215 | ||
| 182 | // TODO: proper names | 216 | // TODO: proper names |
| @@ -234,7 +268,7 @@ void action_exec(keyevent_t event); | |||
| 234 | /* Command */ | 268 | /* Command */ |
| 235 | #define ACTION_COMMAND(opt, id) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) | 269 | #define ACTION_COMMAND(opt, id) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) |
| 236 | /* Function */ | 270 | /* Function */ |
| 237 | #define ACTION_FUNCTION(addr) ACTION(ACT_FUNCTION, addr) | 271 | #define ACTION_FUNCTION(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | id) |
| 238 | 272 | ||
| 239 | 273 | ||
| 240 | /* helpers for readability */ | 274 | /* helpers for readability */ |
diff --git a/common/keyboard.c b/common/keyboard.c index 9f0ca7676..6677e8011 100644 --- a/common/keyboard.c +++ b/common/keyboard.c | |||
| @@ -89,7 +89,8 @@ void keyboard_task(void) | |||
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | } | 91 | } |
| 92 | // call to update delaying layer when no real event | 92 | // call with not real event to update state of aciton |
| 93 | // TODO: use NOEVENT macro | ||
| 93 | action_exec((keyevent_t) { | 94 | action_exec((keyevent_t) { |
| 94 | .key.pos = (keypos_t){ .row = 255, .col = 255 }, // assume this key doesn't exist | 95 | .key.pos = (keypos_t){ .row = 255, .col = 255 }, // assume this key doesn't exist |
| 95 | .pressed = false, | 96 | .pressed = false, |
diff --git a/common/keyboard.h b/common/keyboard.h index 4a3ee85a8..6d06c95bb 100644 --- a/common/keyboard.h +++ b/common/keyboard.h | |||
| @@ -44,10 +44,10 @@ typedef struct { | |||
| 44 | 44 | ||
| 45 | #define KEYEQ(keya, keyb) (keya.raw == keyb.raw) | 45 | #define KEYEQ(keya, keyb) (keya.raw == keyb.raw) |
| 46 | #define IS_NOEVENT(event) (event.time == 0) | 46 | #define IS_NOEVENT(event) (event.time == 0) |
| 47 | #define NOEVENT (keyevent_t) { \ | 47 | #define NOEVENT (keyevent_t){ \ |
| 48 | .key = (keypos_t){ .row = 255, .col = 255 }, \ | 48 | .key = (keypos_t){ .row = 255, .col = 255 }, \ |
| 49 | .pressed = false, \ | 49 | .pressed = false, \ |
| 50 | .time = 0, \ | 50 | .time = 0 \ |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | 53 | ||
