Skip to content
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

Make ResetReason and RunReason available #3797

Merged
merged 1 commit into from Dec 7, 2020

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Dec 6, 2020

  • microcontroller.ResetReason and supervisor.RunReason were missing from the corresponding module dictionaries, making them unavailable.
  • The printer for ResetReason mistakenly was saying it was part of alarm.
  • Fixed a typo in deep-sleep API documentation.
  • Remove a blank line at the top of a file (found accidentally).

Testing:

>>> import microcontroller
>>> microcontroller.<tab>
Pin             Processor       ResetReason     RunMode
cpu             delay_us        disable_interrupts
enable_interrupts               nvm             on_next_reset
pin             reset           watchdog
>>> microcontroller.ResetReason.<tab>
BROWNOUT        DEEP_SLEEP_ALARM                POWER_ON
RESET_PIN       SOFTWARE        UNKNOWN         WATCHDOG
>>> microcontroller.cpu.reset_reason
microcontroller.ResetReason.POWER_ON
>>> microcontroller.cpu.reset_reason == microcontroller.ResetReason.POWER_ON
True
>>> microcontroller.cpu.reset_reason == microcontroller.ResetReason.BROWNOUT
False
>>> import supervisor
>>> supervisor.runtime.run_reason
supervisor.RunReason.STARTUP
>>> supervisor.RunReason.STARTUP == supervisor.runtime.run_reason
True

@ladyada
Copy link
Member

ladyada commented Dec 6, 2020

hihi fyi on some chips the reset-reason register can have multiple bits set. so you can have "power on reset" bit and "reset pin" bits both set.

@dhalbert
Copy link
Collaborator Author

dhalbert commented Dec 6, 2020

hihi fyi on some chips the reset-reason register can have multiple bits set. so you can have "power on reset" bit and "reset pin" bits both set.

I am trying to think of a use case for multiple reasons, and how to decide which one to use.

We could make microcontroller.cpu.reset_reason be plural (.reset_reasons), and make it a bit mask. Then it's no longer an enum that will print as a string.

RunReason is still one at a time.

Incomplete chip survey:

SAMD51 says only one of the bits is set at at time:
image


STM32Fxx is unclear:
image


nRF is one at at time, but register is cumulative:
image


i.MX RT1050 is multiple:
image

@ladyada
Copy link
Member

ladyada commented Dec 6, 2020

theres' no particular reason youd want it but i know that some chips are like that. just an FYI that may be better to do if RESET_PIN in reset_reason) instead of == to account for it?

Copy link
Member

@anecdata anecdata left a comment

Choose a reason for hiding this comment

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

Replicating Dan's tests on ESP32-S2, looks good:

Adafruit CircuitPython 6.1.0-beta.2-5-gacbc5fc7a on 2020-12-06; FeatherS2 with ESP32S2
>>> 
>>> import microcontroller
>>> microcontroller.cpu.reset_reason
microcontroller.ResetReason.POWER_ON
>>> microcontroller.cpu.reset_reason is microcontroller.cpu.reset_reason.POWER_ON
True
>>> microcontroller.cpu.reset_reason is microcontroller.ResetReason.POWER_ON
True
>>> microcontroller.cpu.reset_reason is microcontroller.ResetReason.UNKNOWN
False
>>> 
>>> import supervisor
>>> supervisor.runtime.run_reason
supervisor.RunReason.REPL_RELOAD
>>> supervisor.runtime.run_reason is supervisor.runtime.run_reason.REPL_RELOAD
True
>>> supervisor.runtime.run_reason is supervisor.RunReason.REPL_RELOAD
True
>>> supervisor.runtime.run_reason is supervisor.RunReason.STARTUP
False

I can re-test if / when there are changes.

@dhalbert
Copy link
Collaborator Author

dhalbert commented Dec 6, 2020

theres' no particular reason youd want it but i know that some chips are like that. just an FYI that may be better to do if RESET_PIN in reset_reason) instead of == to account for it?

Yes, good point. we could make it microcontroller.cpu.reset_reasons and return a set or a tuple or something else that supports in, instead of requiring someone to do bit-checking, like microcontroller.cpu.reset_reasons & microcontroller.ResetReason.POWER_ON.

@tannewt
Copy link
Member

tannewt commented Dec 7, 2020

My preference would be a set or tuple if we want to support multiple reasons. I'm not sure we do though.

I think we can simplify to one reason. For chips that are cumulative we can clear the state or prioritize the reason.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@dhalbert
Copy link
Collaborator Author

dhalbert commented Dec 7, 2020

My preference would be a set or tuple if we want to support multiple reasons. I'm not sure we do though.

I think we can simplify to one reason. For chips that are cumulative we can clear the state or prioritize the reason.

This is OK with me. I think we can prioritize the reasons: I think there will be an overriding one that the user will really care about.

@dhalbert dhalbert merged commit 054eafd into adafruit:main Dec 7, 2020
@dhalbert dhalbert deleted the reset-reason-run-reason-available branch December 7, 2020 20:41
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.

None yet

4 participants