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.
6
6
This library is based on the Arduino RTCZero library.
7
7
The library allows to take control of the internal RTC of the STM32 boards.
8
8
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
+
9
15
The following functions are not supported:
10
16
11
17
* ** ` void standbyMode() ` ** : use the STM32 Low Power library instead.
Original file line number Diff line number Diff line change 38
38
39
39
#include < STM32RTC.h>
40
40
41
- /* Create a rtc object */
42
- STM32RTC rtc;
41
+ /* Get the rtc object */
42
+ STM32RTC& rtc = STM32RTC::getInstance() ;
43
43
44
44
void setup () {
45
45
Serial.begin (9600 );
Original file line number Diff line number Diff line change 39
39
40
40
#include < STM32RTC.h>
41
41
42
- /* Create a rtc object */
43
- STM32RTC rtc;
42
+ /* Get the rtc object */
43
+ STM32RTC& rtc = STM32RTC::getInstance() ;
44
44
45
45
/* Change these values to set the current initial time */
46
46
const byte seconds = 0 ;
Original file line number Diff line number Diff line change 38
38
39
39
#include < STM32RTC.h>
40
40
41
- /* Create a rtc object */
42
- STM32RTC rtc;
41
+ /* Get the rtc object */
42
+ STM32RTC& rtc = STM32RTC::getInstance() ;
43
43
44
44
/* Change these values to set the current initial time */
45
45
const byte seconds = 0 ;
Original file line number Diff line number Diff line change 38
38
39
39
#include < STM32RTC.h>
40
40
41
- /* Create a rtc object */
42
- STM32RTC rtc;
41
+ /* Get the rtc object */
42
+ STM32RTC& rtc = STM32RTC::getInstance() ;
43
43
44
44
/* Change these values to set the current initial time */
45
45
const byte seconds = 0 ;
Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ STM32RTC KEYWORD1
12
12
# Methods and Functions (KEYWORD2)
13
13
#######################################
14
14
15
+ getInstance KEYWORD2
16
+
15
17
getWeekDay KEYWORD2
16
18
getDay KEYWORD2
17
19
getMonth KEYWORD2
Original file line number Diff line number Diff line change 46
46
// Initialize static variable
47
47
bool STM32RTC::_configured = false ;
48
48
49
- STM32RTC::STM32RTC (void ): _clockSource(RTC_LSI_CLOCK)
50
- {
51
-
52
- }
53
-
54
49
/* *
55
50
* @brief initializes the RTC
56
51
* @param resetTime: if true reconfigures the RTC
Original file line number Diff line number Diff line change @@ -86,7 +86,14 @@ class STM32RTC {
86
86
RTC_HSE_CLOCK = HSE_CLOCK
87
87
};
88
88
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 ;
90
97
91
98
void begin (bool resetTime, RTC_Hour_Format format = RTC_HOUR_24);
92
99
void begin (RTC_Hour_Format format = RTC_HOUR_24);
@@ -177,6 +184,8 @@ class STM32RTC {
177
184
}
178
185
179
186
private:
187
+ STM32RTC (void ): _clockSource(RTC_LSI_CLOCK) {}
188
+
180
189
static bool _configured;
181
190
182
191
RTC_AM_PM _hoursPeriod;
@@ -202,6 +211,7 @@ class STM32RTC {
202
211
void syncTime (void );
203
212
void syncDate (void );
204
213
void syncAlarmTime (void );
214
+
205
215
};
206
216
207
217
#endif // __STM32_RTC_H
You can’t perform that action at this time.
0 commit comments