From d9f287586635a401b8d6a80614bee6dbebe2f18c Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 15 Feb 2013 18:48:36 +0900 Subject: Replace layer_stack with layer_switch --- common/layer_switch.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 common/layer_switch.c (limited to 'common/layer_switch.c') diff --git a/common/layer_switch.c b/common/layer_switch.c new file mode 100644 index 0000000000..9bc804e641 --- /dev/null +++ b/common/layer_switch.c @@ -0,0 +1,68 @@ +#include +#include "keyboard.h" +#include "action.h" +#include "debug.h" +#include "layer_switch.h" + + +uint16_t layer_switch_stat = 0; + + +uint16_t layer_switch_stat_get(void) +{ + return layer_switch_stat; +} + +void layer_switch_stat_set(uint16_t stat) +{ + layer_switch_stat = stat; + layer_switch_debug(); +} + +void layer_switch_clear(void) +{ + layer_switch_stat = 0; + layer_switch_debug(); +} + +void layer_switch_on(uint8_t layer) +{ + layer_switch_stat |= (1<= 0; i--) { + if (layer_switch_stat & (1< Date: Sat, 16 Feb 2013 04:05:58 +0900 Subject: Rewrite layer action with layer_switch --- common/layer_switch.c | 66 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 15 deletions(-) (limited to 'common/layer_switch.c') diff --git a/common/layer_switch.c b/common/layer_switch.c index 9bc804e641..22bfb34f65 100644 --- a/common/layer_switch.c +++ b/common/layer_switch.c @@ -2,50 +2,88 @@ #include "keyboard.h" #include "action.h" #include "debug.h" +#include "util.h" #include "layer_switch.h" +uint8_t default_layer = 0; + uint16_t layer_switch_stat = 0; -uint16_t layer_switch_stat_get(void) +uint16_t layer_switch_get_stat(void) { return layer_switch_stat; } -void layer_switch_stat_set(uint16_t stat) +/* return highest layer whose state is on */ +uint8_t layer_switch_get_layer(void) +{ + return biton16(layer_switch_stat); +} + +static inline void stat_set(uint16_t stat) { + debug("layer_switch: "); + layer_switch_debug(); debug(" to "); + layer_switch_stat = stat; - layer_switch_debug(); + + layer_switch_debug(); debug("\n"); + + clear_keyboard_but_mods(); // To avoid stuck keys } void layer_switch_clear(void) { - layer_switch_stat = 0; - layer_switch_debug(); + stat_set(0); +} + + +void layer_switch_set(uint16_t stat) +{ + stat_set(stat); +} + +void layer_switch_move(uint8_t layer) +{ + if (layer) + stat_set(1<