X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=keyboard%2Fhhkb%2Fmatrix.c;h=f53e36dbe0acd4d23e83de136408681f0f314a20;hb=c4421f585b085d3eef5e468ff1defcbc3b4ec8d3;hp=350066b9040ece0a3f89c678f3d15f50575d0b04;hpb=62d1ebb91c7b381ce3d88aad9ee0b03bea9fce26;p=max%2Ftmk_keyboard.git
diff --git a/keyboard/hhkb/matrix.c b/keyboard/hhkb/matrix.c
index 350066b9..f53e36db 100644
--- a/keyboard/hhkb/matrix.c
+++ b/keyboard/hhkb/matrix.c
@@ -24,6 +24,7 @@ along with this program. If not, see .
#include
#include
#include "print.h"
+#include "debug.h"
#include "util.h"
#include "timer.h"
#include "matrix.h"
@@ -43,22 +44,10 @@ along with this program. If not, see .
// matrix state buffer(1:on, 0:off)
-#if (MATRIX_COLS <= 8)
-static uint8_t *matrix;
-static uint8_t *matrix_prev;
-static uint8_t _matrix0[MATRIX_ROWS];
-static uint8_t _matrix1[MATRIX_ROWS];
-#else
-static uint16_t *matrix;
-static uint16_t *matrix_prev;
-static uint16_t _matrix0[MATRIX_ROWS];
-static uint16_t _matrix1[MATRIX_ROWS];
-#endif
-
-// HHKB has no ghost and no bounce.
-#ifdef MATRIX_HAS_GHOST
-static bool matrix_has_ghost_in_row(uint8_t row);
-#endif
+static matrix_row_t *matrix;
+static matrix_row_t *matrix_prev;
+static matrix_row_t _matrix0[MATRIX_ROWS];
+static matrix_row_t _matrix1[MATRIX_ROWS];
// Matrix I/O ports
@@ -68,8 +57,8 @@ static bool matrix_has_ghost_in_row(uint8_t row);
// key: on: 0/off: 1
// prev: unknown: output previous key state(negated)?
-#ifdef HOST_PJRC
-// Ports for Teensy
+#if defined(__AVR_AT90USB1286__)
+// Ports for Teensy++
// row: PB0-2
// col: PB3-5,6
// key: PE6(pull-uped)
@@ -90,7 +79,8 @@ static bool matrix_has_ghost_in_row(uint8_t row);
#define KEY_PREV_OFF() (PORTE &= ~(1<<7))
#define KEY_POWER_ON()
#define KEY_POWER_OFF()
-#else
+
+#elif defined(__AVR_ATmega328P__)
// Ports for V-USB
// key: PB0(pull-uped)
// prev: PB1
@@ -118,7 +108,7 @@ static bool matrix_has_ghost_in_row(uint8_t row);
#define KEY_POWER_ON() do { \
KEY_INIT(); \
PORTB &= ~(1<<5); \
- _delay_us(200); \
+ _delay_ms(1); \
} while (0)
#define KEY_POWER_OFF() do { \
DDRB &= ~0x3F; \
@@ -126,6 +116,9 @@ static bool matrix_has_ghost_in_row(uint8_t row);
DDRC &= ~0x0F; \
PORTC &= ~0x0F; \
} while (0)
+
+#else
+# error "define code for matrix scan"
#endif
@@ -143,6 +136,12 @@ uint8_t matrix_cols(void)
void matrix_init(void)
{
+#ifdef DEBUG
+ print_enable = true;
+ debug_enable = true;
+ debug_keyboard = true;
+#endif
+
KEY_INIT();
// initialize matrix state: all keys off
@@ -188,6 +187,8 @@ uint8_t matrix_scan(void)
}
// Ignore if this code region execution time elapses more than 20us.
+ // MEMO: 20[us] * (TIMER_RAW_FREQ / 1000000)[count per us]
+ // MEMO: then change above using this rule: a/(b/c) = a*1/(b/c) = a*(c/b)
if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) {
matrix[row] = matrix_prev[row];
}
@@ -215,12 +216,6 @@ bool matrix_is_modified(void)
inline
bool matrix_has_ghost(void)
{
-#ifdef MATRIX_HAS_GHOST
- for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- if (matrix_has_ghost_in_row(i))
- return true;
- }
-#endif
return false;
}
@@ -253,11 +248,6 @@ void matrix_print(void)
pbin_reverse(matrix_get_row(row));
#else
pbin_reverse16(matrix_get_row(row));
-#endif
-#ifdef MATRIX_HAS_GHOST
- if (matrix_has_ghost_in_row(row)) {
- print("