diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2015-09-13 22:10:01 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2015-09-13 22:10:01 -0400 |
| commit | 5bb7ef0012378cd800bff74680b08c587e6338e4 (patch) | |
| tree | 4a2b7e159c7c9a5977ca53108de87732c8699e0e /keyboard/planck/matrix.c | |
| parent | b89a9cdc917e06427f3efaf0da53cc060f94b3cf (diff) | |
| download | qmk_firmware-5bb7ef0012378cd800bff74680b08c587e6338e4.tar.gz qmk_firmware-5bb7ef0012378cd800bff74680b08c587e6338e4.zip | |
rows to col option, maybe
Diffstat (limited to 'keyboard/planck/matrix.c')
| -rw-r--r-- | keyboard/planck/matrix.c | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/keyboard/planck/matrix.c b/keyboard/planck/matrix.c index 98ef55ed6..8a021719c 100644 --- a/keyboard/planck/matrix.c +++ b/keyboard/planck/matrix.c | |||
| @@ -37,6 +37,11 @@ static uint8_t debouncing = DEBOUNCE; | |||
| 37 | static matrix_row_t matrix[MATRIX_ROWS]; | 37 | static matrix_row_t matrix[MATRIX_ROWS]; |
| 38 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | 38 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; |
| 39 | 39 | ||
| 40 | #if DIODE_DIRECTION == ROW2COL | ||
| 41 | static matrix_row_t matrix_reversed[MATRIX_COLS]; | ||
| 42 | static matrix_row_t matrix_reversed_debouncing[MATRIX_COLS]; | ||
| 43 | #endif | ||
| 44 | |||
| 40 | static matrix_row_t read_cols(void); | 45 | static matrix_row_t read_cols(void); |
| 41 | static void init_cols(void); | 46 | static void init_cols(void); |
| 42 | static void unselect_rows(void); | 47 | static void unselect_rows(void); |
| @@ -80,6 +85,7 @@ void matrix_init(void) | |||
| 80 | 85 | ||
| 81 | uint8_t matrix_scan(void) | 86 | uint8_t matrix_scan(void) |
| 82 | { | 87 | { |
| 88 | #if DIODE_DIRECTION == COL2ROW | ||
| 83 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 89 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { |
| 84 | select_row(i); | 90 | select_row(i); |
| 85 | _delay_us(30); // without this wait read unstable value. | 91 | _delay_us(30); // without this wait read unstable value. |
| @@ -103,6 +109,38 @@ uint8_t matrix_scan(void) | |||
| 103 | } | 109 | } |
| 104 | } | 110 | } |
| 105 | } | 111 | } |
| 112 | #else | ||
| 113 | for (uint8_t i = 0; i < MATRIX_COLS; i++) { | ||
| 114 | select_row(i); | ||
| 115 | _delay_us(30); // without this wait read unstable value. | ||
| 116 | matrix_row_t rows = read_cols(); | ||
| 117 | if (matrix_reversed_debouncing[i] != rows) { | ||
| 118 | matrix_reversed_debouncing[i] = rows; | ||
| 119 | if (debouncing) { | ||
| 120 | debug("bounce!: "); debug_hex(debouncing); debug("\n"); | ||
| 121 | } | ||
| 122 | debouncing = DEBOUNCE; | ||
| 123 | } | ||
| 124 | unselect_rows(); | ||
| 125 | } | ||
| 126 | |||
| 127 | if (debouncing) { | ||
| 128 | if (--debouncing) { | ||
| 129 | _delay_ms(1); | ||
| 130 | } else { | ||
| 131 | for (uint8_t i = 0; i < MATRIX_COLS; i++) { | ||
| 132 | matrix_reversed[i] = matrix_reversed_debouncing[i]; | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | for (uint8_t y = 0; y < MATRIX_ROWS; y++) { | ||
| 137 | matrix_row_t row = 0; | ||
| 138 | for (uint8_t x = 0; x < MATRIX_COLS; x++) { | ||
| 139 | row |= ((matrix_reversed[x] & (1<<y)) >> y) << x; | ||
| 140 | } | ||
| 141 | matrix[y] = row; | ||
| 142 | } | ||
| 143 | #endif | ||
| 106 | 144 | ||
| 107 | return 1; | 145 | return 1; |
| 108 | } | 146 | } |
| @@ -147,8 +185,14 @@ uint8_t matrix_key_count(void) | |||
| 147 | static void init_cols(void) | 185 | static void init_cols(void) |
| 148 | { | 186 | { |
| 149 | int B = 0, C = 0, D = 0, E = 0, F = 0; | 187 | int B = 0, C = 0, D = 0, E = 0, F = 0; |
| 150 | for(int x = 0; x < MATRIX_COLS; x++) { | 188 | |
| 189 | #if DIODE_DIRECTION == COL2ROW | ||
| 190 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 151 | int col = COLS[x]; | 191 | int col = COLS[x]; |
| 192 | #else | ||
| 193 | for(int x = 0; x < MATRIX_ROWS; x++) { | ||
| 194 | int col = ROWS[x]; | ||
| 195 | #endif | ||
| 152 | if ((col & 0xF0) == 0x20) { | 196 | if ((col & 0xF0) == 0x20) { |
| 153 | B |= (1<<(col & 0x0F)); | 197 | B |= (1<<(col & 0x0F)); |
| 154 | } else if ((col & 0xF0) == 0x30) { | 198 | } else if ((col & 0xF0) == 0x30) { |
| @@ -171,8 +215,15 @@ static void init_cols(void) | |||
| 171 | static matrix_row_t read_cols(void) | 215 | static matrix_row_t read_cols(void) |
| 172 | { | 216 | { |
| 173 | matrix_row_t result = 0; | 217 | matrix_row_t result = 0; |
| 218 | |||
| 219 | #if DIODE_DIRECTION == COL2ROW | ||
| 174 | for(int x = 0; x < MATRIX_COLS; x++) { | 220 | for(int x = 0; x < MATRIX_COLS; x++) { |
| 175 | int col = COLS[x]; | 221 | int col = COLS[x]; |
| 222 | #else | ||
| 223 | for(int x = 0; x < MATRIX_ROWS; x++) { | ||
| 224 | int col = ROWS[x]; | ||
| 225 | #endif | ||
| 226 | |||
| 176 | if ((col & 0xF0) == 0x20) { | 227 | if ((col & 0xF0) == 0x20) { |
| 177 | result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1<<x)); | 228 | result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1<<x)); |
| 178 | } else if ((col & 0xF0) == 0x30) { | 229 | } else if ((col & 0xF0) == 0x30) { |
| @@ -191,8 +242,14 @@ static matrix_row_t read_cols(void) | |||
| 191 | static void unselect_rows(void) | 242 | static void unselect_rows(void) |
| 192 | { | 243 | { |
| 193 | int B = 0, C = 0, D = 0, E = 0, F = 0; | 244 | int B = 0, C = 0, D = 0, E = 0, F = 0; |
| 245 | |||
| 246 | #if DIODE_DIRECTION == COL2ROW | ||
| 194 | for(int x = 0; x < MATRIX_ROWS; x++) { | 247 | for(int x = 0; x < MATRIX_ROWS; x++) { |
| 195 | int row = ROWS[x]; | 248 | int row = ROWS[x]; |
| 249 | #else | ||
| 250 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 251 | int row = COLS[x]; | ||
| 252 | #endif | ||
| 196 | if ((row & 0xF0) == 0x20) { | 253 | if ((row & 0xF0) == 0x20) { |
| 197 | B |= (1<<(row & 0x0F)); | 254 | B |= (1<<(row & 0x0F)); |
| 198 | } else if ((row & 0xF0) == 0x30) { | 255 | } else if ((row & 0xF0) == 0x30) { |
| @@ -214,7 +271,13 @@ static void unselect_rows(void) | |||
| 214 | 271 | ||
| 215 | static void select_row(uint8_t row) | 272 | static void select_row(uint8_t row) |
| 216 | { | 273 | { |
| 274 | |||
| 275 | #if DIODE_DIRECTION == COL2ROW | ||
| 217 | int row_pin = ROWS[row]; | 276 | int row_pin = ROWS[row]; |
| 277 | #else | ||
| 278 | int row_pin = COLS[row]; | ||
| 279 | #endif | ||
| 280 | |||
| 218 | if ((row_pin & 0xF0) == 0x20) { | 281 | if ((row_pin & 0xF0) == 0x20) { |
| 219 | DDRB |= (1<<(row_pin & 0x0F)); | 282 | DDRB |= (1<<(row_pin & 0x0F)); |
| 220 | PORTB &= ~(1<<(row_pin & 0x0F)); | 283 | PORTB &= ~(1<<(row_pin & 0x0F)); |
