aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorNikolaus Wittenstein <nikolaus.wittenstein@gmail.com>2017-02-05 19:42:00 -0500
committerNikolaus Wittenstein <nikolaus.wittenstein@gmail.com>2017-02-05 19:47:33 -0500
commit8cbf61c91923e5399b158f7f9258096cb0089ce2 (patch)
treeeb525287e392da707d5319296da1c8b6aaf815ef /quantum
parentd961c80df2391631f7b3f46afa595ce93f51f217 (diff)
downloadqmk_firmware-8cbf61c91923e5399b158f7f9258096cb0089ce2.tar.gz
qmk_firmware-8cbf61c91923e5399b158f7f9258096cb0089ce2.zip
Add new DIODE_DIRECTION option
The previous two options were COL2ROW, ROW2COL; this adds CUSTOM_MATRIX to disable the built-in matrix scanning code. Most notably, this obviates the need to set MATRIX_ROW_PINS or MATRIX_COL_PINS.
Diffstat (limited to 'quantum')
-rw-r--r--quantum/config_common.h6
-rw-r--r--quantum/matrix.c12
-rw-r--r--quantum/template/config.h2
3 files changed, 12 insertions, 8 deletions
diff --git a/quantum/config_common.h b/quantum/config_common.h
index 4bdb2065d..28f68b9c7 100644
--- a/quantum/config_common.h
+++ b/quantum/config_common.h
@@ -2,8 +2,10 @@
2#define CONFIG_DEFINITIONS_H 2#define CONFIG_DEFINITIONS_H
3 3
4/* diode directions */ 4/* diode directions */
5#define COL2ROW 0 5#define COL2ROW 0
6#define ROW2COL 1 6#define ROW2COL 1
7#define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
8
7/* I/O pins */ 9/* I/O pins */
8#ifndef F0 10#ifndef F0
9 #define B0 0x30 11 #define B0 0x30
diff --git a/quantum/matrix.c b/quantum/matrix.c
index fd312bffb..ac523482a 100644
--- a/quantum/matrix.c
+++ b/quantum/matrix.c
@@ -60,8 +60,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
60 extern const matrix_row_t matrix_mask[]; 60 extern const matrix_row_t matrix_mask[];
61#endif 61#endif
62 62
63#if (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW)
63static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; 64static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
64static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; 65static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
66#endif
65 67
66/* matrix state(1:on, 0:off) */ 68/* matrix state(1:on, 0:off) */
67static matrix_row_t matrix[MATRIX_ROWS]; 69static matrix_row_t matrix[MATRIX_ROWS];
@@ -75,7 +77,7 @@ static matrix_row_t matrix_debouncing[MATRIX_ROWS];
75 static void unselect_rows(void); 77 static void unselect_rows(void);
76 static void select_row(uint8_t row); 78 static void select_row(uint8_t row);
77 static void unselect_row(uint8_t row); 79 static void unselect_row(uint8_t row);
78#else // ROW2COL 80#elif (DIODE_DIRECTION == ROW2COL)
79 static void init_rows(void); 81 static void init_rows(void);
80 static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col); 82 static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col);
81 static void unselect_cols(void); 83 static void unselect_cols(void);
@@ -132,7 +134,7 @@ uint8_t matrix_cols(void) {
132// /* PORTxn */ 134// /* PORTxn */
133// _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF); 135// _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF);
134// } 136// }
135// #else 137// #elif (DIODE_DIRECTION == ROW2COL)
136// for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) { 138// for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
137// /* DDRxn */ 139// /* DDRxn */
138// _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF); 140// _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF);
@@ -157,7 +159,7 @@ void matrix_init(void) {
157#if (DIODE_DIRECTION == COL2ROW) 159#if (DIODE_DIRECTION == COL2ROW)
158 unselect_rows(); 160 unselect_rows();
159 init_cols(); 161 init_cols();
160#else // ROW2COL 162#elif (DIODE_DIRECTION == ROW2COL)
161 unselect_cols(); 163 unselect_cols();
162 init_rows(); 164 init_rows();
163#endif 165#endif
@@ -192,7 +194,7 @@ uint8_t matrix_scan(void)
192 194
193 } 195 }
194 196
195#else // ROW2COL 197#elif (DIODE_DIRECTION == ROW2COL)
196 198
197 // Set col, read rows 199 // Set col, read rows
198 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { 200 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
@@ -334,7 +336,7 @@ static void unselect_rows(void)
334 } 336 }
335} 337}
336 338
337#else // ROW2COL 339#elif (DIODE_DIRECTION == ROW2COL)
338 340
339static void init_rows(void) 341static void init_rows(void)
340{ 342{
diff --git a/quantum/template/config.h b/quantum/template/config.h
index b02f0c7eb..c61c4a618 100644
--- a/quantum/template/config.h
+++ b/quantum/template/config.h
@@ -46,7 +46,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
46#define MATRIX_COL_PINS { F1, F0, B0 } 46#define MATRIX_COL_PINS { F1, F0, B0 }
47#define UNUSED_PINS 47#define UNUSED_PINS
48 48
49/* COL2ROW or ROW2COL */ 49/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
50#define DIODE_DIRECTION COL2ROW 50#define DIODE_DIRECTION COL2ROW
51 51
52// #define BACKLIGHT_PIN B7 52// #define BACKLIGHT_PIN B7