aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/action_layer.h
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2021-07-03 00:19:52 -0700
committerGitHub <noreply@github.com>2021-07-03 00:19:52 -0700
commit8da8aabbe5796232c0f17f849badd455d42b0277 (patch)
tree7cec61a96672644bba25c97fc8a1a9dd8b75d58d /tmk_core/common/action_layer.h
parent03807c2c6e470a3046c1ff40ac7ab74f76b94f74 (diff)
downloadqmk_firmware-8da8aabbe5796232c0f17f849badd455d42b0277.tar.gz
qmk_firmware-8da8aabbe5796232c0f17f849badd455d42b0277.zip
Improve layer mask handling (#13065)
Diffstat (limited to 'tmk_core/common/action_layer.h')
-rw-r--r--tmk_core/common/action_layer.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index d72cd3e3a..b87d096ee 100644
--- a/tmk_core/common/action_layer.h
+++ b/tmk_core/common/action_layer.h
@@ -21,6 +21,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include "keyboard.h" 21#include "keyboard.h"
22#include "action.h" 22#include "action.h"
23 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
24#if defined(LAYER_STATE_8BIT) 47#if defined(LAYER_STATE_8BIT)
25typedef uint8_t layer_state_t; 48typedef uint8_t layer_state_t;
26# define MAX_LAYER_BITS 3 49# define MAX_LAYER_BITS 3
@@ -35,13 +58,15 @@ typedef uint16_t layer_state_t;
35# define MAX_LAYER 16 58# define MAX_LAYER 16
36# endif 59# endif
37# define get_highest_layer(state) biton16(state) 60# define get_highest_layer(state) biton16(state)
38#else 61#elif defined(LAYER_STATE_32BIT)
39typedef uint32_t layer_state_t; 62typedef uint32_t layer_state_t;
40# define MAX_LAYER_BITS 5 63# define MAX_LAYER_BITS 5
41# ifndef MAX_LAYER 64# ifndef MAX_LAYER
42# define MAX_LAYER 32 65# define MAX_LAYER 32
43# endif 66# endif
44# define get_highest_layer(state) biton32(state) 67# define get_highest_layer(state) biton32(state)
68#else
69# error Layer Mask size not specified. HOW?!
45#endif 70#endif
46 71
47/* 72/*
@@ -92,7 +117,7 @@ layer_state_t layer_state_set_kb(layer_state_t state);
92 117
93# define layer_state_set(layer) 118# define layer_state_set(layer)
94# define layer_state_is(layer) (layer == 0) 119# define layer_state_is(layer) (layer == 0)
95# define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & 1UL << layer) != 0) 120# define layer_state_cmp(state, layer) (state == 0 ? layer == 0 : (state & (layer_state_t)1 << layer) != 0)
96 121
97# define layer_debug() 122# define layer_debug()
98# define layer_clear() 123# define layer_clear()