Skip to content

Improved RTC Functionality #170

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 53 commits into from
Jul 16, 2020
Merged

Improved RTC Functionality #170

merged 53 commits into from
Jul 16, 2020

Conversation

adamgarbo
Copy link
Contributor

Hi @nseidle,

Happy to finally submit my Artemis RTC functionality improvements! I've attempted to address all of your comments from the related SparkFun forum post.

Notable changes:

Added functions:

void setEpoch(uint32_t ts); // Set's the RTC's date and time using UNIX Epoch time
void getAlarm(); // Get's the RTC current alarm date/time
void setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month); // Set's alarm time
void setAlarmMode(uint8_t mode); // Set's the RTC's alarm interrupt mode
void attachInterrupt(); // Enables the RTC alarm interrupt
void detachInterrupt(); // Disables the RTC alarm interrupt

Note that I've changed the order of date/time values for setTime() from:
hh, mm, ss, hund, dd, mm, yy
to:
hund, ss, mm, hh, dd, mm, yy

I believe this is a more intuitive way to set the RTC time, and is also in line with the majority of other SparkFun RTC libraries (e.g. RV1805, RV8803, DS1307, DS3234, etc.). However, glad to get your thoughts on this. As far as I’m aware, this will only break code in the OpenLog Artemis repositories (both OLA and Paul’s GNSS logger). However, these are a minor fixes that I can submit PRs for.

I also created a number of examples to demonstrate the added functionality. I attempted to keep them as simple as possible and included more explanatory information in the comment section.

Examples:

  1. Example1_Get_Time
    • Not modified.
  2. Example2_Set_Alarms
    • A simple example to set the RTC alarm, which replaces the existing example 2. Now makes use of am_isr_rtc() instead of am_stimer_cmpr6_isr().
  3. Example3_Test_RTC
    • Not modified.
  4. Example4_Set_Epoch
    • Demonstrates how to set the RTC using UNIX Epoch time.
  5. Example5_Rolling_Alarms
    • Demonstrates how to read and set rolling RTC alarms.
  6. Example6_LowPower_Alarm
    • Demonstrates how to set an RTC alarm and enter/wake from deep sleep.

All code was tested using a SparkFun Redboard Artemis, as well as an Edge 2 to confirm the sleep current draw in Example 6.

Happy to address any major/minor concerns!

Cheers,
Adam

@oclyke
Copy link
Contributor

oclyke commented Jun 5, 2020

@adamgarbo I just want to chime in and let you know this PR is not forgotten - we will get to it as soon as we can :D

@stephenf7072
Copy link
Contributor

Looks like good stuff @adamgarbo. Changing the parameters order of setTime() is not backwards-compatible with anyone (me!) who has written custom code, although it does make more sense. Can I suggest the new version of the function is called "setTimeA()" or something to differentiate it.

@adamgarbo
Copy link
Contributor Author

Thanks @oclyke!

Let me know if there's anything I can do to help!

Cheers,
Adam

@oclyke oclyke changed the base branch from master to release-candidate July 14, 2020 19:58
@oclyke
Copy link
Contributor

oclyke commented Jul 14, 2020

@adamgarbo, @stephenf7072

I'm reviewing right now - about ready to merge. So far the only bother I have is @stephenf7072's comment about backward compatibility of the setTime() function. According to semantic versioning making this change should push us to v2.0.0 (which is planned for soon anyway) but I want to include this as part of a final patch to the v1.x.x lineage.

I do prefer the new order of setTime parameters. Perhaps we can keep the functional changes in this PR and separate the API changes into a new PR that I will bring in along with v2.0.0?

@adamgarbo would you be willing to commit changes that (somehow) revert the API back to its original state?

Copy link
Contributor

@oclyke oclyke left a comment

Choose a reason for hiding this comment

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

Generally looks good. Formatting changes to examples are acceptable. Requesting that the setTime API change is undone in this PR and moved to a separate PR for v2.0.0

@oclyke
Copy link
Contributor

oclyke commented Jul 14, 2020

Just a note - I'm not sure why the test compile jobs are failing. I tried compilation on my local machine and it worked fine. Now that I am more familiar with GitHub actions I may investigate further.

@adamgarbo
Copy link
Contributor Author

Hi @oclyke,

Thanks for getting to this!

I'm happy to revert the order of the setTime parameters until the v2.0.0 release. I will try to get to this soon, as I'll need to change all the examples that make use of the new setTime parameter ordering.

What are your thoughts on the order of the setAlarm parameters? Should they be left as such (i.e. hund, ss, mm, hh, dd, mm), or changed to match setTime (hh, mm, ss, hund, dd, mm)?

Cheers,
Adam

@oclyke
Copy link
Contributor

oclyke commented Jul 15, 2020

Let's match them for this release and then change both APIs at once in v2.0.0

It seems most intuitive that the two would match. I'll see if I can't help with the examples.

In v1.x.x we are using (hh, mm, ss, hund, dom, mon, year)
Planning to change api in v2.0.0 to (hund, mm, ss, hh, dom, mon, year)
@oclyke
Copy link
Contributor

oclyke commented Jul 15, 2020

I've changed setAlarm to match setTime and updated the examples. All compile. I'd appreciate a second pair of eyes for testing to ensure that the examples are accurate.

Copy link
Contributor Author

@adamgarbo adamgarbo left a comment

Choose a reason for hiding this comment

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

Hi @oclyke,

Just reviewed the changes and they all look good!

Cheers,
Adam

@oclyke
Copy link
Contributor

oclyke commented Jul 15, 2020

Just noticed some odd behavior - before my latest commit Example3 was broken. This turned out to be due to unclear logic but it was harder to diagnose because setTime does not appear to update the internal structures myRTC.dayOfMonth etc...

For example:

myRTC.setTime(23, 59, 59, 0, 1, 1, 20);
Serial.printf("weekday: %d\n", myRTC.weekday);

prints
weekday: 0

but

myRTC.setTime(23, 59, 59, 0, 1, 1, 20);
myRTC.getTime();
Serial.printf("weekday: %d\n", myRTC.weekday);

prints
weekday: 3

Is there a reason for this? Or can we change setTime to include a call to getTime internally? This would make a lot more sense to me - after all why would a clock ever have two different times?

@adamgarbo
Copy link
Contributor Author

Hi Owen,

Based on my experiences with a number RTC libraries, I've found that it's actually a common behaviour to need to manually poll/update the RTC before executing a print statement. That being said, I don't see any reason why we couldn't include the bulk of the getTime() function in setTime(). This would basically just involve manually updating the time variables (e.g. hour, minute, second, etc.) when the time is set.

I think one of the reasons for this behaviour is due to the fact we're using the HAL as a middleman to write to the RTC registers.

Cheers,
Adam

oclyke added 2 commits July 16, 2020 11:01
…Time

This allows the user to immediately access correct internal values (myRTC.weekday, myRTC.minute, etc...)

```
  myRTC.setTime(23, 59, 59, 99, myRTC.dayOfMonth, myRTC.month, myRTC.year);
  previousDay = myRTC.weekday;
```

Updated Example3 to make use of this feature
This allows the user to see that the alarm fired 'exactly' when they wanted it to.
Copy link
Contributor

@oclyke oclyke left a comment

Choose a reason for hiding this comment

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

This is all great, thanks @adamgarbo!

@oclyke oclyke merged commit 8dbc5d1 into sparkfun:release-candidate Jul 16, 2020
@adamgarbo adamgarbo deleted the rtcAlarms branch July 16, 2020 17:06
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.

3 participants