6 #include "layer_switch.h"
10 * Default Layer (0-15)
12 uint8_t default_layer = 0;
14 void default_layer_set(uint8_t layer)
16 debug("default_layer_set: ");
17 debug_dec(default_layer); debug(" to ");
19 default_layer = layer;
21 debug_dec(default_layer); debug("\n");
23 clear_keyboard_but_mods(); // To avoid stuck keys
27 #ifndef NO_ACTION_KEYMAP
31 uint16_t keymap_stat = 0;
33 /* return highest layer whose state is on */
34 uint8_t keymap_get_layer(void)
36 return biton16(keymap_stat);
39 static void keymap_stat_set(uint16_t stat)
42 keymap_debug(); debug(" to ");
46 keymap_debug(); debug("\n");
48 clear_keyboard_but_mods(); // To avoid stuck keys
51 void keymap_clear(void)
57 void keymap_set(uint16_t stat)
59 keymap_stat_set(stat);
62 void keymap_move(uint8_t layer)
64 keymap_stat_set(1<<layer);
67 void keymap_on(uint8_t layer)
69 keymap_stat_set(keymap_stat | (1<<layer));
72 void keymap_off(uint8_t layer)
74 keymap_stat_set(keymap_stat & ~(1<<layer));
77 void keymap_invert(uint8_t layer)
79 keymap_stat_set(keymap_stat ^ (1<<layer));
82 void keymap_or(uint16_t stat)
84 keymap_stat_set(keymap_stat | stat);
86 void keymap_and(uint16_t stat)
88 keymap_stat_set(keymap_stat & stat);
90 void keymap_xor(uint16_t stat)
92 keymap_stat_set(keymap_stat ^ stat);
95 void keymap_debug(void)
97 debug_hex16(keymap_stat); debug("("); debug_dec(keymap_get_layer()); debug(")");
103 #ifndef NO_ACTION_OVERLAY
105 * Overlay Layer (16-31 = 0-15|0x10)
107 uint16_t overlay_stat = 0;
109 /* return highest layer whose state is on */
110 uint8_t overlay_get_layer(void)
112 return biton16(overlay_stat);
115 static void overlay_stat_set(uint16_t stat)
118 overlay_debug(); debug(" to ");
122 overlay_debug(); debug("\n");
124 clear_keyboard_but_mods(); // To avoid stuck keys
127 void overlay_clear(void)
133 void overlay_set(uint16_t stat)
135 overlay_stat_set(stat);
138 void overlay_move(uint8_t layer)
140 overlay_stat_set(1<<layer);
143 void overlay_on(uint8_t layer)
145 overlay_stat_set(overlay_stat | (1<<layer));
148 void overlay_off(uint8_t layer)
150 overlay_stat_set(overlay_stat & ~(1<<layer));
153 void overlay_invert(uint8_t layer)
155 overlay_stat_set(overlay_stat ^ (1<<layer));
158 void overlay_or(uint16_t stat)
160 overlay_stat_set(overlay_stat | stat);
162 void overlay_and(uint16_t stat)
164 overlay_stat_set(overlay_stat & stat);
166 void overlay_xor(uint16_t stat)
168 overlay_stat_set(overlay_stat ^ stat);
171 void overlay_debug(void)
173 debug_hex16(overlay_stat); debug("("); debug_dec(overlay_get_layer()); debug(")");
177 action_t layer_switch_get_action(key_t key)
180 action.code = ACTION_TRANSPARENT;
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) {
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) {
207 action = action_for_key(default_layer, key);