1
0

Merge branch 'matrix-fix'

This commit is contained in:
tmk 2016-10-08 13:15:00 +09:00
commit f699291e2a
17 changed files with 16 additions and 826 deletions

View File

@ -31,44 +31,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "host.h" #include "host.h"
#if (MATRIX_COLS > 16)
# error "MATRIX_COLS must not exceed 16"
#endif
#if (MATRIX_ROWS > 255)
# error "MATRIX_ROWS must not exceed 255"
#endif
static bool has_media_keys = false; static bool has_media_keys = false;
static bool is_iso_layout = false; static bool is_iso_layout = false;
static bool is_modified = false;
static report_mouse_t mouse_report = {}; static report_mouse_t mouse_report = {};
// matrix state buffer(1:on, 0:off) // matrix state buffer(1:on, 0:off)
#if (MATRIX_COLS <= 8) static matrix_row_t matrix[MATRIX_ROWS];
static uint8_t matrix[MATRIX_ROWS];
#else
static uint16_t matrix[MATRIX_ROWS];
#endif
#ifdef MATRIX_HAS_GHOST
static bool matrix_has_ghost_in_row(uint8_t row);
#endif
static void register_key(uint8_t key); static void register_key(uint8_t key);
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
// LED on // LED on
@ -208,8 +182,6 @@ uint8_t matrix_scan(void)
uint16_t codes; uint16_t codes;
uint8_t key0, key1; uint8_t key0, key1;
is_modified = false;
codes = extra_key; codes = extra_key;
extra_key = 0xFFFF; extra_key = 0xFFFF;
@ -328,93 +300,12 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
bool matrix_is_modified(void)
{
return is_modified;
}
inline inline
bool matrix_has_ghost(void) matrix_row_t matrix_get_row(uint8_t row)
{
#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;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline
#if (MATRIX_COLS <= 8)
uint8_t matrix_get_row(uint8_t row)
#else
uint16_t matrix_get_row(uint8_t row)
#endif
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
if (!debug_matrix) return;
#if (MATRIX_COLS <= 8)
print("r/c 01234567\n");
#else
print("r/c 0123456789ABCDEF\n");
#endif
for (uint8_t row = 0; row < matrix_rows(); row++) {
phex(row); print(": ");
#if (MATRIX_COLS <= 8)
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(" <ghost");
}
#endif
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
#if (MATRIX_COLS <= 8)
count += bitpop(matrix[i]);
#else
count += bitpop16(matrix[i]);
#endif
}
return count;
}
#ifdef MATRIX_HAS_GHOST
inline
static bool matrix_has_ghost_in_row(uint8_t row)
{
// no ghost exists in case less than 2 keys on
if (((matrix[row] - 1) & matrix[row]) == 0)
return false;
// ghost exists in case same state as other row
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
if (i != row && (matrix[i] & matrix[row]) == matrix[row])
return true;
}
return false;
}
#endif
inline inline
static void register_key(uint8_t key) static void register_key(uint8_t key)
{ {
@ -426,5 +317,4 @@ static void register_key(uint8_t key)
} else { } else {
matrix[row] |= (1<<col); matrix[row] |= (1<<col);
} }
is_modified = true;
} }

View File

