diff options
author | Vijay Hiremath <vijay.p.hiremath@intel.com> | 2016-09-01 14:23:48 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-09-02 15:12:21 -0700 |
commit | d99bc90631e9d9762d6646372c71e29359cf8947 (patch) | |
tree | 4ab90bde496b4e6ed581865c18cebec5a769db8b | |
parent | 12608eceb6a4bed6e09380f6811e2280aed94d6e (diff) | |
download | chrome-ec-d99bc90631e9d9762d6646372c71e29359cf8947.tar.gz |
button: Add console command to simulate button press
BUG=chrome-os-partner:56878
BRANCH=none
TEST=Using console command 'button' verified that volume button
icon slides on reef.
Change-Id: I8051194fd91f989f8887cebce6ea2af1b8c9f731
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/380315
Commit-Ready: Bill Richardson <wfrichar@chromium.org>
Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Tested-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
-rw-r--r-- | common/button.c | 86 | ||||
-rw-r--r-- | include/config.h | 1 |
2 files changed, 86 insertions, 1 deletions
diff --git a/common/button.c b/common/button.c index deace7f2f1..fb47984ad9 100644 --- a/common/button.c +++ b/common/button.c @@ -26,12 +26,29 @@ static struct button_state_t __bss_slow state[CONFIG_BUTTON_COUNT]; static uint64_t __bss_slow next_deferred_time; +#ifdef CONFIG_CMD_BUTTON +static int siml_btn_presd; + +static int simulated_button_pressed(void) +{ + static int button = 1; + + button = !button; + return button; +} +#endif + /* * Whether a button is currently pressed. */ static int raw_button_pressed(const struct button_config *button) { - int raw_value = gpio_get_level(button->gpio); + int raw_value = +#ifdef CONFIG_CMD_BUTTON + siml_btn_presd ? + simulated_button_pressed() : +#endif + gpio_get_level(button->gpio); return button->flags & BUTTON_FLAG_ACTIVE_HIGH ? raw_value : !raw_value; @@ -130,3 +147,70 @@ void button_interrupt(enum gpio_signal signal) break; } } + +#ifdef CONFIG_CMD_BUTTON +static int button_present(enum keyboard_button_type type) +{ + int i; + + for (i = 0; i < CONFIG_BUTTON_COUNT; i++) + if (buttons[i].type == type) + break; + + return i; +} + +static void button_interrupt_simulate(int button) +{ + button_interrupt(buttons[button].gpio); + usleep(buttons[button].debounce_us >> 2); + button_interrupt(buttons[button].gpio); +} + +static int console_command_button(int argc, char **argv) +{ + int button; + int press_ms = 50; + char *e; + + if (argc < 2) + return EC_ERROR_PARAM_COUNT; + + if (!strcasecmp(argv[1], "vup")) + button = button_present(KEYBOARD_BUTTON_VOLUME_UP); + else if (!strcasecmp(argv[1], "vdown")) + button = button_present(KEYBOARD_BUTTON_VOLUME_DOWN); + else + return EC_ERROR_PARAM1; + + if (button == CONFIG_BUTTON_COUNT) + return EC_ERROR_PARAM1; + + if (argc > 2) { + press_ms = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_PARAM2; + } + + siml_btn_presd = 1; + + /* Press the button */ + button_interrupt_simulate(button); + + /* Hold the button */ + msleep(press_ms); + + /* Release the button */ + button_interrupt_simulate(button); + + /* Wait till button processing is finished */ + msleep(100); + + siml_btn_presd = 0; + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(button, console_command_button, + "vup|vdown msec", + "Simulate button press"); +#endif diff --git a/include/config.h b/include/config.h index 5ccb5ce39e..1cb5b83108 100644 --- a/include/config.h +++ b/include/config.h @@ -560,6 +560,7 @@ #define CONFIG_CMD_APTHROTTLE #undef CONFIG_CMD_BATDEBUG #define CONFIG_CMD_BATTFAKE +#undef CONFIG_CMD_BUTTON #define CONFIG_CMD_CHARGER #undef CONFIG_CMD_CHARGER_ADC_AMON_BMON #undef CONFIG_CMD_CHARGER_PSYS |