@@ -92,16 +92,20 @@ void RTC_Handler(void)
92
92
93
93
void RTCZero::enableAlarm (Alarm_Match match)
94
94
{
95
- RTC->MODE2 .Mode2Alarm [0 ].MASK .bit .SEL = match;
96
- while (RTCisSyncing ())
97
- ;
95
+ if (_configured) {
96
+ RTC->MODE2 .Mode2Alarm [0 ].MASK .bit .SEL = match;
97
+ while (RTCisSyncing ())
98
+ ;
99
+ }
98
100
}
99
101
100
102
void RTCZero::disableAlarm ()
101
103
{
102
- RTC->MODE2 .Mode2Alarm [0 ].MASK .bit .SEL = 0x00 ;
103
- while (RTCisSyncing ())
104
- ;
104
+ if (_configured) {
105
+ RTC->MODE2 .Mode2Alarm [0 ].MASK .bit .SEL = 0x00 ;
106
+ while (RTCisSyncing ())
107
+ ;
108
+ }
105
109
}
106
110
107
111
void RTCZero::attachInterrupt (voidFuncPtr callback)
@@ -198,114 +202,146 @@ uint8_t RTCZero::getAlarmYear()
198
202
199
203
void RTCZero::setSeconds (uint8_t seconds)
200
204
{
201
- RTC->MODE2 .CLOCK .bit .SECOND = seconds;
202
- while (RTCisSyncing ())
203
- ;
205
+ if (_configured) {
206
+ RTC->MODE2 .CLOCK .bit .SECOND = seconds;
207
+ while (RTCisSyncing ())
208
+ ;
209
+ }
204
210
}
205
211
206
212
void RTCZero::setMinutes (uint8_t minutes)
207
213
{
208
- RTC->MODE2 .CLOCK .bit .MINUTE = minutes;
209
- while (RTCisSyncing ())
210
- ;
214
+ if (_configured) {
215
+ RTC->MODE2 .CLOCK .bit .MINUTE = minutes;
216
+ while (RTCisSyncing ())
217
+ ;
218
+ }
211
219
}
212
220
213
221
void RTCZero::setHours (uint8_t hours)
214
222
{
215
- RTC->MODE2 .CLOCK .bit .HOUR = hours;
216
- while (RTCisSyncing ())
217
- ;
223
+ if (_configured) {
224
+ RTC->MODE2 .CLOCK .bit .HOUR = hours;
225
+ while (RTCisSyncing ())
226
+ ;
227
+ }
218
228
}
219
229
220
230
void RTCZero::setTime (uint8_t hours, uint8_t minutes, uint8_t seconds)
221
231
{
222
- setSeconds (seconds);
223
- setMinutes (minutes);
224
- setHours (hours);
232
+ if (_configured) {
233
+ setSeconds (seconds);
234
+ setMinutes (minutes);
235
+ setHours (hours);
236
+ }
225
237
}
226
238
227
239
void RTCZero::setDay (uint8_t day)
228
240
{
229
- RTC->MODE2 .CLOCK .bit .DAY = day;
230
- while (RTCisSyncing ())
231
- ;
241
+ if (_configured) {
242
+ RTC->MODE2 .CLOCK .bit .DAY = day;
243
+ while (RTCisSyncing ())
244
+ ;
245
+ }
232
246
}
233
247
234
248
void RTCZero::setMonth (uint8_t month)
235
249
{
236
- RTC->MODE2 .CLOCK .bit .MONTH = month;
237
- while (RTCisSyncing ())
238
- ;
250
+ if (_configured) {
251
+ RTC->MODE2 .CLOCK .bit .MONTH = month;
252
+ while (RTCisSyncing ())
253
+ ;
254
+ }
239
255
}
240
256
241
257
void RTCZero::setYear (uint8_t year)
242
258
{
243
- RTC->MODE2 .CLOCK .bit .YEAR = year;
244
- while (RTCisSyncing ())
245
- ;
259
+ if (_configured) {
260
+ RTC->MODE2 .CLOCK .bit .YEAR = year;
261
+ while (RTCisSyncing ())
262
+ ;
263
+ }
246
264
}
247
265
248
266
void RTCZero::setDate (uint8_t day, uint8_t month, uint8_t year)
249
267
{
250
- setDay (day);
251
- setMonth (month);
252
- setYear (year);
268
+ if (_configured) {
269
+ setDay (day);
270
+ setMonth (month);
271
+ setYear (year);
272
+ }
253
273
}
254
274
255
275
void RTCZero::setAlarmSeconds (uint8_t seconds)
256
276
{
257
- RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .SECOND = seconds;
258
- while (RTCisSyncing ())
259
- ;
277
+ if (_configured) {
278
+ RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .SECOND = seconds;
279
+ while (RTCisSyncing ())
280
+ ;
281
+ }
260
282
}
261
283
262
284
void RTCZero::setAlarmMinutes (uint8_t minutes)
263
285
{
264
- RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .MINUTE = minutes;
265
- while (RTCisSyncing ())
266
- ;
286
+ if (_configured) {
287
+ RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .MINUTE = minutes;
288
+ while (RTCisSyncing ())
289
+ ;
290
+ }
267
291
}
268
292
269
293
void RTCZero::setAlarmHours (uint8_t hours)
270
294
{
271
- RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .HOUR = hours;
272
- while (RTCisSyncing ())
273
- ;
295
+ if (_configured) {
296
+ RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .HOUR = hours;
297
+ while (RTCisSyncing ())
298
+ ;
299
+ }
274
300
}
275
301
276
302
void RTCZero::setAlarmTime (uint8_t hours, uint8_t minutes, uint8_t seconds)
277
303
{
278
- setAlarmSeconds (seconds);
279
- setAlarmMinutes (minutes);
280
- setAlarmHours (hours);
304
+ if (_configured) {
305
+ setAlarmSeconds (seconds);
306
+ setAlarmMinutes (minutes);
307
+ setAlarmHours (hours);
308
+ }
281
309
}
282
310
283
311
void RTCZero::setAlarmDay (uint8_t day)
284
312
{
285
- RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .DAY = day;
286
- while (RTCisSyncing ())
287
- ;
313
+ if (_configured) {
314
+ RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .DAY = day;
315
+ while (RTCisSyncing ())
316
+ ;
317
+ }
288
318
}
289
319
290
320
void RTCZero::setAlarmMonth (uint8_t month)
291
321
{
292
- RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .MONTH = month;
293
- while (RTCisSyncing ())
294
- ;
322
+ if (_configured) {
323
+ RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .MONTH = month;
324
+ while (RTCisSyncing ())
325
+ ;
326
+ }
295
327
}
296
328
297
329
void RTCZero::setAlarmYear (uint8_t year)
298
330
{
299
- RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .YEAR = year;
300
- while (RTCisSyncing ())
301
- ;
331
+ if (_configured) {
332
+ RTC->MODE2 .Mode2Alarm [0 ].ALARM .bit .YEAR = year;
333
+ while (RTCisSyncing ())
334
+ ;
335
+ }
302
336
}
303
337
304
338
void RTCZero::setAlarmDate (uint8_t day, uint8_t month, uint8_t year)
305
339
{
306
- setAlarmDay (day);
307
- setAlarmMonth (month);
308
- setAlarmYear (year);
340
+ if (_configured) {
341
+ setAlarmDay (day);
342
+ setAlarmMonth (month);
343
+ setAlarmYear (year);
344
+ }
309
345
}
310
346
311
347
uint32_t RTCZero::getEpoch ()
@@ -336,27 +372,31 @@ uint32_t RTCZero::getY2kEpoch()
336
372
337
373
void RTCZero::setEpoch (uint32_t ts)
338
374
{
339
- if (ts < EPOCH_TIME_OFF) {
340
- ts = EPOCH_TIME_OFF;
341
- }
375
+ if (_configured) {
376
+ if (ts < EPOCH_TIME_OFF) {
377
+ ts = EPOCH_TIME_OFF;
378
+ }
342
379
343
- time_t t = ts;
344
- struct tm * tmp = gmtime (&t);
380
+ time_t t = ts;
381
+ struct tm * tmp = gmtime (&t);
345
382
346
- RTC->MODE2 .CLOCK .bit .YEAR = tmp->tm_year - EPOCH_TIME_YEAR_OFF;
347
- RTC->MODE2 .CLOCK .bit .MONTH = tmp->tm_mon + 1 ;
348
- RTC->MODE2 .CLOCK .bit .DAY = tmp->tm_mday ;
349
- RTC->MODE2 .CLOCK .bit .HOUR = tmp->tm_hour ;
350
- RTC->MODE2 .CLOCK .bit .MINUTE = tmp->tm_min ;
351
- RTC->MODE2 .CLOCK .bit .SECOND = tmp->tm_sec ;
383
+ RTC->MODE2 .CLOCK .bit .YEAR = tmp->tm_year - EPOCH_TIME_YEAR_OFF;
384
+ RTC->MODE2 .CLOCK .bit .MONTH = tmp->tm_mon + 1 ;
385
+ RTC->MODE2 .CLOCK .bit .DAY = tmp->tm_mday ;
386
+ RTC->MODE2 .CLOCK .bit .HOUR = tmp->tm_hour ;
387
+ RTC->MODE2 .CLOCK .bit .MINUTE = tmp->tm_min ;
388
+ RTC->MODE2 .CLOCK .bit .SECOND = tmp->tm_sec ;
352
389
353
- while (RTCisSyncing ())
354
- ;
390
+ while (RTCisSyncing ())
391
+ ;
392
+ }
355
393
}
356
394
357
395
void RTCZero::setY2kEpoch (uint32_t ts)
358
396
{
359
- setEpoch (ts + EPOCH_TIME_OFF);
397
+ if (_configured) {
398
+ setEpoch (ts + EPOCH_TIME_OFF);
399
+ }
360
400
}
361
401
362
402
/*
0 commit comments