annotate main.c @ 16:f74b797ac060

Parts of the upcoming rewrite
author Jacob Alexander <triplehaata@gmail.com>
date Thu, 22 Sep 2011 23:33:56 -0700
parents 8b6ef979a50e
children 85bc68be98df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
1 /* Copyright (C) 2011 by Jacob Alexander
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
2 *
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
4 * of this software and associated documentation files (the "Software"), to deal
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
5 * in the Software without restriction, including without limitation the rights
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
7 * copies of the Software, and to permit persons to whom the Software is
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
8 * furnished to do so, subject to the following conditions:
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
9 *
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
10 * The above copyright notice and this permission notice shall be included in
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
11 * all copies or substantial portions of the Software.
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
12 *
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
19 * THE SOFTWARE.
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
20 */
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
21
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
22 #include <avr/io.h>
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
23 #include <avr/pgmspace.h>
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
24 #include <avr/interrupt.h>
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
25 #include <util/delay.h>
10
f35ea5de4456 Adding all of the USB keycodes, and proper key ordering.
Jacob Alexander <triplehaata@gmail.com>
parents: 9
diff changeset
26 #include "usb_keys.h"
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
27 #include "scan_loop.h"
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
28 //#include "layouts.h"
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
29 //#include "usb_keyboard.h"
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
30
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
31 // TEMP INCLUDES
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
32 #include "usb_keyboard_debug.h"
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
33 #include <print.h>
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
34
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
35 #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
36
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
37
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
38 // Debouncing Defines
13
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
39 #define SAMPLE_THRESHOLD 110
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
40 #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
41
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
42
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
43 // Verified Keypress Defines
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
44 #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
45
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
46 /*
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
47 // Number of keys
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
48 #define KEYBOARD_SIZE 63
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
49 #define KEYPAD_SIZE 16
1
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 // Switch Codes
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
106 #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
107 #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
108 #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
109 #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
110 #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
111 #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
112 #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
113 #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
114 #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
115 #define DETECT_group_array_10 <blank>
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
116 #define DETECT_group_array_11 <blank>
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
117 #define DETECT_group_array_12 <blank>
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
118
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
119
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
120
3
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
121 // Drive Macros (Generally don't need to be changed), except for maybe DRIVE_DETECT
14
31e2022f06a0 Correcting debounce issues.
Jacob Alexander <triplehaata@gmail.com>
parents: 13
diff changeset
122 // Sleep is for signal debouncing
1
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
123 #define DRIVE_DETECT(reg,pin,group) \
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
124 reg &= ~(1 << pin); \
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
125 detection(group); \
14
31e2022f06a0 Correcting debounce issues.
Jacob Alexander <triplehaata@gmail.com>
parents: 13
diff changeset
126 reg |= (1 << pin); \
31e2022f06a0 Correcting debounce issues.
Jacob Alexander <triplehaata@gmail.com>
parents: 13
diff changeset
127 _delay_us(1);
1
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
128
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
129 #define DD_CASE(number) \
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
130 case number:\
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
131 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
132
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
133 #define DD_CASE_ORD(number) \
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
134 DD_CASE(number) \
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
135 break;
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
136
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
137 #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
138 DD_CASE(number) \
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
139 var = -1; \
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
140 break;
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
141
3
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
142
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
143 // Updates the current detection sample and last sample bit
3
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
144 // 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
145 // 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
146 #define DET_GROUP_CHECK(index,test) \
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
147 if ( test ) { \
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
148 keyDetectArray[groupArray[index]]++; \
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
149 }
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
150
3
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
151
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
152 // XXX - Detection Groups
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
153 // 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
154 // Inverse logic applies for the PINs
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
155
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
156 // Used for 1 detection group (Special group)
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
157 #define DET_GROUP_1 \
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
158 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
159 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
160 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
161 DET_GROUP_CHECK(3,!( PIND & (1 << 1) )) \
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
162
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
163 // Used for 4 detection groups (Skips J1 P9)
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
164 #define DET_GROUP_2 \
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
165 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
166 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
167 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
168 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
169 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
170 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
171 DET_GROUP_CHECK(6,!( PINB & (1 << 5) )) \
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
172
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
173 // 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
174 #define DET_GROUP_3 \
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
175 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
176 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
177 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
178 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
179 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
180 DET_GROUP_CHECK(5,!( 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 3 detection groups (No skips, except special group 1)
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
183 #define DET_GROUP_4 \
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 << 3) )) \
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 << 4) )) \
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
190 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
191 DET_GROUP_CHECK(7,!( PINB & (1 << 6) )) \
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
192
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
193 // Combines the DET_GROUP_Xs above for the given groupArray
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
194 #define DET_GROUP(group,det_group) \
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
195 case group: \
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
196 { \
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
197 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
198 _delay_us(1); \
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
199 DET_GROUP_##det_group \
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
200 } \
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
201 break;
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
202
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
203
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
204 // 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
205 // 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
206 // 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
207 #define DEBOUNCE_ASSESS(table,size) \
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
208 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
209 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
210 } \
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
211
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
212
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
213 // Keypad detection
8
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
214 // Each switch has it's own detection line, inverse logic
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
215 #define KEYPAD_DETECT(test,switch_code) \
8
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
216 if ( !(test) ) { \
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
217 keypadDetectArray[switch_code]++; \
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
218 } \
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
219
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
220
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
221 // 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
222 // Other Bits: Pressed state sample counter
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
223 uint8_t keyboardDetectArray[KEYBOARD_SIZE + 1];
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
224
12
d42d16dd7393 Moving the layouts to a separate file.
Jacob Alexander <triplehaata@gmail.com>
parents: 11
diff changeset
225 // Interrupt Variables
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
226 uint16_t sendKeypressCounter = 0;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
227 volatile uint8_t sendKeypresses = 0;
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
228
11
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
229
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
230 void detection( int group )
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
231 {
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
232 // XXX Modify for different detection groups <-> groupArray mappings
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
233 switch ( group ) {
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
234 DET_GROUP(1,2)
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
235 DET_GROUP(2,2)
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
236 DET_GROUP(3,3)
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
237 DET_GROUP(4,4)
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
238 DET_GROUP(5,2)
3
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
239 DET_GROUP(6,2)
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
240 DET_GROUP(7,4)
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
241 DET_GROUP(8,4)
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
242 DET_GROUP(9,1)
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
243 }
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
244 }
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
245 */
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
246
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
247 // Error LED Control
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
248 void errorLED( uint8_t on )
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
249 {
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
250 // Error LED On
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
251 if ( on ) {
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
252 DDRD |= (1<<6);
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
253 PORTD |= (1<<6);
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
254 }
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
255 // Error LED Off
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
256 else {
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
257 DDRD &= ~(1<<6);
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
258 PORTD &= ~(1<<6);
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
259 }
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
260 }
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
261
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
262
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
263
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
264 // Initial Pin Setup
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
265 // If the matrix is properly set, this function does not need to be changed
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
266 inline void pinSetup(void)
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
267 {
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
268 // For each pin, 0=input, 1=output
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
269 DDRA = 0x00;
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
270 DDRB = 0x00;
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
271 DDRC = 0x00;
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
272 DDRD = 0x40; // LED Setup
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
273 DDRE = 0x00;
5
a8be29294c26 Updating for the latest pinout
Jacob Alexander <triplehaata@gmail.com>
parents: 4
diff changeset
274 DDRF = 0x00;
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
275
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
276
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
277 // Setting pins to either high or pull-up resistor
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
278 PORTA = 0x00;
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
279 PORTB = 0x00;
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
280 PORTC = 0x00;
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
281 PORTD = 0x40; // LED Enable
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
282 PORTE = 0x00;
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
283 PORTF = 0x00;
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
284 }
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
285 /*
10
f35ea5de4456 Adding all of the USB keycodes, and proper key ordering.
Jacob Alexander <triplehaata@gmail.com>
parents: 9
diff changeset
286 // Given a sampling array, and the current number of detected keypress
f35ea5de4456 Adding all of the USB keycodes, and proper key ordering.
Jacob Alexander <triplehaata@gmail.com>
parents: 9
diff changeset
287 // Add as many keypresses from the sampling array to the USB key send array as possible.
11
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
288 void keyPressDetection( uint8_t *keys, uint8_t *validKeys, uint8_t numberOfKeys, uint8_t *modifiers, uint8_t numberOfModifiers, uint8_t *map ) {
9
102b7ec2ce6b Adding array sizes (fixing the extra key problem)
Jacob Alexander <triplehaata@gmail.com>
parents: 8
diff changeset
289 for ( uint8_t key = 0; key < numberOfKeys + 1; key++ ) {
8
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
290 if ( keys[key] & (1 << 7) ) {
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
291 pint8( key );
15
8b6ef979a50e Seems to be compiling now...finally after many months.
Jacob Alexander <triplehaata@gmail.com>
parents: 14
diff changeset
292 //print(" ");
11
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
293 uint8_t modFound = 0;
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
294
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
295 // Determine if the key is a modifier
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
296 for ( uint8_t mod = 0; mod < numberOfModifiers; mod++ ) {
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
297 // Modifier found
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
298 if ( modifiers[mod] == key ) {
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
299 keyboard_modifier_keys |= map[key];
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
300 modFound = 1;
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
301 break;
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
302 }
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
303 }
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
304 if ( modFound )
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
305 continue;
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
306
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
307 // Too many keys
8
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
308 if ( *validKeys == 6 )
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
309 break;
13
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
310
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
311 // Allow ignoring keys with 0's
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
312 if ( map[key] != 0 )
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
313 keyboard_keys[(*validKeys)++] = map[key];
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
314 }
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
315 }
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
316 }
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
317 */
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
318
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
319 int main( void )
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
320 {
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
321 // Setup with 16 MHz clock
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
322 CPU_PRESCALE( 0 );
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
323
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
324 // Configuring Pins
2
c3b2eaa4a89d Significant progress made.
Jacob Alexander <triplehaata@gmail.com>
parents: 1
diff changeset
325 pinSetup();
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
326
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
327 // Initialize the USB, and then wait for the host to set configuration.
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
328 // If the Teensy is powered without a PC connected to the USB port,
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
329 // this will wait forever.
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
330 usb_init();
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
331 while ( !usb_configured() ) /* wait */ ;
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
332
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
333 // Wait an extra second for the PC's operating system to load drivers
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
334 // and do whatever it does to actually be ready for input
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
335 _delay_ms(1000);
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
336
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
337 // 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
338 // 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
339 TCCR0A = 0x00;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
340 TCCR0B = 0x03;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
341 TIMSK0 = (1 << TOIE0);
4
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
342
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
343 // Main Detection Loop
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
344 while ( 1 ) {
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
345 scan_loop();
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
346
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
347 // Loop should never get here (indicate error)
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
348 errorLED( 1 );
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
349
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
350 // TODO HID Debug message
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
351 }
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
352 }
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
353 /*
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
354 int8_t group = 1;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
355 uint8_t count = 0;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
356 for ( ;;group++ ) {
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
357 // 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
358 // Determine which keys are being pressed
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
359 switch ( group ) {
3
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
360 DD_CASE_ORD(1)
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
361 DD_CASE_ORD(2)
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
362 DD_CASE_ORD(3)
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
363 DD_CASE_ORD(4)
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
364 DD_CASE_ORD(5)
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
365 DD_CASE_ORD(6)
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
366 DD_CASE_ORD(7)
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
367 DD_CASE_ORD(8)
4
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
368 DD_CASE_END(9,group)
3
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
369 }
4
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
370
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
371 // Check all Keyboard keys first
4
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
372 if ( group != -1 )
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
373 continue;
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
374
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
375 // Check Keypad keys
8
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
376 KEYPAD_DETECT(PINA & (1 << 0),11)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
377 KEYPAD_DETECT(PINA & (1 << 1),3)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
378 KEYPAD_DETECT(PINA & (1 << 2),7)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
379 KEYPAD_DETECT(PINA & (1 << 3),4)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
380 KEYPAD_DETECT(PINA & (1 << 4),15)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
381 KEYPAD_DETECT(PINA & (1 << 5),6)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
382 KEYPAD_DETECT(PINA & (1 << 6),2)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
383 KEYPAD_DETECT(PINA & (1 << 7),10)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
384 KEYPAD_DETECT(PINF & (1 << 0),8)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
385 KEYPAD_DETECT(PINF & (1 << 1),12)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
386 KEYPAD_DETECT(PINF & (1 << 2),16)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
387 KEYPAD_DETECT(PINF & (1 << 3),13)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
388 KEYPAD_DETECT(PINF & (1 << 4),1)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
389 KEYPAD_DETECT(PINF & (1 << 5),5)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
390 KEYPAD_DETECT(PINF & (1 << 6),9)
1e71d8e52392 Working keypad switch code detection.
Jacob Alexander <triplehaata@gmail.com>
parents: 7
diff changeset
391 KEYPAD_DETECT(PINF & (1 << 7),14)
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
392
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
393 // 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
394 count++;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
395 if ( count < MAX_SAMPLES )
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
396 continue;
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 // Reset Sample Counter
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
399 count = 0;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
400
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
401 // Assess debouncing sample table
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
402 DEBOUNCE_ASSESS(keyDetectArray,KEYBOARD_SIZE)
7
18e424630cbd Adding basic per line keypad detection
Jacob Alexander <haata@users.sf.net>
parents: 6
diff changeset
403 DEBOUNCE_ASSESS(keypadDetectArray,KEYPAD_SIZE)
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
404
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
405 // 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
406 if ( !sendKeypresses )
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
407 continue;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
408
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
409 // Detect Valid Keypresses - TODO
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
410 uint8_t validKeys = 0;
12
d42d16dd7393 Moving the layouts to a separate file.
Jacob Alexander <triplehaata@gmail.com>
parents: 11
diff changeset
411
13
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
412 uint8_t *keyboard_MODMASK = keyboard_modifierMask;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
413 uint8_t keyboard_NUMMODS = MODIFIERS_KEYBOARD;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
414 uint8_t *keyboard_MAP = defaultMap;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
415 uint8_t *keypad_MODMASK = keypad_modifierMask;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
416 uint8_t keypad_NUMMODS = MODIFIERS_KEYPAD;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
417 uint8_t *keypad_MAP = keypadDefaultMap;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
418
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
419 // Map selection - CapsLock FN
12
d42d16dd7393 Moving the layouts to a separate file.
Jacob Alexander <triplehaata@gmail.com>
parents: 11
diff changeset
420 if ( keyDetectArray[34] & (1 << 7) ) { // CapsLock FN Modifier
13
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
421 keyboard_MAP = colemakMap;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
422 keyboard_MODMASK = alternate_modifierMask;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
423 keyboard_NUMMODS = 5;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
424
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
425 // Function Key
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
426 if ( keyDetectArray[61] & (1 << 7) ) {
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
427 keyboard_MAP = navigationMap;
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
428 }
12
d42d16dd7393 Moving the layouts to a separate file.
Jacob Alexander <triplehaata@gmail.com>
parents: 11
diff changeset
429 }
d42d16dd7393 Moving the layouts to a separate file.
Jacob Alexander <triplehaata@gmail.com>
parents: 11
diff changeset
430
13
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
431 keyPressDetection( keyDetectArray, &validKeys, KEYBOARD_SIZE, keyboard_MODMASK, keyboard_NUMMODS, keyboard_MAP );
932f34404318 Adding the HHKB style navigation layer.
Jacob Alexander <triplehaata@gmail.com>
parents: 12
diff changeset
432 keyPressDetection( keypadDetectArray, &validKeys, KEYPAD_SIZE, keypad_MODMASK, keypad_NUMMODS, keypad_MAP );
15
8b6ef979a50e Seems to be compiling now...finally after many months.
Jacob Alexander <triplehaata@gmail.com>
parents: 14
diff changeset
433 //print(":\n");
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
434
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
435 // TODO undo potentially old keys
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
436 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
437 keyboard_keys[c] = 0;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
438
4
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
439 // Send keypresses
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
440 usb_keyboard_send();
4
b97797936037 Redefining pinouts and adding key sending code.
Jacob Alexander <triplehaata@gmail.com>
parents: 3
diff changeset
441
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
442 // Clear sendKeypresses Flag
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
443 sendKeypresses = 0;
11
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
444
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
445 // Clear modifiers
c033251c3e6b Minor modifications.
Jacob Alexander <triplehaata@gmail.com>
parents: 10
diff changeset
446 keyboard_modifier_keys = 0;
3
7b9bde7ba7ef Key detection complete.
Jacob Alexander <triplehaata@gmail.com>
parents: 2
diff changeset
447 }
1
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
448
0f88e9aad77a Initial macro line filler design for multiple keyboards matrices.
Jacob Alexander <triplehaata@gmail.com>
parents: 0
diff changeset
449 return 0;
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
450 }
16
f74b797ac060 Parts of the upcoming rewrite
Jacob Alexander <triplehaata@gmail.com>
parents: 15
diff changeset
451 */
0
43dfb6e4e697 Initial Commit
Jacob Alexander <triplehaata@gmail.com>
parents:
diff changeset
452
10
f35ea5de4456 Adding all of the USB keycodes, and proper key ordering.
Jacob Alexander <triplehaata@gmail.com>
parents: 9
diff changeset
453 // Timer Interrupt for flagging a send of the sampled key detection data to the USB host
6
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
454 ISR( TIMER0_OVF_vect )
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
455 {
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
456 sendKeypressCounter++;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
457 if ( sendKeypressCounter > USB_TRANSFER_DIVIDER ) {
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
458 sendKeypressCounter = 0;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
459 sendKeypresses = 1;
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
460 }
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
461 }
9df636be6feb Keyboard functionally working with very very good debouncing.
Jacob Alexander <triplehaata@gmail.com>
parents: 5
diff changeset
462