Skip to content

Commit 9659d83

Browse files
committed
wrap peripheral clock configuration in its own private function
1 parent 5f80582 commit 9659d83

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/RTCZero.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,7 @@ void RTCZero::begin(bool resetTime)
5252
}
5353

5454
// Setup clock GCLK2 with OSC32K divided by 32
55-
GCLK->GENDIV.reg = GCLK_GENDIV_ID(2)|GCLK_GENDIV_DIV(4);
56-
while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY)
57-
;
58-
GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_XOSC32K | GCLK_GENCTRL_ID(2) | GCLK_GENCTRL_DIVSEL );
59-
while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY)
60-
;
61-
GCLK->CLKCTRL.reg = (uint32_t)((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK2 | (RTC_GCLK_ID << GCLK_CLKCTRL_ID_Pos)));
62-
while (GCLK->STATUS.bit.SYNCBUSY)
63-
;
55+
configureClock();
6456

6557
RTCdisable();
6658

@@ -419,6 +411,19 @@ void RTCZero::setY2kEpoch(uint32_t ts)
419411
}
420412
}
421413

414+
/* Attach peripheral clock to 32k oscillator */
415+
void RTCZero::configureClock() {
416+
GCLK->GENDIV.reg = GCLK_GENDIV_ID(2)|GCLK_GENDIV_DIV(4);
417+
while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY)
418+
;
419+
GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_XOSC32K | GCLK_GENCTRL_ID(2) | GCLK_GENCTRL_DIVSEL );
420+
while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY)
421+
;
422+
GCLK->CLKCTRL.reg = (uint32_t)((GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK2 | (RTC_GCLK_ID << GCLK_CLKCTRL_ID_Pos)));
423+
while (GCLK->STATUS.bit.SYNCBUSY)
424+
;
425+
}
426+
422427
/*
423428
* Private Utility Functions
424429
*/

src/RTCZero.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class RTCZero {
100100
bool _configured;
101101

102102
void config32kOSC(void);
103+
void configureClock(void);
103104
void RTCreadRequest();
104105
bool RTCisSyncing(void);
105106
void RTCdisable();

0 commit comments

Comments
 (0)