button: Check volume up/down status and set recovery mode

Add support for entering recovery mode using volume up/down keys.

BRANCH=none
BUG=chrome-os-partner:61930
TEST=Press Power+Volume Up+Volume Down, poppy enters recovery

Change-Id: Id40a144e9b430cfb9dfd47048e9e96d598bc3db8
Reviewed-on: https://chromium-review.googlesource.com/428530
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Nicolas Boichat
2017-01-14 17:33:02 +08:00
committed by chrome-bot
parent a1064d9979
commit 90ae18655c
5 changed files with 32 additions and 8 deletions

View File

@@ -9,8 +9,10 @@
#include "common.h"
#include "console.h"
#include "gpio.h"
#include "host_command.h"
#include "hooks.h"
#include "keyboard_protocol.h"
#include "system.h"
#include "timer.h"
#include "util.h"
@@ -57,7 +59,7 @@ static int raw_button_pressed(const struct button_config *button)
/*
* Button initialization.
*/
static void button_init(void)
void button_init(void)
{
int i;
@@ -68,8 +70,16 @@ static void button_init(void)
state[i].debounce_time = 0;
gpio_enable_interrupt(buttons[i].gpio);
}
#ifdef CONFIG_BUTTON_RECOVERY
if (!system_jumped_to_this_image() &&
(system_get_reset_flags() & RESET_FLAG_RESET_PIN) &&
raw_button_pressed(&buttons[BUTTON_VOLUME_DOWN]) &&
raw_button_pressed(&buttons[BUTTON_VOLUME_UP])) {
host_set_single_event(EC_HOST_EVENT_KEYBOARD_RECOVERY);
}
#endif
}
DECLARE_HOOK(HOOK_INIT, button_init, HOOK_PRIO_DEFAULT);
/*
* Handle debounced button changing state.

View File

@@ -6,6 +6,7 @@
*/
#include "board_config.h"
#include "button.h"
#include "clock.h"
#include "common.h"
#include "console.h"
@@ -157,6 +158,9 @@ test_mockable __keep int main(void)
#ifdef HAS_TASK_KEYSCAN
keyboard_scan_init();
#endif
#ifdef CONFIG_BUTTON_COUNT
button_init();
#endif
#ifdef CONFIG_RWSIG
/*

View File

@@ -42,6 +42,11 @@ struct button_config {
*/
extern const struct button_config buttons[];
/*
* Button initialization, called from main.
*/
void button_init(void);
/*
* Interrupt handler for button.
*

View File

@@ -349,6 +349,9 @@
*/
#undef CONFIG_BUTTON_COUNT
/* Support for entering recovery mode using volume buttons. */
#undef CONFIG_BUTTON_RECOVERY
/*
* Enable case close debug (CCD) mode in the EC.
*/

View File

@@ -140,7 +140,7 @@ static int test_button_press_both(void)
return EC_SUCCESS;
}
static void button_init(void)
static void button_test_init(void)
{
int i;
@@ -159,21 +159,23 @@ void run_test(void)
test_reset();
button_init();
button_test_init();
RUN_TEST(test_button_press);
button_init();
button_test_init();
RUN_TEST(test_button_release);
button_init();
button_test_init();
RUN_TEST(test_button_debounce_short_press);
button_init();
button_test_init();
RUN_TEST(test_button_debounce_short_bounce);
button_init();
button_test_init();
RUN_TEST(test_button_debounce_stability);
button_init();
button_test_init();
RUN_TEST(test_button_press_both);
test_print_result();