summaryrefslogtreecommitdiff
path: root/common/mkbp_event.c
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2016-07-06 19:37:00 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-07-19 18:33:36 -0700
commit87a071941b89e3f7fd3eb329b682e60b3fbd6c73 (patch)
treed82c7b76924dea16c7c9d4de69b591be3a9ddfe6 /common/mkbp_event.c
parentc0f6ac5e02cdb7a25f593af6dce7b0eea71d996d (diff)
downloadchrome-ec-87a071941b89e3f7fd3eb329b682e60b3fbd6c73.tar.gz
mkbp: Add support for buttons and switches.
Currently, the matrix keyboard protocol does not have support for handling non-matrixed keys. This commit adds support for buttons which do not appear in the keyboard matrix as well as switches. Additionally, the keyboard FIFO is now just a general MKBP events FIFO which MKBP events are free to use. Now, buttons and switches wil join the key matrix event. BUG=chrome-os-partner:54988 BUG=chrome-os-partner:54976 BUG=chromium:626863 BRANCH=None TEST=Flash kevin, and verify that keyboard is still functional. TEST=make -j buildall CQ-DEPEND=CL:358926 Change-Id: If4ada904cbd5d77823a0710d4671484b198c9d91 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/358633 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/mkbp_event.c')
-rw-r--r--common/mkbp_event.c63
1 files changed, 38 insertions, 25 deletions
diff --git a/common/mkbp_event.c b/common/mkbp_event.c
index 60ca19d645..844aaf01f1 100644
--- a/common/mkbp_event.c
+++ b/common/mkbp_event.c
@@ -75,35 +75,49 @@ static int mkbp_get_next_event(struct host_cmd_handler_args *args)
uint8_t *resp = args->response;
const struct mkbp_event_source *src;
- /*
- * Find the next event to service. We do this in a round-robin
- * way to make sure no event gets starved.
- */
- for (i = 0; i < EC_MKBP_EVENT_COUNT; ++i)
- if (event_is_set((last + i) % EC_MKBP_EVENT_COUNT))
- break;
-
- if (i == EC_MKBP_EVENT_COUNT)
- return EC_RES_ERROR;
+ do {
+ /*
+ * Find the next event to service. We do this in a round-robin
+ * way to make sure no event gets starved.
+ */
+ for (i = 0; i < EC_MKBP_EVENT_COUNT; ++i)
+ if (event_is_set((last + i) % EC_MKBP_EVENT_COUNT))
+ break;
- evt = (i + last) % EC_MKBP_EVENT_COUNT;
- last = evt + 1;
+ if (i == EC_MKBP_EVENT_COUNT)
+ return EC_RES_UNAVAILABLE;
- /*
- * Clear the event before retrieving the event data in case the
- * event source wants to send the same event.
- */
- clear_event(evt);
+ evt = (i + last) % EC_MKBP_EVENT_COUNT;
+ last = evt + 1;
- for (src = __mkbp_evt_srcs; src < __mkbp_evt_srcs_end; ++src)
- if (src->event_type == evt)
- break;
+ /*
+ * Clear the event before retrieving the event data in case the
+ * event source wants to send the same event.
+ */
+ clear_event(evt);
- if (src == __mkbp_evt_srcs_end)
- return EC_RES_ERROR;
+ for (src = __mkbp_evt_srcs; src < __mkbp_evt_srcs_end; ++src)
+ if (src->event_type == evt)
+ break;
+
+ if (src == __mkbp_evt_srcs_end)
+ return EC_RES_ERROR;
+
+ resp[0] = evt; /* Event type */
+
+ /*
+ * get_data() can return -EC_ERROR_BUSY which indicates that the
+ * next element in the keyboard FIFO does not match what we were
+ * called with. For example, get_data is expecting a keyboard
+ * matrix, however the next element in the FIFO is a button
+ * event instead. Therefore, we have to service that button
+ * event first.
+ */
+ data_size = src->get_data(resp + 1);
+ if (data_size == -EC_ERROR_BUSY)
+ set_event(evt);
+ } while (data_size == -EC_ERROR_BUSY);
- resp[0] = evt; /* Event type */
- data_size = src->get_data(resp + 1);
if (data_size < 0)
return EC_RES_ERROR;
args->response_size = 1 + data_size;
@@ -116,4 +130,3 @@ static int mkbp_get_next_event(struct host_cmd_handler_args *args)
DECLARE_HOST_COMMAND(EC_CMD_GET_NEXT_EVENT,
mkbp_get_next_event,
EC_VER_MASK(0));
-