From 34a97f50d5275f1fa2f1cb377683c96286b2421d Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Wed, 15 Nov 2017 22:23:00 -0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/773794 Commit-Ready: Aseda Aboagye Tested-by: Aseda Aboagye Reviewed-by: Daisuke Nojiri Reviewed-by: Shawn N --- board/coral/board.c | 7 ------ board/coral/board.h | 4 ++- board/eve/board.c | 7 ------ board/eve/board.h | 2 +- board/fizz/board.c | 10 -------- board/fizz/board.h | 6 ----- board/glados/board.c | 7 ------ board/glados/board.h | 2 +- board/glkrvp/board.c | 18 -------------- board/glkrvp/board.h | 4 ++- board/grunt/board.c | 7 ------ board/grunt/board.h | 5 +++- board/host/board.c | 10 -------- board/host/gpio.inc | 4 +-- board/kahlee/board.h | 1 - board/kevin/board.c | 7 ------ board/kevin/board.h | 2 +- board/nautilus/board.c | 7 ------ board/nautilus/board.h | 8 +----- board/nefario/board.c | 7 ------ board/nefario/board.h | 2 +- board/poppy/board.c | 7 ------ board/poppy/board.h | 8 +----- board/rainier/board.c | 7 ------ board/rainier/board.h | 8 +----- board/reef/board.c | 7 ------ board/reef/board.h | 4 ++- board/reef_it8320/board.c | 7 ------ board/reef_it8320/board.h | 4 ++- board/rowan/board.c | 7 ------ board/rowan/board.h | 8 +----- board/scarlet/board.c | 7 ------ board/scarlet/board.h | 8 +----- board/strago/board.c | 8 ------ board/strago/board.h | 4 ++- board/wheatley/board.c | 7 ------ board/wheatley/board.h | 2 +- common/build.mk | 3 ++- common/button.c | 43 +++++++++++++++++++++++++++----- common/keyboard_mkbp.c | 20 +++++++-------- common/main.c | 4 +-- include/button.h | 15 ++++++++--- include/config.h | 12 ++++----- test/button.c | 63 +++++++++++++++++++++++------------------------ test/test_config.h | 2 +- 45 files changed, 132 insertions(+), 260 deletions(-) diff --git a/board/coral/board.c b/board/coral/board.c index 43ea4fca91..7ab358e912 100644 --- a/board/coral/board.c +++ b/board/coral/board.c @@ -501,13 +501,6 @@ const struct temp_sensor_t temp_sensors[] = { }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_EC_VOLDN_BTN_ODL, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_EC_VOLUP_BTN_ODL, - 30 * MSEC, 0}, -}; - /* Called by APL power state machine when transitioning from G3 to S5 */ static void chipset_pre_init(void) { diff --git a/board/coral/board.h b/board/coral/board.h index 3706cd4ae8..d10081f0a0 100644 --- a/board/coral/board.h +++ b/board/coral/board.h @@ -120,7 +120,6 @@ #define CONFIG_ADC #define CONFIG_BOARD_VERSION #define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_EXTPOWER_GPIO #undef CONFIG_EXTPOWER_DEBOUNCE_MS #define CONFIG_EXTPOWER_DEBOUNCE_MS 1000 @@ -148,6 +147,9 @@ #define CONFIG_SCI_GPIO GPIO_PCH_SCI_L #define CONFIG_UART_HOST 0 #define CONFIG_VBOOT_HASH +#define CONFIG_VOLUME_BUTTONS +#define GPIO_VOLUME_DOWN_L GPIO_EC_VOLDN_BTN_ODL +#define GPIO_VOLUME_UP_L GPIO_EC_VOLUP_BTN_ODL #define CONFIG_BACKLIGHT_LID #define CONFIG_WIRELESS #define CONFIG_WIRELESS_SUSPEND EC_WIRELESS_SWITCH_WLAN_POWER diff --git a/board/eve/board.c b/board/eve/board.c index f580c30651..243bc3dc21 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -346,13 +346,6 @@ const struct temp_sensor_t temp_sensors[] = { }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_VOLUME_DOWN_L, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_VOLUME_UP_L, - 30 * MSEC, 0}, -}; - static void board_pmic_init(void) { if (system_jumped_to_this_image()) diff --git a/board/eve/board.h b/board/eve/board.h index 6182e7c2ac..12e791944f 100644 --- a/board/eve/board.h +++ b/board/eve/board.h @@ -27,7 +27,6 @@ #define CONFIG_BACKLIGHT_LID #define CONFIG_BOARD_VERSION #define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_DEVICE_EVENT #define CONFIG_DPTF #define CONFIG_DPTF_DEVICE_ORIENTATION @@ -46,6 +45,7 @@ #define CONFIG_SPI_FLASH_W25X40 #define CONFIG_UART_HOST 0 #define CONFIG_VBOOT_HASH +#define CONFIG_VOLUME_BUTTONS #define CONFIG_VSTORE #define CONFIG_VSTORE_SLOT_COUNT 1 #define CONFIG_WATCHDOG_HELP diff --git a/board/fizz/board.c b/board/fizz/board.c index 918d38892d..8e345c1ad4 100644 --- a/board/fizz/board.c +++ b/board/fizz/board.c @@ -498,16 +498,6 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, } } -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - [BUTTON_RECOVERY] = { - .name = "Recovery", - .type = KEYBOARD_BUTTON_RECOVERY, - .gpio = GPIO_RECOVERY_L, - .debounce_us = 30 * MSEC, - .flags = 0, - }, -}; - const struct button_config *recovery_buttons[] = { &buttons[BUTTON_RECOVERY], }; diff --git a/board/fizz/board.h b/board/fizz/board.h index 93dce5bd49..33b4ee1741 100644 --- a/board/fizz/board.h +++ b/board/fizz/board.h @@ -18,7 +18,6 @@ /* EC */ #define CONFIG_ADC #define CONFIG_BOARD_VERSION -#define CONFIG_BUTTON_COUNT 1 #define CONFIG_BUTTON_RECOVERY #define CONFIG_DEDICATED_RECOVERY_BUTTON #define CONFIG_EMULATED_SYSRQ @@ -202,11 +201,6 @@ enum adc_channel { ADC_CH_COUNT }; -enum button { - BUTTON_RECOVERY = 0, - BUTTON_COUNT -}; - enum pwm_channel { PWM_CH_LED_RED, PWM_CH_LED_GREEN, diff --git a/board/glados/board.c b/board/glados/board.c index e435cad8eb..1914a615ab 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -202,13 +202,6 @@ struct als_t als[] = { }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_VOLUME_DOWN_L, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_VOLUME_UP_L, - 30 * MSEC, 0}, -}; - static void board_pmic_init(void) { /* No need to re-init PMIC since settings are sticky across sysjump */ diff --git a/board/glados/board.h b/board/glados/board.h index 4ed3186b06..24f1ac1b57 100644 --- a/board/glados/board.h +++ b/board/glados/board.h @@ -23,7 +23,6 @@ #define CONFIG_BATTERY_PRESENT_GPIO GPIO_BAT_PRESENT_L #define CONFIG_BATTERY_SMART #define CONFIG_BOARD_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_CHARGE_MANAGER #define CONFIG_CHARGE_RAMP_HW @@ -88,6 +87,7 @@ #define CONFIG_USBC_VCONN #define CONFIG_USBC_VCONN_SWAP #define CONFIG_VBOOT_HASH +#define CONFIG_VOLUME_BUTTONS #define CONFIG_SPI_FLASH_PORT 1 #define CONFIG_SPI_FLASH diff --git a/board/glkrvp/board.c b/board/glkrvp/board.c index 9c5f22eb58..1038811f60 100644 --- a/board/glkrvp/board.c +++ b/board/glkrvp/board.c @@ -74,24 +74,6 @@ const enum gpio_signal hibernate_wake_pins[] = { }; const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - { - .name = "Volume Up", - .type = KEYBOARD_BUTTON_VOLUME_UP, - .gpio = GPIO_EC_VOLUP_BTN_ODL, - .debounce_us = 30 * MSEC, - .flags = 0, - }, - { - .name = "Volume Down", - .type = KEYBOARD_BUTTON_VOLUME_DOWN, - .gpio = GPIO_EC_VOLDN_BTN_ODL, - .debounce_us = 30 * MSEC, - .flags = 0, - }, -}; -BUILD_ASSERT(ARRAY_SIZE(buttons) == CONFIG_BUTTON_COUNT); - /* Called by APL power state machine when transitioning from G3 to S5 */ static void chipset_pre_init(void) { diff --git a/board/glkrvp/board.h b/board/glkrvp/board.h index 3ff9fca52f..2115be6d3b 100644 --- a/board/glkrvp/board.h +++ b/board/glkrvp/board.h @@ -85,7 +85,9 @@ /* EC */ #define CONFIG_BOARD_VERSION #define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 +#define CONFIG_VOLUME_BUTTONS +#define GPIO_VOLUME_UP_L GPIO_EC_VOLUP_BTN_ODL +#define GPIO_VOLUME_DOWN_L GPIO_EC_VOLDN_BTN_ODL #define CONFIG_WP_ALWAYS #define CONFIG_I2C #define CONFIG_I2C_MASTER diff --git a/board/grunt/board.c b/board/grunt/board.c index a8755e08c2..68d765dab4 100644 --- a/board/grunt/board.c +++ b/board/grunt/board.c @@ -72,13 +72,6 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_VOLDN_BTN_ODL, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_VOLUP_BTN_ODL, - 30 * MSEC, 0}, -}; - /* Keyboard scan setting */ struct keyboard_scan_config keyscan_config = { /* Extra delay when KSO2 is tied to Cr50. */ diff --git a/board/grunt/board.h b/board/grunt/board.h index bb15a7e0bf..8e20aaddeb 100644 --- a/board/grunt/board.h +++ b/board/grunt/board.h @@ -29,7 +29,6 @@ #define CONFIG_LPC #define CONFIG_BOARD_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_CHIPSET_STONEY #define CONFIG_CHIPSET_RESET_HOOK @@ -46,6 +45,10 @@ #define CONFIG_KEYBOARD_COL2_INVERTED #define CONFIG_KEYBOARD_PROTOCOL_8042 +#define CONFIG_VOLUME_BUTTONS +#define GPIO_VOLUME_DOWN_L GPIO_VOLDN_BTN_ODL +#define GPIO_VOLUME_UP_L GPIO_VOLUP_BTN_ODL + #define I2C_PORT_BATTERY I2C_PORT_POWER #define I2C_PORT_POWER NPCX_I2C_PORT0_0 #define I2C_PORT_TCPC0 NPCX_I2C_PORT1_0 diff --git a/board/host/board.c b/board/host/board.c index b29f6e9230..e3183fa874 100644 --- a/board/host/board.c +++ b/board/host/board.c @@ -45,16 +45,6 @@ test_mockable void button_interrupt(enum gpio_signal signal) { }; -#ifdef CONFIG_BUTTON_COUNT -const struct button_config buttons[] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_BUTTON_VOLUME_DOWN_L, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_BUTTON_VOLUME_UP, - 60 * MSEC, BUTTON_FLAG_ACTIVE_HIGH}, -}; -BUILD_ASSERT(ARRAY_SIZE(buttons) == CONFIG_BUTTON_COUNT); -#endif - #ifdef CONFIG_I2C /* I2C ports */ const struct i2c_port_t i2c_ports[] = { diff --git a/board/host/gpio.inc b/board/host/gpio.inc index 7695a6021d..73bd6c0252 100644 --- a/board/host/gpio.inc +++ b/board/host/gpio.inc @@ -11,8 +11,8 @@ GPIO_INT(LID_OPEN, PIN(0, 0), GPIO_INT_BOTH, lid_interrupt) GPIO_INT(POWER_BUTTON_L, PIN(0, 1), GPIO_INT_BOTH, power_button_interrupt) GPIO_INT(AC_PRESENT, PIN(0, 2), GPIO_INT_BOTH, extpower_interrupt) -GPIO_INT(BUTTON_VOLUME_DOWN_L, PIN(0, 3), GPIO_INT_BOTH, button_interrupt) -GPIO_INT(BUTTON_VOLUME_UP, PIN(0, 4), GPIO_INT_BOTH, button_interrupt) +GPIO_INT(VOLUME_DOWN_L, PIN(0, 3), GPIO_INT_BOTH, button_interrupt) +GPIO_INT(VOLUME_UP_L, PIN(0, 4), GPIO_INT_BOTH, button_interrupt) GPIO_INT(CHARGE_DONE, PIN(0, 5), GPIO_INT_BOTH, inductive_charging_interrupt) GPIO(EC_INT_L, PIN(0, 6), 0) diff --git a/board/kahlee/board.h b/board/kahlee/board.h index ab028983b4..d43356c8af 100644 --- a/board/kahlee/board.h +++ b/board/kahlee/board.h @@ -97,7 +97,6 @@ #define CONFIG_ADC #define CONFIG_BOARD_VERSION #define CONFIG_BOARD_SPECIFIC_VERSION -#undef CONFIG_BUTTON_COUNT #define CONFIG_EXTPOWER_GPIO #undef CONFIG_EXTPOWER_DEBOUNCE_MS #define CONFIG_EXTPOWER_DEBOUNCE_MS 1000 diff --git a/board/kevin/board.c b/board/kevin/board.c index 6dadcd5c67..c7b0442c65 100644 --- a/board/kevin/board.c +++ b/board/kevin/board.c @@ -163,13 +163,6 @@ struct keyboard_scan_config keyscan_config = { }, }; -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_VOLUME_DOWN_L, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_VOLUME_UP_L, - 30 * MSEC, 0}, -}; - const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { {I2C_PORT_TCPC0, FUSB302_I2C_SLAVE_ADDR, &fusb302_tcpm_drv}, {I2C_PORT_TCPC1, FUSB302_I2C_SLAVE_ADDR, &fusb302_tcpm_drv}, diff --git a/board/kevin/board.h b/board/kevin/board.h index 8b0eac980f..d0306c8c26 100644 --- a/board/kevin/board.h +++ b/board/kevin/board.h @@ -48,7 +48,6 @@ /* Optional features */ #define CONFIG_BOARD_VERSION #define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_FLASH_SIZE 0x00080000 /* 512KB spi flash */ #define CONFIG_HOST_COMMAND_STATUS #define CONFIG_HOSTCMD_SECTION_SORTED /* Host commands are sorted. */ @@ -63,6 +62,7 @@ #define CONFIG_POWER_BUTTON #define CONFIG_POWER_TRACK_HOST_SLEEP_STATE #define CONFIG_VBOOT_HASH +#define CONFIG_VOLUME_BUTTONS #define CONFIG_CHARGER #define CONFIG_CHARGER_BD9995X diff --git a/board/nautilus/board.c b/board/nautilus/board.c index 2f40113d6f..3bacf3a0e7 100644 --- a/board/nautilus/board.c +++ b/board/nautilus/board.c @@ -470,13 +470,6 @@ struct als_t als[] = { }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - [BUTTON_VOLUME_DOWN] = {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, - GPIO_VOLUME_DOWN_L, 30 * MSEC, 0}, - [BUTTON_VOLUME_UP] = {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, - GPIO_VOLUME_UP_L, 30 * MSEC, 0}, -}; - const struct button_config *recovery_buttons[] = { &buttons[BUTTON_VOLUME_DOWN], &buttons[BUTTON_VOLUME_UP], diff --git a/board/nautilus/board.h b/board/nautilus/board.h index afd0f45b11..a85f1d2aa3 100644 --- a/board/nautilus/board.h +++ b/board/nautilus/board.h @@ -18,7 +18,6 @@ #define CONFIG_ADC #define CONFIG_BACKLIGHT_LID #define CONFIG_BOARD_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_BUTTON_RECOVERY #define CONFIG_CASE_CLOSED_DEBUG_EXTERNAL #define CONFIG_DPTF @@ -38,6 +37,7 @@ #define CONFIG_UART_HOST 0 #define CONFIG_VBOOT_HASH #define CONFIG_SHA256_UNROLLED +#define CONFIG_VOLUME_BUTTONS #define CONFIG_VSTORE #define CONFIG_VSTORE_SLOT_COUNT 1 #define CONFIG_WATCHDOG_HELP @@ -228,12 +228,6 @@ enum adc_channel { ADC_CH_COUNT }; -enum button { - BUTTON_VOLUME_DOWN = 0, - BUTTON_VOLUME_UP = 1, - BUTTON_COUNT -}; - /* TODO(crosbug.com/p/61098): Verify the numbers below. */ /* * delay to turn on the power supply max is ~16ms. diff --git a/board/nefario/board.c b/board/nefario/board.c index c31cb2dc7d..71c53e2e0e 100644 --- a/board/nefario/board.c +++ b/board/nefario/board.c @@ -145,13 +145,6 @@ struct keyboard_scan_config keyscan_config = { }, }; -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_VOLUME_DOWN_L, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_VOLUME_UP_L, - 30 * MSEC, 0}, -}; - const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { {I2C_PORT_TCPC0, FUSB302_I2C_SLAVE_ADDR, &fusb302_tcpm_drv}, {I2C_PORT_TCPC1, FUSB302_I2C_SLAVE_ADDR, &fusb302_tcpm_drv}, diff --git a/board/nefario/board.h b/board/nefario/board.h index f6d24893dd..12f3816d56 100644 --- a/board/nefario/board.h +++ b/board/nefario/board.h @@ -51,7 +51,6 @@ /* Optional features */ #define CONFIG_BOARD_VERSION #define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_FLASH_SIZE 0x00080000 /* 512KB spi flash */ #define CONFIG_HOST_COMMAND_STATUS /* By default, set hcdebug to off */ @@ -66,6 +65,7 @@ #define CONFIG_POWER_TRACK_HOST_SLEEP_STATE #define CONFIG_SOFTWARE_PANIC #define CONFIG_VBOOT_HASH +#define CONFIG_VOLUME_BUTTONS #define CONFIG_CHARGER #define CONFIG_CHARGER_BD9995X diff --git a/board/poppy/board.c b/board/poppy/board.c index 4baf488a85..a270e985e7 100644 --- a/board/poppy/board.c +++ b/board/poppy/board.c @@ -545,13 +545,6 @@ struct als_t als[] = { }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - [BUTTON_VOLUME_DOWN] = {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, - GPIO_VOLUME_DOWN_L, 30 * MSEC, 0}, - [BUTTON_VOLUME_UP] = {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, - GPIO_VOLUME_UP_L, 30 * MSEC, 0}, -}; - const struct button_config *recovery_buttons[] = { &buttons[BUTTON_VOLUME_DOWN], &buttons[BUTTON_VOLUME_UP], diff --git a/board/poppy/board.h b/board/poppy/board.h index 03076417d2..245f8027d0 100644 --- a/board/poppy/board.h +++ b/board/poppy/board.h @@ -19,7 +19,6 @@ #define CONFIG_BACKLIGHT_LID #define CONFIG_BOARD_VERSION #define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_BUTTON_RECOVERY #define CONFIG_DPTF #define CONFIG_EMULATED_SYSRQ @@ -37,6 +36,7 @@ #define CONFIG_UART_HOST 0 #define CONFIG_VBOOT_HASH #define CONFIG_SHA256_UNROLLED +#define CONFIG_VOLUME_BUTTONS #define CONFIG_VSTORE #define CONFIG_VSTORE_SLOT_COUNT 1 #define CONFIG_WATCHDOG_HELP @@ -232,12 +232,6 @@ enum adc_channel { ADC_CH_COUNT }; -enum button { - BUTTON_VOLUME_DOWN = 0, - BUTTON_VOLUME_UP = 1, - BUTTON_COUNT -}; - /* TODO(crosbug.com/p/61098): Verify the numbers below. */ /* * delay to turn on the power supply max is ~16ms. diff --git a/board/rainier/board.c b/board/rainier/board.c index 237cfcca12..b8c8627983 100644 --- a/board/rainier/board.c +++ b/board/rainier/board.c @@ -129,13 +129,6 @@ const enum gpio_signal hibernate_wake_pins[] = { const int hibernate_wake_pins_used = ARRAY_SIZE(hibernate_wake_pins); /******************************************************************************/ -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - [BUTTON_VOLUME_DOWN] = {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, - GPIO_VOLUME_DOWN_L, 30 * MSEC, 0}, - [BUTTON_VOLUME_UP] = {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, - GPIO_VOLUME_UP_L, 30 * MSEC, 0}, -}; - const struct button_config *recovery_buttons[] = { &buttons[BUTTON_VOLUME_DOWN], &buttons[BUTTON_VOLUME_UP], diff --git a/board/rainier/board.h b/board/rainier/board.h index 8c67257695..4b6e4fb97a 100644 --- a/board/rainier/board.h +++ b/board/rainier/board.h @@ -43,7 +43,6 @@ #define CONFIG_BOARD_PRE_INIT #define CONFIG_BOARD_SPECIFIC_VERSION #define CONFIG_BOARD_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_BUTTON_RECOVERY #define CONFIG_CHARGER_ILIM_PIN_DISABLED #define CONFIG_FORCE_CONSOLE_RESUME @@ -59,6 +58,7 @@ #define CONFIG_POWER_TRACK_HOST_SLEEP_STATE #define CONFIG_SOFTWARE_PANIC #define CONFIG_VBOOT_HASH +#define CONFIG_VOLUME_BUTTONS #define CONFIG_USB_MUX_VIRTUAL @@ -142,12 +142,6 @@ enum adc_channel { ADC_CH_COUNT }; -enum button { - BUTTON_VOLUME_DOWN = 0, - BUTTON_VOLUME_UP = 1, - BUTTON_COUNT -}; - /* power signal definitions */ enum power_signal { PP1250_S3_PWR_GOOD = 0, diff --git a/board/reef/board.c b/board/reef/board.c index 3e0becb255..43bee25318 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -496,13 +496,6 @@ const struct temp_sensor_t temp_sensors[] = { }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_EC_VOLDN_BTN_ODL, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_EC_VOLUP_BTN_ODL, - 30 * MSEC, 0}, -}; - /* Called by APL power state machine when transitioning from G3 to S5 */ static void chipset_pre_init(void) { diff --git a/board/reef/board.h b/board/reef/board.h index 2825bad90e..f67994c2b8 100644 --- a/board/reef/board.h +++ b/board/reef/board.h @@ -117,7 +117,6 @@ #define CONFIG_ADC #define CONFIG_BOARD_VERSION #define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_EXTPOWER_GPIO #undef CONFIG_EXTPOWER_DEBOUNCE_MS #define CONFIG_EXTPOWER_DEBOUNCE_MS 1000 @@ -141,6 +140,9 @@ #define CONFIG_DPTF_DEVICE_ORIENTATION #define CONFIG_SCI_GPIO GPIO_PCH_SCI_L #define CONFIG_UART_HOST 0 +#define CONFIG_VOLUME_BUTTONS +#define GPIO_VOLUME_DOWN_L GPIO_EC_VOLDN_BTN_ODL +#define GPIO_VOLUME_UP_L GPIO_EC_VOLUP_BTN_ODL #define CONFIG_VBOOT_HASH #define CONFIG_BACKLIGHT_LID #define CONFIG_WIRELESS diff --git a/board/reef_it8320/board.c b/board/reef_it8320/board.c index c8eeb2b8ef..3cb1d49afc 100644 --- a/board/reef_it8320/board.c +++ b/board/reef_it8320/board.c @@ -277,13 +277,6 @@ const struct temp_sensor_t temp_sensors[] = { }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_EC_VOLDN_BTN_ODL, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_EC_VOLUP_BTN_ODL, - 30 * MSEC, 0}, -}; - /* Called by APL power state machine when transitioning from G3 to S5 */ static void chipset_pre_init(void) { diff --git a/board/reef_it8320/board.h b/board/reef_it8320/board.h index 0d86f37e4f..0fe238d043 100644 --- a/board/reef_it8320/board.h +++ b/board/reef_it8320/board.h @@ -101,7 +101,6 @@ #define CONFIG_ADC #define CONFIG_BOARD_VERSION #define CONFIG_BOARD_SPECIFIC_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_EXTPOWER_GPIO #undef CONFIG_EXTPOWER_DEBOUNCE_MS #define CONFIG_EXTPOWER_DEBOUNCE_MS 1000 @@ -121,6 +120,9 @@ #define CONFIG_DPTF_DEVICE_ORIENTATION #define CONFIG_SCI_GPIO GPIO_PCH_SCI_L #define CONFIG_VBOOT_HASH +#define CONFIG_VOLUME_BUTTONS +#define GPIO_VOLUME_DOWN_L GPIO_EC_VOLDN_BTN_ODL +#define GPIO_VOLUME_UP_L GPIO_EC_VOLUP_BTN_ODL #define CONFIG_BACKLIGHT_LID #define CONFIG_WIRELESS #define CONFIG_WIRELESS_SUSPEND EC_WIRELESS_SWITCH_WLAN_POWER diff --git a/board/rowan/board.c b/board/rowan/board.c index 31e0da5cea..35864a2493 100644 --- a/board/rowan/board.c +++ b/board/rowan/board.c @@ -156,13 +156,6 @@ const struct temp_sensor_t temp_sensors[] = { }; BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - [BUTTON_VOLUME_DOWN] = {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, - GPIO_VOLUME_DOWN_L, 30 * MSEC, 0}, - [BUTTON_VOLUME_UP] = {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, - GPIO_VOLUME_UP_L, 30 * MSEC, 0}, -}; - const struct button_config *recovery_buttons[] = { &buttons[BUTTON_VOLUME_DOWN], &buttons[BUTTON_VOLUME_UP], diff --git a/board/rowan/board.h b/board/rowan/board.h index 12d4e382c8..82aabcdf73 100644 --- a/board/rowan/board.h +++ b/board/rowan/board.h @@ -17,8 +17,8 @@ #define CONFIG_CMD_GPIO_EXTENDED /* Button */ -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_BUTTON_RECOVERY +#define CONFIG_VOLUME_BUTTONS /* Accelero meter and gyro sensor */ #define CONFIG_ACCELGYRO_BMI160 @@ -185,12 +185,6 @@ enum adc_channel { ADC_CH_COUNT }; -enum button { - BUTTON_VOLUME_DOWN = 0, - BUTTON_VOLUME_UP = 1, - BUTTON_COUNT -}; - enum temp_sensor_id { #ifdef CONFIG_TEMP_SENSOR_TMP432 /* TMP432 local and remote sensors */ diff --git a/board/scarlet/board.c b/board/scarlet/board.c index 558ece8540..5a9e7db8ee 100644 --- a/board/scarlet/board.c +++ b/board/scarlet/board.c @@ -123,13 +123,6 @@ const struct spi_device_t spi_devices[] = { const unsigned int spi_devices_used = ARRAY_SIZE(spi_devices); /******************************************************************************/ -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - [BUTTON_VOLUME_DOWN] = {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, - GPIO_VOLUME_DOWN_L, 30 * MSEC, 0}, - [BUTTON_VOLUME_UP] = {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, - GPIO_VOLUME_UP_L, 30 * MSEC, 0}, -}; - const struct button_config *recovery_buttons[] = { &buttons[BUTTON_VOLUME_DOWN], &buttons[BUTTON_VOLUME_UP], diff --git a/board/scarlet/board.h b/board/scarlet/board.h index 1d45efddb0..c729de8650 100644 --- a/board/scarlet/board.h +++ b/board/scarlet/board.h @@ -46,7 +46,6 @@ #define CONFIG_BOARD_PRE_INIT #define CONFIG_BOARD_SPECIFIC_VERSION #define CONFIG_BOARD_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_BUTTON_RECOVERY #define CONFIG_CHARGER_ILIM_PIN_DISABLED #define CONFIG_FORCE_CONSOLE_RESUME @@ -62,6 +61,7 @@ #define CONFIG_POWER_TRACK_HOST_SLEEP_STATE #define CONFIG_SOFTWARE_PANIC #define CONFIG_VBOOT_HASH +#define CONFIG_VOLUME_BUTTONS #define CONFIG_CHARGER #define CONFIG_CHARGER_RT9467 @@ -182,12 +182,6 @@ enum adc_channel { ADC_CH_COUNT }; -enum button { - BUTTON_VOLUME_DOWN = 0, - BUTTON_VOLUME_UP = 1, - BUTTON_COUNT -}; - /* power signal definitions */ enum power_signal { PP1250_S3_PWR_GOOD = 0, diff --git a/board/strago/board.c b/board/strago/board.c index 98c9c2618c..38ad6f8292 100644 --- a/board/strago/board.c +++ b/board/strago/board.c @@ -167,14 +167,6 @@ struct als_t als[] = { }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); -const struct button_config buttons[] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_VOLUME_DOWN, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_VOLUME_UP, - 30 * MSEC, 0}, -}; -BUILD_ASSERT(ARRAY_SIZE(buttons) == CONFIG_BUTTON_COUNT); - /** * Reset PD MCU */ diff --git a/board/strago/board.h b/board/strago/board.h index f13e650008..7ca153ce07 100644 --- a/board/strago/board.h +++ b/board/strago/board.h @@ -94,7 +94,9 @@ #define CONFIG_LID_ANGLE_SENSOR_LID 1 /* Number of buttons */ -#define CONFIG_BUTTON_COUNT 2 +#define CONFIG_VOLUME_BUTTONS +#define GPIO_VOLUME_DOWN_L GPIO_VOLUME_DOWN +#define GPIO_VOLUME_UP_L GPIO_VOLUME_UP #define CONFIG_ADC diff --git a/board/wheatley/board.c b/board/wheatley/board.c index 99d83d29f9..f67e56f45f 100644 --- a/board/wheatley/board.c +++ b/board/wheatley/board.c @@ -202,13 +202,6 @@ struct als_t als[] = { }; BUILD_ASSERT(ARRAY_SIZE(als) == ALS_COUNT); -const struct button_config buttons[CONFIG_BUTTON_COUNT] = { - {"Volume Down", KEYBOARD_BUTTON_VOLUME_DOWN, GPIO_VOLUME_DOWN_L, - 30 * MSEC, 0}, - {"Volume Up", KEYBOARD_BUTTON_VOLUME_UP, GPIO_VOLUME_UP_L, - 30 * MSEC, 0}, -}; - static void board_pmic_init(void) { /* No need to re-init PMIC since settings are sticky across sysjump */ diff --git a/board/wheatley/board.h b/board/wheatley/board.h index 4c5fdbd55f..eb2e579608 100644 --- a/board/wheatley/board.h +++ b/board/wheatley/board.h @@ -17,7 +17,6 @@ #define CONFIG_BATTERY_PRESENT_GPIO GPIO_BAT_PRESENT_L #define CONFIG_BATTERY_SMART #define CONFIG_BOARD_VERSION -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_CHARGE_MANAGER #define CONFIG_CHARGER @@ -87,6 +86,7 @@ #define CONFIG_USBC_VCONN #define CONFIG_USBC_VCONN_SWAP #define CONFIG_VBOOT_HASH +#define CONFIG_VOLUME_BUTTONS #define CONFIG_FLASH_SIZE 0x80000 /* 512 KB Flash used for EC */ #define CONFIG_SPI_FLASH_REGS diff --git a/common/build.mk b/common/build.mk index 57eb0c9d82..c0ea4bbd5f 100644 --- a/common/build.mk +++ b/common/build.mk @@ -24,7 +24,6 @@ common-$(CONFIG_BASE32)+=base32.o common-$(CONFIG_BATTERY)+=battery.o common-$(CONFIG_BLUETOOTH_LE)+=bluetooth_le.o common-$(CONFIG_BLUETOOTH_LE_STACK)+=btle_hci_controller.o btle_ll.o -common-$(CONFIG_BUTTON_COUNT)+=button.o common-$(CONFIG_CAPSENSE)+=capsense.o common-$(CONFIG_CASE_CLOSED_DEBUG_V1)+=ccd_config.o common-$(CONFIG_CHARGE_MANAGER)+=charge_manager.o @@ -43,6 +42,7 @@ common-$(CONFIG_CURVE25519)+=curve25519.o ifneq ($(CORE),cortex-m0) common-$(CONFIG_CURVE25519)+=curve25519-generic.o endif +common-$(CONFIG_DEDICATED_RECOVERY_BUTTON)+=button.o common-$(CONFIG_DEVICE_EVENT)+=device_event.o common-$(CONFIG_DEVICE_STATE)+=device_state.o common-$(CONFIG_DPTF)+=dptf.o @@ -114,6 +114,7 @@ common-$(CONFIG_USB_PD_TCPC)+=usb_pd_tcpc.o common-$(CONFIG_USB_UPDATE)+=usb_update.o update_fw.o common-$(CONFIG_VBOOT_EFS)+=vboot/vboot.o common-$(CONFIG_VBOOT_HASH)+=sha256.o vboot_hash.o +common-$(CONFIG_VOLUME_BUTTONS)+=button.o common-$(CONFIG_VSTORE)+=vstore.o common-$(CONFIG_WEBUSB_URL)+=webusb_desc.o common-$(CONFIG_WIRELESS)+=wireless.o 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) */ +}; diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c index df2ae73045..2e1806abec 100644 --- a/common/keyboard_mkbp.c +++ b/common/keyboard_mkbp.c @@ -399,19 +399,19 @@ void clear_typematic_key(void) static uint32_t get_supported_buttons(void) { uint32_t val = 0; -#ifdef CONFIG_BUTTON_COUNT - int i; - for (i = 0; i < CONFIG_BUTTON_COUNT; i++) { - if (buttons[i].type == KEYBOARD_BUTTON_VOLUME_UP) - val |= (1 << EC_MKBP_VOL_UP); - if (buttons[i].type == KEYBOARD_BUTTON_VOLUME_DOWN) - val |= (1 << EC_MKBP_VOL_DOWN); - } -#endif +#ifdef CONFIG_VOLUME_BUTTONS + val |= (1 << EC_MKBP_VOL_UP) | (1 << EC_MKBP_VOL_DOWN); +#endif /* defined(CONFIG_VOLUME_BUTTONS) */ + +#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON + val |= (1 << EC_MKBP_RECOVERY); +#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON) */ + #ifdef CONFIG_POWER_BUTTON val |= (1 << EC_MKBP_POWER_BUTTON); -#endif +#endif /* defined(CONFIG_POWER_BUTTON) */ + return val; } diff --git a/common/main.c b/common/main.c index 48efa14f78..fe3424b67f 100644 --- a/common/main.c +++ b/common/main.c @@ -164,9 +164,9 @@ test_mockable __keep int main(void) #ifdef HAS_TASK_KEYSCAN keyboard_scan_init(); #endif -#ifdef CONFIG_BUTTON_COUNT +#if defined(CONFIG_DEDICATED_RECOVERY_BUTTON) || defined(CONFIG_VOLUME_BUTTONS) button_init(); -#endif +#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON | CONFIG_VOLUME_BUTTONS) */ #if !defined(CONFIG_VBOOT_EFS) && \ defined(CONFIG_RWSIG) && !defined(HAS_TASK_RWSIG) diff --git a/include/button.h b/include/button.h index c542d44c47..29b648eb60 100644 --- a/include/button.h +++ b/include/button.h @@ -38,9 +38,18 @@ struct button_config { int flags; }; -/* - * Defined in board.c. Should be CONFIG_BUTTON_COUNT elements long. - */ +enum button { +#ifdef CONFIG_VOLUME_BUTTONS + BUTTON_VOLUME_UP, + BUTTON_VOLUME_DOWN, +#endif /* defined(CONFIG_VOLUME_BUTTONS) */ +#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON + BUTTON_RECOVERY, +#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON) */ + BUTTON_COUNT, +}; + +/* Table of buttons for the board. */ extern const struct button_config buttons[]; /* diff --git a/include/config.h b/include/config.h index 42961a3300..083f81258d 100644 --- a/include/config.h +++ b/include/config.h @@ -393,12 +393,6 @@ /*****************************************************************************/ -/* - * Number of extra buttons not on the keyboard scan matrix. Doesn't include - * the power button, which has its own handler. - */ -#undef CONFIG_BUTTON_COUNT - /* * Support for entering recovery mode using volume buttons. You need to * list the buttons in recovery_buttons. @@ -410,6 +404,12 @@ */ #undef CONFIG_DEDICATED_RECOVERY_BUTTON +/* + * The board has volume up and volume down buttons. Note, these are *buttons* + * and not keys in the keyboard matrix. + */ +#undef CONFIG_VOLUME_BUTTONS + /* Support V1 CCD configuration */ #undef CONFIG_CASE_CLOSED_DEBUG_V1 /* Allow unsafe debugging functionality in V1 configuration */ diff --git a/test/button.c b/test/button.c index 2e8511df98..73172abbfd 100644 --- a/test/button.c +++ b/test/button.c @@ -18,14 +18,13 @@ #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 const struct button_config *button_vol_down = + &buttons[BUTTON_VOLUME_DOWN]; +static const struct button_config *button_vol_up = &buttons[BUTTON_VOLUME_UP]; -static int button_state[CONFIG_BUTTON_COUNT]; +static int button_state[BUTTON_COUNT]; /* * Callback from the button handling logic. @@ -35,7 +34,7 @@ void keyboard_update_button(enum keyboard_button_type button, int is_pressed) { int i; - for (i = 0; i < CONFIG_BUTTON_COUNT; i++) { + for (i = 0; i < BUTTON_COUNT; i++) { if (buttons[i].type == button) { button_state[i] = is_pressed; break; @@ -48,7 +47,7 @@ static int test_button_press(void) { gpio_set_level(button_vol_down->gpio, 0); msleep(100); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == 1); return EC_SUCCESS; } @@ -56,11 +55,11 @@ static int test_button_press(void) /* 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); + gpio_set_level(button_vol_up->gpio, 1); + msleep(100); + TEST_ASSERT(button_state[BUTTON_VOLUME_UP] == 0); return EC_SUCCESS; } @@ -72,7 +71,7 @@ static int test_button_debounce_short_press(void) msleep(10); gpio_set_level(button_vol_down->gpio, 1); msleep(100); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == UNCHANGED); return EC_SUCCESS; } @@ -82,15 +81,15 @@ 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); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == UNCHANGED); gpio_set_level(button_vol_down->gpio, 1); msleep(10); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == UNCHANGED); gpio_set_level(button_vol_down->gpio, 0); msleep(20); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == UNCHANGED); msleep(20); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == 1); return EC_SUCCESS; } @@ -100,24 +99,24 @@ 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); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == UNCHANGED); gpio_set_level(button_vol_down->gpio, 1); msleep(20); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == UNCHANGED); gpio_set_level(button_vol_down->gpio, 0); msleep(20); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == UNCHANGED); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == UNCHANGED); msleep(20); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == 1); msleep(60); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == 1); gpio_set_level(button_vol_down->gpio, 1); msleep(20); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == 1); msleep(20); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 0); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == 0); msleep(60); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 0); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == 0); return EC_SUCCESS; } @@ -127,15 +126,15 @@ 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); + gpio_set_level(button_vol_up->gpio, 0); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == UNCHANGED); + TEST_ASSERT(button_state[BUTTON_VOLUME_UP] == UNCHANGED); msleep(30); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1); - TEST_ASSERT(button_state[INDEX_VOL_UP] == UNCHANGED); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == 1); + TEST_ASSERT(button_state[BUTTON_VOLUME_UP] == UNCHANGED); msleep(40); - TEST_ASSERT(button_state[INDEX_VOL_DOWN] == 1); - TEST_ASSERT(button_state[INDEX_VOL_UP] == 1); + TEST_ASSERT(button_state[BUTTON_VOLUME_DOWN] == 1); + TEST_ASSERT(button_state[BUTTON_VOLUME_UP] == 1); return EC_SUCCESS; } @@ -145,12 +144,12 @@ static void button_test_init(void) int i; ccprintf("[%T Setting button GPIOs to inactive state.]\n"); - for (i = 0; i < CONFIG_BUTTON_COUNT; i++) + for (i = 0; i < 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++) + for (i = 0; i < BUTTON_COUNT; i++) button_state[i] = UNCHANGED; } diff --git a/test/test_config.h b/test/test_config.h index 5dd714f98b..e784bb8b2e 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -145,8 +145,8 @@ int ncp15wb_calculate_temp(uint16_t adc); #endif #ifdef TEST_BUTTON -#define CONFIG_BUTTON_COUNT 2 #define CONFIG_KEYBOARD_PROTOCOL_8042 +#define CONFIG_VOLUME_BUTTONS #endif #ifdef TEST_BATTERY_GET_PARAMS_SMART -- cgit v1.2.1