@@ -936,30 +936,43 @@ void STM32RTC::setY2kEpoch(uint32_t ts)
936
936
* @brief configure RTC source clock for low power
937
937
* @param none
938
938
*/
939
- void STM32RTC::configForLowPower (void )
939
+ void STM32RTC::configForLowPower (RTC_Source_Clock source )
940
940
{
941
941
#if defined(HAL_PWR_MODULE_ENABLED)
942
942
if (!_configured){
943
- // LSE must be selected as clock source to wakeup the device from shutdown mode
944
- _clockSource = RTC_LSE_CLOCK;
943
+ _clockSource = source;
945
944
// Enable RTC
946
945
begin ();
947
946
} else {
948
- if (_clockSource != RTC_LSE_CLOCK ) {
947
+ if (_clockSource != source ) {
949
948
// Save current config
950
- RTC_AM_PM period;
949
+ RTC_AM_PM period, alarmPeriod = _alarmPeriod ;
951
950
uint32_t subSeconds;
952
951
uint8_t seconds, minutes, hours, weekDay, day, month, years;
952
+ uint8_t alarmSeconds, alarmMinutes, alarmHours, alarmDay;
953
+ Alarm_Match alarmMatch = _alarmMatch;
954
+ bool alarmEnabled = _alarmEnabled;
955
+
956
+ alarmDay = _alarmDay;
957
+ alarmHours = _alarmHours;
958
+ alarmMinutes = _alarmMinutes;
959
+ alarmSeconds = _alarmSeconds;
960
+
953
961
getDate (&weekDay, &day, &month, &years);
954
962
getTime (&seconds, &minutes, &hours, &subSeconds, &period);
963
+
955
964
end ();
956
- // LSE must be selected as clock source to wakeup the device from shutdown mode
957
- _clockSource = RTC_LSE_CLOCK;
965
+ _clockSource = source;
958
966
// Enable RTC
959
967
begin (period);
960
968
// Restore config
961
969
setTime (seconds, minutes, hours, subSeconds, period);
962
970
setDate (weekDay, day, month, years);
971
+ setAlarmTime (alarmHours, alarmMinutes, alarmSeconds, alarmPeriod);
972
+ setAlarmDay (alarmDay);
973
+ if (alarmEnabled) {
974
+ enableAlarm (alarmMatch);
975
+ }
963
976
}
964
977
}
965
978
#endif
0 commit comments