@@ -39,6 +39,8 @@ typedef struct _machine_rtc_obj_t {
39
39
mp_obj_base_t base ;
40
40
RTC_HandleTypeDef * rtc ;
41
41
mp_obj_t callback ;
42
+ mp_int_t period ;
43
+ mp_int_t type ;
42
44
} machine_rtc_obj_t ;
43
45
44
46
RTC_HandleTypeDef RTCHandle0 = {.config .p_instance = NULL , .id = 0 };
@@ -53,6 +55,11 @@ STATIC void hal_interrupt_handle(NRF_RTC_Type * p_instance) {
53
55
if (p_instance == RTC0 ) {
54
56
const machine_rtc_obj_t * self = & machine_rtc_obj [0 ];
55
57
mp_call_function_0 (self -> callback );
58
+
59
+ hal_rtc_stop (& self -> rtc -> config );
60
+ if (self -> type == 1 ) {
61
+ hal_rtc_start (& self -> rtc -> config , self -> period );
62
+ }
56
63
} else if (p_instance == RTC1 ) {
57
64
const machine_rtc_obj_t * self = & machine_rtc_obj [1 ];
58
65
mp_call_function_0 (self -> callback );
@@ -111,7 +118,7 @@ STATIC void rtc_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind)
111
118
from machine import RTC
112
119
def cb():
113
120
print("Callback")
114
- r = RTC(0, 8, cb)
121
+ r = RTC(0, 8, cb, type=RTC.PERIODIC )
115
122
r.start(16)
116
123
*/
117
124
@@ -120,6 +127,7 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
120
127
{ MP_QSTR_id , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = mp_const_none } },
121
128
{ MP_QSTR_frequency , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = mp_const_none } },
122
129
{ MP_QSTR_callback , MP_ARG_REQUIRED | MP_ARG_OBJ , {.u_obj = mp_const_none } },
130
+ { MP_QSTR_type , MP_ARG_KW_ONLY | MP_ARG_INT , {.u_int = 0 } },
123
131
};
124
132
125
133
// parse args
@@ -150,6 +158,8 @@ STATIC mp_obj_t machine_rtc_make_new(const mp_obj_type_t *type, size_t n_args, s
150
158
self -> callback = args [2 ].u_obj ;
151
159
}
152
160
161
+ self -> type = args [3 ].u_int ;
162
+
153
163
hal_rtc_init (& self -> rtc -> config );
154
164
155
165
return MP_OBJ_FROM_PTR (self );
@@ -163,6 +173,8 @@ STATIC mp_obj_t machine_rtc_start(mp_obj_t self_in, mp_obj_t period_in) {
163
173
machine_rtc_obj_t * self = MP_OBJ_TO_PTR (self_in );
164
174
mp_int_t period = mp_obj_get_int (period_in );
165
175
176
+ self -> period = mp_obj_get_int (period_in );
177
+
166
178
hal_rtc_start (& self -> rtc -> config , period );
167
179
168
180
return mp_const_none ;
@@ -185,6 +197,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_rtc_stop_obj, machine_rtc_stop);
185
197
STATIC const mp_map_elem_t machine_rtc_locals_dict_table [] = {
186
198
{ MP_OBJ_NEW_QSTR (MP_QSTR_start ), (mp_obj_t )(& machine_rtc_start_obj ) },
187
199
{ MP_OBJ_NEW_QSTR (MP_QSTR_stop ), (mp_obj_t )(& machine_rtc_stop_obj ) },
200
+
201
+ // constants
202
+ { MP_OBJ_NEW_QSTR (MP_QSTR_ONESHOT ), MP_OBJ_NEW_SMALL_INT (0 ) },
203
+ { MP_OBJ_NEW_QSTR (MP_QSTR_PERIODIC ), MP_OBJ_NEW_SMALL_INT (1 ) },
188
204
};
189
205
190
206
STATIC MP_DEFINE_CONST_DICT (machine_rtc_locals_dict , machine_rtc_locals_dict_table );
0 commit comments