Skip to content

Commit 6b9ce31

Browse files
committed
Updated for ProMicro pinout. Not working yet
1 parent 3338939 commit 6b9ce31

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

xr22-950-splint/xr22-950-splint.ino

+37-42
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,44 @@
99
See https://docs.google.com/spreadsheets/d/1VIy-GSjdG2L6Flt3NPSkQuhC4tW-Hb9asVCBoYnCuk4/edit
1010
for the key matrix in spreadsheet form.
1111
12-
THIS VERSION FOR UNO ONLY.
12+
THIS VERSION FOR PRO MICRO ONLY.
1313
*/
1414

1515
// This MUST be an interrupt-enabled pin.
1616
const int outputEnabledPin = 2;
1717

18-
// Input (control) pins are PD6 (D) through PD3 (A)
18+
// Input (control) pins are PF4 (A) through PF7 (D)
1919
// These aren't used because we need to use direct port manipulation to
2020
// 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;
2525

26-
// Output (splint) pins are PB0 (pin 8) through PB5 (pin 12)
26+
// Output (splint) pins are PB2 through PB6
2727
// These aren't used because we need to use direct port manipulation to
2828
// set the appropriate pin high for a very short duration, and digitalWrite
2929
// 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)
3535

3636
void setup() {
3737
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");
3943

4044
pinMode(outputEnabledPin, INPUT);
4145

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;
4650
// Set outputs to low
4751
PORTB = 0;
4852

@@ -58,11 +62,11 @@ void setupSplintPins() {
5862
splintPins[i] = 0;
5963
}
6064

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.
6670
}
6771

6872
// One nop is 62NS
@@ -79,38 +83,34 @@ void setupSplintPins() {
7983
// Delay 1.4 microseconds. One nop = 62.5ns, so we use 22 nops (1.375 us)
8084
#define DELAY_1_4US "nop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\tnop\n\t"
8185

82-
#undef DEBUG
86+
#define DEBUG 1
8387

8488
#ifdef DEBUG
85-
#define DBG_COUNT 1000000
86-
volatile int printed = 0; // debugging
89+
#define DBG_COUNT 1000
90+
long printed = 0; // debugging
8791
#endif
8892

8993
void intHandler() {
9094
// 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];
9297

9398
#ifdef DEBUG
9499
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;
99104
// Debugging
100105
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;
101108
} else {
102109
printed++;
103110
}
104111
#endif
105112

106-
byte outputPins = splintPins[controlPins];
107113
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-
114114
// Wait 3 us between the OE and the pulse.
115115
__asm__(DELAY_3US);
116116
// Set all outputs on Port B
@@ -120,11 +120,6 @@ void intHandler() {
120120
__asm__(DELAY_4US);
121121
PORTB = B00000000;
122122
}
123-
#ifdef DEBUG
124-
if (printed == DBG_COUNT) {
125-
printed = 0;
126-
}
127-
#endif
128123
}
129124

130125
void loop() {

0 commit comments

Comments
 (0)