9
9
#include "runtime.h"
10
10
#include "rtc.h"
11
11
12
+ /// \moduleref pyb
13
+ /// \class RTC - real time clock
14
+ ///
15
+ /// The RTC is and independent clock that keeps track of the date
16
+ /// and time.
17
+
12
18
RTC_HandleTypeDef RTCHandle ;
13
19
14
20
// rtc_info indicates various things about RTC startup
@@ -159,13 +165,13 @@ void rtc_init(void) {
159
165
// fresh reset; configure RTC Calendar
160
166
RTC_CalendarConfig ();
161
167
} else {
162
- // RTC was previously set, so leave it alon
168
+ // RTC was previously set, so leave it alone
163
169
if (__HAL_RCC_GET_FLAG (RCC_FLAG_PORRST ) != RESET ) {
164
- // power on reset occured
170
+ // power on reset occurred
165
171
rtc_info |= 0x10000 ;
166
172
}
167
173
if (__HAL_RCC_GET_FLAG (RCC_FLAG_PINRST ) != RESET ) {
168
- // external reset occured
174
+ // external reset occurred
169
175
rtc_info |= 0x20000 ;
170
176
}
171
177
// Clear source Reset Flag
@@ -213,6 +219,8 @@ typedef struct _pyb_rtc_obj_t {
213
219
214
220
STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{& pyb_rtc_type }};
215
221
222
+ /// \classmethod \constructor()
223
+ /// Create an RTC object.
216
224
STATIC mp_obj_t pyb_rtc_make_new (mp_obj_t type_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
217
225
// check arguments
218
226
mp_arg_check_num (n_args , n_kw , 0 , 0 , false);
@@ -221,11 +229,32 @@ STATIC mp_obj_t pyb_rtc_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
221
229
return (mp_obj_t )& pyb_rtc_obj ;
222
230
}
223
231
232
+ /// \method info()
233
+ /// Get information about the startup time and reset source.
234
+ ///
235
+ /// - The lower 0xffff are the number of milliseconds the RTC took to
236
+ /// start up.
237
+ /// - Bit 0x10000 is set if a power-on reset occurred.
238
+ /// - Bit 0x20000 is set if an external reset occurred
224
239
mp_obj_t pyb_rtc_info (mp_obj_t self_in ) {
225
240
return mp_obj_new_int (rtc_info );
226
241
}
227
242
MP_DEFINE_CONST_FUN_OBJ_1 (pyb_rtc_info_obj , pyb_rtc_info );
228
243
244
+ /// \method datetime([datetimetuple])
245
+ /// Get or set the date and time of the RTC.
246
+ ///
247
+ /// With no arguments, this method returns an 8-tuple with the current
248
+ /// date and time. With 1 argument (being an 8-tuple) it sets the date
249
+ /// and time.
250
+ ///
251
+ /// The 8-tuple has the following format:
252
+ ///
253
+ /// (year, month, day, weekday, hours, minutes, seconds, subseconds)
254
+ ///
255
+ /// `weekday` is 1-7 for Monday through Sunday.
256
+ ///
257
+ /// `subseconds` is 0-59.
229
258
mp_obj_t pyb_rtc_datetime (uint n_args , const mp_obj_t * args ) {
230
259
if (n_args == 1 ) {
231
260
// get date and time
0 commit comments