From db79418605d6c128a03af99156467963c01c05d8 Mon Sep 17 00:00:00 2001 From: Furquan Shaikh Date: Tue, 7 Nov 2017 12:49:17 -0800 Subject: buttons: Update button codes for vup, vdn and power 1. Differentiate button codes for short press and long press of volume up and volume down. 2. Add a new code for volume up-down combo press since it is expected to be used for one of the firmware screens. 3. Treat volume down long press as Ctrl-D on developer screen. 4. Treat volume up long press as Ctrl-U on developer screen. CQ-DEPEND=CL:756254 BUG=b:64992445,b:65013794 BRANCH=None TEST=Verified that buttons work as expected on Soraka. Change-Id: I5d443f43f785b973f3ff4aeaac52b152ed2fe0bd Signed-off-by: Furquan Shaikh Reviewed-on: https://chromium-review.googlesource.com/757123 Reviewed-by: Aaron Durbin --- firmware/include/vboot_api.h | 17 +++++++++++++---- firmware/lib/vboot_ui_menu.c | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h index 3df025e2..cedf266d 100644 --- a/firmware/include/vboot_api.h +++ b/firmware/include/vboot_api.h @@ -877,11 +877,20 @@ enum VbKeyCode_t { VB_KEY_CTRL_ENTER = 0x104 }; -/* Button codes match that of 8042 ascii values */ +/* + * WARNING!!! Before updating the codes in enum VbButtonCode_t, ensure that the + * code does not overlap the values in VbKeyCode_t unless the button action is + * the same as key action. + */ enum VbButtonCode_t { - VB_BUTTON_VOL_UP = 0x62, - VB_BUTTON_VOL_DOWN = 0x63, - VB_BUTTON_POWER = 0x90 + /* Volume up/down short press match the values in 8042 driver. */ + VB_BUTTON_VOL_UP_SHORT_PRESS = 0x62, + VB_BUTTON_VOL_DOWN_SHORT_PRESS = 0x63, + /* Dummy values used below. */ + VB_BUTTON_POWER_SHORT_PRESS = 0x90, + VB_BUTTON_VOL_UP_LONG_PRESS = 0x91, + VB_BUTTON_VOL_DOWN_LONG_PRESS = 0x92, + VB_BUTTON_VOL_UP_DOWN_COMBO_PRESS = 0x93, }; /* Flags for additional information. diff --git a/firmware/lib/vboot_ui_menu.c b/firmware/lib/vboot_ui_menu.c index 2e3b17b7..91993064 100644 --- a/firmware/lib/vboot_ui_menu.c +++ b/firmware/lib/vboot_ui_menu.c @@ -674,7 +674,7 @@ void vb2_update_selection(VbCommonParams *cparams, uint32_t key) { } switch (key) { - case VB_BUTTON_VOL_UP: + case VB_BUTTON_VOL_UP_SHORT_PRESS: case VB_KEY_UP: idx = current_menu_idx - 1; while (idx >= 0 && @@ -684,7 +684,7 @@ void vb2_update_selection(VbCommonParams *cparams, uint32_t key) { if (idx >= 0) current_menu_idx = idx; break; - case VB_BUTTON_VOL_DOWN: + case VB_BUTTON_VOL_DOWN_SHORT_PRESS: case VB_KEY_DOWN: idx = current_menu_idx + 1; while (idx < menu_size && @@ -808,6 +808,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams) case 0: /* Nothing pressed */ break; + case VB_BUTTON_VOL_DOWN_LONG_PRESS: case 0x04: /* Ctrl+D = dismiss warning; advance to timeout */ VB2_DEBUG("user pressed Ctrl+D; skip delay\n"); @@ -818,6 +819,7 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams) VB2_DEBUG("user pressed Ctrl+L; Try legacy boot\n"); VbTryLegacyMenu(allow_legacy); break; + case VB_BUTTON_VOL_UP_LONG_PRESS: case 0x15: /* Ctrl+U = try USB boot, or beep if failure */ VB2_DEBUG("user pressed Ctrl+U; try USB\n"); @@ -848,21 +850,21 @@ VbError_t vb2_developer_menu(struct vb2_context *ctx, VbCommonParams *cparams) } } break; - case VB_BUTTON_VOL_UP: + case VB_BUTTON_VOL_UP_SHORT_PRESS: case VB_KEY_UP: vb2_update_selection(cparams, key); vb2_draw_current_screen(ctx, cparams); /* reset 30 second timer */ audio = VbAudioOpen(cparams); break; - case VB_BUTTON_VOL_DOWN: + case VB_BUTTON_VOL_DOWN_SHORT_PRESS: case VB_KEY_DOWN: vb2_update_selection(cparams, key); vb2_draw_current_screen(ctx, cparams); /* reset 30 second timer */ audio = VbAudioOpen(cparams); break; - case VB_BUTTON_POWER: + case VB_BUTTON_POWER_SHORT_PRESS: case '\r': selected = 1; @@ -1064,7 +1066,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) VB2_DEBUG("waiting for manual recovery\n"); while (1) { key = VbExKeyboardRead(); - if (key == VB_BUTTON_POWER) + if (key == VB_BUTTON_POWER_SHORT_PRESS) return VBERROR_SHUTDOWN_REQUESTED; else { VbCheckDisplayKey(ctx, cparams, key); @@ -1123,8 +1125,8 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) break; case VB_KEY_UP: case VB_KEY_DOWN: - case VB_BUTTON_VOL_UP: - case VB_BUTTON_VOL_DOWN: + case VB_BUTTON_VOL_UP_SHORT_PRESS: + case VB_BUTTON_VOL_DOWN_LONG_PRESS: /* User cannot use keyboard to enable dev mode. * They need to use the volume buttons from a * trusted source to navigate to the disable os @@ -1147,7 +1149,7 @@ static VbError_t recovery_ui(struct vb2_context *ctx, VbCommonParams *cparams) } vb2_draw_current_screen(ctx, cparams); break; - case VB_BUTTON_POWER: + case VB_BUTTON_POWER_SHORT_PRESS: case '\r': selected = 1; -- cgit v1.2.1