Skip to content

modmachine: Add machine.wake_pins. - #17542

Merged
dpgeorge merged 1 commit into
micropython:masterfrom
meirarmon:machine-wake-pins
May 8, 2026
Merged

dpgeorge merged 1 commit into
micropython:masterfrom
meirarmon:machine-wake-pins

Conversation

@meirarmon

@meirarmon meirarmon commented Jun 21, 2025 •

Copy link
Copy Markdown
Contributor

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 - #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.

@projectgus projectgus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks like a useful function to me, and a good abstraction to eventually support on other ports as well. Thanks @meirarmon!

Comment thread ports/esp32/modmachine.c Outdated

@projectgus projectgus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @meirarmon, thanks for being so patient while I got back to this.

I have one very nitpicky optional suggestion, but this looks good to me and I think we should merge it either way. Thank you for contributing it!

Comment thread ports/esp32/modmachine.c Outdated
// Only a few (~8) pins might cause wakeup.
// Therefore, we calculate the required space in a first pass.
for (index = 0, len = 0; index < 64; index++) {
len += (status & ((uint64_t)1 << index)) ? 1 : 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
len += (status & ((uint64_t)1 << index)) ? 1 : 0;
len += (status & (1ULL << index)) ? 1 : 0;

(This is nitpicky, but it's easier to read.)

Comment thread ports/esp32/modmachine.c Outdated
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(len, NULL));

for (index = 0, len = 0; index < 64; index++) {
if (status & ((uint64_t)1 << index)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (status & ((uint64_t)1 << index)) {
if (status & (1ULL << index)) {

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.

Signed-off-by: Meir Armon <[email protected]>
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown

Code size report:

Reference:  esp32/machine_pin: Add mode, pull and drive to machine_pin_print(). [cc502ab]
Comparison: esp32/modmachine: Add new machine.wake_pins() function. [merge of f563d3c]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:  +300 +0.017% ESP32_GENERIC[incl +32(data)]
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@dpgeorge
dpgeorge merged commit f563d3c into micropython:master May 8, 2026
14 checks passed
@dpgeorge

dpgeorge commented May 8, 2026

Copy link
Copy Markdown
Member

Now merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants