Skip to content

Commit

Permalink
Merge branch 'fix/button_low_power_issue' into 'master'
Browse files Browse the repository at this point in the history
fix(button): resolve button issue causing CPU wake during press

See merge request ae_group/esp-iot-solution!1044
  • Loading branch information
lijunru-hub committed Jul 8, 2024
2 parents d164459 + 84dc0c6 commit d8782c7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 5 deletions.
4 changes: 4 additions & 0 deletions components/button/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

## v3.2.3 - 2024-7-2

* Fixed the issue where the GPIO button in low-power mode continuously woke up the CPU after being pressed, causing abnormal power consumption.

## v3.2.2 - 2024-6-17

* Fix the compilation error for chips that do not support ADC.
Expand Down
13 changes: 12 additions & 1 deletion components/button/button_gpio.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
/* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -79,3 +79,14 @@ esp_err_t button_gpio_intr_control(int gpio_num, bool enable)
}
return ESP_OK;
}

esp_err_t button_gpio_enable_gpio_wakeup(uint32_t gpio_num, uint8_t active_level, bool enable)
{
esp_err_t ret;
if (enable) {
ret = gpio_wakeup_enable(gpio_num, active_level == 0 ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL);
} else {
ret = gpio_wakeup_disable(gpio_num);
}
return ret;
}
2 changes: 1 addition & 1 deletion components/button/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.2.2"
version: "3.2.3"
description: GPIO and ADC button driver
url: https://github.com/espressif/esp-iot-solution/tree/master/components/button
repository: https://github.com/espressif/esp-iot-solution.git
Expand Down
14 changes: 14 additions & 0 deletions components/button/include/button_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ esp_err_t button_gpio_set_intr(int gpio_num, gpio_int_type_t intr_type, gpio_isr
*/
esp_err_t button_gpio_intr_control(int gpio_num, bool enable);

/**
* @brief Enable or disable GPIO wakeup functionality.
*
* This function allows enabling or disabling GPIO wakeup feature.
*
* @param gpio_num GPIO number for wakeup functionality.
* @param active_level Active level of the GPIO when triggered.
* @param enable Enable or disable the GPIO wakeup.
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if trigger was not active or in conflict.
*/
esp_err_t button_gpio_enable_gpio_wakeup(uint32_t gpio_num, uint8_t active_level, bool enable);

#ifdef __cplusplus
}
#endif
11 changes: 8 additions & 3 deletions components/button/iot_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,14 @@ static void button_cb(void *args)
#if CONFIG_GPIO_BUTTON_SUPPORT_POWER_SAVE
if (enter_power_save_flag) {
/*!< Stop esp timer for power save */
esp_timer_stop(g_button_timer_handle);
g_is_timer_running = false;
if (g_is_timer_running) {
esp_timer_stop(g_button_timer_handle);
g_is_timer_running = false;
}
for (target = g_head_handle; target; target = target->next) {
if (target->type == BUTTON_TYPE_GPIO && target->enable_power_save) {
button_gpio_intr_control((int)(target->hardware_data), true);
button_gpio_enable_gpio_wakeup((uint32_t)(target->hardware_data), target->active_level, true);
}
}
}
Expand All @@ -327,6 +330,8 @@ static void IRAM_ATTR button_power_save_isr_handler(void* arg)
g_is_timer_running = true;
}
button_gpio_intr_control((int)arg, false);
/*!< disable gpio wakeup not need active level*/
button_gpio_enable_gpio_wakeup((uint32_t)arg, 0, false);
}
#endif

Expand Down Expand Up @@ -453,7 +458,7 @@ button_handle_t iot_button_create(const button_config_t *config)
}
BTN_CHECK(NULL != btn, "button create failed", NULL);
btn->type = config->type;
if (!btn->enable_power_save) {
if (!btn->enable_power_save && !g_is_timer_running) {
esp_timer_start_periodic(g_button_timer_handle, TICKS_INTERVAL * 1000U);
g_is_timer_running = true;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d8782c7

Please sign in to comment.