Swadge ESP32-S2/S3
APIs to develop for the Magfest Swadge
Loading...
Searching...
No Matches
hdw-sleep-switch.h File Reference

Detailed Description

Design Philosophy

Prior to the Fairy Swadge, the power switch would cut power between the battery and the ESP.

As of the Fairy Swadge, the power switch is connected to a GPIO on one end and either a 10K pullup to VCC or GND on the other end.

The Swadge enters or exits deep sleep depending on the GPIO state.

The GPIO is configured as an RTC GPIO in order to wake the ESP from deep sleep.

Usage

This component is not intended to be used by developers. It is set up and used in app_main() and should only be used there.

Example

// Initialize sleep switch
initSleepSwitch(GPIO_SLEEP);
// If the switch says it's time to sleep
{
// Don't start a specific mode when awoken
pendingSwadgeMode = NULL;
// Deinitialize everything (including the swadge mode)
// Sleep until the switch wakes the swadge
esp_deep_sleep_start();
}
esp_err_t initSleepSwitch(gpio_num_t gpio)
Initialize a GPIO as an RTC GPIO which monitors the sleep switch.
Definition hdw-sleep-switch.c:16
bool sleepSwitchShouldSleep(void)
Check if the sleep switch should put the Swadge to sleep. This function does not call esp_deep_sleep_...
Definition hdw-sleep-switch.c:50
void deinitSystem(void)
Deinitialize all components in the system.
Definition swadge.c:782

Go to the source code of this file.

Functions

esp_err_t initSleepSwitch (gpio_num_t gpio)
 Initialize a GPIO as an RTC GPIO which monitors the sleep switch.
bool sleepSwitchShouldSleep (void)
 Check if the sleep switch should put the Swadge to sleep. This function does not call esp_deep_sleep_start(). That must be done by the caller after de-initializing the Swadge mode, hardware peripherals, etc.

Function Documentation

◆ initSleepSwitch()

esp_err_t initSleepSwitch ( gpio_num_t gpio)

Initialize a GPIO as an RTC GPIO which monitors the sleep switch.

Parameters
gpioThe GPIO connected to the sleep switch. Must ben an RTC GPIO (GPIO_NUM_0 through GPIO_NUM_21 on ESP32-S3)
Returns
esp_err_t ESP_OK on success, or an ESP_ERR_ value

◆ sleepSwitchShouldSleep()

bool sleepSwitchShouldSleep ( void )

Check if the sleep switch should put the Swadge to sleep. This function does not call esp_deep_sleep_start(). That must be done by the caller after de-initializing the Swadge mode, hardware peripherals, etc.

Returns
true if the Swadge should enter deep sleep, false if it should stay awake