diff options
| -rw-r--r-- | common/matrix.h | 2 | ||||
| -rw-r--r-- | keyboard/gh60/matrix.c | 44 | ||||
| -rw-r--r-- | keyboard/hbkb/config.h | 19 | ||||
| -rw-r--r-- | keyboard/hbkb/matrix.c | 65 | ||||
| -rw-r--r-- | keyboard/hid_liber/config.h | 11 | ||||
| -rw-r--r-- | keyboard/hid_liber/matrix.c | 2 | ||||
| -rw-r--r-- | keyboard/macway/config.h | 25 | ||||
| -rw-r--r-- | keyboard/macway/matrix.c | 77 | ||||
| -rw-r--r-- | keyboard/phantom/config.h | 13 | ||||
| -rw-r--r-- | keyboard/phantom/matrix.c | 34 |
10 files changed, 127 insertions, 165 deletions
diff --git a/common/matrix.h b/common/matrix.h index d62acb668..d1d14a6ea 100644 --- a/common/matrix.h +++ b/common/matrix.h | |||
| @@ -44,7 +44,7 @@ void matrix_init(void); | |||
| 44 | /* scan all key states on matrix */ | 44 | /* scan all key states on matrix */ |
| 45 | uint8_t matrix_scan(void); | 45 | uint8_t matrix_scan(void); |
| 46 | /* whether modified from previous scan. used after matrix_scan. */ | 46 | /* whether modified from previous scan. used after matrix_scan. */ |
| 47 | bool matrix_is_modified(void); | 47 | bool matrix_is_modified(void) __attribute__ ((deprecated)); |
| 48 | /* whether a swtich is on */ | 48 | /* whether a swtich is on */ |
| 49 | bool matrix_is_on(uint8_t row, uint8_t col); | 49 | bool matrix_is_on(uint8_t row, uint8_t col); |
| 50 | /* matrix state on row */ | 50 | /* matrix state on row */ |
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)) | |
diff --git a/keyboard/hbkb/config.h b/keyboard/hbkb/config.h index 57adecfa5..aa3af30c1 100644 --- a/keyboard/hbkb/config.h +++ b/keyboard/hbkb/config.h | |||
| @@ -27,18 +27,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 27 | #define DEVICE_VER 0x0100 | 27 | #define DEVICE_VER 0x0100 |
| 28 | #define PRODUCT Happy Buckling Keyboard | 28 | #define PRODUCT Happy Buckling Keyboard |
| 29 | 29 | ||
| 30 | |||
| 31 | #define DESCRIPTION mod version of IBM Model M keyboard | 30 | #define DESCRIPTION mod version of IBM Model M keyboard |
| 32 | 31 | ||
| 33 | |||
| 34 | /* matrix size */ | 32 | /* matrix size */ |
| 35 | #define MATRIX_ROWS 12 | 33 | #define MATRIX_ROWS 12 |
| 36 | #define MATRIX_COLS 8 | 34 | #define MATRIX_COLS 8 |
| 35 | |||
| 37 | /* define if matrix has ghost */ | 36 | /* define if matrix has ghost */ |
| 38 | #define MATRIX_HAS_GHOST | 37 | #define MATRIX_HAS_GHOST |
| 38 | |||
| 39 | /* Set 0 if need no debouncing */ | 39 | /* Set 0 if need no debouncing */ |
| 40 | #define DEBOUNCE 10 | 40 | #define DEBOUNCE 10 |
| 41 | 41 | ||
| 42 | /* legacy keymap support */ | ||
| 43 | #define USE_LEGACY_KEYMAP | ||
| 42 | 44 | ||
| 43 | /* key combination for command */ | 45 | /* key combination for command */ |
| 44 | #define IS_COMMAND() ( \ | 46 | #define IS_COMMAND() ( \ |
| @@ -46,10 +48,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 46 | keyboard_report->mods == (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) \ | 48 | keyboard_report->mods == (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT)) \ |
| 47 | ) | 49 | ) |
| 48 | 50 | ||
| 49 | 51 | /* Boot Section Size in *BYTEs* | |
| 50 | /* mouse keys */ | 52 | * Teensy halfKay 512 |
| 51 | #ifdef MOUSEKEY_ENABLE | 53 | * Teensy++ halfKay 1024 |
| 52 | # define MOUSEKEY_DELAY_TIME 128 | 54 | * Atmel DFU loader 4096 |
| 53 | #endif | 55 | * LUFA bootloader 4096 |
| 56 | * USBaspLoader 2048 | ||
| 57 | */ | ||
| 58 | #define BOOTLOADER_SIZE 4096 | ||
| 54 | 59 | ||
| 55 | #endif | 60 | #endif |
diff --git a/keyboard/hbkb/matrix.c b/keyboard/hbkb/matrix.c index a24d24b8c..f6830a0f7 100644 --- a/keyboard/hbkb/matrix.c +++ b/keyboard/hbkb/matrix.c | |||
| @@ -32,32 +32,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 32 | * COL: PD0-7 | 32 | * COL: PD0-7 |
| 33 | * ROW: PB0-7, PF4-7 | 33 | * ROW: PB0-7, PF4-7 |
| 34 | */ | 34 | */ |
| 35 | |||
| 36 | #if (MATRIX_COLS > 16) | ||
| 37 | # error "MATRIX_COLS must not exceed 16" | ||
| 38 | #endif | ||
| 39 | #if (MATRIX_ROWS > 255) | ||
| 40 | # error "MATRIX_ROWS must not exceed 255" | ||
| 41 | #endif | ||
| 42 | |||
| 43 | |||
| 44 | #ifndef DEBOUNCE | 35 | #ifndef DEBOUNCE |
| 45 | # define DEBOUNCE 0 | 36 | # define DEBOUNCE 10 |
| 46 | #endif | 37 | #endif |
| 47 | static uint8_t debouncing = DEBOUNCE; | 38 | static uint8_t debouncing = DEBOUNCE; |
| 48 | 39 | ||
| 49 | // matrix state buffer(1:on, 0:off) | 40 | // matrix state buffer(1:on, 0:off) |
| 50 | #if (MATRIX_COLS <= 8) | ||
| 51 | static uint8_t *matrix; | 41 | static uint8_t *matrix; |
| 52 | static uint8_t *matrix_prev; | 42 | static uint8_t *matrix_debouncing; |
| 53 | static uint8_t _matrix0[MATRIX_ROWS]; | 43 | static uint8_t matrix0[MATRIX_ROWS]; |
| 54 | static uint8_t _matrix1[MATRIX_ROWS]; | 44 | static uint8_t matrix1[MATRIX_ROWS]; |
| 55 | #else | ||
| 56 | static uint16_t *matrix; | ||
| 57 | static uint16_t *matrix_prev; | ||
| 58 | static uint16_t _matrix0[MATRIX_ROWS]; | ||
| 59 | static uint16_t _matrix1[MATRIX_ROWS]; | ||
| 60 | #endif | ||
| 61 | 45 | ||
| 62 | #ifdef MATRIX_HAS_GHOST | 46 | #ifdef MATRIX_HAS_GHOST |
| 63 | static bool matrix_has_ghost_in_row(uint8_t row); | 47 | static bool matrix_has_ghost_in_row(uint8_t row); |
| @@ -100,37 +84,35 @@ void matrix_init(void) | |||
| 100 | PORTD = 0xFF; | 84 | PORTD = 0xFF; |
| 101 | 85 | ||
| 102 | // initialize matrix state: all keys off | 86 | // initialize matrix state: all keys off |
| 103 | for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; | 87 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix0[i] = 0x00; |
| 104 | for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00; | 88 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix1[i] = 0x00; |
| 105 | matrix = _matrix0; | 89 | matrix = matrix0; |
| 106 | matrix_prev = _matrix1; | 90 | matrix_debouncing = matrix1; |
| 107 | } | 91 | } |
| 108 | 92 | ||
| 109 | uint8_t matrix_scan(void) | 93 | uint8_t matrix_scan(void) |
| 110 | { | 94 | { |
| 111 | if (!debouncing) { | ||
| 112 | uint8_t *tmp = matrix_prev; | ||
| 113 | matrix_prev = matrix; | ||
| 114 | matrix = tmp; | ||
| 115 | } | ||
| 116 | |||
| 117 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 95 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { |
| 118 | unselect_rows(); | ||
| 119 | select_row(i); | 96 | select_row(i); |
| 120 | _delay_us(30); // without this wait read unstable value. | 97 | _delay_us(30); // without this wait read unstable value. |
| 121 | if (matrix[i] != (uint8_t)~read_col()) { | 98 | if (matrix_debouncing[i] != read_col()) { |
| 122 | matrix[i] = (uint8_t)~read_col(); | 99 | matrix_debouncing[i] = read_col(); |
| 123 | if (debouncing) { | 100 | if (debouncing) { |
| 124 | debug("bounce!: "); debug_hex(debouncing); print("\n"); | 101 | debug("bounce!: "); debug_hex(debouncing); debug("\n"); |
| 125 | } | 102 | } |
| 126 | _delay_ms(1); // TODO: work around. HAHAHAHAHAAHA | ||
| 127 | debouncing = DEBOUNCE; | 103 | debouncing = DEBOUNCE; |
| 128 | } | 104 | } |
| 105 | unselect_rows(); | ||
| 129 | } | 106 | } |
| 130 | unselect_rows(); | ||
| 131 | 107 | ||
| 132 | if (debouncing) { | 108 | if (debouncing) { |
| 133 | debouncing--; | 109 | if (--debouncing) { |
| 110 | _delay_ms(1); | ||
| 111 | } else { | ||
| 112 | uint8_t *tmp = matrix; | ||
| 113 | matrix = matrix_debouncing; | ||
| 114 | matrix_debouncing = tmp; | ||
| 115 | } | ||
| 134 | } | 116 | } |
| 135 | 117 | ||
| 136 | return 1; | 118 | return 1; |
| @@ -139,12 +121,7 @@ uint8_t matrix_scan(void) | |||
| 139 | bool matrix_is_modified(void) | 121 | bool matrix_is_modified(void) |
| 140 | { | 122 | { |
| 141 | if (debouncing) return false; | 123 | if (debouncing) return false; |
| 142 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 124 | return true; |
| 143 | if (matrix[i] != matrix_prev[i]) { | ||
| 144 | return true; | ||
| 145 | } | ||
| 146 | } | ||
| 147 | return false; | ||
| 148 | } | 125 | } |
| 149 | 126 | ||
| 150 | inline | 127 | inline |
| @@ -202,7 +179,7 @@ static bool matrix_has_ghost_in_row(uint8_t row) | |||
| 202 | inline | 179 | inline |
| 203 | static uint8_t read_col(void) | 180 | static uint8_t read_col(void) |
| 204 | { | 181 | { |
| 205 | return PIND; | 182 | return ~PIND; |
| 206 | } | 183 | } |
| 207 | 184 | ||
| 208 | inline | 185 | inline |
diff --git a/keyboard/hid_liber/config.h b/keyboard/hid_liber/config.h index a9b77c7dc..61a75dd0c 100644 --- a/keyboard/hid_liber/config.h +++ b/keyboard/hid_liber/config.h | |||
| @@ -41,12 +41,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 41 | /* Set 0 if need no debouncing */ | 41 | /* Set 0 if need no debouncing */ |
| 42 | #define DEBOUNCE 8 | 42 | #define DEBOUNCE 8 |
| 43 | 43 | ||
| 44 | /* legacy keymap support */ | ||
| 45 | #define USE_LEGACY_KEYMAP | ||
| 44 | 46 | ||
| 45 | /* key combination for command */ | 47 | /* key combination for command */ |
| 46 | #define IS_COMMAND() ( \ | 48 | #define IS_COMMAND() ( \ |
| 47 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ | 49 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ |
| 48 | ) | 50 | ) |
| 49 | 51 | ||
| 52 | /* Boot Section Size in *BYTEs* | ||
| 53 | * Teensy halfKay 512 | ||
| 54 | * Teensy++ halfKay 1024 | ||
| 55 | * Atmel DFU loader 4096 | ||
| 56 | * LUFA bootloader 4096 | ||
| 57 | * USBaspLoader 2048 | ||
| 58 | */ | ||
| 59 | #define BOOTLOADER_SIZE 4096 | ||
| 60 | |||
| 50 | // TODO: configurable | 61 | // TODO: configurable |
| 51 | #define DEBUG_LED 0 | 62 | #define DEBUG_LED 0 |
| 52 | #define DEBUG_LED_CONFIG | 63 | #define DEBUG_LED_CONFIG |
diff --git a/keyboard/hid_liber/matrix.c b/keyboard/hid_liber/matrix.c index 2d939ef63..12ade3302 100644 --- a/keyboard/hid_liber/matrix.c +++ b/keyboard/hid_liber/matrix.c | |||
| @@ -173,7 +173,6 @@ uint8_t matrix_scan(void) | |||
| 173 | if (debouncing) { | 173 | if (debouncing) { |
| 174 | debug("bounce!: "); debug_hex(debouncing); print("\n"); | 174 | debug("bounce!: "); debug_hex(debouncing); print("\n"); |
| 175 | } | 175 | } |
| 176 | _delay_ms(1); // improved affect on bouncing | ||
| 177 | debouncing = DEBOUNCE; | 176 | debouncing = DEBOUNCE; |
| 178 | } | 177 | } |
| 179 | } | 178 | } |
| @@ -181,6 +180,7 @@ uint8_t matrix_scan(void) | |||
| 181 | } | 180 | } |
| 182 | 181 | ||
| 183 | if (debouncing) { | 182 | if (debouncing) { |
| 183 | _delay_ms(1); | ||
| 184 | debouncing--; | 184 | debouncing--; |
| 185 | } | 185 | } |
| 186 | 186 | ||
diff --git a/keyboard/macway/config.h b/keyboard/macway/config.h index 6ab0dec92..b88f898e2 100644 --- a/keyboard/macway/config.h +++ b/keyboard/macway/config.h | |||
| @@ -29,19 +29,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 29 | #define MANUFACTURER t.m.k. | 29 | #define MANUFACTURER t.m.k. |
| 30 | #define PRODUCT Macway mod | 30 | #define PRODUCT Macway mod |
| 31 | 31 | ||
| 32 | |||
| 33 | /* message strings */ | 32 | /* message strings */ |
| 34 | #define DESCRIPTION t.m.k. keyboard firmware for Macway mod | 33 | #define DESCRIPTION t.m.k. keyboard firmware for Macway mod |
| 35 | 34 | ||
| 36 | |||
| 37 | /* matrix size */ | 35 | /* matrix size */ |
| 38 | #define MATRIX_ROWS 9 | 36 | #define MATRIX_ROWS 9 |
| 39 | #define MATRIX_COLS 8 | 37 | #define MATRIX_COLS 8 |
| 38 | |||
| 40 | /* define if matrix has ghost */ | 39 | /* define if matrix has ghost */ |
| 41 | #define MATRIX_HAS_GHOST | 40 | #define MATRIX_HAS_GHOST |
| 41 | |||
| 42 | /* Set 0 if need no debouncing */ | 42 | /* Set 0 if need no debouncing */ |
| 43 | #define DEBOUNCE 5 | 43 | #define DEBOUNCE 5 |
| 44 | 44 | ||
| 45 | /* legacy keymap support */ | ||
| 46 | #define USE_LEGACY_KEYMAP | ||
| 45 | 47 | ||
| 46 | /* key combination for command */ | 48 | /* key combination for command */ |
| 47 | #define IS_COMMAND() ( \ | 49 | #define IS_COMMAND() ( \ |
| @@ -49,17 +51,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 49 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ | 51 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ |
| 50 | ) | 52 | ) |
| 51 | 53 | ||
| 52 | 54 | /* Boot Section Size in *BYTEs* | |
| 53 | /* layer switching */ | 55 | * Teensy halfKay 512 |
| 54 | #define LAYER_SWITCH_DELAY 100 | 56 | * Teensy++ halfKay 1024 |
| 55 | #define LAYER_SEND_FN_TERM 300 | 57 | * Atmel DFU loader 4096 |
| 56 | 58 | * LUFA bootloader 4096 | |
| 57 | 59 | * USBaspLoader 2048 | |
| 58 | /* mouse keys */ | 60 | */ |
| 59 | #ifdef MOUSEKEY_ENABLE | 61 | #define BOOTLOADER_SIZE 4096 |
| 60 | # define MOUSEKEY_DELAY_TIME 192 | ||
| 61 | #endif | ||
| 62 | |||
| 63 | 62 | ||
| 64 | /* PS/2 mouse */ | 63 | /* PS/2 mouse */ |
| 65 | #ifdef PS2_MOUSE_ENABLE | 64 | #ifdef PS2_MOUSE_ENABLE |
diff --git a/keyboard/macway/matrix.c b/keyboard/macway/matrix.c index 4b0fd98f0..0f57bfeae 100644 --- a/keyboard/macway/matrix.c +++ b/keyboard/macway/matrix.c | |||
| @@ -37,27 +37,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | #ifndef DEBOUNCE | 39 | #ifndef DEBOUNCE |
| 40 | # define DEBOUNCE 0 | 40 | # define DEBOUNCE 5 |
| 41 | #endif | 41 | #endif |
| 42 | static uint8_t debouncing = DEBOUNCE; | 42 | static uint8_t debouncing = DEBOUNCE; |
| 43 | 43 | ||
| 44 | // matrix state buffer(1:on, 0:off) | 44 | // matrix state buffer(1:on, 0:off) |
| 45 | #if (MATRIX_COLS <= 8) | 45 | static matrix_row_t *matrix; |
| 46 | static uint8_t *matrix; | 46 | static matrix_row_t *matrix_debouncing; |
| 47 | static uint8_t *matrix_prev; | 47 | static matrix_row_t matrix0[MATRIX_ROWS]; |
| 48 | static uint8_t _matrix0[MATRIX_ROWS]; | 48 | static matrix_row_t matrix1[MATRIX_ROWS]; |
| 49 | static uint8_t _matrix1[MATRIX_ROWS]; | ||
| 50 | #else | ||
| 51 | static uint16_t *matrix; | ||
| 52 | static uint16_t *matrix_prev; | ||
| 53 | static uint16_t _matrix0[MATRIX_ROWS]; | ||
| 54 | static uint16_t _matrix1[MATRIX_ROWS]; | ||
| 55 | #endif | ||
| 56 | 49 | ||
| 57 | #ifdef MATRIX_HAS_GHOST | 50 | #ifdef MATRIX_HAS_GHOST |
| 58 | static bool matrix_has_ghost_in_row(uint8_t row); | 51 | static bool matrix_has_ghost_in_row(uint8_t row); |
| 59 | #endif | 52 | #endif |
| 60 | static uint8_t read_col(void); | 53 | static matrix_row_t read_col(void); |
| 61 | static void unselect_rows(void); | 54 | static void unselect_rows(void); |
| 62 | static void select_row(uint8_t row); | 55 | static void select_row(uint8_t row); |
| 63 | 56 | ||
| @@ -83,26 +76,22 @@ void matrix_init(void) | |||
| 83 | PORTB = 0xFF; | 76 | PORTB = 0xFF; |
| 84 | 77 | ||
| 85 | // initialize matrix state: all keys off | 78 | // initialize matrix state: all keys off |
| 86 | for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; | 79 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { |
| 87 | for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00; | 80 | matrix0[i] = 0; |
| 88 | matrix = _matrix0; | 81 | matrix1[i] = 0; |
| 89 | matrix_prev = _matrix1; | 82 | } |
| 83 | matrix = matrix0; | ||
| 84 | matrix_debouncing = matrix1; | ||
| 90 | } | 85 | } |
| 91 | 86 | ||
| 92 | uint8_t matrix_scan(void) | 87 | uint8_t matrix_scan(void) |
| 93 | { | 88 | { |
| 94 | if (!debouncing) { | ||
| 95 | uint8_t *tmp = matrix_prev; | ||
| 96 | matrix_prev = matrix; | ||
| 97 | matrix = tmp; | ||
| 98 | } | ||
| 99 | |||
| 100 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 89 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { |
| 101 | unselect_rows(); | 90 | unselect_rows(); |
| 102 | select_row(i); | 91 | select_row(i); |
| 103 | _delay_us(30); // without this wait read unstable value. | 92 | _delay_us(30); // without this wait read unstable value. |
| 104 | if (matrix[i] != (uint8_t)~read_col()) { | 93 | if (matrix[i] != read_col()) { |
| 105 | matrix[i] = (uint8_t)~read_col(); | 94 | matrix[i] = read_col(); |
| 106 | if (debouncing) { | 95 | if (debouncing) { |
| 107 | debug("bounce!: "); debug_hex(debouncing); print("\n"); | 96 | debug("bounce!: "); debug_hex(debouncing); print("\n"); |
| 108 | } | 97 | } |
| @@ -112,7 +101,14 @@ uint8_t matrix_scan(void) | |||
| 112 | unselect_rows(); | 101 | unselect_rows(); |
| 113 | 102 | ||
| 114 | if (debouncing) { | 103 | if (debouncing) { |
| 115 | debouncing--; | 104 | if (--debouncing) { |
| 105 | _delay_ms(1); | ||
| 106 | } else { | ||
| 107 | matrix_row_t *tmp = matrix; | ||
| 108 | matrix = matrix_debouncing; | ||
| 109 | matrix_debouncing = tmp; | ||
| 110 | } | ||
| 111 | |||
| 116 | } | 112 | } |
| 117 | 113 | ||
| 118 | return 1; | 114 | return 1; |
| @@ -121,24 +117,7 @@ uint8_t matrix_scan(void) | |||
| 121 | bool matrix_is_modified(void) | 117 | bool matrix_is_modified(void) |
| 122 | { | 118 | { |
| 123 | if (debouncing) return false; | 119 | if (debouncing) return false; |
| 124 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 120 | return true; |
| 125 | if (matrix[i] != matrix_prev[i]) { | ||
| 126 | return true; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | return false; | ||
| 130 | } | ||
| 131 | |||
| 132 | inline | ||
| 133 | bool matrix_has_ghost(void) | ||
| 134 | { | ||
| 135 | #ifdef MATRIX_HAS_GHOST | ||
| 136 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 137 | if (matrix_has_ghost_in_row(i)) | ||
| 138 | return true; | ||
| 139 | } | ||
| 140 | #endif | ||
| 141 | return false; | ||
| 142 | } | 121 | } |
| 143 | 122 | ||
| 144 | inline | 123 | inline |
| @@ -148,11 +127,7 @@ bool matrix_is_on(uint8_t row, uint8_t col) | |||
| 148 | } | 127 | } |
| 149 | 128 | ||
| 150 | inline | 129 | inline |
| 151 | #if (MATRIX_COLS <= 8) | 130 | matrix_row_t matrix_get_row(uint8_t row) |
| 152 | uint8_t matrix_get_row(uint8_t row) | ||
| 153 | #else | ||
| 154 | uint16_t matrix_get_row(uint8_t row) | ||
| 155 | #endif | ||
| 156 | { | 131 | { |
| 157 | return matrix[row]; | 132 | return matrix[row]; |
| 158 | } | 133 | } |
| @@ -207,9 +182,9 @@ static bool matrix_has_ghost_in_row(uint8_t row) | |||
| 207 | #endif | 182 | #endif |
| 208 | 183 | ||
| 209 | inline | 184 | inline |
| 210 | static uint8_t read_col(void) | 185 | static matrix_row_t read_col(void) |
| 211 | { | 186 | { |
| 212 | return PINB; | 187 | return ~PINB; |
| 213 | } | 188 | } |
| 214 | 189 | ||
| 215 | inline | 190 | inline |
diff --git a/keyboard/phantom/config.h b/keyboard/phantom/config.h index 9e8a823d7..a5d472979 100644 --- a/keyboard/phantom/config.h +++ b/keyboard/phantom/config.h | |||
| @@ -26,11 +26,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 26 | #define MANUFACTURER t.m.k. | 26 | #define MANUFACTURER t.m.k. |
| 27 | #define PRODUCT Phantom | 27 | #define PRODUCT Phantom |
| 28 | 28 | ||
| 29 | |||
| 30 | /* message strings */ | 29 | /* message strings */ |
| 31 | #define DESCRIPTION t.m.k. keyboard firmware for Phantom | 30 | #define DESCRIPTION t.m.k. keyboard firmware for Phantom |
| 32 | 31 | ||
| 33 | |||
| 34 | /* matrix size */ | 32 | /* matrix size */ |
| 35 | #define MATRIX_ROWS 6 | 33 | #define MATRIX_ROWS 6 |
| 36 | #define MATRIX_COLS 17 | 34 | #define MATRIX_COLS 17 |
| @@ -41,12 +39,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 41 | /* Set 0 if need no debouncing */ | 39 | /* Set 0 if need no debouncing */ |
| 42 | #define DEBOUNCE 7 | 40 | #define DEBOUNCE 7 |
| 43 | 41 | ||
| 42 | /* legacy keymap support */ | ||
| 43 | #define USE_LEGACY_KEYMAP | ||
| 44 | 44 | ||
| 45 | /* key combination for command */ | 45 | /* key combination for command */ |
| 46 | #define IS_COMMAND() ( \ | 46 | #define IS_COMMAND() ( \ |
| 47 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ | 47 | keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ |
| 48 | ) | 48 | ) |
| 49 | 49 | ||
| 50 | /* Boot Section Size in *BYTEs* | ||
| 51 | * Teensy halfKay 512 | ||
| 52 | * Teensy++ halfKay 1024 | ||
| 53 | * Atmel DFU loader 4096 | ||
| 54 | * LUFA bootloader 4096 | ||
| 55 | * USBaspLoader 2048 | ||
| 56 | */ | ||
| 57 | #define BOOTLOADER_SIZE 4096 | ||
| 58 | |||
| 50 | // TODO: configurable | 59 | // TODO: configurable |
| 51 | #define DEBUG_LED 0 | 60 | #define DEBUG_LED 0 |
| 52 | #define DEBUG_LED_CONFIG | 61 | #define DEBUG_LED_CONFIG |
diff --git a/keyboard/phantom/matrix.c b/keyboard/phantom/matrix.c index 07f3f4289..7ea494a7e 100644 --- a/keyboard/phantom/matrix.c +++ b/keyboard/phantom/matrix.c | |||
| @@ -26,8 +26,8 @@ static uint8_t debouncing = DEBOUNCE; | |||
| 26 | // bit array of key state(1:on, 0:off) | 26 | // bit array of key state(1:on, 0:off) |
| 27 | static matrix_row_t *matrix; | 27 | static matrix_row_t *matrix; |
| 28 | static matrix_row_t *matrix_debounced; | 28 | static matrix_row_t *matrix_debounced; |
| 29 | static matrix_row_t _matrix0[MATRIX_ROWS]; | 29 | static matrix_row_t matrix0[MATRIX_ROWS]; |
| 30 | static matrix_row_t _matrix1[MATRIX_ROWS]; | 30 | static matrix_row_t matrix1[MATRIX_ROWS]; |
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | #define _DDRA (uint8_t *const)&DDRA | 33 | #define _DDRA (uint8_t *const)&DDRA |
| @@ -164,20 +164,16 @@ void matrix_init(void) | |||
| 164 | setup_leds(); | 164 | setup_leds(); |
| 165 | 165 | ||
| 166 | // initialize matrix state: all keys off | 166 | // initialize matrix state: all keys off |
| 167 | for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; | 167 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { |
| 168 | for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00; | 168 | matrix0[i] = 0; |
| 169 | matrix = _matrix0; | 169 | matrix1[i] = 0; |
| 170 | matrix_debounced = _matrix1; | 170 | } |
| 171 | matrix = matrix0; | ||
| 172 | matrix_debounced = matrix1; | ||
| 171 | } | 173 | } |
| 172 | 174 | ||
| 173 | uint8_t matrix_scan(void) | 175 | uint8_t matrix_scan(void) |
| 174 | { | 176 | { |
| 175 | if (!debouncing) { | ||
| 176 | matrix_row_t *tmp = matrix_debounced; | ||
| 177 | matrix_debounced = matrix; | ||
| 178 | matrix = tmp; | ||
| 179 | } | ||
| 180 | |||
| 181 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { // 0-16 | 177 | for (uint8_t col = 0; col < MATRIX_COLS; col++) { // 0-16 |
| 182 | pull_column(col); // output hi on theline | 178 | pull_column(col); // output hi on theline |
| 183 | _delay_us(3); // without this wait it won't read stable value. | 179 | _delay_us(3); // without this wait it won't read stable value. |
| @@ -196,7 +192,13 @@ uint8_t matrix_scan(void) | |||
| 196 | } | 192 | } |
| 197 | 193 | ||
| 198 | if (debouncing) { | 194 | if (debouncing) { |
| 199 | debouncing--; | 195 | if (--debouncing) { |
| 196 | _delay_ms(1); | ||
| 197 | } else { | ||
| 198 | matrix_row_t *tmp = matrix_debounced; | ||
| 199 | matrix_debounced = matrix; | ||
| 200 | matrix = tmp; | ||
| 201 | } | ||
| 200 | } | 202 | } |
| 201 | 203 | ||
| 202 | return 1; | 204 | return 1; |
| @@ -209,12 +211,6 @@ bool matrix_is_modified(void) | |||
| 209 | } | 211 | } |
| 210 | 212 | ||
| 211 | inline | 213 | inline |
| 212 | bool matrix_has_ghost(void) | ||
| 213 | { | ||
| 214 | return false; | ||
| 215 | } | ||
| 216 | |||
| 217 | inline | ||
| 218 | bool matrix_is_on(uint8_t row, uint8_t col) | 214 | bool matrix_is_on(uint8_t row, uint8_t col) |
| 219 | { | 215 | { |
| 220 | return (matrix_debounced[row] & ((matrix_row_t)1<<col)); | 216 | return (matrix_debounced[row] & ((matrix_row_t)1<<col)); |
