diff options
author | Aseda Aboagye <aaboagye@google.com> | 2016-07-06 21:11:01 -0700 |
---|---|---|
committer | Bernie Thompson <bhthompson@chromium.org> | 2016-07-08 01:32:50 +0000 |
commit | 085084e72e38bf024c57219a187737de5c51adcc (patch) | |
tree | 5f6248b75b8a6dfd71e950f4a19028cc9db19850 | |
parent | 8b9791a421c5b0a43da0b016a641af5addb7ab4d (diff) | |
download | chrome-ec-085084e72e38bf024c57219a187737de5c51adcc.tar.gz |
mkbp: Add mkbp_update_button().
This commit adds a call to the general button handler as well as the
power button to update the state of the buttons. Now on a button
change, the EC will send an MKBP button event in the keyboard FIFO.
BUG=chrome-os-partner:54976
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 <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/359027
Reviewed-by: Bernie Thompson <bhthompson@chromium.org>
Tested-by: Bernie Thompson <bhthompson@chromium.org>
-rw-r--r-- | common/button.c | 4 | ||||
-rw-r--r-- | common/keyboard_mkbp.c | 35 | ||||
-rw-r--r-- | common/power_button.c | 6 | ||||
-rw-r--r-- | include/keyboard_mkbp.h | 8 |
4 files changed, 53 insertions, 0 deletions
diff --git a/common/button.c b/common/button.c index 38f5a61403..ce8f344a26 100644 --- a/common/button.c +++ b/common/button.c @@ -85,6 +85,10 @@ static void button_change_deferred(void) keyboard_update_button(buttons[i].type, new_pressed); #endif +#ifdef CONFIG_KEYBOARD_PROTOCOL_MKBP + mkbp_update_button(buttons[i].type, + new_pressed); +#endif } /* Clear the debounce time to stop checking it */ diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c index 418fd71eab..72e939e57d 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" @@ -207,6 +208,40 @@ kb_fifo_push_done: return ret; } +void mkbp_update_button(enum keyboard_button_type button, int is_pressed) +{ + struct mkbp_btn_data d; + static uint8_t buttons; + + switch (button) { + case KEYBOARD_BUTTON_POWER: + buttons &= ~(1 << POWER_BUTTON); + buttons |= (is_pressed << POWER_BUTTON); + break; + + case KEYBOARD_BUTTON_VOLUME_UP: + buttons &= ~(1 << VOL_UP); + buttons |= (is_pressed << VOL_UP); + break; + + case KEYBOARD_BUTTON_VOLUME_DOWN: + buttons &= ~(1 << VOL_DOWN); + buttons |= (is_pressed << VOL_DOWN); + break; + + default: + /* ignored. */ + return; + } + + CPRINTS("buttons: %x", buttons); + + /* Add the new state to the FIFO. */ + memcpy(d.cookie, MKBP_BUTTON_COOKIE, MKBP_BUTTON_COOKIE_LEN); + d.state = buttons; + keyboard_fifo_add((uint8_t *)&d); +} + #ifdef CONFIG_MKBP_EVENT static int get_next_event(uint8_t *out, enum ec_mkbp_event evt) { diff --git a/common/power_button.c b/common/power_button.c index 747be2381e..2f237401b1 100644 --- a/common/power_button.c +++ b/common/power_button.c @@ -5,12 +5,14 @@ /* Power button module for Chrome EC */ +#include "button.h" #include "common.h" #include "console.h" #include "gpio.h" #include "hooks.h" #include "host_command.h" #include "keyboard_scan.h" +#include "keyboard_mkbp.h" #include "lid_switch.h" #include "power_button.h" #include "task.h" @@ -141,6 +143,10 @@ static void power_button_change_deferred(void) /* Notify host if power button has been pressed */ if (new_pressed) host_set_single_event(EC_HOST_EVENT_POWER_BUTTON); + +#ifdef CONFIG_KEYBOARD_PROTOCOL_MKBP + mkbp_update_button(KEYBOARD_BUTTON_POWER, new_pressed); +#endif } DECLARE_DEFERRED(power_button_change_deferred); diff --git a/include/keyboard_mkbp.h b/include/keyboard_mkbp.h index 14b1bb1c34..efea02c38f 100644 --- a/include/keyboard_mkbp.h +++ b/include/keyboard_mkbp.h @@ -62,4 +62,12 @@ void keyboard_send_battery_key(void); static inline void keyboard_send_battery_key(void) { } #endif +/** + * Update the state of non-matrixed buttons. + * + * @param button The button that changed. + * @param is_pressed Whether the button is now pressed. + */ +void mkbp_update_button(enum keyboard_button_type button, int is_pressed); + #endif /* __CROS_EC_KEYBOARD_MKBP_H */ |