aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/action.c95
-rw-r--r--common/debug.h1
-rw-r--r--common/print.c9
-rw-r--r--common/print.h2
4 files changed, 84 insertions, 23 deletions
diff --git a/common/action.c b/common/action.c
index fb06e463c..e93a9afe3 100644
--- a/common/action.c
+++ b/common/action.c
@@ -29,6 +29,41 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
29static bool process_tapping(keyrecord_t *record); 29static bool process_tapping(keyrecord_t *record);
30static void process_action(keyrecord_t *record); 30static void process_action(keyrecord_t *record);
31 31
32static void debug_event(keyevent_t event)
33{
34 debug_hex16(event.key.raw);
35 if (event.pressed) debug("d("); else debug("u(");
36 debug_dec(event.time); debug(")");
37}
38static void debug_record(keyrecord_t record)
39{
40 debug_event(record.event); debug(":"); debug_dec(record.tap_count);
41}
42static void debug_action(action_t action)
43{
44 switch (action.kind.id) {
45 case ACT_LMODS: debug("ACT_LMODS"); break;
46 case ACT_RMODS: debug("ACT_RMODS"); break;
47 case ACT_LMODS_TAP: debug("ACT_LMODS_TAP"); break;
48 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break;
49 case ACT_USAGE: debug("ACT_USAGE"); break;
50 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
51 case ACT_LAYER_PRESSED: debug("ACT_LAYER_PRESSED"); break;
52 case ACT_LAYER_RELEASED: debug("ACT_LAYER_RELEASED"); break;
53 case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break;
54 case ACT_LAYER_EXT: debug("ACT_LAYER_EXT"); break;
55 case ACT_MACRO: debug("ACT_MACRO"); break;
56 case ACT_COMMAND: debug("ACT_COMMAND"); break;
57 case ACT_FUNCTION: debug("ACT_FUNCTION"); break;
58 default: debug("UNKNOWN"); break;
59 }
60 debug("[");
61 debug_hex4(action.kind.param>>8);
62 debug(":");
63 debug_hex8(action.kind.param & 0xff);
64 debug("]");
65}
66
32 67
33/* 68/*
34 * Tapping 69 * Tapping
@@ -67,6 +102,14 @@ static uint8_t waiting_buffer_head = 0;
67/* point to the oldest data cell to deq */ 102/* point to the oldest data cell to deq */
68static uint8_t waiting_buffer_tail = 0; 103static uint8_t waiting_buffer_tail = 0;
69 104
105static void debug_waiting_buffer(void)
106{
107 debug("{ ");
108 for (uint8_t i = waiting_buffer_tail; i != waiting_buffer_head; i = (i + 1) % WAITING_BUFFER_SIZE) {
109 debug("["); debug_dec(i); debug("]="); debug_record(waiting_buffer[i]); debug(" ");
110 }
111 debug("}\n");
112}
70static bool waiting_buffer_enq(keyrecord_t record) 113static bool waiting_buffer_enq(keyrecord_t record)
71{ 114{
72 if (IS_NOEVENT(record.event)) { 115 if (IS_NOEVENT(record.event)) {
@@ -78,11 +121,10 @@ static bool waiting_buffer_enq(keyrecord_t record)
78 return false; 121 return false;
79 } 122 }
80 123
81 debug("waiting_buffer_enq["); debug_dec(waiting_buffer_head); debug("] = ");
82 debug_hex16(record.event.key.raw); debug("\n");
83
84 waiting_buffer[waiting_buffer_head] = record; 124 waiting_buffer[waiting_buffer_head] = record;
85 waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE; 125 waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE;
126
127 debug("waiting_buffer_enq: "); debug_waiting_buffer();
86 return true; 128 return true;
87} 129}
88/* 130/*
@@ -162,21 +204,18 @@ static void oneshot_toggle(void)
162void action_exec(keyevent_t event) 204void action_exec(keyevent_t event)
163{ 205{
164 if (!IS_NOEVENT(event)) { 206 if (!IS_NOEVENT(event)) {
165 debug("event: "); 207 debug("\n---- action_exec: start -----\n");
166 debug_hex16(event.time); debug(": "); 208 debug("EVENT: "); debug_event(event); debug("\n");
167 debug_hex16(event.key.raw);
168 debug("[");
169 if (event.pressed) debug("down"); else debug("up");
170 debug("]\n");
171 } 209 }
172 210
173 keyrecord_t record = { .event = event }; 211 keyrecord_t record = { .event = event };
174 212
175 // pre-process on tapping 213 // pre-process on tapping
176 if (process_tapping(&record)) { 214 if (process_tapping(&record)) {
177 if (!IS_NOEVENT(record.event)) debug("processed.\n"); 215 if (!IS_NOEVENT(record.event)) {
216 debug("processed: "); debug_record(record); debug("\n");
217 }
178 } else { 218 } else {
179 if (!IS_NOEVENT(record.event)) debug("enqueued.\n");
180 // enqueue 219 // enqueue
181 if (!waiting_buffer_enq(record)) { 220 if (!waiting_buffer_enq(record)) {
182 // clear all in case of overflow. 221 // clear all in case of overflow.
@@ -187,14 +226,20 @@ void action_exec(keyevent_t event)
187 } 226 }
188 227
189 // process waiting_buffer 228 // process waiting_buffer
229 if (!IS_NOEVENT(event) && waiting_buffer_head != waiting_buffer_tail) {
230 debug("---- action_exec: process waiting_buffer -----\n");
231 }
190 for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) { 232 for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) {
191 if (process_tapping(&waiting_buffer[waiting_buffer_tail])) { 233 if (process_tapping(&waiting_buffer[waiting_buffer_tail])) {
192 debug("processed: waiting_buffer["); debug_dec(waiting_buffer_tail); debug("] = "); 234 debug("processed: waiting_buffer["); debug_dec(waiting_buffer_tail); debug("] = ");
193 debug_hex16(waiting_buffer[waiting_buffer_tail].event.key.raw); debug("\n"); 235 debug_record(waiting_buffer[waiting_buffer_tail]); debug("\n\n");
194 } else { 236 } else {
195 break; 237 break;
196 } 238 }
197 } 239 }
240 if (!IS_NOEVENT(event)) {
241 debug("\n");
242 }
198} 243}
199 244
200static void process_action(keyrecord_t *record) 245static void process_action(keyrecord_t *record)
@@ -205,8 +250,8 @@ static void process_action(keyrecord_t *record)
205 if (IS_NOEVENT(event)) { return; } 250 if (IS_NOEVENT(event)) { return; }
206 251
207 action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col); 252 action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col);
208 debug("action: "); debug_hex16(action.code); 253 //debug("action: "); debug_hex16(action.code); if (event.pressed) debug("d\n"); else debug("u\n");
209 if (event.pressed) debug("[down]\n"); else debug("[up]\n"); 254 debug("ACTION: "); debug_action(action); debug("\n");
210 255
211 switch (action.kind.id) { 256 switch (action.kind.id) {
212 /* Key and Mods */ 257 /* Key and Mods */
@@ -635,8 +680,8 @@ static bool process_tapping(keyrecord_t *keyp)
635 if (tapping_key.tap_count == 0) { 680 if (tapping_key.tap_count == 0) {
636 if (IS_TAPPING_KEY(event.key) && !event.pressed) { 681 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
637 // first tap! 682 // first tap!
638 debug("Tapping: First tap.\n");
639 tapping_key.tap_count = 1; 683 tapping_key.tap_count = 1;
684 debug("Tapping: First tap: tapping_key="); debug_record(tapping_key); debug("\n");
640 process_action(&tapping_key); 685 process_action(&tapping_key);
641 686
642 // enqueue 687 // enqueue
@@ -644,7 +689,7 @@ static bool process_tapping(keyrecord_t *keyp)
644 return false; 689 return false;
645 } else if (!event.pressed && waiting_buffer_typed(event)) { 690 } else if (!event.pressed && waiting_buffer_typed(event)) {
646 // other key typed. not tap. 691 // other key typed. not tap.
647 debug("Tapping: End(No tap. Interfered by typing key).\n"); 692 debug("Tapping: End. No tap. Interfered by typing key: tapping_key={}\n");
648 process_action(&tapping_key); 693 process_action(&tapping_key);
649 tapping_key = (keyrecord_t){}; 694 tapping_key = (keyrecord_t){};
650 695
@@ -654,15 +699,19 @@ static bool process_tapping(keyrecord_t *keyp)
654 // other key events shall be stored till tapping state settles. 699 // other key events shall be stored till tapping state settles.
655 return false; 700 return false;
656 } 701 }
657 } else { 702 }
703 // tap_count > 0
704 else {
658 if (IS_TAPPING_KEY(event.key) && !event.pressed) { 705 if (IS_TAPPING_KEY(event.key) && !event.pressed) {
659 keyp->tap_count = tapping_key.tap_count; 706 keyp->tap_count = tapping_key.tap_count;
660 debug("Tapping: tap release("); debug_dec(keyp->tap_count); debug(")\n"); 707 debug("Tapping: Tap release: tapping_key="); debug_record(*keyp); debug("\n");
661 tapping_key = *keyp; 708 tapping_key = *keyp;
662 return false; 709 return false;
663 } 710 }
664 else if (is_tap_key(keyp->event.key) && event.pressed) { 711 else if (is_tap_key(keyp->event.key) && event.pressed) {
665 debug("Tapping: Start with forcing to release last tap.\n"); 712 debug("Tapping: Start with forcing to release last tap: tapping_key=");
713 debug_record(*keyp); debug("\n");
714// TODO: need only when tap > 1?
666 process_action(&(keyrecord_t){ 715 process_action(&(keyrecord_t){
667 .tap_count = tapping_key.tap_count, 716 .tap_count = tapping_key.tap_count,
668 .event.key = tapping_key.event.key, 717 .event.key = tapping_key.event.key,
@@ -673,7 +722,10 @@ static bool process_tapping(keyrecord_t *keyp)
673 return false; 722 return false;
674 } 723 }
675 else { 724 else {
676 if (!IS_NOEVENT(keyp->event)) debug("Tapping: key event while tap.\n"); 725 if (!IS_NOEVENT(keyp->event)) {
726 debug("Tapping: key event while tap: tapping_key=");
727 debug_record(tapping_key); debug("\n");
728 }
677 process_action(keyp); 729 process_action(keyp);
678 return true; 730 return true;
679 } 731 }
@@ -683,7 +735,7 @@ static bool process_tapping(keyrecord_t *keyp)
683 else { 735 else {
684 if (tapping_key.tap_count == 0) { 736 if (tapping_key.tap_count == 0) {
685 // timeout. not tap. 737 // timeout. not tap.
686 debug("Tapping: End. Not tap(time out).\n"); 738 debug("Tapping: End. Not tap(time out): tapping_key={}: "); debug_record(*keyp); debug("\n");
687 process_action(&tapping_key); 739 process_action(&tapping_key);
688 tapping_key = (keyrecord_t){}; 740 tapping_key = (keyrecord_t){};
689 return false; 741 return false;
@@ -731,6 +783,7 @@ static bool process_tapping(keyrecord_t *keyp)
731 if (event.pressed && is_tap_key(event.key)) { 783 if (event.pressed && is_tap_key(event.key)) {
732 debug("Tapping: Start(Press tap key).\n"); 784 debug("Tapping: Start(Press tap key).\n");
733 tapping_key = *keyp; 785 tapping_key = *keyp;
786 debug("tapping_key="); debug_record(*keyp); debug("\n");
734 return true; 787 return true;
735 } else { 788 } else {
736 process_action(keyp); 789 process_action(keyp);
diff --git a/common/debug.h b/common/debug.h
index 648f0e096..e63d46f0e 100644
--- a/common/debug.h
+++ b/common/debug.h
@@ -36,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
36 36
37#define debug_dec(data) do { if (debug_enable) print_dec(data); } while (0) 37#define debug_dec(data) do { if (debug_enable) print_dec(data); } while (0)
38#define debug_decs(data) do { if (debug_enable) print_decs(data); } while (0) 38#define debug_decs(data) do { if (debug_enable) print_decs(data); } while (0)
39#define debug_hex4(data) do { if (debug_enable) print_hex4(data); } while (0)
39#define debug_hex8(data) do { if (debug_enable) print_hex8(data); } while (0) 40#define debug_hex8(data) do { if (debug_enable) print_hex8(data); } while (0)
40#define debug_hex16(data) do { if (debug_enable) print_hex16(data); } while (0) 41#define debug_hex16(data) do { if (debug_enable) print_hex16(data); } while (0)
41#define debug_hex32(data) do { if (debug_enable) print_hex32(data); } while (0) 42#define debug_hex32(data) do { if (debug_enable) print_hex32(data); } while (0)
diff --git a/common/print.c b/common/print.c
index d8a899b40..08d211f20 100644
--- a/common/print.c
+++ b/common/print.c
@@ -113,7 +113,6 @@ void print_decs(int16_t data)
113} 113}
114 114
115 115
116static inline
117void print_hex4(uint8_t data) 116void print_hex4(uint8_t data)
118{ 117{
119 sendchar(data + ((data < 10) ? '0' : 'A' - 10)); 118 sendchar(data + ((data < 10) ? '0' : 'A' - 10));
@@ -137,8 +136,14 @@ void print_hex32(uint32_t data)
137 print_hex16(data); 136 print_hex16(data);
138} 137}
139 138
139void print_bin4(uint8_t data)
140{
141 for (int i = 4; i >= 0; i--) {
142 sendchar((data & (1<<i)) ? '1' : '0');
143 }
144}
140 145
141void print_bin(uint8_t data) 146void print_bin8(uint8_t data)
142{ 147{
143 for (int i = 7; i >= 0; i--) { 148 for (int i = 7; i >= 0; i--) {
144 sendchar((data & (1<<i)) ? '1' : '0'); 149 sendchar((data & (1<<i)) ? '1' : '0');
diff --git a/common/print.h b/common/print.h
index 9c31b24a2..b22509477 100644
--- a/common/print.h
+++ b/common/print.h
@@ -87,11 +87,13 @@ void print_dec(uint16_t data);
87void print_decs(int16_t data); 87void print_decs(int16_t data);
88 88
89/* hex */ 89/* hex */
90void print_hex4(uint8_t data);
90void print_hex8(uint8_t data); 91void print_hex8(uint8_t data);
91void print_hex16(uint16_t data); 92void print_hex16(uint16_t data);
92void print_hex32(uint32_t data); 93void print_hex32(uint32_t data);
93 94
94/* binary */ 95/* binary */
96void print_bin4(uint8_t data);
95void print_bin8(uint8_t data); 97void print_bin8(uint8_t data);
96void print_bin16(uint16_t data); 98void print_bin16(uint16_t data);
97void print_bin32(uint32_t data); 99void print_bin32(uint32_t data);