X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=hhkb%2Fkeymap.c;h=cad601d4676d8d4bb58f6738d1435b9cff031904;hb=45d4a7a89883c3433604d4e011b665796a583008;hp=ca78200c089ee46a3525abd76fe1a1a1c44b0541;hpb=2f80e790c6310ad24a4cb3d4a72c31314364fef7;p=max%2Ftmk_keyboard.git diff --git a/hhkb/keymap.c b/hhkb/keymap.c index ca78200c..cad601d4 100644 --- a/hhkb/keymap.c +++ b/hhkb/keymap.c @@ -6,16 +6,13 @@ #include #include "usb_keyboard.h" #include "usb_keycodes.h" -#include "matrix.h" #include "print.h" #include "debug.h" #include "util.h" -#include "keymap.h" +#include "controller.h" +#include "keymap_skel.h" -#define FN_KEYCODE(fn) (pgm_read_byte(&fn_keycode[(fn)])) -#define FN_LAYER(fn) (pgm_read_byte(&fn_layer[(fn)])) -#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) #define KEYMAP( \ R3C1, R3C0, R0C0, R1C0, R1C1, R2C0, R2C1, R4C0, R4C1, R6C0, R6C1, R7C0, R7C1, R5C0, R5C1, \ R3C2, R0C1, R0C2, R1C3, R1C2, R2C3, R2C2, R4C2, R4C3, R6C2, R6C3, R7C3, R7C2, R5C2, \ @@ -34,13 +31,11 @@ { R7C0, R7C1, R7C2, R7C3, R7C4, R7C5, R7C6, KB_NO } \ } - -static int current_layer = 0; -static bool layer_used = false; +#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) /* layer to change into while Fn key pressed */ -static const int PROGMEM fn_layer[] = { 0, 1, 2, 3, 4, 0, 0, 0 }; +static const int PROGMEM fn_layer[] = { 0, 1, 2, 3, 4, 0, 0, 1 }; /* keycode to sent when Fn key released without using layer keys. */ static const uint8_t PROGMEM fn_keycode[] = { @@ -51,7 +46,7 @@ static const uint8_t PROGMEM fn_keycode[] = { KB_SPACE, // FN_4 layer 4 [NOT USED] KB_NO, // FN_5 [NOT USED] KB_NO, // FN_6 [NOT USED] - KB_NO // FN_7 [NOT USED] + KB_NO // FN_7 layer 1 }; static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { @@ -65,14 +60,14 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * |-----------------------------------------------------------| * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1| * `-----------------------------------------------------------' - * |Gui|Alt |Space |Alt |Gui| + * |Gui|Alt |Space |Alt |Fn7| * `-------------------------------------------' */ KEYMAP(KB_ESC, KB_1, KB_2, KB_3, KB_4, KB_5, KB_6, KB_7, KB_8, KB_9, KB_0, KB_MINS,KB_EQL, KB_BSLS,KB_GRV, \ KB_TAB, KB_Q, KB_W, KB_E, KB_R, KB_T, KB_Y, KB_U, KB_I, KB_O, KB_P, KB_LBRC,KB_RBRC,KB_BSPC, \ KB_LCTL,KB_A, KB_S, KB_D, KB_F, KB_G, KB_H, KB_J, KB_K, KB_L, FN_3, FN_2, KB_ENT, \ KB_LSFT,KB_Z, KB_X, KB_C, KB_V, KB_B, KB_N, KB_M, KB_COMM,KB_DOT, KB_SLSH,KB_RSFT,FN_1, \ - KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_RGUI), + KB_LGUI,KB_LALT,KB_SPC, KB_RALT,FN_7), /* Layer 1: HHKB mode (HHKB Fn) * ,-----------------------------------------------------------. @@ -84,14 +79,14 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * |-----------------------------------------------------------| * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx| * `-----------------------------------------------------------' - * |Gui |Alt |Space |Alt |Gui| + * |Gui |Alt |Space |Alt |xxx| * `--------------------------------------------' */ KEYMAP(KB_PWR, KB_F1, KB_F2, KB_F3, KB_F4, KB_F5, KB_F6, KB_F7, KB_F8, KB_F9, KB_F10, KB_F11, KB_F12, KB_INS, KB_DEL, \ KB_CAPS,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_PSCR,KB_SLCK,KB_BRK, KB_UP, KB_NO, KB_BSPC, \ KB_LCTL,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KP_ASTR,KP_SLSH,KB_HOME,KB_PGUP,KB_LEFT,KB_RGHT,KB_ENT, \ KB_LSFT,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KP_PLUS,KP_MINS,KB_END, KB_PGDN,KB_DOWN,KB_RSFT,FN_1, \ - KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_RGUI), + KB_LGUI,KB_LALT,KB_SPC, KB_RALT,FN_7), /* Layer 2: Vi mode (Quote/Rmeta) * ,-----------------------------------------------------------. @@ -114,7 +109,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Layer 3: Mouse mode (Semicolon) * ,-----------------------------------------------------------. - * |Esc| | | | | | | | | | | | | | | + * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del| * |-----------------------------------------------------------| * |Tab |MwL|MwU|McU|MwD|MwL|MwR|MwD|MwU|MwR| | | |Backs| * |-----------------------------------------------------------| @@ -153,76 +148,22 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; -uint8_t keymap_get_keycode(int row, int col) +uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col) { - return keymap_get_keycodel(current_layer, row, col); + return KEYCODE(layer, row, col); } -uint8_t keymap_get_keycodel(int layer, int row, int col) +int keymap_fn_layer(uint8_t fn_bits) { - uint8_t code = KEYCODE(layer, row, col); - // normal key or mouse key - if (IS_KEY(code) || IS_MOUSE(code)) - layer_used = true; - return code; + return pgm_read_byte(&fn_layer[biton(fn_bits)]); } -inline -int keymap_get_layer(void) +uint8_t keymap_fn_keycode(uint8_t fn_bits) { - return current_layer; + return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); } -inline -int keymap_set_layer(int layer) -{ - current_layer = layer; - return current_layer; -} - -inline -bool keymap_is_special_mode(int fn_bits) +bool keymap_is_special_mode(uint8_t fn_bits) { return (keyboard_modifier_keys == (BIT_LCTRL | BIT_LSHIFT | BIT_LALT | BIT_LGUI)); } - -void keymap_fn_proc(int fn_bits) -{ - // layer switching - static int last_bits = 0; - static uint8_t last_mod = 0; - - if (usb_keyboard_has_key() || fn_bits == last_bits) { - // do nothing during press other than Fn key - return; - } else if (fn_bits == 0) { - // send key when Fn key is released without using the layer - if (!layer_used) { - uint8_t code = FN_KEYCODE(biton(last_bits)); - if (code != KB_NO) { - if (IS_MOD(code)) { - keyboard_modifier_keys = last_mod | 1<<(code & 0x07); - } else { - keyboard_keys[0] = code; - keyboard_modifier_keys = last_mod; - } - usb_keyboard_send(); - usb_keyboard_print(); - usb_keyboard_clear(); - } - } - last_bits = 0; - last_mod = 0; - layer_used = false; - keymap_set_layer(0); // default layer - } else if ((fn_bits & (fn_bits - 1)) == 0) { - // switch layer when just one Fn Key is pressed - last_bits = fn_bits; - last_mod = keyboard_modifier_keys; - layer_used = false; - keymap_set_layer(FN_LAYER(biton(fn_bits))); - debug("layer: "); phex(current_layer); debug("("); - debug_bin(last_bits); debug(")\n"); - debug("last_mod: "); debug_hex(last_mod); debug("\n"); - } -}