Skip to content

Commit b50ebb2

Browse files
committed
Add get/set prediv methods
Signed-off-by: Frederic.Pillon <[email protected]>
1 parent d6d2d9f commit b50ebb2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/STM32RTC.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,37 @@ void STM32RTC::setClockSource(RTC_Source_Clock source)
117117
{
118118
if(IS_CLOCK_SOURCE(source)) {
119119
_clockSource = source;
120+
RTC_SetClockSource((_clockSource == RTC_LSE_CLOCK)? LSE_CLOCK:
121+
(_clockSource == RTC_HSE_CLOCK)? HSE_CLOCK : LSI_CLOCK);
122+
}
123+
}
124+
125+
/**
126+
* @brief get user (a)synchronous prescaler values if set else computed
127+
* ones for the current clock source.
128+
* @param predivA: pointer to the current Asynchronous prescaler value
129+
* @param predivS: pointer to the current Synchronous prescaler value
130+
* @retval None
131+
*/
132+
void STM32RTC::getPrediv(int8_t *predivA, int16_t *predivS)
133+
{
134+
if((predivA != NULL) && (predivS != NULL)) {
135+
RTC_getPrediv(predivA, predivS);
120136
}
121137
}
122138

139+
/**
140+
* @brief set user (a)synchronous prescalers value.
141+
* @note This method must be called before begin().
142+
* @param predivA: Asynchronous prescaler value. Reset value: -1
143+
* @param predivS: Synchronous prescaler value. Reset value: -1
144+
* @retval None
145+
*/
146+
void STM32RTC::setPrediv(int8_t predivA, int16_t predivS)
147+
{
148+
RTC_setPrediv(predivA, predivS);
149+
}
150+
123151
/**
124152
* @brief enable the RTC alarm.
125153
* @param match: Alarm_Match configuration

src/STM32RTC.h

+3
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class STM32RTC {
166166
void setY2kEpoch(uint32_t ts);
167167
void setAlarmEpoch(uint32_t ts, Alarm_Match match = MATCH_DHHMMSS);
168168

169+
void getPrediv(int8_t *predivA, int16_t *predivS);
170+
void setPrediv(int8_t predivA, int16_t predivS);
171+
169172
bool isConfigured(void) {
170173
return _configured;
171174
}

0 commit comments

Comments
 (0)