aboutsummaryrefslogtreecommitdiff
path: root/quantum/action_layer.h
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-08-18 00:18:58 +0100
committerGitHub <noreply@github.com>2021-08-18 00:18:58 +0100
commitb8e913c8db73ebf890e4604ee41991a34354a600 (patch)
tree258035f8fda9f83f08a309f6cd608b9c61476678 /quantum/action_layer.h
parent96e2b13d1de227cdc2b918fb0292bd832d346a25 (diff)
downloadqmk_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.h147
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/*
2Copyright 2013 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along 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)
48typedef 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)
55typedef 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)
62typedef 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 */
75extern layer_state_t default_layer_state;
76void default_layer_debug(void);
77void 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 */
84void default_layer_or(layer_state_t state);
85void default_layer_and(layer_state_t state);
86void 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
97extern layer_state_t layer_state;
98
99void layer_state_set(layer_state_t state);
100bool layer_state_is(uint8_t layer);
101bool layer_state_cmp(layer_state_t layer1, uint8_t layer2);
102
103void layer_debug(void);
104void layer_clear(void);
105void layer_move(uint8_t layer);
106void layer_on(uint8_t layer);
107void layer_off(uint8_t layer);
108void layer_invert(uint8_t layer);
109/* bitwise operation */
110void layer_or(layer_state_t state);
111void layer_and(layer_state_t state);
112void layer_xor(layer_state_t state);
113layer_state_t layer_state_set_user(layer_state_t state);
114layer_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
138void update_source_layers_cache(keypos_t key, uint8_t layer);
139uint8_t read_source_layers_cache(keypos_t key);
140#endif
141action_t store_or_get_action(bool pressed, keypos_t key);
142
143/* return the topmost non-transparent layer currently associated with key */
144uint8_t layer_switch_get_layer(keypos_t key);
145
146/* return action depending on current layer status */
147action_t layer_switch_get_action(keypos_t key);