-
Notifications
You must be signed in to change notification settings - Fork 512
[SX1262] Support deep sleep by allowing ::begin(...) without reset of module. #1608
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
base: master
Are you sure you want to change the base?
Conversation
9b3e958 to
5041899
Compare
|
Responding to @StevenCellist's related #1607 (comment):
Would love to dig into this line of thinking. I originally expected to have to export/import state to keep RadioLib functioning correctly over deep sleep, or find a way to keep it all in RTC memory (like @DarkZeros did here). But, I discovered that it is possible to reinitialize the entire RadioLib stack, and even the module itself, without losing the packet buffer - just by making sure the SX1262 isn't fully reset. So it really is just a fresh "begin" of the library, just without resetting the module. And reading the packet that triggered the wakeup (i.e. keeping the packet buffer intact) is all people seem to be missing wrt deep sleep. Regarding the extra However, an alternative, similar to your suggestion, would be to add a method that has the same signature as |
|
BTW - Section 7.4 of the SX1262 datasheet (v1.2) describes the data buffer behavior, and it does seem that the only operation that will clear it is putting the module into sleep mode (note for the wary: that's the SX1262, not the MCU). So it would seem that, as long as you avoid resetting, sleeping the module, or changing the buffer's RX pointer ( Given that, I suspect that even if the user called I haven't tested this on hardware yet (I'm traveling this weekend) but I can do so on Monday. |
|
It is worth noting that there are 2 different problems and use cases.
The PR is implementing case 1, not case 2. After a deep sleep the old setup done to the module will still be completely lost. Typically this is "known" by the developer, but might be good to have. In order not to lose the state, it should be stored on RTC_DATA. I had a working implementation wrapping all the classes in std::optional to avoid recontructing the objects after deep sleep. Still, it was needed to reset the GPIO states. You can see a working example here https://github.com/DarkZeros/LightMyInk/blob/devel/main/radio.cpp The PR on itself is fine, i am just adding some context, that it might be nice to have some support to wrap module speficics into a struct that survives deep sleeps using RTC_DATA atrributes. Wrapping all the classes is ok, but it uses too much memory, storing strings and other helper things. |
Curious. In your use cases, what state do you need to keep other than the packet buffer and why? I have deep sleep working well with just this change and can't think of what other state I'd ever need to have preserved. [Edit to add] I just looked through that code, and I don't see anything that needs to be preserved in RTC memory. You're programmatically setting the power level, but always revert it back to the known value |
Eaxctly right. This is what i mean that in most cases the developer can simply reset the known state after deep sleep. Therefore the PR is valid for most cases, still doesnt make the library deep sleep safe, just resilient. In my case i did it this way since I wanted to use the upstream version of the lib. If this PR is merged i will switch to the new method. |
I don't want to push the point too hard, but I'm curious what state you're concerned with? As far as I can determine from the data sheet, this approach isn't just resilient, it's perfectly "safe" for deep sleep wake up. |
If I'm not mistaken (i may have comoletely missunderstood the code) things like Again, it may not be an issue, and if it is, a very minor edge case. |
Ah. So I think both of those are ok, for different reasons:
|
d6bc93f to
d996756
Compare
Tested and confirmed that I can call |
Enables resuming from deep sleep without losing the packet buffer.
d996756 to
a30c99c
Compare
Currently, invoking
SX1262::begin(...)always resets the module during RadioLib initialization. This adds an additional argument,resetModule, which causesSX1262::begin(...)to avoid reseting the module during initialization, allowing the library to be configured while leaving the SX1262 in a known state, e.g. with a received packet in the packet buffer.This enables support for ESP32 deep sleep without losing the packet buffer on wakeup. An example sketch for deep sleep is also provided.
NOTE: I do not like adding the additional
resetModule=trueto the already long list of arguments to::begin(...). I have proposed #1607 to make this much cleaner. Making this a draft PR while #1607 is considered.