mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-07-15 08:32:42 +08:00
feat(esp8266): add function to enable GPIO wakeup from light sleep and disable wakeup source
This commit is contained in:
@ -33,6 +33,16 @@ typedef enum esp_sleep_mode {
|
|||||||
|
|
||||||
typedef void (*fpm_wakeup_cb)(void);
|
typedef void (*fpm_wakeup_cb)(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sleep wakeup cause
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
ESP_SLEEP_WAKEUP_UNDEFINED, //!< In case of deep sleep, reset was not caused by exit from deep sleep
|
||||||
|
ESP_SLEEP_WAKEUP_ALL, //!< Not a wakeup cause, used to disable all wakeup sources with esp_sleep_disable_wakeup_source
|
||||||
|
ESP_SLEEP_WAKEUP_TIMER, //!< Wakeup caused by timer
|
||||||
|
ESP_SLEEP_WAKEUP_GPIO, //!< Wakeup caused by GPIO (light sleep only)
|
||||||
|
} esp_sleep_source_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the chip to deep-sleep mode.
|
* @brief Set the chip to deep-sleep mode.
|
||||||
*
|
*
|
||||||
@ -208,6 +218,32 @@ esp_err_t esp_light_sleep_start(void);
|
|||||||
*/
|
*/
|
||||||
void esp_sleep_start(void);
|
void esp_sleep_start(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable wakeup from light sleep using GPIOs
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK on success
|
||||||
|
* - ESP_ERR_INVALID_STATE if wakeup triggers conflict
|
||||||
|
*/
|
||||||
|
esp_err_t esp_sleep_enable_gpio_wakeup(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Disable wakeup source
|
||||||
|
*
|
||||||
|
* This function is used to deactivate wake up trigger for source
|
||||||
|
* defined as parameter of the function.
|
||||||
|
*
|
||||||
|
* @note This function does not modify wake up configuration in RTC.
|
||||||
|
* It will be performed in esp_sleep_start function.
|
||||||
|
*
|
||||||
|
* @param source - number of source to disable of type esp_sleep_source_t
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK on success
|
||||||
|
* - ESP_ERR_INVALID_STATE if trigger was not active
|
||||||
|
*/
|
||||||
|
esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -164,6 +164,33 @@ esp_err_t esp_sleep_enable_timer_wakeup(uint32_t time_in_us)
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t esp_sleep_enable_gpio_wakeup(void)
|
||||||
|
{
|
||||||
|
s_sleep_wakup_triggers |= RTC_GPIO_TRIG_EN;
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source)
|
||||||
|
{
|
||||||
|
// For most of sources it is enough to set trigger mask in local
|
||||||
|
// configuration structure. The actual RTC wake up options
|
||||||
|
// will be updated by esp_sleep_start().
|
||||||
|
if (source == ESP_SLEEP_WAKEUP_ALL) {
|
||||||
|
s_sleep_wakup_triggers = 0;
|
||||||
|
} else if (ESP_SLEEP_WAKEUP_TIMER == source) {
|
||||||
|
s_sleep_wakup_triggers &= ~RTC_TIMER_TRIG_EN;
|
||||||
|
s_sleep_duration = 0;
|
||||||
|
} else if (ESP_SLEEP_WAKEUP_GPIO == source) {
|
||||||
|
s_sleep_wakup_triggers &= ~RTC_GPIO_TRIG_EN;
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "Incorrect wakeup source (%d) to disable.", (int) source);
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
esp_err_t esp_light_sleep_start(void)
|
esp_err_t esp_light_sleep_start(void)
|
||||||
{
|
{
|
||||||
uint32_t period = pm_rtc_clock_cali_proc();
|
uint32_t period = pm_rtc_clock_cali_proc();
|
||||||
|
Reference in New Issue
Block a user