diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/keyboard_8042.c | 2 | ||||
-rw-r--r-- | common/keyboard_8042_sharedlib.c | 4 | ||||
-rw-r--r-- | common/keyboard_mkbp.c | 13 | ||||
-rw-r--r-- | common/keyboard_scan.c | 53 | ||||
-rw-r--r-- | common/keyboard_test.c | 2 |
5 files changed, 40 insertions, 34 deletions
diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c index 124ac8adee..f45b84d465 100644 --- a/common/keyboard_8042.c +++ b/common/keyboard_8042.c @@ -306,7 +306,7 @@ static enum ec_error_list matrix_callback(int8_t row, int8_t col, ASSERT(scan_code); ASSERT(len); - if (row >= KEYBOARD_ROWS || col >= KEYBOARD_COLS) + if (row >= KEYBOARD_ROWS || col >= keyboard_cols) return EC_ERROR_INVAL; make_code = scancode_set2[col][row]; diff --git a/common/keyboard_8042_sharedlib.c b/common/keyboard_8042_sharedlib.c index 98d71cc1f9..a189d17744 100644 --- a/common/keyboard_8042_sharedlib.c +++ b/common/keyboard_8042_sharedlib.c @@ -16,7 +16,7 @@ #ifndef CONFIG_KEYBOARD_SCANCODE_MUTABLE SHAREDLIB(const #endif -uint16_t scancode_set2[KEYBOARD_COLS][KEYBOARD_ROWS] = { +uint16_t scancode_set2[KEYBOARD_COLS_MAX][KEYBOARD_ROWS] = { {0x0000, 0x0000, 0x0014, 0xe01f, 0xe014, 0xe007, 0x0000, 0x0000}, {0xe01f, 0x0076, 0x000d, 0x000e, 0x001c, 0x001a, 0x0016, 0x0015}, {0x0005, 0x000c, 0x0004, 0x0006, 0x0023, 0x0021, 0x0026, 0x0024}, @@ -79,7 +79,7 @@ char * const keycap_long_label[KLLI_MAX & KEYCAP_LONG_LABEL_INDEX_BITMASK] = { #ifndef CONFIG_KEYBOARD_SCANCODE_MUTABLE SHAREDLIB(const #endif -char keycap_label[KEYBOARD_COLS][KEYBOARD_ROWS] = { +char keycap_label[KEYBOARD_COLS_MAX][KEYBOARD_ROWS] = { {KLLI_UNKNO, KLLI_UNKNO, KLLI_L_CTR, KLLI_UNKNO, KLLI_R_CTR, KLLI_UNKNO, KLLI_UNKNO, KLLI_UNKNO}, {KLLI_SEARC, KLLI_ESC, KLLI_TAB, '~', diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c index efd86f2e10..186475b4dd 100644 --- a/common/keyboard_mkbp.c +++ b/common/keyboard_mkbp.c @@ -72,7 +72,8 @@ static uint32_t mkbp_button_state; static uint32_t mkbp_switch_state; #ifndef HAS_TASK_KEYSCAN /* Keys simulated-pressed */ -static uint8_t __bss_slow simulated_key[KEYBOARD_COLS]; +static uint8_t __bss_slow simulated_key[KEYBOARD_COLS_MAX]; +uint8_t keyboard_cols = KEYBOARD_COLS_MAX; #endif /* !defined(HAS_TASK_KEYSCAN) */ /* Config for mkbp protocol; does not include fields from scan config */ @@ -99,7 +100,7 @@ static int get_data_size(enum ec_mkbp_event e) { switch (e) { case EC_MKBP_EVENT_KEY_MATRIX: - return KEYBOARD_COLS; + return keyboard_cols; #ifdef CONFIG_HOST_EVENT64 case EC_MKBP_EVENT_HOST_EVENT64: @@ -396,7 +397,7 @@ DECLARE_EVENT_SOURCE(EC_MKBP_EVENT_SYSRQ, sysrq_get_next_event); void keyboard_send_battery_key(void) { - uint8_t state[KEYBOARD_COLS]; + uint8_t state[KEYBOARD_COLS_MAX]; /* Copy debounced state and add battery pseudo-key */ memcpy(state, keyboard_scan_get_state(), sizeof(state)); @@ -456,7 +457,7 @@ static int mkbp_get_info(struct host_cmd_handler_args *args) /* Version 0 just returns info about the keyboard. */ r->rows = KEYBOARD_ROWS; - r->cols = KEYBOARD_COLS; + r->cols = keyboard_cols; /* This used to be "switches" which was previously 0. */ r->reserved = 0; @@ -551,7 +552,7 @@ static int command_mkbp_keyboard_press(int argc, char **argv) int i, j; ccputs("Simulated keys:\n"); - for (i = 0; i < KEYBOARD_COLS; ++i) { + for (i = 0; i < keyboard_cols; ++i) { if (simulated_key[i] == 0) continue; for (j = 0; j < KEYBOARD_ROWS; ++j) @@ -564,7 +565,7 @@ static int command_mkbp_keyboard_press(int argc, char **argv) char *e; c = strtoi(argv[1], &e, 0); - if (*e || c < 0 || c >= KEYBOARD_COLS) + if (*e || c < 0 || c >= keyboard_cols) return EC_ERROR_PARAM1; r = strtoi(argv[2], &e, 0); diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c index 034b82519c..f9a64eb806 100644 --- a/common/keyboard_scan.c +++ b/common/keyboard_scan.c @@ -82,14 +82,16 @@ static const struct boot_key_entry boot_key_list[] = { static uint32_t boot_key_value = BOOT_KEY_NONE; #endif +uint8_t keyboard_cols = KEYBOARD_COLS_MAX; + /* Debounced key matrix */ -static uint8_t __bss_slow debounced_state[KEYBOARD_COLS]; +static uint8_t __bss_slow debounced_state[KEYBOARD_COLS_MAX]; /* Matrix from previous scan */ -static uint8_t __bss_slow prev_state[KEYBOARD_COLS]; +static uint8_t __bss_slow prev_state[KEYBOARD_COLS_MAX]; /* Mask of keys being debounced */ -static uint8_t __bss_slow debouncing[KEYBOARD_COLS]; +static uint8_t __bss_slow debouncing[KEYBOARD_COLS_MAX]; /* Keys simulated-pressed */ -static uint8_t __bss_slow simulated_key[KEYBOARD_COLS]; +static uint8_t __bss_slow simulated_key[KEYBOARD_COLS_MAX]; #ifdef CONFIG_KEYBOARD_LANGUAGE_ID static uint8_t __bss_slow keyboard_id[KEYBOARD_IDS]; #endif @@ -100,7 +102,7 @@ static uint32_t __bss_slow scan_time[SCAN_TIME_COUNT]; static int __bss_slow scan_time_index; /* Index into scan_time[] when each key started debouncing */ -static uint8_t __bss_slow scan_edge_index[KEYBOARD_COLS][KEYBOARD_ROWS]; +static uint8_t __bss_slow scan_edge_index[KEYBOARD_COLS_MAX][KEYBOARD_ROWS]; /* Minimum delay between keyboard scans based on current clock frequency */ static uint32_t __bss_slow post_scan_clock_us; @@ -151,7 +153,7 @@ static void print_state(const uint8_t *state, const char *msg) int c; CPRINTF("[%T KB %s:", msg); - for (c = 0; c < KEYBOARD_COLS; c++) { + for (c = 0; c < keyboard_cols; c++) { if (state[c]) CPRINTF(" %02x", state[c]); else @@ -227,7 +229,7 @@ static void simulate_key(int row, int col, int pressed) * Used in pre-init, so must not make task-switching-dependent calls; udelay() * is ok because it's a spin-loop. * - * @param state Destination for new state (must be KEYBOARD_COLS long). + * @param state Destination for new state (must be KEYBOARD_COLS_MAX long). * * @return 1 if at least one key is pressed, else zero. */ @@ -237,7 +239,7 @@ static int read_matrix(uint8_t *state) uint8_t r; int pressed = 0; - for (c = 0; c < KEYBOARD_COLS; c++) { + for (c = 0; c < keyboard_cols; c++) { /* * Stop if scanning becomes disabled. Note, scanning is enabled * on boot by default. @@ -294,8 +296,11 @@ static void read_matrix_id(uint8_t *id) int c; for (c = 0; c < KEYBOARD_IDS; c++) { - /* Select the ID pin, then wait a bit for it to settle */ - keyboard_raw_drive_column(KEYBOARD_COLS + c); + /* Select the ID pin, then wait a bit for it to settle. + * Caveat: If a keyboard maker puts ID pins right after scan + * columns, we can't support variable column size with a single + * image. */ + keyboard_raw_drive_column(KEYBOARD_COLS_MAX + c); udelay(keyscan_config.output_settle_us); /* Read the row state */ @@ -378,7 +383,7 @@ static int check_runtime_keys(const uint8_t *state) * pressed for volume up and alt, so if only one more key is pressed * there will be exactly 3 non-zero columns. */ - for (c = 0; c < KEYBOARD_COLS; c++) { + for (c = 0; c < keyboard_cols; c++) { if (state[c]) num_press++; } @@ -419,11 +424,11 @@ static int has_ghosting(const uint8_t *state) { int c, c2; - for (c = 0; c < KEYBOARD_COLS; c++) { + for (c = 0; c < keyboard_cols; c++) { if (!state[c]) continue; - for (c2 = c + 1; c2 < KEYBOARD_COLS; c2++) { + for (c2 = c + 1; c2 < keyboard_cols; c2++) { /* * A little bit of cleverness here. Ghosting happens * if 2 columns share at least 2 keys. So we OR the @@ -453,7 +458,7 @@ static int check_keys_changed(uint8_t *state) int any_pressed = 0; int c, i; int any_change = 0; - static uint8_t __bss_slow new_state[KEYBOARD_COLS]; + static uint8_t __bss_slow new_state[KEYBOARD_COLS_MAX]; uint32_t tnow = get_time().le.lo; /* Save the current scan time */ @@ -469,7 +474,7 @@ static int check_keys_changed(uint8_t *state) return any_pressed; /* Check for changes between previous scan and this one */ - for (c = 0; c < KEYBOARD_COLS; c++) { + for (c = 0; c < keyboard_cols; c++) { int diff = new_state[c] ^ prev_state[c]; if (!diff) @@ -485,7 +490,7 @@ static int check_keys_changed(uint8_t *state) } /* Check for keys which are done debouncing */ - for (c = 0; c < KEYBOARD_COLS; c++) { + for (c = 0; c < keyboard_cols; c++) { int debc = debouncing[c]; if (!debc) @@ -567,7 +572,7 @@ static int check_keys_changed(uint8_t *state) */ static uint32_t check_key_list(const uint8_t *state) { - uint8_t curr_state[KEYBOARD_COLS]; + uint8_t curr_state[KEYBOARD_COLS_MAX]; int c; uint32_t boot_key_mask = BOOT_KEY_NONE; const struct boot_key_entry *k; @@ -580,13 +585,13 @@ static uint32_t check_key_list(const uint8_t *state) * Check if KSI2 or KSI3 is asserted for all columns due to power * button hold, and ignore it if so. */ - for (c = 0; c < KEYBOARD_COLS; c++) + for (c = 0; c < keyboard_cols; c++) if ((keyscan_config.actual_key_mask[c] & KEYBOARD_MASK_PWRBTN) && !(curr_state[c] & KEYBOARD_MASK_PWRBTN)) break; - if (c == KEYBOARD_COLS) - for (c = 0; c < KEYBOARD_COLS; c++) + if (c == keyboard_cols) + for (c = 0; c < keyboard_cols; c++) curr_state[c] &= ~KEYBOARD_MASK_PWRBTN; #endif @@ -602,7 +607,7 @@ static uint32_t check_key_list(const uint8_t *state) } /* If any other key was pressed, ignore all boot keys. */ - for (c = 0; c < KEYBOARD_COLS; c++) { + for (c = 0; c < keyboard_cols; c++) { if (curr_state[c]) return BOOT_KEY_NONE; } @@ -844,7 +849,7 @@ static int mkbp_command_simulate_key(struct host_cmd_handler_args *args) if (system_is_locked()) return EC_RES_ACCESS_DENIED; - if (p->col >= KEYBOARD_COLS || p->row >= KEYBOARD_ROWS) + if (p->col >= keyboard_cols || p->row >= KEYBOARD_ROWS) return EC_RES_INVALID_PARAM; simulate_key(p->row, p->col, p->pressed); @@ -933,7 +938,7 @@ static int command_keyboard_press(int argc, char **argv) int i, j; ccputs("Simulated keys:\n"); - for (i = 0; i < KEYBOARD_COLS; ++i) { + for (i = 0; i < keyboard_cols; ++i) { if (simulated_key[i] == 0) continue; for (j = 0; j < KEYBOARD_ROWS; ++j) @@ -946,7 +951,7 @@ static int command_keyboard_press(int argc, char **argv) char *e; c = strtoi(argv[1], &e, 0); - if (*e || c < 0 || c >= KEYBOARD_COLS) + if (*e || c < 0 || c >= keyboard_cols) return EC_ERROR_PARAM1; r = strtoi(argv[2], &e, 0); diff --git a/common/keyboard_test.c b/common/keyboard_test.c index 580d4745cf..fee7d6db69 100644 --- a/common/keyboard_test.c +++ b/common/keyboard_test.c @@ -78,7 +78,7 @@ uint8_t keyscan_seq_get_scan(int column, uint8_t scan) int c; scan = 0; - for (c = 0; c < KEYBOARD_COLS; c++) + for (c = 0; c < keyboard_cols; c++) scan |= item->scan[c]; } else { scan = item->scan[column]; |