From 0325284e17c04dbd03552f2b152cf3e079d7148f Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Wed, 6 Jul 2016 21:11:01 -0700 Subject: [PATCH] mkbp: Add keyboard_update_button(). MKBP can now support buttons, so this commit adds the keyboard_update_button() function which will be used to handle the non-matrixed buttons. BUG=chrome-os-partner:54976 BUG=chromium:626863 BRANCH=None TEST=Flash kevin, press volume and power buttons and verify that keyboard is still functional. TEST=make -j buildall CQ-DEPEND=CL:358633 Change-Id: I1c2d36d2113715cf6bd8c6fa7b26fe9253f6ac9f Signed-off-by: Aseda Aboagye Reviewed-on: https://chromium-review.googlesource.com/358634 Commit-Ready: Aseda Aboagye Tested-by: Aseda Aboagye Reviewed-by: Randall Spangler --- common/button.c | 2 +- common/keyboard_mkbp.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/common/button.c b/common/button.c index 38f5a61403..deace7f2f1 100644 --- a/common/button.c +++ b/common/button.c @@ -81,7 +81,7 @@ static void button_change_deferred(void) CPRINTS("Button '%s' was %s", buttons[i].name, new_pressed ? "pressed" : "released"); -#ifdef HAS_TASK_KEYPROTO +#if defined(HAS_TASK_KEYPROTO) || defined(CONFIG_KEYBOARD_PROTOCOL_MKBP) keyboard_update_button(buttons[i].type, new_pressed); #endif diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c index b461227300..68665ca4db 100644 --- a/common/keyboard_mkbp.c +++ b/common/keyboard_mkbp.c @@ -6,6 +6,7 @@ */ #include "atomic.h" +#include "button.h" #include "chipset.h" #include "common.h" #include "console.h" @@ -213,6 +214,49 @@ static void lid_change(void) DECLARE_HOOK(HOOK_LID_CHANGE, lid_change, HOOK_PRIO_LAST); DECLARE_HOOK(HOOK_INIT, lid_change, HOOK_PRIO_INIT_LID+1); +void keyboard_update_button(enum keyboard_button_type button, int is_pressed) +{ + switch (button) { + case KEYBOARD_BUTTON_POWER: + mkbp_button_state &= ~(1 << EC_MKBP_POWER_BUTTON); + mkbp_button_state |= (is_pressed << EC_MKBP_POWER_BUTTON); + break; + + case KEYBOARD_BUTTON_VOLUME_UP: + mkbp_button_state &= ~(1 << EC_MKBP_VOL_UP); + mkbp_button_state |= (is_pressed << EC_MKBP_VOL_UP); + break; + + case KEYBOARD_BUTTON_VOLUME_DOWN: + mkbp_button_state &= ~(1 << EC_MKBP_VOL_DOWN); + mkbp_button_state |= (is_pressed << EC_MKBP_VOL_DOWN); + break; + + default: + /* ignored. */ + return; + } + + CPRINTS("buttons: %x", mkbp_button_state); + + /* Add the new state to the FIFO. */ + mkbp_fifo_add(EC_MKBP_EVENT_BUTTON, + (const uint8_t *)&mkbp_button_state); +} + +#ifdef CONFIG_POWER_BUTTON +/** + * Handle power button changing state. + */ +static void keyboard_power_button(void) +{ + keyboard_update_button(KEYBOARD_BUTTON_POWER, + power_button_is_pressed()); +} +DECLARE_HOOK(HOOK_POWER_BUTTON_CHANGE, keyboard_power_button, + HOOK_PRIO_DEFAULT); +#endif /* defined(CONFIG_POWER_BUTTON) */ + static int get_next_event(uint8_t *out, enum ec_mkbp_event evt) { uint8_t t = fifo[fifo_start].event_type;