libraries/STM32RTC-1.2.0/src/STM32RTC.cpp
void STM32RTC::configForLowPower(Source_Clock source)
{
#if defined(HAL_PWR_MODULE_ENABLED)
#ifdef __HAL_RCC_RTCAPB_CLKAM_ENABLE
  __HAL_RCC_RTCAPB_CLKAM_ENABLE();
#endif
  if (!_configured) {
    _clockSource = source;
    // Enable RTC
    begin();
  } else {
    if (_clockSource != source) {
      // Save current config
      AM_PM period, alarmPeriod = _alarmPeriod;
      uint32_t subSeconds;
      uint8_t seconds, minutes, hours, weekDay, day, month, years;
      uint8_t alarmSeconds, alarmMinutes, alarmHours, alarmDay;
      Alarm_Match alarmMatch = _alarmMatch;
      bool alarmEnabled = _alarmEnabled;

      alarmDay = _alarmDay;
      alarmHours = _alarmHours;
      alarmMinutes = _alarmMinutes;
      alarmSeconds = _alarmSeconds;

      getDate(&weekDay, &day, &month, &years);
      getTime(&seconds, &minutes, &hours, &subSeconds, &period);

      end();
      _clockSource = source;
      // Enable RTC
      begin(period);
      // Restore config
      setTime(seconds, minutes, hours, subSeconds, period);
      setDate(weekDay, day, month, years);
      setAlarmTime(alarmHours, alarmMinutes, alarmSeconds, alarmPeriod);
      setAlarmDay(alarmDay);
      if (alarmEnabled) {
        enableAlarm(alarmMatch);
      }
    }
  }
#endif
}
/**
  * @brief  configure RTC source clock for low power
  * @param  none
  */
@brief  configure RTC source clock for low power
@param  none
@brief configure RTC source clock for low power @param none
void STM32RTC::configForLowPower(Source_Clock source)
{
#if defined(HAL_PWR_MODULE_ENABLED)
#ifdef __HAL_RCC_RTCAPB_CLKAM_ENABLE
  __HAL_RCC_RTCAPB_CLKAM_ENABLE();
#endif
  if (!_configured) {
    _clockSource = source;
    begin();
  } else {
    if (_clockSource != source) {
      AM_PM period, alarmPeriod = _alarmPeriod;
      uint32_t subSeconds;
      uint8_t seconds, minutes, hours, weekDay, day, month, years;
      uint8_t alarmSeconds, alarmMinutes, alarmHours, alarmDay;
      Alarm_Match alarmMatch = _alarmMatch;
      bool alarmEnabled = _alarmEnabled;
      alarmDay = _alarmDay;
      alarmHours = _alarmHours;
      alarmMinutes = _alarmMinutes;
      alarmSeconds = _alarmSeconds;
      getDate(&weekDay, &day, &month, &years);
      getTime(&seconds, &minutes, &hours, &subSeconds, &period);
      end();
      _clockSource = source;
      begin(period);
      setTime(seconds, minutes, hours, subSeconds, period);
      setDate(weekDay, day, month, years);
      setAlarmTime(alarmHours, alarmMinutes, alarmSeconds, alarmPeriod);
      setAlarmDay(alarmDay);
      if (alarmEnabled) {
        enableAlarm(alarmMatch);
      }
    }
  }
#endif
}
void STM32RTC :: configForLowPower ( Source_Clock source ) { #if defined ( HAL_PWR_MODULE_ENABLED ) #ifdef __HAL_RCC_RTCAPB_CLKAM_ENABLE __HAL_RCC_RTCAPB_CLKAM_ENABLE ( ) ; #endif if ( ! _configured ) { _clockSource = source ; begin ( ) ; } else { if ( _clockSource != source ) { AM_PM period , alarmPeriod = _alarmPeriod ; uint32_t subSeconds ; uint8_t seconds , minutes , hours , weekDay , day , month , years ; uint8_t alarmSeconds , alarmMinutes , alarmHours , alarmDay ; Alarm_Match alarmMatch = _alarmMatch ; bool alarmEnabled = _alarmEnabled ; alarmDay = _alarmDay ; alarmHours = _alarmHours ; alarmMinutes = _alarmMinutes ; alarmSeconds = _alarmSeconds ; getDate ( & weekDay , & day , & month , & years ) ; getTime ( & seconds , & minutes , & hours , & subSeconds , & period ) ; end ( ) ; _clockSource = source ; begin ( period ) ; setTime ( seconds , minutes , hours , subSeconds , period ) ; setDate ( weekDay , day , month , years ) ; setAlarmTime ( alarmHours , alarmMinutes , alarmSeconds , alarmPeriod ) ; setAlarmDay ( alarmDay ) ; if ( alarmEnabled ) { enableAlarm ( alarmMatch ) ; } } } #endif }
@brief  configure RTC source clock for low power
 @param  none
@brief configure RTC source clock for low power @param none
// Enable RTC // Save current config // Enable RTC // Restore config