24
24
25
25
static const uint8_t daysInMonth[12 ] = { 31 ,28 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31 };
26
26
27
- static bool __time24 = false ;
28
-
29
27
voidFuncPtr RTC_callBack = NULL ;
30
28
29
+ RTCZero::RTCZero ()
30
+ {
31
+ _time24 = false ;
32
+ }
33
+
31
34
void RTCZero::begin (bool timeRep)
32
35
{
33
36
uint16_t tmp_reg = 0 ;
34
37
35
38
if (timeRep)
36
- __time24 = true ; // 24h representation chosen
39
+ _time24 = true ; // 24h representation chosen
37
40
38
41
PM->APBAMASK .reg |= PM_APBAMASK_RTC; // turn on digital interface clock
39
42
config32kOSC ();
@@ -58,7 +61,7 @@ void RTCZero::begin(bool timeRep)
58
61
tmp_reg &= ~RTC_MODE2_CTRL_MATCHCLR; // disable clear on match
59
62
60
63
// According to the datasheet RTC_MODE2_CTRL_CLKREP = 0 for 24h
61
- if (timeRep )
64
+ if (_time24 )
62
65
tmp_reg &= ~RTC_MODE2_CTRL_CLKREP; // 24h time representation
63
66
else
64
67
tmp_reg |= RTC_MODE2_CTRL_CLKREP; // 12h time representation
@@ -80,9 +83,6 @@ void RTCZero::begin(bool timeRep)
80
83
81
84
RTCenable ();
82
85
RTCresetRemove ();
83
-
84
- // The clock does not seem to sync until the first tick
85
- delay (1000 );
86
86
}
87
87
88
88
void RTC_Handler (void )
@@ -136,7 +136,7 @@ uint8_t RTCZero::getHours()
136
136
{
137
137
uint8_t hours = RTC->MODE2 .CLOCK .bit .HOUR ;
138
138
139
- if (!__time24 ) {
139
+ if (!_time24 ) {
140
140
hours &= ~RTC_MODE2_CLOCK_HOUR_PM_Val;
141
141
}
142
142
@@ -147,7 +147,7 @@ uint8_t RTCZero::getAM_PM()
147
147
{
148
148
uint8_t result = RTC_AM_PM::RTC_AM;
149
149
150
- if (__time24 ) {
150
+ if (_time24 ) {
151
151
if (RTC->MODE2 .CLOCK .bit .HOUR > 11 ) {
152
152
result = RTC_AM_PM::RTC_PM;
153
153
}
@@ -190,7 +190,7 @@ uint8_t RTCZero::getAlarmHours()
190
190
{
191
191
uint8_t hours = RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .HOUR ;
192
192
193
- if (!__time24 ) {
193
+ if (!_time24 ) {
194
194
hours &= ~RTC_MODE2_CLOCK_HOUR_PM_Val;
195
195
}
196
196
@@ -201,7 +201,7 @@ uint8_t RTCZero::getAlarmAM_PM()
201
201
{
202
202
uint8_t result = RTC_AM_PM::RTC_AM;
203
203
204
- if (__time24 ) {
204
+ if (_time24 ) {
205
205
if (RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .HOUR > 11 ) {
206
206
result = RTC_AM_PM::RTC_PM;
207
207
}
@@ -250,7 +250,7 @@ void RTCZero::setMinutes(uint8_t minutes)
250
250
251
251
void RTCZero::setHours (uint8_t hours, uint8_t am_pm)
252
252
{
253
- if (!__time24 )
253
+ if (!_time24 )
254
254
{
255
255
if (hours > 12 ) {
256
256
hours -= 12 ;
@@ -317,7 +317,7 @@ void RTCZero::setAlarmMinutes(uint8_t minutes)
317
317
318
318
void RTCZero::setAlarmHours (uint8_t hours, uint8_t am_pm)
319
319
{
320
- if (!__time24 )
320
+ if (!_time24 )
321
321
{
322
322
if (hours > 12 ) {
323
323
hours -= 12 ;
@@ -376,6 +376,7 @@ uint32_t RTCZero::getEpoch()
376
376
uint32_t RTCZero::getY2kEpoch ()
377
377
{
378
378
uint16_t days = RTC->MODE2 .CLOCK .bit .DAY ;
379
+ days = days > 0 ? days : 1 ;
379
380
uint8_t months = RTC->MODE2 .CLOCK .bit .MONTH ;
380
381
uint16_t years = RTC->MODE2 .CLOCK .bit .YEAR ;
381
382
@@ -386,12 +387,11 @@ uint32_t RTCZero::getY2kEpoch()
386
387
if ((months > 2 ) && (years % 4 == 0 )) {
387
388
++days;
388
389
}
389
-
390
390
days += 365 * years + (years + 3 ) / 4 - 1 ;
391
-
391
+
392
392
uint8_t hours = RTC->MODE2 .CLOCK .bit .HOUR ;
393
393
394
- if (!__time24 ) {
394
+ if (!_time24 ) {
395
395
uint8_t pm = hours & RTC_MODE2_CLOCK_HOUR_PM_Val;
396
396
hours &= ~RTC_MODE2_CLOCK_HOUR_PM_Val;
397
397
0 commit comments