aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2010-10-27 20:51:45 +0900
committertmk <nobody@nowhere>2010-10-27 22:56:01 +0900
commit2f80e790c6310ad24a4cb3d4a72c31314364fef7 (patch)
treeaad001abdb61ff736e580f98184ab7cd9e870648
parent461e0d3d8c82cc78d29d3115af3c417bb51bb50f (diff)
downloadqmk_firmware-2f80e790c6310ad24a4cb3d4a72c31314364fef7.tar.gz
qmk_firmware-2f80e790c6310ad24a4cb3d4a72c31314364fef7.zip
new build method for macway
-rw-r--r--Makefile.common33
-rw-r--r--README20
-rw-r--r--hhkb/Makefile8
-rw-r--r--hhkb/keymap.c22
-rw-r--r--hhkb/keymap.h2
-rw-r--r--hhkb/matrix.c27
-rw-r--r--key_process.c9
-rw-r--r--macway/Makefile14
-rw-r--r--macway/controller.h6
-rw-r--r--macway/keymap.c335
-rw-r--r--macway/keymap.h15
-rw-r--r--macway/matrix.c90
-rw-r--r--macway/matrix.h15
-rw-r--r--tmk.c9
-rw-r--r--usb.c22
-rw-r--r--util.c18
-rw-r--r--util.h14
17 files changed, 432 insertions, 227 deletions
diff --git a/Makefile.common b/Makefile.common
index df367128b..5febcd758 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -56,7 +56,8 @@ SRC = tmk.c \
56 usb_debug.c \ 56 usb_debug.c \
57 usb.c \ 57 usb.c \
58 jump_bootloader.c \ 58 jump_bootloader.c \
59 print.c 59 print.c \
60 util.c
60SRC += $(TARGET_SRC) 61SRC += $(TARGET_SRC)
61 62
62# C source file search path 63# C source file search path
@@ -116,17 +117,41 @@ CSTANDARD = -std=gnu99
116 117
117 118
118# Place -D or -U options here for C sources 119# Place -D or -U options here for C sources
119CDEFS = -DF_CPU=$(F_CPU)UL -DDESCRIPTION=$(DESCRIPTION) 120CDEFS = -DF_CPU=$(F_CPU)UL
121CDEFS += -DDESCRIPTION=$(DESCRIPTION)
122CDEFS += -DVENDOR_ID=$(VENDOR_ID)
123CDEFS += -DPRODUCT_ID=$(PRODUCT_ID)
124CDEFS += -DMANUFACTURER=$(MANUFACTURER)
125CDEFS += -DPRODUCT=$(PRODUCT)
126ifdef MOUSE_DELAY_TIME
127CDEFS += -DMOUSE_DELAY_TIME=$(MOUSE_DELAY_TIME)
128endif
120 129
121 130
122# Place -D or -U options here for ASM sources 131# Place -D or -U options here for ASM sources
123ADEFS = -DF_CPU=$(F_CPU) -DDESCRIPTION=$(DESCRIPTION) 132ADEFS = -DF_CPU=$(F_CPU)
133ADEFS += -DDESCRIPTION=$(DESCRIPTION)
134ADEFS += -DVENDOR_ID=$(VENDOR_ID)
135ADEFS += -DPRODUCT_ID=$(PRODUCT_ID)
136ADEFS += -DMANUFACTURER=$(MANUFACTURER)
137ADEFS += -DPRODUCT=$(PRODUCT)
138ifdef MOUSE_DELAY_TIME
139ADEFS += -DMOUSE_DELAY_TIME=$(MOUSE_DELAY_TIME)
140endif
124 141
125 142
126# Place -D or -U options here for C++ sources 143# Place -D or -U options here for C++ sources
127CPPDEFS = -DF_CPU=$(F_CPU)UL -DDESCRIPTION=$(DESCRIPTION) 144CPPDEFS = -DF_CPU=$(F_CPU)UL -DDESCRIPTION=$(DESCRIPTION) -DVENDOR_ID=$(VENDOR_ID) -DPRODUCT_ID=$(PRODUCT_ID)
128#CPPDEFS += -D__STDC_LIMIT_MACROS 145#CPPDEFS += -D__STDC_LIMIT_MACROS
129#CPPDEFS += -D__STDC_CONSTANT_MACROS 146#CPPDEFS += -D__STDC_CONSTANT_MACROS
147CPPDEFS += -DDESCRIPTION=$(DESCRIPTION)
148CPPDEFS += -DVENDOR_ID=$(VENDOR_ID)
149CPPDEFS += -DPRODUCT_ID=$(PRODUCT_ID)
150CPPDEFS += -DMANUFACTURER=$(MANUFACTURER)
151CPPDEFS += -DPRODUCT=$(PRODUCT)
152ifdef MOUSE_DELAY_TIME
153CPPDEFS += -DMOUSE_DELAY_TIME=$(MOUSE_DELAY_TIME)
154endif
130 155
131 156
132 157
diff --git a/README b/README
index 9bc883410..1d78fa45a 100644
--- a/README
+++ b/README
@@ -93,21 +93,12 @@ debouncing logic
93layer switching 93layer switching
94 time before switching 94 time before switching
95 timeout when not used during specific time 95 timeout when not used during specific time
96debug on/off
97 Fn key conbination during normal operation
98 matrix print on/off
99 key print on/off
100 mouse print on/off
101 96
102Trackpoint(PS/2) 97Trackpoint(PS/2)
103 receive PS/2 signal from TrackPoint 98 receive PS/2 signal from TrackPoint
104 send USB HID report 99 send USB HID report
105Thinkpad keyboard support 100Thinkpad keyboard support
106 turn keyboard to USB keyboard/mouse composite device 101 turn keyboard to USB keyboard/mouse composite device
107mouse horizontal wheel
108 http://www.microchip.com/forums/tm.aspx?high=&m=391435&mpage=1#391521
109 http://www.keil.com/forum/15671/
110 http://www.microsoft.com/whdc/device/input/wheel.mspx
111setting menu(configure without changing firmware) 102setting menu(configure without changing firmware)
112 console for display 103 console for display
113 keymap/layer setting 104 keymap/layer setting
@@ -131,6 +122,17 @@ debug on/off
131 debug off by default 122 debug off by default
132 pressing keys during booting 123 pressing keys during booting
133 2010/10/23 124 2010/10/23
125mouse horizontal wheel
126 http://www.microchip.com/forums/tm.aspx?high=&m=391435&mpage=1#391521
127 http://www.keil.com/forum/15671/
128 http://www.microsoft.com/whdc/device/input/wheel.mspx
129 2010/10/13
130debug on/off
131 Fn key conbination during normal operation
132 matrix print on/off
133 key print on/off
134 mouse print on/off
135 2010/10/26
134 136
135 137
136EOF 138EOF
diff --git a/hhkb/Makefile b/hhkb/Makefile
index 1c6eb3db5..7339e7023 100644
--- a/hhkb/Makefile
+++ b/hhkb/Makefile
@@ -39,7 +39,13 @@
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' 42VENDOR_ID = 0xFEED
43PRODUCT_ID = 0xCAFE
44MANUFACTURER = 't.m.k.'
45PRODUCT = 't.m.k. HHKB pro'
46DESCRIPTION = 't.m.k. firmware for HHKB pro'
47
48MOUSE_DELAY_TIME = 127
43 49
44# Target file name (without extension). 50# Target file name (without extension).
45TARGET = tmk_hhkb 51TARGET = tmk_hhkb
diff --git a/hhkb/keymap.c b/hhkb/keymap.c
index f5386b722..ca78200c0 100644
--- a/hhkb/keymap.c
+++ b/hhkb/keymap.c
@@ -1,14 +1,16 @@
1/* 1/*
2 * Keymap for PFU HHKB Pro 2 * Keymap for PFU HHKB Pro
3 */ 3 */
4#include <stdint.h>
4#include <stdbool.h> 5#include <stdbool.h>
5#include <avr/pgmspace.h> 6#include <avr/pgmspace.h>
6#include "usb_keyboard.h" 7#include "usb_keyboard.h"
7#include "usb_keycodes.h" 8#include "usb_keycodes.h"
8#include "matrix.h" 9#include "matrix.h"
9#include "keymap.h"
10#include "print.h" 10#include "print.h"
11#include "debug.h" 11#include "debug.h"
12#include "util.h"
13#include "keymap.h"
12 14
13 15
14#define FN_KEYCODE(fn) (pgm_read_byte(&fn_keycode[(fn)])) 16#define FN_KEYCODE(fn) (pgm_read_byte(&fn_keycode[(fn)]))
@@ -33,9 +35,6 @@
33} 35}
34 36
35 37
36static int onbit(uint8_t bits);
37
38
39static int current_layer = 0; 38static int current_layer = 0;
40static bool layer_used = false; 39static bool layer_used = false;
41 40
@@ -104,7 +103,7 @@ static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
104 * |-----------------------------------------------------------| 103 * |-----------------------------------------------------------|
105 * |Shift | | | | | | | | | | |Shift | | 104 * |Shift | | | | | | | | | | |Shift | |
106 * `-----------------------------------------------------------' 105 * `-----------------------------------------------------------'
107 * |Gui|Alt |Sapce |Alt |Gui| 106 * |Gui|Alt |Space |Alt |Gui|
108 * `-------------------------------------------' 107 * `-------------------------------------------'
109 */ 108 */
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, \ 109 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, \
@@ -199,7 +198,7 @@ void keymap_fn_proc(int fn_bits)
199 } else if (fn_bits == 0) { 198 } else if (fn_bits == 0) {
200 // send key when Fn key is released without using the layer 199 // send key when Fn key is released without using the layer
201 if (!layer_used) { 200 if (!layer_used) {
202 uint8_t code = FN_KEYCODE(onbit(last_bits)); 201 uint8_t code = FN_KEYCODE(biton(last_bits));
203 if (code != KB_NO) { 202 if (code != KB_NO) {
204 if (IS_MOD(code)) { 203 if (IS_MOD(code)) {
205 keyboard_modifier_keys = last_mod | 1<<(code & 0x07); 204 keyboard_modifier_keys = last_mod | 1<<(code & 0x07);
@@ -221,18 +220,9 @@ void keymap_fn_proc(int fn_bits)
221 last_bits = fn_bits; 220 last_bits = fn_bits;
222 last_mod = keyboard_modifier_keys; 221 last_mod = keyboard_modifier_keys;
223 layer_used = false; 222 layer_used = false;
224 keymap_set_layer(FN_LAYER(onbit(fn_bits))); 223 keymap_set_layer(FN_LAYER(biton(fn_bits)));
225 debug("layer: "); phex(current_layer); debug("("); 224 debug("layer: "); phex(current_layer); debug("(");
226 debug_bin(last_bits); debug(")\n"); 225 debug_bin(last_bits); debug(")\n");
227 debug("last_mod: "); debug_hex(last_mod); debug("\n"); 226 debug("last_mod: "); debug_hex(last_mod); debug("\n");
228 } 227 }
229} 228}
230
231static int onbit(uint8_t bits)
232{
233 int n = 0;
234 if (bits >> 4) { bits >>= 4; n += 4;}
235 if (bits >> 2) { bits >>= 2; n += 2;}
236 if (bits >> 1) { bits >>= 1; n += 1;}
237 return n;
238}
diff --git a/hhkb/keymap.h b/hhkb/keymap.h
index a577c79b9..c65c2e19b 100644
--- a/hhkb/keymap.h
+++ b/hhkb/keymap.h
@@ -1,8 +1,6 @@
1#ifndef KEYMAP_H 1#ifndef KEYMAP_H
2#define KEYMAP_H 1 2#define KEYMAP_H 1
3 3
4#include <stdint.h>
5#include <stdbool.h>
6#include "usb_keycodes.h" 4#include "usb_keycodes.h"
7#include "keymap_skel.h" 5#include "keymap_skel.h"
8 6
diff --git a/hhkb/matrix.c b/hhkb/matrix.c
index d8dc9a7f8..d95ee1135 100644
--- a/hhkb/matrix.c
+++ b/hhkb/matrix.c
@@ -1,10 +1,13 @@
1/* 1/*
2 * scan matrix 2 * scan matrix
3 */ 3 */
4#include <stdint.h>
5#include <stdbool.h>
4#include <avr/io.h> 6#include <avr/io.h>
5#include <util/delay.h> 7#include <util/delay.h>
6#include "matrix.h" 8#include "matrix.h"
7#include "print.h" 9#include "print.h"
10#include "util.h"
8 11
9// matrix is active low. (key on: 0/key off: 1) 12// matrix is active low. (key on: 0/key off: 1)
10// 13//
@@ -30,10 +33,6 @@ static uint8_t _matrix0[MATRIX_ROWS];
30static uint8_t _matrix1[MATRIX_ROWS]; 33static uint8_t _matrix1[MATRIX_ROWS];
31 34
32 35
33static bool matrix_has_ghost_in_row(int row);
34static int bit_pop(uint8_t bits);
35
36
37inline 36inline
38int matrix_rows(void) 37int matrix_rows(void)
39{ 38{
@@ -122,9 +121,6 @@ void matrix_print(void)
122 for (int row = 0; row < matrix_rows(); row++) { 121 for (int row = 0; row < matrix_rows(); row++) {
123 phex(row); print(": "); 122 phex(row); print(": ");
124 pbin_reverse(matrix_get_row(row)); 123 pbin_reverse(matrix_get_row(row));
125 if (matrix_has_ghost_in_row(row)) {
126 print(" <ghost");
127 }
128 print("\n"); 124 print("\n");
129 } 125 }
130} 126}
@@ -133,22 +129,7 @@ int matrix_key_count(void)
133{ 129{
134 int count = 0; 130 int count = 0;
135 for (int i = 0; i < MATRIX_ROWS; i++) { 131 for (int i = 0; i < MATRIX_ROWS; i++) {
136 count += bit_pop(matrix[i]); 132 count += bitpop(matrix[i]);
137 } 133 }
138 return count; 134 return count;
139} 135}
140
141inline
142static bool matrix_has_ghost_in_row(int row)
143{
144 return false;
145}
146
147inline
148static int bit_pop(uint8_t bits)
149{
150 int c;
151 for (c = 0; bits; c++)
152 bits &= bits -1;
153 return c;
154}
diff --git a/key_process.c b/key_process.c
index e4f2326e9..e4d66e303 100644
--- a/key_process.c
+++ b/key_process.c
@@ -17,8 +17,11 @@
17 17
18#define MOUSE_MOVE_UNIT 10 18#define MOUSE_MOVE_UNIT 10
19#define MOUSE_MOVE_ACCEL (mouse_repeat < 50 ? mouse_repeat/5 : 10) 19#define MOUSE_MOVE_ACCEL (mouse_repeat < 50 ? mouse_repeat/5 : 10)
20#define MOUSE_DELAY_TIME 255 20
21#define MOUSE_DELAY_MS (MOUSE_DELAY_TIME >> (mouse_repeat < 5 ? mouse_repeat : 5)) 21#ifndef MOUSE_DELAY_TIME
22# define MOUSE_DELAY_TIME 255
23#endif
24#define MOUSE_DELAY_MS (MOUSE_DELAY_TIME >> (mouse_repeat < 5 ? mouse_repeat : 4))
22 25
23 26
24// TODO: refactoring 27// TODO: refactoring
@@ -157,7 +160,7 @@ void proc_matrix(void) {
157 case KB_V: // print version & information 160 case KB_V: // print version & information
158 usb_keyboard_clear(); 161 usb_keyboard_clear();
159 usb_keyboard_send(); 162 usb_keyboard_send();
160 print(XSTR(DESCRIPTION)); 163 print(STR(DESCRIPTION) "\n");
161 _delay_ms(1000); 164 _delay_ms(1000);
162 break; 165 break;
163 } 166 }
diff --git a/macway/Makefile b/macway/Makefile
index 7559b2b05..b69b2d2e4 100644
--- a/macway/Makefile
+++ b/macway/Makefile
@@ -39,14 +39,24 @@
39# To rebuild project do "make clean" then "make all". 39# To rebuild project do "make clean" then "make all".
40#---------------------------------------------------------------------------- 40#----------------------------------------------------------------------------
41 41
42VENDOR_ID = 0xFEED
43PRODUCT_ID = 0xBEEF
44MANUFACTURER = 't.m.k.'
45PRODUCT = 't.m.k. Macway mod'
46DESCRIPTION = 't.m.k. firmware for Macway mod'
42 47
43# Target file name (without extension). 48# Target file name (without extension).
44TARGET = tmk_macway 49TARGET = tmk_macway
45 50
51# Directory common source filess exist
46COMMON_DIR = .. 52COMMON_DIR = ..
53
54# Directory keyboard dependent files exist
47TARGET_DIR = . 55TARGET_DIR = .
48TARGET_SRC = $(TARGET_DIR)/keymap.c \ 56
49 $(TARGET_DIR)/matrix.c 57# keyboard dependent files
58TARGET_SRC = keymap.c \
59 matrix.c
50 60
51 61
52# MCU name, you MUST set this to match the board you are using 62# MCU name, you MUST set this to match the board you are using
diff --git a/macway/controller.h b/macway/controller.h
new file mode 100644
index 000000000..aa862cdc1
--- /dev/null
+++ b/macway/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/macway/keymap.c b/macway/keymap.c
index c690ce43a..09dafc5c8 100644
--- a/macway/keymap.c
+++ b/macway/keymap.c
@@ -1,140 +1,227 @@
1/* 1/*
2 * keymap for modified Macway 2 * Keymap for Macway mod
3 */ 3 */
4#include <stdint.h>
4#include <stdbool.h> 5#include <stdbool.h>
5#include <avr/pgmspace.h> 6#include <avr/pgmspace.h>
7#include "usb_keyboard.h"
8#include "usb_keycodes.h"
6#include "matrix.h" 9#include "matrix.h"
10#include "print.h"
11#include "debug.h"
12#include "util.h"
7#include "keymap.h" 13#include "keymap.h"
8#include "usb_keyboard.h"
9 14
10int current_layer = 0; 15
11bool key_sent = false; 16#define FN_KEYCODE(fn) (pgm_read_byte(&fn_keycode[(fn)]))
12 17#define FN_LAYER(fn) (pgm_read_byte(&fn_layer[(fn)]))
13/* 18#define KEYCODE(layer, row, col) (pgm_read_byte(&keymaps[(layer)][(row)][(col)]))
14 * Layer0(Default Layer) 19#define KEYMAP( \
15 * ,----------------------------------------------------------. 20 R1C1, R1C0, R2C0, R3C0, R4C0, R4C1, R5C1, R5C0, R6C0, R7C0, R8C0, R8C1, R6C1, R0C2, \
16 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp| 21 R1C2, R1C3, R2C3, R3C3, R4C3, R4C2, R5C2, R5C3, R6C3, R7C3, R8C3, R8C2, R6C2, \
17 * |----------------------------------------------------------| 22 R1C5, R1C4, R2C4, R3C4, R4C4, R4C5, R5C5, R5C4, R6C4, R7C4, R8C4, R8C5, R0C6, \
18 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| | 23 R6C7, R1C6, R2C6, R3C6, R4C6, R4C7, R5C7, R5C6, R6C6, R7C6, R8C7, R3C2, R3C5, \
19 * |----------------------------------------------------' | 24 R7C5, R2C2, R0C0, R0C7, R2C1, R0C4, R3C7, R2C7, R1C7 \
20 * |Contr| A| S| D| F| G| H| J| K| L| ;| '|Return | 25) { \
21 * |----------------------------------------------------------| 26 { R0C0, KB_NO, R0C2, KB_NO, R0C4, KB_NO, R0C6, R0C7 }, \
22 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn2| 27 { R1C0, R1C1, R1C2, R1C3, R1C4, R1C5, R1C6, R1C7 }, \
23 * |----------------------------------------------------------| 28 { R2C0, R2C1, R2C2, R2C3, R2C4, KB_NO, R2C6, R2C7 }, \
24 * |Fn3|Gui |Alt |Space |Fn1 |Lef|Dow|Up |Rig| 29 { R3C0, KB_NO, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7 }, \
25 * `----------------------------------------------------------' 30 { R4C0, R4C1, R4C2, R4C3, R4C4, R4C5, R4C6, R4C7 }, \
26 * 31 { R5C0, R5C1, R5C2, R5C3, R5C4, R5C5, R5C6, R5C7 }, \
27 * Layer1(with Fn1) 32 { R6C0, R6C1, R6C2, R6C3, R6C4, KB_NO, R6C6, R6C7 }, \
28 * ,----------------------------------------------------------. 33 { R7C0, KB_NO, KB_NO, R7C3, R7C4, R7C5, R7C6, KB_NO }, \
29 * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete| 34 { R8C0, R8C1, R8C2, R8C3, R8C4, R8C5, KB_NO, R8C7 } \
30 * |----------------------------------------------------------| 35}
31 * | \ | | | | | | | | | | | | | | 36
32 * |----------------------------------------------------' | 37
33 * |Contr| | | | | |Lef|Dow|Up |Rig| | | \ | 38static int current_layer = 0;
34 * |----------------------------------------------------------| 39static bool layer_used = false;
35 * |Shift | | | | | |Hom|PgD|PgU|End| |Shift | | 40
36 * |----------------------------------------------------------| 41/* layer to change into while Fn key pressed */
37 * | |Gui |Alt | |Fn1 |Lef|Dow|Up |Rig| 42static const int PROGMEM fn_layer[] = { 0, 1, 2, 3, 4, 0, 2, 3 };
38 * `----------------------------------------------------------' 43
39 * 44/* keycode to sent when Fn key released without using layer keys. */
40 * Layer2(with Fn2) 45static const uint8_t PROGMEM fn_keycode[] = {
41 * ,----------------------------------------------------------. 46 KB_NO, // FN_0 [NOT USED]
42 * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete| 47 KB_NO, // FN_1 layer 1
43 * |----------------------------------------------------------| 48 KB_QUOTE, // FN_2 layer 2
44 * | \ | | | | | | | | | | |Up | | | 49 KB_SCOLON, // FN_3 layer 3
45 * |----------------------------------------------------' | 50 KB_SPACE, // FN_4 layer 4 [NOT USED]
46 * |Contr|VoD|VoU|Mut|F20| | *| /|Hom|PgU|Lef|Rig| \ | 51 KB_NO, // FN_5 [NOT USED]
47 * |----------------------------------------------------------| 52 KB_NO, // FN_6 layer 2
48 * |Shift | | | | | | +| -|End|PgD|Dow|Shift |Fn2| 53 KB_NO // FN_7 layer 3
49 * |----------------------------------------------------------|
50 * | |Gui |Alt | | |Lef|Dow|Up |Rig|
51 * `----------------------------------------------------------'
52 *
53 * Layer3(with Fn3)
54 * ,----------------------------------------------------------.
55 * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete|
56 * |----------------------------------------------------------|
57 * | \ | | | | | | | | | | | | | |
58 * |----------------------------------------------------' |
59 * |Contr|Mb1|Mb2|Mb3| | |McL|McD|McU|McR| | | \ |
60 * |----------------------------------------------------------|
61 * |Shift | | | | | |MwL|MwD|MwU|MwR| |Shift | |
62 * |----------------------------------------------------------|
63 * | |Gui |Alt |Mb1 |Mb2 |MsL|MsD|MsU|MsR|
64 * `----------------------------------------------------------'
65 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
66 */
67static const uint8_t PROGMEM Keymap[][MATRIX_ROWS][MATRIX_COLS] = {
68 // 0: default
69 {
70 { KB_LALT, KB_NO, KB_BSPACE, KB_NO, KB_LEFT, KB_NO, KB_ENTER, KB_SPACE },
71 { KB_1, KB_ESCAPE, KB_TAB, KB_Q, KB_A, KB_LCTRL, KB_Z, KB_RIGHT },
72 { KB_2, FN_1, KB_LGUI, KB_W, KB_S, KB_NO, KB_X, KB_UP },
73 { KB_3, KB_NO, KB_RSHIFT, KB_E, KB_D, FN_2, KB_C, KB_DOWN },
74 { KB_4, KB_5, KB_T, KB_R, KB_F, KB_G, KB_V, KB_B },
75 { KB_7, KB_6, KB_Y, KB_U, KB_J, KB_H, KB_M, KB_N },
76 { KB_8, KB_EQUAL, KB_RBRACKET,KB_I, KB_K, KB_NO, KB_COMMA, KB_LSHIFT },
77 { KB_9, KB_NO, KB_NO, KB_O, KB_L, FN_3, KB_DOT, KB_NO },
78 { KB_0, KB_MINUS, KB_LBRACKET,KB_P, KB_SCOLON, KB_QUOTE, KB_NO, KB_SLASH }
79 },
80 // 1: FN_1(RIGHT ALT)
81 {
82 { KB_LALT, KB_NO, KB_DELETE, KB_NO, KB_NO, KB_NO, KB_BSLASH,KB_NO },
83 { KB_F1, KB_GRAVE, KB_BSLASH, KB_NO, KB_NO, KB_LCTRL, KB_NO, KB_NO },
84 { KB_F2, KB_NO, KB_LGUI, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO },
85 { KB_F3, KB_NO, KB_RSHIFT, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO },
86 { KB_F4, KB_F5, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO },
87 { KB_F7, KB_F6, KB_NO, KB_NO, KB_DOWN, KB_LEFT, KB_PGDOWN,KB_HOME },
88 { KB_F8, KB_F12, KB_NO, KB_NO, KB_UP, KB_NO, KB_PGUP, KB_LSHIFT },
89 { KB_F9, KB_NO, KB_NO, KB_NO, KB_RIGHT, KB_NO, KB_END, KB_NO },
90 { KB_F10, KB_F11, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }
91 },
92 // 2: FN_2(HHKB Fn)
93 {
94 { KB_LALT, KB_NO, KB_DELETE, KB_NO, KB_NO, KB_NO, KB_BSLASH,KB_NO },
95 { KB_F1, KB_GRAVE, KB_BSLASH, KB_NO, KB_VOLDOWN,KB_LCTRL, KB_NO, KB_NO },
96 { KB_F2, KB_NO, KB_LGUI, KB_NO, KB_VOLUP, KB_NO, KB_NO, KB_NO },
97 { KB_F3, KB_NO, KB_RSHIFT, KB_NO, KB_MUTE, KB_NO, KB_NO, KB_NO },
98 { KB_F4, KB_F5, KB_NO, KB_NO, KB_F20, KB_NO, KB_NO, KB_NO },
99 { KB_F7, KB_F6, KB_NO, KB_NO, KP_SLASH, KP_ASTERISK,KP_MINUS, KP_PLUS },
100 { KB_F8, KB_F12, KB_NO, KB_NO, KB_HOME, KB_NO, KB_END, KB_LSHIFT },
101 { KB_F9, KB_NO, KB_NO, KB_NO, KB_PGUP, KB_NO, KB_PGDOWN,KB_NO },
102 { KB_F10, KB_F11, KB_UP, KB_NO, KB_LEFT, KB_RIGHT, KB_NO, KB_DOWN }
103 },
104 // 3: FN_3(LEFT Bottom)
105 {
106 { KB_LALT, KB_NO, KB_DELETE, KB_NO, MS_LEFT, KB_NO, KB_BSLASH, MS_BTN1 },
107 { KB_F1, KB_GRAVE, KB_BSLASH, KB_NO, MS_BTN1, KB_LCTRL, KB_NO, MS_RIGHT },
108 { KB_F2, MS_BTN2, KB_LGUI, KB_NO, MS_BTN2, KB_NO, KB_NO, MS_UP },
109 { KB_F3, KB_NO, KB_RSHIFT, KB_NO, MS_BTN3, KB_NO, KB_NO, MS_DOWN },
110 { KB_F4, KB_F5, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO },
111 { KB_F7, KB_F6, KB_NO, KB_NO, MS_DOWN, MS_LEFT, MS_WH_UP, MS_WH_LEFT },
112 { KB_F8, KB_F12, MS_BTN5, KB_NO, MS_UP, KB_NO, MS_WH_DOWN, KB_LSHIFT },
113 { KB_F9, KB_NO, KB_NO, KB_NO, MS_RIGHT, KB_NO, MS_WH_RIGHT,KB_NO },
114 { KB_F10, KB_F11, MS_BTN4, KB_NO, KB_NO, KB_NO, KB_NO, KB_NO }
115 },
116}; 54};
117 55
56static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
57 /* Layer 0: Default Layer
58 * ,-----------------------------------------------------------.
59 * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =|Backsp |
60 * |-----------------------------------------------------------|
61 * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| |
62 * |-----------------------------------------------------' |
63 * |Contro| A| S| D| F| G| H| J| K| L|Fn3|Fn2|Return |
64 * |-----------------------------------------------------------|
65 * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Fn1|
66 * |-----------------------------------------------------------|
67 * |Fn7|Gui |Alt |Space |Fn6 |\ |` | | |
68 * `-----------------------------------------------------------'
69 */
70 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_BSPC, \
71 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, \
72 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, \
73 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, \
74 FN_7, KB_LGUI,KB_LALT,KB_SPC, FN_6, KB_BSLS,KB_GRV, KB_NO, KB_NO),
118 75
119uint8_t get_keycode(int layer, int row, int col) 76 /* Layer 1: HHKB mode (HHKB Fn)
77 * ,-----------------------------------------------------------.
78 * |Pow| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete |
79 * |-----------------------------------------------------------|
80 * |Caps | | | | | | | |Psc|Slk|Pus|Up | | |
81 * |-----------------------------------------------------' |
82 * |Contro| | | | | | *| /|Hom|PgU|Lef|Rig|Enter |
83 * |-----------------------------------------------------------|
84 * |Shift | | | | | | +| -|End|PgD|Dow|Shift |xxx|
85 * |-----------------------------------------------------------|
86 * | |Gui |Alt | |Alt | | | | |
87 * `-----------------------------------------------------------'
88 */
89 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_DEL, \
90 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, \
91 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, \
92 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, \
93 KB_NO, KB_LGUI,KB_LALT,KB_SPC, KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO),
94
95 /* Layer 2: Vi mode (Quote/Rmeta)
96 * ,-----------------------------------------------------------.
97 * | `| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| ` |
98 * |-----------------------------------------------------------|
99 * | \ |Hom|PgD|Up |PgU|End|Hom|PgD|PgU|End| | | | |
100 * |-----------------------------------------------------' |
101 * |Contro| |Lef|Dow|Rig| |Lef|Dow|Up |Rig| |xxx| \ |
102 * |-----------------------------------------------------------|
103 * |Shift | | | | | |Hom|PgD|PgU|End| |Shift | |
104 * |-----------------------------------------------------------|
105 * | |Gui |Alt |Space |xxxxx| | | | |
106 * `-----------------------------------------------------------'
107 */
108 KEYMAP(KB_GRV, 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_GRV, \
109 KB_BSLS,KB_HOME,KB_PGDN,KB_UP, KB_PGUP,KB_END, KB_HOME,KB_PGDN,KB_PGUP,KB_END, KB_NO, KB_NO, KB_NO, \
110 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_BSLS, \
111 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, \
112 KB_NO, KB_LGUI,KB_LALT,KB_SPC, FN_6, KB_NO, KB_NO, KB_NO, KB_NO),
113
114 /* Layer 3: Mouse mode (Semicolon)
115 * ,-------------------------------------------------------- --.
116 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete |
117 * |-----------------------------------------------------------|
118 * |Tab |MwL|MwU|McU|MwD|MwR|MwL|MwD|MwU|MwR| | | | |
119 * |-----------------------------------------------------' |
120 * |Contro|Mb1|Mb2|Mb3| | |McL|McD|McU|McR|xxx| |Return |
121 * |-----------------------------------------------------------|
122 * |Shift | | | | | |MwL|MwD|MwU|MwR| |Shift | |
123 * |-----------------------------------------------------------|
124 * |xxx|Gui |Alt |Mb1 |Alt | | | | |
125 * `-----------------------------------------------------------'
126 * Mc: Mouse Cursor / Mb: Mouse Button / Mw: Mouse Wheel
127 */
128 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_DEL, \
129 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, \
130 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, \
131 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, \
132 FN_7, KB_LGUI,KB_LALT,MS_BTN1,KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO),
133
134 /* Layer 4: Matias half keyboard style (Space)
135 * ,-----------------------------------------------------------.
136 * |Esc| F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12|Delete |
137 * |-----------------------------------------------------------|
138 * |Backs| P| O| I| U| Y| T| R| E| W| Q|Tab|Tab| |
139 * |-----------------------------------------------------' |
140 * |Contro| ;| L| K| J| H| G| F| D| S| A|Con|Control |
141 * |-----------------------------------------------------------|
142 * |Shift | /| .| ,| M| N| B| V| C| X| Z|Shift | |
143 * |-----------------------------------------------------------|
144 * | |Gui |Alt |xxxxxxxxxxxxxxxxxxxxxx|Alt | | | | |
145 * `-----------------------------------------------------------'
146 */
147 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_ESC, \
148 KB_BSPC,KB_P, KB_O, KB_I, KB_U, KB_Y, KB_T, KB_R, KB_E, KB_W, KB_Q, KB_TAB, KB_TAB, \
149 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, \
150 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, \
151 KB_NO, KB_LGUI,KB_LALT,FN_4, KB_RALT,KB_NO, KB_NO, KB_NO, KB_NO),
152};
153
154
155uint8_t keymap_get_keycode(int row, int col)
120{ 156{
121 if (row >= MATRIX_ROWS) 157 return keymap_get_keycodel(current_layer, row, col);
122 return KB_NO;
123 if (col >= MATRIX_COLS)
124 return KB_NO;
125 return pgm_read_byte(&Keymap[layer][row][col]);
126} 158}
127 159
128int get_layer(void) { 160uint8_t keymap_get_keycodel(int layer, int row, int col)
129 int layer = 0; 161{
130 for (int row = 0; row < MATRIX_ROWS; row++) { 162 uint8_t code = KEYCODE(layer, row, col);
131 for (int col = 0; col < MATRIX_ROWS; col++) { 163 // normal key or mouse key
132 if (matrix[row] & 1<<col) continue; 164 if (IS_KEY(code) || IS_MOUSE(code))
133 if (get_keycode(0, row, col) == FN_1) layer = 1; 165 layer_used = true;
134 if (get_keycode(0, row, col) == FN_2) layer = 2; 166 return code;
135 if (get_keycode(0, row, col) == FN_3) layer = 3; 167}
136 } 168
137 } 169inline
170int keymap_get_layer(void)
171{
172 return current_layer;
173}
174
175inline
176int keymap_set_layer(int layer)
177{
138 current_layer = layer; 178 current_layer = layer;
139 return current_layer; 179 return current_layer;
140} 180}
181
182inline
183bool keymap_is_special_mode(int fn_bits)
184{
185 return (keyboard_modifier_keys == (BIT_LCTRL | BIT_LSHIFT | BIT_LALT | BIT_LGUI));
186}
187
188void keymap_fn_proc(int fn_bits)
189{
190 // layer switching
191 static int last_bits = 0;
192 static uint8_t last_mod = 0;
193
194 if (usb_keyboard_has_key() || fn_bits == last_bits) {
195 // do nothing during press other than Fn key
196 return;
197 } else if (fn_bits == 0) {
198 // send key when Fn key is released without using the layer
199 if (!layer_used) {
200 uint8_t code = FN_KEYCODE(biton(last_bits));
201 if (code != KB_NO) {
202 if (IS_MOD(code)) {
203 keyboard_modifier_keys = last_mod | 1<<(code & 0x07);
204 } else {
205 keyboard_keys[0] = code;
206 keyboard_modifier_keys = last_mod;
207 }
208 usb_keyboard_send();
209 usb_keyboard_print();
210 usb_keyboard_clear();
211 }
212 }
213 last_bits = 0;
214 last_mod = 0;
215 layer_used = false;
216 keymap_set_layer(0); // default layer
217 } else if ((fn_bits & (fn_bits - 1)) == 0) {
218 // switch layer when just one Fn Key is pressed
219 last_bits = fn_bits;
220 last_mod = keyboard_modifier_keys;
221 layer_used = false;
222 keymap_set_layer(FN_LAYER(biton(fn_bits)));
223 debug("layer: "); phex(current_layer); debug("(");
224 debug_bin(last_bits); debug(")\n");
225 debug("last_mod: "); debug_hex(last_mod); debug("\n");
226 }
227}
diff --git a/macway/keymap.h b/macway/keymap.h
index b428b47a8..c65c2e19b 100644
--- a/macway/keymap.h
+++ b/macway/keymap.h
@@ -1,20 +1,7 @@
1#ifndef KEYMAP_H 1#ifndef KEYMAP_H
2#define KEYMAP_H 1 2#define KEYMAP_H 1
3 3
4#include <stdint.h>
5#include <stdbool.h>
6#include "usb_keycodes.h" 4#include "usb_keycodes.h"
7 5#include "keymap_skel.h"
8
9#define MATRIX_ROWS 9
10#define MATRIX_COLS 8
11
12
13extern int current_layer;
14extern bool key_sent;
15
16
17int get_layer(void);
18uint8_t get_keycode(int layer, int row, int col);
19 6
20#endif 7#endif
diff --git a/macway/matrix.c b/macway/matrix.c
index cb52d79c3..30da657ea 100644
--- a/macway/matrix.c
+++ b/macway/matrix.c
@@ -1,10 +1,13 @@
1/* 1/*
2 * scan matrix 2 * scan matrix
3 */ 3 */
4#include <stdint.h>
5#include <stdbool.h>
4#include <avr/io.h> 6#include <avr/io.h>
5#include <util/delay.h> 7#include <util/delay.h>
6#include "keymap.h"
7#include "matrix.h" 8#include "matrix.h"
9#include "print.h"
10#include "util.h"
8 11
9// matrix is active low. (key on: 0/key off: 1) 12// matrix is active low. (key on: 0/key off: 1)
10// row: Hi-Z(unselected)/low output(selected) 13// row: Hi-Z(unselected)/low output(selected)
@@ -18,11 +21,24 @@ uint8_t *matrix_prev;
18static uint8_t _matrix0[MATRIX_ROWS]; 21static uint8_t _matrix0[MATRIX_ROWS];
19static uint8_t _matrix1[MATRIX_ROWS]; 22static uint8_t _matrix1[MATRIX_ROWS];
20 23
24static bool matrix_has_ghost_in_row(uint8_t row);
21static uint8_t read_col(void); 25static uint8_t read_col(void);
22static void unselect_rows(void); 26static void unselect_rows(void);
23static void select_row(uint8_t row); 27static void select_row(uint8_t row);
24 28
25 29
30inline
31int matrix_rows(void)
32{
33 return MATRIX_ROWS;
34}
35
36inline
37int matrix_cols(void)
38{
39 return MATRIX_COLS;
40}
41
26// this must be called once before matrix_scan. 42// this must be called once before matrix_scan.
27void matrix_init(void) 43void matrix_init(void)
28{ 44{
@@ -32,58 +48,91 @@ void matrix_init(void)
32 PORTB = 0xFF; 48 PORTB = 0xFF;
33 49
34 // initialize matrix state: all keys off 50 // initialize matrix state: all keys off
35 for (int i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0xFF; 51 for (int i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
36 for (int i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0xFF; 52 for (int i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00;
37 matrix = _matrix0; 53 matrix = _matrix0;
38 matrix_prev = _matrix1; 54 matrix_prev = _matrix1;
39} 55}
40 56
41uint8_t matrix_scan(void) 57int matrix_scan(void)
42{ 58{
43 uint8_t row, state;
44 uint8_t *tmp; 59 uint8_t *tmp;
45 60
46 tmp = matrix_prev; 61 tmp = matrix_prev;
47 matrix_prev = matrix; 62 matrix_prev = matrix;
48 matrix = tmp; 63 matrix = tmp;
49 64
50 for (row = 0; row < MATRIX_ROWS; row++) { 65 for (int i = 0; i < MATRIX_ROWS; i++) {
51 select_row(row); 66 select_row(i);
52 _delay_us(30); // without this wait read unstable value. 67 _delay_us(30); // without this wait read unstable value.
53 state = read_col(); 68 matrix[i] = ~read_col();
54 unselect_rows(); 69 unselect_rows();
55
56 matrix[row] = state;
57 } 70 }
58 return 1; 71 return 1;
59} 72}
60 73
61bool matrix_is_modified(void) { 74bool matrix_is_modified(void)
62 for (int i=0; i <MATRIX_ROWS; i++) { 75{
76 for (int i = 0; i < MATRIX_ROWS; i++) {
63 if (matrix[i] != matrix_prev[i]) 77 if (matrix[i] != matrix_prev[i])
64 return true; 78 return true;
65 } 79 }
66 return false; 80 return false;
67} 81}
68 82
69bool matrix_has_ghost(void) { 83bool matrix_has_ghost(void)
70 for (int i=0; i <MATRIX_ROWS; i++) { 84{
85 for (int i = 0; i < MATRIX_ROWS; i++) {
71 if (matrix_has_ghost_in_row(i)) 86 if (matrix_has_ghost_in_row(i))
72 return true; 87 return true;
73 } 88 }
74 return false; 89 return false;
75} 90}
76 91
77bool matrix_has_ghost_in_row(uint8_t row) { 92inline
78 uint8_t state = ~matrix[row]; 93bool matrix_is_on(int row, int col)
94{
95 return (matrix[row] & (1<<col));
96}
97
98inline
99uint16_t matrix_get_row(int row)
100{
101 return matrix[row];
102}
103
104void matrix_print(void)
105{
106 print("\nr/c 01234567\n");
107 for (int row = 0; row < matrix_rows(); row++) {
108 phex(row); print(": ");
109 pbin_reverse(matrix_get_row(row));
110 if (matrix_has_ghost_in_row(row)) {
111 print(" <ghost");
112 }
113 print("\n");
114 }
115}
116
117int matrix_key_count(void)
118{
119 int count = 0;
120 for (int i = 0; i < MATRIX_ROWS; i++) {
121 count += bitpop(matrix[i]);
122 }
123 return count;
124}
125
126static bool matrix_has_ghost_in_row(uint8_t row)
127{
79 // no ghost exists in case less than 2 keys on 128 // no ghost exists in case less than 2 keys on
80 if (((state - 1) & state) == 0) 129 if (((matrix[row] - 1) & matrix[row]) == 0)
81 return false; 130 return false;
82 131
83 // ghost exists in case same state as other row 132 // ghost exists in case same state as other row
84 for (int i=0; i < MATRIX_ROWS; i++) { 133 for (int i=0; i < MATRIX_ROWS; i++) {
85 if (i == row) continue; 134 if (i != row && (matrix[i] & matrix[row]) == matrix[row])
86 if ((~matrix[i] & state) == state) return true; 135 return true;
87 } 136 }
88 return false; 137 return false;
89} 138}
@@ -93,7 +142,8 @@ static uint8_t read_col(void)
93 return PINB; 142 return PINB;
94} 143}
95 144
96static void unselect_rows(void) { 145static void unselect_rows(void)
146{
97 DDRD = 0x00; 147 DDRD = 0x00;
98 PORTD = 0x00; 148 PORTD = 0x00;
99 DDRC = 0x00; 149 DDRC = 0x00;
diff --git a/macway/matrix.h b/macway/matrix.h
new file mode 100644
index 000000000..c11f1f3e2
--- /dev/null
+++ b/macway/matrix.h
@@ -0,0 +1,15 @@
1#ifndef MATRIX_H
2#define MATRIX_H 1
3
4#include <stdint.h>
5#include "matrix_skel.h"
6
7
8#define MATRIX_ROWS 9
9#define MATRIX_COLS 8
10
11
12extern uint8_t *matrix;
13extern uint8_t *matrix_prev;
14
15#endif
diff --git a/tmk.c b/tmk.c
index 1d4b8fb01..ae138623b 100644
--- a/tmk.c
+++ b/tmk.c
@@ -69,8 +69,11 @@ int main(void)
69 69
70 matrix_init(); 70 matrix_init();
71 matrix_scan(); 71 matrix_scan();
72 // debug on by pressing down any 4 keys during boot time. 72 // debug on by pressing down any 4 or more keys during boot time.
73 if (matrix_key_count() == 4) print_enable = true; 73 if (matrix_key_count() >= 4) {
74 print_enable = true;
75 debug_enable = true;
76 }
74 77
75 /* wait for debug pipe ready */ 78 /* wait for debug pipe ready */
76 if (print_enable) { 79 if (print_enable) {
@@ -87,7 +90,7 @@ int main(void)
87#endif 90#endif
88 } 91 }
89 // print description 92 // print description
90 print(XSTR(DESCRIPTION)); 93 print(STR(DESCRIPTION) "\n");
91 94
92 while (1) { 95 while (1) {
93 proc_matrix(); 96 proc_matrix();
diff --git a/usb.c b/usb.c
index f5905f2ee..5c3240a47 100644
--- a/usb.c
+++ b/usb.c
@@ -29,6 +29,7 @@
29#include "usb_mouse.h" 29#include "usb_mouse.h"
30#include "usb_debug.h" 30#include "usb_debug.h"
31#include "print.h" 31#include "print.h"
32#include "util.h"
32 33
33 34
34/************************************************************************** 35/**************************************************************************
@@ -38,16 +39,29 @@
38 **************************************************************************/ 39 **************************************************************************/
39 40
40// You can change these to give your code its own name. 41// You can change these to give your code its own name.
41#define STR_MANUFACTURER L"t.m.k." 42#ifndef MANUFACTURER
42#define STR_PRODUCT L"t.m.k. keyboard" 43# define STR_MANUFACTURER L"t.m.k."
44#else
45# define STR_MANUFACTURER LSTR(MANUFACTURER)
46#endif
47#ifndef PRODUCT
48# define STR_PRODUCT L"t.m.k. keyboard"
49#else
50# define STR_PRODUCT LSTR(PRODUCT)
51#endif
43 52
44 53
45// Mac OS-X and Linux automatically load the correct drivers. On 54// Mac OS-X and Linux automatically load the correct drivers. On
46// Windows, even though the driver is supplied by Microsoft, an 55// Windows, even though the driver is supplied by Microsoft, an
47// INF file is needed to load the driver. These numbers need to 56// INF file is needed to load the driver. These numbers need to
48// match the INF file. 57// match the INF file.
49#define VENDOR_ID 0xFEED 58#ifndef VENDOR_ID
50#define PRODUCT_ID 0xCAFE 59# define VENDOR_ID 0xFEED
60#endif
61
62#ifndef PRODUCT_ID
63# define PRODUCT_ID 0xBABE
64#endif
51 65
52 66
53// USB devices are supposed to implment a halt feature, which is 67// USB devices are supposed to implment a halt feature, which is
diff --git a/util.c b/util.c
new file mode 100644
index 000000000..b02d077cc
--- /dev/null
+++ b/util.c
@@ -0,0 +1,18 @@
1#include "util.h"
2
3int bitpop(uint8_t bits)
4{
5 int c;
6 for (c = 0; bits; c++)
7 bits &= bits -1;
8 return c;
9}
10
11int biton(uint8_t bits)
12{
13 int n = 0;
14 if (bits >> 4) { bits >>= 4; n += 4;}
15 if (bits >> 2) { bits >>= 2; n += 2;}
16 if (bits >> 1) { bits >>= 1; n += 1;}
17 return n;
18}
diff --git a/util.h b/util.h
index 256bda020..2b607ad28 100644
--- a/util.h
+++ b/util.h
@@ -1,7 +1,17 @@
1#ifndef UTIL_H 1#ifndef UTIL_H
2#define UTIL_H 1 2#define UTIL_H 1
3 3
4#define XSTR(s) STR(s) 4#include <stdint.h>
5#define STR(s) #s 5
6// convert to L string
7#define LSTR(s) XLSTR(s)
8#define XLSTR(s) L ## #s
9// convert to string
10#define STR(s) XSTR(s)
11#define XSTR(s) #s
12
13
14int bitpop(uint8_t bits);
15int biton(uint8_t bits);
6 16
7#endif 17#endif