aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.mk2
-rw-r--r--common/action.c378
-rw-r--r--common/action.h319
-rw-r--r--common/action_code.h289
-rw-r--r--common/action_layer.c135
-rw-r--r--common/action_layer.h77
-rw-r--r--common/action_tapping.h3
-rw-r--r--common/command.c6
-rw-r--r--common/keymap.c2
-rw-r--r--common/layer_switch.c209
-rw-r--r--common/layer_switch.h110
-rw-r--r--common/util.c19
-rw-r--r--common/util.h3
-rw-r--r--converter/pc98_usb/keymap.c32
-rw-r--r--converter/pc98_usb/matrix.c4
-rw-r--r--doc/keymap.md340
-rw-r--r--keyboard/gh60/config.h3
-rw-r--r--keyboard/gh60/keymap.c45
-rw-r--r--keyboard/gh60/keymap_plain.h3
-rw-r--r--keyboard/gh60/keymap_poker.h28
-rw-r--r--keyboard/gh60/keymap_poker_bit.h24
-rw-r--r--keyboard/gh60/keymap_poker_set.h37
-rw-r--r--keyboard/hhkb/config.h3
-rw-r--r--keyboard/hhkb/keymap.c19
-rw-r--r--keyboard/hid_liber/keymap.c29
25 files changed, 880 insertions, 1239 deletions
diff --git a/common.mk b/common.mk
index be9f289c9..6759e6ef9 100644
--- a/common.mk
+++ b/common.mk
@@ -5,7 +5,7 @@ SRC += $(COMMON_DIR)/host.c \
5 $(COMMON_DIR)/action_tapping.c \ 5 $(COMMON_DIR)/action_tapping.c \
6 $(COMMON_DIR)/action_oneshot.c \ 6 $(COMMON_DIR)/action_oneshot.c \
7 $(COMMON_DIR)/action_macro.c \ 7 $(COMMON_DIR)/action_macro.c \
8 $(COMMON_DIR)/layer_switch.c \ 8 $(COMMON_DIR)/action_layer.c \
9 $(COMMON_DIR)/keymap.c \ 9 $(COMMON_DIR)/keymap.c \
10 $(COMMON_DIR)/timer.c \ 10 $(COMMON_DIR)/timer.c \
11 $(COMMON_DIR)/print.c \ 11 $(COMMON_DIR)/print.c \
diff --git a/common/action.c b/common/action.c
index 07a3a64d6..065188744 100644
--- a/common/action.c
+++ b/common/action.c
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include "command.h" 21#include "command.h"
22#include "debug.h" 22#include "debug.h"
23#include "led.h" 23#include "led.h"
24#include "layer_switch.h" 24#include "action_layer.h"
25#include "action_tapping.h" 25#include "action_tapping.h"
26#include "action_oneshot.h" 26#include "action_oneshot.h"
27#include "action_macro.h" 27#include "action_macro.h"
@@ -50,15 +50,19 @@ void action_exec(keyevent_t event)
50void process_action(keyrecord_t *record) 50void process_action(keyrecord_t *record)
51{ 51{
52 keyevent_t event = record->event; 52 keyevent_t event = record->event;
53#ifndef NO_ACTION_TAPPING
53 uint8_t tap_count = record->tap.count; 54 uint8_t tap_count = record->tap.count;
55#endif
54 56
55 if (IS_NOEVENT(event)) { return; } 57 if (IS_NOEVENT(event)) { return; }
56 58
57 action_t action = layer_switch_get_action(event.key); 59 action_t action = layer_switch_get_action(event.key);
58 debug("ACTION: "); debug_action(action); 60 debug("ACTION: "); debug_action(action);
59 debug(" overlays: "); overlay_debug(); 61#ifndef NO_ACTION_LAYER
60 debug(" keymaps: "); keymap_debug(); 62 debug(" layer_state: "); layer_debug();
61 debug(" default_layer: "); debug_dec(default_layer); debug("\n"); 63 debug(" default_layer_state: "); default_layer_debug();
64#endif
65 debug("\n");
62 66
63 switch (action.kind.id) { 67 switch (action.kind.id) {
64 /* Key and Mods */ 68 /* Key and Mods */
@@ -68,22 +72,17 @@ void process_action(keyrecord_t *record)
68 uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods : 72 uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods :
69 action.key.mods<<4; 73 action.key.mods<<4;
70 if (event.pressed) { 74 if (event.pressed) {
71 uint8_t tmp_mods = host_get_mods();
72 if (mods) { 75 if (mods) {
73 host_add_mods(mods); 76 host_add_mods(mods);
74 host_send_keyboard_report(); 77 host_send_keyboard_report();
75 } 78 }
76 register_code(action.key.code); 79 register_code(action.key.code);
77 if (mods && action.key.code) {
78 host_set_mods(tmp_mods);
79 host_send_keyboard_report();
80 }
81 } else { 80 } else {
82 if (mods && !action.key.code) { 81 unregister_code(action.key.code);
82 if (mods) {
83 host_del_mods(mods); 83 host_del_mods(mods);
84 host_send_keyboard_report(); 84 host_send_keyboard_report();
85 } 85 }
86 unregister_code(action.key.code);
87 } 86 }
88 } 87 }
89 break; 88 break;
@@ -93,7 +92,7 @@ void process_action(keyrecord_t *record)
93 { 92 {
94 uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : 93 uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods :
95 action.key.mods<<4; 94 action.key.mods<<4;
96 switch (action.layer.code) { 95 switch (action.layer_tap.code) {
97 #ifndef NO_ACTION_ONESHOT 96 #ifndef NO_ACTION_ONESHOT
98 case 0x00: 97 case 0x00:
99 // Oneshot modifier 98 // Oneshot modifier
@@ -199,323 +198,88 @@ void process_action(keyrecord_t *record)
199 } 198 }
200 break; 199 break;
201#endif 200#endif
202#ifndef NO_ACTION_KEYMAP 201#ifndef NO_ACTION_LAYER
203 case ACT_KEYMAP: 202 case ACT_LAYER:
204 switch (action.layer.code) { 203 if (action.layer_bitop.on == 0) {
205 /* Keymap clear */ 204 /* Default Layer Bitwise Operation */
206 case OP_RESET: 205 if (!event.pressed) {
207 switch (action.layer.val & 0x03) { 206 uint8_t shift = action.layer_bitop.part*4;
208 case 0: 207 uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
209 // NOTE: reserved 208 uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
210 overlay_clear(); 209 switch (action.layer_bitop.op) {
211 keymap_clear(); 210 case OP_BIT_AND: default_layer_and(bits | mask); break;
212 break; 211 case OP_BIT_OR: default_layer_or(bits | mask); break;
213 case ON_PRESS: 212 case OP_BIT_XOR: default_layer_xor(bits | mask); break;
214 if (event.pressed) { 213 case OP_BIT_SET: default_layer_and(mask); default_layer_or(bits); break;
215 overlay_clear();
216 keymap_clear();
217 }
218 break;
219 case ON_RELEASE:
220 if (!event.pressed) {
221 overlay_clear();
222 keymap_clear();
223 }
224 break;
225 case ON_BOTH:
226 overlay_clear();
227 keymap_clear();
228 break;
229 /* NOTE: 4-7 rserved */
230 } 214 }
231 break; 215 }
232 /* Keymap Reset default layer */ 216 } else {
233 case (OP_RESET | ON_PRESS): 217 /* Layer Bitwise Operation */
234 if (event.pressed) { 218 if (event.pressed ? (action.layer_bitop.on & ON_PRESS) :
235 default_layer_set(action.layer.val); 219 (action.layer_bitop.on & ON_RELEASE)) {
236 } 220 uint8_t shift = action.layer_bitop.part*4;
237 break; 221 uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
238 case (OP_RESET | ON_RELEASE): 222 uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
239 if (!event.pressed) { 223 switch (action.layer_bitop.op) {
240 default_layer_set(action.layer.val); 224 case OP_BIT_AND: layer_and(bits | mask); break;
225 case OP_BIT_OR: layer_or(bits | mask); break;
226 case OP_BIT_XOR: layer_xor(bits | mask); break;
227 case OP_BIT_SET: layer_and(mask); layer_or(bits); break;
241 } 228 }
242 break; 229 }
243 case (OP_RESET | ON_BOTH): 230 }
244 default_layer_set(action.layer.val); 231 break;
245 break; 232 #ifndef NO_ACTION_TAPPING
246 233 case ACT_LAYER_TAP:
247 /* Keymap Bit invert */ 234 case ACT_LAYER_TAP1:
248 case OP_INV: 235 switch (action.layer_tap.code) {
249 /* with tap toggle */ 236 case OP_TAP_TOGGLE:
237 /* tap toggle */
250 if (event.pressed) { 238 if (event.pressed) {
251 if (tap_count < TAPPING_TOGGLE) { 239 if (tap_count < TAPPING_TOGGLE) {
252 debug("KEYMAP_INV: tap toggle(press).\n"); 240 layer_invert(action.layer_tap.val);
253 keymap_invert(action.layer.val);
254 } 241 }
255 } else { 242 } else {
256 if (tap_count <= TAPPING_TOGGLE) { 243 if (tap_count <= TAPPING_TOGGLE) {
257 debug("KEYMAP_INV: tap toggle(release).\n"); 244 layer_invert(action.layer_tap.val);
258 keymap_invert(action.layer.val);
259 } 245 }
260 } 246 }
261 break; 247 break;
262 case (OP_INV | ON_PRESS): 248 case OP_ON_OFF:
263 if (event.pressed) { 249 event.pressed ? layer_on(action.layer_tap.val) :
264 keymap_invert(action.layer.val); 250 layer_off(action.layer_tap.val);
265 }
266 break;
267 case (OP_INV | ON_RELEASE):
268 if (!event.pressed) {
269 keymap_invert(action.layer.val);
270 }
271 break; 251 break;
272 case (OP_INV | ON_BOTH): 252 case OP_OFF_ON:
273 keymap_invert(action.layer.val); 253 event.pressed ? layer_off(action.layer_tap.val) :
254 layer_on(action.layer_tap.val);
274 break; 255 break;
275 256 case OP_SET_CLEAR:
276 /* Keymap Bit on */ 257 event.pressed ? layer_move(action.layer_tap.val) :
277 case OP_ON: 258 layer_clear();
278 if (event.pressed) {
279 keymap_on(action.layer.val);
280 } else {
281 keymap_off(action.layer.val);
282 }
283 break;
284 case (OP_ON | ON_PRESS):
285 if (event.pressed) {
286 keymap_on(action.layer.val);
287 }
288 break;
289 case (OP_ON | ON_RELEASE):
290 if (!event.pressed) {
291 keymap_on(action.layer.val);
292 }
293 break; 259 break;
294 case (OP_ON | ON_BOTH):
295 keymap_on(action.layer.val);
296 break;
297
298 /* Keymap Bit off */
299 case OP_OFF:
300 if (event.pressed) {
301 keymap_off(action.layer.val);
302 } else {
303 keymap_on(action.layer.val);
304 }
305 break;
306 case (OP_OFF | ON_PRESS):
307 if (event.pressed) {
308 keymap_off(action.layer.val);
309 }
310 break;
311 case (OP_OFF | ON_RELEASE):
312 if (!event.pressed) {
313 keymap_off(action.layer.val);
314 }
315 break;
316 case (OP_OFF | ON_BOTH):
317 keymap_off(action.layer.val);
318 break;
319
320 /* Keymap Bit set */
321 case OP_SET:
322 if (event.pressed) {
323 keymap_set(action.layer.val);
324 } else {
325 keymap_clear();
326 }
327 break;
328 case (OP_SET | ON_PRESS):
329 if (event.pressed) {
330 keymap_set(action.layer.val);
331 }
332 break;
333 case (OP_SET | ON_RELEASE):
334 if (!event.pressed) {
335 keymap_set(action.layer.val);
336 }
337 break;
338 case (OP_SET | ON_BOTH):
339 keymap_set(action.layer.val);
340 break;
341
342 /* Keymap Bit invert with tap key */
343 default: 260 default:
261 /* tap key */
344 if (event.pressed) { 262 if (event.pressed) {
345 if (tap_count > 0) { 263 if (tap_count > 0) {
346 debug("KEYMAP_TAP_KEY: Tap: register_code\n"); 264 debug("KEYMAP_TAP_KEY: Tap: register_code\n");
347 register_code(action.layer.code); 265 register_code(action.layer_tap.code);
348 } else { 266 } else {
349 debug("KEYMAP_TAP_KEY: No tap: On on press\n"); 267 debug("KEYMAP_TAP_KEY: No tap: On on press\n");
350 keymap_on(action.layer.val); 268 layer_on(action.layer_tap.val);
351 } 269 }
352 } else { 270 } else {
353 if (tap_count > 0) { 271 if (tap_count > 0) {
354 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); 272 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n");
355 unregister_code(action.layer.code); 273 unregister_code(action.layer_tap.code);
356 } else { 274 } else {
357 debug("KEYMAP_TAP_KEY: No tap: Off on release\n"); 275 debug("KEYMAP_TAP_KEY: No tap: Off on release\n");
358 keymap_off(action.layer.val); 276 layer_off(action.layer_tap.val);
359 }
360 }
361 break;
362 }
363 break;
364#endif
365#ifndef NO_ACTION_OVERLAY
366 case ACT_OVERLAY:
367 switch (action.layer.code) {
368 // Overlay Invert bit4
369 case OP_INV4 | 0:
370 if (action.layer.val == 0) {
371 // NOTE: reserved for future use
372 overlay_clear();
373 } else {
374 overlay_set(overlay_stat ^ action.layer.val);
375 }
376 break;
377 case OP_INV4 | 1:
378 if (action.layer.val == 0) {
379 // on pressed
380 if (event.pressed) overlay_clear();
381 } else {
382 overlay_set(overlay_stat ^ action.layer.val<<4);
383 }
384 break;
385 case OP_INV4 | 2:
386 if (action.layer.val == 0) {
387 // on released
388 if (!event.pressed) overlay_clear();
389 } else {
390 overlay_set(overlay_stat ^ action.layer.val<<8);
391 }
392 break;
393 case OP_INV4 | 3:
394 if (action.layer.val == 0) {
395 // on both
396 overlay_clear();
397 } else {
398 overlay_set(overlay_stat ^ action.layer.val<<12);
399 }
400 break;
401
402 /* Overlay Bit invert */
403 case OP_INV:
404 /* with tap toggle */
405 if (event.pressed) {
406 if (tap_count < TAPPING_TOGGLE) {
407 debug("OVERLAY_INV: tap toggle(press).\n");
408 overlay_invert(action.layer.val);
409 }
410 } else {
411 if (tap_count <= TAPPING_TOGGLE) {
412 debug("OVERLAY_INV: tap toggle(release).\n");
413 overlay_invert(action.layer.val);
414 }
415 }
416 break;
417 case (OP_INV | ON_PRESS):
418 if (event.pressed) {
419 overlay_invert(action.layer.val);
420 }
421 break;
422 case (OP_INV | ON_RELEASE):
423 if (!event.pressed) {
424 overlay_invert(action.layer.val);
425 }
426 break;
427 case (OP_INV | ON_BOTH):
428 overlay_invert(action.layer.val);
429 break;
430
431 /* Overlay Bit on */
432 case OP_ON:
433 if (event.pressed) {
434 overlay_on(action.layer.val);
435 } else {
436 overlay_off(action.layer.val);
437 }
438 break;
439 case (OP_ON | ON_PRESS):
440 if (event.pressed) {
441 overlay_on(action.layer.val);
442 }
443 break;
444 case (OP_ON | ON_RELEASE):
445 if (!event.pressed) {
446 overlay_on(action.layer.val);
447 }
448 break;
449 case (OP_ON | ON_BOTH):
450 overlay_on(action.layer.val);
451 break;
452
453 /* Overlay Bit off */
454 case OP_OFF:
455 if (event.pressed) {
456 overlay_off(action.layer.val);
457 } else {
458 overlay_on(action.layer.val);
459 }
460 break;
461 case (OP_OFF | ON_PRESS):
462 if (event.pressed) {
463 overlay_off(action.layer.val);
464 }
465 break;
466 case (OP_OFF | ON_RELEASE):
467 if (!event.pressed) {
468 overlay_off(action.layer.val);
469 }
470 break;
471 case (OP_OFF | ON_BOTH):
472 overlay_off(action.layer.val);
473 break;
474
475 /* Overlay Bit set */
476 case OP_SET:
477 if (event.pressed) {
478 overlay_move(action.layer.val);
479 } else {
480 overlay_clear();
481 }
482 break;
483 case (OP_SET | ON_PRESS):
484 if (event.pressed) {
485 overlay_move(action.layer.val);
486 }
487 break;
488 case (OP_SET | ON_RELEASE):
489 if (!event.pressed) {
490 overlay_move(action.layer.val);
491 }
492 break;
493 case (OP_SET | ON_BOTH):
494 overlay_move(action.layer.val);
495 break;
496
497 /* Overlay Bit invert with tap key */
498 default:
499 if (event.pressed) {
500 if (tap_count > 0) {
501 debug("OVERLAY_TAP_KEY: Tap: register_code\n");
502 register_code(action.layer.code);
503 } else {
504 debug("OVERLAY_TAP_KEY: No tap: On on press\n");
505 overlay_on(action.layer.val);
506 }
507 } else {
508 if (tap_count > 0) {
509 debug("OVERLAY_TAP_KEY: Tap: unregister_code\n");
510 unregister_code(action.layer.code);
511 } else {
512 debug("OVERLAY_TAP_KEY: No tap: Off on release\n");
513 overlay_off(action.layer.val);
514 } 277 }
515 } 278 }
516 break; 279 break;
517 } 280 }
518 break; 281 break;
282 #endif
519#endif 283#endif
520 /* Extentions */ 284 /* Extentions */
521#ifndef NO_ACTION_MACRO 285#ifndef NO_ACTION_MACRO
@@ -667,16 +431,9 @@ bool is_tap_key(key_t key)
667 switch (action.kind.id) { 431 switch (action.kind.id) {
668 case ACT_LMODS_TAP: 432 case ACT_LMODS_TAP:
669 case ACT_RMODS_TAP: 433 case ACT_RMODS_TAP:
434 case ACT_LAYER_TAP:
435 case ACT_LAYER_TAP1:
670 return true; 436 return true;
671 case ACT_KEYMAP:
672 case ACT_OVERLAY:
673 switch (action.layer.code) {
674 case 0x04 ... 0xEF: /* tap key */
675 case OP_INV:
676 return true;
677 default:
678 return false;
679 }
680 case ACT_MACRO: 437 case ACT_MACRO:
681 case ACT_FUNCTION: 438 case ACT_FUNCTION:
682 if (action.func.opt & FUNC_TAP) { return true; } 439 if (action.func.opt & FUNC_TAP) { return true; }
@@ -714,8 +471,9 @@ void debug_action(action_t action)
714 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; 471 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break;
715 case ACT_USAGE: debug("ACT_USAGE"); break; 472 case ACT_USAGE: debug("ACT_USAGE"); break;
716 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; 473 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
717 case ACT_KEYMAP: debug("ACT_KEYMAP"); break; 474 case ACT_LAYER: debug("ACT_LAYER"); break;
718 case ACT_OVERLAY: debug("ACT_OVERLAY"); break; 475 case ACT_LAYER_TAP: debug("ACT_LAYER_TAP"); break;
476 case ACT_LAYER_TAP1: debug("ACT_LAYER_TAP1"); break;
719 case ACT_MACRO: debug("ACT_MACRO"); break; 477 case ACT_MACRO: debug("ACT_MACRO"); break;
720 case ACT_COMMAND: debug("ACT_COMMAND"); break; 478 case ACT_COMMAND: debug("ACT_COMMAND"); break;
721 case ACT_FUNCTION: debug("ACT_FUNCTION"); break; 479 case ACT_FUNCTION: debug("ACT_FUNCTION"); break;
diff --git a/common/action.h b/common/action.h
index a6cb45384..98c4ef81a 100644
--- a/common/action.h
+++ b/common/action.h
@@ -21,71 +21,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include <stdbool.h> 21#include <stdbool.h>
22#include "keyboard.h" 22#include "keyboard.h"
23#include "keycode.h" 23#include "keycode.h"
24#include "action_code.h"
24#include "action_macro.h" 25#include "action_macro.h"
25 26
26 27
28/* tapping count and state */
29typedef struct {
30 bool interrupted :1;
31 bool reserved2 :1;
32 bool reserved1 :1;
33 bool reserved0 :1;
34 uint8_t count :4;
35} tap_t;
36
37/* Key event container for recording */
27typedef struct { 38typedef struct {
28 keyevent_t event; 39 keyevent_t event;
29#ifndef NO_ACTION_TAPPING 40#ifndef NO_ACTION_TAPPING
30 /* tapping count and state */ 41 tap_t tap;
31 struct {
32 bool interrupted :1;
33 bool reserved2 :1;
34 bool reserved1 :1;
35 bool reserved0 :1;
36 uint8_t count :4;
37 } tap;
38#endif 42#endif
39} keyrecord_t; 43} keyrecord_t;
40 44
41/* Action struct.
42 *
43 * In avr-gcc bit field seems to be assigned from LSB(bit0) to MSB(bit15).
44 * AVR looks like a little endian in avr-gcc.
45 *
46 * NOTE: not portable across compiler/endianness?
47 * Byte order and bit order of 0x1234:
48 * Big endian: 15 ... 8 7 ... 210
49 * | 0x12 | 0x34 |
50 * 0001 0010 0011 0100
51 * Little endian: 012 ... 7 8 ... 15
52 * | 0x34 | 0x12 |
53 * 0010 1100 0100 1000
54 */
55typedef union {
56 uint16_t code;
57 struct action_kind {
58 uint16_t param :12;
59 uint8_t id :4;
60 } kind;
61 struct action_key {
62 uint8_t code :8;
63 uint8_t mods :4;
64 uint8_t kind :4;
65 } key;
66 struct action_layer {
67 uint8_t code :8;
68 uint8_t val :4;
69 uint8_t kind :4;
70 } layer;
71 struct action_usage {
72 uint16_t code :10;
73 uint8_t page :2;
74 uint8_t kind :4;
75 } usage;
76 struct action_command {
77 uint8_t id :8;
78 uint8_t opt :4;
79 uint8_t kind :4;
80 } command;
81 struct action_function {
82 uint8_t id :8;
83 uint8_t opt :4;
84 uint8_t kind :4;
85 } func;
86} action_t;
87
88
89 45
90/* Execute action per keyevent */ 46/* Execute action per keyevent */
91void action_exec(keyevent_t event); 47void action_exec(keyevent_t event);
@@ -117,255 +73,4 @@ void debug_event(keyevent_t event);
117void debug_record(keyrecord_t record); 73void debug_record(keyrecord_t record);
118void debug_action(action_t action); 74void debug_action(action_t action);
119 75
120
121
122/*
123 * Action codes
124 * ============
125 * 16bit code: action_kind(4bit) + action_parameter(12bit)
126 *
127 * Keyboard Keys(00XX)
128 * -------------------
129 * ACT_LMODS(0000):
130 * 0000|0000|000000|00 No action
131 * 0000|0000|000000|01 Transparent
132 * 0000|0000| keycode Key
133 * 0000|mods|000000|00 Left mods
134 * 0000|mods| keycode Key & Left mods
135 *
136 * ACT_RMODS(0001):
137 * 0001|0000|000000|00 No action(not used)
138 * 0001|0000|000000|01 Transparent(not used)
139 * 0001|0000| keycode Key(no used)
140 * 0001|mods|000000|00 Right mods
141 * 0001|mods| keycode Key & Right mods
142 *
143 * ACT_LMODS_TAP(0010):
144 * 0010|mods|000000|00 Left mods OneShot
145 * 0010|mods|000000|01 (reserved)
146 * 0010|mods|000000|10 (reserved)
147 * 0010|mods|000000|11 (reserved)
148 * 0010|mods| keycode Left mods + tap Key
149 *
150 * ACT_RMODS_TAP(0011):
151 * 0011|mods|000000|00 Right mods OneShot
152 * 0011|mods|000000|01 (reserved)
153 * 0011|mods|000000|10 (reserved)
154 * 0011|mods|000000|11 (reserved)
155 * 0011|mods| keycode Right mods + tap Key
156 *
157 *
158 * Other keys(01XX)
159 * --------------------
160 * This action handles other usages than keyboard.
161 * ACT_USAGE(0100):
162 * 0100|00| usage(10) System control(0x80) - General Desktop page(0x01)
163 * 0100|01| usage(10) Consumer control(0x01) - Consumer page(0x0C)
164 * 0100|10| usage(10) (reserved)
165 * 0100|11| usage(10) (reserved)
166 *
167 * ACT_MOUSEKEY(0110):
168 * 0101|XXXX| keycode Mouse key
169 *
170 *
171 * Layer Actions(10XX)
172 * -------------------
173 * ACT_KEYMAP:
174 * 1000|--xx|0000 0000 Clear keyamp and overlay
175 * 1000|LLLL|0000 00xx Reset default layer and clear keymap and overlay
176 * 1000|LLLL| keycode Invert with tap key
177 * 1000|LLLL|1111 0000 Invert with tap toggle
178 * 1000|LLLL|1111 00xx Invert[^= 1<<L]
179 * 1000|LLLL|1111 0100 On/Off
180 * 1000|LLLL|1111 01xx On[|= 1<<L]
181 * 1000|LLLL|1111 1000 Off/On
182 * 1000|LLLL|1111 10xx Off[&= ~(1<<L)]
183 * 1000|LLLL|1111 1100 Set/Clear
184 * 1000|LLLL|1111 11xx Set[= 1<<L]
185 * default layer: 0-15(4bit)
186 * xx: On {00:for special use, 01:press, 10:release, 11:both}
187 *
188 * ACT_OVERLAY:
189 * 1011|0000|0000 0000 Clear overlay
190 * 1011|LLLL|0000 00ss Invert 4-bit chunk [^= L<<(4*ss)]
191 * 1011|LLLL| keycode Invert with tap key
192 * 1011|LLLL|1111 0000 Invert with tap toggle
193 * 1011|LLLL|1111 00xx Invert[^= 1<<L]
194 * 1011|LLLL|1111 0100 On/Off(momentary)
195 * 1011|LLLL|1111 01xx On[|= 1<<L]
196 * 1011|LLLL|1111 1000 Off/On
197 * 1011|LLLL|1111 10xx Off[&= ~(1<<L)]
198 * 1011|LLLL|1111 1100 Set/Clear
199 * 1011|LLLL|1111 11xx Set[= 1<<L]
200 * overlays: 16-layer on/off status(16bit)
201 * xx: On {00:for special use, 01:press, 10:release, 11:both}
202 *
203 *
204 * Extensions(11XX)
205 * ----------------
206 * ACT_MACRO(1100):
207 * 1100|opt | id(8) Macro play?
208 * 1100|1111| id(8) Macro record?
209 *
210 * ACT_COMMAND(1110):
211 * 1110|opt | id(8) Built-in Command exec
212 *
213 * ACT_FUNCTION(1111):
214 * 1111| address(12) Function?
215 * 1111|opt | id(8) Function?
216 *
217 */
218enum action_kind_id {
219 ACT_LMODS = 0b0000,
220 ACT_RMODS = 0b0001,
221 ACT_LMODS_TAP = 0b0010,
222 ACT_RMODS_TAP = 0b0011,
223
224 ACT_USAGE = 0b0100,
225 ACT_MOUSEKEY = 0b0101,
226
227 ACT_KEYMAP = 0b1000,
228 ACT_OVERLAY = 0b1001,
229
230 ACT_MACRO = 0b1100,
231 ACT_COMMAND = 0b1110,
232 ACT_FUNCTION = 0b1111
233};
234
235
236/* action utility */
237#define ACTION_NO 0
238#define ACTION_TRANSPARENT 1
239#define ACTION(kind, param) ((kind)<<12 | (param))
240#define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F)
241
242/*
243 * Key
244 */
245#define ACTION_KEY(key) ACTION(ACT_LMODS, key)
246/* Mods & key */
247#define ACTION_LMODS(mods) ACTION(ACT_LMODS, MODS4(mods)<<8 | 0x00)
248#define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, MODS4(mods)<<8 | (key))
249#define ACTION_RMODS(mods) ACTION(ACT_RMODS, MODS4(mods)<<8 | 0x00)
250#define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, MODS4(mods)<<8 | (key))
251#define ACTION_LMOD(mod) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | 0x00)
252#define ACTION_LMOD_KEY(mod, key) ACTION(ACT_LMODS, MODS4(MOD_BIT(mod))<<8 | (key))
253#define ACTION_RMOD(mod) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | 0x00)
254#define ACTION_RMOD_KEY(mod, key) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | (key))
255/* Tap key */
256enum mods_codes {
257 MODS_ONESHOT = 0x00,
258};
259#define ACTION_LMODS_TAP_KEY(mods, key) ACTION(ACT_LMODS_TAP, MODS4(mods)<<8 | (key))
260#define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT)
261#define ACTION_RMODS_TAP_KEY(mods, key) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | (key))
262#define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT)
263#define ACTION_LMOD_TAP_KEY(mod, key) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key))
264#define ACTION_LMOD_ONESHOT(mod) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT)
265#define ACTION_RMOD_TAP_KEY(mod, key) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key))
266#define ACTION_RMOD_ONESHOT(mod) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT)
267
268/* HID Usage */
269enum usage_pages {
270 PAGE_SYSTEM,
271 PAGE_CONSUMER
272};
273#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM<<10 | (id))
274#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER<<10 | (id))
275
276/* Mousekey */
277#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)
278
279
280
281/* Layer Actions:
282 * Invert layer ^= (1<<layer)
283 * On layer |= (1<<layer)
284 * Off layer &= ~(1<<layer)
285 * Set layer = (1<<layer)
286 * Clear layer = 0
287 */
288enum layer_params {
289 ON_PRESS = 1,
290 ON_RELEASE = 2,
291 ON_BOTH = 3,
292
293 OP_RESET = 0x00,
294 OP_INV4 = 0x00,
295 OP_INV = 0xF0,
296 OP_ON = 0xF4,
297 OP_OFF = 0xF8,
298 OP_SET = 0xFC,
299};
300
301/*
302 * Default Layer
303 */
304#define ACTION_DEFAULT_LAYER ACTION(ACT_KEYMAP, ON_RELEASE<<8 | OP_RESET | 0)
305#define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER_TO(layer, ON_RELEASE)
306#define ACTION_DEFAULT_LAYER_TO(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_RESET | (on))
307/*
308 * Keymap Layer
309 */
310#define ACTION_KEYMAP_MOMENTARY(layer) ACTION_KEYMAP_ON_OFF(layer)
311#define ACTION_KEYMAP_TOGGLE(layer) ACTION_KEYMAP_INV(layer, ON_RELEASE)
312/* Keymap Invert */
313#define ACTION_KEYMAP_INV(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_INV | (on))
314#define ACTION_KEYMAP_TAP_TOGGLE(layer) ACTION(ACT_KEYMAP, (layer)<<8 | OP_INV | 0)
315/* Keymap On */
316#define ACTION_KEYMAP_ON(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_ON | (on))
317#define ACTION_KEYMAP_ON_OFF(layer) ACTION(ACT_KEYMAP, (layer)<<8 | OP_ON | 0)
318/* Keymap Off */
319#define ACTION_KEYMAP_OFF(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_OFF | (on))
320#define ACTION_KEYMAP_OFF_ON(layer) ACTION(ACT_KEYMAP, (layer)<<8 | OP_OFF | 0)
321/* Keymap Set */
322#define ACTION_KEYMAP_SET(layer, on) ACTION(ACT_KEYMAP, (layer)<<8 | OP_SET | (on))
323#define ACTION_KEYMAP_SET_CLEAR(layer) ACTION(ACT_KEYMAP, (layer)<<8 | OP_SET | 0)
324/* Keymap Invert with tap key */
325#define ACTION_KEYMAP_TAP_KEY(layer, key) ACTION(ACT_KEYMAP, (layer)<<8 | (key))
326
327/*
328 * Overlay Layer
329 */
330#define ACTION_OVERLAY_MOMENTARY(layer) ACTION_OVERLAY_ON_OFF(layer)
331#define ACTION_OVERLAY_TOGGLE(layer) ACTION_OVERLAY_INV(layer, ON_RELEASE)
332/* Overlay Clear */
333#define ACTION_OVERLAY_CLEAR(on) ACTION(ACT_OVERLAY, 0<<8 | OP_INV4 | (on))
334/* Overlay Invert 4-bit chunk */
335#define ACTION_OVERLAY_INV4(bits, shift) ACTION(ACT_OVERLAY, (bits)<<8 | OP_INV4 | shift)
336/* Overlay Invert */
337#define ACTION_OVERLAY_INV(layer, on) ACTION(ACT_OVERLAY, (layer)<<8 | OP_INV | (on))
338#define ACTION_OVERLAY_TAP_TOGGLE(layer) ACTION(ACT_OVERLAY, (layer)<<8 | OP_INV | 0)
339/* Overlay On */
340#define ACTION_OVERLAY_ON(layer, on) ACTION(ACT_OVERLAY, (layer)<<8 | OP_ON | (on))
341#define ACTION_OVERLAY_ON_OFF(layer) ACTION(ACT_OVERLAY, (layer)<<8 | OP_ON | 0)
342/* Overlay Off */
343#define ACTION_OVERLAY_OFF(layer, on) ACTION(ACT_OVERLAY, (layer)<<8 | OP_OFF | (on))
344#define ACTION_OVERLAY_OFF_ON(layer) ACTION(ACT_OVERLAY, (layer)<<8 | OP_OFF | 0)
345/* Overlay Set */
346#define ACTION_OVERLAY_SET(layer, on) ACTION(ACT_OVERLAY, (layer)<<8 | OP_SET | (on))
347#define ACTION_OVERLAY_SET_CLEAR(layer) ACTION(ACT_OVERLAY, (layer)<<8 | OP_SET | 0)
348/* Overlay Invert with tap key */
349#define ACTION_OVERLAY_TAP_KEY(layer, key) ACTION(ACT_OVERLAY, (layer)<<8 | (key))
350
351
352/*
353 * Extensions
354 */
355/* Macro */
356#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id))
357#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id))
358#define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id))
359
360/* Command */
361#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr))
362
363/* Function */
364enum function_opts {
365 FUNC_TAP = 0x8, /* indciates function is tappable */
366};
367#define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id))
368#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id))
369#define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id))
370
371#endif /* ACTION_H */ 76#endif /* ACTION_H */
diff --git a/common/action_code.h b/common/action_code.h
new file mode 100644
index 000000000..0933dce13
--- /dev/null
+++ b/common/action_code.h
@@ -0,0 +1,289 @@
1/*
2Copyright 2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifndef ACTION_CODE_H
18#define ACTION_CODE_H
19
20/* Action codes
21 * ============
22 * 16bit code: action_kind(4bit) + action_parameter(12bit)
23 *
24 *
25 * Key Actions(00xx)
26 * -----------------
27 * ACT_MODS(000r):
28 * 000r|0000|0000 0000 No action code
29 * 000r|0000|0000 0001 Transparent code
30 * 000r|0000| keycode Key
31 * 000r|mods|0000 0000 Modifiers
32 * 000r|mods| keycode Key and Modifiers
33 * r: Left/Right flag(Left:0, Right:1)
34 *
35 * ACT_MODS_TAP(001r):
36 * 0010|mods|0000 0000 Modifiers with OneShot
37 * 0010|mods|0000 00xx (reserved)
38 * 0010|mods| keycode Modifiers with Tap Key
39 *
40 *
41 * Other Keys(01xx)
42 * ----------------
43 * ACT_USAGE(0100): TODO: Not needed?
44 * 0100|00| usage(10) System control(0x80) - General Desktop page(0x01)
45 * 0100|01| usage(10) Consumer control(0x01) - Consumer page(0x0C)
46 * 0100|10| usage(10) (reserved)
47 * 0100|11| usage(10) (reserved)
48 *
49 * ACT_MOUSEKEY(0110): TODO: Not needed?
50 * 0101|xxxx| keycode Mouse key
51 *
52 * 011x|xxxx xxxx xxxx (reseved)
53 *
54 *
55 * Layer Actions(10xx)
56 * -------------------
57 * ACT_LAYER(1000):
58 * 1000|oo00|pppE BBBB Default Layer Bitwise operation
59 * oo: operation(00:AND, 01:OR, 10:XOR, 11:SET)
60 * ppp: 4-bit chunk part(0-7)
61 * EBBBB: bits and extra bit
62 * 1000|ooee|pppE BBBB Layer Bitwise Operation
63 * oo: operation(00:AND, 01:OR, 10:XOR, 11:SET)
64 * ppp: 4-bit chunk part(0-7)
65 * eBBBB: bits and extra bit
66 * ee: on event(00:default layer, 01:press, 10:release, 11:both)
67 *
68 * 1001|xxxx|xxxx xxxx (reserved)
69 * 1001|oopp|BBBB BBBB 8-bit Bitwise Operation???
70 *
71 * ACT_LAYER_TAP(101x):
72 * 101E|LLLL| keycode Invert with tap key
73 * 101E|LLLL|1110 xxxx Reserved(0xE0-EF)
74 * 101E|LLLL|1111 0000 Invert with tap toggle(0xF0)
75 * 101E|LLLL|1111 0001 On/Off
76 * 101E|LLLL|1111 0010 Off/On
77 * 101E|LLLL|1111 0011 Set/Clear
78 * 101E|LLLL|1111 xxxx Reserved(0xF4-FF)
79 * ELLLL: layer(0-31)
80 *
81 *
82 * Extensions(11xx)
83 * ----------------
84 * ACT_MACRO(1100):
85 * 1100|opt | id(8) Macro play?
86 * 1100|1111| id(8) Macro record?
87 *
88 * ACT_COMMAND(1110):
89 * 1110|opt | id(8) Built-in Command exec
90 *
91 * ACT_FUNCTION(1111):
92 * 1111| address(12) Function?
93 * 1111|opt | id(8) Function?
94 */
95enum action_kind_id {
96 /* Key Actions */
97 ACT_MODS = 0b0000,
98 ACT_LMODS = 0b0000,
99 ACT_RMODS = 0b0001,
100 ACT_MODS_TAP = 0b0010,
101 ACT_LMODS_TAP = 0b0010,
102 ACT_RMODS_TAP = 0b0011,
103 /* Other Keys */
104 ACT_USAGE = 0b0100,
105 ACT_MOUSEKEY = 0b0101,
106 /* Layer Actions */
107 ACT_LAYER = 0b1000,
108 ACT_LAYER_TAP = 0b1010,
109 ACT_LAYER_TAP1 = 0b1011,
110 /* Extensions */
111 ACT_MACRO = 0b1100,
112 ACT_COMMAND = 0b1110,
113 ACT_FUNCTION = 0b1111
114};
115
116
117/* Action Code Struct
118 *
119 * NOTE:
120 * In avr-gcc bit field seems to be assigned from LSB(bit0) to MSB(bit15).
121 * AVR looks like a little endian in avr-gcc.
122 * Not portable across compiler/endianness?
123 *
124 * Byte order and bit order of 0x1234:
125 * Big endian: Little endian:
126 * -------------------- --------------------
127 * FEDC BA98 7654 3210 0123 4567 89AB CDEF
128 * 0001 0010 0011 0100 0010 1100 0100 1000
129 * 0x12 0x34 0x34 0x12
130 */
131typedef union {
132 uint16_t code;
133 struct action_kind {
134 uint16_t param :12;
135 uint8_t id :4;
136 } kind;
137 struct action_key {
138 uint8_t code :8;
139 uint8_t mods :4;
140 uint8_t kind :4;
141 } key;
142 struct action_layer_bitop {
143 uint8_t bits :4;
144 uint8_t xbit :1;
145 uint8_t part :3;
146 uint8_t on :2;
147 uint8_t op :2;
148 uint8_t kind :4;
149 } layer_bitop;
150 struct action_layer_tap {
151 uint8_t code :8;
152 uint8_t val :5;
153 uint8_t kind :3;
154 } layer_tap;
155 struct action_usage {
156 uint16_t code :10;
157 uint8_t page :2;
158 uint8_t kind :4;
159 } usage;
160 struct action_command {
161 uint8_t id :8;
162 uint8_t opt :4;
163 uint8_t kind :4;
164 } command;
165 struct action_function {
166 uint8_t id :8;
167 uint8_t opt :4;
168 uint8_t kind :4;
169 } func;
170} action_t;
171
172
173/* action utility */
174#define ACTION_NO 0
175#define ACTION_TRANSPARENT 1
176#define ACTION(kind, param) ((kind)<<12 | (param))
177
178
179/*
180 * Key Actions
181 */
182/* Mod bits: 43210
183 * bit 0 ||||+- Control
184 * bit 1 |||+-- Shift
185 * bit 2 ||+--- Alt
186 * bit 3 |+---- Gui
187 * bit 4 +----- LR flag(Left:0, Right:1)
188 */
189enum mods_bit {
190 MOD_LCTL = 0x01,
191 MOD_LSFT = 0x02,
192 MOD_LALT = 0x04,
193 MOD_LGUI = 0x08,
194 MOD_RCTL = 0x11,
195 MOD_RSFT = 0x12,
196 MOD_RALT = 0x14,
197 MOD_RGUI = 0x18,
198};
199enum mods_codes {
200 MODS_ONESHOT = 0x00,
201};
202#define ACTION_KEY(key) ACTION(ACT_MODS, (key))
203#define ACTION_MODS(mods) ACTION(ACT_MODS, (mods)<<8 | 0)
204#define ACTION_MODS_KEY(mods, key) ACTION(ACT_MODS, (mods)<<8 | (key))
205#define ACTION_MODS_TAP_KEY(mods, key) ACTION(ACT_MODS_TAP, (mods)<<8 | (key))
206#define ACTION_MODS_ONESHOT(mods) ACTION(ACT_MODS_TAP, (mods)<<8 | MODS_ONESHOT)
207
208
209/*
210 * Other Keys
211 */
212enum usage_pages {
213 PAGE_SYSTEM,
214 PAGE_CONSUMER
215};
216#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM<<10 | (id))
217#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER<<10 | (id))
218#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)
219
220
221
222/*
223 * Layer Actions
224 */
225enum layer_param_on {
226 ON_PRESS = 1,
227 ON_RELEASE = 2,
228 ON_BOTH = 3,
229};
230enum layer_param_bit_op {
231 OP_BIT_AND = 0,
232 OP_BIT_OR = 1,
233 OP_BIT_XOR = 2,
234 OP_BIT_SET = 3,
235};
236enum layer_pram_tap_op {
237 OP_TAP_TOGGLE = 0xF0,
238 OP_ON_OFF,
239 OP_OFF_ON,
240 OP_SET_CLEAR,
241};
242#define ACTION_LAYER_BITOP(op, part, bits, on) (ACT_LAYER<<12 | (op)<<10 | (on)<<8 | (part)<<5 | ((bits)&0x1f))
243#define ACTION_LAYER_TAP(layer, key) (ACT_LAYER_TAP<<12 | (layer)<<8 | (key))
244/* Default Layer */
245#define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER_BIT_SET((layer)/4, 1<<((layer)%4))
246/* Layer Operation */
247#define ACTION_LAYER_CLEAR(on) ACTION_LAYER_BIT_AND(0, 0, (on))
248#define ACTION_LAYER_MOMENTARY(layer) ACTION_LAYER_ON_OFF(layer)
249#define ACTION_LAYER_TOGGLE(layer) ACTION_LAYER_INVERT(layer, ON_RELEASE)
250#define ACTION_LAYER_INVERT(layer, on) ACTION_LAYER_BIT_XOR((layer)/4, 1<<((layer)%4), (on))
251#define ACTION_LAYER_ON(layer, on) ACTION_LAYER_BIT_OR( (layer)/4, 1<<((layer)%4), (on))
252#define ACTION_LAYER_OFF(layer, on) ACTION_LAYER_BIT_AND((layer)/4, ~(1<<((layer)%4)), (on))
253#define ACTION_LAYER_SET(layer, on) ACTION_LAYER_BIT_SET((layer)/4, 1<<((layer)%4), (on))
254#define ACTION_LAYER_ON_OFF(layer) ACTION_LAYER_TAP((layer), OP_ON_OFF)
255#define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON)
256#define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR)
257/* With Tapping */
258#define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key))
259#define ACTION_LAYER_TAP_TOGGLE(layer) ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE)
260/* Bitwise Operation */
261#define ACTION_LAYER_BIT_AND(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), (on))
262#define ACTION_LAYER_BIT_OR( part, bits, on) ACTION_LAYER_BITOP(OP_BIT_OR, (part), (bits), (on))
263#define ACTION_LAYER_BIT_XOR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), (on))
264#define ACTION_LAYER_BIT_SET(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), (on))
265/* Default Layer Bitwise Operation */
266#define ACTION_DEFAULT_LAYER_BIT_AND(part, bits) ACTION_LAYER_BITOP(OP_BIT_AND, (part), (bits), 0)
267#define ACTION_DEFAULT_LAYER_BIT_OR( part, bits) ACTION_LAYER_BITOP(OP_BIT_OR, (part), (bits), 0)
268#define ACTION_DEFAULT_LAYER_BIT_XOR(part, bits) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), 0)
269#define ACTION_DEFAULT_LAYER_BIT_SET(part, bits) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), 0)
270
271
272/*
273 * Extensions
274 */
275/* Macro */
276#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id))
277#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP<<8 | (id))
278#define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt)<<8 | (id))
279/* Command */
280#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt)<<8 | (addr))
281/* Function */
282enum function_opts {
283 FUNC_TAP = 0x8, /* indciates function is tappable */
284};
285#define ACTION_FUNCTION(id) ACTION(ACT_FUNCTION, (id))
286#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | (id))
287#define ACTION_FUNCTION_OPT(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | (id))
288
289#endif /* ACTION_CODE_H */
diff --git a/common/action_layer.c b/common/action_layer.c
new file mode 100644
index 000000000..3413c53e6
--- /dev/null
+++ b/common/action_layer.c
@@ -0,0 +1,135 @@
1#include <stdint.h>
2#include "keyboard.h"
3#include "action.h"
4#include "debug.h"
5#include "util.h"
6#include "action_layer.h"
7
8
9/*
10 * Default Layer State
11 */
12uint32_t default_layer_state = 0;
13
14static void default_layer_state_set(uint32_t state)
15{
16 debug("default_layer_state: ");
17 default_layer_debug(); debug(" to ");
18 default_layer_state = state;
19 default_layer_debug(); debug("\n");
20 clear_keyboard_but_mods(); // To avoid stuck keys
21}
22
23void default_layer_debug(void)
24{
25 debug_hex32(default_layer_state);
26 debug("("); debug_dec(biton32(default_layer_state)); debug(")");
27}
28
29void default_layer_set(uint8_t layer)
30{
31 default_layer_state_set(1UL<<layer);
32}
33
34#ifndef NO_ACTION_LAYER
35void default_layer_or(uint32_t state)
36{
37 default_layer_state_set(default_layer_state | state);
38}
39void default_layer_and(uint32_t state)
40{
41 default_layer_state_set(default_layer_state & state);
42}
43void default_layer_xor(uint32_t state)
44{
45 default_layer_state_set(default_layer_state ^ state);
46}
47#endif
48
49
50#ifndef NO_ACTION_LAYER
51/*
52 * Keymap Layer State
53 */
54uint32_t layer_state = 0;
55
56static void layer_state_set(uint32_t state)
57{
58 debug("layer_state: ");
59 layer_debug(); debug(" to ");
60 layer_state = state;
61 layer_debug(); debug("\n");
62 clear_keyboard_but_mods(); // To avoid stuck keys
63}
64
65void layer_clear(void)
66{
67 layer_state_set(0);
68}
69
70void layer_move(uint8_t layer)
71{
72 layer_state_set(1UL<<layer);
73}
74
75void layer_on(uint8_t layer)
76{
77 layer_state_set(layer_state | (1UL<<layer));
78}
79
80void layer_off(uint8_t layer)
81{
82 layer_state_set(layer_state & ~(1UL<<layer));
83}
84
85void layer_invert(uint8_t layer)
86{
87 layer_state_set(layer_state ^ (1UL<<layer));
88}
89
90void layer_or(uint32_t state)
91{
92 layer_state_set(layer_state | state);
93}
94void layer_and(uint32_t state)
95{
96 layer_state_set(layer_state & state);
97}
98void layer_xor(uint32_t state)
99{
100 layer_state_set(layer_state ^ state);
101}
102
103void layer_debug(void)
104{
105 debug_hex32(layer_state);
106 debug("("); debug_dec(biton32(layer_state)); debug(")");
107}
108#endif
109
110
111
112action_t layer_switch_get_action(key_t key)
113{
114 action_t action;
115 action.code = ACTION_TRANSPARENT;
116
117#ifndef NO_ACTION_LAYER
118 uint32_t layers = layer_state | default_layer_state;
119 /* check top layer first */
120 for (int8_t i = 31; i >= 0; i--) {
121 if (layers & (1UL<<i)) {
122 action = action_for_key(i, key);
123 if (action.code != ACTION_TRANSPARENT) {
124 return action;
125 }
126 }
127 }
128 /* fall back to layer 0 */
129 action = action_for_key(0, key);
130 return action;
131#else
132 action = action_for_key(biton32(default_layer_state), key);
133 return action;
134#endif
135}
diff --git a/common/action_layer.h b/common/action_layer.h
new file mode 100644
index 000000000..23f8a00bb
--- /dev/null
+++ b/common/action_layer.h
@@ -0,0 +1,77 @@
1/*
2Copyright 2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifndef ACTION_LAYER_H
18#define ACTION_LAYER_H
19
20#include <stdint.h>
21#include "keyboard.h"
22#include "action.h"
23
24
25/*
26 * Default Layer
27 */
28extern uint32_t default_layer_state;
29void default_layer_debug(void);
30void default_layer_set(uint8_t layer);
31
32#ifndef NO_ACTION_LAYER
33/* bitwise operation */
34void default_layer_or(uint32_t state);
35void default_layer_and(uint32_t state);
36void default_layer_xor(uint32_t state);
37#else
38#define default_layer_or(state)
39#define default_layer_and(state)
40#define default_layer_xor(state)
41#endif
42
43
44/*
45 * Keymap Layer
46 */
47#ifndef NO_ACTION_LAYER
48extern uint32_t layer_state;
49void layer_debug(void);
50void layer_clear(void);
51void layer_move(uint8_t layer);
52void layer_on(uint8_t layer);
53void layer_off(uint8_t layer);
54void layer_invert(uint8_t layer);
55/* bitwise operation */
56void layer_or(uint32_t state);
57void layer_and(uint32_t state);
58void layer_xor(uint32_t state);
59#else
60#define layer_state 0
61#define layer_clear()
62#define layer_move(layer)
63#define layer_on(layer)
64#define layer_off(layer)
65#define layer_invert(layer)
66
67#define layer_or(state)
68#define layer_and(state)
69#define layer_xor(state)
70#define layer_debug()
71#endif
72
73
74/* return action depending on current layer status */
75action_t layer_switch_get_action(key_t key);
76
77#endif
diff --git a/common/action_tapping.h b/common/action_tapping.h
index c9f09f576..9b42d50dc 100644
--- a/common/action_tapping.h
+++ b/common/action_tapping.h
@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#define ACTION_TAPPING_H 18#define ACTION_TAPPING_H
19 19
20 20
21#ifndef NO_ACTION_TAPPING
22 21
23/* period of tapping(ms) */ 22/* period of tapping(ms) */
24#ifndef TAPPING_TERM 23#ifndef TAPPING_TERM
@@ -33,8 +32,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
33#define WAITING_BUFFER_SIZE 8 32#define WAITING_BUFFER_SIZE 8
34 33
35 34
35#ifndef NO_ACTION_TAPPING
36void action_tapping_process(keyrecord_t record); 36void action_tapping_process(keyrecord_t record);
37
38#endif 37#endif
39 38
40#endif 39#endif
diff --git a/common/command.c b/common/command.c
index b29333883..3a1fcb186 100644
--- a/common/command.c
+++ b/common/command.c
@@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
26#include "timer.h" 26#include "timer.h"
27#include "keyboard.h" 27#include "keyboard.h"
28#include "bootloader.h" 28#include "bootloader.h"
29#include "layer_switch.h" 29#include "action_layer.h"
30#include "eeconfig.h" 30#include "eeconfig.h"
31#include "sleep_led.h" 31#include "sleep_led.h"
32#include "led.h" 32#include "led.h"
@@ -573,8 +573,8 @@ static uint8_t numkey2num(uint8_t code)
573 573
574static void switch_default_layer(uint8_t layer) 574static void switch_default_layer(uint8_t layer)
575{ 575{
576 print("switch_default_layer: "); print_dec(default_layer); print(" to "); print_dec(layer); print("\n"); 576 print("switch_default_layer: "); print_dec(biton32(default_layer_state));
577 print(" to "); print_dec(layer); print("\n");
577 default_layer_set(layer); 578 default_layer_set(layer);
578 overlay_clear();
579 clear_keyboard(); 579 clear_keyboard();
580} 580}
diff --git a/common/keymap.c b/common/keymap.c
index ace3f49b6..c98ce09b6 100644
--- a/common/keymap.c
+++ b/common/keymap.c
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#include "keymap.h" 18#include "keymap.h"
19#include "report.h" 19#include "report.h"
20#include "keycode.h" 20#include "keycode.h"
21#include "layer_switch.h" 21#include "action_layer.h"
22#include "action.h" 22#include "action.h"
23#include "action_macro.h" 23#include "action_macro.h"
24#include "debug.h" 24#include "debug.h"
diff --git a/common/layer_switch.c b/common/layer_switch.c
deleted file mode 100644
index a5d426a89..000000000
--- a/common/layer_switch.c
+++ /dev/null
@@ -1,209 +0,0 @@
1#include <stdint.h>
2#include "keyboard.h"
3#include "action.h"
4#include "debug.h"
5#include "util.h"
6#include "layer_switch.h"
7
8
9/*
10 * Default Layer (0-15)
11 */
12uint8_t default_layer = 0;
13
14void default_layer_set(uint8_t layer)
15{
16 debug("default_layer_set: ");
17 debug_dec(default_layer); debug(" to ");
18
19 default_layer = layer;
20
21 debug_dec(default_layer); debug("\n");
22
23 clear_keyboard_but_mods(); // To avoid stuck keys
24}
25
26
27#ifndef NO_ACTION_KEYMAP
28/*
29 * Keymap Layer (0-15)
30 */
31uint16_t keymap_stat = 0;
32
33/* return highest layer whose state is on */
34uint8_t keymap_get_layer(void)
35{
36 return biton16(keymap_stat);
37}
38
39static void keymap_stat_set(uint16_t stat)
40{
41 debug("keymap: ");
42 keymap_debug(); debug(" to ");
43
44 keymap_stat = stat;
45
46 keymap_debug(); debug("\n");
47
48 clear_keyboard_but_mods(); // To avoid stuck keys
49}
50
51void keymap_clear(void)
52{
53 keymap_stat_set(0);
54}
55
56
57void keymap_set(uint16_t stat)
58{
59 keymap_stat_set(stat);
60}
61
62void keymap_move(uint8_t layer)
63{
64 keymap_stat_set(1<<layer);
65}
66
67void keymap_on(uint8_t layer)
68{
69 keymap_stat_set(keymap_stat | (1<<layer));
70}
71
72void keymap_off(uint8_t layer)
73{
74 keymap_stat_set(keymap_stat & ~(1<<layer));
75}
76
77void keymap_invert(uint8_t layer)
78{
79 keymap_stat_set(keymap_stat ^ (1<<layer));
80}
81
82void keymap_or(uint16_t stat)
83{
84 keymap_stat_set(keymap_stat | stat);
85}
86void keymap_and(uint16_t stat)
87{
88 keymap_stat_set(keymap_stat & stat);
89}
90void keymap_xor(uint16_t stat)
91{
92 keymap_stat_set(keymap_stat ^ stat);
93}
94
95void keymap_debug(void)
96{
97 debug_hex16(keymap_stat); debug("("); debug_dec(keymap_get_layer()); debug(")");
98}
99#endif
100
101
102
103#ifndef NO_ACTION_OVERLAY
104/*
105 * Overlay Layer (16-31 = 0-15|0x10)
106 */
107uint16_t overlay_stat = 0;
108
109/* return highest layer whose state is on */
110uint8_t overlay_get_layer(void)
111{
112 return biton16(overlay_stat);
113}
114
115static void overlay_stat_set(uint16_t stat)
116{
117 debug("overlay: ");
118 overlay_debug(); debug(" to ");
119
120 overlay_stat = stat;
121
122 overlay_debug(); debug("\n");
123
124 clear_keyboard_but_mods(); // To avoid stuck keys
125}
126
127void overlay_clear(void)
128{
129 overlay_stat_set(0);
130}
131
132
133void overlay_set(uint16_t stat)
134{
135 overlay_stat_set(stat);
136}
137
138void overlay_move(uint8_t layer)
139{
140 overlay_stat_set(1<<layer);
141}
142
143void overlay_on(uint8_t layer)
144{
145 overlay_stat_set(overlay_stat | (1<<layer));
146}
147
148void overlay_off(uint8_t layer)
149{
150 overlay_stat_set(overlay_stat & ~(1<<layer));
151}
152
153void overlay_invert(uint8_t layer)
154{
155 overlay_stat_set(overlay_stat ^ (1<<layer));
156}
157
158void overlay_or(uint16_t stat)
159{
160 overlay_stat_set(overlay_stat | stat);
161}
162void overlay_and(uint16_t stat)
163{
164 overlay_stat_set(overlay_stat & stat);
165}
166void overlay_xor(uint16_t stat)
167{
168 overlay_stat_set(overlay_stat ^ stat);
169}
170
171void overlay_debug(void)
172{
173 debug_hex16(overlay_stat); debug("("); debug_dec(overlay_get_layer()); debug(")");
174}
175#endif
176
177action_t layer_switch_get_action(key_t key)
178{
179 action_t action;
180 action.code = ACTION_TRANSPARENT;
181
182#ifndef NO_ACTION_OVERLAY
183 /* overlay: top layer first */
184 for (int8_t i = 15; i >= 0; i--) {
185 if (overlay_stat & (1<<i)) {
186 action = action_for_key(i | OVERLAY_BIT, key);
187 if (action.code != ACTION_TRANSPARENT) {
188 return action;
189 }
190 }
191 }
192#endif
193
194#ifndef NO_ACTION_KEYMAP
195 /* keymap: top layer first */
196 for (int8_t i = 15; i >= 0; i--) {
197 if (keymap_stat & (1<<i)) {
198 action = action_for_key(i, key);
199 if (action.code != ACTION_TRANSPARENT) {
200 return action;
201 }
202 }
203 }
204#endif
205
206 /* default layer */
207 action = action_for_key(default_layer, key);
208 return action;
209}
diff --git a/common/layer_switch.h b/common/layer_switch.h
deleted file mode 100644
index eb4cf61ba..000000000
--- a/common/layer_switch.h
+++ /dev/null
@@ -1,110 +0,0 @@
1/*
2Copyright 2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17#ifndef LAYER_SWITCH_H
18#define LAYER_SWITCH_H
19
20#include <stdint.h>
21#include "keyboard.h"
22#include "action.h"
23
24
25/* overlays are asigned at layer 16-31 */
26#define OVERLAY_BIT 0x10
27#define OVERLAY_MASK 0x0F
28
29
30/*
31 * Default Layer
32 */
33/* base layer to fall back */
34extern uint8_t default_layer;
35void default_layer_set(uint8_t layer);
36
37
38/*
39 * Keymap Layer
40 */
41#ifndef NO_ACTION_KEYMAP
42extern uint16_t keymap_stat;
43/* return current active layer */
44uint8_t keymap_get_layer(void);
45void keymap_clear(void);
46void keymap_set(uint16_t stat);
47void keymap_move(uint8_t layer);
48void keymap_on(uint8_t layer);
49void keymap_off(uint8_t layer);
50void keymap_invert(uint8_t layer);
51/* bitwise operation */
52void keymap_or(uint16_t stat);
53void keymap_and(uint16_t stat);
54void keymap_xor(uint16_t stat);
55void keymap_debug(void);
56#else
57#define keymap_stat 0
58#define keymap_get_layer()
59#define keymap_clear()
60#define keymap_set(stat)
61#define keymap_move(layer)
62#define keymap_on(layer)
63#define keymap_off(layer)
64#define keymap_invert(layer)
65#define keymap_or(stat)
66#define keymap_and(stat)
67#define keymap_xor(stat)
68#define keymap_debug()
69#endif
70
71
72/*
73 * Overlay Layer
74 */
75#ifndef NO_ACTION_OVERLAY
76extern uint16_t overlay_stat;
77/* return current active layer */
78uint8_t overlay_get_layer(void);
79void overlay_clear(void);
80void overlay_set(uint16_t stat);
81void overlay_move(uint8_t layer);
82void overlay_on(uint8_t layer);
83void overlay_off(uint8_t layer);
84void overlay_invert(uint8_t layer);
85/* bitwise operation */
86void overlay_or(uint16_t stat);
87void overlay_and(uint16_t stat);
88void overlay_xor(uint16_t stat);
89void overlay_debug(void);
90#else
91#define overlay_stat 0
92#define overlay_get_layer()
93#define overlay_clear()
94#define overlay_set(stat)
95#define overlay_move(layer)
96#define overlay_on(layer)
97#define overlay_off(layer)
98#define overlay_invert(layer)
99#define overlay_or(stat)
100#define overlay_and(stat)
101#define overlay_xor(stat)
102#define overlay_debug()
103#endif
104
105
106
107/* return action depending on current layer status */
108action_t layer_switch_get_action(key_t key);
109
110#endif
diff --git a/common/util.c b/common/util.c
index ff1926d7d..6d4d6bfda 100644
--- a/common/util.c
+++ b/common/util.c
@@ -38,6 +38,14 @@ uint8_t bitpop16(uint16_t bits)
38 return c; 38 return c;
39} 39}
40 40
41uint8_t bitpop32(uint32_t bits)
42{
43 uint8_t c;
44 for (c = 0; bits; c++)
45 bits &= bits - 1;
46 return c;
47}
48
41// most significant on-bit - return highest location of on-bit 49// most significant on-bit - return highest location of on-bit
42// NOTE: return 0 when bit0 is on or all bits are off 50// NOTE: return 0 when bit0 is on or all bits are off
43uint8_t biton(uint8_t bits) 51uint8_t biton(uint8_t bits)
@@ -58,3 +66,14 @@ uint8_t biton16(uint16_t bits)
58 if (bits >> 1) { bits >>= 1; n += 1;} 66 if (bits >> 1) { bits >>= 1; n += 1;}
59 return n; 67 return n;
60} 68}
69
70uint8_t biton32(uint32_t bits)
71{
72 uint8_t n = 0;
73 if (bits >>16) { bits >>=16; n +=16;}
74 if (bits >> 8) { bits >>= 8; n += 8;}
75 if (bits >> 4) { bits >>= 4; n += 4;}
76 if (bits >> 2) { bits >>= 2; n += 2;}
77 if (bits >> 1) { bits >>= 1; n += 1;}
78 return n;
79}
diff --git a/common/util.h b/common/util.h
index 58b7fdf14..4b8b5ca3a 100644
--- a/common/util.h
+++ b/common/util.h
@@ -30,7 +30,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30 30
31uint8_t bitpop(uint8_t bits); 31uint8_t bitpop(uint8_t bits);
32uint8_t bitpop16(uint16_t bits); 32uint8_t bitpop16(uint16_t bits);
33uint8_t bitpop32(uint32_t bits);
34
33uint8_t biton(uint8_t bits); 35uint8_t biton(uint8_t bits);
34uint8_t biton16(uint16_t bits); 36uint8_t biton16(uint16_t bits);
37uint8_t biton32(uint32_t bits);
35 38
36#endif 39#endif
diff --git a/converter/pc98_usb/keymap.c b/converter/pc98_usb/keymap.c
index 279b2b60c..3ab0a4dbe 100644
--- a/converter/pc98_usb/keymap.c
+++ b/converter/pc98_usb/keymap.c
@@ -21,7 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include "keycode.h" 21#include "keycode.h"
22#include "action.h" 22#include "action.h"
23#include "action_macro.h" 23#include "action_macro.h"
24#include "layer_switch.h"
25#include "util.h" 24#include "util.h"
26#include "keymap.h" 25#include "keymap.h"
27 26
@@ -165,10 +164,10 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
165 * Fn actions 164 * Fn actions
166 */ 165 */
167static const uint16_t PROGMEM fn_actions[] = { 166static const uint16_t PROGMEM fn_actions[] = {
168 ACTION_KEYMAP_TAP_TOGGLE(0), // FN0 167 ACTION_LAYER_TAP_TOGGLE(0), // FN0
169 ACTION_KEYMAP_TAP_KEY(1, KC_SLASH), // FN1 168 ACTION_LAYER_TAP_KEY(1, KC_SLASH), // FN1
170 ACTION_KEYMAP_TAP_KEY(2, KC_SCLN), // FN2 169 ACTION_LAYER_TAP_KEY(2, KC_SCLN), // FN2
171 ACTION_KEYMAP_MOMENTARY(2), // FN3 170 ACTION_LAYER_MOMENTARY(2), // FN3
172 ACTION_MACRO(LBRACKET), // FN4 171 ACTION_MACRO(LBRACKET), // FN4
173 ACTION_MACRO(RBRACKET), // FN5 172 ACTION_MACRO(RBRACKET), // FN5
174 ACTION_MACRO(DUMMY), // FN6 173 ACTION_MACRO(DUMMY), // FN6
@@ -183,29 +182,16 @@ static const uint16_t PROGMEM fn_actions[] = {
183 * No need to edit. 182 * No need to edit.
184 */ 183 */
185#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) 184#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
186#define OVERLAYS_SIZE (sizeof(overlays) / sizeof(overlays[0]))
187#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) 185#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
188 186
189/* translates key to keycode */ 187/* translates key to keycode */
190uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) 188uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
191{ 189{
192 /* Overlay: 16-31(OVERLAY_BIT(0x10) | overlay_layer) */ 190 if (layer < KEYMAPS_SIZE) {
193 if (layer & OVERLAY_BIT) { 191 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
194 layer &= OVERLAY_MASK; 192 } else {
195 if (layer < OVERLAYS_SIZE) { 193 // fall back to layer 0
196 return pgm_read_byte(&overlays[(layer)][(key.row)][(key.col)]); 194 return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
197 } else {
198 return KC_TRANSPARENT;
199 }
200 }
201 /* Keymap: 0-15 */
202 else {
203 if (layer < KEYMAPS_SIZE) {
204 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
205 } else {
206 // fall back to layer 0
207 return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
208 }
209 } 195 }
210} 196}
211 197
diff --git a/converter/pc98_usb/matrix.c b/converter/pc98_usb/matrix.c
index d03aaf10d..8833e0a85 100644
--- a/converter/pc98_usb/matrix.c
+++ b/converter/pc98_usb/matrix.c
@@ -93,10 +93,6 @@ RETRY:
93 93
94void matrix_init(void) 94void matrix_init(void)
95{ 95{
96 print_enable = true;
97// debug_enable = true;
98// debug_matrix = true;
99
100 PC98_RST_DDR |= (1<<PC98_RST_BIT); 96 PC98_RST_DDR |= (1<<PC98_RST_BIT);
101 PC98_RDY_DDR |= (1<<PC98_RDY_BIT); 97 PC98_RDY_DDR |= (1<<PC98_RDY_BIT);
102 PC98_RTY_DDR |= (1<<PC98_RTY_BIT); 98 PC98_RTY_DDR |= (1<<PC98_RTY_BIT);
diff --git a/doc/keymap.md b/doc/keymap.md
index ca48c6e5a..474a706e0 100644
--- a/doc/keymap.md
+++ b/doc/keymap.md
@@ -3,20 +3,20 @@ Keymap framework - how to define your keymap
3***NOTE: This is not final version, may be inconsistent with source code and changed occasionally for a while.*** 3***NOTE: This is not final version, may be inconsistent with source code and changed occasionally for a while.***
4 4
5## 0. Keymap and layers 5## 0. Keymap and layers
6**Keymap** is comprised of multiple layers of key layout, you can define **16** layers at most. 6**Keymap** is comprised of multiple layers of key layout, you can define **32 layers** at most.
7**Layer** is an array of **keycodes** to define **actions** on each physical keys. 7**Layer** is an array of **keycodes** to define **actions** for each physical keys.
8respective layers can be validated simultaneously. Layers are indexed with 0 to 15 and higher layer has precedence. 8respective layers can be validated simultaneously. Layers are indexed with 0 to 31 and higher layer has precedence.
9 9
10 Keymap with 16 Layers Layer: array of Keycodes 10 Keymap: 32 Layers Layer: Keycode matrix
11 --------------------- ------------------------ 11 ----------------- ---------------------
12 stack of layers content of layer 12 stack of layers array_of_keycode[row][column]
13 ____________ precedence _______________________ 13 ____________ precedence _______________________
14 / / | high / ESC / F1 / F2 / F3 .... 14 / / | high / ESC / F1 / F2 / F3 ....
15 15 /___________// | /-----/-----/-----/----- 15 31 /___________// | /-----/-----/-----/-----
16 14 /___________// | / TAB / / / .... 16 30 /___________// | / TAB / Q / W / E ....
17 13 /___________/_ | /-----/-----/-----/----- 17 29 /___________/ | /-----/-----/-----/-----
18 : / : : : : : / | /LCtrl/ / / .... 18 : _:_:_:_:_:__ | : /LCtrl/ A / S / D ....
19 3 /___________// | : / : : : : 19 : / : : : : : / | : / : : : :
20 2 /___________// | 2 `-------------------------- 20 2 /___________// | 2 `--------------------------
21 1 /___________// | 1 `-------------------------- 21 1 /___________// | 1 `--------------------------
22 0 /___________/ V low 0 `-------------------------- 22 0 /___________/ V low 0 `--------------------------
@@ -25,42 +25,42 @@ respective layers can be validated simultaneously. Layers are indexed with 0 to
25 25
26### 0.1 Keymap status 26### 0.1 Keymap status
27Keymap has its state in two parameters: 27Keymap has its state in two parameters:
28**`default_layer`** indicates a base keymap layer(0-15) which is always valid and to be referred, **`keymap_stat`** is 16bit variable which has current on/off status of layers on its each bit. 28**`default_layer`** indicates a base keymap layer(0-31) which is always valid and to be referred, **`keymap_stat`** is 16bit variable which has current on/off status of layers on its each bit.
29 29
30Keymap layer '0' is usually `default_layer` and which is the only valid layer and other layers is initially off after boot up firmware, though, you can configured them in `config.h`. 30Keymap layer '0' is usually `default_layer` and which is the only valid layer and other layers is initially off after boot up firmware, though, you can configured them in `config.h`.
31To change `default_layer` will be useful when you want to switch key layout completely, say you use Colmak instead of Qwerty. 31To change `default_layer` will be useful when you switch key layout completely, say you want Colmak instead of Qwerty.
32 32
33 Initial state of Keymap Change base layout 33 Initial state of Keymap Change base layout
34 ----------------------- ------------------ 34 ----------------------- ------------------
35 35
36 15 15 36 31 31
37 14 14 37 30 30
38 13 13 38 29 29
39 : : 39 : :
40 3 3 ____________ 40 : : ____________
41 2 ____________ 2 / / 41 2 ____________ 2 / /
42 1 / / ,->1 /___________/ 42 1 / / ,->1 /___________/
43 ,->0 /___________/ | 0 43 ,->0 /___________/ | 0
44 | | 44 | |
45 `--- default_layer = 0 `--- default_layer = 1 45 `--- default_layer = 0 `--- default_layer = 1
46 keymap_stat = 0x0001 keymap_stat = 0x0002 46 layer_state = 0x00000001 layer_state = 0x00000002
47 47
48On the other hand, you shall change `keymap_state` to overlay base layer with some layers for feature such as navigation keys, function key(F1-F12), media keys or special actions. 48On the other hand, you shall change `layer_state` to overlay base layer with some layers for feature such as navigation keys, function key(F1-F12), media keys or special actions.
49 49
50 Overlay feature layer 50 Overlay feature layer
51 --------------------- bit|status 51 --------------------- bit|status
52 ____________ ---+------ 52 ____________ ---+------
53 15 / / 15 | 0 53 31 / / 31 | 0
54 14 /___________// -----> 14 | 1 54 30 /___________// -----> 30 | 1
55 13 /___________/ -----> 13 | 1 55 29 /___________/ -----> 29 | 1
56 : : | 56 : : | :
57 3 ____________ 3 | 0 57 : ____________ : | :
58 2 / / 2 | 0 58 2 / / 2 | 0
59 ,->1 /___________/ -----> 1 | 1 59 ,->1 /___________/ -----> 1 | 1
60 | 0 0 | 0 60 | 0 0 | 0
61 | | 61 | +
62 `--- default_layer = 1 | 62 `--- default_layer = 1 |
63 keymap_stat = 0x6002 <-----' 63 layer_state = 0x60000002 <-'
64 64
65 65
66 66
@@ -146,9 +146,9 @@ You can find other keymap definitions in file `keymap.c` located on project dire
146 }; 146 };
147 147
148 static const uint16_t PROGMEM fn_actions[] = { 148 static const uint16_t PROGMEM fn_actions[] = {
149 ACTION_KEYMAP_MOMENTARY(1), // FN0 149 ACTION_LAYER_MOMENTARY(1), // FN0
150 ACTION_KEYMAP_TAP_KEY(2, KC_SCLN), // FN1 150 ACTION_LAYER_TAP_KEY(2, KC_SCLN), // FN1
151 ACTION_KEYMAP_TOGGLE(2), // FN2 151 ACTION_LAYER_TOGGLE(2), // FN2
152 }; 152 };
153 153
154 154
@@ -192,7 +192,7 @@ There are 8 modifiers which has discrimination between left and right.
192- `KC_WSCH`, `KC_WHOM`, `KC_WBAK`, `KC_WFWD`, `KC_WSTP`, `KC_WREF`, `KC_WFAV` for web browser operation 192- `KC_WSCH`, `KC_WHOM`, `KC_WBAK`, `KC_WFWD`, `KC_WSTP`, `KC_WREF`, `KC_WFAV` for web browser operation
193 193
194### 1.5 Fn key 194### 1.5 Fn key
195`KC_FNnn` are keycodes for `Fn` key which not given any actions at the beginning unlike most of keycodes has its own inborn action. To use these keycodes in `KEYMAP` you need to assign action you want at first. Action of `Fn` key is defined in `fn_actions[]` and its index of the array is identical with number part of `KC_FNnn`. Thus `KC_FN0` keyocde indicates the action defined in first element of the array. ***32 `Fn` keys can be defined at most.*** 195`KC_FNnn` are keycodes for `Fn` key which not given any actions at the beginning unlike most of keycodes has its own inborn action. To use these keycodes in `KEYMAP()` you need to assign action you want at first. Action of `Fn` key is defined in `fn_actions[]` and its index of the array is identical with number part of `KC_FNnn`. Thus `KC_FN0` keyocde indicates the action defined in first element of the array. ***32 `Fn` keys can be defined at most.***
196 196
197### 1.6 Keycode Table 197### 1.6 Keycode Table
198 See keycode table in [`doc/keycode.txt`](./keycode.txt) for description of keycodes. 198 See keycode table in [`doc/keycode.txt`](./keycode.txt) for description of keycodes.
@@ -203,130 +203,158 @@ There are 8 modifiers which has discrimination between left and right.
203 203
204 204
205## 2. Action 205## 2. Action
206See [`common/action.h`](../common/action.h). Action is a **16bit code** and defines function to perform on events of a key like press, release, holding and tapping. 206See [`common/action_code.h`](../common/action_code.h). Action is a **16bit code** and defines function to perform on events of a key like press, release, holding and tapping.
207 207
208Most of keys just register 8bit scancode to host, but to support other complex features needs 16bit extended action codes internally. However, using 16bit action codes in keymap results in double size in memory against using jsut keycodes. To avoid this waste 8bit keycodes are used in `KEYMAP` instead of action codes. 208Most of keys just register 8bit scancode to host, but to support other complex features needs 16bit extended action codes internally. However, using 16bit action codes in keymap results in double size in memory compared to using jsut keycodes. To avoid this waste 8bit keycodes are used in `KEYMAP()` instead of action codes.
209 209
210***You can just use keycodes of `Normal key`, `Modifier`, `Mousekey` and `System & Media key` in keymap*** to indicate corresponding actions instead of using action codes. While ***to use other special actions you should use keycode of `Fn` key defined in `fn_actions[]`.*** 210***You can just use keycodes of `Normal key`, `Modifier`, `Mousekey` and `System & Media key` in keymap*** to indicate corresponding actions instead of using action codes. While ***to use other special actions you should use keycode of `Fn` key defined in `fn_actions[]`.***
211 211
212Usually action codes are needed only when you want to use layer switching, or
213 212
214### 2.1 Key action 213### 2.1 Key Action
215This is a simple action that registers scancodes(HID usage in fact) to host on press event of key and unregister on release. 214This is a simple action that registers scancodes(HID usage in fact) to host on press event of key and unregister on release.
216 215
216#### Parameters
217+ **mods**: { ` MOD_LCTL`, ` MOD_LSFT`, ` MOD_LALT`, ` MOD_LGUI`,
218 ` MOD_RCTL`, ` MOD_RSFT`, ` MOD_RALT`, ` MOD_RGUI` }
219+ **key**: keycode
220
221
217#### 2.1.1 Normal key and Modifier 222#### 2.1.1 Normal key and Modifier
218This action usually won't be used expressly because you can use keycodes in `KEYMAP()` instead. 223***This action usually won't be used expressly in keymap*** because you can just use keycodes in `KEYMAP()` instead.
219You can define `Key` action on *'A'* key and *'left shift'* modifier with: 224
225You can define these actions on *'A'* key and *'left shift'* modifier with:
220 226
221 ACTION_KEY(KC_A) 227 ACTION_KEY(KC_A)
222 ACTION_KEY(KC_LSHIFT) 228 ACTION_KEY(KC_LSFT)
223 229
224#### 2.1.2 Key with modifiers 230#### 2.1.2 Key with modifiers
225This action is comprised of strokes of modifiers and a key. `Macro` action is needed if you want more complex key strokes. 231This action is comprised of strokes of modifiers and a key. `Macro` action is needed if you want more complex key strokes.
232
226Say you want to assign a key to `Shift + 1` to get charactor *'!'* or `Alt + Tab` to switch application windows. 233Say you want to assign a key to `Shift + 1` to get charactor *'!'* or `Alt + Tab` to switch application windows.
227 234
228 ACTION_LMOD_KEY(KC_LSHIFT, KC_1) 235 ACTION_MODS_KEY(MOD_LSFT, KC_1)
229 ACTION_LMOD_KEY(KC_LALT, KC_TAB) 236 ACTION_MODS_KEY(MOD_LALT, KC_TAB)
237
238Or `Alt,Shift + Tab` can be defined. `ACTION_MODS_KEY(mods, key)` requires **4-bit modifier state** and a **keycode** as arguments. See `keycode.h` for `MOD_BIT()` macro.
239
240 ACTION_MODS_KEY(MOD_LALT | MOD_LSFT, KC_TAB)
241
242#### 2.1.3 Multiple Modifiers
243Registers multiple modifiers with pressing a key. To specify multiple modifiers use `|`.
244
245 ACTION_MODS(MOD_ALT | MOD_LSFT)
246
247#### 2.1.3 Modifier with tap key
248Works as a modifier key while holding, but registers a key on tap(press and release quickly).
230 249
231Or `Alt,Shift + Tab` can be defined. `ACTION_LMODS_KEY()` requires **4-bit modifier state** and a **keycode** as arguments. See `keycode.h` for `MOD_BIT()` macro.
232 250
233 ACTION_LMODS_KEY((MOD_BIT(KC_LALT) | MOD_BIT(KC_LSHIFT)), KC_TAB) 251 ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT)
234 252
235 253
236 254
237### 2.2 Layer Action 255### 2.2 Layer Action
238These actions operate layers of keymap. 256These actions operate layers of keymap.
239 257
240Parameters: 258#### Parameters
241- layer: 0-15 259You can specify a **target layer** of action and **when the action is executed**. Some actions take a **bit value** for bitwise operation.
242- on: { press | release | both }
243 260
244 261
245#### 2.2.0 Default Layer 262+ **layer**: `0`-`31`
246`default_layer` is layer which always is valid and referred to when actions is not defined on other layers. 263+ **on**: { `ON_PRESS` | `ON_RELEASE` | `ON_BOTH` }
264+ **bits**: 4-bit value and 1-bit mask bit
247 265
248##### Return to Default Layer
249Turns on only `default layer` with clearing other all layers.
250 266
251 ACTION_DEFAULT_LAYER 267#### 2.2.1 Default Layer
268Default Layer is a layer which always is valid and referred to when actions is not defined on other overlay layers.
252 269
253##### Set Default Layer 270This sets Default Layer to given parameter `layer` and activate it.
254Sets 'default layer' to layer and turn it on.
255 271
256 ACTION_DEFAULT_LAYER_SET_TO(layer) 272 ACTION_DEFAULT_LAYER(layer)
257 ACTION_DEFAULT_LAYER_SET(layer, on)
258 273
259 274
260#### 2.2.1 Keymap 275#### 2.2.2 Momentary Switch
261These actions operate layer status of keymap. 276Turns on `layer` momentarily while holding, in other words it activates when key is pressed and deactivate when released.
262 277
263##### Momentary Switch 278 ACTION_LAYER_MOMENTARY(layer)
264Turns on layer momentary while holding, in other words turn on when key is pressed and off when released.
265 279
266 ACTION_KEYMAP_MOMENTARY(layer)
267 280
281#### 2.2.3 Toggle Switch
282Turns on `layer` with first type(press and release) and turns off with next.
268 283
269##### Toggle Switch 284 ACTION_LAYER_TOGGLE(layer)
270Turns on layer on first type and turns off on next.
271 285
272 ACTION_KEYMAP_TOGGLE(layer)
273 286
287#### 2.2.4 Momentary Switch with tap key
288Turns on `layer` momentary while holding, but registers key on tap(press and release quickly).
274 289
275##### Momentary Switch with tap key 290 ACTION_LAYER_TAP_KEY(layer, key)
276Turns on layer momentary while holding but registers key on tap.
277 291
278 ACTION_KEYMAP_TAP_KEY(layer, key)
279 292
293#### 2.2.5 Momentary Switch with tap toggle
294Turns on `layer` momentary while holding and toggles it with serial taps.
280 295
281##### Momentary Switch with tap toggle 296 ACTION_LAYER_TAP_TOGGLE(layer)
282Turns on layer momentary while holding but toggles it with serial taps.
283 297
284 ACTION_KEYMAP_TAP_TOGGLE(layer)
285 298
299#### 2.2.6 Invert state of layer
300Inverts current state of `layer`. If the layer is on it becomes off with this action.
286 301
287##### Invert layer 302 ACTION_LAYER_INVERT(layer, on)
288Inverts current layer state. If the layer is on it becomes off with this action.
289 303
290 ACTION_KEYMAP_INV(layer, on)
291 304
292 305#### 2.2.7 Turn On layer
293##### Turn On layer
294Turns on layer state. 306Turns on layer state.
295 307
296 ACTION_KEYMAP_ON(layer, on) 308 ACTION_LAYER_ON(layer, on)
297 309
298Turns on layer state on press and turn off on release. This is identical to **'Switch to layer'** action. 310Turns on layer state on press and turns off on release.
299 311
300 ACTION_KEYMAP_ON_OFF(layer) 312 ACTION_LAYER_ON_OFF(layer)
301 313
302 314
303##### Turn Off layer 315#### 2.2.8 Turn Off layer
304Turns off layer state. 316Turns off layer state.
305 317
306 ACTION_KEYMAP_OFF(layer, on) 318 ACTION_LAYER_OFF(layer, on)
319
320Turns off layer state on press and activates on release.
321
322 ACTION_LAYER_OFF_ON(layer)
307 323
308 324
309##### Set layer 325#### 2.2.9 Set layer
310Turn on layer only. 326Turn on layer only.
311`keymap_stat = (1<<layer) [layer: 0-15]` 327`layer_state = (1<<layer) [layer: 0-31]`
312 328
313 ACTION_KEYMAP_SET(layer, on) 329 ACTION_LAYER_SET(layer, on)
314 330
315Turns on layer only and clear all layer on release.. 331Turns on layer only and clear all layer on release..
316 332
317 ACTION_KEYMAP_SET_CLEAR(layer) 333 ACTION_LAYER_SET_CLEAR(layer)
318 334
319 335
320#### 2.2.2 Overlay 336#### 2.2.10 Bitwise operation
321***TBD*** 337
338**part** indicates which part of 32bit layer state(0-7). **bits** is 5-bit value. **on** indicates when the action is executed.
339
340 ACTION_LAYER_BIT_AND(part, bits, on)
341 ACTION_LAYER_BIT_OR(part, bits, on)
342 ACTION_LAYER_BIT_XOR(part, bits, on)
343 ACTION_LAYER_BIT_SET(part, bits, on)
322 344
323In addition to actions of `Keymap` above these actions are also available. 345These actions works with prameters as following code.
324 346
325##### Invert 4bit layer states 347 uint8_t shift = part*4;
326Invert 4bits out of 16bits of overlay status on both press and release. 348 uint32_t mask = (bits&0x10) ? ~(0xf<<shift) : 0;
327`overlay_stat = (overlay_stat ^ bits<<(shift*4)) [bits: 0-15, shift: 0-3]` 349 uint32_t layer_state = layer_state <bitop> ((bits<<shift)|mask);
328 350
329 ACTION_OVERLAY_INV4(bits, shift) 351
352Default Layer also has bitwise operations, they are executed when key is released.
353
354 ACTION_DEFAULT_LAYER_BIT_AND(part, bits)
355 ACTION_DEFAULT_LAYER_BIT_OR(part, bits)
356 ACTION_DEFAULT_LAYER_BIT_XOR(part, bits)
357 ACTION_DEFAULT_LAYER_BIT_SET(part, bits)
330 358
331 359
332 360
@@ -355,6 +383,7 @@ Invert 4bits out of 16bits of overlay status on both press and release.
355See `keyboard/hhkb/keymap.c` for sample. 383See `keyboard/hhkb/keymap.c` for sample.
356 384
357 385
386
358### 2.4 Function action 387### 2.4 Function action
359***TBD*** 388***TBD***
360 389
@@ -403,88 +432,92 @@ See `keyboard/hhkb/keymap.c` for sample.
403 432
404 433
405 434
406## 4. Layer switching Example 435## 3. Layer switching Example
407There are some ways to switch layer with 'Layer' actions. 436There are some ways to switch layer with 'Layer' actions.
408 437
409### 4.1 Momentary switching 438### 3.1 Momentary switching
410Momentary switching changes layer only while holding Fn key. 439Momentary switching changes layer only while holding Fn key.
411 440
412This action makes 'Layer 1' active(valid) on key press event and inactive on release event. Namely you can overlay a layer on base layer temporarily with this. 441This action makes 'Layer 1' active(valid) on key press event and inactive on release event. Namely you can overlay a layer on lower layers or default layer temporarily with this action.
413 442
414 ACTION_KEYMAP_MOMENTARY(1) 443 ACTION_LAYER_MOMENTARY(1)
415 444
416 445
417After switch actions of destination layer are perfomed. 446Note that after switching on press the actions on destinaton layer(Layer 1) are perfomed.
418***Thus you shall need to place action to come back on destination layer***, or you will be stuck in destination layer without way to get back. Usually you need to palce same action or 'KC_TRNS` on destination layer to get back. 447***Thus you shall need to place an action to go back on destination layer***, or you will be stuck in destination layer without way to get back. Usually you need to palce same action or 'KC_TRNS` on destination layer to get back.
419 448
420 449
421### 4.2 Toggle switching 450### 3.2 Toggle switching
422Toggle switching changes layer after press then release. With this you can keep staying on the layer until you press the key again to return. 451Toggle switching performed after releasing a key. With this action you can keep staying on the destination layer until you type the key again to return.
423 452
424This is toggle action of 'Layer 2'. 453This performs toggle switching action of 'Layer 2'.
425 454
426 ACTION_KEYMAP_TOGGLE(2) 455 ACTION_LAYER_TOGGLE(2)
427 456
428 457
429 458
430### 4.3 Momentary switching with Tap key 459### 3.3 Momentary switching with Tap key
431These actions switch layer only while holding `Fn` key and register key on tap. **Tap** means to press and release key quickly. 460These actions switch a layer only while holding a key but register the key on tap. **Tap** means to press and release a key quickly.
432 461
433 ACTION_KEYMAP_TAP_KEY(2, KC_SCLN) 462 ACTION_LAYER_TAP_KEY(2, KC_SCLN)
434 463
435With this you can place layer switching function on normal key like ';' without losing its original key register function. 464With this you can place a layer switching action on normal key like ';' without losing its original key register function. This action allows you to have layer switchig action without necessity of a dedicated key. It means you can have it even on home row of keyboard.
436 465
437 466
438 467
439### 4.4 Momentary switching with Tap Toggle 468### 3.4 Momentary switching with Tap Toggle
440This switches layer only while holding `Fn` key and toggle layer after several taps. **Tap** means to press and release key quickly. 469This switches layer only while holding a key but toggle layer with several taps. **Tap** means to press and release key quickly.
441 470
442 ACTION_KEYMAP_TAP_TOGGLE(1) 471 ACTION_LAYER_TAP_TOGGLE(1)
443 472
444Number of taps can be defined with `TAPPING_TOGGLE` in `config.h`, `5` by default. 473Number of taps can be configured with `TAPPING_TOGGLE` in `config.h`, `5` by default.
445 474
446 475
447 476
448## Tapping 477## 4. Tapping
449Tapping is to press and release key quickly. Tapping speed is determined with setting of `TAPPING_TERM`, which can be defined in `config.h`, 200ms by default. 478Tapping is to press and release a key quickly. Tapping speed is determined with setting of `TAPPING_TERM`, which can be defined in `config.h`, 200ms by default.
450 479
451### Tap Key 480### 4.1 Tap Key
452This is feature to assign normal key action and modifier including `Fn` to just one physical key. This is a kind of [Dual role modifier][dual_role]. It works as modifier or `Fn` when holding a key but registers normal key when tapping. 481This is a feature to assign normal key action and modifier including layer switching to just same one physical key. This is a kind of [Dual role modifier][dual_role]. It works as modifier when holding the key but registers normal key when tapping.
453 482
454Action for modifier with tap key. 483Modifier with tap key:
455 484
456 ACTION_LMODS_TAP_KEY(mods, key) 485 ACTION_MODS_TAP_KEY(MOD_RSFT, KC_GRV)
457 486
458Action for `Fn` with tap key. 487Layer switching with tap key:
459 488
460 ACTION_KEYMAP_TAP_KEY(layer, key) 489 ACTION_LAYER_TAP_KEY(2, KC_SCLN)
461 490
462[dual_role]: http://en.wikipedia.org/wiki/Modifier_key#Dual-role_modifier_keys 491[dual_role]: http://en.wikipedia.org/wiki/Modifier_key#Dual-role_modifier_keys
463 492
464 493
465### Tap Toggle 494### 4.2 Tap Toggle
466This is feature to assign both toggle layer and momentary switch layer action to just one physical key. It works as mementary switch when holding a key but toggle switch when tapping. 495This is a feature to assign both toggle layer and momentary switch layer action to just same one physical key. It works as mementary layer switch when holding a key but toggle switch with several taps.
467 496
468 ACTION_KEYMAP_TAP_TOGGLE(layer) 497 ACTION_LAYER_TAP_TOGGLE(1)
469 498
470 499
471### One Shot Modifier 500### 4.3 One Shot Modifier
472This adds oneshot feature to modifier key. 'One Shot Modifier' is one time modifier which has effect only on following one alpha key. 501This adds oneshot feature to modifier key. 'One Shot Modifier' is one time modifier which has effect only on following just one key.
473It works as normal modifier key when holding but oneshot modifier when tapping. 502It works as normal modifier key when holding but oneshot modifier when tapping.
474 503
475 ACTION_LMODS_ONESHOT(mods) 504 ACTION_MODS_ONESHOT(MOD_LSFT)
476 505
477Say you want to type 'The', you have to push and hold Shift before type 't' then release Shift before type 'h' and 'e' or you'll get 'THe'. With One Shot Modifier you can tap Shift then type 't', 'h' and 'e' normally, you don't need to holding Shift key properly here. 506Say you want to type 'The', you have to push and hold Shift before type 't' then release Shift before type 'h' and 'e' or you'll get 'THe'. With One Shot Modifier you can tap Shift then type 't', 'h' and 'e' normally, you don't need to holding Shift key properly here.
478 507
479 508
480 509
481 510
482## Legacy Keymap 511## 5. Legacy Keymap
483This was used in prior version and still works due to legacy support code in `common/keymap.c`. Legacy keymap doesn't support many of features that new keymap offers. 512This was used in prior version and still works due to legacy support code in `common/keymap.c`. Legacy keymap doesn't support many of features that new keymap offers. ***It is not recommended to use Legacy Keymap for new project.***
484 513
485In comparison with new keymap how to define Fn key is different. It uses two arrays `fn_layer[]` and `fn_keycode[]`. The index of arrays corresponds with postfix number of `Fn` key. Array `fn_layer[]` indicates destination layer to switch and `fn_keycode[]` has keycodes to send when tapping `Fn` key. 514To enable Legacy Keymap support define this macro in `config.h`.
486 515
487In following setting example, `Fn0`, `Fn1` and `Fn2` switch layer to 1, 2 and 2 respectively. `Fn2` registers `Space` key when tap while `Fn0` and `Fn1` doesn't send any key. 516 #define USE_LEGACY_KEYMAP
517
518Legacy Keymap uses two arrays `fn_layer[]` and `fn_keycode[]` to define Fn key. The index of arrays corresponds with postfix number of `Fn` key. Array `fn_layer[]` indicates destination layer to switch and `fn_keycode[]` has keycodes to send when tapping `Fn` key.
519
520In following setting example, `Fn0`, `Fn1` and `Fn2` switch layer to 1, 2 and 2 respectively. `Fn2` registers `Space` key when tapping while `Fn0` and `Fn1` doesn't send any key.
488 521
489 static const uint8_t PROGMEM fn_layer[] = { 522 static const uint8_t PROGMEM fn_layer[] = {
490 1, // Fn0 523 1, // Fn0
@@ -499,16 +532,25 @@ In following setting example, `Fn0`, `Fn1` and `Fn2` switch layer to 1, 2 and 2
499 }; 532 };
500 533
501 534
502## Terminology 535## 6. Terminology
503- keymap 536***TBD***
504- layer 537### keymap
505- layout 538is comprised of multiple layers.
506- key 539### layer
507- keycode 540is matrix of keycodes.
508- scancode 541### key
509- action 542is physical button on keyboard or logical switch on software.
510- layer transparency 543### keycode
511- layer precedence 544is codes used on firmware.
512- register 545### action
513- tap 546is a function assigned on a key.
514- Fn key 547### layer transparency
548Using transparent keycode one layer can refer key definition on other lower layer.
549### layer precedence
550Top layer has higher precedence than lower layers.
551### tapping
552is to press and release a key quickly.
553### Fn key
554is key which executes a special action like layer switching, mouse key, macro or etc.
555### dual role modifier
556<http://en.wikipedia.org/wiki/Modifier_key#Dual-role_modifier_keys>
diff --git a/keyboard/gh60/config.h b/keyboard/gh60/config.h
index fbe587081..567b126b6 100644
--- a/keyboard/gh60/config.h
+++ b/keyboard/gh60/config.h
@@ -61,8 +61,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
61//#define NO_PRINT 61//#define NO_PRINT
62 62
63/* disable action features */ 63/* disable action features */
64//#define NO_ACTION_KEYMAP 64//#define NO_ACTION_LAYER
65//#define NO_ACTION_OVERLAY
66//#define NO_ACTION_TAPPING 65//#define NO_ACTION_TAPPING
67//#define NO_ACTION_ONESHOT 66//#define NO_ACTION_ONESHOT
68//#define NO_ACTION_MACRO 67//#define NO_ACTION_MACRO
diff --git a/keyboard/gh60/keymap.c b/keyboard/gh60/keymap.c
index d6af16961..edc1caf19 100644
--- a/keyboard/gh60/keymap.c
+++ b/keyboard/gh60/keymap.c
@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20#include "keycode.h" 20#include "keycode.h"
21#include "action.h" 21#include "action.h"
22#include "action_macro.h" 22#include "action_macro.h"
23#include "layer_switch.h"
24#include "report.h" 23#include "report.h"
25#include "host.h" 24#include "host.h"
26#include "print.h" 25#include "print.h"
@@ -91,7 +90,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
91 ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 90 ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
92 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ 91 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
93 LCTL,A, S, D, F, G, H, J, K, L, FN2, QUOT, ENT, \ 92 LCTL,A, S, D, F, G, H, J, K, L, FN2, QUOT, ENT, \
94 LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, RSFT, \ 93 LSFT,Z, X, C, V, B, N, M, COMM,DOT, FN1, FN9, \
95 LCTL,LGUI,LALT, SPC, RALT,FN3, FN3, FN0), 94 LCTL,LGUI,LALT, SPC, RALT,FN3, FN3, FN0),
96 /* Keymap 1: colemak */ 95 /* Keymap 1: colemak */
97 KEYMAP_ANSI( 96 KEYMAP_ANSI(
@@ -198,54 +197,38 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
198 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS), 197 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
199}; 198};
200 199
201static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {};
202
203/* 200/*
204 * Fn action definition 201 * Fn action definition
205 */ 202 */
206static const uint16_t PROGMEM fn_actions[] = { 203static const uint16_t PROGMEM fn_actions[] = {
207 [0] = ACTION_KEYMAP_MOMENTARY(4), 204 [0] = ACTION_LAYER_MOMENTARY(4),
208 [1] = ACTION_KEYMAP_TAP_KEY(5, KC_SLASH), 205 [1] = ACTION_LAYER_TAP_KEY(5, KC_SLASH),
209 [2] = ACTION_KEYMAP_TAP_KEY(6, KC_SCLN), 206 [2] = ACTION_LAYER_TAP_KEY(6, KC_SCLN),
210 [3] = ACTION_KEYMAP_MOMENTARY(6), 207 [3] = ACTION_LAYER_MOMENTARY(6),
211 [4] = ACTION_KEYMAP_MOMENTARY(7), // to Layout selector 208 [4] = ACTION_LAYER_MOMENTARY(7), // to Layout selector
212 [5] = ACTION_DEFAULT_LAYER_SET(0), // set qwerty layout 209 [5] = ACTION_DEFAULT_LAYER_SET(0), // set qwerty layout
213 [6] = ACTION_DEFAULT_LAYER_SET(1), // set colemak layout 210 [6] = ACTION_DEFAULT_LAYER_SET(1), // set colemak layout
214 [7] = ACTION_DEFAULT_LAYER_SET(2), // set dvorak layout 211 [7] = ACTION_DEFAULT_LAYER_SET(2), // set dvorak layout
215 [8] = ACTION_DEFAULT_LAYER_SET(3), // set workman layout 212 [8] = ACTION_DEFAULT_LAYER_SET(3), // set workman layout
213 [9] = ACTION_MODS_TAP_KEY(MOD_RSFT, KC_GRV),
216}; 214};
217#endif 215#endif
218 216
219 217
220 218
221#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) 219#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
222#define OVERLAYS_SIZE (sizeof(overlays) / sizeof(overlays[0]))
223#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) 220#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
224 221
225/* translates key to keycode */ 222/* translates key to keycode */
226uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) 223uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
227{ 224{
228 /* Overlay: 16-31(OVERLAY_BIT(0x10) | overlay_layer) */ 225 if (layer < KEYMAPS_SIZE) {
229 if (layer & OVERLAY_BIT) { 226 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
230 layer &= OVERLAY_MASK; 227 } else {
231 if (layer < OVERLAYS_SIZE) { 228 // XXX: this may cuaes bootlaoder_jump inconsistent fail.
232 return pgm_read_byte(&overlays[(layer)][(key.row)][(key.col)]); 229 //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n");
233 } else { 230 // fall back to layer 0
234 // XXX: this may cuaes bootlaoder_jump incositent fail. 231 return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
235 //debug("key_to_keycode: overlay "); debug_dec(layer); debug(" is invalid.\n");
236 return KC_TRANSPARENT;
237 }
238 }
239 /* Keymap: 0-15 */
240 else {
241 if (layer < KEYMAPS_SIZE) {
242 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
243 } else {
244 // XXX: this may cuaes bootlaoder_jump incositent fail.
245 //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n");
246 // fall back to layer 0
247 return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
248 }
249 } 232 }
250} 233}
251 234
diff --git a/keyboard/gh60/keymap_plain.h b/keyboard/gh60/keymap_plain.h
index 85331715d..52d11256c 100644
--- a/keyboard/gh60/keymap_plain.h
+++ b/keyboard/gh60/keymap_plain.h
@@ -1,10 +1,9 @@
1static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 1static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
2 /* Keymap 0: qwerty */ 2 /* 0: qwerty */
3 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 3 KEYMAP(ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
4 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ 4 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
5 CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,NO, ENT, \ 5 CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,NO, ENT, \
6 LSFT,NO, Z, X, C, V, B, N, M, COMM,DOT, SLSH,NO, RSFT, \ 6 LSFT,NO, Z, X, C, V, B, N, M, COMM,DOT, SLSH,NO, RSFT, \
7 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL), 7 LCTL,LGUI,LALT, SPC, RALT,RGUI,APP, RCTL),
8}; 8};
9static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {};
10static const uint16_t PROGMEM fn_actions[] = {}; 9static const uint16_t PROGMEM fn_actions[] = {};
diff --git a/keyboard/gh60/keymap_poker.h b/keyboard/gh60/keymap_poker.h
index 3e0921ad9..164299949 100644
--- a/keyboard/gh60/keymap_poker.h
+++ b/keyboard/gh60/keymap_poker.h
@@ -1,49 +1,47 @@
1static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 1static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
2 /* Keymap 0: qwerty */ 2 /* 0: qwerty */
3 KEYMAP_ANSI( 3 KEYMAP_ANSI(
4 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 4 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
5 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ 5 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
6 CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ 6 CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \
7 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \ 7 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \
8 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), 8 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
9 /* Keymap 1: colemak */ 9 /* 1: colemak */
10 KEYMAP_ANSI( 10 KEYMAP_ANSI(
11 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 11 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
12 TAB, Q, W, F, P, G, J, L, U, Y, SCLN,LBRC,RBRC,BSLS, \ 12 TAB, Q, W, F, P, G, J, L, U, Y, SCLN,LBRC,RBRC,BSLS, \
13 BSPC,A, R, S, T, D, H, N, E, I, O, QUOT, ENT, \ 13 BSPC,A, R, S, T, D, H, N, E, I, O, QUOT, ENT, \
14 LSFT,Z, X, C, V, B, K, M, COMM,DOT, SLSH, RSFT, \ 14 LSFT,Z, X, C, V, B, K, M, COMM,DOT, SLSH, RSFT, \
15 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), 15 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
16 /* Keymap 2: dvorak */ 16 /* 2: dvorak */
17 KEYMAP_ANSI( 17 KEYMAP_ANSI(
18 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, \ 18 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, LBRC,RBRC,BSPC, \
19 TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, \ 19 TAB, QUOT,COMM,DOT, P, Y, F, G, C, R, L, SLSH,EQL, BSLS, \
20 CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, \ 20 CAPS,A, O, E, U, I, D, H, T, N, S, MINS, ENT, \
21 LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, \ 21 LSFT,SCLN,Q, J, K, X, B, M, W, V, Z, RSFT, \
22 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), 22 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
23 /* Keymap: workman */ 23 /* 3: workman */
24 KEYMAP_ANSI( 24 KEYMAP_ANSI(
25 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 25 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
26 TAB, Q, D, R, W, B, J, F, U, P, SCLN,LBRC,RBRC,BSLS, \ 26 TAB, Q, D, R, W, B, J, F, U, P, SCLN,LBRC,RBRC,BSLS, \
27 BSPC,A, S, H, T, G, Y, N, E, O, I, QUOT, ENT, \ 27 BSPC,A, S, H, T, G, Y, N, E, O, I, QUOT, ENT, \
28 LSFT,Z, X, M, C, V, K, L, COMM,DOT, SLSH, RSFT, \ 28 LSFT,Z, X, M, C, V, K, L, COMM,DOT, SLSH, RSFT, \
29 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), 29 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
30}; 30 /* 4: Poker with Arrow */
31static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {
32 /* Overlay 0: Poker with Arrow */
33 KEYMAP_ANSI( 31 KEYMAP_ANSI(
34 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 32 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
35 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 33 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
36 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 34 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
37 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ 35 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \
38 TRNS,TRNS,TRNS, TRNS, TRNS,LEFT,DOWN,RGHT), 36 TRNS,TRNS,TRNS, TRNS, TRNS,LEFT,DOWN,RGHT),
39 /* Overlay 1: Poker with Esc */ 37 /* 5: Poker with Esc */
40 KEYMAP_ANSI( 38 KEYMAP_ANSI(
41 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 39 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
42 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 40 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
43 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 41 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
44 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 42 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
45 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS), 43 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
46 /* Overlay 2: Poker Fn 44 /* 6: Poker Fn
47 * ,-----------------------------------------------------------. 45 * ,-----------------------------------------------------------.
48 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| | 46 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| |
49 * |-----------------------------------------------------------| 47 * |-----------------------------------------------------------|
@@ -66,7 +64,7 @@ static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {
66 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \ 64 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN3, END, TRNS, \
67 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ 65 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \
68 TRNS,TRNS,TRNS, FN1, TRNS,TRNS,TRNS,TRNS), 66 TRNS,TRNS,TRNS, FN1, TRNS,TRNS,TRNS,TRNS),
69 /* Overlay 3: Layout selector 67 /* 7: Layout selector
70 * ,-----------------------------------------------------------. 68 * ,-----------------------------------------------------------.
71 * | Lq| Lc| Ld| Lw| | | | | | | | | | | 69 * | Lq| Lc| Ld| Lw| | | | | | | | | | |
72 * |-----------------------------------------------------------| 70 * |-----------------------------------------------------------|
@@ -92,11 +90,11 @@ static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {
92}; 90};
93static const uint16_t PROGMEM fn_actions[] = { 91static const uint16_t PROGMEM fn_actions[] = {
94 /* Poker Layout */ 92 /* Poker Layout */
95 [0] = ACTION_OVERLAY_MOMENTARY(2), // to Fn overlay 93 [0] = ACTION_LAYER_MOMENTARY(6), // to Fn overlay
96 [1] = ACTION_OVERLAY_TOGGLE(0), // toggle arrow overlay 94 [1] = ACTION_LAYER_TOGGLE(4), // toggle arrow overlay
97 [2] = ACTION_OVERLAY_TOGGLE(1), // toggle Esc overlay 95 [2] = ACTION_LAYER_TOGGLE(5), // toggle Esc overlay
98 [3] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // Task(RControl,RShift+Esc) 96 [3] = ACTION_MODS_KEY(MOD_RCTL|MOD_RSFT, KC_ESC), // Task(RControl,RShift+Esc)
99 [4] = ACTION_OVERLAY_MOMENTARY(3), // to Layout selector 97 [4] = ACTION_LAYER_MOMENTARY(7), // to Layout selector
100 [5] = ACTION_DEFAULT_LAYER_SET(0), // set qwerty layout 98 [5] = ACTION_DEFAULT_LAYER_SET(0), // set qwerty layout
101 [6] = ACTION_DEFAULT_LAYER_SET(1), // set colemak layout 99 [6] = ACTION_DEFAULT_LAYER_SET(1), // set colemak layout
102 [7] = ACTION_DEFAULT_LAYER_SET(2), // set dvorak layout 100 [7] = ACTION_DEFAULT_LAYER_SET(2), // set dvorak layout
diff --git a/keyboard/gh60/keymap_poker_bit.h b/keyboard/gh60/keymap_poker_bit.h
index 982632d05..1b498351d 100644
--- a/keyboard/gh60/keymap_poker_bit.h
+++ b/keyboard/gh60/keymap_poker_bit.h
@@ -2,37 +2,35 @@
2// Fn + Esc = ` 2// Fn + Esc = `
3// Fn + {left, down, up, right} = {home, pgdown, pgup, end} 3// Fn + {left, down, up, right} = {home, pgdown, pgup, end}
4static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 4static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
5 /* Keymap 0: qwerty */ 5 /* 0: qwerty */
6 KEYMAP_ANSI( 6 KEYMAP_ANSI(
7 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 7 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
8 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ 8 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
9 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ 9 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \
10 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \ 10 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \
11 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), 11 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
12}; 12 /* 4: Poker Default + Fn'd */
13static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = { 13 [4] = KEYMAP_ANSI(
14 /* Overlay 0: Poker Default + Fn'd */
15 KEYMAP_ANSI(
16 TRNS,F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ 14 TRNS,F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
17 CAPS,FN2, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ 15 CAPS,FN2, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
18 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN4, END, TRNS, \ 16 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN4, END, TRNS, \
19 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ 17 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \
20 TRNS,TRNS,TRNS, FN1, TRNS,TRNS,TRNS,TRNS), 18 TRNS,TRNS,TRNS, FN1, TRNS,TRNS,TRNS,TRNS),
21 /* Overlay 1: Poker with Arrow */ 19 /* 5: Poker with Arrow */
22 KEYMAP_ANSI( 20 KEYMAP_ANSI(
23 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 21 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
24 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 22 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
25 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 23 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
26 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, PGUP, \ 24 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, PGUP, \
27 TRNS,TRNS,TRNS, TRNS, FN3, HOME,PGDN,END), 25 TRNS,TRNS,TRNS, TRNS, FN3, HOME,PGDN,END),
28 /* Overlay 2: Poker with Esc */ 26 /* 6: Poker with Esc */
29 KEYMAP_ANSI( 27 KEYMAP_ANSI(
30 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 28 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
31 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 29 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
32 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 30 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
33 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 31 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
34 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS), 32 TRNS,TRNS,TRNS, TRNS, TRNS,TRNS,TRNS,TRNS),
35 /* Overlay 3: Poker with Arrow + Fn'd */ 33 /* 7: Poker with Arrow + Fn'd */
36 KEYMAP_ANSI( 34 KEYMAP_ANSI(
37 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 35 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
38 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 36 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
@@ -42,9 +40,9 @@ static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {
42}; 40};
43static const uint16_t PROGMEM fn_actions[] = { 41static const uint16_t PROGMEM fn_actions[] = {
44 /* Poker Layout */ 42 /* Poker Layout */
45 [0] = ACTION_OVERLAY_INV4(0b0101, 0), // Poker Fn(with fix for Esc) 43 [0] = ACTION_LAYER_BIT_XOR(1, 0b0101, ON_BOTH), // Poker Fn(with fix for Esc)
46 [1] = ACTION_OVERLAY_TOGGLE(1), // Poker Arrow toggle 44 [1] = ACTION_LAYER_TOGGLE(5), // Poker Arrow toggle
47 [2] = ACTION_OVERLAY_TOGGLE(2), // Poker Esc toggle 45 [2] = ACTION_LAYER_TOGGLE(6), // Poker Esc toggle
48 [3] = ACTION_OVERLAY_INV4(0b1101, 0), // Poker Fn(with fix for Arrow) 46 [3] = ACTION_LAYER_BIT_XOR(1, 0b1101, ON_BOTH), // Poker Fn(with fix for Arrow)
49 [4] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN3 Task(RControl,RShift+Esc) 47 [4] = ACTION_MODS_KEY(MOD_RCTL|MOD_RSFT, KC_ESC), // FN3 Task(RControl,RShift+Esc)
50}; 48};
diff --git a/keyboard/gh60/keymap_poker_set.h b/keyboard/gh60/keymap_poker_set.h
index eaaf3159d..e1e4d80ee 100644
--- a/keyboard/gh60/keymap_poker_set.h
+++ b/keyboard/gh60/keymap_poker_set.h
@@ -2,58 +2,56 @@
2// Fn + Esc = ` 2// Fn + Esc = `
3// Fn + {left, down, up, right} = {home, pgdown, pgup, end} 3// Fn + {left, down, up, right} = {home, pgdown, pgup, end}
4static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 4static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
5 /* Keymap 0: qwerty */ 5 /* 0: qwerty */
6 KEYMAP_ANSI( 6 KEYMAP_ANSI(
7 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \ 7 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, \
8 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \ 8 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, \
9 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \ 9 LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT, \
10 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \ 10 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH, RSFT, \
11 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL), 11 LCTL,LGUI,LALT, SPC, FN0, RGUI,APP, RCTL),
12}; 12 /* 1: Poker with Arrow */
13static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {
14 /* Overlay 0: Poker with Arrow */
15 KEYMAP_ANSI( 13 KEYMAP_ANSI(
16 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 14 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
17 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 15 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
18 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 16 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
19 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ 17 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \
20 TRNS,TRNS,TRNS, TRNS, FN1, LEFT,DOWN,RGHT), 18 TRNS,TRNS,TRNS, TRNS, FN1, LEFT,DOWN,RGHT),
21 /* Overlay 1: Poker with Esc */ 19 /* 2: Poker with Esc */
22 KEYMAP_ANSI( 20 KEYMAP_ANSI(
23 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 21 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
24 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 22 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
25 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 23 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
26 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 24 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
27 TRNS,TRNS,TRNS, TRNS, FN2, TRNS,TRNS,TRNS), 25 TRNS,TRNS,TRNS, TRNS, FN2, TRNS,TRNS,TRNS),
28 /* Overlay 2: Poker with Arrow and Esc */ 26 /* 3: Poker with Arrow and Esc */
29 KEYMAP_ANSI( 27 KEYMAP_ANSI(
30 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 28 ESC, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
31 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \ 29 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, \
32 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \ 30 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, TRNS, \
33 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \ 31 TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS, UP, \
34 TRNS,TRNS,TRNS, TRNS, FN3, LEFT,DOWN,RGHT), 32 TRNS,TRNS,TRNS, TRNS, FN3, LEFT,DOWN,RGHT),
35 /* Overlay 3: Poker Fn'd */ 33 /* 4: Poker Fn'd */
36 KEYMAP_ANSI( 34 KEYMAP_ANSI(
37 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ 35 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
38 TRNS,FN6, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ 36 TRNS,FN6, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
39 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \ 37 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \
40 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ 38 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \
41 TRNS,TRNS,TRNS, FN5, FN4, TRNS,TRNS,TRNS), 39 TRNS,TRNS,TRNS, FN5, FN4, TRNS,TRNS,TRNS),
42 /* Overlay 4: Poker Fn'd arrow */ 40 /* 5: Poker Fn'd arrow */
43 KEYMAP_ANSI( 41 KEYMAP_ANSI(
44 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ 42 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
45 TRNS,FN7, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ 43 TRNS,FN7, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
46 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \ 44 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \
47 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, PGUP, \ 45 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, PGUP, \
48 TRNS,TRNS,TRNS, FN4, FN5, HOME,PGDN,END), 46 TRNS,TRNS,TRNS, FN4, FN5, HOME,PGDN,END),
49 /* Overlay 5: Poker Fn'd Esc */ 47 /* 6: Poker Fn'd Esc */
50 KEYMAP_ANSI( 48 KEYMAP_ANSI(
51 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ 49 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
52 TRNS,FN4, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ 50 TRNS,FN4, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
53 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \ 51 TRNS,LEFT,DOWN,RGHT,TRNS,TRNS,PSCR,SLCK,PAUS,TRNS,FN8, END, TRNS, \
54 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \ 52 TRNS,DEL, TRNS,WHOM,MUTE,VOLU,VOLD,TRNS,PGUP,PGDN,DEL, TRNS, \
55 TRNS,TRNS,TRNS, FN7, FN6, TRNS,TRNS,TRNS), 53 TRNS,TRNS,TRNS, FN7, FN6, TRNS,TRNS,TRNS),
56 /* Overlay 6: Poker Fn'd Arrow + Esc */ 54 /* 7: Poker Fn'd Arrow + Esc */
57 KEYMAP_ANSI( 55 KEYMAP_ANSI(
58 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \ 56 GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, TRNS, \
59 TRNS,FN5, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \ 57 TRNS,FN5, UP, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,CALC,TRNS,HOME,INS, TRNS, \
@@ -67,15 +65,16 @@ static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {
67 */ 65 */
68static const uint16_t PROGMEM fn_actions[] = { 66static const uint16_t PROGMEM fn_actions[] = {
69 /* Poker Layout */ 67 /* Poker Layout */
70 [0] = ACTION_OVERLAY_SET(3, ON_PRESS), // FN0 move to Fn'd when press 68 [0] = ACTION_LAYER_SET(4, ON_PRESS), // FN0 move to Fn'd when press
71 [1] = ACTION_OVERLAY_SET(4, ON_PRESS), // FN1 move to Fn'd arrow when press 69 [1] = ACTION_LAYER_SET(5, ON_PRESS), // FN1 move to Fn'd arrow when press
72 [2] = ACTION_OVERLAY_SET(5, ON_PRESS), // FN2 move to Fn'd Esc when press 70 [2] = ACTION_LAYER_SET(6, ON_PRESS), // FN2 move to Fn'd Esc when press
73 [3] = ACTION_OVERLAY_SET(6, ON_PRESS), // FN3 move to Fn'd arrow + Esc when press 71 [3] = ACTION_LAYER_SET(7, ON_PRESS), // FN3 move to Fn'd arrow + Esc when press
74 72
75 [4] = ACTION_OVERLAY_CLEAR(ON_RELEASE), // FN4 clear overlay when release 73 //[4] = ACTION_LAYER_CLEAR(ON_RELEASE), // FN4 clear overlay when release
76 [5] = ACTION_OVERLAY_SET(0, ON_RELEASE), // FN5 move to arrow when release 74 [4] = ACTION_LAYER_SET(0, ON_RELEASE), // FN4 clear overlay when release
77 [6] = ACTION_OVERLAY_SET(1, ON_RELEASE), // FN6 move to Esc when release 75 [5] = ACTION_LAYER_SET(1, ON_RELEASE), // FN5 move to arrow when release
78 [7] = ACTION_OVERLAY_SET(2, ON_RELEASE), // FN7 move to arrow + Esc when release 76 [6] = ACTION_LAYER_SET(2, ON_RELEASE), // FN6 move to Esc when release
77 [7] = ACTION_LAYER_SET(3, ON_RELEASE), // FN7 move to arrow + Esc when release
79 78
80 [8] = ACTION_RMODS_KEY(MOD_BIT(KC_RCTL)|MOD_BIT(KC_RSFT), KC_ESC), // FN8 Task(RControl,RShift+Esc) 79 [8] = ACTION_MODS_KEY(MOD_RCTL|MOD_RSFT, KC_ESC), // FN8 Task(RControl,RShift+Esc)
81}; 80};
diff --git a/keyboard/hhkb/config.h b/keyboard/hhkb/config.h
index 6e26edbef..9df86126e 100644
--- a/keyboard/hhkb/config.h
+++ b/keyboard/hhkb/config.h
@@ -74,8 +74,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
74//#define NO_PRINT 74//#define NO_PRINT
75 75
76/* disable action features */ 76/* disable action features */
77//#define NO_ACTION_KEYMAP 77//#define NO_ACTION_LAYER
78//#define NO_ACTION_OVERLAY
79//#define NO_ACTION_TAPPING 78//#define NO_ACTION_TAPPING
80//#define NO_ACTION_ONESHOT 79//#define NO_ACTION_ONESHOT
81//#define NO_ACTION_MACRO 80//#define NO_ACTION_MACRO
diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c
index 094d33af1..7afbdbec2 100644
--- a/keyboard/hhkb/keymap.c
+++ b/keyboard/hhkb/keymap.c
@@ -186,17 +186,14 @@ enum macro_id {
186 * Fn action definition 186 * Fn action definition
187 */ 187 */
188static const uint16_t PROGMEM fn_actions[] = { 188static const uint16_t PROGMEM fn_actions[] = {
189 [0] = ACTION_DEFAULT_LAYER, // Default layer(not used) 189 [0] = ACTION_DEFAULT_LAYER_SET(0), // Default layer(not used)
190// [1] = ACTION_KEYMAP(1), // HHKB layer 190 [1] = ACTION_LAYER_TAP_TOGGLE(1), // HHKB layer(toggle with 5 taps)
191 [1] = ACTION_KEYMAP_TAP_TOGGLE(1), // HHKB layer(toggle with 5 taps) 191 [2] = ACTION_LAYER_TAP_KEY(2, KC_SLASH), // Cursor layer with Slash*
192 [2] = ACTION_KEYMAP_TAP_KEY(2, KC_SLASH), // Cursor layer with Slash* 192 [3] = ACTION_LAYER_TAP_KEY(3, KC_SCLN), // Mousekey layer with Semicolon*
193 [3] = ACTION_KEYMAP_TAP_KEY(3, KC_SCLN), // Mousekey layer with Semicolon* 193 [4] = ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT), // RControl with tap Enter*
194 [4] = ACTION_RMOD_TAP_KEY(KC_RCTL, KC_ENT), // RControl with tap Enter* 194 [5] = ACTION_MODS_ONESHOT(MOD_LSFT), // Oneshot Shift*
195 [5] = ACTION_LMOD_ONESHOT(KC_LSFT), // Oneshot Shift* 195 [6] = ACTION_LAYER_TAP_KEY(5, KC_SPC), // Mousekey layer with Space
196// [6] = ACTION_KEYMAP_TAP_KEY(4, KC_SPC), // Half-qwerty layer with Space 196 [7] = ACTION_LAYER_TOGGLE(3), // Mousekey layer(toggle)
197 [6] = ACTION_KEYMAP_TAP_KEY(5, KC_SPC), // Mousekey layer with Space
198// [7] = ACTION_KEYMAP(3), // Mousekey layer
199 [7] = ACTION_KEYMAP_TOGGLE(3), // Mousekey layer(toggle)
200 197
201// [8] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // LControl with tap Backspace 198// [8] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_BSPC), // LControl with tap Backspace
202// [9] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_ESC), // LControl with tap Esc 199// [9] = ACTION_LMOD_TAP_KEY(KC_LCTL, KC_ESC), // LControl with tap Esc
diff --git a/keyboard/hid_liber/keymap.c b/keyboard/hid_liber/keymap.c
index f3d6bfa2e..609edb5e1 100644
--- a/keyboard/hid_liber/keymap.c
+++ b/keyboard/hid_liber/keymap.c
@@ -24,7 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24#include "keycode.h" 24#include "keycode.h"
25#include "action.h" 25#include "action.h"
26#include "action_macro.h" 26#include "action_macro.h"
27#include "layer_switch.h"
28#include "report.h" 27#include "report.h"
29#include "host.h" 28#include "host.h"
30#include "print.h" 29#include "print.h"
@@ -160,8 +159,6 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
160 159
161}; 160};
162 161
163static const uint8_t PROGMEM overlays[][MATRIX_ROWS][MATRIX_COLS] = {};
164
165/* 162/*
166 * Fn action definition 163 * Fn action definition
167 */ 164 */
@@ -179,33 +176,15 @@ static const uint16_t PROGMEM fn_actions[] = {
179#endif 176#endif
180 177
181#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0])) 178#define KEYMAPS_SIZE (sizeof(keymaps) / sizeof(keymaps[0]))
182#define OVERLAYS_SIZE (sizeof(overlays) / sizeof(overlays[0]))
183#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0])) 179#define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
184 180
185/* translates key to keycode */ 181/* translates key to keycode */
186uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) 182uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
187{ 183{
188 /* Overlay: 16-31(OVERLAY_BIT(0x10) | overlay_layer) */ 184 if (layer < KEYMAPS_SIZE) {
189 if (layer & OVERLAY_BIT) { 185 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
190 layer &= OVERLAY_MASK; 186 } else {
191 if (layer < OVERLAYS_SIZE) { 187 return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
192 return pgm_read_byte(&overlays[(layer)][(key.row)][(key.col)]);
193 } else {
194 // XXX: this may cuaes bootlaoder_jump incositent fail.
195 //debug("key_to_keycode: overlay "); debug_dec(layer); debug(" is invalid.\n");
196 return KC_TRANSPARENT;
197 }
198 }
199 /* Keymap: 0-15 */
200 else {
201 if (layer < KEYMAPS_SIZE) {
202 return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
203 } else {
204 // XXX: this may cuaes bootlaoder_jump incositent fail.
205 //debug("key_to_keycode: base "); debug_dec(layer); debug(" is invalid.\n");
206 // fall back to layer 0
207 return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
208 }
209 } 188 }
210} 189}
211 190