@@ -71,6 +71,7 @@ void STM32RTC::begin(bool resetTime, Hour_Format format)
71
71
void STM32RTC::begin (Hour_Format format)
72
72
{
73
73
if (_configured == false ) {
74
+ _format = format;
74
75
RTC_init ((format == HOUR_12) ? HOUR_FORMAT_12 : HOUR_FORMAT_24,
75
76
(_clockSource == LSE_CLOCK) ? ::LSE_CLOCK :
76
77
(_clockSource == HSE_CLOCK) ? ::HSE_CLOCK : ::LSI_CLOCK
@@ -143,7 +144,7 @@ void STM32RTC::setClockSource(Source_Clock source)
143
144
*/
144
145
void STM32RTC::getPrediv (int8_t *predivA, int16_t *predivS)
145
146
{
146
- if ((predivA != NULL ) && (predivS != NULL )) {
147
+ if ((predivA != nullptr ) && (predivS != nullptr )) {
147
148
RTC_getPrediv (predivA, predivS);
148
149
}
149
150
}
@@ -263,14 +264,14 @@ uint8_t STM32RTC::getMinutes(void)
263
264
264
265
/* *
265
266
* @brief get RTC hours.
266
- * @param format: optional (default: NULL )
267
+ * @param format: optional (default: nullptr )
267
268
* pointer to the current hour period set in the RTC: AM or PM
268
269
* @retval return the current hours from the RTC.
269
270
*/
270
271
uint8_t STM32RTC::getHours (AM_PM *period)
271
272
{
272
273
syncTime ();
273
- if (period != NULL ) {
274
+ if (period != nullptr ) {
274
275
*period = _hoursPeriod;
275
276
}
276
277
return _hours;
@@ -282,26 +283,26 @@ uint8_t STM32RTC::getHours(AM_PM *period)
282
283
* @param minutes: pointer to the current minutes
283
284
* @param seconds: pointer to the current seconds
284
285
* @param subSeconds: pointer to the current subSeconds
285
- * @param period: optional (default: NULL )
286
+ * @param period: optional (default: nullptr )
286
287
* pointer to the current hour period set in the RTC: AM or PM
287
288
* @retval none
288
289
*/
289
290
void STM32RTC::getTime (uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period)
290
291
{
291
292
syncTime ();
292
- if (hours != NULL ) {
293
+ if (hours != nullptr ) {
293
294
*hours = _hours;
294
295
}
295
- if (minutes != NULL ) {
296
+ if (minutes != nullptr ) {
296
297
*minutes = _minutes;
297
298
}
298
- if (seconds != NULL ) {
299
+ if (seconds != nullptr ) {
299
300
*seconds = _seconds;
300
301
}
301
- if (subSeconds != NULL ) {
302
+ if (subSeconds != nullptr ) {
302
303
*subSeconds = _subSeconds;
303
304
}
304
- if (period != NULL ) {
305
+ if (period != nullptr ) {
305
306
*period = _hoursPeriod;
306
307
}
307
308
}
@@ -357,16 +358,16 @@ uint8_t STM32RTC::getYear(void)
357
358
void STM32RTC::getDate (uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year)
358
359
{
359
360
syncDate ();
360
- if (weekDay != NULL ) {
361
+ if (weekDay != nullptr ) {
361
362
*weekDay = _wday;
362
363
}
363
- if (day != NULL ) {
364
+ if (day != nullptr ) {
364
365
*day = _day;
365
366
}
366
- if (month != NULL ) {
367
+ if (month != nullptr ) {
367
368
*month = _month;
368
369
}
369
- if (year != NULL ) {
370
+ if (year != nullptr ) {
370
371
*year = _year;
371
372
}
372
373
}
@@ -403,14 +404,14 @@ uint8_t STM32RTC::getAlarmMinutes(void)
403
404
404
405
/* *
405
406
* @brief get RTC alarm hour.
406
- * @param format: optional (default: NULL )
407
+ * @param format: optional (default: nullptr )
407
408
* pointer to the current hour format set in the RTC: AM or PM
408
409
* @retval return the current alarm hour.
409
410
*/
410
411
uint8_t STM32RTC::getAlarmHours (AM_PM *period)
411
412
{
412
413
syncAlarmTime ();
413
- if (period != NULL ) {
414
+ if (period != nullptr ) {
414
415
*period = _alarmPeriod;
415
416
}
416
417
return _alarmHours;
@@ -503,23 +504,7 @@ void STM32RTC::setMinutes(uint8_t minutes)
503
504
/* *
504
505
* @brief set RTC hours.
505
506
* @param hours: 0-23
506
- * @retval none
507
- */
508
- void STM32RTC::setHours (uint8_t hours)
509
- {
510
- if (_configured) {
511
- syncTime ();
512
- if (hours < 24 ) {
513
- _hours = hours;
514
- }
515
- RTC_SetTime (_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM) ? HOUR_AM : HOUR_PM);
516
- }
517
- }
518
-
519
- /* *
520
- * @brief set RTC hours.
521
- * @param hours: 0-23 or 0-12
522
- * @param hours format: AM or PM
507
+ * @param period: hour format AM or PM (optional)
523
508
* @retval none
524
509
*/
525
510
void STM32RTC::setHours (uint8_t hours, AM_PM period)
@@ -529,41 +514,20 @@ void STM32RTC::setHours(uint8_t hours, AM_PM period)
529
514
if (hours < 24 ) {
530
515
_hours = hours;
531
516
}
532
- _hoursPeriod = period;
533
- RTC_SetTime (_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM) ? HOUR_AM : HOUR_PM);
534
- }
535
- }
536
-
537
- /* *
538
- * @brief set RTC time.
539
- * @param hours: 0-23
540
- * @param minutes: 0-59
541
- * @param seconds: 0-59
542
- * @retval none
543
- */
544
- void STM32RTC::setTime (uint8_t hours, uint8_t minutes, uint8_t seconds)
545
- {
546
- if (_configured) {
547
- syncTime ();
548
- if (seconds < 60 ) {
549
- _seconds = seconds;
550
- }
551
- if (minutes < 60 ) {
552
- _minutes = minutes;
553
- }
554
- if (hours < 24 ) {
555
- _hours = hours;
517
+ if (_format == HOUR_12) {
518
+ _hoursPeriod = period;
556
519
}
557
520
RTC_SetTime (_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM) ? HOUR_AM : HOUR_PM);
558
521
}
559
522
}
560
523
561
524
/* *
562
525
* @brief set RTC time.
563
- * @param hours: 0-23 or 0-12
526
+ * @param hours: 0-23
564
527
* @param minutes: 0-59
565
528
* @param seconds: 0-59
566
- * @param hour format: AM or PM
529
+ * @param subSeconds: 0-999 (optional)
530
+ * @param period: hour format AM or PM (optional)
567
531
* @retval none
568
532
*/
569
533
void STM32RTC::setTime (uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, AM_PM period)
@@ -582,7 +546,9 @@ void STM32RTC::setTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t
582
546
if (hours < 24 ) {
583
547
_hours = hours;
584
548
}
585
- _hoursPeriod = period;
549
+ if (_format == HOUR_12) {
550
+ _hoursPeriod = period;
551
+ }
586
552
RTC_SetTime (_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM) ? HOUR_AM : HOUR_PM);
587
553
}
588
554
}
@@ -745,24 +711,10 @@ void STM32RTC::setAlarmMinutes(uint8_t minutes)
745
711
}
746
712
}
747
713
748
- /* *
749
- * @brief set RTC alarm hour.
750
- * @param hour: 0-23
751
- * @retval none
752
- */
753
- void STM32RTC::setAlarmHours (uint8_t hours)
754
- {
755
- if (_configured) {
756
- if (hours < 24 ) {
757
- _alarmHours = hours;
758
- }
759
- }
760
- }
761
-
762
714
/* *
763
715
* @brief set RTC alarm hour.
764
716
* @param hour: 0-23 or 0-12
765
- * @param hour format: AM or PM
717
+ * @param period: hour format AM or PM (optional)
766
718
* @retval none
767
719
*/
768
720
void STM32RTC::setAlarmHours (uint8_t hours, AM_PM period)
@@ -771,24 +723,9 @@ void STM32RTC::setAlarmHours(uint8_t hours, AM_PM period)
771
723
if (hours < 24 ) {
772
724
_alarmHours = hours;
773
725
}
774
- _alarmPeriod = period;
775
- }
776
- }
777
-
778
- /* *
779
- * @brief set RTC alarm time.
780
- * @param hours: 0-23
781
- * @param minutes: 0-59
782
- * @param seconds: 0-59
783
- * @retval none
784
- */
785
- void STM32RTC::setAlarmTime (uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds)
786
- {
787
- if (_configured) {
788
- setAlarmHours (hours);
789
- setAlarmMinutes (minutes);
790
- setAlarmSeconds (seconds);
791
- setAlarmSubSeconds (subSeconds);
726
+ if (_format == HOUR_12) {
727
+ _alarmPeriod = period;
728
+ }
792
729
}
793
730
}
794
731
@@ -797,15 +734,17 @@ void STM32RTC::setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uin
797
734
* @param hours: 0-23
798
735
* @param minutes: 0-59
799
736
* @param seconds: 0-59
800
- * @param hour format: AM or PM
737
+ * @param subSeconds: 0-999 (optional)
738
+ * @param period: hour format AM or PM (optional)
801
739
* @retval none
802
740
*/
803
- void STM32RTC::setAlarmTime (uint8_t hours, uint8_t minutes, uint8_t seconds, AM_PM period)
741
+ void STM32RTC::setAlarmTime (uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds, AM_PM period)
804
742
{
805
743
if (_configured) {
806
744
setAlarmHours (hours, period);
807
745
setAlarmMinutes (minutes);
808
746
setAlarmSeconds (seconds);
747
+ setAlarmSubSeconds (subSeconds);
809
748
}
810
749
}
811
750
0 commit comments