Skip to content

Commit 0dbf73d

Browse files
committed
core: Add matrix_clear() and default impl.
1 parent 3202ca3 commit 0dbf73d

File tree

6 files changed

+105
-5
lines changed

6 files changed

+105
-5
lines changed

common.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
COMMON_DIR = common
22
SRC += $(COMMON_DIR)/host.c \
33
$(COMMON_DIR)/keyboard.c \
4+
$(COMMON_DIR)/matrix.c \
45
$(COMMON_DIR)/action.c \
56
$(COMMON_DIR)/action_tapping.c \
67
$(COMMON_DIR)/action_macro.c \

common/avr/suspend.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ void suspend_power_down(void)
105105
#endif
106106
}
107107

108-
__attribute__ ((weak)) void matrix_power_up(void) {}
109-
__attribute__ ((weak)) void matrix_power_down(void) {}
110108
bool suspend_wakeup_condition(void)
111109
{
112110
matrix_power_up();
@@ -122,7 +120,7 @@ bool suspend_wakeup_condition(void)
122120
void suspend_wakeup_init(void)
123121
{
124122
// clear keyboard state
125-
matrix_init();
123+
matrix_clear();
126124
clear_keyboard();
127125
#ifdef BACKLIGHT_ENABLE
128126
backlight_init();

common/keyboard.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ static bool has_ghost_in_row(uint8_t row)
6363
#endif
6464

6565

66-
__attribute__ ((weak)) void matrix_setup(void) {}
6766
void keyboard_setup(void)
6867
{
6968
matrix_setup();

common/matrix.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
Copyright 2016 Jun Wako <[email protected]>
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 2 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
#include "print.h"
18+
#include "matrix.h"
19+
20+
21+
__attribute__ ((weak))
22+
uint8_t matrix_rows(void)
23+
{
24+
return MATRIX_ROWS;
25+
}
26+
27+
__attribute__ ((weak))
28+
uint8_t matrix_cols(void)
29+
{
30+
return MATRIX_COLS;
31+
}
32+
33+
__attribute__ ((weak))
34+
void matrix_clear(void)
35+
{
36+
matrix_init();
37+
}
38+
39+
__attribute__ ((weak))
40+
void matrix_setup(void) {}
41+
42+
__attribute__ ((weak))
43+
bool matrix_is_on(uint8_t row, uint8_t col)
44+
{
45+
return (matrix_get_row(row) & (1<<col));
46+
}
47+
48+
__attribute__ ((weak))
49+
void matrix_print(void)
50+
{
51+
#if (MATRIX_COLS <= 8)
52+
print("r/c 01234567\n");
53+
#elif (MATRIX_COLS <= 16)
54+
print("r/c 0123456789ABCDEF\n");
55+
#elif (MATRIX_COLS <= 32)
56+
print("r/c 0123456789ABCDEF0123456789ABCDEF\n");
57+
#endif
58+
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
59+
xprintf("%02X:", row);
60+
61+
#if (MATRIX_COLS <= 8)
62+
print_bin_reverse8(matrix_get_row(row));
63+
#elif (MATRIX_COLS <= 16)
64+
print_bin_reverse16(matrix_get_row(row));
65+
#elif (MATRIX_COLS <= 32)
66+
print_bin_reverse32(matrix_get_row(row));
67+
#endif
68+
69+
#ifdef MATRIX_HAS_GHOST
70+
if (matrix_has_ghost_in_row(row)) {
71+
print(" <ghost");
72+
}
73+
#endif
74+
print("\n");
75+
}
76+
}
77+
78+
#ifdef MATRIX_HAS_GHOST
79+
__attribute__ ((weak))
80+
bool matrix_has_ghost_in_row(uint8_t row)
81+
{
82+
matrix_row_t matrix_row = matrix_get_row(row);
83+
// No ghost exists when less than 2 keys are down on the row
84+
if (((matrix_row - 1) & matrix_row) == 0)
85+
return false;
86+
87+
// Ghost occurs when the row shares column line with other row
88+
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
89+
if (i != row && (matrix_get_row(i) & matrix_row))
90+
return true;
91+
}
92+
return false;
93+
}
94+
#endif
95+
96+
__attribute__ ((weak)) void matrix_power_up(void) {}
97+
__attribute__ ((weak)) void matrix_power_down(void) {}

common/matrix.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ bool matrix_is_on(uint8_t row, uint8_t col);
5757
matrix_row_t matrix_get_row(uint8_t row);
5858
/* print matrix for debug */
5959
void matrix_print(void);
60+
/* clear matrix */
61+
void matrix_clear(void);
6062

63+
#ifdef MATRIX_HAS_GHOST
64+
bool matrix_has_ghost_in_row(uint8_t row);
65+
#endif
6166

6267
/* power control */
6368
void matrix_power_up(void);

protocol/lufa/lufa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ void hook_usb_suspend_entry(void)
693693
keyboard_led_stats = 0;
694694
led_set(keyboard_led_stats);
695695

696-
matrix_init();
696+
matrix_clear();
697697
clear_keyboard();
698698
#ifdef SLEEP_LED_ENABLE
699699
sleep_led_enable();

0 commit comments

Comments
 (0)