diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-10-18 11:03:28 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-10-24 16:45:04 -0700 |
commit | bcd764143b1a00016251908908120cb8d7261890 (patch) | |
tree | cb4127711fffc0deaa1bc2b82fdd43f229edb221 | |
parent | d0d86e66c917812e1a9e7ef50fe3edf6ea4721f8 (diff) | |
download | chrome-ec-bcd764143b1a00016251908908120cb8d7261890.tar.gz |
Keyboard: Add set & get API for keyboard_cols
keyboard_cols is a global variable which defines the keyboard size.
This patch adds keyboard_raw_get_cols and keyboard_raw_set_cols
for getting and setting the variable.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b:117126568
BRANCH=none
TEST=buildall
Change-Id: Ie0bd54ac4155d5649f72343584d970dfde26d1d4
Reviewed-on: https://chromium-review.googlesource.com/1289309
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | include/keyboard_config.h | 4 | ||||
-rw-r--r-- | include/keyboard_raw.h | 19 |
2 files changed, 23 insertions, 0 deletions
diff --git a/include/keyboard_config.h b/include/keyboard_config.h index 2d6398c548..61ee80960f 100644 --- a/include/keyboard_config.h +++ b/include/keyboard_config.h @@ -31,6 +31,10 @@ #endif #define KEYBOARD_ROWS 8 +/* + * WARNING: Do not directly modify it. You should call keyboard_raw_set_cols, + * instead. It checks whether you're eligible or not. + */ extern uint8_t keyboard_cols; #define KEYBOARD_ROW_TO_MASK(r) (1 << (r)) diff --git a/include/keyboard_raw.h b/include/keyboard_raw.h index d2c3e6b38b..7b21898f91 100644 --- a/include/keyboard_raw.h +++ b/include/keyboard_raw.h @@ -11,8 +11,10 @@ #ifndef __CROS_EC_KEYBOARD_RAW_H #define __CROS_EC_KEYBOARD_RAW_H +#include "assert.h" #include "common.h" #include "gpio.h" +#include "keyboard_config.h" /* Column values for keyboard_raw_drive_column() */ enum keyboard_column_index { @@ -78,4 +80,21 @@ static inline void keyboard_raw_gpio_interrupt(enum gpio_signal signal) { } */ int keyboard_factory_test_scan(void); +static inline int keyboard_raw_get_cols(void) { + return keyboard_cols; +} + +static inline void keyboard_raw_set_cols(int cols) { +#ifdef CONFIG_KEYBOARD_LANGUAGE_ID + /* Keyboard ID is probably encoded right after the last column. Scanner + * would read keyboard ID if the column size is decreased. */ + assert(cols == KEYBOARD_COLS_MAX); +#else + /* We can only decrease the column size. You have to assume a larger + * grid (and reduce scanning size if the keyboard has no keypad). */ + assert(cols <= KEYBOARD_COLS_MAX); +#endif + keyboard_cols = cols; +} + #endif /* __CROS_EC_KEYBOARD_RAW_H */ |