5757 DECLARE TYPES
5858 ******************************************************************************/
5959typedef struct {
60- mp_obj_t callback ;
6160 uint32_t alarm_sec ;
6261 uint16_t alarm_msec ;
6362 uint8_t pwrmode ;
@@ -66,7 +65,7 @@ typedef struct {
6665/******************************************************************************
6766 DECLARE PRIVATE DATA
6867 ******************************************************************************/
69- STATIC pybrtc_data_t pybrtc_data = {. callback = mp_const_none } ;
68+ STATIC pybrtc_data_t pybrtc_data ;
7069STATIC const mp_cb_methods_t pybrtc_cb_methods ;
7170
7271/******************************************************************************
@@ -159,7 +158,7 @@ mp_obj_t pyb_rtc_datetime(mp_uint_t n_args, const mp_obj_t *args) {
159158 return mp_const_none ;
160159 }
161160}
162- MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (pyb_rtc_datetime_obj , 1 , 2 , pyb_rtc_datetime );
161+ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (pyb_rtc_datetime_obj , 1 , 2 , pyb_rtc_datetime );
163162
164163/// \method callback(handler, intmode, value, priority, pwrmode)
165164/// Creates a callback object associated with the real time clock
@@ -170,7 +169,8 @@ STATIC mp_obj_t pyb_rtc_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp
170169 mp_arg_parse_all (n_args - 1 , pos_args + 1 , kw_args , mpcallback_INIT_NUM_ARGS , mpcallback_init_args , args );
171170
172171 // check if any parameters were passed
173- if (kw_args -> used > 0 || pybrtc_data .callback == mp_const_none ) {
172+ mp_obj_t _callback = mpcallback_find ((mp_obj_t )& pyb_rtc_obj );
173+ if (kw_args -> used > 0 || _callback == mp_const_none ) {
174174 uint32_t seconds ;
175175 uint16_t mseconds ;
176176 // get the seconds and the milliseconds from the RTC
@@ -195,11 +195,10 @@ STATIC mp_obj_t pyb_rtc_callback (mp_uint_t n_args, const mp_obj_t *pos_args, mp
195195 pybrtc_data .alarm_msec = mseconds ;
196196 pybrtc_data .pwrmode = args [4 ].u_int ;
197197
198- // create the callback
199- pybrtc_data . callback = mpcallback_new ((mp_obj_t )& pyb_rtc_obj , args [1 ].u_obj , & pybrtc_cb_methods );
198+ // create the new callback
199+ _callback = mpcallback_new ((mp_obj_t )& pyb_rtc_obj , args [1 ].u_obj , & pybrtc_cb_methods );
200200 }
201-
202- return pybrtc_data .callback ;
201+ return _callback ;
203202}
204203STATIC MP_DEFINE_CONST_FUN_OBJ_KW (pyb_rtc_callback_obj , 1 , pyb_rtc_callback );
205204
0 commit comments