summaryrefslogtreecommitdiffstats
path: root/keyboards/converter/xt_usb/matrix.c
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-03-18 11:48:09 +1100
committerGitHub <noreply@github.com>2021-03-18 11:48:09 +1100
commit9331c22620fb9a4012a370d717e6362a5ab84ec4 (patch)
tree999f3893d22eb551a351ef28a53fbfca2809ab43 /keyboards/converter/xt_usb/matrix.c
parentcc84831cae1d1f7159aea3bc03001a6293d43ee7 (diff)
XT converter cleanup (#12264)
Diffstat (limited to 'keyboards/converter/xt_usb/matrix.c')
-rw-r--r--keyboards/converter/xt_usb/matrix.c81
1 files changed, 41 insertions, 40 deletions
diff --git a/keyboards/converter/xt_usb/matrix.c b/keyboards/converter/xt_usb/matrix.c
index d75f077ce9..7a16750432 100644
--- a/keyboards/converter/xt_usb/matrix.c
+++ b/keyboards/converter/xt_usb/matrix.c
@@ -25,13 +25,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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<<COL(code);
+ matrix[ROW(code)] |= 1 << COL(code);
}
}
-inline
-static void matrix_break(uint8_t code)
-{
+inline static void matrix_break(uint8_t code) {
if (matrix_is_on(ROW(code), COL(code))) {
- matrix[ROW(code)] &= ~(1<<COL(code));
+ matrix[ROW(code)] &= ~(1 << COL(code));
}
}
-void matrix_clear(void)
-{
+void matrix_clear(void) {
for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
}
-bool matrix_is_on(uint8_t row, uint8_t col)
-{
- return (matrix_get_row(row) & (1<<col));
+bool matrix_is_on(uint8_t row, uint8_t col) {
+ return (matrix_get_row(row) & (1 << col));
}
#if (MATRIX_COLS <= 8)
-# define print_matrix_header() print("\nr/c 01234567\n")
-# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
+# define print_matrix_header() print("\nr/c 01234567\n")
+# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
#elif (MATRIX_COLS <= 16)
-# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
-# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
+# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
+# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
#elif (MATRIX_COLS <= 32)
-# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
-# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
+# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
+# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
#endif
-void matrix_print(void)
-{
+void matrix_print(void) {
print_matrix_header();
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
- print_hex8(row); print(": ");
+ print_hex8(row);
+ print(": ");
print_matrix_row(row);
print("\n");
}