From 4ae979f6ef8dbf9e1d1f35be15322ad6d02e2958 Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 6 Oct 2012 02:23:12 +0900 Subject: Initial version of new code for layer switch is added. --- common/keyboard.h | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) mode change 100644 => 100755 common/keyboard.h (limited to 'common/keyboard.h') diff --git a/common/keyboard.h b/common/keyboard.h old mode 100644 new mode 100755 index 51bf67379..2353805e1 --- a/common/keyboard.h +++ b/common/keyboard.h @@ -18,15 +18,41 @@ along with this program. If not, see . #ifndef KEYBOARD_H #define KEYBOARD_H +#include #include #ifdef __cplusplus extern "C" { #endif + +typedef struct { + uint8_t row; + uint8_t col; +} key_t; + +typedef struct { + key_t key; + bool pressed; +} keyevent_t; + +typedef struct { + keyevent_t event; + uint8_t code; + uint8_t mods; + uint16_t time; +} keyrecord_t; + +#define KEYEQ(keya, keyb) (keya.row == keyb.row && keya.col == keyb.col) + + +extern uint8_t current_layer; +extern uint8_t default_layer; + void keyboard_init(void); -void keyboard_proc(void); +void keyboard_task(void); void keyboard_set_leds(uint8_t leds); + #ifdef __cplusplus } #endif -- cgit v1.2.3-70-g09d2 From e9af482690152f1beedbbb915791eccd2d5c22d1 Mon Sep 17 00:00:00 2001 From: tmk Date: Sun, 7 Oct 2012 12:25:18 +0900 Subject: Add repeating of Fn key with alt keycode. --- common/keyboard.c | 29 ++++++++++++++++++++++------- common/keyboard.h | 0 2 files changed, 22 insertions(+), 7 deletions(-) mode change 100755 => 100644 common/keyboard.c mode change 100755 => 100644 common/keyboard.h (limited to 'common/keyboard.h') diff --git a/common/keyboard.c b/common/keyboard.c old mode 100755 new mode 100644 index 9f0c27670..b7063a264 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -163,7 +163,7 @@ static void unregister_code(uint8_t code) * Event/State|IDLE DELAYING[f] WAITING[f,k] PRESSING * -----------+------------------------------------------------------------------ * Fn Down |IDLE(L+) WAITING(Sk) WAITING(Sk) - - * Up |IDLE(L-) IDLE(L-) IDLE(L-) IDLE(L-) + * Up |IDLE(L-) IDLE(L-) IDLE(L-) IDLE(L-) * Fnk Down |DELAYING(Sf) WAITING(Sk) WAINTING(Sk) PRESSING(Rf) * Up |IDLE(L-) IDLE(Rf,Uf) IDLE(Rf,Ps,Uf)*3 PRESSING(Uf) * Key Down |PRESSING(Rk) WAITING(Sk) WAITING(Sk) PRESSING(Rk) @@ -208,7 +208,6 @@ static void unregister_code(uint8_t code) static inline void process_key(keyevent_t event) { - /* TODO: ring buffer static keyrecord_t waiting_keys[5]; static uint8_t waiting_keys_head = 0; @@ -220,12 +219,12 @@ static inline void process_key(keyevent_t event) uint8_t tmp_mods; - //debug("kbdstate: "); debug_hex(kbdstate); debug("state: "); print_P(state_str(kbdstate)); debug(" kind: "); debug_hex(kind); debug(" code: "); debug_hex(code); if (event.pressed) { debug("d"); } else { debug("u"); } debug("\n"); + switch (kbdstate) { case IDLE: switch (kind) { @@ -236,9 +235,20 @@ static inline void process_key(keyevent_t event) layer_switch_off(code); break; case FNK_DOWN: - // store event - delayed_fn = (keyrecord_t) { .event = event, .code = code, .mods = keyboard_report->mods, .time = timer_read() }; - NEXT(DELAYING); + // repeat Fn alt key when press Fn key down, up then down again quickly + if (KEYEQ(delayed_fn.event.key, event.key) && + timer_elapsed(delayed_fn.time) < LAYER_DELAY) { + register_code(keymap_fn_keycode(FN_INDEX(code))); + NEXT(PRESSING); + } else { + delayed_fn = (keyrecord_t) { + .event = event, + .code = code, + .mods = keyboard_report->mods, + .time = timer_read() + }; + NEXT(DELAYING); + } break; case FNK_UP: layer_switch_off(code); @@ -298,7 +308,12 @@ static inline void process_key(keyevent_t event) case FNK_DOWN: case KEY_DOWN: case MOUSEKEY_DOWN: - waiting_key = (keyrecord_t) { .event = event, .code = code, .mods = keyboard_report->mods, .time = timer_read() }; + waiting_key = (keyrecord_t) { + .event = event, + .code = code, + .mods = keyboard_report->mods, + .time = timer_read() + }; NEXT(WAITING); break; case MOD_DOWN: diff --git a/common/keyboard.h b/common/keyboard.h old mode 100755 new mode 100644 -- cgit v1.2.3-70-g09d2