Skip to content

Commit ff701cd

Browse files
committed
Add get methods for clock source, date and time
RTC_Source_Clock getClockSource(void); void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, RTC_AM_PM *period = NULL); void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year); Signed-off-by: Frederic.Pillon <[email protected]>
1 parent fa452ad commit ff701cd

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ _RTC hours mode (12 or 24)_
2121
* **`void begin(RTC_Hour_Format format)`**
2222

2323
_RTC clock source_
24+
* **`RTC_Source_Clock setClockSource(void)`** : get current clock source.
2425
* **`void setClockSource(RTC_Source_Clock source)`** : this function must be called before `begin()`.
2526

2627
_RTC Asynchronous and Synchronous prescaler_
@@ -44,6 +45,10 @@ _Week day configuration_
4445
* **`void setWeekDay(uint8_t weekDay)`**
4546
* **`void setDate(uint8_t weekDay, uint8_t day, uint8_t month, uint8_t year)`**
4647

48+
_Time and date configuration (added for convenience)_
49+
* **`void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, RTC_AM_PM *period = NULL)`**
50+
* **`void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year)`**
51+
4752
Refer to the Arduino RTC documentation for the other functions
4853
http://arduino.cc/en/Reference/RTC
4954

keywords.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ getHours KEYWORD2
2020
getMinutes KEYWORD2
2121
getSeconds KEYWORD2
2222
getSubSeconds KEYWORD2
23+
getTime KEYWORD2
24+
getDate KEYWORD2
2325

2426
setWeekDay KEYWORD2
2527
setDay KEYWORD2
@@ -61,6 +63,7 @@ disableAlarm KEYWORD2
6163
attachInterrupt KEYWORD2
6264
detachInterrupt KEYWORD2
6365

66+
getClockSource KEYWORD2
6467
setClockSource KEYWORD2
6568
isConfigured KEYWORD2
6669

src/STM32RTC.cpp

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ void STM32RTC::end(void)
107107
}
108108
}
109109

110+
/**
111+
* @brief get the RTC clock source.
112+
* @retval clock source: RTC_LSI_CLOCK, RTC_LSE_CLOCK or RTC_HSE_CLOCK
113+
*/
114+
STM32RTC::RTC_Source_Clock STM32RTC::getClockSource(void)
115+
{
116+
return _clockSource;
117+
}
118+
110119
/**
111120
* @brief set the RTC clock source. By default LSI clock is selected. This
112121
* method must be called before begin().
@@ -250,7 +259,7 @@ uint8_t STM32RTC::getMinutes(void)
250259
/**
251260
* @brief get RTC hours.
252261
* @param format: optional (default: NULL)
253-
* pointer to the current hour format set in the RTC: AM or PM
262+
* pointer to the current hour period set in the RTC: AM or PM
254263
* @retval return the current hours from the RTC.
255264
*/
256265
uint8_t STM32RTC::getHours(RTC_AM_PM *period)
@@ -262,6 +271,36 @@ uint8_t STM32RTC::getHours(RTC_AM_PM *period)
262271
return _hours;
263272
}
264273

274+
/**
275+
* @brief get RTC time.
276+
* @param hours: pointer to the current hours
277+
* @param minutes: pointer to the current minutes
278+
* @param seconds: pointer to the current seconds
279+
* @param subSeconds: pointer to the current subSeconds
280+
* @param period: optional (default: NULL)
281+
* pointer to the current hour period set in the RTC: AM or PM
282+
* @retval none
283+
*/
284+
void STM32RTC::getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, RTC_AM_PM *period)
285+
{
286+
syncTime();
287+
if(hours != NULL) {
288+
*hours = _hours;
289+
}
290+
if(minutes != NULL) {
291+
*minutes = _minutes;
292+
}
293+
if(seconds != NULL) {
294+
*seconds = _seconds;
295+
}
296+
if(subSeconds != NULL) {
297+
*subSeconds = _subSeconds;
298+
}
299+
if(period != NULL) {
300+
*period = _hoursPeriod;
301+
}
302+
}
303+
265304
/**
266305
* @brief get RTC week day.
267306
* @retval return the current week day from the RTC.
@@ -302,6 +341,31 @@ uint8_t STM32RTC::getYear(void)
302341
return _year;
303342
}
304343

344+
/**
345+
* @brief get RTC time.
346+
* @param weekDay: pointer to the current weekDay
347+
* @param day: pointer to the current day
348+
* @param month: pointer to the current month
349+
* @param year: pointer to the current year
350+
* @retval none
351+
*/
352+
void STM32RTC::getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year)
353+
{
354+
syncDate();
355+
if(weekDay != NULL) {
356+
*weekDay = _wday;
357+
}
358+
if(day != NULL) {
359+
*day = _day;
360+
}
361+
if(month != NULL) {
362+
*month = _month;
363+
}
364+
if(year != NULL) {
365+
*year = _year;
366+
}
367+
}
368+
305369
/**
306370
* @brief get RTC alarm subsecond.
307371
* @retval return the current alarm subsecond.

src/STM32RTC.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class STM32RTC {
9393

9494
void end(void);
9595

96+
RTC_Source_Clock getClockSource(void);
9697
void setClockSource(RTC_Source_Clock source);
9798

9899
void enableAlarm(Alarm_Match match);
@@ -110,11 +111,13 @@ class STM32RTC {
110111
uint8_t getSeconds(void);
111112
uint8_t getMinutes(void);
112113
uint8_t getHours(RTC_AM_PM *period = NULL);
114+
void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, RTC_AM_PM *period = NULL);
113115

114116
uint8_t getWeekDay(void);
115117
uint8_t getDay(void);
116118
uint8_t getMonth(void);
117119
uint8_t getYear(void);
120+
void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year);
118121

119122
uint32_t getAlarmSubSeconds(void);
120123
uint8_t getAlarmSeconds(void);

0 commit comments

Comments
 (0)