diff options
author | Joel Challis <git@zvecr.com> | 2021-08-18 00:18:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-18 00:18:58 +0100 |
commit | b8e913c8db73ebf890e4604ee41991a34354a600 (patch) | |
tree | 258035f8fda9f83f08a309f6cd608b9c61476678 /quantum/action_layer.h | |
parent | 96e2b13d1de227cdc2b918fb0292bd832d346a25 (diff) | |
download | qmk_firmware-b8e913c8db73ebf890e4604ee41991a34354a600.tar.gz qmk_firmware-b8e913c8db73ebf890e4604ee41991a34354a600.zip |
Migrate platform independent code from tmk_core -> quantum (#13673)
* Migrate action|keyboard|keycode|eeconfig from tmk_core -> quantum
Diffstat (limited to 'quantum/action_layer.h')
-rw-r--r-- | quantum/action_layer.h | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/quantum/action_layer.h b/quantum/action_layer.h new file mode 100644 index 000000000..b87d096ee --- /dev/null +++ b/quantum/action_layer.h | |||
@@ -0,0 +1,147 @@ | |||
1 | /* | ||
2 | Copyright 2013 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | |||
18 | #pragma once | ||
19 | |||
20 | #include <stdint.h> | ||
21 | #include "keyboard.h" | ||
22 | #include "action.h" | ||
23 | |||
24 | #ifdef DYNAMIC_KEYMAP_ENABLE | ||
25 | # ifndef DYNAMIC_KEYMAP_LAYER_COUNT | ||
26 | # define DYNAMIC_KEYMAP_LAYER_COUNT 4 | ||
27 | # endif | ||
28 | # if DYNAMIC_KEYMAP_LAYER_COUNT <= 8 | ||
29 | # ifndef LAYER_STATE_8BIT | ||
30 | # define LAYER_STATE_8BIT | ||
31 | # endif | ||
32 | # elif DYNAMIC_KEYMAP_LAYER_COUNT <= 16 | ||
33 | # ifndef LAYER_STATE_16BIT | ||
34 | # define LAYER_STATE_16BIT | ||
35 | # endif | ||
36 | # else | ||
37 | # ifndef LAYER_STATE_32BIT | ||
38 | # define LAYER_STATE_32BIT | ||
39 | # endif | ||
40 | # endif | ||
41 | #endif | ||
42 | |||
43 | #if !defined(LAYER_STATE_8BIT) && !defined(LAYER_STATE_16BIT) && !defined(LAYER_STATE_32BIT) | ||
44 | # define LAYER_STATE_32BIT | ||
45 | #endif | ||
46 | |||
47 | #if defined(LAYER_STATE_8BIT) | ||
48 | typedef uint8_t layer_state_t; | ||
49 | # define MAX_LAYER_BITS 3 | ||
50 | # ifndef MAX_LAYER | ||
51 | # define MAX_LAYER 8 | ||
52 | # endif | ||
53 | # define get_highest_layer(state) biton(state) | ||
54 | #elif defined(LAYER_STATE_16BIT) | ||
55 | typedef uint16_t layer_state_t; | ||
56 | # define MAX_LAYER_BITS 4 | ||
57 | # ifndef MAX_LAYER | ||
58 | # define MAX_LAYER 16 | ||
59 | # endif | ||
60 | # define get_highest_layer(state) biton16(state) | ||
61 | #elif defined(LAYER_STATE_32BIT) | ||
62 | typedef uint32_t layer_state_t; | ||
63 | # define MAX_LAYER_BITS 5 | ||
64 | # ifndef MAX_LAYER | ||
65 | # define MAX_LAYER 32 | ||
66 | # endif | ||
67 | # define get_highest_layer(state) biton32(state) | ||
68 | #else | ||
69 | # error Layer Mask size not specified. HOW?! | ||
70 | #endif | ||
71 | |||
72 | /* | ||
73 | * Default Layer | ||
74 | */ | ||
75 | extern layer_state_t default_layer_state; | ||
76 | void default_layer_debug(void); | ||
77 | void default_layer_set(layer_state_t state); | ||
78 | |||
79 | __attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t state); | ||
80 | __attribute__((weak)) layer_state_t default_layer_state_set_user(layer_state_t state); | ||
81 | |||
82 | #ifndef NO_ACTION_LAYER | ||
83 | /* bitwise operation */ | ||
84 | void default_layer_or(layer_state_t state); | ||
85 | void default_layer_and(layer_state_t state); | ||
86 | void default_layer_xor(layer_state_t state); | ||
87 | #else | ||
88 | # define default_layer_or(state) | ||
89 | # define default_layer_and(state) | ||
90 | # define default_layer_xor(state) | ||
91 | #endif | ||
92 | |||
93 | /* | ||
94 | * Keymap Layer | ||
95 | */ | ||
96 | #ifndef NO_ACTION_LAYER | ||
97 | extern layer_state_t layer_state; | ||
98 | |||
99 | void layer_state_set(layer_state_t state); | ||
100 | bool layer_state_is(uint8_t layer); | ||
101 | bool layer_state_cmp(layer_state_t layer1, uint8_t layer2); | ||
102 | |||
103 | void layer_debug(void); | ||
104 | void layer_clear(void); | ||
105 | void layer_move(uint8_t layer); | ||
106 | void layer_on(uint8_t layer); | ||
107 | void layer_off(uint8_t layer); | ||
108 | void layer_invert(uint8_t layer); | ||
109 | /* bitwise operation */ | ||
110 | void layer_or(layer_state_t state); | ||
111 | void layer_and(layer_state_t state); | ||
112 | void layer_xor(layer_state_t state); | ||
113 | layer_state_t layer_state_set_user(layer_state_t state); | ||
114 | layer_state_t layer_state_set_kb(layer_state_t state); | ||
115 | #else | ||
116 | # define layer_state 0 | ||
117 | |||
118 | # define layer_state_set(layer) | ||
119 | # define layer_state_is(layer) (layer == 0) | ||
120 | # define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & (layer_state_t)1 << layer) != 0) | ||
121 | |||
122 | # define layer_debug() | ||
123 | # define layer_clear() | ||
124 | # define layer_move(layer) (void)layer | ||
125 | # define layer_on(layer) (void)layer | ||
126 | # define layer_off(layer) (void)layer | ||
127 | # define layer_invert(layer) (void)layer | ||
128 | # define layer_or(state) (void)state | ||
129 | # define layer_and(state) (void)state | ||
130 | # define layer_xor(state) (void)state | ||
131 | # define layer_state_set_kb(state) (void)state | ||
132 | # define layer_state_set_user(state) (void)state | ||
133 | #endif | ||
134 | |||
135 | /* pressed actions cache */ | ||
136 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) | ||
137 | |||
138 | void update_source_layers_cache(keypos_t key, uint8_t layer); | ||
139 | uint8_t read_source_layers_cache(keypos_t key); | ||
140 | #endif | ||
141 | action_t store_or_get_action(bool pressed, keypos_t key); | ||
142 | |||
143 | /* return the topmost non-transparent layer currently associated with key */ | ||
144 | uint8_t layer_switch_get_layer(keypos_t key); | ||
145 | |||
146 | /* return action depending on current layer status */ | ||
147 | action_t layer_switch_get_action(keypos_t key); | ||