From 06bfe3c037195ac5eece31dff184a93194b65708 Mon Sep 17 00:00:00 2001 From: Ben Blazak Date: Thu, 21 Jun 2012 20:42:56 -0700 Subject: [PATCH] separated kbfun_layer_inc_exec() and ...dec_exec() also added another layer to _kb_layout_release[][][], mostly NULL, but including at least one of each available kbfun*(). this way, all the functions appear to be used, and none of them get optimised out by the compiler --- src/keyboard/ergodox/layout/qwerty.c | 22 ++++++++- src/lib/key-functions.c | 72 +++++++++++++++++++--------- src/lib/key-functions.h | 3 +- 3 files changed, 72 insertions(+), 25 deletions(-) diff --git a/src/keyboard/ergodox/layout/qwerty.c b/src/keyboard/ergodox/layout/qwerty.c index 8055010..8061a42 100644 --- a/src/keyboard/ergodox/layout/qwerty.c +++ b/src/keyboard/ergodox/layout/qwerty.c @@ -25,8 +25,9 @@ #define f_l_set &kbfun_layer_set #define f_l_inc &kbfun_layer_inc #define f_l_dec &kbfun_layer_dec +#define f_l_iex &kbfun_layer_inc_exec +#define f_l_dex &kbfun_layer_dec_exec #define f_2kcap &kbfun_2_keys_capslock_press_release -#define f_lidpr &kbfun_layer_inc_dec_press_release uint8_t PROGMEM _kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS] = { @@ -171,7 +172,24 @@ f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel, f_prrel, f_prrel, -f_prrel,f_prrel,f_prrel ) +f_prrel,f_prrel,f_prrel ), +// ---------------------------------------------------------------------------- + LAYER( // layer 2: nothing (just making sure unused functions don't + // get compiled out) +// unused +NULL, +// other +f_prrel, NULL, NULL, NULL, NULL, NULL, NULL, +f_toggl, NULL, NULL, NULL, NULL, NULL, NULL, +f_l_set, NULL, NULL, NULL, NULL, NULL, NULL, +f_l_inc, NULL, NULL, NULL, NULL, NULL, NULL, +f_l_dec, NULL, NULL, NULL, NULL, NULL, NULL, +f_l_iex, NULL, NULL, NULL, NULL, NULL, NULL, +f_l_dex, NULL, NULL, NULL, NULL, NULL, NULL, +f_2kcap, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL ) // ---------------------------------------------------------------------------- }; diff --git a/src/lib/key-functions.c b/src/lib/key-functions.c index 5fa4405..ea16367 100644 --- a/src/lib/key-functions.c +++ b/src/lib/key-functions.c @@ -245,6 +245,56 @@ void kbfun_layer_dec( KBFUN_FUNCTION_ARGS ) { current_layers_ ); } +/* + * Increase layer, Execute key + * - Increment the current layer by the value specified in the keymap (for all + * non-masked keys), and execute (usually press|release) the key in the same + * position on that new layer + * + * Note + * - Meant to be paired with `kbfun_layer_dec_exec()` + */ +void kbfun_layer_inc_exec( KBFUN_FUNCTION_ARGS ) { + // switch layers + _layer_set_current( + (*current_layer_) + keycode_, + current_layer_, + current_layers_ ); + + // exececute second key (in the same position) + // - `layer_+keycode_` will be constant (under normal circumstances) + // between the press and release + _kbfun_exec_key( + pressed_, 0, layer_+keycode_, + row_, col_, current_layer_, + current_layers_, pressed_layers_ ); +} + +/* + * Decrease layer, Execute key + * - Decrement the current layer by the value specified in the keymap (for all + * non-masked keys), and execute (usually press|release) the key in the same + * position on that new layer + * + * Note + * - Meant to be paired with `kbfun_layer_inc_exec()` + */ +void kbfun_layer_dec_exec( KBFUN_FUNCTION_ARGS ) { + // switch layers + _layer_set_current( + (*current_layer_) - keycode_, + current_layer_, + current_layers_ ); + + // exececute second key (in the same position) + // - `layer_+keycode_` will be constant (under normal circumstances) + // between the press and release + _kbfun_exec_key( + pressed_, 0, layer_+keycode_, + row_, col_, current_layer_, + current_layers_, pressed_layers_ ); +} + /* * Two keys => capslock * - When assigned to two keys (e.g. the physical left and right shift keys) @@ -292,25 +342,3 @@ void kbfun_2_keys_capslock_press_release( KBFUN_FUNCTION_ARGS ) { if (pressed_) keys_pressed++; } -/* - * Layer (inc|dec), key (press|release) - * - Increment (for press) or decrement (for release) the current layer by the - * value specified in the keymap (for all non-masked keys), and press or - * release the key in the same position on that new layer - */ -void kbfun_layer_inc_dec_press_release( KBFUN_FUNCTION_ARGS ) { - // switch layers - _layer_set_current( - ( (pressed_) - ? (*current_layer_) + keycode_ - : (*current_layer_) - keycode_ ), - current_layer_, - current_layers_ ); - - // exececute second key (in the same position) - _kbfun_exec_key( - pressed_, 0, layer_+keycode_, - row_, col_, current_layer_, - current_layers_, pressed_layers_ ); -} - diff --git a/src/lib/key-functions.h b/src/lib/key-functions.h index 42d87c2..5ccb545 100644 --- a/src/lib/key-functions.h +++ b/src/lib/key-functions.h @@ -53,8 +53,9 @@ void kbfun_layer_set (KBFUN_FUNCTION_ARGS); void kbfun_layer_inc (KBFUN_FUNCTION_ARGS); void kbfun_layer_dec (KBFUN_FUNCTION_ARGS); + void kbfun_layer_inc_exec (KBFUN_FUNCTION_ARGS); + void kbfun_layer_dec_exec (KBFUN_FUNCTION_ARGS); void kbfun_2_keys_capslock_press_release (KBFUN_FUNCTION_ARGS); - void kbfun_layer_inc_dec_press_release (KBFUN_FUNCTION_ARGS); #endif