diff options
-rw-r--r-- | board/daisy/board.h | 4 | ||||
-rw-r--r-- | board/link/board.h | 2 | ||||
-rw-r--r-- | board/mccroskey/board.h | 4 | ||||
-rw-r--r-- | board/snow/board.h | 4 | ||||
-rw-r--r-- | board/spring/board.h | 6 | ||||
-rw-r--r-- | chip/lm4/keyboard_scan.c | 73 | ||||
-rw-r--r-- | chip/lm4/mock_keyboard_scan_stub.c | 11 | ||||
-rw-r--r-- | chip/stm32/keyboard_raw.c | 7 | ||||
-rw-r--r-- | chip/stm32/keyboard_scan.c | 84 | ||||
-rw-r--r-- | common/keyboard.c | 19 | ||||
-rw-r--r-- | common/keyboard_test.c | 4 | ||||
-rw-r--r-- | include/keyboard_config.h | 35 | ||||
-rw-r--r-- | include/keyboard_raw.h | 4 | ||||
-rw-r--r-- | include/keyboard_test.h | 4 | ||||
-rw-r--r-- | util/ectool_keyscan.c | 13 |
15 files changed, 133 insertions, 141 deletions
diff --git a/board/daisy/board.h b/board/daisy/board.h index 105cf46111..f32d2e86a9 100644 --- a/board/daisy/board.h +++ b/board/daisy/board.h @@ -36,9 +36,7 @@ #define USB_CHARGE_PORT_COUNT 0 -/* EC drives 13 outputs to the keyboard matrix and reads 8 inputs/interrupts */ -#define KB_INPUTS 8 -#define KB_OUTPUTS 13 +/* Keyboard output port list */ #define KB_OUT_PORT_LIST GPIO_B, GPIO_C /* Charging */ diff --git a/board/link/board.h b/board/link/board.h index b5ced2755d..a7b6f2ae60 100644 --- a/board/link/board.h +++ b/board/link/board.h @@ -102,7 +102,7 @@ enum adc_channel /* There are only 3 I2C ports used because battery and charger share a port */ #define I2C_PORTS_USED 3 -/* Keyboard scanner uses an entire GPIO bank for row inputs */ +/* 13x8 keyboard scanner uses an entire GPIO bank for row inputs */ #define KB_SCAN_ROW_IRQ LM4_IRQ_GPION #define KB_SCAN_ROW_GPIO LM4_GPIO_N diff --git a/board/mccroskey/board.h b/board/mccroskey/board.h index b775c66cd9..095a95fc42 100644 --- a/board/mccroskey/board.h +++ b/board/mccroskey/board.h @@ -44,9 +44,7 @@ #define USB_CHARGE_PORT_COUNT 0 -/* EC drives 13 outputs to the keyboard matrix and reads 8 inputs/interrupts */ -#define KB_INPUTS 8 -#define KB_OUTPUTS 13 +/* Keyboard output ports */ #define KB_OUT_PORT_LIST GPIO_C /* EC is I2C master */ diff --git a/board/snow/board.h b/board/snow/board.h index a0964a8d05..fe9883e7b1 100644 --- a/board/snow/board.h +++ b/board/snow/board.h @@ -38,9 +38,7 @@ #define USB_CHARGE_PORT_COUNT 0 -/* EC drives 13 outputs to the keyboard matrix and reads 8 inputs/interrupts */ -#define KB_INPUTS 8 -#define KB_OUTPUTS 13 +/* Keyboard output ports */ #define KB_OUT_PORT_LIST GPIO_B, GPIO_C /* Charging */ diff --git a/board/spring/board.h b/board/spring/board.h index ea4ce7db89..03bb785af1 100644 --- a/board/spring/board.h +++ b/board/spring/board.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -40,9 +40,7 @@ /* By default, enable all console messages except keyboard */ #define CC_DEFAULT (CC_ALL & ~CC_MASK(CC_KEYSCAN)) -/* EC drives 13 outputs to the keyboard matrix and reads 8 inputs/interrupts */ -#define KB_INPUTS 8 -#define KB_OUTPUTS 13 +/* Keyboard output port list */ #define KB_OUT_PORT_LIST GPIO_B, GPIO_C /* Charging */ diff --git a/chip/lm4/keyboard_scan.c b/chip/lm4/keyboard_scan.c index 0c56738a05..950af73136 100644 --- a/chip/lm4/keyboard_scan.c +++ b/chip/lm4/keyboard_scan.c @@ -10,6 +10,7 @@ #include "console.h" #include "host_command.h" #include "keyboard.h" +#include "keyboard_config.h" #include "keyboard_raw.h" #include "keyboard_scan.h" #include "switch.h" @@ -29,8 +30,6 @@ #define SCAN_LOOP_DELAY MSEC /* Delay in scan loop */ #define COLUMN_CHARGE_US 40 /* Column charge time in usec */ -#define KB_COLS 13 - #define SCAN_TIME_COUNT 32 /* Number of last scan times to track */ /* Boot key list. Must be in same order as enum boot_key. */ @@ -40,22 +39,22 @@ struct boot_key_entry { }; const struct boot_key_entry boot_key_list[] = { {0, 0x00}, /* (none) */ - {1, 0x02}, /* Esc */ - {11, 0x40}, /* Down-arrow */ + {KEYBOARD_COL_ESC, KEYBOARD_MASK_ESC}, /* Esc */ + {KEYBOARD_COL_DOWN, KEYBOARD_MASK_DOWN}, /* Down-arrow */ }; -static uint8_t debounced_state[KB_COLS]; /* Debounced key matrix */ -static uint8_t prev_state[KB_COLS]; /* Matrix from previous scan */ -static uint8_t debouncing[KB_COLS]; /* Mask of keys being debounced */ +static uint8_t debounced_state[KEYBOARD_COLS]; /* Debounced key matrix */ +static uint8_t prev_state[KEYBOARD_COLS]; /* Matrix from previous scan */ +static uint8_t debouncing[KEYBOARD_COLS]; /* Mask of keys being debounced */ static uint32_t scan_time[SCAN_TIME_COUNT]; /* Times of last scans */ static int scan_time_index; /* Current scan_time[] index */ /* Index into scan_time[] when each key started debouncing */ -static uint8_t scan_edge_index[KB_COLS][8]; +static uint8_t scan_edge_index[KEYBOARD_COLS][KEYBOARD_ROWS]; enum boot_key boot_key_value = BOOT_KEY_OTHER; /* Mask with 1 bits only for keys that actually exist */ -static const uint8_t actual_key_mask[KB_COLS] = { +static const uint8_t actual_key_mask[KEYBOARD_COLS] = { 0x14, 0xff, 0xff, 0xff, 0xff, 0xf5, 0xff, 0xa4, 0xff, 0xf6, 0x55, 0xfa, 0xc8 /* full set */ }; @@ -66,22 +65,6 @@ static const uint8_t actual_key_mask[KB_COLS] = { */ static int print_state_changes; -/* Key masks for special boot keys */ -#define MASK_INDEX_REFRESH 2 -#define MASK_VALUE_REFRESH 0x04 - -/* Key masks for special runtime keys */ -#define MASK_INDEX_VOL_UP 4 -#define MASK_VALUE_VOL_UP 0x01 -#define MASK_INDEX_RIGHT_ALT 10 -#define MASK_VALUE_RIGHT_ALT 0x01 -#define MASK_INDEX_LEFT_ALT 10 -#define MASK_VALUE_LEFT_ALT 0x40 -#define MASK_INDEX_KEY_R 3 -#define MASK_VALUE_KEY_R 0x80 -#define MASK_INDEX_KEY_H 6 -#define MASK_VALUE_KEY_H 0x02 - static int enable_scanning = 1; /* Must init to 1 for scanning at boot */ static void enable_interrupt(void) @@ -113,7 +96,7 @@ static int is_scanning_enabled(void) * 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 KB_COLS long). + * @param state Destination for new state (must be KEYBOARD_COLS long). * * @return 1 if at least one key is pressed, else zero. */ @@ -123,7 +106,7 @@ static int read_matrix(uint8_t *state) uint8_t r; int pressed = 0; - for (c = 0; c < KB_COLS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { /* Stop if scanning becomes disabled */ if (!enable_scanning) break; @@ -158,7 +141,7 @@ static void print_state(const uint8_t *state, const char *msg) int c; CPRINTF("[%T KB %s:", msg); - for (c = 0; c < KB_COLS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { if (state[c]) CPRINTF(" %02x", state[c]); else @@ -181,10 +164,10 @@ static void check_runtime_keys(const uint8_t *state) * All runtime key combos are (right or left ) alt + volume up + (some * key NOT on the same col as alt or volume up ) */ - if (state[MASK_INDEX_VOL_UP] != MASK_VALUE_VOL_UP) + if (state[KEYBOARD_COL_VOL_UP] != KEYBOARD_MASK_VOL_UP) return; - if (state[MASK_INDEX_RIGHT_ALT] != MASK_VALUE_RIGHT_ALT && - state[MASK_INDEX_LEFT_ALT] != MASK_VALUE_LEFT_ALT) + if (state[KEYBOARD_COL_RIGHT_ALT] != KEYBOARD_MASK_RIGHT_ALT && + state[KEYBOARD_COL_LEFT_ALT] != KEYBOARD_MASK_LEFT_ALT) return; /* @@ -192,7 +175,7 @@ static void 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 < KB_COLS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { if (state[c]) num_press++; } @@ -200,11 +183,11 @@ static void check_runtime_keys(const uint8_t *state) return; /* Check individual keys */ - if (state[MASK_INDEX_KEY_R] == MASK_VALUE_KEY_R) { + if (state[KEYBOARD_COL_KEY_R] == KEYBOARD_MASK_KEY_R) { /* R = reboot */ CPRINTF("[%T KB warm reboot]\n"); chipset_reset(0); - } else if (state[MASK_INDEX_KEY_H] == MASK_VALUE_KEY_H) { + } else if (state[KEYBOARD_COL_KEY_H] == KEYBOARD_MASK_KEY_H) { /* H = hibernate */ CPRINTF("[%T KB hibernate]\n"); system_hibernate(0, 0); @@ -222,11 +205,11 @@ static int has_ghosting(const uint8_t *state) { int c, c2; - for (c = 0; c < KB_COLS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { if (!state[c]) continue; - for (c2 = c + 1; c2 < KB_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 @@ -256,7 +239,7 @@ static int check_keys_changed(uint8_t *state) int any_pressed = 0; int c, i; int any_change = 0; - uint8_t new_state[KB_COLS]; + uint8_t new_state[KEYBOARD_COLS]; uint32_t tnow = get_time().le.lo; /* Save the current scan time */ @@ -277,12 +260,12 @@ static int check_keys_changed(uint8_t *state) return any_pressed; /* Check for changes between previous scan and this one */ - for (c = 0; c < KB_COLS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { int diff = new_state[c] ^ prev_state[c]; if (!diff) continue; - for (i = 0; i < 8; i++) { + for (i = 0; i < KEYBOARD_ROWS; i++) { if (diff & (1 << i)) scan_edge_index[c][i] = scan_time_index; } @@ -292,12 +275,12 @@ static int check_keys_changed(uint8_t *state) } /* Check for keys which are done debouncing */ - for (c = 0; c < KB_COLS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { int debc = debouncing[c]; if (!debc) continue; - for (i = 0; i < 8; i++) { + for (i = 0; i < KEYBOARD_ROWS; i++) { int mask = 1 << i; int new_mask = new_state[c] & mask; @@ -350,7 +333,7 @@ static int check_keys_changed(uint8_t *state) */ static int check_key(const uint8_t *state, int index, int mask) { - uint8_t allowed_mask[KB_COLS] = {0}; + uint8_t allowed_mask[KEYBOARD_COLS] = {0}; int c; /* Check for the key */ @@ -359,9 +342,9 @@ static int check_key(const uint8_t *state, int index, int mask) /* Check for other allowed keys */ allowed_mask[index] |= mask; - allowed_mask[MASK_INDEX_REFRESH] |= MASK_VALUE_REFRESH; + allowed_mask[KEYBOARD_COL_REFRESH] |= KEYBOARD_MASK_REFRESH; - for (c = 0; c < KB_COLS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { if (state[c] & ~allowed_mask[c]) return 0; /* Disallowed key pressed */ } @@ -392,7 +375,7 @@ static enum boot_key keyboard_scan_check_boot_key(const uint8_t *state) /* If reset was not caused by reset pin, refresh must be held down */ if (!(system_get_reset_flags() & RESET_FLAG_RESET_PIN) && - !(state[MASK_INDEX_REFRESH] & MASK_VALUE_REFRESH)) + !(state[KEYBOARD_COL_REFRESH] & KEYBOARD_MASK_REFRESH)) return BOOT_KEY_OTHER; /* Check what single key is down */ diff --git a/chip/lm4/mock_keyboard_scan_stub.c b/chip/lm4/mock_keyboard_scan_stub.c index 0c9ecff2f5..6334475dfa 100644 --- a/chip/lm4/mock_keyboard_scan_stub.c +++ b/chip/lm4/mock_keyboard_scan_stub.c @@ -7,24 +7,23 @@ #include "common.h" #include "console.h" +#include "keyboard_config.h" #include "keyboard_raw.h" #include "keyboard_scan.h" #include "task.h" #include "uart.h" #include "util.h" -#define MOCK_COLUMN_COUNT 13 - static int enable_scanning = 1; static int selected_column = -1; static int interrupt_enabled = 0; -static uint8_t matrix_status[MOCK_COLUMN_COUNT]; +static uint8_t matrix_status[KEYBOARD_COLS]; void keyboard_raw_init(void) { /* Init matrix status to release all */ int i; - for (i = 0; i < MOCK_COLUMN_COUNT; ++i) + for (i = 0; i < KEYBOARD_COLS; ++i) matrix_status[i] = 0xff; } @@ -59,11 +58,11 @@ static int command_mock_matrix(int argc, char **argv) return EC_ERROR_PARAM_COUNT; c = strtoi(argv[1], &e, 0); - if (*e || c < 0 || c >= MOCK_COLUMN_COUNT) + if (*e || c < 0 || c >= KEYBOARD_COLS) return EC_ERROR_PARAM1; r = strtoi(argv[2], &e, 0); - if (*e || r < 0 || r >= 8) + if (*e || r < 0 || r >= KEYBOARD_ROWS) return EC_ERROR_PARAM2; p = strtoi(argv[3], &e, 0); diff --git a/chip/stm32/keyboard_raw.c b/chip/stm32/keyboard_raw.c index e6a3dc65eb..1c799ba894 100644 --- a/chip/stm32/keyboard_raw.c +++ b/chip/stm32/keyboard_raw.c @@ -8,10 +8,11 @@ * input and output entries in the board's gpio_list[]. Each set of inputs or * outputs must be listed in consecutive, increasing order so that scan loops * can iterate beginning at KB_IN00 or KB_OUT00 for however many GPIOs are - * utilized (KB_INPUTS or KB_OUTPUTS). + * utilized (KEYBOARD_ROWS or KEYBOARD_COLS). */ #include "gpio.h" +#include "keyboard_config.h" #include "keyboard_raw.h" #include "keyboard_scan.h" #include "registers.h" @@ -27,7 +28,7 @@ static void set_irq_mask(void) { int i; - for (i = GPIO_KB_IN00; i < GPIO_KB_IN00 + KB_INPUTS; i++) + for (i = GPIO_KB_IN00; i < GPIO_KB_IN00 + KEYBOARD_ROWS; i++) irq_mask |= gpio_list[i].mask; } @@ -100,7 +101,7 @@ int keyboard_raw_read_rows(void) int state = 0; uint16_t port_val = 0; - for (i = 0; i < KB_INPUTS; i++) { + for (i = 0; i < KEYBOARD_ROWS; i++) { port = gpio_list[GPIO_KB_IN00 + i].port; if (port != prev_port) { port_val = STM32_GPIO_IDR_OFF(port); diff --git a/chip/stm32/keyboard_scan.c b/chip/stm32/keyboard_scan.c index 7839a5d1d7..1d8bf2819e 100644 --- a/chip/stm32/keyboard_scan.c +++ b/chip/stm32/keyboard_scan.c @@ -11,6 +11,7 @@ #include "gpio.h" #include "host_command.h" #include "keyboard.h" +#include "keyboard_config.h" #include "keyboard_raw.h" #include "keyboard_scan.h" #include "keyboard_test.h" @@ -27,29 +28,13 @@ static struct mutex scanning_enabled; -static uint8_t debounced_state[KB_OUTPUTS]; /* Debounced key matrix */ -static uint8_t prev_state[KB_OUTPUTS]; /* Matrix from previous scan */ -static uint8_t debouncing[KB_OUTPUTS]; /* Mask of keys being debounced */ +static uint8_t debounced_state[KEYBOARD_COLS]; /* Debounced key matrix */ +static uint8_t prev_state[KEYBOARD_COLS]; /* Matrix from previous scan */ +static uint8_t debouncing[KEYBOARD_COLS]; /* Mask of keys being debounced */ static uint32_t scan_time[SCAN_TIME_COUNT]; /* Times of last scans */ static int scan_time_index; /* Current scan_time[] index */ /* Index into scan_time[] when each key started debouncing */ -static uint8_t scan_edge_index[KB_OUTPUTS][KB_INPUTS]; - -/* Key masks for special boot keys */ -#define MASK_INDEX_ESC 1 -#define MASK_VALUE_ESC 0x02 -#define MASK_INDEX_REFRESH 2 -#define MASK_VALUE_REFRESH 0x04 - -/* Key masks and values for warm reboot combination */ -#define MASK_INDEX_KEYR 3 -#define MASK_VALUE_KEYR 0x80 -#define MASK_INDEX_VOL_UP 4 -#define MASK_VALUE_VOL_UP 0x01 -#define MASK_INDEX_RIGHT_ALT 10 -#define MASK_VALUE_RIGHT_ALT 0x01 -#define MASK_INDEX_LEFT_ALT 10 -#define MASK_VALUE_LEFT_ALT 0x40 +static uint8_t scan_edge_index[KEYBOARD_COLS][KEYBOARD_ROWS]; /*****************************************************************************/ @@ -65,7 +50,7 @@ void board_keyboard_suppress_noise(void) static uint32_t kb_fifo_start; /* first entry */ static uint32_t kb_fifo_end; /* last entry */ static uint32_t kb_fifo_entries; /* number of existing entries */ -static uint8_t kb_fifo[KB_FIFO_DEPTH][KB_OUTPUTS]; +static uint8_t kb_fifo[KB_FIFO_DEPTH][KEYBOARD_COLS]; /* * Our configuration. The debounce parameters are not yet supported. @@ -86,7 +71,9 @@ static struct ec_mkbp_config config = { .fifo_max_depth = KB_FIFO_DEPTH, }; -/* clear keyboard state variables */ +/** + * Clear keyboard state variables. + */ void keyboard_clear_state(void) { int i; @@ -96,7 +83,7 @@ void keyboard_clear_state(void) kb_fifo_end = 0; kb_fifo_entries = 0; for (i = 0; i < KB_FIFO_DEPTH; i++) - memset(kb_fifo[i], 0, KB_OUTPUTS); + memset(kb_fifo[i], 0, KEYBOARD_COLS); } /** @@ -115,7 +102,7 @@ static int kb_fifo_add(uint8_t *buffp) goto kb_fifo_push_done; } - memcpy(kb_fifo[kb_fifo_end], buffp, KB_OUTPUTS); + memcpy(kb_fifo[kb_fifo_end], buffp, KEYBOARD_COLS); kb_fifo_end = (kb_fifo_end + 1) % KB_FIFO_DEPTH; @@ -135,7 +122,7 @@ static int kb_fifo_remove(uint8_t *buffp) if (!kb_fifo_entries) { /* no entry remaining in FIFO : return last known state */ int last = (kb_fifo_start + KB_FIFO_DEPTH - 1) % KB_FIFO_DEPTH; - memcpy(buffp, kb_fifo[last], KB_OUTPUTS); + memcpy(buffp, kb_fifo[last], KEYBOARD_COLS); /* * Bail out without changing any FIFO indices and let the @@ -144,7 +131,7 @@ static int kb_fifo_remove(uint8_t *buffp) */ return EC_ERROR_UNKNOWN; } - memcpy(buffp, kb_fifo[kb_fifo_start], KB_OUTPUTS); + memcpy(buffp, kb_fifo[kb_fifo_start], KEYBOARD_COLS); kb_fifo_start = (kb_fifo_start + 1) % KB_FIFO_DEPTH; @@ -174,7 +161,7 @@ static int check_runtime_keys(const uint8_t *state) int c; /* Count number of key pressed */ - for (c = num_press = 0; c < KB_OUTPUTS; c++) { + for (c = num_press = 0; c < KEYBOARD_COLS; c++) { if (state[c]) ++num_press; } @@ -182,10 +169,10 @@ static int check_runtime_keys(const uint8_t *state) if (num_press != 3) return 0; - if (state[MASK_INDEX_KEYR] == MASK_VALUE_KEYR && - state[MASK_INDEX_VOL_UP] == MASK_VALUE_VOL_UP && - (state[MASK_INDEX_RIGHT_ALT] == MASK_VALUE_RIGHT_ALT || - state[MASK_INDEX_LEFT_ALT] == MASK_VALUE_LEFT_ALT)) { + if (state[KEYBOARD_COL_KEY_R] == KEYBOARD_MASK_KEY_R && + state[KEYBOARD_COL_VOL_UP] == KEYBOARD_MASK_VOL_UP && + (state[KEYBOARD_COL_RIGHT_ALT] == KEYBOARD_MASK_RIGHT_ALT || + state[KEYBOARD_COL_LEFT_ALT] == KEYBOARD_MASK_LEFT_ALT)) { keyboard_clear_state(); chipset_reset(0); return 1; @@ -200,7 +187,7 @@ static void print_state(const uint8_t *state, const char *msg) int c; CPRINTF("[%T KB %s:", msg); - for (c = 0; c < KB_OUTPUTS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { if (state[c]) CPRINTF(" %02x", state[c]); else @@ -215,7 +202,7 @@ static void print_state(const uint8_t *state, const char *msg) * 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 KB_OUTPUTS long). + * @param state Destination for new state (must be KEYBOARD_COLS long). * * @return 1 if at least one key is pressed, else zero. */ @@ -225,7 +212,7 @@ static int read_matrix(uint8_t *state) uint8_t r; int pressed = 0; - for (c = 0; c < KB_OUTPUTS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { /* Assert output, then wait a bit for it to settle */ keyboard_raw_drive_column(c); udelay(config.output_settle_us); @@ -263,7 +250,7 @@ static int check_keys_changed(uint8_t *state) int any_pressed = 0; int c, i; int any_change = 0; - uint8_t new_state[KB_OUTPUTS]; + uint8_t new_state[KEYBOARD_COLS]; uint32_t tnow = get_time().le.lo; /* Save the current scan time */ @@ -275,13 +262,13 @@ static int check_keys_changed(uint8_t *state) any_pressed = read_matrix(new_state); /* Check for changes between previous scan and this one */ - for (c = 0; c < KB_OUTPUTS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { int diff = new_state[c] ^ prev_state[c]; if (!diff) continue; - for (i = 0; i < KB_INPUTS; i++) { + for (i = 0; i < KEYBOARD_ROWS; i++) { if (diff & (1 << i)) scan_edge_index[c][i] = scan_time_index; } @@ -291,13 +278,13 @@ static int check_keys_changed(uint8_t *state) } /* Check for keys which are done debouncing */ - for (c = 0; c < KB_OUTPUTS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { int debc = debouncing[c]; if (!debc) continue; - for (i = 0; i < KB_INPUTS; i++) { + for (i = 0; i < KEYBOARD_ROWS; i++) { int mask = 1 << i; int new_mask = new_state[c] & mask; @@ -367,17 +354,18 @@ static int check_recovery_key(const uint8_t *state) /* cold boot : Power + Refresh were pressed, * check if ESC is also pressed for recovery. */ - if (!(state[MASK_INDEX_ESC] & MASK_VALUE_ESC)) + if (!(state[KEYBOARD_COL_ESC] & KEYBOARD_MASK_ESC)) return 0; /* Make sure only other allowed keys are pressed. This protects * against accidentally triggering the special key when a cat sits on * your keyboard. Currently, only the requested key and ESC are * allowed. */ - for (c = 0; c < KB_OUTPUTS; c++) { + for (c = 0; c < KEYBOARD_COLS; c++) { if (state[c] && - (c != MASK_INDEX_ESC || state[c] != MASK_VALUE_ESC) && - (c != MASK_INDEX_REFRESH || state[c] != MASK_VALUE_REFRESH)) + (c != KEYBOARD_COL_ESC || state[c] != KEYBOARD_MASK_ESC) && + (c != KEYBOARD_COL_REFRESH || + state[c] != KEYBOARD_MASK_REFRESH)) return 0; /* Additional disallowed key pressed */ } @@ -497,7 +485,7 @@ static int keyboard_get_scan(struct host_cmd_handler_args *args) if (!kb_fifo_entries) set_host_interrupt(0); - args->response_size = KB_OUTPUTS; + args->response_size = KEYBOARD_COLS; return EC_RES_SUCCESS; } @@ -509,8 +497,8 @@ static int keyboard_get_info(struct host_cmd_handler_args *args) { struct ec_response_mkbp_info *r = args->response; - r->rows = KB_INPUTS; - r->cols = KB_OUTPUTS; + r->rows = KEYBOARD_ROWS; + r->cols = KEYBOARD_COLS; r->switches = 0; args->response_size = sizeof(*r); @@ -567,11 +555,11 @@ static int command_keyboard_press(int argc, char **argv) return EC_ERROR_PARAM_COUNT; c = strtoi(argv[1], &e, 0); - if (*e || c < 0 || c >= KB_OUTPUTS) + if (*e || c < 0 || c >= KEYBOARD_COLS) return EC_ERROR_PARAM1; r = strtoi(argv[2], &e, 0); - if (*e || r < 0 || r >= 8) + if (*e || r < 0 || r >= KEYBOARD_ROWS) return EC_ERROR_PARAM2; p = strtoi(argv[3], &e, 0); diff --git a/common/keyboard.c b/common/keyboard.c index a9d0a38623..feda6d884a 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -13,6 +13,7 @@ #include "i8042.h" #include "i8042_protocol.h" #include "keyboard.h" +#include "keyboard_config.h" #include "lightbar.h" #include "lpc.h" #include "registers.h" @@ -107,9 +108,7 @@ struct kb_state { /* The standard Chrome OS keyboard matrix table. */ -#define CROS_ROW_NUM 8 /* TODO: +1 for power button. */ -#define CROS_COL_NUM 13 -static const uint16_t scancode_set1[CROS_ROW_NUM][CROS_COL_NUM] = { +static const uint16_t scancode_set1[KEYBOARD_ROWS][KEYBOARD_COLS] = { {0x0000, 0xe05b, 0x003b, 0x0030, 0x0044, 0x0073, 0x0031, 0x0000, 0x000d, 0x0000, 0xe038, 0x0000, 0x0000}, {0x0000, 0x0001, 0x003e, 0x0022, 0x0041, 0x0000, 0x0023, 0x0000, 0x0028, @@ -128,7 +127,7 @@ static const uint16_t scancode_set1[CROS_ROW_NUM][CROS_COL_NUM] = { 0x0018, 0x0000, 0xe048, 0xe04b}, }; -static const uint16_t scancode_set2[CROS_ROW_NUM][CROS_COL_NUM] = { +static const uint16_t scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS] = { {0x0000, 0xe01f, 0x0005, 0x0032, 0x0009, 0x0051, 0x0031, 0x0000, 0x0055, 0x0000, 0xe011, 0x0000, 0x0000}, {0x0000, 0x0076, 0x000c, 0x0034, 0x0083, 0x0000, 0x0033, 0x0000, 0x0052, @@ -149,7 +148,7 @@ static const uint16_t scancode_set2[CROS_ROW_NUM][CROS_COL_NUM] = { /* Recording which key is being simulated pressed. */ -static uint8_t simulated_key[CROS_COL_NUM]; +static uint8_t simulated_key[KEYBOARD_COLS]; /* Log the traffic between EC and host -- for debug only */ @@ -184,7 +183,7 @@ static enum ec_error_list matrix_callback(int8_t row, int8_t col, ASSERT(scan_code); ASSERT(len); - if (row > CROS_ROW_NUM || col > CROS_COL_NUM) + if (row > KEYBOARD_ROWS || col > KEYBOARD_COLS) return EC_ERROR_INVAL; if (pressed) @@ -842,10 +841,10 @@ static int command_keyboard_press(int argc, char **argv) int i, j; ccputs("Simulated key:\n"); - for (i = 0; i < CROS_COL_NUM; ++i) { + for (i = 0; i < KEYBOARD_COLS; ++i) { if (simulated_key[i] == 0) continue; - for (j = 0; j < CROS_ROW_NUM; ++j) + for (j = 0; j < KEYBOARD_ROWS; ++j) if (simulated_key[i] & (1 << j)) ccprintf("\t%d %d\n", i, j); } @@ -855,11 +854,11 @@ static int command_keyboard_press(int argc, char **argv) char *e; c = strtoi(argv[1], &e, 0); - if (*e || c < 0 || c >= CROS_COL_NUM) + if (*e || c < 0 || c >= KEYBOARD_COLS) return EC_ERROR_PARAM1; r = strtoi(argv[2], &e, 0); - if (*e || r < 0 || r >= CROS_ROW_NUM) + if (*e || r < 0 || r >= KEYBOARD_ROWS) return EC_ERROR_PARAM2; p = strtoi(argv[3], &e, 0); diff --git a/common/keyboard_test.c b/common/keyboard_test.c index 03d31fd63b..580d4745cf 100644 --- a/common/keyboard_test.c +++ b/common/keyboard_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 The Chromium OS Authors. All rights reserved. + * Copyright (c) 2013 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -78,7 +78,7 @@ uint8_t keyscan_seq_get_scan(int column, uint8_t scan) int c; scan = 0; - for (c = 0; c < KB_OUTPUTS; c++) + for (c = 0; c < KEYBOARD_COLS; c++) scan |= item->scan[c]; } else { scan = item->scan[column]; diff --git a/include/keyboard_config.h b/include/keyboard_config.h new file mode 100644 index 0000000000..ff2eded50c --- /dev/null +++ b/include/keyboard_config.h @@ -0,0 +1,35 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Keyboard configuration constants for Chrome EC */ + +#ifndef __CROS_EC_KEYBOARD_CONFIG_H +#define __CROS_EC_KEYBOARD_CONFIG_H + +#include "common.h" + +/* Keyboard matrix is 13 output columns x 8 input rows */ +#define KEYBOARD_COLS 13 +#define KEYBOARD_ROWS 8 + +/* Columns and masks for keys we particularly care about */ +#define KEYBOARD_COL_DOWN 11 +#define KEYBOARD_MASK_DOWN 0x40 +#define KEYBOARD_COL_ESC 1 +#define KEYBOARD_MASK_ESC 0x02 +#define KEYBOARD_COL_KEY_H 6 +#define KEYBOARD_MASK_KEY_H 0x02 +#define KEYBOARD_COL_KEY_R 3 +#define KEYBOARD_MASK_KEY_R 0x80 +#define KEYBOARD_COL_LEFT_ALT 10 +#define KEYBOARD_MASK_LEFT_ALT 0x40 +#define KEYBOARD_COL_REFRESH 2 +#define KEYBOARD_MASK_REFRESH 0x04 +#define KEYBOARD_COL_RIGHT_ALT 10 +#define KEYBOARD_MASK_RIGHT_ALT 0x01 +#define KEYBOARD_COL_VOL_UP 4 +#define KEYBOARD_MASK_VOL_UP 0x01 + +#endif /* __CROS_EC_KEYBOARD_CONFIG_H */ diff --git a/include/keyboard_raw.h b/include/keyboard_raw.h index 6432335a52..339b5344cb 100644 --- a/include/keyboard_raw.h +++ b/include/keyboard_raw.h @@ -14,11 +14,11 @@ #include "common.h" #include "gpio.h" -/* used for select_column() */ +/* Column values for keyboard_raw_drive_column() */ enum keyboard_column_index { KEYBOARD_COLUMN_ALL = -2, /* Drive all columns */ KEYBOARD_COLUMN_NONE = -1, /* Drive no columns (tri-state all) */ - /* 0 ~ 12 for the corresponding column */ + /* 0 ~ KEYBOARD_COLS-1 for the corresponding column */ }; /** diff --git a/include/keyboard_test.h b/include/keyboard_test.h index df95d9c081..b1e4abb9c5 100644 --- a/include/keyboard_test.h +++ b/include/keyboard_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 The Chromium OS Authors. All rights reserved. + * Copyright (c) 2013 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -19,7 +19,7 @@ struct keyscan_item { timestamp_t abs_time; /* absolute timestamp to present this item */ uint32_t time_us; /* time for this item relative to test start */ uint8_t done; /* 1 if we managed to present this */ - uint8_t scan[KB_OUTPUTS]; + uint8_t scan[KEYBOARD_COLS]; }; /** diff --git a/util/ectool_keyscan.c b/util/ectool_keyscan.c index 7ca0af660e..868fbd11ab 100644 --- a/util/ectool_keyscan.c +++ b/util/ectool_keyscan.c @@ -12,6 +12,7 @@ #include <sys/stat.h> #include "comm-host.h" +#include "keyboard_config.h" #include "ectool.h" enum { @@ -21,13 +22,6 @@ enum { KEYSCAN_MAX_INPUT_LEN = 20, /* Maximum characters we can receive */ }; -#ifdef KB_OUTPUTS -#define KEYSCAN_OUTPUTS KB_OUTPUTS -#else -/* Use a suitable default */ -#define KEYSCAN_OUTPUTS 13 -#endif - /* A single entry of the key matrix */ struct matrix_entry { int row; /* key matrix row */ @@ -37,7 +31,7 @@ struct matrix_entry { struct keyscan_test_item { uint32_t beat; /* Beat number */ - uint8_t scan[KEYSCAN_OUTPUTS]; /* Scan data */ + uint8_t scan[KEYBOARD_COLS]; /* Scan data */ }; /* A single test, consisting of a list of key scans and expected ascii input */ @@ -107,7 +101,8 @@ static int keyscan_read_fdt_matrix(struct keyscan_info *keyscan, matrix->keycode = word & 0xffff; /* Hard-code some sanity limits for now */ - if (matrix->row >= 8 || matrix->col >= 13) { + if (matrix->row >= KEYBOARD_ROWS || + matrix->col >= KEYBOARD_COLS) { fprintf(stderr, "Matrix pos out of range (%d,%d)\n", matrix->row, matrix->col); return -1; |