9
9
See https://docs.google.com/spreadsheets/d/1VIy-GSjdG2L6Flt3NPSkQuhC4tW-Hb9asVCBoYnCuk4/edit
10
10
for the key matrix in spreadsheet form.
11
11
12
- THIS VERSION FOR UNO ONLY.
12
+ THIS VERSION FOR PRO MICRO ONLY.
13
13
*/
14
14
15
15
// This MUST be an interrupt-enabled pin.
16
16
const int outputEnabledPin = 2 ;
17
17
18
- // Input (control) pins are PD6 (D ) through PD3 (A )
18
+ // Input (control) pins are PF4 (A ) through PF7 (D )
19
19
// These aren't used because we need to use direct port manipulation to
20
20
// read all 4 pins at the same time.
21
- // const int aPin = 3 ;
22
- // const int bPin = 4 ;
23
- // const int cPin = 5 ;
24
- // const int dPin = 6 ;
21
+ // const int aPin = A3 ;
22
+ // const int bPin = A2 ;
23
+ // const int cPin = A1 ;
24
+ // const int dPin = A0 ;
25
25
26
- // Output (splint) pins are PB0 (pin 8) through PB5 (pin 12)
26
+ // Output (splint) pins are PB2 through PB6
27
27
// These aren't used because we need to use direct port manipulation to
28
28
// set the appropriate pin high for a very short duration, and digitalWrite
29
29
// is too slow.
30
- // const int y0 = 8 ; // PB2, XR22-950 pin 12 (Y0)
31
- // const int y1 = 9 ; // PB3, XR22-950 pin 13 (Y1)
32
- // const int y2 = 10; // PB4, XR22-950 pin 14 (Y2)
33
- // const int y3 = 11; // PB5, XR22-950 pin 15 (Y3)
34
- // const int y4 = 12; // PB6, XR22-950 pin 16 (Y4)
30
+ // const int y0 = 16 ; // PB2, XR22-950 pin 12 (Y0)
31
+ // const int y1 = 14 ; // PB3, XR22-950 pin 13 (Y1)
32
+ // const int y2 = 8; // PB4, XR22-950 pin 14 (Y2)
33
+ // const int y3 = 9; // PB5, XR22-950 pin 15 (Y3)
34
+ // const int y4 = 10; // PB6, XR22-950 pin 16 (Y4)
35
35
36
36
void setup () {
37
37
Serial.begin (9600 );
38
- Serial.println (" Hello xr22-950-splint for uno" );
38
+
39
+ while (!Serial) {
40
+ ; // wait for serial port to connect. Needed for native USB port only
41
+ }
42
+ Serial.println (" Hello xr22-950-splint for ProMicro" );
39
43
40
44
pinMode (outputEnabledPin, INPUT);
41
45
42
- // Input (control) pins are PD6 (D ) through PD3 (A )
43
- DDRD = B00000000;
44
- // Output (splint) pins are PB0 (pin8) through PB5 (pin 12)
45
- DDRB |= B00011111 ;
46
+ // Input (control) pins are PF4 (A ) through PF7 (D )
47
+ DDRF = B00000000;
48
+ // Output (splint) pins are PB2 through PB6
49
+ DDRB |= B01111100 ;
46
50
// Set outputs to low
47
51
PORTB = 0 ;
48
52
@@ -58,11 +62,11 @@ void setupSplintPins() {
58
62
splintPins[i] = 0 ;
59
63
}
60
64
61
- splintPins[0 ] = B00000001 ; // PB2, XR22-950 Pin 12 (Y0). Restores shift, ctrl, caps lock.
62
- splintPins[1 ] = B00000010 ; // PB3, XR22-950 Pin 13 (Y1): Should restore the right half of the numeric keypad.
63
- splintPins[2 ] = B00000100 ; // PB4, XR22-950 Pin 14 (Y2): Should restore the left half of the numeric keypad.
64
- splintPins[3 ] = B00001000 ; // PB5, XR22-950 Pin 15 (Y3). Should restore right third of keys (enter, backspace), etc.
65
- splintPins[4 ] = B00010000 ; // PB6, XR22-950 Pin 16 (Y4). Restores AZXCV, space.
65
+ splintPins[0 ] = B00000100 ; // PB2, XR22-950 Pin 12 (Y0). Restores shift, ctrl, caps lock.
66
+ splintPins[1 ] = B00001000 ; // PB3, XR22-950 Pin 13 (Y1): Should restore the right half of the numeric keypad.
67
+ splintPins[2 ] = B00010000 ; // PB4, XR22-950 Pin 14 (Y2): Should restore the left half of the numeric keypad.
68
+ splintPins[3 ] = B00100000 ; // PB5, XR22-950 Pin 15 (Y3). Should restore right third of keys (enter, backspace), etc.
69
+ splintPins[4 ] = B01000000 ; // PB6, XR22-950 Pin 16 (Y4). Restores AZXCV, space.
66
70
}
67
71
68
72
// One nop is 62NS
@@ -79,38 +83,34 @@ void setupSplintPins() {
79
83
// Delay 1.4 microseconds. One nop = 62.5ns, so we use 22 nops (1.375 us)
80
84
#define DELAY_1_4US " nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t "
81
85
82
- #undef DEBUG
86
+ #define DEBUG 1
83
87
84
88
#ifdef DEBUG
85
- #define DBG_COUNT 1000000
86
- volatile int printed = 0 ; // debugging
89
+ #define DBG_COUNT 1000
90
+ long printed = 0 ; // debugging
87
91
#endif
88
92
89
93
void intHandler () {
90
94
// Read pins a,b,c,d at the same time (upper 4 bits, then shift to the bottom nibble)
91
- int controlPins = (PIND & B01111000) >> 3 ;
95
+ int inputPins = (PINF & B11110000) >> 4 ;
96
+ byte outputPins = splintPins[inputPins];
92
97
93
98
#ifdef DEBUG
94
99
if (printed == DBG_COUNT) {
95
- int a = (controlPins & B00000001),
96
- b = (controlPins & B00000010) >> 1 ,
97
- c = (controlPins & B00000100) >> 2 ,
98
- d = (controlPins & B00001000) >> 3 ;
100
+ int a = (inputPins & B00000001),
101
+ b = (inputPins & B00000010) >> 1 ,
102
+ c = (inputPins & B00000100) >> 2 ,
103
+ d = (inputPins & B00001000) >> 3 ;
99
104
// Debugging
100
105
Serial.print (" DCBA=" ); Serial.print (d); Serial.print (c); Serial.print (b); Serial.println (a);
106
+ Serial.print (" sending blip on 0B" ); Serial.println (outputPins, BIN);
107
+ printed = 0 ;
101
108
} else {
102
109
printed++;
103
110
}
104
111
#endif
105
112
106
- byte outputPins = splintPins[controlPins];
107
113
if (outputPins != 0 ) {
108
- #ifdef DEBUG
109
- if (printed == DBG_COUNT) {
110
- Serial.print (" sending blip on 0B" ); Serial.println (outputPins, BIN);
111
- }
112
- #endif
113
-
114
114
// Wait 3 us between the OE and the pulse.
115
115
__asm__ (DELAY_3US);
116
116
// Set all outputs on Port B
@@ -120,11 +120,6 @@ void intHandler() {
120
120
__asm__ (DELAY_4US);
121
121
PORTB = B00000000;
122
122
}
123
- #ifdef DEBUG
124
- if (printed == DBG_COUNT) {
125
- printed = 0 ;
126
- }
127
- #endif
128
123
}
129
124
130
125
void loop () {
0 commit comments