diff options
author | Damien George <damien.p.george@gmail.com> | 2014-07-02 14:06:28 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-07-02 14:06:28 +0100 |
commit | 92a47b4dae14189cfd6572ee6eef09b973069d0d (patch) | |
tree | cc2b8729380716c83af74bbb65133366772b6576 /stmhal/timer.c | |
parent | 9cd96cf25d4b044288a923dae63e8e7d8c261c7b (diff) | |
parent | 0d81c133b31774058408a5f1d1a058d9734a9def (diff) | |
download | micropython-92a47b4dae14189cfd6572ee6eef09b973069d0d.tar.gz micropython-92a47b4dae14189cfd6572ee6eef09b973069d0d.zip |
Merge branch 'add-timer-deinit' of github.com:dhylands/micropython into dhylands-add-timer-deinit
Diffstat (limited to 'stmhal/timer.c')
-rw-r--r-- | stmhal/timer.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/stmhal/timer.c b/stmhal/timer.c index ec0c4dec4c..8634c46bf2 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -366,13 +366,20 @@ STATIC mp_obj_t pyb_timer_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_a } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(pyb_timer_init_obj, 1, pyb_timer_init); +STATIC mp_obj_t pyb_timer_callback(mp_obj_t self_in, mp_obj_t callback); + /// \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); @@ -464,6 +471,16 @@ const mp_obj_type_t pyb_timer_type = { .locals_dict = (mp_obj_t)&pyb_timer_locals_dict, }; +// 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); + } + } +} + void timer_irq_handler(uint tim_id) { if (tim_id - 1 < PYB_TIMER_OBJ_ALL_NUM) { // get the timer object |