Skip to content

Conversation

bettio
Copy link
Collaborator

@bettio bettio commented Aug 8, 2025

Allow putting ESP32 to light sleep, and wake it up using a GPIO or a timer.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@bettio bettio force-pushed the add-support-to-esp32-light-sleep branch from 778ca20 to 0cb4308 Compare August 8, 2025 14:39
@@ -513,6 +528,47 @@ static term nif_esp_deep_sleep_enable_gpio_wakeup(Context *ctx, int argc, term a
}
#endif

static term nif_esp_gpio_wakeup_enable(Context *ctx, int argc, term argv[])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this gpio:wakeup_enable/2 to match with the esp-idf function name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means we are leaking more ESP32 specific stuff into GPIO module. I think they can be made somehow generic, but I'm not sure how.

@bettio
Copy link
Collaborator Author

bettio commented Aug 10, 2025

There is something that I'd like to here the opinion about:

Should we use the avm_pubsub for pushing power manager events when returning from sleep?
Such as different 3rd party drivers might need to check if any IRQ pin has been raised during sleep, or any other process might need to know that everything was suspend for a certain amount of time.
So we have either 2 options: leave the caller handle this when returning from sleep, or standardizing some kind of mechanism for informing drivers and anything else that there was a power management related event.

@pguyot
Copy link
Collaborator

pguyot commented Aug 10, 2025

There is something that I'd like to here the opinion about:

Should we use the avm_pubsub for pushing power manager events when returning from sleep? Such as different 3rd party drivers might need to check if any IRQ pin has been raised during sleep, or any other process might need to know that everything was suspend for a certain amount of time. So we have either 2 options: leave the caller handle this when returning from sleep, or standardizing some kind of mechanism for informing drivers and anything else that there was a power management related event.

We could use monitor/2 to get the event.

BEAM documentation reads:

The monitor functionality is expected to be extended. That is, other Types and Items are expected to be supported in a future release.

Allow putting ESP32 to light sleep, and wake it up using a GPIO or a
timer.

Signed-off-by: Davide Bettio <[email protected]>
@bettio bettio force-pushed the add-support-to-esp32-light-sleep branch from 0cb4308 to 4d62044 Compare August 10, 2025 15:01
@UncleGrumpy
Copy link
Collaborator

We could use monitor/2 to get the event.

This is an interesting suggestion, and might be useful to expose an API for pushing other “monitored” events, like acquiring or loosing a network connection.

I think some standardized notification system would be good, but it should be opt in, so extra resources are not consumed if they are not used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants