-
Notifications
You must be signed in to change notification settings - Fork 221
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
Allow setting RTC time #1883
Allow setting RTC time #1883
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a nice addition, do you plan on finishing this up?
Absolutely, but first I'd like to know what the preference is for general API (for instance, should the boot time functions be public?) and for implementing the rtcc traits. There is also the "boot time adjustment" and rtc offset to consider, but I don't really think they're needed. |
I've deprecated |
Oh, cool that you have checks for different devices |
For the c6 I think only this was needed:
using Some resources: Full commit here: |
Yes, that's correct. I saw LP_AON in the register headers but assumed it was the same as LP_TIMER, especially since LP_TIMER is used for the other RTC stuff. I'll add a fix when I have some time |
Additionally I tested it on esp32c6 with the latest changes, works good |
Chrono sounds good and in my own personal usage of this PR, is what I'm converting the Although, it is important to consider that embassy has their own DateTime struct and simply provides a |
Currently, |
Any chance of further review? It's been more than a month and it would be great to get this merged. I can update the example and fix merge conflicts if the API seems fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM API-wise, I don't see the problem in directly depending on chrono, versus having our own types here.
Changelog and examples are updated, so this PR should be ready to be merged |
There is some overlap now between |
Hmm good point, but I would somewhat argue that we should change Imo |
👍 Sure - I'd vote for |
After a rebase this should be fine I guess |
The PR has been rebased, and some basic info has been added to the migration guide |
…it isn't really relevant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
esp-idf has gettimeofday (see here) and settimeofday (see here) functions, allowing the user to get and set the internal RTC time. While esp-hal allows getting the RTC time, it does not allow setting it.
esp-idf sets the RTC time by storing the boot time (see here for getting, here for setting, here for esp32s3 register info). It calculates the current time by adding the boot time and the RTC time. Therefore, you can set the current time by setting the boot time to the new current time minus the RTC time. esp-idf also does some more advanced things like calculating the offset between RTC and systimer and adjusting the boot time, which I haven't taken the time to understand or implement since the current implementation is good enough for my needs.
This PR contains a basic port of esp-idf's boot time usage in the
Rtc
struct. It addsset_time_us
,set_time_ms
,get_rtc_time_us
,get_rtc_time_us
, and renamesget_time_raw
toget_rtc_time_raw
. It should support all esp32 chips.To avoid overflows when adding the boot time and the rtc time, the boot time also wraps around
u64::MAX
.There are also some traits in the rtcc crate that may be worth implementing.
Testing
This PR has been tested on a esp32s3.