@ -52,18 +52,6 @@ static uint8_t matrix[MATRIX_ROWS];
#define COL(code) (code&0x07) #define COL(code) (code&0x07)
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
static void enable_break(void) static void enable_break(void)
{ {
print("Enable break: "); print("Enable break: ");
@ -120,28 +108,12 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline inline
uint8_t matrix_get_row(uint8_t row) uint8_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
xprintf("%02X: %08b\n", row, bitrev(matrix_get_row(row)));
}
}
inline inline
static void matrix_make(uint8_t code) static void matrix_make(uint8_t code)
{ {

View File

@ -46,18 +46,6 @@ static uint8_t _matrix0[MATRIX_ROWS];
static void register_key(uint8_t key); static void register_key(uint8_t key);
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
m0110_init(); m0110_init();
@ -95,48 +83,12 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
bool matrix_is_modified(void)
{
return is_modified;
}
inline
bool matrix_has_ghost(void)
{
return false;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline inline
uint8_t matrix_get_row(uint8_t row) uint8_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
phex(row); print(": ");
pbin_reverse(matrix_get_row(row));
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
count += bitpop(matrix[i]);
}
return count;
}
inline inline
static void register_key(uint8_t key) static void register_key(uint8_t key)
{ {

View File

@ -47,20 +47,6 @@ static uint8_t matrix[MATRIX_ROWS];
#define ROW(code) ((code>>3)&0xF) #define ROW(code) ((code>>3)&0xF)
#define COL(code) (code&0x07) #define COL(code) (code&0x07)
static bool is_modified = false;
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
@ -74,8 +60,6 @@ void matrix_init(void)
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
{ {
is_modified = false;
uint8_t code; uint8_t code;
code = news_recv(); code = news_recv();
if (code == 0) { if (code == 0) {
@ -87,56 +71,18 @@ uint8_t matrix_scan(void)
// break code // break code
if (matrix_is_on(ROW(code), COL(code))) { if (matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] &= ~(1<<COL(code)); matrix[ROW(code)] &= ~(1<<COL(code));
is_modified = true;
} }
} else { } else {
// make code // make code
if (!matrix_is_on(ROW(code), COL(code))) { if (!matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] |= (1<<COL(code)); matrix[ROW(code)] |= (1<<COL(code));
is_modified = true;
} }
} }
return code; return code;
} }
bool matrix_is_modified(void)
{
return is_modified;
}
inline
bool matrix_has_ghost(void)
{
return false;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline inline
uint8_t matrix_get_row(uint8_t row) uint8_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
phex(row); print(": ");
pbin_reverse(matrix_get_row(row));
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
count += bitpop(matrix[i]);
}
return count;
}

View File

@ -66,20 +66,6 @@ static uint8_t matrix[MATRIX_ROWS];
static bool is_modified = false; static bool is_modified = false;
/* number of matrix rows */
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
/* number of matrix columns */
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
#ifndef NEXT_KBD_LED1_ON #ifndef NEXT_KBD_LED1_ON
#define NEXT_KBD_LED1_ON #define NEXT_KBD_LED1_ON
#endif #endif
@ -227,19 +213,6 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
/* whether modified from previous scan. used after matrix_scan. */
bool matrix_is_modified()
{
return is_modified;
}
/* whether a switch is on */
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
/* matrix state on row */ /* matrix state on row */
inline inline
uint8_t matrix_get_row(uint8_t row) uint8_t matrix_get_row(uint8_t row)
@ -247,11 +220,6 @@ uint8_t matrix_get_row(uint8_t row)
return matrix[row]; return matrix[row];
} }
/* print matrix for debug */
void matrix_print(void)
{
}
inline inline
static void matrix_make(uint8_t code) static void matrix_make(uint8_t code)
{ {

View File

@ -46,20 +46,6 @@ static uint8_t matrix[MATRIX_ROWS];
#define ROW(code) ((code>>3)&0xF) #define ROW(code) ((code>>3)&0xF)
#define COL(code) (code&0x07) #define COL(code) (code&0x07)
static bool is_modified = false;
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
static void pc98_inhibit_repeat(void) static void pc98_inhibit_repeat(void)
{ {
@ -128,8 +114,6 @@ void matrix_init(void)
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
{ {
is_modified = false;
uint16_t code; uint16_t code;
PC98_RDY_PORT |= (1<<PC98_RDY_BIT); PC98_RDY_PORT |= (1<<PC98_RDY_BIT);
_delay_us(30); _delay_us(30);
@ -156,56 +140,18 @@ if (code == 0x60) {
// break code // break code
if (matrix_is_on(ROW(code), COL(code))) { if (matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] &= ~(1<<COL(code)); matrix[ROW(code)] &= ~(1<<COL(code));
is_modified = true;
} }
} else { } else {
// make code // make code
if (!matrix_is_on(ROW(code), COL(code))) { if (!matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] |= (1<<COL(code)); matrix[ROW(code)] |= (1<<COL(code));
is_modified = true;
} }
} }
return code; return code;
} }
bool matrix_is_modified(void)
{
return is_modified;
}
inline
bool matrix_has_ghost(void)
{
return false;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline inline
uint8_t matrix_get_row(uint8_t row) uint8_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
phex(row); print(": ");
pbin_reverse(matrix_get_row(row));
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
count += bitpop(matrix[i]);
}
return count;
}

