diff --git a/keyboards/converter/xt_usb/config.h b/keyboards/converter/xt_usb/config.h
index e5624d843..5f93fbfc6 100644
--- a/keyboards/converter/xt_usb/config.h
+++ b/keyboards/converter/xt_usb/config.h
@@ -19,14 +19,14 @@ along with this program. If not, see .
#include "config_common.h"
-#define VENDOR_ID 0xFEED
-#define PRODUCT_ID 0x6512
-#define DEVICE_VER 0x0001
-#define MANUFACTURER QMK
-#define PRODUCT XT keyboard converter
+/* USB Device descriptor parameter */
+#define VENDOR_ID 0xFEED
+#define PRODUCT_ID 0x6512
+#define DEVICE_VER 0x0001
+#define MANUFACTURER QMK
+#define PRODUCT XT keyboard converter
-
-/* matrix size */
+/* key matrix size */
#define MATRIX_ROWS 16 // keycode bit: 3-0
#define MATRIX_COLS 8 // keycode bit: 6-4
@@ -36,44 +36,31 @@ along with this program. If not, see .
get_mods() == (MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT)) \
)
-
-//#define NO_SUSPEND_POWER_DOWN
-
-/*
- * XT Pin interrupt
- */
-#define XT_CLOCK_PORT PORTD
-#define XT_CLOCK_PIN PIND
-#define XT_CLOCK_DDR DDRD
-#define XT_CLOCK_BIT 1
-#define XT_DATA_PORT PORTD
-#define XT_DATA_PIN PIND
-#define XT_DATA_DDR DDRD
-#define XT_DATA_BIT 0
-#define XT_RST_PORT PORTB
-#define XT_RST_PIN PINB
-#define XT_RST_DDR DDRB
-#define XT_RST_BIT 7
+#define XT_CLOCK_PIN D1
+#define XT_DATA_PIN D0
+#define XT_RST_PIN B7
/* hard reset: low pulse for 500ms and after that HiZ for safety */
#define XT_RESET() do { \
- XT_RST_PORT &= ~(1<.
#include "xt.h"
#include "matrix.h"
-
static void matrix_make(uint8_t code);
static void matrix_break(uint8_t code);
static uint8_t matrix[MATRIX_ROWS];
-#define ROW(code) (code>>3)
-#define COL(code) (code&0x07)
+
+#define ROW(code) (code >> 3)
+#define COL(code) (code & 0x07)
__attribute__ ((weak))
void matrix_init_kb(void) {
@@ -48,16 +48,16 @@ void matrix_init_user(void) {
}
__attribute__ ((weak))
-void matrix_scan_user(void) {
-}
+void matrix_scan_user(void) { }
-void matrix_init(void)
-{
+void matrix_init(void) {
debug_enable = true;
xt_host_init();
// initialize matrix state: all keys off
- for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
+ for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
+ matrix[i] = 0x00;
+ }
matrix_init_quantum();
}
@@ -71,7 +71,7 @@ static uint8_t move_e0code(uint8_t code) {
case 0x1C: return 0x6F; // Keypad Enter
case 0x35: return 0x7F; // Keypad /
- // Any XT keyobard with these keys?
+ // Any XT keyboard with these keys?
// http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf
// https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc
case 0x5B: return 0x5A; // Left GUI
@@ -96,8 +96,7 @@ static uint8_t move_e0code(uint8_t code) {
return 0x00;
}
-uint8_t matrix_scan(void)
-{
+uint8_t matrix_scan(void) {
static enum {
XT_STATE_INIT,
XT_STATE_E0,
@@ -108,8 +107,13 @@ uint8_t matrix_scan(void)
} state = XT_STATE_INIT;
uint8_t code = xt_host_recv();
- if (!code) return 0;
+
+ if (!code) {
+ return 0;
+ }
+
xprintf("%02X ", code);
+
switch (state) {
case XT_STATE_INIT:
switch (code) {
@@ -120,10 +124,11 @@ uint8_t matrix_scan(void)
state = XT_STATE_E1;
break;
default:
- if (code < 0x80)
+ if (code < 0x80) {
matrix_make(code);
- else
+ } else {
matrix_break(code & 0x7F);
+ }
break;
}
break;
@@ -137,10 +142,11 @@ uint8_t matrix_scan(void)
state = XT_STATE_INIT;
break;
default:
- if (code < 0x80)
+ if (code < 0x80) {
matrix_make(move_e0code(code));
- else
+ } else {
matrix_break(move_e0code(code & 0x7F));
+ }
state = XT_STATE_INIT;
break;
}
@@ -181,59 +187,54 @@ uint8_t matrix_scan(void)
default:
state = XT_STATE_INIT;
}
+
matrix_scan_quantum();
+
return 1;
}
inline
-uint8_t matrix_get_row(uint8_t row)
-{
+uint8_t matrix_get_row(uint8_t row) {
return matrix[row];
}
-inline
-static void matrix_make(uint8_t code)
-{
+inline static void matrix_make(uint8_t code) {
if (!matrix_is_on(ROW(code), COL(code))) {
- matrix[ROW(code)] |= 1<
.
#include "quantum.h"
+#define XXX KC_NO
+
/* IBM XT keyboard layout
* ,-------. ,--------------------------------------------------------------------------.
* | F1| F2| |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| BS |NumLck |ScrLck |
@@ -44,28 +46,28 @@ along with this program. If not, see .
* `-------' `--------------------------------------------------------------------------'
*/
#define LAYOUT_xt( \
- K3B,K3C, K01,K02,K03,K04,K05,K06,K07,K08,K09,K0A,K0B,K0C,K0D,K0E, K45, K46, \
- K3D,K3E, K0F,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K1A,K1B, K47,K48,K49,K4A, \
- K3F,K40, K1D,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28,K29,K1C,K4B,K4C,K4D, \
- K41,K42, K2A,K2B,K2C,K2D,K2E,K2F,K30,K31,K32,K33,K34,K35,K36,K37,K4F,K50,K51,K4E, \
- K43,K44, K38, K39, K3A, K52, K53 \
+ k3B, k3C, k01, k02, k03, k04, k05, k06, k07, k08, k09, k0A, k0B, k0C, k0D, k0E, k45, k46, \
+ k3D, k3E, k0F, k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k47, k48, k49, k4A, \
+ k3F, k40, k1D, k1E, k1F, k20, k21, k22, k23, k24, k25, k26, k27, k28, k29, k1C, k4B, k4C, k4D, \
+ k41, k42, k2A, k2B, k2C, k2D, k2E, k2F, k30, k31, k32, k33, k34, k35, k36, k37, k4F, k50, k51, k4E, \
+ k43, k44, k38, k39, k3A, k52, k53 \
) { \
- { KC_NO, K01, K02, K03, K04, K05, K06, K07 }, \
- { K08, K09, K0A, K0B, K0C, K0D, K0E, K0F }, \
- { K10, K11, K12, K13, K14, K15, K16, K17 }, \
- { K18, K19, K1A, K1B, K1C, K1D, K1E, K1F }, \
- { K20, K21, K22, K23, K24, K25, K26, K27 }, \
- { K28, K29, K2A, K2B, K2C, K2D, K2E, K2F }, \
- { K30, K31, K32, K33, K34, K35, K36, K37 }, \
- { K38, K39, K3A, K3B, K3C, K3D, K3E, K3F }, \
- { K40, K41, K42, K43, K44, K45, K46, K47 }, \
- { K48, K49, K4A, K4B, K4C, K4D, K4E, K4F }, \
- { K50, K51, K52, K53, KC_NO, KC_NO, KC_NO, KC_NO }, \
- { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
- { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
- { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
- { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO }, \
- { KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO } \
+ { XXX, k01, k02, k03, k04, k05, k06, k07 }, \
+ { k08, k09, k0A, k0B, k0C, k0D, k0E, k0F }, \
+ { k10, k11, k12, k13, k14, k15, k16, k17 }, \
+ { k18, k19, k1A, k1B, k1C, k1D, k1E, k1F }, \
+ { k20, k21, k22, k23, k24, k25, k26, k27 }, \
+ { k28, k29, k2A, k2B, k2C, k2D, k2E, k2F }, \
+ { k30, k31, k32, k33, k34, k35, k36, k37 }, \
+ { k38, k39, k3A, k3B, k3C, k3D, k3E, k3F }, \
+ { k40, k41, k42, k43, k44, k45, k46, k47 }, \
+ { k48, k49, k4A, k4B, k4C, k4D, k4E, k4F }, \
+ { k50, k51, k52, k53, XXX, XXX, XXX, XXX }, \
+ { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX }, \
+ { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX }, \
+ { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX }, \
+ { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX }, \
+ { XXX, XXX, XXX, XXX, XXX, XXX, XXX, XXX } \
}
/* Extended keyboard layout
@@ -105,28 +107,28 @@ along with this program. If not, see .
* *: special handling codes
*/
#define LAYOUT( \
- K64,K65,K66,K67,K68,K69,K6A,K6B,K6C,K6D,K6E,K76, \
- K01, K3B,K3C,K3D,K3E,K3F,K40,K41,K42,K43,K44,K57,K58, K54,K46,K55, K5D,K5E,K5F, \
- K29,K02,K03,K04,K05,K06,K07,K08,K09,K0A,K0B,K0C,K0D,K7D,K0E, K71,K74,K77, K45,K7F,K37,K4A, \
- K0F,K10,K11,K12,K13,K14,K15,K16,K17,K18,K19,K1A,K1B, K2B, K72,K75,K78, K47,K48,K49,K4E, \
- K3A,K1E,K1F,K20,K21,K22,K23,K24,K25,K26,K27,K28, K00,K1C, K4B,K4C,K4D,K7E, \
- K2A,K56,K2C,K2D,K2E,K2F,K30,K31,K32,K33,K34,K35, K73,K36, K60, K4F,K50,K51,K6F, \
- K1D,K5A,K38,K7B, K39, K79,K70,K7C,K5B,K5C,K7A, K61,K62,K63, K52,K53,K59 \
+ k64, k65, k66, k67, k68, k69, k6A, k6B, k6C, k6D, k6E, k76, \
+ k01, k3B, k3C, k3D, k3E, k3F, k40, k41, k42, k43, k44, k57, k58, k54, k46, k55, k5D, k5E, k5F, \
+ k29, k02, k03, k04, k05, k06, k07, k08, k09, k0A, k0B, k0C, k0D, k7D, k0E, k71, k74, k77, k45, k7F, k37, k4A, \
+ k0F, k10, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k2B, k72, k75, k78, k47, k48, k49, k4E, \
+ k3A, k1E, k1F, k20, k21, k22, k23, k24, k25, k26, k27, k28, k00, k1C, k4B, k4C, k4D, k7E, \
+ k2A, k56, k2C, k2D, k2E, k2F, k30, k31, k32, k33, k34, k35, k73, k36, k60, k4F, k50, k51, k6F, \
+ k1D, k5A, k38, k7B, k39, k79, k70, k7C, k5B, k5C, k7A, k61, k62, k63, k52, k53, k59 \
) { \
- { K00, K01, K02, K03, K04, K05, K06, K07 }, \
- { K08, K09, K0A, K0B, K0C, K0D, K0E, K0F }, \
- { K10, K11, K12, K13, K14, K15, K16, K17 }, \
- { K18, K19, K1A, K1B, K1C, K1D, K1E, K1F }, \
- { K20, K21, K22, K23, K24, K25, K26, K27 }, \
- { K28, K29, K2A, K2B, K2C, K2D, K2E, K2F }, \
- { K30, K31, K32, K33, K34, K35, K36, K37 }, \
- { K38, K39, K3A, K3B, K3C, K3D, K3E, K3F }, \
- { K40, K41, K42, K43, K44, K45, K46, K47 }, \
- { K48, K49, K4A, K4B, K4C, K4D, K4E, K4F }, \
- { K50, K51, K52, K53, K54, K55, K56, K57 }, \
- { K58, K59, K5A, K5B, K5C, K5D, K5E, K5F }, \
- { K60, K61, K62, K63, K64, K65, K66, K67 }, \
- { K68, K69, K6A, K6B, K6C, K6D, K6E, K6F }, \
- { K70, K71, K72, K73, K74, K75, K76, K77 }, \
- { K78, K79, K7A, K7B, K7C, K7D, K7E, K7F } \
+ { k00, k01, k02, k03, k04, k05, k06, k07 }, \
+ { k08, k09, k0A, k0B, k0C, k0D, k0E, k0F }, \
+ { k10, k11, k12, k13, k14, k15, k16, k17 }, \
+ { k18, k19, k1A, k1B, k1C, k1D, k1E, k1F }, \
+ { k20, k21, k22, k23, k24, k25, k26, k27 }, \
+ { k28, k29, k2A, k2B, k2C, k2D, k2E, k2F }, \
+ { k30, k31, k32, k33, k34, k35, k36, k37 }, \
+ { k38, k39, k3A, k3B, k3C, k3D, k3E, k3F }, \
+ { k40, k41, k42, k43, k44, k45, k46, k47 }, \
+ { k48, k49, k4A, k4B, k4C, k4D, k4E, k4F }, \
+ { k50, k51, k52, k53, k54, k55, k56, k57 }, \
+ { k58, k59, k5A, k5B, k5C, k5D, k5E, k5F }, \
+ { k60, k61, k62, k63, k64, k65, k66, k67 }, \
+ { k68, k69, k6A, k6B, k6C, k6D, k6E, k6F }, \
+ { k70, k71, k72, k73, k74, k75, k76, k77 }, \
+ { k78, k79, k7A, k7B, k7C, k7D, k7E, k7F } \
}
diff --git a/tmk_core/protocol/xt.h b/tmk_core/protocol/xt.h
index 6dc5f19d0..cc55b7dbc 100644
--- a/tmk_core/protocol/xt.h
+++ b/tmk_core/protocol/xt.h
@@ -38,33 +38,36 @@ POSSIBILITY OF SUCH DAMAGE.
#pragma once
-#define XT_DATA_IN() \
- do { \
- XT_DATA_DDR &= ~(1 << XT_DATA_BIT); \
- XT_DATA_PORT |= (1 << XT_DATA_BIT); \
+#include "quantum.h"
+
+#define XT_DATA_IN() \
+ do { \
+ setPinInput(XT_DATA_PIN); \
+ writePinHigh(XT_DATA_PIN); \
} while (0)
-#define XT_DATA_READ() (XT_DATA_PIN & (1 << XT_DATA_BIT))
+#define XT_DATA_READ() readPin(XT_DATA_PIN)
-#define XT_DATA_LO() \
- do { \
- XT_DATA_PORT &= ~(1 << XT_DATA_BIT); \
- XT_DATA_DDR |= (1 << XT_DATA_BIT); \
+#define XT_DATA_LO() \
+ do { \
+ writePinLow(XT_DATA_PIN); \
+ setPinOutput(XT_DATA_PIN); \
} while (0)
-#define XT_CLOCK_IN() \
- do { \
- XT_CLOCK_DDR &= ~(1 << XT_CLOCK_BIT); \
- XT_CLOCK_PORT |= (1 << XT_CLOCK_BIT); \
+#define XT_CLOCK_IN() \
+ do { \
+ setPinInput(XT_CLOCK_PIN); \
+ writePinHigh(XT_CLOCK_PIN); \
} while (0)
-#define XT_CLOCK_READ() (XT_CLOCK_PIN & (1 << XT_CLOCK_BIT))
+#define XT_CLOCK_READ() readPin(XT_CLOCK_PIN)
-#define XT_CLOCK_LO() \
- do { \
- XT_CLOCK_PORT &= ~(1 << XT_CLOCK_BIT); \
- XT_CLOCK_DDR |= (1 << XT_CLOCK_BIT); \
+#define XT_CLOCK_LO() \
+ do { \
+ writePinLow(XT_CLOCK_PIN); \
+ setPinOutput(XT_CLOCK_PIN); \
} while (0)
void xt_host_init(void);
+
uint8_t xt_host_recv(void);
diff --git a/tmk_core/protocol/xt_interrupt.c b/tmk_core/protocol/xt_interrupt.c
index 51e52243f..3dd7e6177 100644
--- a/tmk_core/protocol/xt_interrupt.c
+++ b/tmk_core/protocol/xt_interrupt.c
@@ -38,7 +38,6 @@ POSSIBILITY OF SUCH DAMAGE.
#include
#include
-#include
#include "xt.h"
#include "wait.h"
#include "debug.h"
@@ -60,7 +59,7 @@ void xt_host_init(void) {
/* soft reset: pull clock line down for 20ms */
XT_DATA_LO();
XT_CLOCK_LO();
- _delay_ms(20);
+ wait_ms(20);
/* input mode with pullup */
XT_CLOCK_IN();
@@ -123,6 +122,7 @@ ISR(XT_INT_VECT) {
static uint8_t pbuf[PBUF_SIZE];
static uint8_t pbuf_head = 0;
static uint8_t pbuf_tail = 0;
+
static inline void pbuf_enqueue(uint8_t data) {
uint8_t sreg = SREG;
cli();
@@ -135,6 +135,7 @@ static inline void pbuf_enqueue(uint8_t data) {
}
SREG = sreg;
}
+
static inline uint8_t pbuf_dequeue(void) {
uint8_t val = 0;
@@ -148,6 +149,7 @@ static inline uint8_t pbuf_dequeue(void) {
return val;
}
+
static inline bool pbuf_has_data(void) {
uint8_t sreg = SREG;
cli();
@@ -155,6 +157,7 @@ static inline bool pbuf_has_data(void) {
SREG = sreg;
return has_data;
}
+
static inline void pbuf_clear(void) {
uint8_t sreg = SREG;
cli();