-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
[ports/rp2] new machine_rtc.c module #6932
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
Conversation
Signed-off-by: Rafael González <astrorafael@gmail.com>
A basic machine.RTC class conforming to the API published in http://docs.micropython.org/en/v1.14/library/machine.RTC.html with no interrupts (no RTC.irq() method). Signed-off-by: Rafael González <astrorafael@gmail.com>
This is a duplicate of #6928. Also it implements the "old" API.. This is the API described in the documentation but it is not really used by the ports, see #5733. I guess @dpgeorge should first resolve the issue with the documentation vs common implementation so we know which API should indeed be used. I've seen Thonny and Rshell uses the API as described in #5733 so my pull request implemented it. |
// RTC.now() method | ||
STATIC mp_obj_t machine_rtc_now(mp_obj_t self_in) { | ||
datetime_t t; | ||
rtc_get_datetime(&t); |
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.
In theory, this could return an error so just to be safe, it would be good to check the return value.
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.
Thanks, will take care of it if this implementation gets the green light.
mp_obj_new_int(t.min), | ||
mp_obj_new_int(t.sec), | ||
mp_obj_new_int(0), // usecs | ||
mp_const_none // tzinfo |
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.
The example in the documetation (which sadly is not followed by the ports) puts 0 here instead of None.
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.
IMHO, if we are using the standard datetime tuple convention, we should return None, as tzinfo is an object.
Well, In fact, it is a duplicate of #6923 :-), which I messed up with my bad abilities at git. |
Anyways, we have now two PR open for machine.RTC on rp2. Yours and mine. Mine is simpler as it only supports setting/getting the time and nothing else but it uses the API that is compatible with other ports. Yours implements more but it uses API from the docs which seems outdated. Also you set the default time to some specific time as documented by the docs but @dpgeorge set different default time in main.c for some reason.
Well, it was a low hanging fruit, wasn't it? :)
I don't think so. @dpgeorge should make his mind about the API and #5733. If mine implementation is accepted, you could add your alarms handling on top of that. Otherwise maybe he will prefer your implementation and mine is just thrown away. That being said, well, the project has almost 400 PRs hanging there so.. we'll see what happens. I personally think that clarifying the API is more important than either of our implementations so lets hope this gives some momentum for fixing this. API inconsistencies are, in my opinion, the biggest issue in micropython. |
Totally agreed. |
This is a basic implementation of machine_rtc.c module. No interrupt handling for the time being and conforms (I hope) to the interface documented in the MicroPython 1.14 official documentation.
It seems that somehow, updating my local & remote repos with upstream and doing git reset --mixed, made my previous PR #6929 to close. Sorry for the inconveniences.
The python test code is this: