File tree Expand file tree Collapse file tree 8 files changed +27
-14
lines changed Expand file tree Collapse file tree 8 files changed +27
-14
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ A RTC library for STM32.
66This library is based on the Arduino RTCZero library.
77The library allows to take control of the internal RTC of the STM32 boards.
88
9+ Singleton design pattern is used to ensure that only one STM32RTC instance is instantiated:
10+ ```
11+ /* Get the rtc object */
12+ STM32RTC& rtc = STM32RTC::getInstance();
13+ ```
14+
915The following functions are not supported:
1016
1117* ** ` void standbyMode() ` ** : use the STM32 Low Power library instead.
Original file line number Diff line number Diff line change 3838
3939#include < STM32RTC.h>
4040
41- /* Create a rtc object */
42- STM32RTC rtc;
41+ /* Get the rtc object */
42+ STM32RTC& rtc = STM32RTC::getInstance() ;
4343
4444void setup () {
4545 Serial.begin (9600 );
Original file line number Diff line number Diff line change 3939
4040#include < STM32RTC.h>
4141
42- /* Create a rtc object */
43- STM32RTC rtc;
42+ /* Get the rtc object */
43+ STM32RTC& rtc = STM32RTC::getInstance() ;
4444
4545/* Change these values to set the current initial time */
4646const byte seconds = 0 ;
Original file line number Diff line number Diff line change 3838
3939#include < STM32RTC.h>
4040
41- /* Create a rtc object */
42- STM32RTC rtc;
41+ /* Get the rtc object */
42+ STM32RTC& rtc = STM32RTC::getInstance() ;
4343
4444/* Change these values to set the current initial time */
4545const byte seconds = 0 ;
Original file line number Diff line number Diff line change 3838
3939#include < STM32RTC.h>
4040
41- /* Create a rtc object */
42- STM32RTC rtc;
41+ /* Get the rtc object */
42+ STM32RTC& rtc = STM32RTC::getInstance() ;
4343
4444/* Change these values to set the current initial time */
4545const byte seconds = 0 ;
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ STM32RTC KEYWORD1
1212# Methods and Functions (KEYWORD2)
1313#######################################
1414
15+ getInstance KEYWORD2
16+
1517getWeekDay KEYWORD2
1618getDay KEYWORD2
1719getMonth KEYWORD2
Original file line number Diff line number Diff line change 4646// Initialize static variable
4747bool STM32RTC::_configured = false ;
4848
49- STM32RTC::STM32RTC (void ): _clockSource(RTC_LSI_CLOCK)
50- {
51-
52- }
53-
5449/* *
5550 * @brief initializes the RTC
5651 * @param resetTime: if true reconfigures the RTC
Original file line number Diff line number Diff line change @@ -86,7 +86,14 @@ class STM32RTC {
8686 RTC_HSE_CLOCK = HSE_CLOCK
8787 };
8888
89- STM32RTC ();
89+ static STM32RTC& getInstance () {
90+ static STM32RTC instance; // Guaranteed to be destroyed.
91+ // Instantiated on first use.
92+ return instance;
93+ }
94+
95+ STM32RTC (STM32RTC const &) = delete ;
96+ void operator =(STM32RTC const &) = delete ;
9097
9198 void begin (bool resetTime, RTC_Hour_Format format = RTC_HOUR_24);
9299 void begin (RTC_Hour_Format format = RTC_HOUR_24);
@@ -177,6 +184,8 @@ class STM32RTC {
177184 }
178185
179186private:
187+ STM32RTC (void ): _clockSource(RTC_LSI_CLOCK) {}
188+
180189 static bool _configured;
181190
182191 RTC_AM_PM _hoursPeriod;
@@ -202,6 +211,7 @@ class STM32RTC {
202211 void syncTime (void );
203212 void syncDate (void );
204213 void syncAlarmTime (void );
214+
205215};
206216
207217#endif // __STM32_RTC_H
You can’t perform that action at this time.
0 commit comments