diff options
author | Damien George <damien.p.george@gmail.com> | 2014-07-02 14:10:18 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-07-02 14:10:18 +0100 |
commit | 5e6419cb11b2897e29ab6dd5b74245d5b42742cf (patch) | |
tree | 7c9519100291697b52c3e08231bd3b39cc67f93c /stmhal/timer.c | |
parent | 9cd96cf25d4b044288a923dae63e8e7d8c261c7b (diff) | |
parent | e70b5dbe589ea1c085247ca21c7b4d0efd972c27 (diff) |
Merge branch 'dhylands-add-timer-deinit'
Diffstat (limited to 'stmhal/timer.c')
-rw-r--r-- | stmhal/timer.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/stmhal/timer.c b/stmhal/timer.c index ec0c4dec4..73842e4b1 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -107,6 +107,9 @@ static uint32_t tim3_counter = 0; STATIC pyb_timer_obj_t *pyb_timer_obj_all[14]; #define PYB_TIMER_OBJ_ALL_NUM MP_ARRAY_SIZE(pyb_timer_obj_all) +STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in); +STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback); + void timer_init0(void) { tim3_counter = 0; for (uint i = 0; i < PYB_TIMER_OBJ_ALL_NUM; i++) { @@ -114,6 +117,16 @@ void timer_init0(void) { } } +// unregister all interrupt sources +void timer_deinit(void) { + for (uint i = 0; i < PYB_TIMER_OBJ_ALL_NUM; i++) { + pyb_timer_obj_t *tim = pyb_timer_obj_all[i]; + if (tim != NULL) { + pyb_timer_deinit(tim); + } + } +} + // TIM3 is set-up for the USB CDC interface void timer_tim3_init(void) { // 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); /// \method deinit() /// Deinitialises the timer. /// -/// *This function is not yet implemented.* +/// Disables the callback (and the associated irq). +/// Stops the timer, and disables the timer peripheral. STATIC mp_obj_t pyb_timer_deinit(mp_obj_t self_in) { - //pyb_timer_obj_t *self = self_in; - // TODO implement me + pyb_timer_obj_t *self = self_in; + + // Disable the interrupt + pyb_timer_callback(self_in, mp_const_none); + + HAL_TIM_Base_DeInit(&self->tim); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_timer_deinit_obj, pyb_timer_deinit); |