diff options
-rw-r--r-- | chip/npcx/keyboard_raw.c | 6 | ||||
-rw-r--r-- | chip/npcx/registers.h | 1 | ||||
-rw-r--r-- | common/keyboard_scan.c | 37 | ||||
-rw-r--r-- | include/config.h | 4 | ||||
-rw-r--r-- | include/keyboard_config.h | 5 |
5 files changed, 49 insertions, 4 deletions
diff --git a/chip/npcx/keyboard_raw.c b/chip/npcx/keyboard_raw.c index 96390a5720..8c2915b542 100644 --- a/chip/npcx/keyboard_raw.c +++ b/chip/npcx/keyboard_raw.c @@ -94,14 +94,14 @@ test_mockable void keyboard_raw_drive_column(int col) /* Drive all lines to high */ if (col == KEYBOARD_COLUMN_NONE) { - mask = KB_COL_MASK; + mask = ~0; #ifdef CONFIG_KEYBOARD_COL2_INVERTED gpio_set_level(GPIO_KBD_KSO2, 0); #endif } /* Set KBSOUT to zero to detect key-press */ else if (col == KEYBOARD_COLUMN_ALL) { - mask = 0; + mask = ~((1 << KEYBOARD_COLS) - 1); #ifdef CONFIG_KEYBOARD_COL2_INVERTED gpio_set_level(GPIO_KBD_KSO2, 1); #endif @@ -114,7 +114,7 @@ test_mockable void keyboard_raw_drive_column(int col) else gpio_set_level(GPIO_KBD_KSO2, 0); #endif - mask = ((~(1 << col_out)) & KB_COL_MASK); + mask = ~(1 << col_out); } /* Set KBSOUT */ diff --git a/chip/npcx/registers.h b/chip/npcx/registers.h index 32ad827833..9e3ee1938d 100644 --- a/chip/npcx/registers.h +++ b/chip/npcx/registers.h @@ -363,7 +363,6 @@ #define KB_ROW_NUM 8 /* Rows numbers of keyboard matrix */ #define KB_COL_NUM 18 /* Columns numbers of keyboard matrix */ #define KB_ROW_MASK ((1<<KB_ROW_NUM) - 1) /* Mask of rows of keyboard matrix */ -#define KB_COL_MASK ((1<<KB_COL_NUM) - 1) /* Mask of cols of keyboard matrix */ /******************************************************************************/ /* GLUE registers */ diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c index fee48e6a26..96dececd78 100644 --- a/common/keyboard_scan.c +++ b/common/keyboard_scan.c @@ -89,6 +89,9 @@ static uint8_t __bss_slow prev_state[KEYBOARD_COLS]; static uint8_t __bss_slow debouncing[KEYBOARD_COLS]; /* Keys simulated-pressed */ static uint8_t __bss_slow simulated_key[KEYBOARD_COLS]; +#ifdef CONFIG_KEYBOARD_LANGUAGE_ID +static uint8_t __bss_slow keyboard_id[KEYBOARD_IDS]; +#endif /* Times of last scans */ static uint32_t __bss_slow scan_time[SCAN_TIME_COUNT]; @@ -275,6 +278,35 @@ static int read_matrix(uint8_t *state) return pressed ? 1 : 0; } +#ifdef CONFIG_KEYBOARD_LANGUAGE_ID +/** + * Read the raw keyboard IDs state. + * + * Used in pre-init, so must not make task-switching-dependent calls; udelay() + * is ok because it's a spin-loop. + * + * @param id Destination for keyboard id (must be KEYBOARD_IDS long). + * + */ +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); + udelay(keyscan_config.output_settle_us); + + /* Read the row state */ + id[c] = keyboard_raw_read_rows(); + + CPRINTS("Keyboard ID%u: 0x%02x\n", c, id[c]); + } + + keyboard_raw_drive_column(KEYBOARD_COLUMN_NONE); +} +#endif + #ifdef CONFIG_KEYBOARD_RUNTIME_KEYS /** * Check special runtime key combinations. @@ -647,6 +679,11 @@ void keyboard_scan_init(void) read_matrix(debounced_state); memcpy(prev_state, debounced_state, sizeof(prev_state)); +#ifdef CONFIG_KEYBOARD_LANGUAGE_ID + /* Check keyboard ID state */ + read_matrix_id(keyboard_id); +#endif + #ifdef CONFIG_KEYBOARD_BOOT_KEYS /* Check for keys held down at boot */ boot_key_value = check_boot_key(debounced_state); diff --git a/include/config.h b/include/config.h index 8b7003c96b..faf6f42764 100644 --- a/include/config.h +++ b/include/config.h @@ -1960,6 +1960,10 @@ */ #undef CONFIG_KEYBOARD_KSO_HIGH_DRIVE +/* + * Add support for keyboards with language ID pins + */ +#undef CONFIG_KEYBOARD_LANGUAGE_ID /*****************************************************************************/ /* Support common LED interface */ diff --git a/include/keyboard_config.h b/include/keyboard_config.h index f338d63c7f..932935de4c 100644 --- a/include/keyboard_config.h +++ b/include/keyboard_config.h @@ -10,6 +10,11 @@ #include "common.h" +#ifdef CONFIG_KEYBOARD_LANGUAGE_ID +/* Keyboard matrix support for language ID pins */ +#define KEYBOARD_IDS 2 +#endif + /* Keyboard matrix is 13 output columns x 8 input rows */ #define KEYBOARD_COLS 13 #define KEYBOARD_ROWS 8 |