mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 12:14:32 +02:00
driver/gpio: support wakeup function for RTC IOs
This commit is contained in:
@@ -423,16 +423,19 @@ esp_err_t gpio_isr_register(void (*fn)(void*), void * arg, int intr_alloc_flags,
|
|||||||
return esp_intr_alloc(ETS_GPIO_INTR_SOURCE, intr_alloc_flags, fn, arg, handle);
|
return esp_intr_alloc(ETS_GPIO_INTR_SOURCE, intr_alloc_flags, fn, arg, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*only level interrupt can be used for wake-up function*/
|
|
||||||
esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
||||||
{
|
{
|
||||||
GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
||||||
esp_err_t ret = ESP_OK;
|
esp_err_t ret = ESP_OK;
|
||||||
if (( intr_type == GPIO_INTR_LOW_LEVEL ) || ( intr_type == GPIO_INTR_HIGH_LEVEL )) {
|
if (( intr_type == GPIO_INTR_LOW_LEVEL ) || ( intr_type == GPIO_INTR_HIGH_LEVEL )) {
|
||||||
|
if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
|
||||||
|
ret = rtc_gpio_wakeup_enable(gpio_num, intr_type);
|
||||||
|
} else {
|
||||||
GPIO.pin[gpio_num].int_type = intr_type;
|
GPIO.pin[gpio_num].int_type = intr_type;
|
||||||
GPIO.pin[gpio_num].wakeup_enable = 0x1;
|
GPIO.pin[gpio_num].wakeup_enable = 0x1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(GPIO_TAG, "GPIO wakeup only support Level mode,but edge mode set. gpio_num:%u", gpio_num);
|
ESP_LOGE(GPIO_TAG, "GPIO wakeup only supports level mode, but edge mode set. gpio_num:%u", gpio_num);
|
||||||
ret = ESP_ERR_INVALID_ARG;
|
ret = ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@@ -246,6 +246,29 @@ esp_err_t rtc_gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t st
|
|||||||
*/
|
*/
|
||||||
esp_err_t rtc_gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength);
|
esp_err_t rtc_gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable wakeup from sleep mode using specific GPIO
|
||||||
|
* @param gpio_num GPIO number
|
||||||
|
* @param intr_type Wakeup on high level (GPIO_INTR_HIGH_LEVEL) or low level
|
||||||
|
* (GPIO_INTR_LOW_LEVEL)
|
||||||
|
* @return
|
||||||
|
* - ESP_OK on success
|
||||||
|
* - ESP_ERR_INVALID_ARG if gpio_num is not an RTC IO, or intr_type is not
|
||||||
|
* one of GPIO_INTR_HIGH_LEVEL, GPIO_INTR_LOW_LEVEL.
|
||||||
|
*/
|
||||||
|
esp_err_t rtc_gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Disable wakeup from sleep mode using specific GPIO
|
||||||
|
* @param gpio_num GPIO number
|
||||||
|
* @return
|
||||||
|
* - ESP_OK on success
|
||||||
|
* - ESP_ERR_INVALID_ARG if gpio_num is not an RTC IO
|
||||||
|
*/
|
||||||
|
esp_err_t rtc_gpio_wakeup_disable(gpio_num_t gpio_num);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -383,6 +383,37 @@ void rtc_gpio_force_hold_dis_all()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t rtc_gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type)
|
||||||
|
{
|
||||||
|
int rtc_num = rtc_gpio_desc[gpio_num].rtc_num;
|
||||||
|
if (rtc_num < 0) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
if (( intr_type != GPIO_INTR_LOW_LEVEL ) && ( intr_type != GPIO_INTR_HIGH_LEVEL )) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t reg = RTC_GPIO_PIN0_REG + rtc_num * sizeof(uint32_t);
|
||||||
|
/* each pin has its own register, spinlock not needed */
|
||||||
|
REG_SET_BIT(reg, RTC_GPIO_PIN0_WAKEUP_ENABLE);
|
||||||
|
REG_SET_FIELD(reg, RTC_GPIO_PIN0_INT_TYPE, intr_type);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t rtc_gpio_wakeup_disable(gpio_num_t gpio_num)
|
||||||
|
{
|
||||||
|
int rtc_num = rtc_gpio_desc[gpio_num].rtc_num;
|
||||||
|
if (rtc_num < 0) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t reg = RTC_GPIO_PIN0_REG + rtc_num * sizeof(uint32_t);
|
||||||
|
/* each pin has its own register, spinlock not needed */
|
||||||
|
REG_CLR_BIT(reg, RTC_GPIO_PIN0_WAKEUP_ENABLE);
|
||||||
|
REG_SET_FIELD(reg, RTC_GPIO_PIN0_INT_TYPE, 0);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------
|
/*---------------------------------------------------------------
|
||||||
Touch Pad
|
Touch Pad
|
||||||
|
Reference in New Issue
Block a user