summaryrefslogtreecommitdiff
path: root/common/button.c
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2017-11-15 22:23:00 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-11-17 20:18:38 -0800
commit34a97f50d5275f1fa2f1cb377683c96286b2421d (patch)
tree2ea62dc537426fb252123fb93b3b4f05db5f1443 /common/button.c
parentf587852570770564e8a94b2c3f7ad7d97883c49a (diff)
downloadchrome-ec-34a97f50d5275f1fa2f1cb377683c96286b2421d.tar.gz
buttons: Make buttons[] common.
Nearly every board had a buttons array defined in which its contents had the standard volume buttons. This commit creates a single common buttons array that can contain the standard volume buttons and recovery buttons. If a board has volume up and down buttons, they can simply define CONFIG_VOLUME_BUTTONS and it will populate the buttons array with the standard definition. The buttons are active low and have a 30 ms debounce period. Similiarly, if a board has a dedicated recovery button, defining CONFIG_DEDICATED_RECOVERY_BUTTON will also populate the buttons array with a recovery button. BUG=chromium:783371 BRANCH=None TEST=make -j buildall. TEST=Flash a device with CONFIG_VOLUME_BUTTONS, verify pressing volume buttons still work. Change-Id: Ie5d63670ca4c6b146ec8ffb64d40ea9ce437b913 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/773794 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'common/button.c')
-rw-r--r--common/button.c43
1 files changed, 37 insertions, 6 deletions
diff --git a/common/button.c b/common/button.c
index 72fbb4a6d6..306cefa09f 100644
--- a/common/button.c
+++ b/common/button.c
@@ -8,6 +8,7 @@
#include "button.h"
#include "chipset.h"
#include "common.h"
+#include "compile_time_macros.h"
#include "console.h"
#include "gpio.h"
#include "host_command.h"
@@ -28,7 +29,7 @@ struct button_state_t {
int debounced_pressed;
};
-static struct button_state_t __bss_slow state[CONFIG_BUTTON_COUNT];
+static struct button_state_t __bss_slow state[BUTTON_COUNT];
static uint64_t __bss_slow next_deferred_time;
@@ -172,7 +173,7 @@ void button_init(void)
CPRINTS("init buttons");
next_deferred_time = 0;
- for (i = 0; i < CONFIG_BUTTON_COUNT; i++) {
+ for (i = 0; i < BUTTON_COUNT; i++) {
state[i].debounced_pressed = raw_button_pressed(&buttons[i]);
state[i].debounce_time = 0;
gpio_enable_interrupt(buttons[i].gpio);
@@ -207,7 +208,7 @@ static void button_change_deferred(void)
uint64_t soonest_debounce_time = 0;
uint64_t time_now = get_time().val;
- for (i = 0; i < CONFIG_BUTTON_COUNT; i++) {
+ for (i = 0; i < BUTTON_COUNT; i++) {
/* Skip this button if we are not waiting to debounce */
if (state[i].debounce_time == 0)
continue;
@@ -263,7 +264,7 @@ void button_interrupt(enum gpio_signal signal)
int i;
uint64_t time_now = get_time().val;
- for (i = 0; i < CONFIG_BUTTON_COUNT; i++) {
+ for (i = 0; i < BUTTON_COUNT; i++) {
if (buttons[i].gpio != signal)
continue;
@@ -283,7 +284,7 @@ static int button_present(enum keyboard_button_type type)
{
int i;
- for (i = 0; i < CONFIG_BUTTON_COUNT; i++)
+ for (i = 0; i < BUTTON_COUNT; i++)
if (buttons[i].type == type)
break;
@@ -315,7 +316,7 @@ static int console_command_button(int argc, char **argv)
else
return EC_ERROR_PARAM1;
- if (button == CONFIG_BUTTON_COUNT)
+ if (button == BUTTON_COUNT)
return EC_ERROR_PARAM1;
if (argc > 2) {
@@ -677,3 +678,33 @@ DECLARE_HOOK(HOOK_TICK, debug_led_tick, HOOK_PRIO_DEFAULT);
#endif /* !CONFIG_DEDICATED_RECOVERY_BUTTON */
#endif /* CONFIG_EMULATED_SYSRQ */
+
+const struct button_config buttons[BUTTON_COUNT] = {
+#ifdef CONFIG_VOLUME_BUTTONS
+ [BUTTON_VOLUME_UP] = {
+ .name = "Volume Up",
+ .type = KEYBOARD_BUTTON_VOLUME_UP,
+ .gpio = GPIO_VOLUME_UP_L,
+ .debounce_us = 30 * MSEC,
+ .flags = 0,
+ },
+
+ [BUTTON_VOLUME_DOWN] = {
+ .name = "Volume Down",
+ .type = KEYBOARD_BUTTON_VOLUME_DOWN,
+ .gpio = GPIO_VOLUME_DOWN_L,
+ .debounce_us = 30 * MSEC,
+ .flags = 0,
+ },
+#endif /* defined(CONFIG_VOLUME_BUTTONS) */
+
+#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON
+ [BUTTON_RECOVERY] = {
+ .name = "Recovery",
+ .type = KEYBOARD_BUTTON_RECOVERY,
+ .gpio = GPIO_RECOVERY_L,
+ .debounce_us = 30 * MSEC,
+ .flags = 0,
+ }
+#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON) */
+};