28
28
#define PCF8563T_MONTHS_REG 0x07
29
29
#define PCF8563T_YEARS_REG 0x08
30
30
31
- // allarm management
31
+ // allarm managemet
32
32
#define PCF8563T_MINUTE_ALARM_REG 0x09
33
33
#define PCF8563T_MINUTE_ALARM_AE_M_MASK 0x80
34
34
#define PCF8563T_MINUTE_ALARM_ON 0x7F
49
49
#define PCF8563T_STATUS_2_CLEAR_INT 0xF7
50
50
#define PCF8563T_STATUS_2_INT_OFF 0x7d
51
51
52
+ /* *
53
+ * Object constructor
54
+ *
55
+ */
52
56
PCF8563TClass::PCF8563TClass ()
53
57
{
54
58
}
55
59
60
+ /* *
61
+ * Start the communication with the RTC
62
+ *
63
+ * @return true if the RTC Controller is on the I2C bus, false in case it is not in the bus.
64
+ *
65
+ */
56
66
bool PCF8563TClass::begin ()
57
67
{
58
68
Wire1.begin (); // join i2c bus
@@ -64,12 +74,22 @@ bool PCF8563TClass::begin()
64
74
return false ;
65
75
}
66
76
77
+ /* *
78
+ * Set Year number
79
+ *
80
+ * @param years Year's number
81
+ */
67
82
void PCF8563TClass::setYears (uint8_t years) {
68
83
uint8_t dec = years / 10 ;
69
84
uint8_t unit = years - (dec * 10 );
70
85
writeByte (PCF8563T_YEARS_REG, ((dec << 4 ) + unit));
71
86
}
72
87
88
+ /* *
89
+ * Set Month number
90
+ *
91
+ * @param months Month's number (0 to 12)
92
+ */
73
93
void PCF8563TClass::setMonths (uint8_t months) {
74
94
uint8_t offset = 0 ;
75
95
if (months > 9 ) {
@@ -78,35 +98,65 @@ void PCF8563TClass::setMonths(uint8_t months) {
78
98
writeByte (PCF8563T_MONTHS_REG, months + offset);
79
99
}
80
100
101
+ /* *
102
+ * Set Day number
103
+ *
104
+ * @param days day's number
105
+ */
81
106
void PCF8563TClass::setDays (uint8_t days) {
82
107
uint8_t dec = days / 10 ;
83
108
uint8_t unit = days - (dec * 10 );
84
109
writeByte (PCF8563T_DAYS_REG, ((dec << 4 ) + unit));
85
110
}
86
111
112
+ /* *
113
+ * Set Hour
114
+ *
115
+ * @param hours hour number
116
+ */
87
117
void PCF8563TClass::setHours (uint8_t hours) {
88
118
uint8_t dec = hours / 10 ;
89
119
uint8_t unit = hours - (dec * 10 );
90
120
writeByte (PCF8563T_HOURS_REG, ((dec << 4 ) + unit)); // check formula on datasheet val + 6 * (val / 10)
91
121
}
92
122
123
+ /* *
124
+ * Set Minute
125
+ *
126
+ * @param minutes minute number
127
+ */
93
128
void PCF8563TClass::setMinutes (uint8_t minutes) {
94
129
uint8_t dec = minutes / 10 ;
95
130
uint8_t unit = minutes - (dec * 10 );
96
131
writeByte (PCF8563T_MINUTES_REG, ((dec << 4 ) + unit));
97
132
}
98
133
134
+ /* *
135
+ * Set Second number
136
+ *
137
+ * @param seconds Second number
138
+ */
99
139
void PCF8563TClass::setSeconds (uint8_t seconds) {
100
140
uint8_t dec = seconds / 10 ;
101
141
uint8_t unit = seconds - (dec * 10 );
102
142
writeByte (PCF8563T_VL_SECONDS_REG, ((dec << 4 ) + unit));
103
143
}
104
144
145
+ /* *
146
+ * Get Year number
147
+ *
148
+ * @return number of years
149
+ */
105
150
uint8_t PCF8563TClass::getYears () {
106
151
uint8_t years = readByte (PCF8563T_YEARS_REG);
107
152
return (years & 0x0F ) + ((years >> 4 )*10 );
108
153
}
109
154
155
+ /* *
156
+ * Get Month number
157
+ *
158
+ * @return number of month
159
+ */
110
160
uint8_t PCF8563TClass::getMonths () {
111
161
uint8_t months = readByte (PCF8563T_MONTHS_REG) & 0x1F ;
112
162
if (months > 9 ) {
@@ -116,27 +166,50 @@ uint8_t PCF8563TClass::getMonths() {
116
166
}
117
167
}
118
168
169
+ /* *
170
+ * Get Day number
171
+ *
172
+ * @return number of days
173
+ */
119
174
uint8_t PCF8563TClass::getDays () {
120
175
uint8_t days = readByte (PCF8563T_DAYS_REG);
121
176
return (days & 0x0F ) + ((days >> 4 )*10 );
122
177
}
123
178
179
+ /* *
180
+ * Get Hour number
181
+ *
182
+ * @return number of hours
183
+ */
124
184
uint8_t PCF8563TClass::getHours () {
125
185
uint8_t hours = readByte (PCF8563T_HOURS_REG) & 0x3F ;
126
186
return (hours & 0x0F ) + ((hours >> 4 )*10 );
127
187
}
128
188
189
+ /* *
190
+ * Get Minute number
191
+ *
192
+ * @return number of minutes
193
+ */
129
194
uint8_t PCF8563TClass::getMinutes () {
130
195
uint8_t minutes = (readByte (PCF8563T_MINUTES_REG)) & 0x7F ;
131
196
return (minutes & 0x0F ) + ((minutes >> 4 )*10 );
132
197
}
133
198
199
+ /* *
200
+ * Get Second number
201
+ *
202
+ * @return number of seconds
203
+ */
134
204
uint8_t PCF8563TClass::getSeconds () {
135
205
uint8_t seconds = readByte (PCF8563T_VL_SECONDS_REG) & 0x7F ;
136
206
return (seconds & 0x0F ) + ((seconds >> 4 )*10 );
137
207
}
138
208
139
-
209
+ /* *
210
+ * Set time by epoch
211
+ *
212
+ */
140
213
void PCF8563TClass::setEpoch () {
141
214
struct tm time;
142
215
time.tm_sec = getSeconds ();
@@ -150,6 +223,11 @@ void PCF8563TClass::setEpoch() {
150
223
set_time (seconds);
151
224
}
152
225
226
+ /* *
227
+ * Set time by epoch
228
+ *
229
+ * @param seconds number of seconds
230
+ */
153
231
void PCF8563TClass::setEpoch (time_t seconds) {
154
232
struct tm time;
155
233
_rtc_localtime (seconds, &time, RTC_FULL_LEAP_YEAR_SUPPORT);
@@ -163,7 +241,16 @@ void PCF8563TClass::setEpoch(time_t seconds) {
163
241
set_time (seconds);
164
242
}
165
243
166
-
244
+ /* *
245
+ * Set time by epoch
246
+ *
247
+ * @param years number of years
248
+ * @param mohths number of months
249
+ * @param days number of days
250
+ * @param hours number of hours
251
+ * @param minutes number of minutes
252
+ * @param seconds number of seconds
253
+ */
167
254
void PCF8563TClass::setEpoch (uint8_t years, uint8_t months, uint8_t days, uint8_t hours, uint8_t minutes, uint8_t seconds) {
168
255
struct tm time;
169
256
time_t utcsec;
@@ -179,6 +266,11 @@ void PCF8563TClass::setEpoch(uint8_t years, uint8_t months, uint8_t days, uint8_
179
266
set_time (utcsec);
180
267
}
181
268
269
+ /* *
270
+ * Get epoch number, convert real time to difference between actual time and epoch(Unix time)
271
+ *
272
+ * @return number of seconds after Unix time
273
+ */
182
274
time_t PCF8563TClass::getEpoch () {
183
275
struct tm time;
184
276
time_t seconds;
@@ -194,47 +286,87 @@ time_t PCF8563TClass::getEpoch() {
194
286
return seconds;
195
287
}
196
288
289
+ /* *
290
+ * Enable alarm mode
291
+ *
292
+ */
197
293
void PCF8563TClass::enableAlarm () {
198
294
writeByte (PCF8563T_STATUS_2_REG, (readByte (PCF8563T_STATUS_2_REG) & PCF8563T_STATUS_2_CLEAR_INT) | PCF8563T_STATUS_2_AIE_MASK);
199
295
}
200
296
297
+ /* *
298
+ * Disable alarm mode
299
+ *
300
+ */
201
301
void PCF8563TClass::disableAlarm () {
202
302
writeByte (PCF8563T_STATUS_2_REG, (readByte (PCF8563T_STATUS_2_REG) & PCF8563T_STATUS_2_INT_OFF));
203
303
}
204
304
305
+ /* *
306
+ * Clear alarm status
307
+ *
308
+ */
205
309
void PCF8563TClass::clearAlarm () {
206
310
writeByte (PCF8563T_STATUS_2_REG, (readByte (PCF8563T_STATUS_2_REG) & PCF8563T_STATUS_2_CLEAR_INT) | PCF8563T_STATUS_2_AIE_MASK);
207
311
}
208
312
313
+ /* *
314
+ * Set alarm's minute
315
+ *
316
+ * @param minutes minute number for the Aarm
317
+ * @return none
318
+ */
209
319
void PCF8563TClass::setMinuteAlarm (uint8_t minutes) {
210
320
uint8_t dec = minutes / 10 ;
211
321
uint8_t unit = minutes - (dec * 10 );
212
322
uint8_t min_alarm = PCF8563T_MINUTE_ALARM_ON & ((dec << 4 ) + unit);
213
323
writeByte (PCF8563T_MINUTE_ALARM_REG , min_alarm);
214
324
}
215
325
326
+ /* *
327
+ * Disable and clear the minute of the Alarm
328
+ *
329
+ */
216
330
void PCF8563TClass::disableMinuteAlarm () {
217
331
writeByte (PCF8563T_MINUTE_ALARM_REG, readByte (PCF8563T_MINUTE_ALARM_REG) | PCF8563T_MINUTE_ALARM_AE_M_MASK);
218
332
}
219
333
334
+ /* *
335
+ * Set Alarm's hour
336
+ *
337
+ * @param hours hour number for the Alarm
338
+ */
220
339
void PCF8563TClass::setHourAlarm (uint8_t hours) {
221
340
uint8_t dec = hours / 10 ;
222
341
uint8_t unit = hours - (dec * 10 );
223
342
uint8_t hour_alarm = PCF8563T_HOUR_ALARM_AE_H_MASK & ((dec << 4 ) + unit);
224
343
writeByte (PCF8563T_HOURS_REG, hour_alarm); // check formula on datasheet val + 6 * (val / 10)
225
344
}
226
345
346
+ /* *
347
+ * Disable and clear the hour of the Alarm
348
+ *
349
+ */
227
350
void PCF8563TClass::disableHourAlarm () {
228
351
writeByte (PCF8563T_HOUR_ALARM_REG, readByte (PCF8563T_HOUR_ALARM_REG) | PCF8563T_HOUR_ALARM_AE_H_MASK);
229
352
}
230
353
354
+ /* *
355
+ * Set Alarm's day
356
+ *
357
+ * @param days day number for the Alarm
358
+ */
231
359
void PCF8563TClass::setDayAlarm (uint8_t days) {
232
360
uint8_t dec = days / 10 ;
233
361
uint8_t unit = days - (dec * 10 );
234
362
uint8_t day_alarm = PCF8563T_DAY_ALARM_ON & ((dec << 4 ) + unit);
235
363
writeByte (PCF8563T_DAY_ALARM_REG, day_alarm);
236
364
}
237
365
366
+ /* *
367
+ * Disable and clear the day of the Alarm
368
+ *
369
+ */
238
370
void PCF8563TClass::disableDayAlarm () {
239
371
writeByte (PCF8563T_DAY_ALARM_REG, readByte (PCF8563T_DAY_ALARM_REG) | PCF8563T_DAY_ALARM_AE_D_MASK );
240
372
}
0 commit comments