forked from espressif/esp-idf
esp_system: support gpio wakeup from deep sleep on esp32c3
This commit is contained in:
@@ -555,9 +555,11 @@ esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
if ((intr_type == GPIO_INTR_LOW_LEVEL) || (intr_type == GPIO_INTR_HIGH_LEVEL)) {
|
||||
#if SOC_RTCIO_WAKE_SUPPORTED
|
||||
if (rtc_gpio_is_valid_gpio(gpio_num)) {
|
||||
ret = rtc_gpio_wakeup_enable(gpio_num, intr_type);
|
||||
}
|
||||
#endif
|
||||
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
gpio_hal_wakeup_enable(gpio_context.gpio_hal, gpio_num, intr_type);
|
||||
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
@@ -573,10 +575,11 @@ esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num)
|
||||
{
|
||||
GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
#if SOC_RTCIO_WAKE_SUPPORTED
|
||||
if (rtc_gpio_is_valid_gpio(gpio_num)) {
|
||||
ret = rtc_gpio_wakeup_disable(gpio_num);
|
||||
}
|
||||
#endif
|
||||
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
gpio_hal_wakeup_disable(gpio_context.gpio_hal, gpio_num);
|
||||
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
@@ -631,7 +634,9 @@ esp_err_t gpio_hold_en(gpio_num_t gpio_num)
|
||||
int ret = ESP_OK;
|
||||
|
||||
if (rtc_gpio_is_valid_gpio(gpio_num)) {
|
||||
#if SOC_RTCIO_HOLD_SUPPORTED
|
||||
ret = rtc_gpio_hold_en(gpio_num);
|
||||
#endif
|
||||
} else if (GPIO_HOLD_MASK[gpio_num]) {
|
||||
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
gpio_hal_hold_en(gpio_context.gpio_hal, gpio_num);
|
||||
@@ -649,7 +654,9 @@ esp_err_t gpio_hold_dis(gpio_num_t gpio_num)
|
||||
int ret = ESP_OK;
|
||||
|
||||
if (rtc_gpio_is_valid_gpio(gpio_num)) {
|
||||
#if SOC_RTCIO_HOLD_SUPPORTED
|
||||
ret = rtc_gpio_hold_dis(gpio_num);
|
||||
#endif
|
||||
}else if (GPIO_HOLD_MASK[gpio_num]) {
|
||||
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
gpio_hal_hold_dis(gpio_context.gpio_hal, gpio_num);
|
||||
@@ -679,7 +686,9 @@ void gpio_deep_sleep_hold_dis(void)
|
||||
|
||||
esp_err_t gpio_force_hold_all()
|
||||
{
|
||||
#if SOC_RTCIO_HOLD_SUPPORTED
|
||||
rtc_gpio_force_hold_all();
|
||||
#endif
|
||||
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
gpio_hal_force_hold_all(gpio_context.gpio_hal);
|
||||
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
@@ -688,9 +697,11 @@ esp_err_t gpio_force_hold_all()
|
||||
|
||||
esp_err_t gpio_force_unhold_all()
|
||||
{
|
||||
#if SOC_RTCIO_HOLD_SUPPORTED
|
||||
rtc_gpio_force_hold_dis_all();
|
||||
#endif
|
||||
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
gpio_hal_force_unhold_all(gpio_context.gpio_hal);
|
||||
gpio_hal_force_unhold_all();
|
||||
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -877,5 +888,35 @@ esp_err_t gpio_sleep_pupd_config_unapply(gpio_num_t gpio_num)
|
||||
gpio_hal_sleep_pupd_config_unapply(gpio_context.gpio_hal, gpio_num);
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif // CONFIG_GPIO_ESP32_SUPPORT_SWITCH_SLP_PULL
|
||||
#endif // SOC_GPIO_SUPPORT_SLP_SWITCH
|
||||
|
||||
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
|
||||
esp_err_t gpio_deep_sleep_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
||||
{
|
||||
if (!gpio_hal_is_valid_deepsleep_wakeup_gpio(gpio_num)) {
|
||||
ESP_LOGE(GPIO_TAG, "GPIO %d does not support deep sleep wakeup", gpio_num);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((intr_type != GPIO_INTR_LOW_LEVEL) && (intr_type != GPIO_INTR_HIGH_LEVEL)) {
|
||||
ESP_LOGE(GPIO_TAG, "GPIO wakeup only supports level mode, but edge mode set. gpio_num:%u", gpio_num);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
gpio_hal_deepsleep_wakeup_enable(gpio_context.gpio_hal, gpio_num, intr_type);
|
||||
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t gpio_deep_sleep_wakeup_disable(gpio_num_t gpio_num)
|
||||
{
|
||||
if (!gpio_hal_is_valid_deepsleep_wakeup_gpio(gpio_num)) {
|
||||
ESP_LOGE(GPIO_TAG, "GPIO %d does not support deep sleep wakeup", gpio_num);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
portENTER_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
gpio_hal_deepsleep_wakeup_disable(gpio_context.gpio_hal, gpio_num);
|
||||
portEXIT_CRITICAL(&gpio_context.gpio_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif // SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
|
||||
|
||||
@@ -516,6 +516,38 @@ esp_err_t gpio_sleep_pupd_config_unapply(gpio_num_t gpio_num);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
|
||||
|
||||
#define GPIO_IS_DEEP_SLEEP_WAKEUP_VALID_GPIO(gpio_num) ((gpio_num & ~SOC_GPIO_DEEP_SLEEP_WAKEUP_VALID_GPIO_MASK) == 0)
|
||||
|
||||
/**
|
||||
* @brief Enable GPIO deep-sleep wake-up function.
|
||||
*
|
||||
* @param gpio_num GPIO number.
|
||||
*
|
||||
* @param intr_type GPIO wake-up type. Only GPIO_INTR_LOW_LEVEL or GPIO_INTR_HIGH_LEVEL can be used.
|
||||
*
|
||||
* @note Called by the SDK. User shouldn't call this directly in the APP.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t gpio_deep_sleep_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
||||
|
||||
/**
|
||||
* @brief Disable GPIO deep-sleep wake-up function.
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t gpio_deep_sleep_wakeup_disable(gpio_num_t gpio_num);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "driver/rtc_io.h"
|
||||
#include "hal/rtc_io_hal.h"
|
||||
|
||||
static const char *RTCIO_TAG = "RTCIO";
|
||||
static const char __attribute__((__unused__)) *RTCIO_TAG = "RTCIO";
|
||||
|
||||
#define RTCIO_CHECK(a, str, ret_val) ({ \
|
||||
if (!(a)) { \
|
||||
@@ -164,29 +164,19 @@ esp_err_t rtc_gpio_pulldown_dis(gpio_num_t gpio_num)
|
||||
|
||||
esp_err_t rtc_gpio_hold_en(gpio_num_t gpio_num)
|
||||
{
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32C3 // should use HAL here, TODO ESP32-C3 IDF-2511
|
||||
RTCIO_CHECK(gpio_num <= GPIO_NUM_5, "RTCIO number error", ESP_ERR_INVALID_ARG);
|
||||
REG_SET_BIT(RTC_CNTL_PAD_HOLD_REG, BIT(gpio_num));
|
||||
#else
|
||||
RTCIO_CHECK(rtc_gpio_is_valid_gpio(gpio_num), "RTCIO number error", ESP_ERR_INVALID_ARG);
|
||||
RTCIO_ENTER_CRITICAL();
|
||||
rtcio_hal_hold_enable(rtc_io_number_get(gpio_num));
|
||||
RTCIO_EXIT_CRITICAL();
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num)
|
||||
{
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32C3 // should use HAL here, TODO ESP32-C3 IDF-2511
|
||||
RTCIO_CHECK(gpio_num <= GPIO_NUM_5, "RTCIO number error", ESP_ERR_INVALID_ARG);
|
||||
REG_CLR_BIT(RTC_CNTL_PAD_HOLD_REG, BIT(gpio_num));
|
||||
#else
|
||||
RTCIO_CHECK(rtc_gpio_is_valid_gpio(gpio_num), "RTCIO number error", ESP_ERR_INVALID_ARG);
|
||||
RTCIO_ENTER_CRITICAL();
|
||||
rtcio_hal_hold_disable(rtc_io_number_get(gpio_num));
|
||||
RTCIO_EXIT_CRITICAL();
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -224,16 +214,6 @@ esp_err_t rtc_gpio_force_hold_dis_all(void)
|
||||
|
||||
esp_err_t rtc_gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
||||
{
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32C3 // should use HAL here, TODO ESP32-C3 IDF-2511
|
||||
RTCIO_CHECK(gpio_num <= GPIO_NUM_5, "RTCIO number error", ESP_ERR_INVALID_ARG);
|
||||
REG_SET_BIT(RTC_CNTL_GPIO_WAKEUP_REG, RTC_CNTL_GPIO_PIN0_WAKEUP_ENABLE_M >> gpio_num);
|
||||
|
||||
uint32_t reg = REG_READ(RTC_CNTL_GPIO_WAKEUP_REG);
|
||||
reg &= (~(RTC_CNTL_GPIO_PIN0_INT_TYPE_V << (RTC_CNTL_GPIO_PIN0_INT_TYPE_S - gpio_num * 3)));
|
||||
reg |= (intr_type << (RTC_CNTL_GPIO_PIN0_INT_TYPE_S - gpio_num * 3));
|
||||
REG_WRITE(RTC_CNTL_GPIO_WAKEUP_REG, reg);
|
||||
ESP_LOGD(RTCIO_TAG, "gpio wake up 0x%08x", REG_READ(RTC_CNTL_GPIO_WAKEUP_REG));
|
||||
#else
|
||||
RTCIO_CHECK(rtc_gpio_is_valid_gpio(gpio_num), "RTCIO number error", ESP_ERR_INVALID_ARG);
|
||||
if (intr_type == GPIO_INTR_POSEDGE || intr_type == GPIO_INTR_NEGEDGE || intr_type == GPIO_INTR_ANYEDGE) {
|
||||
return ESP_ERR_INVALID_ARG; // Dont support this mode.
|
||||
@@ -241,21 +221,15 @@ esp_err_t rtc_gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
||||
RTCIO_ENTER_CRITICAL();
|
||||
rtcio_hal_wakeup_enable(rtc_io_number_get(gpio_num), intr_type);
|
||||
RTCIO_EXIT_CRITICAL();
|
||||
#endif // CONFIG_IDF_TARGET_ESP32C3
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t rtc_gpio_wakeup_disable(gpio_num_t gpio_num)
|
||||
{
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32C3 // should use HAL here, TODO ESP32-C3 IDF-2511
|
||||
RTCIO_CHECK(gpio_num <= GPIO_NUM_5, "RTCIO number error", ESP_ERR_INVALID_ARG);
|
||||
REG_CLR_BIT(RTC_CNTL_GPIO_WAKEUP_REG, RTC_CNTL_GPIO_PIN0_WAKEUP_ENABLE_M >> gpio_num);
|
||||
#else
|
||||
RTCIO_CHECK(rtc_gpio_is_valid_gpio(gpio_num), "RTCIO number error", ESP_ERR_INVALID_ARG);
|
||||
RTCIO_ENTER_CRITICAL();
|
||||
rtcio_hal_wakeup_disable(rtc_io_number_get(gpio_num));
|
||||
RTCIO_EXIT_CRITICAL();
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user