Statistics
| Branch: | Tag: | Revision:

root / Matrix.h @ master

History | View | Annotate | Download (10.3 KB)

1 de87a8c5 imp
#include <inttypes.h>
2 e59e5253 imp
#include <LUFA/Drivers/USB/USB.h>
3 76668935 imp
#include <avr/pgmspace.h>
4 de87a8c5 imp
5
#ifndef __matrix_h__
6
#define __matrix_h__
7 76668935 imp
#define HID_KEYBOARD_SC_MOD3 0xf3
8
#define HID_KEYBOARD_SC_MOD4 0xf4
9
10 e59e5253 imp
#define key(NAME) HID_KEYBOARD_SC_ ## NAME
11 76668935 imp
12 632c1b11 imp
// 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 76668935 imp
#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 632c1b11 imp
#define QWERTY_6_AND_CARET {{0,key(6_AND_CARET)},{key(LEFT_SHIFT),key(4_AND_DOLLAR)},{0,0},{0,0}}
22 76668935 imp
#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 632c1b11 imp
#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(X)},{0,key(X)},{key(RIGHT_ALT),key(DOT_AND_GREATER_THAN_SIGN)},{0,key(PAGE_UP)}}
32
#define QWERTY_W {{0,key(V)},{0,key(V)},{key(LEFT_SHIFT),key(SLASH_AND_QUESTION_MARK)},{0,key(BACKSPACE)}}
33
#define QWERTY_E {{0,key(L)},{0,key(L)},{key(RIGHT_ALT),key(8_AND_ASTERISK)},{0,key(UP_ARROW)}}
34
#define QWERTY_R {{0,key(C)},{0,key(C)},{key(RIGHT_ALT),key(9_AND_OPENING_PARENTHESIS)},{0,key(DELETE)}}
35
#define QWERTY_T {{0,key(W)},{0,key(W)},{0,key(GRAVE_ACCENT_AND_TILDE)},{0,key(PAGE_DOWN)}}
36
#define QWERTY_Y {{0,key(K)},{0,key(K)},{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(G)},{0,key(G)},{key(LEFT_SHIFT),key(NON_US_BACKSLASH_AND_PIPE)},{0,key(8_AND_ASTERISK)}}
39
#define QWERTY_O {{0,key(F)},{0,key(F)},{key(LEFT_SHIFT),key(0_AND_CLOSING_PARENTHESIS)},{0,key(9_AND_OPENING_PARENTHESIS)}}
40
#define QWERTY_P {{0,key(Q)},{0,key(Q)},{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(MINUS_AND_UNDERSCORE)},{0,key(MINUS_AND_UNDERSCORE)},{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(U)},{0,key(U)},{key(RIGHT_ALT),key(MINUS_AND_UNDERSCORE)},{0,key(HOME)}}
49
#define QWERTY_S {{0,key(I)},{0,key(I)},{key(LEFT_SHIFT),key(7_AND_AND_AMPERSAND)},{0,key(LEFT_ARROW)}}
50
#define QWERTY_D {{0,key(A)},{0,key(A)},{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(S)},{0,key(S)},{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(T)},{0,key(T)},{0,key(SLASH_AND_QUESTION_MARK)},{0,key(6_AND_CARET)}}
57
// ö
58
#define QWERTY_SEMICOLON_AND_COLON {{0,key(D)},{0,key(D)},{key(LEFT_SHIFT),key(DOT_AND_GREATER_THAN_SIGN)},{0,key(COMMA_AND_LESS_THAN_SIGN)}}
59
// ä
60
#define QWERTY_APOSTROPHE_AND_QUOTE {{0,key(Z)},{0,key(Z)},{key(RIGHT_ALT),key(Q)},{0,key(DOT_AND_GREATER_THAN_SIGN)}}
61
// ' #
62
#define QWERTY_BACKSLASH_AND_PIPE {{key(MOD3),0},{key(MOD3),0},{key(MOD3),0},{key(MOD3),0}}
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(OPENING_BRACKET_AND_OPENING_BRACE)},{0,key(OPENING_BRACKET_AND_OPENING_BRACE)},{0,key(NON_US_HASHMARK_AND_TILDE)},{0,key(ESCAPE)}}
68
#define QWERTY_X {{0,key(SEMICOLON_AND_COLON)},{0,key(SEMICOLON_AND_COLON)},{key(LEFT_SHIFT),key(4_AND_DOLLAR)},{0,key(TAB)}}
69
#define QWERTY_C {{0,key(APOSTROPHE_AND_QUOTE)},{0,key(APOSTROPHE_AND_QUOTE)},{key(RIGHT_ALT),key(NON_US_BACKSLASH_AND_PIPE)},{0,key(INSERT)}}
70
#define QWERTY_V {{0,key(P)},{0,key(P)},{key(RIGHT_ALT),key(CLOSING_BRACKET_AND_CLOSING_BRACE)},{0,key(ENTER)}}
71
#define QWERTY_B {{0,key(Y)},{0,key(Y)},{key(LEFT_SHIFT),key(EQUAL_AND_PLUS)},{0,key(UNDO)}}
72
#define QWERTY_N {{0,key(B)},{0,key(B)},{0,key(CLOSING_BRACKET_AND_CLOSING_BRACE)},{key(LEFT_SHIFT),key(DOT_AND_GREATER_THAN_SIGN)}}
73
#define QWERTY_M {{0,key(M)},{0,key(M)},{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(J)},{0,key(J)},{key(LEFT_SHIFT),key(COMMA_AND_LESS_THAN_SIGN)},{key(LEFT_SHIFT),key(COMMA_AND_LESS_THAN_SIGN)}}
78
79
#define QWERTY_SPACE {{0,key(SPACE)},{0,key(SPACE)},{0,key(SPACE)},{0,key(0_AND_CLOSING_PARENTHESIS)}}
80
#define QWERTY_RIGHT_ALT {{key(MOD4),0},{key(MOD4),0},{key(MOD4),0},{key(MOD4),0}}
81
#define QWERTY_MANU {{0,key(MANU)},{0,0},{0,0},{0,0}} // TODO
82
83
// unchanged keys
84
#define QWERTY_TAB {{0,key(TAB)},{0,key(TAB)},{0,key(TAB)},{0,key(TAB)}}
85
#define QWERTY_BACKSPACE {{0,key(BACKSPACE)},{0,key(BACKSPACE)},{0,key(BACKSPACE)},{0,key(BACKSPACE)}}
86
#define QWERTY_ESCAPE {{0,key(ESCAPE)},{0,key(ESCAPE)},{0,key(ESCAPE)},{0,key(ESCAPE)}}
87
#define QWERTY_ENTER {{0,key(ENTER)},{0,key(ENTER)},{0,key(ENTER)},{0,key(ENTER)}}
88
89
#define QWERTY_LEFT_ALT {{key(LEFT_ALT),0},{key(LEFT_ALT),0},{key(LEFT_ALT),0},{key(LEFT_ALT),0}}
90
#define QWERTY_LEFT_CONTROL {{key(LEFT_CONTROL),0},{key(LEFT_CONTROL),0},{key(LEFT_CONTROL),0},{key(LEFT_CONTROL),0}}
91
#define QWERTY_LEFT_GUI {{key(LEFT_GUI),0},{key(LEFT_GUI),0},{key(LEFT_GUI),0},{key(LEFT_GUI),0}}
92
#define QWERTY_LEFT_SHIFT {{key(LEFT_SHIFT),0},{key(LEFT_SHIFT),0},{key(LEFT_SHIFT),0},{key(LEFT_SHIFT),0}}
93
94
#define QWERTY_RIGHT_CONTROL {{key(RIGHT_CONTROL),0},{key(RIGHT_CONTROL),0},{key(RIGHT_CONTROL),0},{key(RIGHT_CONTROL),0}}
95
#define QWERTY_RIGHT_GUI {{key(RIGHT_GUI),0},{key(RIGHT_GUI),0},{key(RIGHT_GUI),0},{key(RIGHT_GUI),0}}
96
#define QWERTY_RIGHT_SHIFT {{key(RIGHT_SHIFT),0},{key(RIGHT_SHIFT),0},{key(RIGHT_SHIFT),0},{key(RIGHT_SHIFT),0}}
97
98
#define QWERTY_F1 {{0,key(F1)},{0,key(F1)},{0,key(F1)},{0,key(F1)}}
99
#define QWERTY_F2 {{0,key(F2)},{0,key(F2)},{0,key(F2)},{0,key(F2)}}
100
#define QWERTY_F3 {{0,key(F3)},{0,key(F3)},{0,key(F3)},{0,key(F3)}}
101
#define QWERTY_F4 {{0,key(F4)},{0,key(F4)},{0,key(F4)},{0,key(F4)}}
102
#define QWERTY_F5 {{0,key(F5)},{0,key(F5)},{0,key(F5)},{0,key(F5)}}
103
#define QWERTY_F6 {{0,key(F6)},{0,key(F6)},{0,key(F6)},{0,key(F6)}}
104
#define QWERTY_F7 {{0,key(F7)},{0,key(F7)},{0,key(F7)},{0,key(F7)}}
105
#define QWERTY_F8 {{0,key(F8)},{0,key(F8)},{0,key(F8)},{0,key(F8)}}
106
#define QWERTY_F9 {{0,key(F9)},{0,key(F9)},{0,key(F9)},{0,key(F9)}}
107
#define QWERTY_F10 {{0,key(F10)},{0,key(F10)},{0,key(F10)},{0,key(F10)}}
108
#define QWERTY_F11 {{0,key(F11)},{0,key(F11)},{0,key(F11)},{0,key(F11)}}
109
#define QWERTY_F12 {{0,key(F12)},{0,key(F12)},{0,key(F12)},{0,key(F12)}}
110 76668935 imp
111
#define BLANK {{0,0},{0,0},{0,0},{0,0}}
112
113 eaf1704d imp
#define MAX_KEYPRESS_COUNT 50
114
#define KEYPRESS_TRIGGER_COUNT 40
115 47e7c7ed imp
116 de87a8c5 imp
volatile uint8_t matrixState[19];
117 47e7c7ed imp
volatile uint8_t detectedKeypress[30][3];
118 76668935 imp
const volatile static uint8_t mapping[19][8][4][2] PROGMEM =
119 e59e5253 imp
{
120 76668935 imp
 {BLANK, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, BLANK}, //a
121
 {QWERTY_LEFT_ALT, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, QWERTY_RIGHT_ALT}, //b
122
 {BLANK, BLANK, BLANK, BLANK,  BLANK, QWERTY_MANU, BLANK, BLANK}, //c
123
 {BLANK, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, BLANK}, //d
124
 {BLANK, BLANK, QWERTY_F12, BLANK,  BLANK, BLANK, BLANK, BLANK}, //e
125
 {BLANK, BLANK, QWERTY_F11, BLANK,  BLANK, BLANK, BLANK, BLANK}, //f
126
 {QWERTY_F5, QWERTY_ENTER, QWERTY_F10, QWERTY_F9,  BLANK, QWERTY_BACKSPACE, BLANK, QWERTY_SPACE}, //g
127
 {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
128
 {BLANK, QWERTY_DOT_AND_GREATER_THAN_SIGN, QWERTY_9_AND_OPENING_PARENTHESIS, QWERTY_F8,  QWERTY_O, QWERTY_F7, QWERTY_L, BLANK}, //i
129
 {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
130
 {QWERTY_H, QWERTY_M, QWERTY_7_AND_AND_AMPERSAND, QWERTY_6_AND_CARET,  QWERTY_U, QWERTY_Y, QWERTY_J, QWERTY_N}, //k
131
 {QWERTY_G, QWERTY_V, QWERTY_4_AND_DOLLAR, QWERTY_5_AND_PERCENTAGE,  QWERTY_R, QWERTY_T, QWERTY_F, QWERTY_B}, //l
132
 {QWERTY_F4, QWERTY_C, QWERTY_3_AND_HASHMARK, QWERTY_F2,  QWERTY_E, QWERTY_F3, QWERTY_D, BLANK}, //m
133
 {QWERTY_NON_US_BACKSLASH_AND_PIPE, QWERTY_X, QWERTY_2_AND_AT, QWERTY_F1,  QWERTY_W, QWERTY_CAPS_LOCK, QWERTY_S, BLANK}, //n
134
 {QWERTY_ESCAPE, QWERTY_Z, QWERTY_1_AND_EXCLAMATION, QWERTY_GRAVE_ACCENT_AND_TILDE,  QWERTY_Q, QWERTY_TAB, QWERTY_A, BLANK}, //o
135
 {BLANK, QWERTY_RIGHT_SHIFT, BLANK, BLANK,  BLANK, QWERTY_LEFT_SHIFT, BLANK, BLANK}, //p
136
 {BLANK, QWERTY_RIGHT_CONTROL, BLANK, QWERTY_LEFT_CONTROL,  BLANK, BLANK, BLANK, BLANK}, //q
137
 {QWERTY_LEFT_GUI, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, BLANK}, //r
138
 {BLANK, BLANK, BLANK, BLANK,  BLANK, BLANK, BLANK, QWERTY_RIGHT_GUI} //s
139 e59e5253 imp
};
140
#undef key
141 de87a8c5 imp
142 632c1b11 imp
volatile static uint8_t modAfterglow = 0;
143 de87a8c5 imp
#endif