diff options
author | Damien George <damien.p.george@gmail.com> | 2015-07-22 19:37:21 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-07-22 19:41:13 +0100 |
commit | 7693ef3bd6e4456105c86909174a00f535a19261 (patch) | |
tree | 10e802dc6fd2aa502ed7bea85a147027205c3dbd /stmhal/timer.c | |
parent | 99a21dc05d7c7e42131264259f287c84afe86200 (diff) | |
download | micropython-7693ef3bd6e4456105c86909174a00f535a19261.tar.gz micropython-7693ef3bd6e4456105c86909174a00f535a19261.zip |
stmhal: Allow ADC.read_timed to take Timer object in place of freq.
This allows a user-specified Timer for the triggering of the ADC read,
mirroring the new behaviour of DAC.write_timed.
Addresses issue #1129.
Diffstat (limited to 'stmhal/timer.c')
-rw-r--r-- | stmhal/timer.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/stmhal/timer.c b/stmhal/timer.c index 3519c3c150..002e6b4296 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -227,7 +227,7 @@ void timer_tim5_init(void) { // Init TIM6 with a counter-overflow at the given frequency (given in Hz) // TIM6 is used by the DAC and ADC for auto sampling at a given frequency // This function inits but does not start the timer -void timer_tim6_init(uint freq) { +TIM_HandleTypeDef *timer_tim6_init(uint freq) { // TIM6 clock enable __TIM6_CLK_ENABLE(); @@ -247,6 +247,8 @@ void timer_tim6_init(uint freq) { TIM6_Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; // unused for TIM6 TIM6_Handle.Init.CounterMode = TIM_COUNTERMODE_UP; // unused for TIM6 HAL_TIM_Base_Init(&TIM6_Handle); + + return &TIM6_Handle; } #endif @@ -471,6 +473,9 @@ STATIC void config_deadtime(pyb_timer_obj_t *self, mp_int_t ticks) { } TIM_HandleTypeDef *pyb_timer_get_handle(mp_obj_t timer) { + if (mp_obj_get_type(timer) != &pyb_timer_type) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "need a Timer object")); + } pyb_timer_obj_t *self = timer; return &self->tim; } |