-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathRTCZero.h
121 lines (91 loc) · 3.36 KB
/
RTCZero.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
RTC library for Arduino Zero.
Copyright (c) 2015 Arduino LLC. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef RTC_ZERO_H
#define RTC_ZERO_H
#include "Arduino.h"
#define RTCZERO_FREQCORR(_CORR_) (_CORR_ * 240 * 4096)
typedef void(*voidFuncPtr)(void);
class RTCZero {
public:
enum Alarm_Match: uint8_t // Should we have this enum or just use the identifiers from /component/rtc.h ?
{
MATCH_OFF = RTC_MODE2_MASK_SEL_OFF_Val, // Never
MATCH_SS = RTC_MODE2_MASK_SEL_SS_Val, // Every Minute
MATCH_MMSS = RTC_MODE2_MASK_SEL_MMSS_Val, // Every Hour
MATCH_HHMMSS = RTC_MODE2_MASK_SEL_HHMMSS_Val, // Every Day
MATCH_DHHMMSS = RTC_MODE2_MASK_SEL_DDHHMMSS_Val, // Every Month
MATCH_MMDDHHMMSS = RTC_MODE2_MASK_SEL_MMDDHHMMSS_Val, // Every Year
MATCH_YYMMDDHHMMSS = RTC_MODE2_MASK_SEL_YYMMDDHHMMSS_Val // Once, on a specific date and a specific time
};
RTCZero();
void begin(bool resetTime = false);
void enableAlarm(Alarm_Match match);
void disableAlarm();
void attachInterrupt(voidFuncPtr callback);
void detachInterrupt();
void standbyMode();
/* Get Functions */
uint8_t getSeconds();
uint8_t getMinutes();
uint8_t getHours();
uint8_t getDay();
uint8_t getMonth();
uint8_t getYear();
uint8_t getAlarmSeconds();
uint8_t getAlarmMinutes();
uint8_t getAlarmHours();
uint8_t getAlarmDay();
uint8_t getAlarmMonth();
uint8_t getAlarmYear();
/* Set Functions */
void setSeconds(uint8_t seconds);
void setMinutes(uint8_t minutes);
void setHours(uint8_t hours);
void setTime(uint8_t hours, uint8_t minutes, uint8_t seconds);
void setDay(uint8_t day);
void setMonth(uint8_t month);
void setYear(uint8_t year);
void setDate(uint8_t day, uint8_t month, uint8_t year);
void setAlarmSeconds(uint8_t seconds);
void setAlarmMinutes(uint8_t minutes);
void setAlarmHours(uint8_t hours);
void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds);
void setAlarmDay(uint8_t day);
void setAlarmMonth(uint8_t month);
void setAlarmYear(uint8_t year);
void setAlarmDate(uint8_t day, uint8_t month, uint8_t year);
void setFrequencyCorrection(int8_t correction);
/* Epoch Functions */
time_t getEpoch();
uint32_t getY2kEpoch();
void setEpoch(uint32_t ts);
void setY2kEpoch(uint32_t ts);
void setAlarmEpoch(uint32_t ts);
bool isConfigured() {
return _configured;
}
private:
bool _configured;
void config32kOSC(void);
void configureClock(void);
void RTCreadRequest();
bool RTCisSyncing(void);
void RTCdisable();
void RTCenable();
void RTCreset();
void RTCresetRemove();
};
#endif // RTC_ZERO_H