]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/action_layer.h
Fix wake from suspend LED functionality
[qmk_firmware.git] / tmk_core / common / action_layer.h
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 #ifndef ACTION_LAYER_H
18 #define ACTION_LAYER_H
19
20 #include <stdint.h>
21 #include "keyboard.h"
22 #include "action.h"
23
24
25 /*
26  * Default Layer
27  */
28 extern uint32_t default_layer_state;
29 void default_layer_debug(void);
30 void default_layer_set(uint32_t state);
31
32 __attribute__((weak))
33 uint32_t default_layer_state_set_kb(uint32_t state);
34 __attribute__((weak))
35 uint32_t default_layer_state_set_user(uint32_t state);
36
37 #ifndef NO_ACTION_LAYER
38 /* bitwise operation */
39 void default_layer_or(uint32_t state);
40 void default_layer_and(uint32_t state);
41 void default_layer_xor(uint32_t state);
42 #else
43 #define default_layer_or(state)
44 #define default_layer_and(state)
45 #define default_layer_xor(state)
46 #endif
47
48
49 /*
50  * Keymap Layer
51  */
52 #ifndef NO_ACTION_LAYER
53 extern uint32_t layer_state;
54
55 void layer_state_set(uint32_t state);
56 bool layer_state_is(uint8_t layer);
57 bool layer_state_cmp(uint32_t layer1, uint8_t layer2);
58
59 void layer_debug(void);
60 void layer_clear(void);
61 void layer_move(uint8_t layer);
62 void layer_on(uint8_t layer);
63 void layer_off(uint8_t layer);
64 void layer_invert(uint8_t layer);
65 /* bitwise operation */
66 void layer_or(uint32_t state);
67 void layer_and(uint32_t state);
68 void layer_xor(uint32_t state);
69 #else
70 #define layer_state                    0
71
72 #define layer_state_set(layer)
73 #define layer_state_is(layer)          (layer == 0)
74 #define layer_state_cmp(state, layer)  (state == 0 ? layer == 0 : (state & 1UL << layer) != 0)
75
76 #define layer_debug()
77 #define layer_clear()
78 #define layer_move(layer)
79 #define layer_on(layer)
80 #define layer_off(layer)
81 #define layer_invert(layer)
82 #define layer_or(state)
83 #define layer_and(state)
84 #define layer_xor(state)
85 #endif
86
87 uint32_t layer_state_set_user(uint32_t state);
88 uint32_t layer_state_set_kb(uint32_t state);
89
90 /* pressed actions cache */
91 #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
92 /* The number of bits needed to represent the layer number: log2(32). */
93 #define MAX_LAYER_BITS 5
94 void update_source_layers_cache(keypos_t key, uint8_t layer);
95 uint8_t read_source_layers_cache(keypos_t key);
96 #endif
97 action_t store_or_get_action(bool pressed, keypos_t key);
98
99 /* return the topmost non-transparent layer currently associated with key */
100 uint8_t layer_switch_get_layer(keypos_t key);
101
102 /* return action depending on current layer status */
103 action_t layer_switch_get_action(keypos_t key);
104
105 #endif