diff options
author | Alex Ong <the.onga@gmail.com> | 2020-05-11 10:04:38 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-11 01:04:38 +0100 |
commit | 361ac2f32ac8b906dbb29cd0a6c5f971dad298c3 (patch) | |
tree | d4b8a2e2cfc464314a713f00294881fefa67f983 | |
parent | d15a60d2d318ede79746c09d5beb79ba72037f30 (diff) | |
download | qmk_firmware-361ac2f32ac8b906dbb29cd0a6c5f971dad298c3.tar.gz qmk_firmware-361ac2f32ac8b906dbb29cd0a6c5f971dad298c3.zip |
Optimization for scanning less layers. (#8311)
* Optimization for scanning less layers.
* Rename NUM_LAYERS to MAX_LAYER.
-rw-r--r-- | tmk_core/common/action_layer.c | 2 | ||||
-rw-r--r-- | tmk_core/common/action_layer.h | 15 |
2 files changed, 14 insertions, 3 deletions
diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 81f86f0f3..af2d7d964 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c | |||
@@ -257,7 +257,7 @@ uint8_t layer_switch_get_layer(keypos_t key) { | |||
257 | 257 | ||
258 | layer_state_t layers = layer_state | default_layer_state; | 258 | layer_state_t layers = layer_state | default_layer_state; |
259 | /* check top layer first */ | 259 | /* check top layer first */ |
260 | for (int8_t i = sizeof(layer_state_t) * 8 - 1; i >= 0; i--) { | 260 | for (int8_t i = MAX_LAYER - 1; i >= 0; i--) { |
261 | if (layers & (1UL << i)) { | 261 | if (layers & (1UL << i)) { |
262 | action = action_for_key(i, key); | 262 | action = action_for_key(i, key); |
263 | if (action.code != ACTION_TRANSPARENT) { | 263 | if (action.code != ACTION_TRANSPARENT) { |
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index c283d2623..16922c1ff 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h | |||
@@ -23,12 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
23 | 23 | ||
24 | #if defined(LAYER_STATE_8BIT) | 24 | #if defined(LAYER_STATE_8BIT) |
25 | typedef uint8_t layer_state_t; | 25 | typedef uint8_t layer_state_t; |
26 | # define MAX_LAYER_BITS 3 | ||
27 | # ifndef MAX_LAYER | ||
28 | # define MAX_LAYER 8 | ||
29 | # endif | ||
26 | # define get_highest_layer(state) biton(state) | 30 | # define get_highest_layer(state) biton(state) |
27 | #elif defined(LAYER_STATE_16BIT) | 31 | #elif defined(LAYER_STATE_16BIT) |
28 | typedef uint16_t layer_state_t; | 32 | typedef uint16_t layer_state_t; |
33 | # define MAX_LAYER_BITS 4 | ||
34 | # ifndef MAX_LAYER | ||
35 | # define MAX_LAYER 16 | ||
36 | # endif | ||
29 | # define get_highest_layer(state) biton16(state) | 37 | # define get_highest_layer(state) biton16(state) |
30 | #else | 38 | #else |
31 | typedef uint32_t layer_state_t; | 39 | typedef uint32_t layer_state_t; |
40 | # define MAX_LAYER_BITS 5 | ||
41 | # ifndef MAX_LAYER | ||
42 | # define MAX_LAYER 32 | ||
43 | # endif | ||
32 | # define get_highest_layer(state) biton32(state) | 44 | # define get_highest_layer(state) biton32(state) |
33 | #endif | 45 | #endif |
34 | 46 | ||
@@ -96,8 +108,7 @@ layer_state_t layer_state_set_kb(layer_state_t state); | |||
96 | 108 | ||
97 | /* pressed actions cache */ | 109 | /* pressed actions cache */ |
98 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) | 110 | #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) |
99 | /* The number of bits needed to represent the layer number: log2(32). */ | 111 | |
100 | # define MAX_LAYER_BITS 5 | ||
101 | void update_source_layers_cache(keypos_t key, uint8_t layer); | 112 | void update_source_layers_cache(keypos_t key, uint8_t layer); |
102 | uint8_t read_source_layers_cache(keypos_t key); | 113 | uint8_t read_source_layers_cache(keypos_t key); |
103 | #endif | 114 | #endif |