Skip to content

Save wake alarm info in static storage, simplifying recording of alarm #7154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 30, 2022

Conversation

dhalbert
Copy link
Collaborator

Fixes #6483; subsumes PR #7137.

Changes how alarm.wake_alarm is set. Instead of creating an alarm on the heap, after the VM is set up, a static alarm object is used instead, which can be set up outside of the VM.

This simplifies how and when to store the alarm info, and removes the need for the first_run boolean that was passed around in main.c.

Use #pragma once instead of #ifdef #include guards for alarm-related .h files: some were missing, so I just changed them all, to be consistent. Also make some other naming more consistent.

@georgboe, @bablokb your testing is welcome. Tested with fake deep sleep and real deep sleep with a battery on Adafruit Feather RP2040, Feather M4, Feather STM32F405, Feather nRF52840, and Feather ESP32-S2.

Test program, which writes to UART, for battery operation, and to USB:

import digitalio
import board
import alarm
import time

uart = board.UART()
uart.baudrate = 115200

led = digitalio.DigitalInOut(board.LED)
led.switch_to_output(True)
time.sleep(2)
led.value = False
msg = "Alarm was " + str(alarm.wake_alarm) + "\r\n"
print(msg, end = "")
uart.write(msg.encode("utf-8"))

time_alarm = alarm.time.TimeAlarm(monotonic_time=time.monotonic() + 5)

msg = "Entering deep sleep at " + str(time.monotonic()) + "\r\n"
print(msg, end="")
uart.write(msg.encode("utf-8"))
time.sleep(0.1)   # allow time for uart.write() to finish

alarm.exit_and_deep_sleep_until_alarms(time_alarm)

@dhalbert dhalbert requested a review from jepler October 29, 2022 20:36
@georgboe
Copy link

@dhalbert I tested now on a Pico W and it works perfectly.

@dhalbert
Copy link
Collaborator Author

@dhalbert I tested now on a Pico W and it works perfectly.

Thank you for testing!

Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

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

Thanks! I don't 100% follow the changes in main.c but I am relying on the testing.

@dhalbert dhalbert merged commit 952812c into adafruit:main Oct 30, 2022
@dhalbert dhalbert deleted the alarm-lifetime branch October 30, 2022 16:28
@bablokb
Copy link

bablokb commented Oct 30, 2022

Tests ok with TimeAlarm and PinAlarm, thanks. There might be a regression: entering deep-sleep should release the display. At least there was a pull-request for that as far as I remember. And it does work for a few cycles (run-deep-sleep-run-...) and then stops working. Not sure if this is related to this patch, because I have not tested before merging your patch, but I will do so within the next few days.

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.

pico: alarm.wake_alarm not set after deep-sleep
4 participants