1 #include "keymap_skel.h"
2 #include "usb_keyboard.h"
8 * LAYER_ENTER_DELAY: prevent from moving new layer
10 * Fn key sate ____|~~~~~~~~~~~~~~~~~~~|_______________
12 * enter_delay |======|
14 * Layer sw ___________|~~~~~~~~~~~~|_______________
16 #define LAYER_ENTER_DELAY 10
19 * LAYER_SEND_FN_TERM: send keycode if release key in this term
21 * Fn key state ____|~~~~~~~~~~~~~|_______________
22 * press | release(not send)
23 * Fn key state ____|~~~~~~~~~~~~~|~~~~~~|__________
25 * send_fn_term |=============o==| x
27 #define LAYER_SEND_FN_TERM 30
30 static uint8_t current_layer = 0;
31 static bool layer_used = false;
34 uint8_t layer_get_keycode(uint8_t row, uint8_t col)
36 uint8_t code = keymap_get_keycode(current_layer, row, col);
37 // normal key or mouse key
38 if ((IS_KEY(code) || IS_MOUSE(code)))
43 void layer_switching(uint8_t fn_bits)
46 static uint8_t last_bits = 0;
47 static uint8_t last_mod = 0;
48 static uint16_t last_timer = 0;
52 if (fn_bits == last_bits) {
53 // switch layer when specific time elapsed
54 if (current_layer != keymap_fn_layer(fn_bits) &&
55 timer_elapsed(last_timer) > LAYER_ENTER_DELAY) {
56 current_layer = keymap_fn_layer(fn_bits);
57 debug("time_elapsed: "); debug_hex16(timer_elapsed(last_timer)); debug("\n");
58 debug("switch layer: "); debug_hex(current_layer); debug("\n");
60 } else if (fn_bits == 0) {
61 // send key when Fn key is released without using the layer and within specific time
62 if ((!layer_used || current_layer != keymap_fn_layer(last_bits)) &&
63 timer_elapsed(last_timer) < LAYER_SEND_FN_TERM) {
64 uint8_t code = keymap_fn_keycode(last_bits);
67 keyboard_modifier_keys = last_mod | MOD_BIT(code);
69 keyboard_keys[0] = code;
70 keyboard_modifier_keys = last_mod;
80 current_layer = 0; // default layer
81 } else if ((fn_bits & (fn_bits - 1)) == 0) {
82 // switch layer when just one Fn Key is pressed
83 if (!usb_keyboard_has_key()) {
85 last_mod = keyboard_modifier_keys;
86 last_timer = timer_read();
87 debug("last_bits: "); debug_bin(last_bits); debug("\n");
88 debug("last_mod: "); debug_hex(last_mod); debug("\n");
89 debug("last_timer: "); debug_hex16(last_timer); debug("\n");