aboutsummaryrefslogtreecommitdiff
path: root/common/layer_switch.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/layer_switch.c')
-rw-r--r--common/layer_switch.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/common/layer_switch.c b/common/layer_switch.c
new file mode 100644
index 000000000..9bc804e64
--- /dev/null
+++ b/common/layer_switch.c
@@ -0,0 +1,68 @@
1#include <stdint.h>
2#include "keyboard.h"
3#include "action.h"
4#include "debug.h"
5#include "layer_switch.h"
6
7
8uint16_t layer_switch_stat = 0;
9
10
11uint16_t layer_switch_stat_get(void)
12{
13 return layer_switch_stat;
14}
15
16void layer_switch_stat_set(uint16_t stat)
17{
18 layer_switch_stat = stat;
19 layer_switch_debug();
20}
21
22void layer_switch_clear(void)
23{
24 layer_switch_stat = 0;
25 layer_switch_debug();
26}
27
28void layer_switch_on(uint8_t layer)
29{
30 layer_switch_stat |= (1<<layer);
31 layer_switch_debug();
32}
33
34void layer_switch_off(uint8_t layer)
35{
36 layer_switch_stat &= ~(1<<layer);
37 layer_switch_debug();
38}
39
40void layer_switch_inv(uint8_t layer)
41{
42 layer_switch_stat ^= (1<<layer);
43 layer_switch_debug();
44}
45
46void layer_switch_debug(void)
47{
48 debug("layer_switch_stat: "); debug_bin16(layer_switch_stat); debug("\n");
49}
50
51action_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}