aboutsummaryrefslogtreecommitdiff
path: root/hhkb
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2010-10-26 21:32:45 +0900
committertmk <nobody@nowhere>2010-10-26 21:32:45 +0900
commit461e0d3d8c82cc78d29d3115af3c417bb51bb50f (patch)
tree844b28eed904f72aa18873f25de435379fa1bad3 /hhkb
parent7a336b05ec2d1056fe2206ae218199c66e8980da (diff)
downloadqmk_firmware-461e0d3d8c82cc78d29d3115af3c417bb51bb50f.tar.gz
qmk_firmware-461e0d3d8c82cc78d29d3115af3c417bb51bb50f.zip
ADD: keymap macro for human to read easier
ADD: controller.h for controller board definition(teensy) ADD: debug toggle
Diffstat (limited to 'hhkb')
-rw-r--r--hhkb/Makefile1
-rw-r--r--hhkb/controller.h6
-rw-r--r--hhkb/keymap.c297
-rw-r--r--hhkb/matrix.c44
4 files changed, 181 insertions, 167 deletions
diff --git a/hhkb/Makefile b/hhkb/Makefile
index 980980cfe..1c6eb3db5 100644
--- a/hhkb/Makefile
+++ b/hhkb/Makefile
@@ -39,6 +39,7 @@
39# To rebuild project do "make clean" then "make all". 39# To rebuild project do "make clean" then "make all".
40#---------------------------------------------------------------------------- 40#----------------------------------------------------------------------------
41 41
42DESCRIPTION = 't.m.k. firmware for HHKB pro\n'
42 43
43# Target file name (without extension). 44# Target file name (without extension).
44TARGET = tmk_hhkb 45TARGET = tmk_hhkb
diff --git a/hhkb/controller.h b/hhkb/controller.h
new file mode 100644
index 000000000..aa862cdc1
--- /dev/null
+++ b/hhkb/controller.h
@@ -0,0 +1,6 @@
1#ifndef CONTROLLER_H
2#define CONTROLLER_H 1
3
4#include "controller_teensy.h"
5
6#endif
diff --git a/hhkb/keymap.c b/hhkb/keymap.c
index 57f20c31f..f5386b722 100644
--- a/hhkb/keymap.c
+++ b/hhkb/keymap.c
@@ -1,173 +1,156 @@
1/* 1/*
2 * keymap for HHKB pro 2 * Keymap for PFU HHKB Pro
3 */ 3 */
4#include <stdbool.h> 4#include <stdbool.h>
5#include <avr/pgmspace.h> 5#include <avr/pgmspace.h>
6#include "usb_keyboard.h" 6#include "usb_keyboard.h"
7#include "usb_keycodes.h"
7#include "matrix.h" 8#include "matrix.h"
8#include "keymap.h" 9#include "keymap.h"
9#include "print.h" 10#include "print.h"
11#include "debug.h"
12
10 13
11#define FN_KEYCODE(fn) (pgm_read_byte(&fn_keycode[(fn)])) 14#define FN_KEYCODE(fn) (pgm_read_byte(&fn_keycode[(fn)]))
12#define FN_LAYER(fn) (pgm_read_byte(&fn_layer[(fn)])) 15#define FN_LAYER(fn) (pgm_read_byte(&fn_layer[(fn)]))
13#define KEYMAPS(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)])) 16#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)]))
17#define KEYMAP( \
18 R3C1, R3C0, R0C0, R1C0, R1C1, R2C0, R2C1, R4C0, R4C1, R6C0, R6C1, R7C0, R7C1, R5C0, R5C1, \
19 R3C2, R0C1, R0C2, R1C3, R1C2, R2C3, R2C2, R4C2, R4C3, R6C2, R6C3, R7C3, R7C2, R5C2, \
20 R3C3, R0C4, R0C3, R1C4, R1C5, R2C4, R2C5, R4C5, R4C4, R6C5, R6C4, R7C4, R5C3, \
21 R3C4, R0C5, R0C6, R0C7, R1C6, R1C7, R2C6, R4C6, R6C6, R7C6, R7C5, R5C5, R5C4, \
22 R3C5, R3C6, R3C7, R5C7, R5C6 \
23) \
24{ \
25 { R0C0, R0C1, R0C2, R0C3, R0C4, R0C5, R0C6, R0C7 }, \
26 { R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7 }, \
27 { R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, KB_NO }, \
28 { R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7 }, \
29 { R4C0, R4C1, R4C2, R4C3, R4C4, R4C5, R4C6, KB_NO }, \
30 { R5C0, R5C1, R5C2, R5C3, R5C4, R5C5, R5C6, R5C7 }, \
31 { R6C0, R6C1, R6C2, R6C3, R6C4, R6C5, R6C6, KB_NO }, \
32 { R7C0, R7C1, R7C2, R7C3, R7C4, R7C5, R7C6, KB_NO } \
33}
34
35
36static int onbit(uint8_t bits);
37
14 38
15static int current_layer = 0; 39static int current_layer = 0;
16static bool layer_used = false; 40static bool layer_used = false;
17static int onbit(uint8_t bits);
18 41
19/*
20 * Layer0(Default Layer)
21 * ,-----------------------------------------------------------.
22 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
23 * |-----------------------------------------------------------|
24 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
25 * |-----------------------------------------------------------|
26 * |Contro| A| S| D| F| G| H| J| K| L|Fn3|Fn2|Return |
27 * |-----------------------------------------------------------|
28 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1|
29 * `-----------------------------------------------------------'
30 * |Gui|Alt |Space |Alt |Fn7|
31 * `-------------------------------------------'
32 *
33 * Layer1(HHKB Fn) HHKB mode
34 * ,-----------------------------------------------------------.
35 * |Pow| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
36 * |-----------------------------------------------------------|
37 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
38 * |-----------------------------------------------------------|
39 * |Contro|VoD|VoU|Mut| | | *| /|Hom|PgU|Lef|Rig|Enter |
40 * |-----------------------------------------------------------|
41 * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx|
42 * `-----------------------------------------------------------'
43 * |Gui |Alt |Space |Alt |Gui|
44 * `--------------------------------------------'
45 *
46 * Layer2(Quote/Rmeta) vi mode
47 * ,-----------------------------------------------------------.
48 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
49 * |-----------------------------------------------------------|
50 * |Tab | | | | | |Hom|PgD|PgUlEnd| | | |Backs|
51 * |-----------------------------------------------------------|
52 * |Contro| | | | | |Lef|Dow|Up |Rig| |xxx|Return |
53 * |-----------------------------------------------------------|
54 * |Shift | | | | | | | | | | |Shift | |
55 * `-----------------------------------------------------------'
56 * |Gui|Alt |Sapce |Alt |xxx|
57 * `-------------------------------------------'
58 *
59 * Layer3(Semicolon) mouse mode
60 * ,-----------------------------------------------------------.
61 * |Esc| | | | | | | | | | | | | | |
62 * |-----------------------------------------------------------|
63 * |Tab | | | | | |MwL|MwD|MwU|MwR| | | |Backs|
64 * |-----------------------------------------------------------|
65 * |Contro| | | | | |McL|McD|McU|McR|xxx| |Return |
66 * |-----------------------------------------------------------|
67 * |Shift | | | | | | |Mb1|Mb2|Mb3| |Shift | |
68 * `-----------------------------------------------------------'
69 * |Gui |Alt |Mb1 |Alt |Gui|
70 * `--------------------------------------------'
71 *
72 * Layer4(Space) Matias half keyboard style
73 * ,-----------------------------------------------------------.
74 * | -| 0| 9| 8| 7| 6| 5| 4| 3| 2| 1| | | |Esc|
75 * |-----------------------------------------------------------|
76 * |Backs| P| O| I| U| Y| T| R| E| W| Q| | |Tab |
77 * |-----------------------------------------------------------|
78 * |Contro| ;| L| K| J| H| G| F| D| S| A|Con|Control |
79 * |-----------------------------------------------------------|
80 * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | |
81 * `-----------------------------------------------------------'
82 * |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxxx|Alt |Gui|
83 * `--------------------------------------------'
84 *
85 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
86 */
87 42
88/* layer to change into while Fn key pressed */ 43/* layer to change into while Fn key pressed */
89static const int PROGMEM fn_layer[] = { 0, 1, 2, 3, 4, 0, 0, 2 }; 44static const int PROGMEM fn_layer[] = { 0, 1, 2, 3, 4, 0, 0, 0 };
90 45
91/* keycode to sent when Fn key released without using layer keys. */ 46/* keycode to sent when Fn key released without using layer keys. */
92static const uint8_t PROGMEM fn_keycode[] = { 47static const uint8_t PROGMEM fn_keycode[] = {
93 KB_NO, // FN_0 [NOT USED] 48 KB_NO, // FN_0 [NOT USED]
94 KB_NO, // FN_1 layer 1 49 KB_NO, // FN_1 layer 1
95 KB_NO, // FN_2 layer 2 50 KB_QUOTE, // FN_2 layer 2
96 KB_SCOLON, // FN_3 layer 3 51 KB_SCOLON, // FN_3 layer 3
97 KB_SPACE, // FN_4 layer 4 [NOT USED] 52 KB_SPACE, // FN_4 layer 4 [NOT USED]
98 KB_NO, // FN_5 [NOT USED] 53 KB_NO, // FN_5 [NOT USED]
99 KB_NO, // FN_6 [NOT USED] 54 KB_NO, // FN_6 [NOT USED]
100 KB_QUOTE, // FN_7 layer 2 55 KB_NO // FN_7 [NOT USED]
101}; 56};
102 57
103static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 58static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
104/* plain keymap 59 /* Layer 0: Default Layer
105 { 60 * ,-----------------------------------------------------------.
106 { KB_2, KB_Q, KB_W, KB_S, KB_A, KB_Z, KB_X, KB_C }, 61 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| \| `|
107 { KB_3, KB_4, KB_R, KB_E, KB_D, KB_F, KB_V, KB_B }, 62 * |-----------------------------------------------------------|
108 { KB_5, KB_6, KB_Y, KB_T, KB_G, KB_H, KB_N, KB_NO }, 63 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]|Backs|
109 { KB_1, KB_ESCAPE, KB_TAB, KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, KB_SPACE }, 64 * |-----------------------------------------------------------|
110 { KB_7, KB_8, KB_U, KB_I, KB_K, KB_J, KB_M, KB_NO }, 65 * |Contro| A| S| D| F| G| H| J| K| L|Fn3|Fn2|Return |
111 { KB_BSLASH, KB_GRAVE, KB_BSPACE, KB_ENTER, FN_1, KB_RSHIFT, KB_RGUI, KB_RALT }, 66 * |-----------------------------------------------------------|
112 { KB_9, KB_0, KB_O, KB_P, KB_SCOLON, KB_L, KB_COMMA, KB_NO }, 67 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1|
113 { KB_MINUS, KB_EQUAL, KB_RBRACKET,KB_LBRACKET,KB_QUOTE, KB_SLASH, KB_DOT, KB_NO }, 68 * `-----------------------------------------------------------'
114 }, 69 * |Gui|Alt |Space |Alt |Gui|
115*/ 70 * `-------------------------------------------'
116 // 0: default 71 */
117 { 72 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, \
118 { KB_2, KB_Q, KB_W, KB_S, KB_A, KB_Z, KB_X, KB_C }, 73 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, \
119 { KB_3, KB_4, KB_R, KB_E, KB_D, KB_F, KB_V, KB_B }, 74 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, \
120 { KB_5, KB_6, KB_Y, KB_T, KB_G, KB_H, KB_N, KB_NO }, 75 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, \
121 { KB_1, KB_ESCAPE, KB_TAB, KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, KB_SPACE }, 76 KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_RGUI),
122 { KB_7, KB_8, KB_U, KB_I, KB_K, KB_J, KB_M, KB_NO }, 77
123 { KB_BSLASH, KB_GRAVE, KB_BSPACE, KB_ENTER, FN_1, KB_RSHIFT, FN_2, KB_RALT }, 78 /* Layer 1: HHKB mode (HHKB Fn)
124 { KB_9, KB_0, KB_O, KB_P, FN_3, KB_L, KB_COMMA, KB_NO }, 79 * ,-----------------------------------------------------------.
125 { KB_MINUS, KB_EQUAL, KB_RBRACKET,KB_LBRACKET,FN_7, KB_SLASH, KB_DOT, KB_NO }, 80 * |Pow| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
126 }, 81 * |-----------------------------------------------------------|
127 // 1: HHKB mode(HHKB Fn) 82 * |Caps | | | | | | | |Psc|Slk|Pus|Up | |Backs|
128 { 83 * |-----------------------------------------------------------|
129 { KB_F2, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, 84 * |Contro| | | | | | *| /|Hom|PgU|Lef|Rig|Enter |
130 { KB_F3, KB_F4, KB_NO, KB_NO, KB_MUTE, KB_F20, KB_NO, KB_NO }, 85 * |-----------------------------------------------------------|
131 { KB_F5, KB_F6, KB_NO, KB_NO, KB_NO, KP_ASTERISK,KP_PLUS, KB_NO }, 86 * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx|
132 { KB_F1, KB_POWER, KB_CAPSLOCK,KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, KB_SPACE }, 87 * `-----------------------------------------------------------'
133 { KB_F7, KB_F8, KB_NO, KB_PSCREEN, KB_HOME, KP_SLASH, KB_MINUS, KB_NO }, 88 * |Gui |Alt |Space |Alt |Gui|
134 { KB_INSERT, KB_DELETE, KB_BSPACE, KP_ENTER, KB_NO, KB_RSHIFT, KB_RGUI, KB_RALT }, 89 * `--------------------------------------------'
135 { KB_F9, KB_F10, KB_SCKLOCK, KB_BREAK, KB_LEFT, KB_PGUP, KB_END, KB_NO }, 90 */
136 { KB_F11, KB_F12, KB_NO, KB_UP, KB_RIGHT, KB_DOWN, KB_PGDOWN, KB_NO }, 91 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, \
137 }, 92 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, \
138 // 2: vi mode(Quote/Rmeta) 93 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, \
139 { 94 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, \
140 { KB_F2, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, 95 KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_RGUI),
141 { KB_F3, KB_F4, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, 96
142 { KB_F5, KB_F6, KB_HOME, KB_NO, KB_NO, KB_LEFT, KB_NO, KB_NO }, 97 /* Layer 2: Vi mode (Quote/Rmeta)
143 { KB_F1, KB_ESCAPE, KB_TAB, KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, KB_SPACE }, 98 * ,-----------------------------------------------------------.
144 { KB_F7, KB_F8, KB_PGDOWN, KB_PGUP, KB_UP, KB_DOWN, KB_NO, KB_NO }, 99 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Ins|Del|
145 { KB_INSERT, KB_DELETE, KB_BSPACE, KB_ENTER, KB_NO, KB_RSHIFT, KB_NO, KB_RALT }, 100 * |-----------------------------------------------------------|
146 { KB_F9, KB_F10, KB_END, KB_NO, KB_NO, KB_RIGHT, KB_NO, KB_NO }, 101 * |Tab |Hom|PgD|Up |PgU|End|Hom|PgD|PgUlEnd| | | |Backs|
147 { KB_F11, KB_F12, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, 102 * |-----------------------------------------------------------|
148 }, 103 * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| |xxx|Return |
149 // 3: vi mouse mode(Semicolon) 104 * |-----------------------------------------------------------|
150 { 105 * |Shift | | | | | | | | | | |Shift | |
151 { KB_F2, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, 106 * `-----------------------------------------------------------'
152 { KB_F3, KB_F4, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }, 107 * |Gui|Alt |Sapce |Alt |Gui|
153 { KB_F5, KB_F6, MS_WH_LEFT, KB_NO, KB_NO, MS_LEFT, MS_BTN2, KB_NO }, 108 * `-------------------------------------------'
154 { KB_F1, KB_ESCAPE, KB_TAB, KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, MS_BTN1 }, 109 */
155 { KB_F7, KB_F8, MS_WH_DOWN, MS_WH_UP, MS_UP, MS_DOWN, MS_BTN1, KB_NO }, 110 KEYMAP(KB_ESC, 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, \
156 { KB_NO, KB_NO, KB_BSPACE, KB_ENTER, KB_NO, KB_RSHIFT, KB_RGUI, KB_RALT }, 111 KB_TAB, KB_HOME,KB_PGDN,KB_UP, KB_PGUP,KB_END, KB_HOME,KB_PGDN,KB_PGUP,KB_END, KB_NO, KB_NO, KB_NO, KB_BSPC, \
157 { KB_F9, KB_F10, MS_WH_RIGHT,KB_NO, KB_NO, MS_RIGHT, MS_BTN2, KB_NO }, 112 KB_LCTL,KB_NO, KB_LEFT,KB_DOWN,KB_RGHT,KB_NO, KB_LEFT,KB_DOWN,KB_UP, KB_RGHT,KB_NO, FN_2, KB_ENT, \
158 { KB_F11, KB_F12, KB_NO, KB_NO, KB_NO, KB_NO, MS_BTN3, KB_NO }, 113 KB_LSFT,KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_RSFT,KB_NO, \
159 }, 114 KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_RGUI),
160 // 4: Matias half keyboard style(Space) 115
161 { 116 /* Layer 3: Mouse mode (Semicolon)
162 { KB_9, KB_P, KB_O, KB_L, KB_SCOLON, KB_SLASH, KB_DOT, KB_COMMA }, 117 * ,-----------------------------------------------------------.
163 { KB_8, KB_7, KB_U, KB_I, KB_K, KB_J, KB_M, KB_N }, 118 * |Esc| | | | | | | | | | | | | | |
164 { KB_6, KB_5, KB_T, KB_Y, KB_H, KB_G, KB_B, KB_NO }, 119 * |-----------------------------------------------------------|
165 { KB_0, KB_MINUS, KB_BSPACE, KB_LCTRL, KB_LSHIFT, KB_LGUI, KB_LALT, KB_NO }, 120 * |Tab |MwL|MwU|McU|MwD|MwL|MwR|MwD|MwU|MwR| | | |Backs|
166 { KB_4, KB_3, KB_R, KB_E, KB_D, KB_F, KB_V, KB_NO }, 121 * |-----------------------------------------------------------|
167 { KB_NO, KB_ESCAPE, KB_TAB, KB_RCTRL, FN_1, KB_RSHIFT, KB_RGUI, KB_RALT }, 122 * |Contro| |McL|McD|McR| |McL|McD|McU|McR|xxx| |Return |
168 { KB_2, KB_1, KB_W, KB_Q, KB_A, KB_S, KB_C, KB_NO }, 123 * |-----------------------------------------------------------|
169 { KB_NO, KB_NO, KB_RBRACKET,KB_LBRACKET,KB_QUOTE, KB_Z, KB_X, KB_NO }, 124 * |Shift | | | | | |Mb2|Mb1|Mb2|Mb3| |Shift | |
170 }, 125 * `-----------------------------------------------------------'
126 * |Gui |Alt |Mb1 |Alt |Gui|
127 * `--------------------------------------------'
128 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
129 */
130 KEYMAP(KB_ESC, 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, \
131 KB_TAB, MS_WH_L,MS_WH_U,MS_UP, MS_WH_D,MS_WH_R,MS_WH_L,MS_WH_D,MS_WH_U,MS_WH_R,KB_NO, KB_NO, KB_NO, KB_BSPC, \
132 KB_LCTL,KB_NO, MS_LEFT,MS_DOWN,MS_RGHT,KB_NO, MS_LEFT,MS_DOWN,MS_UP, MS_RGHT,FN_3, KB_NO, KB_ENT, \
133 KB_LSFT,KB_NO, MS_DOWN,KB_NO, KB_NO, KB_NO, MS_BTN2,MS_BTN1,MS_BTN2,MS_BTN3,KB_NO, KB_RSFT,KB_NO, \
134 KB_LGUI,KB_LALT,MS_BTN1,KB_RALT,KB_RGUI),
135
136 /* Layer 4: Matias half keyboard style (Space)
137 * ,-----------------------------------------------------------.
138 * | -| 0| 9| 8| 7| 6| 5| 4| 3| 2| 1| | | |Esc|
139 * |-----------------------------------------------------------|
140 * |Backs| P| O| I| U| Y| T| R| E| W| Q| | |Tab |
141 * |-----------------------------------------------------------|
142 * |Contro| ;| L| K| J| H| G| F| D| S| A|Con|Control |
143 * |-----------------------------------------------------------|
144 * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | |
145 * `-----------------------------------------------------------'
146 * |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxxx|Alt |Gui|
147 * `--------------------------------------------'
148 */
149 KEYMAP(KB_MINS,KB_0, KB_9, KB_8, KB_7, KB_6, KB_5, KB_4, KB_3, KB_2, KB_1, KB_NO, KB_NO, KB_NO, KB_ESC, \
150 KB_BSPC,KB_P, KB_O, KB_I, KB_U, KB_Y, KB_T, KB_R, KB_E, KB_W, KB_Q, KB_NO, KB_NO, KB_TAB, \
151 KB_LCTL,KB_SCLN,KB_L, KB_K, KB_J, KB_H, KB_G, KB_F, KB_D, KB_S, KB_A, KB_RCTL,KB_RCTL, \
152 KB_LSFT,KB_SLSH,KB_DOT, KB_COMM,KB_M, KB_N, KB_B, KB_V, KB_C, KB_X, KB_Z, KB_RSFT,KB_NO, \
153 KB_LGUI,KB_LALT,FN_4, KB_RALT,KB_RGUI)
171}; 154};
172 155
173 156
@@ -178,26 +161,34 @@ uint8_t keymap_get_keycode(int row, int col)
178 161
179uint8_t keymap_get_keycodel(int layer, int row, int col) 162uint8_t keymap_get_keycodel(int layer, int row, int col)
180{ 163{
181 uint8_t code = KEYMAPS(layer, row, col); 164 uint8_t code = KEYCODE(layer, row, col);
182 // normal key or mouse key 165 // normal key or mouse key
183 if ((KB_A <= code && code <= KP_HEXADECIMAL) || 166 if (IS_KEY(code) || IS_MOUSE(code))
184 (MS_UP <= code && code <= MS_WH_RIGHT))
185 layer_used = true; 167 layer_used = true;
186 return code; 168 return code;
187} 169}
188 170
189inline 171inline
190int keymap_get_layer(void) { 172int keymap_get_layer(void)
173{
191 return current_layer; 174 return current_layer;
192} 175}
193 176
194inline 177inline
195int keymap_set_layer(int layer) { 178int keymap_set_layer(int layer)
179{
196 current_layer = layer; 180 current_layer = layer;
197 return current_layer; 181 return current_layer;
198} 182}
199 183
200void keymap_fn_proc(int fn_bits) { 184inline
185bool keymap_is_special_mode(int fn_bits)
186{
187 return (keyboard_modifier_keys == (BIT_LCTRL | BIT_LSHIFT | BIT_LALT | BIT_LGUI));
188}
189
190void keymap_fn_proc(int fn_bits)
191{
201 // layer switching 192 // layer switching
202 static int last_bits = 0; 193 static int last_bits = 0;
203 static uint8_t last_mod = 0; 194 static uint8_t last_mod = 0;
@@ -210,7 +201,7 @@ void keymap_fn_proc(int fn_bits) {
210 if (!layer_used) { 201 if (!layer_used) {
211 uint8_t code = FN_KEYCODE(onbit(last_bits)); 202 uint8_t code = FN_KEYCODE(onbit(last_bits));
212 if (code != KB_NO) { 203 if (code != KB_NO) {
213 if (KB_LCTRL <= code && code <= KB_RGUI) { 204 if (IS_MOD(code)) {
214 keyboard_modifier_keys = last_mod | 1<<(code & 0x07); 205 keyboard_modifier_keys = last_mod | 1<<(code & 0x07);
215 } else { 206 } else {
216 keyboard_keys[0] = code; 207 keyboard_keys[0] = code;
@@ -225,20 +216,20 @@ void keymap_fn_proc(int fn_bits) {
225 last_mod = 0; 216 last_mod = 0;
226 layer_used = false; 217 layer_used = false;
227 keymap_set_layer(0); // default layer 218 keymap_set_layer(0); // default layer
228 print("layer default: "); phex(current_layer); print("\n");
229 } else if ((fn_bits & (fn_bits - 1)) == 0) { 219 } else if ((fn_bits & (fn_bits - 1)) == 0) {
230 // switch layer when just one Fn Key is pressed 220 // switch layer when just one Fn Key is pressed
231 last_bits = fn_bits; 221 last_bits = fn_bits;
232 last_mod = keyboard_modifier_keys; 222 last_mod = keyboard_modifier_keys;
233 layer_used = false; 223 layer_used = false;
234 keymap_set_layer(FN_LAYER(onbit(fn_bits))); 224 keymap_set_layer(FN_LAYER(onbit(fn_bits)));
235 print("layer: "); phex(current_layer); print("\n"); 225 debug("layer: "); phex(current_layer); debug("(");
236 print("last_bits: "); phex(last_bits); print("\n"); 226 debug_bin(last_bits); debug(")\n");
237 print("last_mod: "); phex(last_mod); print("\n"); 227 debug("last_mod: "); debug_hex(last_mod); debug("\n");
238 } 228 }
239} 229}
240 230
241static int onbit(uint8_t bits) { 231static int onbit(uint8_t bits)
232{
242 int n = 0; 233 int n = 0;
243 if (bits >> 4) { bits >>= 4; n += 4;} 234 if (bits >> 4) { bits >>= 4; n += 4;}
244 if (bits >> 2) { bits >>= 2; n += 2;} 235 if (bits >> 2) { bits >>= 2; n += 2;}
diff --git a/hhkb/matrix.c b/hhkb/matrix.c
index a64065560..d8dc9a7f8 100644
--- a/hhkb/matrix.c
+++ b/hhkb/matrix.c
@@ -35,12 +35,14 @@ static int bit_pop(uint8_t bits);
35 35
36 36
37inline 37inline
38int matrix_rows(void) { 38int matrix_rows(void)
39{
39 return MATRIX_ROWS; 40 return MATRIX_ROWS;
40} 41}
41 42
42inline 43inline
43int matrix_cols(void) { 44int matrix_cols(void)
45{
44 return MATRIX_COLS; 46 return MATRIX_COLS;
45} 47}
46 48
@@ -55,8 +57,8 @@ void matrix_init(void)
55 PORTE = 0xC0; 57 PORTE = 0xC0;
56 58
57 // initialize matrix state: all keys off 59 // initialize matrix state: all keys off
58 for (int i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0xFF; 60 for (int i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
59 for (int i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0xFF; 61 for (int i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00;
60 matrix = _matrix0; 62 matrix = _matrix0;
61 matrix_prev = _matrix1; 63 matrix_prev = _matrix1;
62} 64}
@@ -76,9 +78,9 @@ int matrix_scan(void)
76 KEY_ENABLE; 78 KEY_ENABLE;
77 _delay_us(10); // from logic analyzer chart 79 _delay_us(10); // from logic analyzer chart
78 if (KEY_ON) { 80 if (KEY_ON) {
79 matrix[row] &= ~(1<<col);
80 } else {
81 matrix[row] |= (1<<col); 81 matrix[row] |= (1<<col);
82 } else {
83 matrix[row] &= ~(1<<col);
82 } 84 }
83 KEY_UNABLE; 85 KEY_UNABLE;
84 _delay_us(150); // from logic analyzer chart 86 _delay_us(150); // from logic analyzer chart
@@ -87,7 +89,8 @@ int matrix_scan(void)
87 return 1; 89 return 1;
88} 90}
89 91
90bool matrix_is_modified(void) { 92bool matrix_is_modified(void)
93{
91 for (int i = 0; i < MATRIX_ROWS; i++) { 94 for (int i = 0; i < MATRIX_ROWS; i++) {
92 if (matrix[i] != matrix_prev[i]) 95 if (matrix[i] != matrix_prev[i])
93 return true; 96 return true;
@@ -96,16 +99,25 @@ bool matrix_is_modified(void) {
96} 99}
97 100
98inline 101inline
99bool matrix_has_ghost(void) { 102bool matrix_has_ghost(void)
103{
100 return false; 104 return false;
101} 105}
102 106
103inline 107inline
104uint16_t matrix_get_row(int row) { 108bool matrix_is_on(int row, int col)
109{
110 return (matrix[row] & (1<<col));
111}
112
113inline
114uint16_t matrix_get_row(int row)
115{
105 return matrix[row]; 116 return matrix[row];
106} 117}
107 118
108void matrix_print(void) { 119void matrix_print(void)
120{
109 print("\nr/c 01234567\n"); 121 print("\nr/c 01234567\n");
110 for (int row = 0; row < matrix_rows(); row++) { 122 for (int row = 0; row < matrix_rows(); row++) {
111 phex(row); print(": "); 123 phex(row); print(": ");
@@ -117,20 +129,24 @@ void matrix_print(void) {
117 } 129 }
118} 130}
119 131
120int matrix_key_count(void) { 132int matrix_key_count(void)
133{
121 int count = 0; 134 int count = 0;
122 for (int i = 0; i < MATRIX_ROWS; i++) { 135 for (int i = 0; i < MATRIX_ROWS; i++) {
123 count += bit_pop(~matrix[i]); 136 count += bit_pop(matrix[i]);
124 } 137 }
125 return count; 138 return count;
126} 139}
127 140
128inline 141inline
129static bool matrix_has_ghost_in_row(int row) { 142static bool matrix_has_ghost_in_row(int row)
143{
130 return false; 144 return false;
131} 145}
132 146
133static int bit_pop(uint8_t bits) { 147inline
148static int bit_pop(uint8_t bits)
149{
134 int c; 150 int c;
135 for (c = 0; bits; c++) 151 for (c = 0; bits; c++)
136 bits &= bits -1; 152 bits &= bits -1;