@@ -107,13 +107,26 @@ static uint32_t tim3_counter = 0;
107107STATIC pyb_timer_obj_t * pyb_timer_obj_all [14 ];
108108#define PYB_TIMER_OBJ_ALL_NUM MP_ARRAY_SIZE(pyb_timer_obj_all)
109109
110+ STATIC mp_obj_t pyb_timer_deinit (mp_obj_t self_in );
111+ STATIC mp_obj_t pyb_timer_callback (mp_obj_t self_in , mp_obj_t callback );
112+
110113void timer_init0 (void ) {
111114 tim3_counter = 0 ;
112115 for (uint i = 0 ; i < PYB_TIMER_OBJ_ALL_NUM ; i ++ ) {
113116 pyb_timer_obj_all [i ] = NULL ;
114117 }
115118}
116119
120+ // unregister all interrupt sources
121+ void timer_deinit (void ) {
122+ for (uint i = 0 ; i < PYB_TIMER_OBJ_ALL_NUM ; i ++ ) {
123+ pyb_timer_obj_t * tim = pyb_timer_obj_all [i ];
124+ if (tim != NULL ) {
125+ pyb_timer_deinit (tim );
126+ }
127+ }
128+ }
129+
117130// TIM3 is set-up for the USB CDC interface
118131void timer_tim3_init (void ) {
119132 // set up the timer for USBD CDC
@@ -369,10 +382,15 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init);
369382/// \method deinit()
370383/// Deinitialises the timer.
371384///
372- /// *This function is not yet implemented.*
385+ /// Disables the callback (and the associated irq).
386+ /// Stops the timer, and disables the timer peripheral.
373387STATIC mp_obj_t pyb_timer_deinit (mp_obj_t self_in ) {
374- //pyb_timer_obj_t *self = self_in;
375- // TODO implement me
388+ pyb_timer_obj_t * self = self_in ;
389+
390+ // Disable the interrupt
391+ pyb_timer_callback (self_in , mp_const_none );
392+
393+ HAL_TIM_Base_DeInit (& self -> tim );
376394 return mp_const_none ;
377395}
378396STATIC MP_DEFINE_CONST_FUN_OBJ_1 (pyb_timer_deinit_obj , pyb_timer_deinit );
0 commit comments