]> git.gir.st - tmk_keyboard.git/blob - common/layer_switch.c
Replace layer_stack with layer_switch
[tmk_keyboard.git] / common / layer_switch.c
1 #include <stdint.h>
2 #include "keyboard.h"
3 #include "action.h"
4 #include "debug.h"
5 #include "layer_switch.h"
6
7
8 uint16_t layer_switch_stat = 0;
9
10
11 uint16_t layer_switch_stat_get(void)
12 {
13 return layer_switch_stat;
14 }
15
16 void layer_switch_stat_set(uint16_t stat)
17 {
18 layer_switch_stat = stat;
19 layer_switch_debug();
20 }
21
22 void layer_switch_clear(void)
23 {
24 layer_switch_stat = 0;
25 layer_switch_debug();
26 }
27
28 void layer_switch_on(uint8_t layer)
29 {
30 layer_switch_stat |= (1<<layer);
31 layer_switch_debug();
32 }
33
34 void layer_switch_off(uint8_t layer)
35 {
36 layer_switch_stat &= ~(1<<layer);
37 layer_switch_debug();
38 }
39
40 void layer_switch_inv(uint8_t layer)
41 {
42 layer_switch_stat ^= (1<<layer);
43 layer_switch_debug();
44 }
45
46 void layer_switch_debug(void)
47 {
48 debug("layer_switch_stat: "); debug_bin16(layer_switch_stat); debug("\n");
49 }
50
51 action_t layer_switch_get_action(key_t key)
52 {
53 action_t action;
54 action.code = ACTION_TRANSPARENT;
55
56 /* higher layer first */
57 for (int8_t i = 15; i >= 0; i--) {
58 if (layer_switch_stat & (1<<i)) {
59 action = action_for_key(i, key);
60 if (action.code != ACTION_TRANSPARENT) {
61 layer_switch_debug();
62 debug("layer_switch: used. "); debug_dec(i); debug("\n");
63 return action;
64 }
65 }
66 }
67 return action;
68 }
Imprint / Impressum