pyboard - deepsleep wake pins
I have just switched to pyboard for a project which has been on the esp32 and I need to be able to wake from deep sleep by either time or a pin edge.
https://github.com/micropython/micropython/blob/master/docs/library/machine.Pin.rst
https://docs.micropython.org/en/latest/pyboard/library/machine.Pin.html
These pages indicate that the syntax for enabling a wake-up pin is:
import machine as mc
door = mc.Pin('X1',mc.Pin.IN)
door.irq(handler=None, trigger=(mc.Pin.IRQ_FALLING | mc.Pin.IRQ_RISING),wake=mc.DEEPSLEEP)
However this results in an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'DEEPSLEEP'
What's the solution ?
modmachine: Add `machine.wake_pins`.
Summary
When waking from deep sleep, it could be helpful to know what pins triggered the wake up since the wake pins could be configured to multiple pins.
Based on work that @m-cas did in this PR - https://github.com/micropython/micropython/pull/15498.
Testing
Tested ESP32_GENERIC_C3 with:
import machine
import esp32
esp32.wake_on_gpio((machine.Pin(5),machine.Pin(2)), esp32.WAKEUP_ANY_HIGH)
machine.deepsleep()
After wakeup checked that machine.wake_pins() returned the correct pin that trigerred the wake.
Trade-offs and Alternatives
I decided to place the method in machine together with wake_reason, since it is feasible that other ports
will want the exact same interface.