@@ -703,6 +703,20 @@ void STM32RTC::setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year
703703 }
704704}
705705
706+ /* *
707+ * @brief set RTC alarm subseconds.
708+ * @param subseconds: 0-999 (in ms)
709+ * @retval none
710+ */
711+ void STM32RTC::setAlarmSubSeconds (uint32_t subSeconds)
712+ {
713+ if (_configured) {
714+ if (subSeconds < 1000 ) {
715+ _alarmSubSeconds = subSeconds;
716+ }
717+ }
718+ }
719+
706720/* *
707721 * @brief set RTC alarm second.
708722 * @param seconds: 0-59
@@ -768,12 +782,13 @@ void STM32RTC::setAlarmHours(uint8_t hours, AM_PM period)
768782 * @param seconds: 0-59
769783 * @retval none
770784 */
771- void STM32RTC::setAlarmTime (uint8_t hours, uint8_t minutes, uint8_t seconds)
785+ void STM32RTC::setAlarmTime (uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds )
772786{
773787 if (_configured) {
774788 setAlarmHours (hours);
775789 setAlarmMinutes (minutes);
776790 setAlarmSeconds (seconds);
791+ setAlarmSubSeconds (subSeconds);
777792 }
778793}
779794
@@ -848,9 +863,10 @@ void STM32RTC::setAlarmDate(uint8_t day, uint8_t month, uint8_t year)
848863
849864/* *
850865 * @brief get epoch time
866+ * @param subSeconds: optional pointer to where to store subseconds of the epoch in ms
851867 * @retval epoch time in seconds
852868 */
853- uint32_t STM32RTC::getEpoch (void )
869+ uint32_t STM32RTC::getEpoch (uint32_t *subSeconds )
854870{
855871 struct tm tm;
856872
@@ -870,6 +886,9 @@ uint32_t STM32RTC::getEpoch(void)
870886 tm.tm_hour = _hours;
871887 tm.tm_min = _minutes;
872888 tm.tm_sec = _seconds;
889+ if (subSeconds != nullptr ) {
890+ *subSeconds = _subSeconds;
891+ }
873892
874893 return mktime (&tm);
875894}
@@ -886,8 +905,10 @@ uint32_t STM32RTC::getY2kEpoch(void)
886905/* *
887906 * @brief set RTC alarm from epoch time
888907 * @param epoch time in seconds
908+ * @param Alarm_Match match enum
909+ * @param subSeconds subSeconds in ms
889910 */
890- void STM32RTC::setAlarmEpoch (uint32_t ts, Alarm_Match match)
911+ void STM32RTC::setAlarmEpoch (uint32_t ts, Alarm_Match match, uint32_t subSeconds )
891912{
892913 if (_configured) {
893914 if (ts < EPOCH_TIME_OFF) {
@@ -901,15 +922,17 @@ void STM32RTC::setAlarmEpoch(uint32_t ts, Alarm_Match match)
901922 setAlarmHours (tmp->tm_hour );
902923 setAlarmMinutes (tmp->tm_min );
903924 setAlarmSeconds (tmp->tm_sec );
925+ setAlarmSubSeconds (subSeconds);
904926 enableAlarm (match);
905927 }
906928}
907929
908930/* *
909931 * @brief set RTC time from epoch time
910932 * @param epoch time in seconds
933+ * @param subSeconds subSeconds in ms
911934 */
912- void STM32RTC::setEpoch (uint32_t ts)
935+ void STM32RTC::setEpoch (uint32_t ts, uint32_t subSeconds )
913936{
914937 if (_configured) {
915938 if (ts < EPOCH_TIME_OFF) {
@@ -930,6 +953,7 @@ void STM32RTC::setEpoch(uint32_t ts)
930953 _hours = tmp->tm_hour ;
931954 _minutes = tmp->tm_min ;
932955 _seconds = tmp->tm_sec ;
956+ _subSeconds = subSeconds;
933957
934958 RTC_SetDate (_year, _month, _day, _wday);
935959 RTC_SetTime (_hours, _minutes, _seconds, _subSeconds, (_hoursPeriod == AM) ? HOUR_AM : HOUR_PM);
0 commit comments