diff options
| author | tmk <nobody@nowhere> | 2013-03-12 16:05:50 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-03-12 16:05:50 +0900 |
| commit | 30f9baf8985f3caa626bcd0eef8519b93f23669b (patch) | |
| tree | ea5b5e0aba4c1229c57d184205d4fc11abfa0a86 /keyboard/gh60 | |
| parent | c4ab832be0f110a127b20e8df2b5223bceb8dcd1 (diff) | |
| download | qmk_firmware-30f9baf8985f3caa626bcd0eef8519b93f23669b.tar.gz qmk_firmware-30f9baf8985f3caa626bcd0eef8519b93f23669b.zip | |
Fix debouncing and add legacy keymap support
Diffstat (limited to 'keyboard/gh60')
| -rw-r--r-- | keyboard/gh60/matrix.c | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/keyboard/gh60/matrix.c b/keyboard/gh60/matrix.c index 09a051aa6..3ba6801fb 100644 --- a/keyboard/gh60/matrix.c +++ b/keyboard/gh60/matrix.c | |||
| @@ -34,13 +34,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 34 | static uint8_t debouncing = DEBOUNCE; | 34 | static uint8_t debouncing = DEBOUNCE; |
| 35 | 35 | ||
| 36 | /* matrix state(1:on, 0:off) */ | 36 | /* matrix state(1:on, 0:off) */ |
| 37 | static uint16_t *matrix; | 37 | static matrix_row_t *matrix; |
| 38 | static uint16_t *matrix_debouncing; | 38 | static matrix_row_t *matrix_debouncing; |
| 39 | static uint16_t matrix0[MATRIX_ROWS]; | 39 | static matrix_row_t matrix0[MATRIX_ROWS]; |
| 40 | static uint16_t matrix1[MATRIX_ROWS]; | 40 | static matrix_row_t matrix1[MATRIX_ROWS]; |
| 41 | static bool is_modified; | ||
| 42 | 41 | ||
| 43 | static uint16_t read_cols(void); | 42 | static matrix_row_t read_cols(void); |
| 44 | static void init_cols(void); | 43 | static void init_cols(void); |
| 45 | static void unselect_rows(void); | 44 | static void unselect_rows(void); |
| 46 | static void select_row(uint8_t row); | 45 | static void select_row(uint8_t row); |
| @@ -71,36 +70,32 @@ void matrix_init(void) | |||
| 71 | matrix[i] = 0; | 70 | matrix[i] = 0; |
| 72 | matrix_debouncing[i] = 0; | 71 | matrix_debouncing[i] = 0; |
| 73 | } | 72 | } |
| 74 | is_modified = false; | ||
| 75 | } | 73 | } |
| 76 | 74 | ||
| 77 | uint8_t matrix_scan(void) | 75 | uint8_t matrix_scan(void) |
| 78 | { | 76 | { |
| 79 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 77 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { |
| 80 | //unselect_rows(); | ||
| 81 | select_row(i); | 78 | select_row(i); |
| 82 | _delay_us(30); // without this wait read unstable value. | 79 | _delay_us(30); // without this wait read unstable value. |
| 83 | uint16_t cols = read_cols(); | 80 | matrix_row_t cols = read_cols(); |
| 84 | if (matrix_debouncing[i] != cols) { | 81 | if (matrix_debouncing[i] != cols) { |
| 85 | matrix_debouncing[i] = cols; | 82 | matrix_debouncing[i] = cols; |
| 86 | if (debouncing) { | 83 | if (debouncing) { |
| 87 | debug("bounce!: "); debug_hex(debouncing); debug("\n"); | 84 | debug("bounce!: "); debug_hex(debouncing); debug("\n"); |
| 88 | } | 85 | } |
| 89 | debouncing = DEBOUNCE; | 86 | debouncing = DEBOUNCE; |
| 90 | is_modified = false; | ||
| 91 | } | 87 | } |
| 92 | unselect_rows(); | 88 | unselect_rows(); |
| 93 | } | 89 | } |
| 94 | //unselect_rows(); | ||
| 95 | 90 | ||
| 96 | if (debouncing) { | 91 | if (debouncing) { |
| 97 | debouncing--; | 92 | if (--debouncing) { |
| 98 | _delay_ms(1); | 93 | _delay_ms(1); |
| 99 | } else { | 94 | } else { |
| 100 | uint16_t *tmp = matrix; | 95 | matrix_row_t *tmp = matrix; |
| 101 | matrix = matrix_debouncing; | 96 | matrix = matrix_debouncing; |
| 102 | matrix_debouncing = tmp; | 97 | matrix_debouncing = tmp; |
| 103 | is_modified = true; | 98 | } |
| 104 | } | 99 | } |
| 105 | 100 | ||
| 106 | return 1; | 101 | return 1; |
| @@ -108,13 +103,8 @@ uint8_t matrix_scan(void) | |||
| 108 | 103 | ||
| 109 | bool matrix_is_modified(void) | 104 | bool matrix_is_modified(void) |
| 110 | { | 105 | { |
| 111 | return is_modified; | 106 | if (debouncing) return false; |
| 112 | } | 107 | return true; |
| 113 | |||
| 114 | inline | ||
| 115 | bool matrix_has_ghost(void) | ||
| 116 | { | ||
| 117 | return false; | ||
| 118 | } | 108 | } |
| 119 | 109 | ||
| 120 | inline | 110 | inline |
| @@ -124,7 +114,7 @@ bool matrix_is_on(uint8_t row, uint8_t col) | |||
| 124 | } | 114 | } |
| 125 | 115 | ||
| 126 | inline | 116 | inline |
| 127 | uint16_t matrix_get_row(uint8_t row) | 117 | matrix_row_t matrix_get_row(uint8_t row) |
| 128 | { | 118 | { |
| 129 | return matrix[row]; | 119 | return matrix[row]; |
| 130 | } | 120 | } |
| @@ -167,7 +157,7 @@ static void init_cols(void) | |||
| 167 | PORTB |= (1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<0); | 157 | PORTB |= (1<<6 | 1<< 5 | 1<<4 | 1<<3 | 1<<1 | 1<<0); |
| 168 | } | 158 | } |
| 169 | 159 | ||
| 170 | static uint16_t read_cols(void) | 160 | static matrix_row_t read_cols(void) |
| 171 | { | 161 | { |
| 172 | return (PINF&(1<<0) ? 0 : (1<<0)) | | 162 | return (PINF&(1<<0) ? 0 : (1<<0)) | |
| 173 | (PINF&(1<<1) ? 0 : (1<<1)) | | 163 | (PINF&(1<<1) ? 0 : (1<<1)) | |
