aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ong <the.onga@gmail.com>2019-05-18 06:47:50 +1000
committerDrashna Jaelre <drashna@live.com>2019-05-17 13:47:50 -0700
commit00d1d7828c63538122d9d3db7336b9a40c9ffe80 (patch)
treee1d055c72f23bbdc6e30ee7e3eb1213857e2ae33
parent90a45aac6e8fdbf8d781d711bb6a27574130ff38 (diff)
downloadqmk_firmware-00d1d7828c63538122d9d3db7336b9a40c9ffe80.tar.gz
qmk_firmware-00d1d7828c63538122d9d3db7336b9a40c9ffe80.zip
Typedef'ed layer_state_t to uint32_t (#3637)
* Typedef'ed layer_state_t to uint32_t. This enables future work with layer_state_t to uint8_t for optimization purposes. * Removed accidental xeal60 commit * Revert to egyptian brackets, added sizeof(layer_state_t) so when layer_state_t is redefined it will automagically work. * Add additional typedefs * Add checks for setting layer state * Update tmk_core/common/action_layer.h Co-Authored-By: alex-ong <the.onga@gmail.com> * Revert commit.
-rw-r--r--quantum/quantum.h4
-rw-r--r--tmk_core/common/action.c8
-rw-r--r--tmk_core/common/action_layer.c36
-rw-r--r--tmk_core/common/action_layer.h38
-rw-r--r--tmk_core/common/bootmagic.c4
-rw-r--r--tmk_core/common/magic.c2
6 files changed, 50 insertions, 42 deletions
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 208268df6..451dd8a4b 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -61,10 +61,10 @@
61#include "send_string_keycodes.h" 61#include "send_string_keycodes.h"
62#include "suspend.h" 62#include "suspend.h"
63 63
64extern uint32_t default_layer_state; 64extern layer_state_t default_layer_state;
65 65
66#ifndef NO_ACTION_LAYER 66#ifndef NO_ACTION_LAYER
67 extern uint32_t layer_state; 67 extern layer_state_t layer_state;
68#endif 68#endif
69 69
70#ifdef MIDI_ENABLE 70#ifdef MIDI_ENABLE
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index bb4e66c9c..3991a8a9e 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -406,8 +406,8 @@ void process_action(keyrecord_t *record, action_t action)
406 /* Default Layer Bitwise Operation */ 406 /* Default Layer Bitwise Operation */
407 if (!event.pressed) { 407 if (!event.pressed) {
408 uint8_t shift = action.layer_bitop.part*4; 408 uint8_t shift = action.layer_bitop.part*4;
409 uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift; 409 layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift;
410 uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0; 410 layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0;
411 switch (action.layer_bitop.op) { 411 switch (action.layer_bitop.op) {
412 case OP_BIT_AND: default_layer_and(bits | mask); break; 412 case OP_BIT_AND: default_layer_and(bits | mask); break;
413 case OP_BIT_OR: default_layer_or(bits | mask); break; 413 case OP_BIT_OR: default_layer_or(bits | mask); break;
@@ -420,8 +420,8 @@ void process_action(keyrecord_t *record, action_t action)
420 if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : 420 if (event.pressed ? (action.layer_bitop.on & ON_PRESS) :
421 (action.layer_bitop.on & ON_RELEASE)) { 421 (action.layer_bitop.on & ON_RELEASE)) {
422 uint8_t shift = action.layer_bitop.part*4; 422 uint8_t shift = action.layer_bitop.part*4;
423 uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift; 423 layer_state_t bits = ((layer_state_t)action.layer_bitop.bits)<<shift;
424 uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0; 424 layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf)<<shift) : 0;
425 switch (action.layer_bitop.op) { 425 switch (action.layer_bitop.op) {
426 case OP_BIT_AND: layer_and(bits | mask); break; 426 case OP_BIT_AND: layer_and(bits | mask); break;
427 case OP_BIT_OR: layer_or(bits | mask); break; 427 case OP_BIT_OR: layer_or(bits | mask); break;
diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c
index 47cad996a..be28107b6 100644
--- a/tmk_core/common/action_layer.c
+++ b/tmk_core/common/action_layer.c
@@ -13,14 +13,14 @@
13 13
14/** \brief Default Layer State 14/** \brief Default Layer State
15 */ 15 */
16uint32_t default_layer_state = 0; 16layer_state_t default_layer_state = 0;
17 17
18/** \brief Default Layer State Set At user Level 18/** \brief Default Layer State Set At user Level
19 * 19 *
20 * Run user code on default layer state change 20 * Run user code on default layer state change
21 */ 21 */
22__attribute__((weak)) 22__attribute__((weak))
23uint32_t default_layer_state_set_user(uint32_t state) { 23layer_state_t default_layer_state_set_user(layer_state_t state) {
24 return state; 24 return state;
25} 25}
26 26
@@ -29,7 +29,7 @@ uint32_t default_layer_state_set_user(uint32_t state) {
29 * Run keyboard code on default layer state change 29 * Run keyboard code on default layer state change
30 */ 30 */
31__attribute__((weak)) 31__attribute__((weak))
32uint32_t default_layer_state_set_kb(uint32_t state) { 32layer_state_t default_layer_state_set_kb(layer_state_t state) {
33 return default_layer_state_set_user(state); 33 return default_layer_state_set_user(state);
34} 34}
35 35
@@ -37,7 +37,7 @@ uint32_t default_layer_state_set_kb(uint32_t state) {
37 * 37 *
38 * Static function to set the default layer state, prints debug info and clears keys 38 * Static function to set the default layer state, prints debug info and clears keys
39 */ 39 */
40static void default_layer_state_set(uint32_t state) { 40static void default_layer_state_set(layer_state_t state) {
41 state = default_layer_state_set_kb(state); 41 state = default_layer_state_set_kb(state);
42 debug("default_layer_state: "); 42 debug("default_layer_state: ");
43 default_layer_debug(); debug(" to "); 43 default_layer_debug(); debug(" to ");
@@ -62,7 +62,7 @@ void default_layer_debug(void) {
62 * 62 *
63 * Sets the default layer state. 63 * Sets the default layer state.
64 */ 64 */
65void default_layer_set(uint32_t state) { 65void default_layer_set(layer_state_t state) {
66 default_layer_state_set(state); 66 default_layer_state_set(state);
67} 67}
68 68
@@ -71,21 +71,21 @@ void default_layer_set(uint32_t state) {
71 * 71 *
72 * Turns on the default layer based on matching bits between specifed layer and existing layer state 72 * Turns on the default layer based on matching bits between specifed layer and existing layer state
73 */ 73 */
74void default_layer_or(uint32_t state) { 74void default_layer_or(layer_state_t state) {
75 default_layer_state_set(default_layer_state | state); 75 default_layer_state_set(default_layer_state | state);
76} 76}
77/** \brief Default Layer And 77/** \brief Default Layer And
78 * 78 *
79 * Turns on default layer based on matching enabled bits between specifed layer and existing layer state 79 * Turns on default layer based on matching enabled bits between specifed layer and existing layer state
80 */ 80 */
81void default_layer_and(uint32_t state) { 81void default_layer_and(layer_state_t state) {
82 default_layer_state_set(default_layer_state & state); 82 default_layer_state_set(default_layer_state & state);
83} 83}
84/** \brief Default Layer Xor 84/** \brief Default Layer Xor
85 * 85 *
86 * Turns on default layer based on non-matching bits between specifed layer and existing layer state 86 * Turns on default layer based on non-matching bits between specifed layer and existing layer state
87 */ 87 */
88void default_layer_xor(uint32_t state) { 88void default_layer_xor(layer_state_t state) {
89 default_layer_state_set(default_layer_state ^ state); 89 default_layer_state_set(default_layer_state ^ state);
90} 90}
91#endif 91#endif
@@ -94,14 +94,14 @@ void default_layer_xor(uint32_t state) {
94#ifndef NO_ACTION_LAYER 94#ifndef NO_ACTION_LAYER
95/** \brief Keymap Layer State 95/** \brief Keymap Layer State
96 */ 96 */
97uint32_t layer_state = 0; 97layer_state_t layer_state = 0;
98 98
99/** \brief Layer state set user 99/** \brief Layer state set user
100 * 100 *
101 * Runs user code on layer state change 101 * Runs user code on layer state change
102 */ 102 */
103__attribute__((weak)) 103__attribute__((weak))
104uint32_t layer_state_set_user(uint32_t state) { 104layer_state_t layer_state_set_user(layer_state_t state) {
105 return state; 105 return state;
106} 106}
107 107
@@ -110,7 +110,7 @@ uint32_t layer_state_set_user(uint32_t state) {
110 * Runs keyboard code on layer state change 110 * Runs keyboard code on layer state change
111 */ 111 */
112__attribute__((weak)) 112__attribute__((weak))
113uint32_t layer_state_set_kb(uint32_t state) { 113layer_state_t layer_state_set_kb(layer_state_t state) {
114 return layer_state_set_user(state); 114 return layer_state_set_user(state);
115} 115}
116 116
@@ -118,7 +118,7 @@ uint32_t layer_state_set_kb(uint32_t state) {
118 * 118 *
119 * Sets the layer to match the specifed state (a bitmask) 119 * Sets the layer to match the specifed state (a bitmask)
120 */ 120 */
121void layer_state_set(uint32_t state) { 121void layer_state_set(layer_state_t state) {
122 state = layer_state_set_kb(state); 122 state = layer_state_set_kb(state);
123 dprint("layer_state: "); 123 dprint("layer_state: ");
124 layer_debug(); dprint(" to "); 124 layer_debug(); dprint(" to ");
@@ -151,7 +151,7 @@ bool layer_state_is(uint8_t layer) {
151 * 151 *
152 * Used for comparing layers {mostly used for unit testing} 152 * Used for comparing layers {mostly used for unit testing}
153 */ 153 */
154bool layer_state_cmp(uint32_t cmp_layer_state, uint8_t layer) { 154bool layer_state_cmp(layer_state_t cmp_layer_state, uint8_t layer) {
155 if (!cmp_layer_state) { return layer == 0; } 155 if (!cmp_layer_state) { return layer == 0; }
156 return (cmp_layer_state & (1UL<<layer)) != 0; 156 return (cmp_layer_state & (1UL<<layer)) != 0;
157} 157}
@@ -192,21 +192,21 @@ void layer_invert(uint8_t layer) {
192 * 192 *
193 * Turns on layers based on matching bits between specifed layer and existing layer state 193 * Turns on layers based on matching bits between specifed layer and existing layer state
194 */ 194 */
195void layer_or(uint32_t state) { 195void layer_or(layer_state_t state) {
196 layer_state_set(layer_state | state); 196 layer_state_set(layer_state | state);
197} 197}
198/** \brief Layer and 198/** \brief Layer and
199 * 199 *
200 * Turns on layers based on matching enabled bits between specifed layer and existing layer state 200 * Turns on layers based on matching enabled bits between specifed layer and existing layer state
201 */ 201 */
202void layer_and(uint32_t state) { 202void layer_and(layer_state_t state) {
203 layer_state_set(layer_state & state); 203 layer_state_set(layer_state & state);
204} 204}
205/** \brief Layer xor 205/** \brief Layer xor
206 * 206 *
207 * Turns on layers based on non-matching bits between specifed layer and existing layer state 207 * Turns on layers based on non-matching bits between specifed layer and existing layer state
208 */ 208 */
209void layer_xor(uint32_t state) { 209void layer_xor(layer_state_t state) {
210 layer_state_set(layer_state ^ state); 210 layer_state_set(layer_state ^ state);
211} 211}
212 212
@@ -301,9 +301,9 @@ uint8_t layer_switch_get_layer(keypos_t key) {
301 action_t action; 301 action_t action;
302 action.code = ACTION_TRANSPARENT; 302 action.code = ACTION_TRANSPARENT;
303 303
304 uint32_t layers = layer_state | default_layer_state; 304 layer_state_t layers = layer_state | default_layer_state;
305 /* check top layer first */ 305 /* check top layer first */
306 for (int8_t i = 31; i >= 0; i--) { 306 for (int8_t i = sizeof(layer_state_t)-1; i >= 0; i--) {
307 if (layers & (1UL << i)) { 307 if (layers & (1UL << i)) {
308 action = action_for_key(i, key); 308 action = action_for_key(i, key);
309 if (action.code != ACTION_TRANSPARENT) { 309 if (action.code != ACTION_TRANSPARENT) {
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index 6e2f35d90..7fa30c86d 100644
--- a/tmk_core/common/action_layer.h
+++ b/tmk_core/common/action_layer.h
@@ -21,24 +21,32 @@ 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#if defined(LAYER_STATE_8BIT) || ( defined(DYNAMIC_KEYMAP_ENABLE) && DYNAMIC_KEYMAP_LAYER_COUNT >= 8 )
25typedef uint8_t layer_state_t;
26#elif defined(LAYER_STATE_16BIT)
27typedef uint16_t layer_state_t;
28#else
29typedef uint32_t layer_state_t;
30#endif
31
24 32
25/* 33/*
26 * Default Layer 34 * Default Layer
27 */ 35 */
28extern uint32_t default_layer_state; 36extern layer_state_t default_layer_state;
29void default_layer_debug(void); 37void default_layer_debug(void);
30void default_layer_set(uint32_t state); 38void default_layer_set(layer_state_t state);
31 39
32__attribute__((weak)) 40__attribute__((weak))
33uint32_t default_layer_state_set_kb(uint32_t state); 41layer_state_t default_layer_state_set_kb(layer_state_t state);
34__attribute__((weak)) 42__attribute__((weak))
35uint32_t default_layer_state_set_user(uint32_t state); 43layer_state_t default_layer_state_set_user(layer_state_t state);
36 44
37#ifndef NO_ACTION_LAYER 45#ifndef NO_ACTION_LAYER
38/* bitwise operation */ 46/* bitwise operation */
39void default_layer_or(uint32_t state); 47void default_layer_or(layer_state_t state);
40void default_layer_and(uint32_t state); 48void default_layer_and(layer_state_t state);
41void default_layer_xor(uint32_t state); 49void default_layer_xor(layer_state_t state);
42#else 50#else
43#define default_layer_or(state) 51#define default_layer_or(state)
44#define default_layer_and(state) 52#define default_layer_and(state)
@@ -50,11 +58,11 @@ void default_layer_xor(uint32_t state);
50 * Keymap Layer 58 * Keymap Layer
51 */ 59 */
52#ifndef NO_ACTION_LAYER 60#ifndef NO_ACTION_LAYER
53extern uint32_t layer_state; 61extern layer_state_t layer_state;
54 62
55void layer_state_set(uint32_t state); 63void layer_state_set(layer_state_t state);
56bool layer_state_is(uint8_t layer); 64bool layer_state_is(uint8_t layer);
57bool layer_state_cmp(uint32_t layer1, uint8_t layer2); 65bool layer_state_cmp(layer_state_t layer1, uint8_t layer2);
58 66
59void layer_debug(void); 67void layer_debug(void);
60void layer_clear(void); 68void layer_clear(void);
@@ -63,9 +71,9 @@ void layer_on(uint8_t layer);
63void layer_off(uint8_t layer); 71void layer_off(uint8_t layer);
64void layer_invert(uint8_t layer); 72void layer_invert(uint8_t layer);
65/* bitwise operation */ 73/* bitwise operation */
66void layer_or(uint32_t state); 74void layer_or(layer_state_t state);
67void layer_and(uint32_t state); 75void layer_and(layer_state_t state);
68void layer_xor(uint32_t state); 76void layer_xor(layer_state_t state);
69#else 77#else
70#define layer_state 0 78#define layer_state 0
71 79
@@ -84,8 +92,8 @@ void layer_xor(uint32_t state);
84#define layer_xor(state) 92#define layer_xor(state)
85#endif 93#endif
86 94
87uint32_t layer_state_set_user(uint32_t state); 95layer_state_t layer_state_set_user(layer_state_t state);
88uint32_t layer_state_set_kb(uint32_t state); 96layer_state_t layer_state_set_kb(layer_state_t state);
89 97
90/* pressed actions cache */ 98/* pressed actions cache */
91#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) 99#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
index 9f79fb8ee..cc780d17a 100644
--- a/tmk_core/common/bootmagic.c
+++ b/tmk_core/common/bootmagic.c
@@ -99,10 +99,10 @@ void bootmagic(void)
99 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); } 99 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
100 if (default_layer) { 100 if (default_layer) {
101 eeconfig_update_default_layer(default_layer); 101 eeconfig_update_default_layer(default_layer);
102 default_layer_set((uint32_t)default_layer); 102 default_layer_set((layer_state_t)default_layer);
103 } else { 103 } else {
104 default_layer = eeconfig_read_default_layer(); 104 default_layer = eeconfig_read_default_layer();
105 default_layer_set((uint32_t)default_layer); 105 default_layer_set((layer_state_t)default_layer);
106 } 106 }
107} 107}
108 108
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
index 714acc0f5..2b1a6a6ad 100644
--- a/tmk_core/common/magic.c
+++ b/tmk_core/common/magic.c
@@ -33,6 +33,6 @@ void magic(void)
33 33
34 uint8_t default_layer = 0; 34 uint8_t default_layer = 0;
35 default_layer = eeconfig_read_default_layer(); 35 default_layer = eeconfig_read_default_layer();
36 default_layer_set((uint32_t)default_layer); 36 default_layer_set((layer_state_t)default_layer);
37 37
38} 38}