Skip to content

Commit aa09d6e

Browse files
committed
add setAlarmEpoch and isConfigured API
1 parent 9659d83 commit aa09d6e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/RTCZero.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,21 @@ uint32_t RTCZero::getY2kEpoch()
382382
return (getEpoch() - EPOCH_TIME_OFF);
383383
}
384384

385+
void RTCZero::setAlarmEpoch(uint32_t ts)
386+
{
387+
if (_configured) {
388+
if (ts < EPOCH_TIME_OFF) {
389+
ts = EPOCH_TIME_OFF;
390+
}
391+
392+
time_t t = ts;
393+
struct tm* tmp = gmtime(&t);
394+
395+
setAlarmDate(tmp->tm_year - EPOCH_TIME_YEAR_OFF, tmp->tm_mon + 1, tmp->tm_mday);
396+
setAlarmTime(tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
397+
}
398+
}
399+
385400
void RTCZero::setEpoch(uint32_t ts)
386401
{
387402
if (_configured) {

src/RTCZero.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ class RTCZero {
9595
uint32_t getY2kEpoch();
9696
void setEpoch(uint32_t ts);
9797
void setY2kEpoch(uint32_t ts);
98+
void setAlarmEpoch(uint32_t ts);
99+
100+
bool isConfigured() {
101+
_configured = RTC->MODE2.CTRL.reg & RTC_MODE2_CTRL_ENABLE;
102+
configureClock();
103+
return _configured;
104+
}
98105

99106
private:
100107
bool _configured;

0 commit comments

Comments
 (0)