From 00d1d7828c63538122d9d3db7336b9a40c9ffe80 Mon Sep 17 00:00:00 2001 From: Alex Ong Date: Sat, 18 May 2019 06:47:50 +1000 Subject: 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 * Revert commit. --- tmk_core/common/action_layer.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'tmk_core/common/action_layer.c') 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 @@ /** \brief Default Layer State */ -uint32_t default_layer_state = 0; +layer_state_t default_layer_state = 0; /** \brief Default Layer State Set At user Level * * Run user code on default layer state change */ __attribute__((weak)) -uint32_t default_layer_state_set_user(uint32_t state) { +layer_state_t default_layer_state_set_user(layer_state_t state) { return state; } @@ -29,7 +29,7 @@ uint32_t default_layer_state_set_user(uint32_t state) { * Run keyboard code on default layer state change */ __attribute__((weak)) -uint32_t default_layer_state_set_kb(uint32_t state) { +layer_state_t default_layer_state_set_kb(layer_state_t state) { return default_layer_state_set_user(state); } @@ -37,7 +37,7 @@ uint32_t default_layer_state_set_kb(uint32_t state) { * * Static function to set the default layer state, prints debug info and clears keys */ -static void default_layer_state_set(uint32_t state) { +static void default_layer_state_set(layer_state_t state) { state = default_layer_state_set_kb(state); debug("default_layer_state: "); default_layer_debug(); debug(" to "); @@ -62,7 +62,7 @@ void default_layer_debug(void) { * * Sets the default layer state. */ -void default_layer_set(uint32_t state) { +void default_layer_set(layer_state_t state) { default_layer_state_set(state); } @@ -71,21 +71,21 @@ void default_layer_set(uint32_t state) { * * Turns on the default layer based on matching bits between specifed layer and existing layer state */ -void default_layer_or(uint32_t state) { +void default_layer_or(layer_state_t state) { default_layer_state_set(default_layer_state | state); } /** \brief Default Layer And * * Turns on default layer based on matching enabled bits between specifed layer and existing layer state */ -void default_layer_and(uint32_t state) { +void default_layer_and(layer_state_t state) { default_layer_state_set(default_layer_state & state); } /** \brief Default Layer Xor * * Turns on default layer based on non-matching bits between specifed layer and existing layer state */ -void default_layer_xor(uint32_t state) { +void default_layer_xor(layer_state_t state) { default_layer_state_set(default_layer_state ^ state); } #endif @@ -94,14 +94,14 @@ void default_layer_xor(uint32_t state) { #ifndef NO_ACTION_LAYER /** \brief Keymap Layer State */ -uint32_t layer_state = 0; +layer_state_t layer_state = 0; /** \brief Layer state set user * * Runs user code on layer state change */ __attribute__((weak)) -uint32_t layer_state_set_user(uint32_t state) { +layer_state_t layer_state_set_user(layer_state_t state) { return state; } @@ -110,7 +110,7 @@ uint32_t layer_state_set_user(uint32_t state) { * Runs keyboard code on layer state change */ __attribute__((weak)) -uint32_t layer_state_set_kb(uint32_t state) { +layer_state_t layer_state_set_kb(layer_state_t state) { return layer_state_set_user(state); } @@ -118,7 +118,7 @@ uint32_t layer_state_set_kb(uint32_t state) { * * Sets the layer to match the specifed state (a bitmask) */ -void layer_state_set(uint32_t state) { +void layer_state_set(layer_state_t state) { state = layer_state_set_kb(state); dprint("layer_state: "); layer_debug(); dprint(" to "); @@ -151,7 +151,7 @@ bool layer_state_is(uint8_t layer) { * * Used for comparing layers {mostly used for unit testing} */ -bool layer_state_cmp(uint32_t cmp_layer_state, uint8_t layer) { +bool layer_state_cmp(layer_state_t cmp_layer_state, uint8_t layer) { if (!cmp_layer_state) { return layer == 0; } return (cmp_layer_state & (1UL<= 0; i--) { + for (int8_t i = sizeof(layer_state_t)-1; i >= 0; i--) { if (layers & (1UL << i)) { action = action_for_key(i, key); if (action.code != ACTION_TRANSPARENT) { -- cgit v1.2.3-70-g09d2