Skip to content

Commit

Permalink
Fix #280: add ability to set clock
Browse files Browse the repository at this point in the history
  • Loading branch information
terrillmoore committed Feb 3, 2021
1 parent 3b9fed0 commit 60a6a54
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CatenaRTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CatenaRTC
bool begin(bool fResetTime = false);

CalendarTime GetTime();

bool SetTime(const CalendarTime *pTime);
void SetAlarm(uint32_t delta);

void SetAlarm(const CalendarTime *pNow);
Expand Down
5 changes: 5 additions & 0 deletions src/CatenaSamd21.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class CatenaSamd21 : public CatenaBase
return this->m_Rtc.GetTime();
}

bool SetCalendarTime(const CatenaRTC::CalendarTime &calendarTime)
{
return this->m_Rtc.SetTime(&calendarTime);
}

protected:
virtual void registerCommands(void);

Expand Down
5 changes: 5 additions & 0 deletions src/CatenaStm32L0.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class CatenaStm32L0 : public CatenaStm32
return this->m_Rtc.GetTime();
}

bool SetCalendarTime(const CatenaStm32L0Rtc::CalendarTime &calendarTime)
{
return this->m_Rtc.SetTime(&calendarTime);
}

virtual uint32_t CalibrateSystemClock(void) override;

protected:
Expand Down
16 changes: 16 additions & 0 deletions src/lib/samd/CatenaRTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ const uint16_t CatenaRTC::md[13] =
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
};

bool
CatenaRTC::SetTime(const CatenaRTC::CalendarTime *pTime)
{
RTC_MODE2_CLOCK_Type Mode2Clock;

Mode2Clock.bit.SECOND = pTime->Second;
Mode2Clock.bit.MINUTE = pTime->Minute;
Mode2Clock.bit.HOUR = pTime->Hour;
Mode2Clock.bit.DAY = pTime->Day;
Mode2Clock.bit.MONTH = pTime->Month;
Mode2Clock.bit.YEAR = pTime->Year;

RTC->MODE2.CLOCK.reg = Mode2Clock.reg;
RtcWaitSynchronize();
return true;
}

CatenaRTC::CalendarTime
CatenaRTC::GetTime(void)
Expand Down

0 comments on commit 60a6a54

Please sign in to comment.