Skip to content

Commit 656c8a2

Browse files
committed
Added the ability to set the match/compare mask
Now by default the interrupt is enabled but the mask is set to no compare.
1 parent a2508d4 commit 656c8a2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/RTCZero.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ void RTCZero::begin(bool timeRep)
6464
NVIC_EnableIRQ(RTC_IRQn); // enable RTC interrupt
6565
NVIC_SetPriority(RTC_IRQn, 0x00);
6666

67-
RTC->MODE2.INTENSET.reg &= ~RTC_MODE2_INTENSET_ALARM0; // disable alarm interrupt by default
67+
RTC->MODE2.INTENSET.reg |= RTC_MODE2_INTENSET_ALARM0; // enable alarm interrupt
68+
RTC->MODE2.Mode2Alarm[0].MASK.bit.SEL = MATCH_OFF; // default alarm match is off (disabled)
6869

6970
while (RTCisSyncing())
7071
;
@@ -78,6 +79,20 @@ void RTC_Handler(void)
7879
RTC->MODE2.INTFLAG.reg = RTC_MODE2_INTFLAG_ALARM0; // must clear flag at end
7980
}
8081

82+
void RTCZero::enableAlarm(Alarm_Match match)
83+
{
84+
RTC->MODE2.Mode2Alarm[0].MASK.bit.SEL = match;
85+
while (RTCisSyncing())
86+
;
87+
}
88+
89+
void RTCZero::disableAlarm()
90+
{
91+
RTC->MODE2.Mode2Alarm[0].MASK.bit.SEL = 0x00;
92+
while (RTCisSyncing())
93+
;
94+
}
95+
8196
/*
8297
* Get Functions
8398
*/

src/RTCZero.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,22 @@
2727
class RTCZero {
2828
public:
2929

30+
enum Alarm_Match: uint8_t
31+
{
32+
MATCH_OFF = 0x00,
33+
MATCH_SS = 0x01,
34+
MATCH_MMSS = 0x02,
35+
MATCH_HHMMSS = 0x03,
36+
MATCH_DHHMMSS = 0x04,
37+
MATCH_MMDDHHMMSS = 0x05,
38+
MATCH_YYMMDDHHMMSS = 0x06
39+
};
40+
3041
RTCZero() {};
3142
void begin(bool timeRep);
43+
44+
void enableAlarm(Alarm_Match match);
45+
void disableAlarm();
3246

3347
/* Get Functions */
3448

0 commit comments

Comments
 (0)