diff options
| author | Gabriel Young <gabeplaysdrums@live.com> | 2017-03-19 20:33:41 -0700 |
|---|---|---|
| committer | Gabriel Young <gabeplaysdrums@live.com> | 2017-03-19 20:34:53 -0700 |
| commit | a43ae7c92fd2c41b283d03a8543677638a7c61f1 (patch) | |
| tree | ed5385861a179747218d695e76746ae51052ec28 /keyboards/frosty_flake/matrix.c | |
| parent | 4a97ef6c48ce7fee2b58c6a175c1c8003267a428 (diff) | |
| download | qmk_firmware-a43ae7c92fd2c41b283d03a8543677638a7c61f1.tar.gz qmk_firmware-a43ae7c92fd2c41b283d03a8543677638a7c61f1.zip | |
Swap rows and columns to match the schematic
Diffstat (limited to 'keyboards/frosty_flake/matrix.c')
| -rw-r--r-- | keyboards/frosty_flake/matrix.c | 154 |
1 files changed, 59 insertions, 95 deletions
diff --git a/keyboards/frosty_flake/matrix.c b/keyboards/frosty_flake/matrix.c index 07b9f6dd6..f289f506a 100644 --- a/keyboards/frosty_flake/matrix.c +++ b/keyboards/frosty_flake/matrix.c | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | Copyright 2014 Ralf Schmitt <ralf@bunkertor.net> | 2 | Copyright 2017 Gabriel Young <gabeplaysdrums@live.com> |
| 3 | 3 | ||
| 4 | This program is free software: you can redistribute it and/or modify | 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 | 5 | it under the terms of the GNU General Public License as published by |
| @@ -24,9 +24,6 @@ | |||
| 24 | #include "util.h" | 24 | #include "util.h" |
| 25 | #include "matrix.h" | 25 | #include "matrix.h" |
| 26 | 26 | ||
| 27 | #ifndef CONFIG_SPECIFIC_H | ||
| 28 | #define CONFIG_SPECIFIC_H | ||
| 29 | |||
| 30 | #define CONFIG_LED_IO \ | 27 | #define CONFIG_LED_IO \ |
| 31 | DDRB |= (1<<7); \ | 28 | DDRB |= (1<<7); \ |
| 32 | DDRC |= (1<<5) | (1<<6); | 29 | DDRC |= (1<<5) | (1<<6); |
| @@ -38,85 +35,40 @@ | |||
| 38 | #define USB_LED_SCROLL_LOCK_ON PORTC &= ~(1<<6) | 35 | #define USB_LED_SCROLL_LOCK_ON PORTC &= ~(1<<6) |
| 39 | #define USB_LED_SCROLL_LOCK_OFF PORTC |= (1<<6) | 36 | #define USB_LED_SCROLL_LOCK_OFF PORTC |= (1<<6) |
| 40 | 37 | ||
| 41 | #define CONFIG_MATRIX_IO \ | ||
| 42 | /* Column output pins */ \ | ||
| 43 | DDRD |= 0b01111011; \ | ||
| 44 | /* Row input pins */ \ | ||
| 45 | DDRC &= ~0b10000000; \ | ||
| 46 | DDRB &= ~0b01111111; \ | ||
| 47 | PORTC |= 0b10000000; \ | ||
| 48 | PORTB |= 0b01111111; | ||
| 49 | |||
| 50 | #define MATRIX_ROW_SCAN \ | ||
| 51 | (PINC&(1<<7) ? 0 : ((matrix_row_t)1<<0)) | \ | ||
| 52 | (PINB&(1<<5) ? 0 : ((matrix_row_t)1<<1)) | \ | ||
| 53 | (PINB&(1<<4) ? 0 : ((matrix_row_t)1<<2)) | \ | ||
| 54 | (PINB&(1<<6) ? 0 : ((matrix_row_t)1<<3)) | \ | ||
| 55 | (PINB&(1<<1) ? 0 : ((matrix_row_t)1<<4)) | \ | ||
| 56 | (PINB&(1<<2) ? 0 : ((matrix_row_t)1<<5)) | \ | ||
| 57 | (PINB&(1<<3) ? 0 : ((matrix_row_t)1<<6)) | \ | ||
| 58 | (PINB&(1<<0) ? 0 : ((matrix_row_t)1<<7)) | ||
| 59 | |||
| 60 | #define MATRIX_ROW_SELECT \ | ||
| 61 | case 0: PORTD = (PORTD & ~0b01111011) | 0b00011011; break; \ | ||
| 62 | case 1: PORTD = (PORTD & ~0b01111011) | 0b01000011; break; \ | ||
| 63 | case 2: PORTD = (PORTD & ~0b01111011) | 0b01101010; break; \ | ||
| 64 | case 3: PORTD = (PORTD & ~0b01111011) | 0b01111001; break; \ | ||
| 65 | case 4: PORTD = (PORTD & ~0b01111011) | 0b01100010; break; \ | ||
| 66 | case 5: PORTD = (PORTD & ~0b01111011) | 0b01110001; break; \ | ||
| 67 | case 6: PORTD = (PORTD & ~0b01111011) | 0b01100001; break; \ | ||
| 68 | case 7: PORTD = (PORTD & ~0b01111011) | 0b01110000; break; \ | ||
| 69 | case 8: PORTD = (PORTD & ~0b01111011) | 0b01100000; break; \ | ||
| 70 | case 9: PORTD = (PORTD & ~0b01111011) | 0b01101000; break; \ | ||
| 71 | case 10: PORTD = (PORTD & ~0b01111011) | 0b00101011; break; \ | ||
| 72 | case 11: PORTD = (PORTD & ~0b01111011) | 0b00110011; break; \ | ||
| 73 | case 12: PORTD = (PORTD & ~0b01111011) | 0b00100011; break; \ | ||
| 74 | case 13: PORTD = (PORTD & ~0b01111011) | 0b01111000; break; \ | ||
| 75 | case 14: PORTD = (PORTD & ~0b01111011) | 0b00010011; break; \ | ||
| 76 | case 15: PORTD = (PORTD & ~0b01111011) | 0b01101001; break; \ | ||
| 77 | case 16: PORTD = (PORTD & ~0b01111011) | 0b00001011; break; \ | ||
| 78 | case 17: PORTD = (PORTD & ~0b01111011) | 0b00111011; break; | ||
| 79 | |||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifndef DEBOUNCING_DELAY | 38 | #ifndef DEBOUNCING_DELAY |
| 83 | # define DEBOUNCING_DELAY 0 | 39 | # define DEBOUNCING_DELAY 5 |
| 84 | #endif | 40 | #endif |
| 85 | static uint8_t debouncing = DEBOUNCING_DELAY; | 41 | static uint8_t debouncing = DEBOUNCING_DELAY; |
| 86 | 42 | ||
| 87 | static matrix_row_t matrix[MATRIX_ROWS]; | 43 | static matrix_row_t matrix[MATRIX_ROWS]; |
| 88 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | 44 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; |
| 89 | 45 | ||
| 90 | static matrix_row_t scan_row(void); | 46 | static matrix_row_t scan_col(void); |
| 91 | static void select_row(uint8_t row); | 47 | static void select_col(uint8_t row); |
| 92 | |||
| 93 | inline uint8_t matrix_rows(void) { | ||
| 94 | return MATRIX_ROWS; | ||
| 95 | } | ||
| 96 | |||
| 97 | inline uint8_t matrix_cols(void) { | ||
| 98 | return MATRIX_COLS; | ||
| 99 | } | ||
| 100 | 48 | ||
| 101 | void matrix_init(void) { | 49 | void matrix_init(void) { |
| 102 | CONFIG_MATRIX_IO; | 50 | /* Row output pins */ |
| 103 | 51 | DDRD |= 0b01111011; | |
| 104 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | 52 | /* Column input pins */ |
| 105 | matrix[i] = 0; | 53 | DDRC &= ~0b10000000; |
| 106 | matrix_debouncing[i] = 0; | 54 | DDRB &= ~0b01111111; |
| 107 | } | 55 | PORTC |= 0b10000000; |
| 108 | 56 | PORTB |= 0b01111111; | |
| 109 | matrix_init_quantum(); | 57 | |
| 58 | for (uint8_t i=0; i < MATRIX_ROWS; i++) | ||
| 59 | matrix[i] = matrix_debouncing[i] = 0; | ||
| 60 | |||
| 61 | matrix_init_quantum(); | ||
| 110 | } | 62 | } |
| 111 | 63 | ||
| 112 | uint8_t matrix_scan(void) { | 64 | uint8_t matrix_scan(void) { |
| 113 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | 65 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { |
| 114 | select_row(row); | 66 | select_col(col); |
| 115 | _delay_us(3); | 67 | _delay_us(3); |
| 116 | matrix_row_t row_scan = scan_row(); | 68 | matrix_row_t col_scan = scan_col(); |
| 117 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | 69 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { |
| 118 | bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col); | 70 | bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col); |
| 119 | bool curr_bit = row_scan & (1<<col); | 71 | bool curr_bit = col_scan & (1<<row); |
| 120 | if (prev_bit != curr_bit) { | 72 | if (prev_bit != curr_bit) { |
| 121 | matrix_debouncing[row] ^= ((matrix_row_t)1<<col); | 73 | matrix_debouncing[row] ^= ((matrix_row_t)1<<col); |
| 122 | debouncing = DEBOUNCING_DELAY; | 74 | debouncing = DEBOUNCING_DELAY; |
| @@ -136,30 +88,17 @@ uint8_t matrix_scan(void) { | |||
| 136 | return 1; | 88 | return 1; |
| 137 | } | 89 | } |
| 138 | 90 | ||
| 139 | bool matrix_is_modified(void) { | ||
| 140 | if (debouncing) | ||
| 141 | return false; | ||
| 142 | else | ||
| 143 | return true; | ||
| 144 | } | ||
| 145 | |||
| 146 | inline bool matrix_is_on(uint8_t row, uint8_t col) { | ||
| 147 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 148 | } | ||
| 149 | |||
| 150 | inline matrix_row_t matrix_get_row(uint8_t row) { | 91 | inline matrix_row_t matrix_get_row(uint8_t row) { |
| 151 | return matrix[row]; | 92 | return matrix[row]; |
| 152 | } | 93 | } |
| 153 | 94 | ||
| 154 | static const char ROW_NAMES[] = "ABCDEFGHIJKLMNOPQR"; | ||
| 155 | |||
| 156 | void matrix_print(void) { | 95 | void matrix_print(void) { |
| 157 | print("\nr/c 01234567\n"); | 96 | print("\nr\\c ABCDEFGHIJKLMNOPQR\n"); |
| 158 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | 97 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { |
| 159 | matrix_row_t row_scan = matrix_get_row(row); | 98 | matrix_row_t matrix_row = matrix_get_row(row); |
| 160 | xprintf("%c: ", ROW_NAMES[row]); | 99 | xprintf("%02X: ", row); |
| 161 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { | 100 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { |
| 162 | bool curr_bit = row_scan & (1<<col); | 101 | bool curr_bit = matrix_row & (1<<col); |
| 163 | xprintf("%c", curr_bit ? '*' : '.'); | 102 | xprintf("%c", curr_bit ? '*' : '.'); |
| 164 | } | 103 | } |
| 165 | print("\n"); | 104 | print("\n"); |
| @@ -168,18 +107,43 @@ void matrix_print(void) { | |||
| 168 | 107 | ||
| 169 | uint8_t matrix_key_count(void) { | 108 | uint8_t matrix_key_count(void) { |
| 170 | uint8_t count = 0; | 109 | uint8_t count = 0; |
| 171 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 110 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) |
| 172 | count += bitpop32(matrix[i]); | 111 | count += bitpop32(matrix[row]); |
| 173 | } | ||
| 174 | return count; | 112 | return count; |
| 175 | } | 113 | } |
| 176 | 114 | ||
| 177 | static matrix_row_t scan_row(void) { | 115 | static matrix_row_t scan_col(void) { |
| 178 | return MATRIX_ROW_SCAN; | 116 | return ( |
| 117 | (PINC&(1<<7) ? 0 : ((matrix_row_t)1<<0)) | | ||
| 118 | (PINB&(1<<5) ? 0 : ((matrix_row_t)1<<1)) | | ||
| 119 | (PINB&(1<<4) ? 0 : ((matrix_row_t)1<<2)) | | ||
| 120 | (PINB&(1<<6) ? 0 : ((matrix_row_t)1<<3)) | | ||
| 121 | (PINB&(1<<1) ? 0 : ((matrix_row_t)1<<4)) | | ||
| 122 | (PINB&(1<<2) ? 0 : ((matrix_row_t)1<<5)) | | ||
| 123 | (PINB&(1<<3) ? 0 : ((matrix_row_t)1<<6)) | | ||
| 124 | (PINB&(1<<0) ? 0 : ((matrix_row_t)1<<7)) | ||
| 125 | ); | ||
| 179 | } | 126 | } |
| 180 | 127 | ||
| 181 | static void select_row(uint8_t row) { | 128 | static void select_col(uint8_t col) { |
| 182 | switch (row) { | 129 | switch (col) { |
| 183 | MATRIX_ROW_SELECT; | 130 | case 0: PORTD = (PORTD & ~0b01111011) | 0b00011011; break; |
| 184 | } | 131 | case 1: PORTD = (PORTD & ~0b01111011) | 0b01000011; break; |
| 132 | case 2: PORTD = (PORTD & ~0b01111011) | 0b01101010; break; | ||
| 133 | case 3: PORTD = (PORTD & ~0b01111011) | 0b01111001; break; | ||
| 134 | case 4: PORTD = (PORTD & ~0b01111011) | 0b01100010; break; | ||
| 135 | case 5: PORTD = (PORTD & ~0b01111011) | 0b01110001; break; | ||
| 136 | case 6: PORTD = (PORTD & ~0b01111011) | 0b01100001; break; | ||
| 137 | case 7: PORTD = (PORTD & ~0b01111011) | 0b01110000; break; | ||
| 138 | case 8: PORTD = (PORTD & ~0b01111011) | 0b01100000; break; | ||
| 139 | case 9: PORTD = (PORTD & ~0b01111011) | 0b01101000; break; | ||
| 140 | case 10: PORTD = (PORTD & ~0b01111011) | 0b00101011; break; | ||
| 141 | case 11: PORTD = (PORTD & ~0b01111011) | 0b00110011; break; | ||
| 142 | case 12: PORTD = (PORTD & ~0b01111011) | 0b00100011; break; | ||
| 143 | case 13: PORTD = (PORTD & ~0b01111011) | 0b01111000; break; | ||
| 144 | case 14: PORTD = (PORTD & ~0b01111011) | 0b00010011; break; | ||
| 145 | case 15: PORTD = (PORTD & ~0b01111011) | 0b01101001; break; | ||
| 146 | case 16: PORTD = (PORTD & ~0b01111011) | 0b00001011; break; | ||
| 147 | case 17: PORTD = (PORTD & ~0b01111011) | 0b00111011; break; | ||
| 148 | } | ||
| 185 | } \ No newline at end of file | 149 | } \ No newline at end of file |
