Last active
November 18, 2017 22:14
-
-
Save pacmancoder/fbc334e8faf5932d2806f10af32a4791 to your computer and use it in GitHub Desktop.
Patch for TMK firmware to work with old BTC keyboard (XT protocol)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/converter/xt_usb/Makefile b/converter/xt_usb/Makefile | |
index 395115e..a798490 100644 | |
--- a/converter/xt_usb/Makefile | |
+++ b/converter/xt_usb/Makefile | |
@@ -70,7 +70,7 @@ F_USB = $(F_CPU) | |
# Atmel DFU loader 4096 | |
# LUFA bootloader 4096 | |
# USBaspLoader 2048 | |
-OPT_DEFS += -DBOOTLOADER_SIZE=512 | |
+OPT_DEFS += -DBOOTLOADER_SIZE=4096 | |
# Build Options | |
diff --git a/converter/xt_usb/led.c b/converter/xt_usb/led.c | |
index 8eaa88b..4e507c3 100644 | |
--- a/converter/xt_usb/led.c | |
+++ b/converter/xt_usb/led.c | |
@@ -1,3 +1,4 @@ | |
+#include <util/delay.h> | |
/* | |
Copyright 2016 Ethan Apodaca <papodaca@gmail.com> | |
@@ -16,5 +17,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
void led_set(uint8_t usb_led) { | |
- //XT Keyboards do not have LEDs, nothing to do. | |
+ PORTF = ((~((usb_led << 6) & 0x40)) & (~((usb_led << 4) & 0x20)) & (~((usb_led << 2) & 0x10))) & 0x70; | |
+ PORTF |= 0x80; | |
+ _delay_ms(1); | |
+ PORTF ^= 0x80; | |
} | |
+ | |
diff --git a/converter/xt_usb/matrix.c b/converter/xt_usb/matrix.c | |
index 51742dd..d0ff8e2 100644 | |
--- a/converter/xt_usb/matrix.c | |
+++ b/converter/xt_usb/matrix.c | |
@@ -45,7 +45,8 @@ void matrix_init(void) | |
// initialize matrix state: all keys off | |
for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; | |
- | |
+ // LED's | |
+ DDRF = 0xF0; | |
return; | |
} | |
@@ -112,7 +113,8 @@ uint8_t matrix_scan(void) | |
E1_1D_45_E1_9D, | |
// pause | |
} state = INIT; | |
- | |
+ | |
+ static int processing = 0; | |
// 'pseudo break code' hack | |
if (matrix_is_on(ROW(PAUSE), COL(PAUSE))) { | |
@@ -120,14 +122,20 @@ uint8_t matrix_scan(void) | |
} | |
uint8_t code = xt_host_recv(); | |
+ // if we waiting for sequence, then wait. | |
+ if (!code && processing) { | |
+ return 1; | |
+ } | |
switch (state) { | |
case INIT: | |
switch (code) { | |
case 0xE0: | |
state = E0; | |
+ processing = 1; | |
break; | |
case 0xE1: | |
state = E1; | |
+ processing = 1; | |
break; | |
default: // normal key make | |
if (code < 0x80 && code != 0x00) { | |
@@ -138,15 +146,18 @@ uint8_t matrix_scan(void) | |
matrix_break(code - 0x80); | |
} | |
state = INIT; | |
+ processing = 0; | |
} | |
break; | |
case E0: // E0-Prefixed | |
switch (code) { //move these codes to unused places on the matrix | |
case 0x2A: | |
state = E0_2A; | |
+ processing = 1; | |
break; | |
case 0xB7: | |
state = E0_B7; | |
+ processing = 1; | |
break; | |
default: | |
if (code < 0x80 && code != 0x00) { | |
@@ -155,64 +166,87 @@ uint8_t matrix_scan(void) | |
matrix_break(move_codes(code - 0x80)); | |
} | |
state = INIT; | |
+ processing = 0; | |
} | |
break; | |
case E0_2A: | |
- if(code == 0xE0) | |
+ if(code == 0xE0) { | |
state = E0_2A_E0; | |
- else | |
+ processing = 1; | |
+ } else { | |
state = INIT; | |
+ processing = 0; | |
+ } | |
break; | |
case E0_2A_E0: | |
if(code == 0x37) | |
matrix_make(PRINT_SCREEN); | |
else | |
state = INIT; | |
+ processing = 0; | |
break; | |
case E0_B7: | |
- if(code == 0xE0) | |
- state = E0_B7; | |
- else | |
+ if(code == 0xE0) { | |
+ state = E0_B7_E0; | |
+ processing = 1; | |
+ } else { | |
state = INIT; | |
+ processing = 0; | |
+ } | |
break; | |
case E0_B7_E0: | |
if(code == 0xAA) | |
matrix_break(PRINT_SCREEN); | |
else | |
state = INIT; | |
+ processing = 0; | |
break; | |
case E1: | |
- if (code == 0x1D) | |
+ if (code == 0x1D) { | |
state = E1_1D; | |
- else | |
+ processing = 1; | |
+ } else { | |
state = INIT; | |
+ processing = 0; | |
+ } | |
break; | |
case E1_1D: | |
- if(code == 0x45) | |
+ if(code == 0x45) { | |
state = E1_1D_45; | |
- else | |
+ processing = 1; | |
+ } else { | |
state = INIT; | |
+ processing = 0; | |
+ } | |
break; | |
case E1_1D_45: | |
- if(code == 0xE1) | |
+ if(code == 0xE1) { | |
state = E1_1D_45_E1; | |
- else | |
+ processing = 1; | |
+ } else { | |
state = INIT; | |
+ processing = 0; | |
+ } | |
break; | |
case E1_1D_45_E1: | |
- if(code == 0x9D) | |
+ if(code == 0x9D) { | |
state = E1_1D_45_E1_9D; | |
- else | |
+ processing = 1; | |
+ } else { | |
state = INIT; | |
+ processing = 0; | |
+ } | |
break; | |
case E1_1D_45_E1_9D: | |
if(code == 0xC5) | |
matrix_make(PAUSE); | |
else | |
state = INIT; | |
+ processing = 0; | |
break; | |
default: | |
state = INIT; | |
+ processing = 0; | |
} | |
return 1; | |
} | |
diff --git a/tmk_core/protocol/xt_interrupt.c b/tmk_core/protocol/xt_interrupt.c | |
index 94b47db..c06d09b 100644 | |
--- a/tmk_core/protocol/xt_interrupt.c | |
+++ b/tmk_core/protocol/xt_interrupt.c | |
@@ -78,17 +78,11 @@ ISR(XT_INT_VECT) | |
if (data_in()) | |
data |= 0x80; | |
if (state == 8) | |
- goto END; | |
+ pbuf_enqueue(data); | |
state++; | |
} else { | |
- goto DONE; | |
+ state = 0; | |
+ data = 0; | |
} | |
- goto RETURN; | |
-END: | |
- pbuf_enqueue(data); | |
-DONE: | |
- state = 0; | |
- data = 0; | |
-RETURN: | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment