summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorChromeOS Developer <dparker@chromium.org>2014-01-11 11:13:39 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-02-07 04:13:18 +0000
commit86eea83ceee8004c6120a759b35cf88745e548a7 (patch)
tree78791b1e8858015af5683f15bcd659002a612927 /test
parent4015172ed1b8a93350e433deb3399693ff4e00ed (diff)
downloadchrome-ec-86eea83ceee8004c6120a759b35cf88745e548a7.tar.gz
Add support for extra buttons not on the keyboard
BUG=chrome-os-partner:24370 BRANCH=tot TEST=Run button unit test. Orig-Change-Id: I61b4a6624d62831ce0bfdf7a0f36a45349b37f96 Signed-off-by: Dave Parker <dparker@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/184544 Reviewed-by: Randall Spangler <rspangler@chromium.org> (cherry picked from commit f6426cc21c20a4f876cff28b9ce7e3115f0b054a) Change-Id: I4face9bf0797a91ec8bef390093aab8e3d8f97ab Reviewed-on: https://chromium-review.googlesource.com/185243 Tested-by: Randall Spangler <rspangler@chromium.org> Reviewed-by: Bill Richardson <wfrichar@chromium.org> Commit-Queue: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/build.mk3
-rw-r--r--test/button.c180
-rw-r--r--test/button.tasklist17
-rw-r--r--test/test_config.h4
4 files changed, 203 insertions, 1 deletions
diff --git a/test/build.mk b/test/build.mk
index b1efd12134..7ea82cc00c 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -22,9 +22,10 @@ test-list-$(BOARD_SAMUS)=
test-list-host=mutex pingpong utils kb_scan kb_mkbp lid_sw power_button hooks
test-list-host+=thermal flash queue kb_8042 extpwr_gpio console_edit system
test-list-host+=sbs_charging adapter host_command thermal_falco led_spring
-test-list-host+=bklight_lid bklight_passthru interrupt timer_dos
+test-list-host+=bklight_lid bklight_passthru interrupt timer_dos button
adapter-y=adapter.o
+button-y=button.o
bklight_lid-y=bklight_lid.o
bklight_passthru-y=bklight_passthru.o
console_edit-y=console_edit.o
diff --git a/test/button.c b/test/button.c
new file mode 100644
index 0000000000..5f18effb0c
--- /dev/null
+++ b/test/button.c
@@ -0,0 +1,180 @@
+/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * Test non-keyboard buttons.
+*
+ * Using GPIOS and buttons[] defined in board/host/board.c
+ * Volume down is active low with a debounce time of 30 mSec.
+ * Volume up is active high with a debounce time of 60 mSec.
+ *
+ */
+
+#include "button.h"
+#include "common.h"
+#include "console.h"
+#include "gpio.h"
+#include "test_util.h"
+#include "timer.h"
+#include "keyboard_protocol.h"
+
+#define INDEX_VOL_DOWN 0
+#define INDEX_VOL_UP 1
+#define UNCHANGED -1
+
+static const struct button_config *button_vol_down = &buttons[INDEX_VOL_DOWN];
+static const struct button_config *button_vol_up = &buttons[INDEX_VOL_UP];
+
+static int button_state[CONFIG_BUTTON_COUNT];
+
+/*
+ * Callback from the button handling logic.
+ * This is normally implemented by a keyboard protocol handler.
+ */
+void keyboard_update_button(enum keyboard_button_type button, int is_pressed)
+{
+ int i;
+
+ for (i = 0; i < CONFIG_BUTTON_COUNT; i++) {
+ if (buttons[i].type == button) {
+ button_state[i] = is_pressed;
+ break;
+ }
+ }
+}
+
+/* Test pressing a button */
+static int test_button_press(void)
+{
+ gpio_set_level(button_vol_down->gpio, 0);
+ msleep(100);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1);
+
+ return EC_SUCCESS;
+}
+
+/* Test releasing a button */
+static int test_button_release(void)
+{
+ gpio_set_level(button_vol_up->gpio, 1);
+ msleep(100);
+ gpio_set_level(button_vol_up->gpio, 0);
+ msleep(100);
+ TEST_ASSERT(button_state[INDEX_VOL_UP] == 0);
+
+ return EC_SUCCESS;
+}
+
+/* A press shorter than the debounce time should not trigger an update */
+static int test_button_debounce_short_press(void)
+{
+ gpio_set_level(button_vol_down->gpio, 0);
+ msleep(10);
+ gpio_set_level(button_vol_down->gpio, 1);
+ msleep(100);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED);
+
+ return EC_SUCCESS;
+}
+
+/* A short bounce while pressing should still result in a button press */
+static int test_button_debounce_short_bounce(void)
+{
+ gpio_set_level(button_vol_down->gpio, 0);
+ msleep(10);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED);
+ gpio_set_level(button_vol_down->gpio, 1);
+ msleep(10);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED);
+ gpio_set_level(button_vol_down->gpio, 0);
+ msleep(20);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED);
+ msleep(20);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1);
+
+ return EC_SUCCESS;
+}
+
+/* Button level must be stable for the entire debounce interval */
+static int test_button_debounce_stability(void)
+{
+ gpio_set_level(button_vol_down->gpio, 0);
+ msleep(20);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED);
+ gpio_set_level(button_vol_down->gpio, 1);
+ msleep(20);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED);
+ gpio_set_level(button_vol_down->gpio, 0);
+ msleep(20);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED);
+ msleep(20);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1);
+ msleep(60);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1);
+ gpio_set_level(button_vol_down->gpio, 1);
+ msleep(20);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1);
+ msleep(20);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 0);
+ msleep(60);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 0);
+
+ return EC_SUCCESS;
+}
+
+/* Test pressing both buttons at different times */
+static int test_button_press_both(void)
+{
+ gpio_set_level(button_vol_down->gpio, 0);
+ msleep(10);
+ gpio_set_level(button_vol_up->gpio, 1);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED);
+ TEST_ASSERT(button_state[INDEX_VOL_UP] == UNCHANGED);
+ msleep(30);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1);
+ TEST_ASSERT(button_state[INDEX_VOL_UP] == UNCHANGED);
+ msleep(40);
+ TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1);
+ TEST_ASSERT(button_state[INDEX_VOL_UP] == 1);
+
+ return EC_SUCCESS;
+}
+
+static void button_init(void)
+{
+ int i;
+
+ ccprintf("[%T Setting button GPIOs to inactive state.]\n");
+ for (i = 0; i < CONFIG_BUTTON_COUNT; i++)
+ gpio_set_level(buttons[i].gpio,
+ !(buttons[i].flags & BUTTON_FLAG_ACTIVE_HIGH));
+
+ msleep(100);
+ for (i = 0; i < CONFIG_BUTTON_COUNT; i++)
+ button_state[i] = UNCHANGED;
+}
+
+void run_test(void)
+{
+ test_reset();
+
+ button_init();
+ RUN_TEST(test_button_press);
+
+ button_init();
+ RUN_TEST(test_button_release);
+
+ button_init();
+ RUN_TEST(test_button_debounce_short_press);
+
+ button_init();
+ RUN_TEST(test_button_debounce_short_bounce);
+
+ button_init();
+ RUN_TEST(test_button_debounce_stability);
+
+ button_init();
+ RUN_TEST(test_button_press_both);
+
+ test_print_result();
+}
diff --git a/test/button.tasklist b/test/button.tasklist
new file mode 100644
index 0000000000..26cfc53453
--- /dev/null
+++ b/test/button.tasklist
@@ -0,0 +1,17 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * List of enabled tasks in the priority order
+ *
+ * The first one has the lowest priority.
+ *
+ * For each task, use the macro TASK_TEST(n, r, d, s) where :
+ * 'n' in the name of the task
+ * 'r' in the main routine of the task
+ * 'd' in an opaque parameter passed to the routine at startup
+ * 's' is the stack size in bytes; must be a multiple of 8
+ */
+#define CONFIG_TEST_TASK_LIST /* No test task */
diff --git a/test/test_config.h b/test/test_config.h
index d88e71ced9..336ab5443a 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -82,5 +82,9 @@ int board_discharge_on_ac(int enabled);
#define I2C_PORT_MASTER 1
#endif
+#ifdef TEST_BUTTON
+#define CONFIG_BUTTON_COUNT 2
+#endif
+
#endif /* TEST_BUILD */
#endif /* __CROS_EC_TEST_CONFIG_H */