99#include "runtime.h"
1010#include "rtc.h"
1111
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+
1218RTC_HandleTypeDef RTCHandle ;
1319
1420// rtc_info indicates various things about RTC startup
@@ -159,13 +165,13 @@ void rtc_init(void) {
159165 // fresh reset; configure RTC Calendar
160166 RTC_CalendarConfig ();
161167 } else {
162- // RTC was previously set, so leave it alon
168+ // RTC was previously set, so leave it alone
163169 if (__HAL_RCC_GET_FLAG (RCC_FLAG_PORRST ) != RESET ) {
164- // power on reset occured
170+ // power on reset occurred
165171 rtc_info |= 0x10000 ;
166172 }
167173 if (__HAL_RCC_GET_FLAG (RCC_FLAG_PINRST ) != RESET ) {
168- // external reset occured
174+ // external reset occurred
169175 rtc_info |= 0x20000 ;
170176 }
171177 // Clear source Reset Flag
@@ -213,6 +219,8 @@ typedef struct _pyb_rtc_obj_t {
213219
214220STATIC const pyb_rtc_obj_t pyb_rtc_obj = {{& pyb_rtc_type }};
215221
222+ /// \classmethod \constructor()
223+ /// Create an RTC object.
216224STATIC mp_obj_t pyb_rtc_make_new (mp_obj_t type_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
217225 // check arguments
218226 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
221229 return (mp_obj_t )& pyb_rtc_obj ;
222230}
223231
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
224239mp_obj_t pyb_rtc_info (mp_obj_t self_in ) {
225240 return mp_obj_new_int (rtc_info );
226241}
227242MP_DEFINE_CONST_FUN_OBJ_1 (pyb_rtc_info_obj , pyb_rtc_info );
228243
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.
229258mp_obj_t pyb_rtc_datetime (uint n_args , const mp_obj_t * args ) {
230259 if (n_args == 1 ) {
231260 // get date and time
0 commit comments