From 93efbe7cfd95b000222e1b9f254548b7499722bf Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Wed, 16 Jan 2019 20:29:51 -0800 Subject: [PATCH] Add documentation and fix formating --- tmk_core/common/action_layer.c | 301 ++++++++++++++++----------------- 1 file changed, 145 insertions(+), 156 deletions(-) diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 3147d61b3643..6ff8c5549b5a 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -17,82 +17,76 @@ uint32_t default_layer_state = 0; /** \brief Default Layer State Set At user Level * - * FIXME: Needs docs + * Run user code on default layer state change */ __attribute__((weak)) uint32_t default_layer_state_set_user(uint32_t state) { - return state; + return state; } /** \brief Default Layer State Set At Keyboard Level * - * FIXME: Needs docs + * Run keyboard code on default layer state change */ __attribute__((weak)) uint32_t default_layer_state_set_kb(uint32_t state) { - return default_layer_state_set_user(state); + return default_layer_state_set_user(state); } /** \brief Default Layer State Set * - * FIXME: Needs docs + * Static function to set the default layer state, prints debug info and clears keys */ -static void default_layer_state_set(uint32_t state) -{ - state = default_layer_state_set_kb(state); - debug("default_layer_state: "); - default_layer_debug(); debug(" to "); - default_layer_state = state; - default_layer_debug(); debug("\n"); +static void default_layer_state_set(uint32_t state) { + state = default_layer_state_set_kb(state); + debug("default_layer_state: "); + default_layer_debug(); debug(" to "); + default_layer_state = state; + default_layer_debug(); debug("\n"); #ifdef STRICT_LAYER_RELEASE - clear_keyboard_but_mods(); // To avoid stuck keys + clear_keyboard_but_mods(); // To avoid stuck keys #else - clear_keyboard_but_mods_and_keys(); // Don't reset held keys + clear_keyboard_but_mods_and_keys(); // Don't reset held keys #endif } /** \brief Default Layer Print * - * FIXME: Needs docs + * Print out the hex value of the 32-bit default layer state, as well as the value of the highest bit. */ -void default_layer_debug(void) -{ - dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state)); +void default_layer_debug(void) { + dprintf("%08lX(%u)", default_layer_state, biton32(default_layer_state)); } /** \brief Default Layer Set * - * FIXME: Needs docs + * Sets the default layer state. */ -void default_layer_set(uint32_t state) -{ - default_layer_state_set(state); +void default_layer_set(uint32_t state) { + default_layer_state_set(state); } #ifndef NO_ACTION_LAYER /** \brief Default Layer Or * - * FIXME: Needs docs + * Turns on the default layer based on matching bits between specifed layer and existing layer state */ -void default_layer_or(uint32_t state) -{ - default_layer_state_set(default_layer_state | state); +void default_layer_or(uint32_t state) { + default_layer_state_set(default_layer_state | state); } /** \brief Default Layer And * - * FIXME: Needs docs + * Turns on default layer based on matching enabled bits between specifed layer and existing layer state */ -void default_layer_and(uint32_t state) -{ - default_layer_state_set(default_layer_state & state); +void default_layer_and(uint32_t state) { + default_layer_state_set(default_layer_state & state); } /** \brief Default Layer Xor * - * FIXME: Needs docs + * Turns on default layer based on non-matching bits between specifed layer and existing layer state */ -void default_layer_xor(uint32_t state) -{ - default_layer_state_set(default_layer_state ^ state); +void default_layer_xor(uint32_t state) { + default_layer_state_set(default_layer_state ^ state); } #endif @@ -104,170 +98,168 @@ uint32_t layer_state = 0; /** \brief Layer state set user * - * FIXME: Needs docs + * Runs user code on layer state change */ __attribute__((weak)) uint32_t layer_state_set_user(uint32_t state) { - return state; + return state; } /** \brief Layer state set keyboard * - * FIXME: Needs docs + * Runs keyboard code on layer state change */ __attribute__((weak)) uint32_t layer_state_set_kb(uint32_t state) { - return layer_state_set_user(state); + return layer_state_set_user(state); } /** \brief Layer state set * - * FIXME: Needs docs + * Sets the layer to match the specifed state (a bitmask) */ -void layer_state_set(uint32_t state) -{ - state = layer_state_set_kb(state); - dprint("layer_state: "); - layer_debug(); dprint(" to "); - layer_state = state; - layer_debug(); dprintln(); +void layer_state_set(uint32_t state) { + state = layer_state_set_kb(state); + dprint("layer_state: "); + layer_debug(); dprint(" to "); + layer_state = state; + layer_debug(); dprintln(); #ifdef STRICT_LAYER_RELEASE - clear_keyboard_but_mods(); // To avoid stuck keys + clear_keyboard_but_mods(); // To avoid stuck keys #else - clear_keyboard_but_mods_and_keys(); // Don't reset held keys + clear_keyboard_but_mods_and_keys(); // Don't reset held keys #endif } /** \brief Layer clear * - * Turn off all layers. + * Turn off all layers */ -void layer_clear(void) -{ - layer_state_set(0); +void layer_clear(void) { + layer_state_set(0); } /** \brief Layer state is * - * Return whether the given state is on (it might still be shadowed by a higher state, though). + * Return whether the given state is on (it might still be shadowed by a higher state, though) */ -bool layer_state_is(uint8_t layer) -{ - return layer_state_cmp(layer_state, layer); +bool layer_state_is(uint8_t layer) { + return layer_state_cmp(layer_state, layer); } /** \brief Layer state compare * - * FIXME: Needs docs + * Used for comparing layers {mostly used for unit testing} */ bool layer_state_cmp(uint32_t cmp_layer_state, uint8_t layer) { - if (!cmp_layer_state) { return layer == 0; } - return (cmp_layer_state & (1UL<= 0; i--) { - if (layers & (1UL<= 0; i--) { + if (layers & (1UL<