View File

@ -24,6 +24,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "matrix.h" #include "matrix.h"
#include "debug.h" #include "debug.h"
#include "protocol/serial.h" #include "protocol/serial.h"
#include "led.h"
#include "host.h"
/* /*
@ -46,20 +48,6 @@ static uint8_t matrix[MATRIX_ROWS];
#define ROW(code) ((code>>3)&0xF) #define ROW(code) ((code>>3)&0xF)
#define COL(code) (code&0x07) #define COL(code) (code&0x07)
static bool is_modified = false;
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
@ -92,8 +80,6 @@ void matrix_init(void)
uint8_t matrix_scan(void) uint8_t matrix_scan(void)
{ {
is_modified = false;
uint8_t code; uint8_t code;
code = serial_recv(); code = serial_recv();
if (!code) return 0; if (!code) return 0;
@ -131,56 +117,18 @@ uint8_t matrix_scan(void)
// break code // break code
if (matrix_is_on(ROW(code), COL(code))) { if (matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] &= ~(1<<COL(code)); matrix[ROW(code)] &= ~(1<<COL(code));
is_modified = true;
} }
} else { } else {
// make code // make code
if (!matrix_is_on(ROW(code), COL(code))) { if (!matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] |= (1<<COL(code)); matrix[ROW(code)] |= (1<<COL(code));
is_modified = true;
} }
} }
return code; return code;
} }
bool matrix_is_modified(void)
{
return is_modified;
}
inline
bool matrix_has_ghost(void)
{
return false;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline inline
uint8_t matrix_get_row(uint8_t row) uint8_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
phex(row); print(": ");
pbin_reverse(matrix_get_row(row));
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
count += bitpop(matrix[i]);
}
return count;
}

View File

@ -28,9 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static void matrix_make(uint8_t code); static void matrix_make(uint8_t code);
static void matrix_break(uint8_t code); static void matrix_break(uint8_t code);
#ifdef MATRIX_HAS_GHOST
static bool matrix_has_ghost_in_row(uint8_t row);
#endif
/* /*
@ -49,20 +46,6 @@ static uint8_t matrix[MATRIX_ROWS];
#define ROW(code) (code>>3) #define ROW(code) (code>>3)
#define COL(code) (code&0x07) #define COL(code) (code&0x07)
static bool is_modified = false;
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
@ -93,8 +76,6 @@ uint8_t matrix_scan(void)
F0, F0,
} state = RESET; } state = RESET;
is_modified = false;
uint8_t code; uint8_t code;
if ((code = ps2_host_recv())) { if ((code = ps2_host_recv())) {
debug("r"); debug_hex(code); debug(" "); debug("r"); debug_hex(code); debug(" ");
@ -172,83 +153,17 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
bool matrix_is_modified(void)
{
return is_modified;
}
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;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline inline
uint8_t matrix_get_row(uint8_t row) uint8_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
phex(row); print(": ");
pbin_reverse(matrix_get_row(row));
#ifdef MATRIX_HAS_GHOST
if (matrix_has_ghost_in_row(row)) {
print(" <ghost");
}
#endif
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
count += bitpop(matrix[i]);
}
return count;
}
#ifdef MATRIX_HAS_GHOST
inline
static bool matrix_has_ghost_in_row(uint8_t row)
{
// no ghost exists in case less than 2 keys on
if (((matrix[row] - 1) & matrix[row]) == 0)
return false;
// ghost exists in case same state as other row
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
if (i != row && (matrix[i] & matrix[row]) == matrix[row])
return true;
}
return false;
}
#endif
inline inline
static void matrix_make(uint8_t code) static void matrix_make(uint8_t code)
{ {
if (!matrix_is_on(ROW(code), COL(code))) { if (!matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] |= 1<<COL(code); matrix[ROW(code)] |= 1<<COL(code);
is_modified = true;
} }
} }
@ -257,6 +172,5 @@ static void matrix_break(uint8_t code)
{ {
if (matrix_is_on(ROW(code), COL(code))) { if (matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] &= ~(1<<COL(code)); matrix[ROW(code)] &= ~(1<<COL(code));
is_modified = true;
} }
} }

View File

@ -50,18 +50,6 @@ static uint8_t matrix[MATRIX_ROWS];
static bool is_modified = false; static bool is_modified = false;
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
serial_init(); serial_init();
@ -99,44 +87,8 @@ uint8_t matrix_scan(void)
return code; return code;
} }
bool matrix_is_modified(void)
{
return is_modified;
}
inline
bool matrix_has_ghost(void)
{
return false;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline inline
uint8_t matrix_get_row(uint8_t row) uint8_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
phex(row); print(": ");
pbin_reverse(matrix_get_row(row));
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
count += bitpop(matrix[i]);
}
return count;
}

View File

@ -28,9 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static void matrix_make(uint8_t code); static void matrix_make(uint8_t code);
static void matrix_break(uint8_t code); static void matrix_break(uint8_t code);
#ifdef MATRIX_HAS_GHOST
static bool matrix_has_ghost_in_row(uint8_t row);
#endif
static uint8_t matrix[MATRIX_ROWS]; static uint8_t matrix[MATRIX_ROWS];
#define ROW(code) (code>>3) #define ROW(code) (code>>3)
@ -40,20 +37,6 @@ static uint8_t matrix[MATRIX_ROWS];
#define PRINT_SCREEN (0x7C) #define PRINT_SCREEN (0x7C)
#define PAUSE (0x7D) #define PAUSE (0x7D)
static bool is_modified = false;
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
@ -131,8 +114,6 @@ uint8_t matrix_scan(void)
} state = INIT; } state = INIT;
is_modified = false;
// 'pseudo break code' hack // 'pseudo break code' hack
if (matrix_is_on(ROW(PAUSE), COL(PAUSE))) { if (matrix_is_on(ROW(PAUSE), COL(PAUSE))) {
matrix_break(PAUSE); matrix_break(PAUSE);
@ -236,83 +217,17 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
bool matrix_is_modified(void)
{
return is_modified;
}
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;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline inline
uint8_t matrix_get_row(uint8_t row) uint8_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
phex(row); print(": ");
pbin_reverse(matrix_get_row(row));
#ifdef MATRIX_HAS_GHOST
if (matrix_has_ghost_in_row(row)) {
print(" <ghost");
}
#endif
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
count += bitpop(matrix[i]);
}
return count;
}
#ifdef MATRIX_HAS_GHOST
inline
static bool matrix_has_ghost_in_row(uint8_t row)
{
// no ghost exists in case less than 2 keys on
if (((matrix[row] - 1) & matrix[row]) == 0)
return false;
// ghost exists in case same state as other row
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
if (i != row && (matrix[i] & matrix[row]) == matrix[row])
return true;
}
return false;
}
#endif
inline inline
static void matrix_make(uint8_t code) static void matrix_make(uint8_t code)
{ {
if (!matrix_is_on(ROW(code), COL(code))) { if (!matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] |= 1<<COL(code); matrix[ROW(code)] |= 1<<COL(code);
is_modified = true;
} }
} }
@ -321,7 +236,6 @@ static void matrix_break(uint8_t code)
{ {
if (matrix_is_on(ROW(code), COL(code))) { if (matrix_is_on(ROW(code), COL(code))) {
matrix[ROW(code)] &= ~(1<<COL(code)); matrix[ROW(code)] &= ~(1<<COL(code));
is_modified = true;
} }
} }

View File

@ -43,18 +43,6 @@ static void unselect_rows(void);
static void select_row(uint8_t row); static void select_row(uint8_t row);
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
#define LED_ON() do { DDRC |= (1<<5); PORTC |= (1<<5); } while (0) #define LED_ON() do { DDRC |= (1<<5); PORTC |= (1<<5); } while (0)
#define LED_OFF() do { DDRC &= ~(1<<5); PORTC &= ~(1<<5); } while (0) #define LED_OFF() do { DDRC &= ~(1<<5); PORTC &= ~(1<<5); } while (0)
#define LED_TGL() do { DDRC |= (1<<5); PINC |= (1<<5); } while (0) #define LED_TGL() do { DDRC |= (1<<5); PINC |= (1<<5); } while (0)
@ -107,28 +95,12 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & ((matrix_row_t)1<<col));
}
inline inline
matrix_row_t matrix_get_row(uint8_t row) matrix_row_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 0123456789ABCDEF\n");
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
phex(row); print(": ");
pbin_reverse16(matrix_get_row(row));
print("\n");
}
}
/* Column pin configuration /* Column pin configuration
* col: 0 1 2 3 4 5 6 7 * col: 0 1 2 3 4 5 6 7
* pin: B0 B1 B2 B3 B4 B5 B6 B7 * pin: B0 B1 B2 B3 B4 B5 B6 B7

View File

@ -43,18 +43,6 @@ static void unselect_rows(void);
static void select_row(uint8_t row); static void select_row(uint8_t row);
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
// initialize row and col // initialize row and col
@ -97,43 +85,12 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
bool matrix_is_modified(void)
{
if (debouncing) return false;
return true;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & ((matrix_row_t)1<<col));
}
inline inline
matrix_row_t matrix_get_row(uint8_t row) matrix_row_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 0123456789ABCDEF\n");
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
phex(row); print(": ");
pbin_reverse16(matrix_get_row(row));
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
count += bitpop16(matrix[i]);
}
return count;
}
/* Column pin configuration /* Column pin configuration
* col: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 * col: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
* pin: F0 F1 E6 C7 C6 B6 D4 B1 B0 B5 B4 D7 D6 B3 (Rev.A) * pin: F0 F1 E6 C7 C6 B6 D4 B1 B0 B5 B4 D7 D6 B3 (Rev.A)

View File

@ -41,26 +41,11 @@ static uint8_t debouncing = DEBOUNCE;
static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix[MATRIX_ROWS];
static matrix_row_t matrix_debouncing[MATRIX_ROWS]; static matrix_row_t matrix_debouncing[MATRIX_ROWS];
#ifdef MATRIX_HAS_GHOST
static bool matrix_has_ghost_in_row(uint8_t row);
#endif
static matrix_row_t read_cols(void); static matrix_row_t read_cols(void);
static void unselect_rows(void); static void unselect_rows(void);
static void select_row(uint8_t row); static void select_row(uint8_t row);
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
// JTAG disable for PORT F. write JTD bit twice within four cycles. // JTAG disable for PORT F. write JTD bit twice within four cycles.
@ -110,56 +95,12 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
bool matrix_is_modified(void)
{
if (debouncing) return false;
return true;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & ((matrix_row_t)1<<col));
}
inline inline
matrix_row_t matrix_get_row(uint8_t row) matrix_row_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
phex(row); print(": ");
pbin_reverse(matrix_get_row(row));
#ifdef MATRIX_HAS_GHOST
if (matrix_has_ghost_in_row(row)) {
print(" <ghost");
}
#endif
print("\n");
}
}
#ifdef MATRIX_HAS_GHOST
inline
static bool matrix_has_ghost_in_row(uint8_t row)
{
// no ghost exists in case less than 2 keys on
if (((matrix[row] - 1) & matrix[row]) == 0)
return false;
// ghost exists in case same state as other row
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
if (i != row && (matrix[i] & matrix[row]))
return true;
}
return false;
}
#endif
inline inline
static matrix_row_t read_cols(void) static matrix_row_t read_cols(void)
{ {

View File

@ -43,18 +43,6 @@ static matrix_row_t _matrix0[MATRIX_ROWS];
static matrix_row_t _matrix1[MATRIX_ROWS]; static matrix_row_t _matrix1[MATRIX_ROWS];
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
#ifdef DEBUG #ifdef DEBUG
@ -153,41 +141,12 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
bool matrix_is_modified(void)
{
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
if (matrix[i] != matrix_prev[i])
return true;
}
return false;
}
inline
bool matrix_has_ghost(void)
{
return false;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & (1<<col));
}
inline inline
matrix_row_t matrix_get_row(uint8_t row) matrix_row_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 01234567\n");
for (uint8_t row = 0; row < matrix_rows(); row++) {
xprintf("%02X: %08b\n", row, bitrev(matrix_get_row(row)));
}
}
void matrix_power_up(void) { void matrix_power_up(void) {
KEY_POWER_ON(); KEY_POWER_ON();
} }

View File

@ -43,18 +43,6 @@ static void unselect_rows(void);
static void select_row(uint8_t row); static void select_row(uint8_t row);
inline
uint8_t matrix_rows(void)
{
return MATRIX_ROWS;
}
inline
uint8_t matrix_cols(void)
{
return MATRIX_COLS;
}
void matrix_init(void) void matrix_init(void)
{ {
debug_enable = true; debug_enable = true;
@ -100,43 +88,12 @@ uint8_t matrix_scan(void)
return 1; return 1;
} }
bool matrix_is_modified(void)
{
if (debouncing) return false;
return true;
}
inline
bool matrix_is_on(uint8_t row, uint8_t col)
{
return (matrix[row] & ((matrix_row_t)1<<col));
}
inline inline
matrix_row_t matrix_get_row(uint8_t row) matrix_row_t matrix_get_row(uint8_t row)
{ {
return matrix[row]; return matrix[row];
} }
void matrix_print(void)
{
print("\nr/c 0123456789ABCDEF\n");
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
phex(row); print(": ");
pbin_reverse16(matrix_get_row(row));
print("\n");
}
}
uint8_t matrix_key_count(void)
{
uint8_t count = 0;
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
count += bitpop16(matrix[i]);
}
return count;
}
/* Column pin configuration /* Column pin configuration
* col: 0 * col: 0
* pin: B0 * pin: B0

View File

@ -33,7 +33,6 @@ uint8_t matrix_cols(void)
__attribute__ ((weak)) __attribute__ ((weak))
void matrix_clear(void) void matrix_clear(void)
{ {
matrix_init();
} }
__attribute__ ((weak)) __attribute__ ((weak))
@ -55,23 +54,22 @@ void matrix_print(void)
#elif (MATRIX_COLS <= 32) #elif (MATRIX_COLS <= 32)
print("r/c 0123456789ABCDEF0123456789ABCDEF\n"); print("r/c 0123456789ABCDEF0123456789ABCDEF\n");
#endif #endif
for (uint8_t row = 0; row < MATRIX_ROWS; row++) { for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
xprintf("%02X:", row);
#if (MATRIX_COLS <= 8) #if (MATRIX_COLS <= 8)
print_bin_reverse8(matrix_get_row(row)); xprintf("%02X: %08b%s\n", row, bitrev(matrix_get_row(row)),
#elif (MATRIX_COLS <= 16) #elif (MATRIX_COLS <= 16)
print_bin_reverse16(matrix_get_row(row)); xprintf("%02X: %016b%s\n", row, bitrev16(matrix_get_row(row)),
#elif (MATRIX_COLS <= 32) #elif (MATRIX_COLS <= 32)
print_bin_reverse32(matrix_get_row(row)); xprintf("%02X: %032b%s\n", row, bitrev32(matrix_get_row(row)),
#endif #endif
#ifdef MATRIX_HAS_GHOST #ifdef MATRIX_HAS_GHOST
if (matrix_has_ghost_in_row(row)) { matrix_has_ghost_in_row(row) ? " <ghost" : ""
print(" <ghost"); #else
} ""
#endif #endif
print("\n"); );
} }
} }

View File

@ -32,6 +32,10 @@ typedef uint32_t matrix_row_t;
#error "MATRIX_COLS: invalid value" #error "MATRIX_COLS: invalid value"
#endif #endif
#if (MATRIX_ROWS > 255)
#error "MATRIX_ROWS must not exceed 255"
#endif
#define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1<<col)) #define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1<<col))