Statistics
| Branch: | Tag: | Revision:

root / Matrix.h @ d28743fa

History | View | Annotate | Download (11.5 KB)

1
#include <inttypes.h>
2
#include <LUFA/Drivers/USB/USB.h>
3
#include <avr/pgmspace.h>
4

    
5
#ifndef __matrix_h__
6
#define __matrix_h__
7
#define HID_KEYBOARD_SC_MOD3 0xf3
8
#define HID_KEYBOARD_SC_MOD4 0xf4
9

    
10
#define key(NAME) HID_KEYBOARD_SC_ ## NAME
11

    
12
// the following comments are based on qwertz labing on keyboards
13
// first line of keys
14
// ^ °
15
#define QWERTY_GRAVE_ACCENT_AND_TILDE {{0,key(GRAVE_ACCENT_AND_TILDE)},{0,0},{0,0},{0,0}}
16
#define QWERTY_1_AND_EXCLAMATION {{0,key(1_AND_EXCLAMATION)},{key(LEFT_SHIFT),key(GRAVE_ACCENT_AND_TILDE)},{0,0},{0,0}}
17
#define QWERTY_2_AND_AT {{0,key(2_AND_AT)},{key(LEFT_SHIFT),key(3_AND_HASHMARK)},{0,0},{0,0}}
18
#define QWERTY_3_AND_HASHMARK {{0,key(3_AND_HASHMARK)},{0,0},{0,0},{0,0}}
19
#define QWERTY_4_AND_DOLLAR {{0,key(4_AND_DOLLAR)},{0,0},{0,0},{0,0}}
20
#define QWERTY_5_AND_PERCENTAGE {{0,key(5_AND_PERCENTAGE)},{0,0},{0,0},{0,0}}
21
#define QWERTY_6_AND_CARET {{0,key(6_AND_CARET)},{key(LEFT_SHIFT),key(4_AND_DOLLAR)},{0,0},{0,0}}
22
#define QWERTY_7_AND_AND_AMPERSAND {{0,key(7_AND_AND_AMPERSAND)},{0,0},{0,0},{0,0}}
23
#define QWERTY_8_AND_ASTERISK {{0,key(8_AND_ASTERISK)},{0,0},{0,0},{0,0}}
24
#define QWERTY_9_AND_OPENING_PARENTHESIS {{0,key(9_AND_OPENING_PARENTHESIS)},{0,0},{0,0},{key(LEFT_SHIFT),key(7_AND_AND_AMPERSAND)}}
25
#define QWERTY_0_AND_CLOSING_PARENTHESIS {{0,key(0_AND_CLOSING_PARENTHESIS)},{0,0},{0,0},{key(LEFT_SHIFT),key(CLOSING_BRACKET_AND_CLOSING_BRACE)}}
26
// ß ? 
27
#define QWERTY_MINUS_AND_UNDERSCORE {{0,key(SLASH_AND_QUESTION_MARK)},{0,0},{0,0},{0,key(SLASH_AND_QUESTION_MARK)}}
28
#define QWERTY_EQUAL_AND_PLUS {{key(LEFT_SHIFT),key(EQUAL_AND_PLUS)},{0,0},{0,0},{0,0}}
29

    
30
// second line of keys
31
#define QWERTY_Q {{0,key(J)},{0,key(J)},{key(RIGHT_ALT),key(DOT_AND_GREATER_THAN_SIGN)},{0,key(PAGE_UP)}}
32
#define QWERTY_W {{0,key(D)},{0,key(D)},{key(LEFT_SHIFT),key(SLASH_AND_QUESTION_MARK)},{0,key(BACKSPACE)}}
33
#define QWERTY_E {{0,key(U)},{0,key(U)},{key(RIGHT_ALT),key(8_AND_ASTERISK)},{0,key(UP_ARROW)}}
34
#define QWERTY_R {{0,key(A)},{0,key(A)},{key(RIGHT_ALT),key(9_AND_OPENING_PARENTHESIS)},{0,key(DELETE)}}
35
#define QWERTY_T {{0,key(X)},{0,key(X)},{0,key(GRAVE_ACCENT_AND_TILDE)},{0,key(PAGE_DOWN)}}
36
#define QWERTY_Y {{0,key(P)},{0,key(P)},{key(LEFT_SHIFT),key(1_AND_EXCLAMATION)},{(key(LEFT_SHIFT)|key(RIGHT_ALT)),key(1_AND_EXCLAMATION)}}
37
#define QWERTY_U {{0,key(H)},{0,key(H)},{0,key(NON_US_BACKSLASH_AND_PIPE)},{0,key(7_AND_AND_AMPERSAND)}}
38
#define QWERTY_I {{0,key(L)},{0,key(L)},{key(LEFT_SHIFT),key(NON_US_BACKSLASH_AND_PIPE)},{0,key(8_AND_ASTERISK)}}
39
#define QWERTY_O {{0,key(M)},{0,key(M)},{key(LEFT_SHIFT),key(0_AND_CLOSING_PARENTHESIS)},{0,key(9_AND_OPENING_PARENTHESIS)}}
40
#define QWERTY_P {{0,key(W)},{0,key(W)},{key(LEFT_SHIFT),key(6_AND_CARET)},{0,key(CLOSING_BRACKET_AND_CLOSING_BRACE)}}
41
// ü
42
#define QWERTY_OPENING_BRACKET_AND_OPENING_BRACE {{0,key(Q)},{0,key(Q)},{0,0},{0,key(SLASH_AND_QUESTION_MARK)}}
43
// + * ~
44
#define QWERTY_CLOSING_BRACKET_AND_CLOSING_BRACE {{0,key(EQUAL_AND_PLUS)},{key(RIGHT_ALT),key(CLOSING_BRACKET_AND_CLOSING_BRACE)},{key(LEFT_SHIFT),key(7_AND_AND_AMPERSAND)},{key(LEFT_SHIFT),key(2_AND_AT)}}
45

    
46
// third line of keys
47
#define QWERTY_CAPS_LOCK {{key(MOD3),0},{key(MOD3),0},{key(MOD3),0},{key(MOD3),0}}
48
#define QWERTY_A {{0,key(C)},{0,key(C)},{key(RIGHT_ALT),key(MINUS_AND_UNDERSCORE)},{0,key(HOME)}}
49
#define QWERTY_S {{0,key(T)},{0,key(T)},{key(LEFT_SHIFT),key(7_AND_AND_AMPERSAND)},{0,key(LEFT_ARROW)}}
50
#define QWERTY_D {{0,key(I)},{0,key(I)},{key(RIGHT_ALT),key(7_AND_AND_AMPERSAND)},{0,key(DOWN_ARROW)}}
51
#define QWERTY_F {{0,key(E)},{0,key(E)},{key(RIGHT_ALT),key(0_AND_CLOSING_PARENTHESIS)},{0,key(RIGHT_ARROW)}}
52
#define QWERTY_G {{0,key(O)},{0,key(O)},{key(LEFT_SHIFT),key(CLOSING_BRACKET_AND_CLOSING_BRACE)},{0,key(END)}}
53
#define QWERTY_H {{0,key(B)},{0,key(B)},{key(LEFT_SHIFT),key(MINUS_AND_UNDERSCORE)},{(key(LEFT_SHIFT)|key(RIGHT_ALT)),key(MINUS_AND_UNDERSCORE)}}
54
#define QWERTY_J {{0,key(N)},{0,key(N)},{key(LEFT_SHIFT),key(8_AND_ASTERISK)},{0,key(4_AND_DOLLAR)}}
55
#define QWERTY_K {{0,key(R)},{0,key(R)},{key(LEFT_SHIFT),key(9_AND_OPENING_PARENTHESIS)},{0,key(5_AND_PERCENTAGE)}}
56
#define QWERTY_L {{0,key(S)},{0,key(S)},{0,key(SLASH_AND_QUESTION_MARK)},{0,key(6_AND_CARET)}}
57
// ö
58
#define QWERTY_SEMICOLON_AND_COLON {{0,key(G)},{0,key(G)},{key(LEFT_SHIFT),key(DOT_AND_GREATER_THAN_SIGN)},{0,key(COMMA_AND_LESS_THAN_SIGN)}}
59
// ä
60
#define QWERTY_APOSTROPHE_AND_QUOTE {{key(MOD3),0},{key(MOD3),0},{key(MOD3),0},{key(MOD3),0}}
61
// ' #
62
#define QWERTY_BACKSLASH_AND_PIPE {{0,key(MINUS_AND_UNDERSCORE)},{0,key(MINUS_AND_UNDERSCORE)},{key(RIGHT_ALT),key(Q)},{0,key(DOT_AND_GREATER_THAN_SIGN)}}
63

    
64
// fourth line of keys
65
// <>|
66
#define QWERTY_NON_US_BACKSLASH_AND_PIPE {{key(MOD4),0},{key(MOD4),0},{key(MOD4),0},{key(MOD4),0}}
67
#define QWERTY_Z {{0,key(F)},{0,key(F)},{0,key(NON_US_HASHMARK_AND_TILDE)},{0,key(ESCAPE)}}
68
#define QWERTY_X {{0,key(V)},{0,key(V)},{key(LEFT_SHIFT),key(4_AND_DOLLAR)},{0,key(TAB)}}
69
#define QWERTY_C {{0,key(OPENING_BRACKET_AND_OPENING_BRACE)}, {0,key(OPENING_BRACKET_AND_OPENING_BRACE)},{key(RIGHT_ALT),key(NON_US_BACKSLASH_AND_PIPE)},{0,key(INSERT)}}
70
#define QWERTY_V {{0,key(APOSTROPHE_AND_QUOTE)},{key(LEFT_SHIFT),key(APOSTROPHE_AND_QUOTE)},{key(RIGHT_ALT),key(CLOSING_BRACKET_AND_CLOSING_BRACE)},{0,key(ENTER)}}
71
#define QWERTY_B {{0,key(SEMICOLON_AND_COLON)},{0,key(SEMICOLON_AND_COLON)},{key(LEFT_SHIFT),key(EQUAL_AND_PLUS)},{0,key(UNDO)}}
72
#define QWERTY_N {{0,key(Y)},{0,key(Y)},{0,key(CLOSING_BRACKET_AND_CLOSING_BRACE)},{key(LEFT_SHIFT),key(DOT_AND_GREATER_THAN_SIGN)}}
73
#define QWERTY_M {{0,key(Z)},{0,key(Z)},{key(LEFT_SHIFT),key(5_AND_PERCENTAGE)},{0,key(1_AND_EXCLAMATION)}}
74
#define QWERTY_COMMA_AND_LESS_THAN_SIGN {{0,key(COMMA_AND_LESS_THAN_SIGN)},{0,key(COMMA_AND_LESS_THAN_SIGN)},{key(LEFT_SHIFT),key(2_AND_AT)},{0,key(2_AND_AT)}}
75
#define QWERTY_DOT_AND_GREATER_THAN_SIGN {{0,key(DOT_AND_GREATER_THAN_SIGN)},{0,key(DOT_AND_GREATER_THAN_SIGN)},{key(LEFT_SHIFT),key(NON_US_HASHMARK_AND_TILDE)},{0,key(3_AND_HASHMARK)}}
76
// - _
77
#define QWERTY_SLASH_AND_QUESTION_MARK {{0,key(K)},{0,key(K)},{key(LEFT_SHIFT),key(COMMA_AND_LESS_THAN_SIGN)},{key(LEFT_SHIFT),key(COMMA_AND_LESS_THAN_SIGN)}}
78

    
79
//bonus stuff you'd miss
80
#define QWERTY_SPACE {{0,key(SPACE)},{0,key(SPACE)},{0,key(SPACE)},{0,key(0_AND_CLOSING_PARENTHESIS)}}
81
#define QWERTY_RIGHT_ALT {{key(MOD4),0},{key(MOD4),0},{key(MOD4),0},{key(MOD4),0}}
82
#define QWERTY_MANU {{0,key(MANU)},{0,0},{0,0},{0,0}} // TODO
83

    
84
// unchanged keys
85
#define QWERTY_TAB {{0,key(TAB)},{0,key(TAB)},{0,key(TAB)},{0,key(TAB)}}
86
#define QWERTY_BACKSPACE {{0,key(BACKSPACE)},{0,key(BACKSPACE)},{0,key(BACKSPACE)},{0,key(BACKSPACE)}}
87
#define QWERTY_ESCAPE {{0,key(ESCAPE)},{0,key(ESCAPE)},{0,key(ESCAPE)},{0,key(ESCAPE)}}
88
#define QWERTY_ENTER {{0,key(ENTER)},{0,key(ENTER)},{0,key(ENTER)},{0,key(ENTER)}}
89

    
90
// from left to right
91
#define QWERTY_LEFT_SHIFT {{key(LEFT_SHIFT),0},{key(LEFT_SHIFT),0},{key(LEFT_SHIFT),0},{key(LEFT_SHIFT),0}}
92
#define QWERTY_LEFT_CONTROL {{key(LEFT_CONTROL),0},{key(LEFT_CONTROL),0},{key(LEFT_CONTROL),0},{key(LEFT_CONTROL),0}}
93
#define QWERTY_LEFT_GUI {{key(LEFT_GUI),0},{key(LEFT_GUI),0},{key(LEFT_GUI),0},{key(LEFT_GUI),0}}
94
#define QWERTY_LEFT_ALT {{key(LEFT_ALT),0},{key(LEFT_ALT),0},{key(LEFT_ALT),0},{key(LEFT_ALT),0}}
95
// Right_ALT is modifier 
96
// Right_GUI becomes ALT
97
#define QWERTY_RIGHT_GUI {{key(RIGHT_GUI),0},{key(RIGHT_GUI),0},{key(RIGHT_GUI),0},{key(RIGHT_GUI),0}}
98
//#define QWERTY_MANU {{key(MANU),0},{key(MANU),0},{key(MANU),0},{key(MANU),0}}
99
#define QWERTY_RIGHT_CONTROL {{key(RIGHT_CONTROL),0},{key(RIGHT_CONTROL),0},{key(RIGHT_CONTROL),0},{key(RIGHT_CONTROL),0}}
100
#define QWERTY_RIGHT_SHIFT {{key(RIGHT_SHIFT),0},{key(RIGHT_SHIFT),0},{key(RIGHT_SHIFT),0},{key(RIGHT_SHIFT),0}}
101

    
102
#define QWERTY_F1 {{0,key(F1)},{0,key(F1)},{0,key(F1)},{0,key(F1)}}
103
#define QWERTY_F2 {{0,key(F2)},{0,key(F2)},{0,key(F2)},{0,key(F2)}}
104
#define QWERTY_F3 {{0,key(F3)},{0,key(F3)},{0,key(F3)},{0,key(F3)}}
105
#define QWERTY_F4 {{0,key(F4)},{0,key(F4)},{0,key(F4)},{0,key(F4)}}
106
#define QWERTY_F5 {{0,key(F5)},{0,key(F5)},{0,key(F5)},{0,key(F5)}}
107
#define QWERTY_F6 {{0,key(F6)},{0,key(F6)},{0,key(F6)},{0,key(F6)}}
108
#define QWERTY_F7 {{0,key(F7)},{0,key(F7)},{0,key(F7)},{0,key(F7)}}
109
#define QWERTY_F8 {{0,key(F8)},{0,key(F8)},{0,key(F8)},{0,key(F8)}}
110
#define QWERTY_F9 {{0,key(F9)},{0,key(F9)},{0,key(F9)},{0,key(F9)}}
111
#define QWERTY_F10 {{0,key(F10)},{0,key(F10)},{0,key(F10)},{0,key(F10)}}
112
#define QWERTY_F11 {{0,key(F11)},{0,key(F11)},{0,key(F11)},{0,key(F11)}}
113
#define QWERTY_F12 {{0,key(F12)},{0,key(F12)},{0,key(F12)},{0,key(F12)}}
114

    
115
#define QWERTY_UP        {{0,key(UP_ARROW)},{0,key(UP_ARROW)},{0,key(UP_ARROW)},{0,key(UP_ARROW)}}
116
#define QWERTY_DOWN        {{0,key(DOWN_ARROW)},{0,key(DOWN_ARROW)},{0,key(DOWN_ARROW)},{0,key(DOWN_ARROW)}}
117
#define QWERTY_LEFT        {{0,key(LEFT_ARROW)},{0,key(LEFT_ARROW)},{0,key(LEFT_ARROW)},{0,key(LEFT_ARROW)}}
118
#define QWERTY_RIGHT        {{0,key(RIGHT_ARROW)},{0,key(RIGHT_ARROW)},{0,key(RIGHT_ARROW)},{0,key(RIGHT_ARROW)}}
119

    
120
#define QWERTY_INSERT        {{0,key(INSERT)},{0,key(INSERT)},{0,key(INSERT)},{0,key(INSERT)}}
121
#define QWERTY_DELETE        {{0,key(DELETE)},{0,key(DELETE)},{0,key(DELETE)},{0,key(DELETE)}}
122
#define QWERTY_HOME        {{0,key(HOME)},{0,key(HOME)},{0,key(HOME)},{0,key(HOME)}}
123
#define QWERTY_END        {{0,key(END)},{0,key(END)},{0,key(END)},{0,key(END)}}
124
#define QWERTY_PAGE_UP        {{0,key(PAGE_UP)},{0,key(PAGE_UP)},{0,key(PAGE_UP)},{0,key(PAGE_UP)}}
125
#define QWERTY_PAGE_DOWN {{0,key(PAGE_DOWN)},{0,key(PAGE_DOWN)},{0,key(PAGE_DOWN)},{0,key(PAGE_DOWN)}}
126

    
127
#define BLANK {{0,0},{0,0},{0,0},{0,0}}
128

    
129
#define MAX_KEYPRESS_COUNT 15
130
#define KEYPRESS_TRIGGER_COUNT 7
131

    
132
volatile uint8_t matrixState[19];
133
volatile uint8_t detectedKeypress[30][3];
134
const volatile static uint8_t mapping[19][8][4][2] PROGMEM =
135
{
136
 {BLANK, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, BLANK}, //a
137
 {QWERTY_LEFT_ALT, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, QWERTY_RIGHT_ALT}, //b
138
 {QWERTY_UP, BLANK, BLANK, BLANK,  BLANK, QWERTY_RIGHT_GUI, BLANK, QWERTY_LEFT}, //c
139
 {BLANK, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, BLANK}, //d
140
 {BLANK, BLANK, QWERTY_F12, QWERTY_INSERT,  BLANK, BLANK, BLANK, QWERTY_RIGHT}, //e
141
 {BLANK, QWERTY_HOME, QWERTY_F11, QWERTY_DELETE, QWERTY_END, QWERTY_PAGE_UP, QWERTY_PAGE_DOWN, QWERTY_DOWN}, //f
142
 {QWERTY_F5, QWERTY_ENTER, QWERTY_F10, QWERTY_F9,  BLANK, QWERTY_BACKSPACE, BLANK, QWERTY_SPACE}, //g
143
 {QWERTY_APOSTROPHE_AND_QUOTE, QWERTY_BACKSLASH_AND_PIPE, QWERTY_0_AND_CLOSING_PARENTHESIS, QWERTY_MINUS_AND_UNDERSCORE,  QWERTY_P, QWERTY_OPENING_BRACKET_AND_OPENING_BRACE, QWERTY_SEMICOLON_AND_COLON, QWERTY_SLASH_AND_QUESTION_MARK}, //h
144
 {BLANK, QWERTY_DOT_AND_GREATER_THAN_SIGN, QWERTY_9_AND_OPENING_PARENTHESIS, QWERTY_F8,  QWERTY_O, QWERTY_F7, QWERTY_L, BLANK}, //i
145
 {QWERTY_F6, QWERTY_COMMA_AND_LESS_THAN_SIGN, QWERTY_8_AND_ASTERISK, QWERTY_EQUAL_AND_PLUS,  QWERTY_I, QWERTY_CLOSING_BRACKET_AND_CLOSING_BRACE, QWERTY_K, BLANK}, //j
146
 {QWERTY_H, QWERTY_M, QWERTY_7_AND_AND_AMPERSAND, QWERTY_6_AND_CARET,  QWERTY_U, QWERTY_Y, QWERTY_J, QWERTY_N}, //k
147
 {QWERTY_G, QWERTY_V, QWERTY_4_AND_DOLLAR, QWERTY_5_AND_PERCENTAGE,  QWERTY_R, QWERTY_T, QWERTY_F, QWERTY_B}, //l
148
 {QWERTY_F4, QWERTY_C, QWERTY_3_AND_HASHMARK, QWERTY_F2,  QWERTY_E, QWERTY_F3, QWERTY_D, BLANK}, //m
149
 {QWERTY_NON_US_BACKSLASH_AND_PIPE, QWERTY_X, QWERTY_2_AND_AT, QWERTY_F1,  QWERTY_W, QWERTY_CAPS_LOCK, QWERTY_S, BLANK}, //n
150
 {QWERTY_ESCAPE, QWERTY_Z, QWERTY_1_AND_EXCLAMATION, QWERTY_GRAVE_ACCENT_AND_TILDE,  QWERTY_Q, QWERTY_TAB, QWERTY_A, BLANK}, //o
151
 {BLANK, QWERTY_RIGHT_SHIFT, BLANK, BLANK,  BLANK, QWERTY_LEFT_SHIFT, BLANK, BLANK}, //p
152
 {BLANK, QWERTY_RIGHT_CONTROL, BLANK, QWERTY_LEFT_CONTROL,  BLANK, BLANK, BLANK, BLANK}, //q
153
 {QWERTY_LEFT_GUI, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, BLANK}, //r
154
 {BLANK, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, QWERTY_LEFT_ALT} //s
155
};
156
#undef key
157

    
158
volatile static uint8_t modAfterglow = 0;
159
#endif