diff options
Diffstat (limited to 'hhkb')
-rw-r--r-- | hhkb/controller.h | 6 | ||||
-rw-r--r-- | hhkb/keymap.c | 77 | ||||
-rw-r--r-- | hhkb/keymap.h | 7 | ||||
-rw-r--r-- | hhkb/matrix.c | 7 | ||||
-rw-r--r-- | hhkb/matrix.h | 15 |
5 files changed, 19 insertions, 93 deletions
diff --git a/hhkb/controller.h b/hhkb/controller.h index aa862cdc1..32a10b7cd 100644 --- a/hhkb/controller.h +++ b/hhkb/controller.h @@ -3,4 +3,10 @@ #include "controller_teensy.h" + +/* matrix row size */ +#define MATRIX_ROWS 8 +/* matrix column size */ +#define MATRIX_COLS 8 + #endif diff --git a/hhkb/keymap.c b/hhkb/keymap.c index 2b887d9c7..cad601d46 100644 --- a/hhkb/keymap.c +++ b/hhkb/keymap.c @@ -6,16 +6,13 @@ #include <avr/pgmspace.h> #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,9 +31,7 @@ { 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 */ @@ -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(uint8_t fn_bits) { return (keyboard_modifier_keys == (BIT_LCTRL | BIT_LSHIFT | BIT_LALT | BIT_LGUI)); } - -void keymap_fn_proc(uint8_t fn_bits) -{ - // layer switching - static uint8_t 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"); - } -} diff --git a/hhkb/keymap.h b/hhkb/keymap.h deleted file mode 100644 index c65c2e19b..000000000 --- a/hhkb/keymap.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef KEYMAP_H -#define KEYMAP_H 1 - -#include "usb_keycodes.h" -#include "keymap_skel.h" - -#endif diff --git a/hhkb/matrix.c b/hhkb/matrix.c index d95ee1135..cf5e8a0ef 100644 --- a/hhkb/matrix.c +++ b/hhkb/matrix.c @@ -5,9 +5,10 @@ #include <stdbool.h> #include <avr/io.h> #include <util/delay.h> -#include "matrix.h" #include "print.h" #include "util.h" +#include "controller.h" +#include "matrix_skel.h" // matrix is active low. (key on: 0/key off: 1) // @@ -27,8 +28,8 @@ #define KEY_ON ((PINE&(1<<6)) ? false : true) // matrix state buffer -uint8_t *matrix; -uint8_t *matrix_prev; +static uint8_t *matrix; +static uint8_t *matrix_prev; static uint8_t _matrix0[MATRIX_ROWS]; static uint8_t _matrix1[MATRIX_ROWS]; diff --git a/hhkb/matrix.h b/hhkb/matrix.h deleted file mode 100644 index 5efffea5f..000000000 --- a/hhkb/matrix.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef MATRIX_H -#define MATRIX_H 1 - -#include <stdbool.h> -#include "matrix_skel.h" - - -#define MATRIX_ROWS 8 -#define MATRIX_COLS 8 - - -extern uint8_t *matrix; -extern uint8_t *matrix_prev; - -#endif |