Mercurial > louis > kiibohd-controller
annotate main.c @ 6:9df636be6feb
Keyboard functionally working with very very good debouncing.
- defaultMap needs to be adjusted
- Modifiers are not yet accounted for when sending keypresses
- keypad needs to be added (detect,debounce, and send)
author | Jacob Alexander <triplehaata@gmail.com> |
---|---|
date | Wed, 16 Mar 2011 22:43:33 -0700 |
parents | a8be29294c26 |
children | 18e424630cbd |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2011 by Jacob Alexander |
2 * | |
3 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
4 * of this software and associated documentation files (the "Software"), to deal | |
5 * in the Software without restriction, including without limitation the rights | |
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
7 * copies of the Software, and to permit persons to whom the Software is | |
8 * furnished to do so, subject to the following conditions: | |
9 * | |
10 * The above copyright notice and this permission notice shall be included in | |
11 * all copies or substantial portions of the Software. | |
12 * | |
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
19 * THE SOFTWARE. | |
20 */ | |
21 | |
22 #include <avr/io.h> | |
23 #include <avr/pgmspace.h> | |
24 #include <avr/interrupt.h> | |
25 #include <util/delay.h> | |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
26 //#include "usb_keyboard.h" |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
27 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
28 // TEMP INCLUDES |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
29 #include "usb_keyboard_debug.h" |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
30 #include <print.h> |
0 | 31 |
32 #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n)) | |
33 | |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
34 // Sleep defined in milliseconds |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
35 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
36 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
37 // Number of keys |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
38 #define KEYBOARD_SIZE 63 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
39 #define KEYPAD_SIZE 16 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
40 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
41 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
42 // Debouncing Defines |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
43 #define SAMPLE_THRESHOLD 100 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
44 #define MAX_SAMPLES 127 // Max is 127, reaching 128 is very bad |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
45 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
46 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
47 // Verified Keypress Defines |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
48 #define USB_TRANSFER_DIVIDER 10 // 1024 == 1 Send of keypresses per second, 1 == 1 Send of keypresses per ~1 millisecond |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
49 |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
50 |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
51 // Drive Pin Defines |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
52 #define DRIVE_reg_1 PORTD |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
53 #define DRIVE_reg_2 PORTD |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
54 #define DRIVE_reg_3 PORTD |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
55 #define DRIVE_reg_4 PORTD |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
56 #define DRIVE_reg_5 PORTD |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
57 #define DRIVE_reg_6 PORTD |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
58 #define DRIVE_reg_7 PORTE |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
59 #define DRIVE_reg_8 PORTE |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
60 #define DRIVE_reg_9 PORTE |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
61 #define DRIVE_reg_10 <blank> |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
62 #define DRIVE_reg_11 <blank> |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
63 #define DRIVE_reg_12 <blank> |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
64 |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
65 #define DRIVE_pin_1 2 |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
66 #define DRIVE_pin_2 3 |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
67 #define DRIVE_pin_3 4 |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
68 #define DRIVE_pin_4 5 |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
69 #define DRIVE_pin_5 6 |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
70 #define DRIVE_pin_6 7 |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
71 #define DRIVE_pin_7 0 |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
72 #define DRIVE_pin_8 1 |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
73 #define DRIVE_pin_9 6 |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
74 #define DRIVE_pin_10 <blank> |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
75 #define DRIVE_pin_11 <blank> |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
76 #define DRIVE_pin_12 <blank> |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
77 |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
78 // Detect Pin/Group Defines |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
79 #define DETECT_group_1 1 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
80 #define DETECT_group_2 2 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
81 #define DETECT_group_3 3 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
82 #define DETECT_group_4 4 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
83 #define DETECT_group_5 5 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
84 #define DETECT_group_6 6 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
85 #define DETECT_group_7 7 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
86 #define DETECT_group_8 8 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
87 #define DETECT_group_9 9 |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
88 #define DETECT_group_10 <blank> |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
89 #define DETECT_group_11 <blank> |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
90 #define DETECT_group_12 <blank> |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
91 |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
92 #define DETECT_group_size_1 7 |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
93 #define DETECT_group_size_2 7 |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
94 #define DETECT_group_size_3 6 |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
95 #define DETECT_group_size_4 8 |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
96 #define DETECT_group_size_5 7 |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
97 #define DETECT_group_size_6 7 |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
98 #define DETECT_group_size_7 8 |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
99 #define DETECT_group_size_8 8 |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
100 #define DETECT_group_size_9 4 |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
101 #define DETECT_group_size_10 <blank> |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
102 #define DETECT_group_size_11 <blank> |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
103 #define DETECT_group_size_12 <blank> |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
104 |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
105 /* |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
106 #define DETECT_group_array_1 {{KEY_ESC,KEY_CTRL,KEY_CAPS_LOCK,KEY_SHIFT},{0,1,0,1}} |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
107 #define DETECT_group_array_2 {{KEY_BACKSPACE,KEY_UP,KEY_DOWN,KEY_A,KEY_INSERT,KEY_ALT,KEY_Z,KEY_RIGHT},{0,0,0,0,0,1,0,0}} |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
108 #define DETECT_group_array_3 {{KEY_TILDE,KEY_DELETE,KEY_LEFT,KEY_SPACE,KEY_X,KEY_S,KEY_TAB,KEY_1},{0,0,0,0,0,0,0,0}} |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
109 #define DETECT_group_array_4 {{KEY_SLASH,KEY_RIGHT_BRACE,KEY_ENTER,KEY_D,KEY_2,KEY_Q,KEY_C},{0,0,0,0,0,0,0}} |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
110 #define DETECT_group_array_5 {{KEY_EQUAL,KEY_LEFT_BRACE,KEY_QUOTE,KEY_F,KEY_3,KEY_W,KEY_V},{0,0,0,0,0,0,0}} |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
111 #define DETECT_group_array_6 {{KEY_MINUS,KEY_P,KEY_SEMICOLON,KEY_G,KEY_4,KEY_E,KEY_B,KEY_BACKSLASH},{0,0,0,0,0,0,0,0}} |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
112 #define DETECT_group_array_7 {{KEY_8,KEY_U,KEY_K,KEY_7,KEY_Y,KEY_COMMA},{0,0,0,0,0,0}} |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
113 #define DETECT_group_array_8 {{KEY_9,KEY_I,KEY_PERIOD,KEY_J,KEY_6,KEY_T,KEY_M},{0,0,0,0,0,0,0}} |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
114 #define DETECT_group_array_9 {{KEY_0,KEY_O,KEY_L,KEY_H,KEY_5,KEY_R,KEY_N},{0,0,0,0,0,0,0}} |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
115 */ |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
116 // Switch Codes |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
117 #define DETECT_group_array_1 {55,22,6 ,40,43,27,11} |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
118 #define DETECT_group_array_2 {56,23,7 ,41,58,26,10} |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
119 #define DETECT_group_array_3 {57,24,8 ,42,25,9} |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
120 #define DETECT_group_array_4 {54,21,5 ,39,44,28,12,59} |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
121 #define DETECT_group_array_5 {53,20,4 ,38,45,29,13} |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
122 #define DETECT_group_array_6 {52,19,3 ,37,46,30,14} |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
123 #define DETECT_group_array_7 {51,18,2 ,36,61,31,15,63} |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
124 #define DETECT_group_array_8 {50,17,1 ,35,47,32,16,62} |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
125 #define DETECT_group_array_9 {48,49,33,34} // 49/60 are the same line |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
126 #define DETECT_group_array_10 <blank> |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
127 #define DETECT_group_array_11 <blank> |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
128 #define DETECT_group_array_12 <blank> |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
129 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
130 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
131 |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
132 // Drive Macros (Generally don't need to be changed), except for maybe DRIVE_DETECT |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
133 #define DRIVE_DETECT(reg,pin,group) \ |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
134 reg &= ~(1 << pin); \ |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
135 detection(group); \ |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
136 reg |= (1 << pin); |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
137 |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
138 #define DD_CASE(number) \ |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
139 case number:\ |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
140 DRIVE_DETECT(DRIVE_reg_##number, DRIVE_pin_##number, DETECT_group_##number) |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
141 |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
142 #define DD_CASE_ORD(number) \ |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
143 DD_CASE(number) \ |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
144 break; |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
145 |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
146 #define DD_CASE_END(number,var) \ |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
147 DD_CASE(number) \ |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
148 var = -1; \ |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
149 break; |
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
150 |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
151 |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
152 // Updates the current detection sample and last sample bit |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
153 // Detection Macros (Probably don't need to be changed, but depending the matrix, may have to be) |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
154 // Determine if key is either normal or a modifier |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
155 #define DET_GROUP_CHECK(index,test) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
156 if ( test ) { \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
157 keyDetectArray[groupArray[index]]++; \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
158 } |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
159 |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
160 |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
161 // XXX - Detection Groups |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
162 // Checks each of the specified pins, and then if press detected, determine if the key is normal or a modifier |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
163 // Inverse logic applies for the PINs |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
164 |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
165 // Used for 1 detection group (Special group) |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
166 #define DET_GROUP_1 \ |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
167 DET_GROUP_CHECK(0,!( PINB & (1 << 7) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
168 DET_GROUP_CHECK(1,!( PINC & (1 << 0) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
169 DET_GROUP_CHECK(2,!( PIND & (1 << 0) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
170 DET_GROUP_CHECK(3,!( PIND & (1 << 1) )) \ |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
171 |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
172 // Used for 4 detection groups (Skips J1 P9) |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
173 #define DET_GROUP_2 \ |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
174 DET_GROUP_CHECK(0,!( PINE & (1 << 7) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
175 DET_GROUP_CHECK(1,!( PINB & (1 << 0) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
176 DET_GROUP_CHECK(2,!( PINB & (1 << 1) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
177 DET_GROUP_CHECK(3,!( PINB & (1 << 2) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
178 DET_GROUP_CHECK(4,!( PINB & (1 << 3) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
179 DET_GROUP_CHECK(5,!( PINB & (1 << 4) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
180 DET_GROUP_CHECK(6,!( PINB & (1 << 5) )) \ |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
181 |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
182 // Used for 1 detection group (Skips J1 P6 and J1 P9) |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
183 #define DET_GROUP_3 \ |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
184 DET_GROUP_CHECK(0,!( PINE & (1 << 7) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
185 DET_GROUP_CHECK(1,!( PINB & (1 << 0) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
186 DET_GROUP_CHECK(2,!( PINB & (1 << 1) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
187 DET_GROUP_CHECK(3,!( PINB & (1 << 2) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
188 DET_GROUP_CHECK(4,!( PINB & (1 << 4) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
189 DET_GROUP_CHECK(5,!( PINB & (1 << 5) )) \ |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
190 |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
191 // Used for 3 detection groups (No skips, except special group 1) |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
192 #define DET_GROUP_4 \ |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
193 DET_GROUP_CHECK(0,!( PINE & (1 << 7) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
194 DET_GROUP_CHECK(1,!( PINB & (1 << 0) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
195 DET_GROUP_CHECK(2,!( PINB & (1 << 1) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
196 DET_GROUP_CHECK(3,!( PINB & (1 << 2) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
197 DET_GROUP_CHECK(4,!( PINB & (1 << 3) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
198 DET_GROUP_CHECK(5,!( PINB & (1 << 4) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
199 DET_GROUP_CHECK(6,!( PINB & (1 << 5) )) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
200 DET_GROUP_CHECK(7,!( PINB & (1 << 6) )) \ |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
201 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
202 // Combines the DET_GROUP_Xs above for the given groupArray |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
203 #define DET_GROUP(group,det_group) \ |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
204 case group: \ |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
205 { \ |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
206 uint8_t groupArray[DETECT_group_size_##group] = DETECT_group_array_##group; \ |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
207 _delay_us(1); \ |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
208 DET_GROUP_##det_group \ |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
209 } \ |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
210 break; |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
211 |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
212 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
213 // Loop over all of the sampled keys of the given array |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
214 // If the number of samples is higher than the sample threshold, flag the high bit, clear otherwise |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
215 // This should be resetting VERY quickly, cutting off a potentially valid keypress is not an issue |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
216 #define DEBOUNCE_ASSESS(table,size) \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
217 for ( uint8_t key = 1; key < size + 1; key++ ) {\ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
218 table[key] = ( table[key] & ~(1 << 7) ) > SAMPLE_THRESHOLD ? (1 << 7) : 0x00; \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
219 } \ |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
220 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
221 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
222 // NOTE: Highest Bit: Valid keypress (0x80 is valid keypress) |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
223 // Other Bits: Pressed state sample counter |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
224 uint8_t keyDetectArray[KEYBOARD_SIZE + 1]; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
225 uint8_t keypadDetectArray[KEYPAD_SIZE + 1]; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
226 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
227 uint16_t sendKeypressCounter = 0; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
228 volatile uint8_t sendKeypresses = 0; |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
229 |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
230 static const uint8_t defaultMap[] = { 0, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
231 KEY_INSERT, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
232 KEY_1, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
233 KEY_2, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
234 KEY_3, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
235 KEY_4, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
236 KEY_5, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
237 KEY_6, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
238 KEY_7, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
239 KEY_8, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
240 KEY_9, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
241 KEY_0, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
242 KEY_MINUS, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
243 KEY_EQUAL, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
244 KEY_BACKSLASH, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
245 KEY_ALT, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
246 KEY_TAB, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
247 KEY_Q, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
248 KEY_W, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
249 KEY_E, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
250 KEY_R, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
251 KEY_T, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
252 KEY_Y, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
253 KEY_U, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
254 KEY_I, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
255 KEY_O, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
256 KEY_P, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
257 KEY_LEFT_BRACE, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
258 KEY_RIGHT_BRACE, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
259 KEY_DELETE, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
260 KEY_UP, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
261 KEY_CTRL, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
262 KEY_CAPS_LOCK, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
263 KEY_A, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
264 KEY_S, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
265 KEY_D, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
266 KEY_F, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
267 KEY_G, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
268 KEY_H, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
269 KEY_J, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
270 KEY_K, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
271 KEY_L, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
272 KEY_SEMICOLON, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
273 KEY_QUOTE, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
274 KEY_ENTER, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
275 KEY_DOWN, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
276 KEY_ESC, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
277 KEY_LEFT_SHIFT, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
278 KEY_Z, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
279 KEY_X, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
280 KEY_C, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
281 KEY_V, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
282 KEY_B, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
283 KEY_N, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
284 KEY_M, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
285 KEY_COMMA, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
286 KEY_PERIOD, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
287 KEY_SLASH, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
288 KEY_RIGHT_SHIFT, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
289 KEY_LEFT, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
290 KEY_RIGHT, |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
291 KEY_SPACE }; |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
292 |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
293 // Scan Code Decoder (for debug) |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
294 void printDecodeScancode( int code ) |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
295 { |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
296 |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
297 static const char* decodeArray[] = { "", "", "", "", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "Enter", "Esc", "Backspace", "Tab", "Space", "-_", "=+", "[{", "]}", "\\", "#", ";:", "'\"", "`~", ",<", ".>", "/?", "Caps Lock", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "Print Screen", "Scroll Lock", "Pause", "Insert", "Home", "Page Up", "Delete", "End", "Page Down", "Right", "Left", "Down", "Up", "Num Lock", "K1", "K2", "K3", "K4", "K5", "K6", "K7", "K8", "K9", "K0", "K." }; |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
298 print_P( decodeArray[ defaultMap[code] ] ); |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
299 } |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
300 |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
301 void detection( int group ) |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
302 { |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
303 // XXX Modify for different detection groups <-> groupArray mappings |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
304 switch ( group ) { |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
305 DET_GROUP(1,2) |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
306 DET_GROUP(2,2) |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
307 DET_GROUP(3,3) |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
308 DET_GROUP(4,4) |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
309 DET_GROUP(5,2) |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
310 DET_GROUP(6,2) |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
311 DET_GROUP(7,4) |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
312 DET_GROUP(8,4) |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
313 DET_GROUP(9,1) |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
314 } |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
315 } |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
316 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
317 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
318 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
319 // XXX This part is configurable |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
320 inline void pinSetup(void) |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
321 { |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
322 // For each pin, 0=input, 1=output |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
323 DDRA = 0x00; |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
324 DDRB = 0x00; |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
325 DDRC = 0x00; |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
326 DDRD = 0xFC; |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
327 DDRE = 0x43; |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
328 DDRF = 0x00; |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
329 |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
330 |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
331 // Setting pins to either high or pull-up resistor |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
332 PORTA = 0xFF; |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
333 PORTB = 0xFF; |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
334 PORTC = 0x01; |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
335 PORTD = 0xFF; |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
336 PORTE = 0xC3; |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
337 PORTF = 0xFF; |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
338 } |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
339 |
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
340 int main( void ) |
0 | 341 { |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
342 // Setup with 16 MHz clock |
0 | 343 CPU_PRESCALE( 0 ); |
344 | |
345 // Configuring Pins | |
2
c3b2eaa4a89d
Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents:
1
diff
changeset
|
346 pinSetup(); |
0 | 347 |
348 // Initialize the USB, and then wait for the host to set configuration. | |
349 // If the Teensy is powered without a PC connected to the USB port, | |
350 // this will wait forever. | |
351 usb_init(); | |
352 while ( !usb_configured() ) /* wait */ ; | |
353 | |
354 // Wait an extra second for the PC's operating system to load drivers | |
355 // and do whatever it does to actually be ready for input | |
356 _delay_ms(1000); | |
357 | |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
358 // Setup ISR Timer for flagging a kepress send to USB |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
359 // Set to 256 * 1024 (8 bit timer with Clock/1024 prescalar) timer |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
360 // |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
361 TCCR0A = 0x00; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
362 TCCR0B = 0x03; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
363 TIMSK0 = (1 << TOIE0); |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
364 |
0 | 365 // Main Detection Loop |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
366 int8_t group = 1; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
367 uint8_t count = 0; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
368 for ( ;;group++ ) { |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
369 // XXX Change number of ORDs if number of lines (RowsxColumns) differ |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
370 // Determine which keys are being pressed |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
371 switch ( group ) { |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
372 DD_CASE_ORD(1) |
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
373 DD_CASE_ORD(2) |
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
374 DD_CASE_ORD(3) |
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
375 DD_CASE_ORD(4) |
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
376 DD_CASE_ORD(5) |
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
377 DD_CASE_ORD(6) |
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
378 DD_CASE_ORD(7) |
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
379 DD_CASE_ORD(8) |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
380 DD_CASE_END(9,group) |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
381 } |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
382 |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
383 // Check all Keyboard keys first |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
384 if ( group != -1 ) |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
385 continue; |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
386 |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
387 // Check Keypad keys |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
388 // TODO |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
389 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
390 // Check count to see if the sample threshold may have been reached, otherwise collect more data |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
391 count++; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
392 if ( count < MAX_SAMPLES ) |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
393 continue; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
394 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
395 // Reset Sample Counter |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
396 count = 0; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
397 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
398 // Assess debouncing sample table |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
399 DEBOUNCE_ASSESS(keyDetectArray,KEYBOARD_SIZE) |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
400 //DEBOUNCE_ASSESS(keypadDetectArray,KEYPAD_SIZE) |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
401 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
402 // Send keypresses over USB if the ISR has signalled that it's time |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
403 if ( !sendKeypresses ) |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
404 continue; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
405 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
406 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
407 // Detect Valid Keypresses - TODO |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
408 uint8_t validKeys = 0; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
409 for ( uint8_t key = 0; key < KEYBOARD_SIZE + 1; key++ ) { |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
410 //phex(keyDetectArray[key]); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
411 //print ("|"); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
412 if ( keyDetectArray[key] & (1 << 7) ) { |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
413 //print("0x"); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
414 //phex( key ); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
415 pint8( key ); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
416 print(" "); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
417 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
418 // Too many keys |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
419 if ( validKeys == 6 ) |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
420 break; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
421 keyboard_keys[validKeys++] = defaultMap[key]; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
422 } |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
423 } |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
424 print(":\n"); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
425 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
426 // TODO undo potentially old keys |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
427 for ( uint8_t c = validKeys; c < 6; c++ ) |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
428 keyboard_keys[c] = 0; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
429 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
430 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
431 // Debugging Output |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
432 //phex(PINA); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
433 //phex(PINF); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
434 //print("\n"); |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
435 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
436 |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
437 |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
438 // Print out the current keys pressed |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
439 /* |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
440 if ( keyDetectCount > 0 ) { |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
441 print("Switch: "); |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
442 for ( int c = 0; c < keyDetectCount; c++ ) { |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
443 print("0x"); |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
444 phex( keyDetectArray[c] ); |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
445 print("|"); |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
446 //printDecodeScancode( keyDetectArray[c] ); |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
447 print(" "); |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
448 |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
449 } |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
450 print("\n"); |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
451 } |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
452 if ( modifiers ) { |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
453 print("Modifiers: "); |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
454 phex( modifiers ); |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
455 print("\n"); |
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
456 } |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
457 */ |
5
a8be29294c26
Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents:
4
diff
changeset
|
458 |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
459 // After going through each of the key groups, send the detected keys and modifiers |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
460 // Currently limited to the USB spec (6 keys + modifiers) |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
461 // Making sure to pass zeros when there are no keys being pressed |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
462 /* |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
463 for ( int c = 0; c < 6 && c < keyDetectCount; c++ ) |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
464 keyboard_keys[c] = c < keyDetectCount ? keyDetectArray[c] : 0; |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
465 |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
466 // Modifiers |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
467 keyboard_modifier_keys = modifiers; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
468 */ |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
469 |
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
470 // Send keypresses |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
471 usb_keyboard_send(); |
4
b97797936037
Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents:
3
diff
changeset
|
472 |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
473 // Clear sendKeypresses Flag |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
474 sendKeypresses = 0; |
3
7b9bde7ba7ef
Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents:
2
diff
changeset
|
475 } |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
476 |
0 | 477 // usb_keyboard_press(KEY_B, KEY_SHIFT); |
1
0f88e9aad77a
Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents:
0
diff
changeset
|
478 return 0; |
0 | 479 } |
480 | |
6
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
481 ISR( TIMER0_OVF_vect ) |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
482 { |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
483 sendKeypressCounter++; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
484 if ( sendKeypressCounter > USB_TRANSFER_DIVIDER ) { |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
485 sendKeypressCounter = 0; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
486 sendKeypresses = 1; |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
487 } |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
488 } |
9df636be6feb
Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents:
5
diff
changeset
|
489 |