diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index fb9ef00af1..a75abd324b 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -252,7 +252,8 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, tc_gclk = 1; #endif - turn_on_clocks(true, tc_index, tc_gclk, TC_HANDLER_NO_INTERRUPT); + set_timer_handler(true, tc_index, TC_HANDLER_NO_INTERRUPT); + turn_on_clocks(true, tc_index, tc_gclk); // Don't bother setting the period. We set it before you playback anything. tc_set_enable(t, false); diff --git a/ports/atmel-samd/common-hal/pulseio/PWMOut.c b/ports/atmel-samd/common-hal/pulseio/PWMOut.c index dcc2363323..19daaa14fd 100644 --- a/ports/atmel-samd/common-hal/pulseio/PWMOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PWMOut.c @@ -235,8 +235,9 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, } } + set_timer_handler(timer->is_tc, timer->index, TC_HANDLER_NO_INTERRUPT); // We use the zeroeth clock on either port to go full speed. - turn_on_clocks(timer->is_tc, timer->index, 0, TC_HANDLER_NO_INTERRUPT); + turn_on_clocks(timer->is_tc, timer->index, 0); if (timer->is_tc) { tc_periods[timer->index] = top; diff --git a/ports/atmel-samd/common-hal/pulseio/PulseOut.c b/ports/atmel-samd/common-hal/pulseio/PulseOut.c index 68f5d8fff9..528a5c808a 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseOut.c @@ -113,13 +113,14 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, pulseout_tc_index = index; + set_timer_handler(true, index, TC_HANDLER_PULSEOUT); // We use GCLK0 for SAMD21 and GCLK1 for SAMD51 because they both run at 48mhz making our // math the same across the boards. #ifdef SAMD21 - turn_on_clocks(true, index, 0, TC_HANDLER_PULSEOUT); + turn_on_clocks(true, index, 0); #endif #ifdef SAMD51 - turn_on_clocks(true, index, 1, TC_HANDLER_PULSEOUT); + turn_on_clocks(true, index, 1); #endif diff --git a/ports/atmel-samd/timer_handler.c b/ports/atmel-samd/timer_handler.c index bb0d248b55..566dd8cbd0 100644 --- a/ports/atmel-samd/timer_handler.c +++ b/ports/atmel-samd/timer_handler.c @@ -34,8 +34,10 @@ static uint8_t tc_handler[TC_INST_NUM]; -void set_timer_handler(uint8_t index, uint8_t timer_handler) { - tc_handler[index] = timer_handler; +void set_timer_handler(bool is_tc, uint8_t index, uint8_t timer_handler) { + if (is_tc) { + tc_handler[index] = timer_handler; + } } void shared_timer_handler(bool is_tc, uint8_t index) { diff --git a/ports/atmel-samd/timer_handler.h b/ports/atmel-samd/timer_handler.h index 3243740e24..a495e21f2a 100644 --- a/ports/atmel-samd/timer_handler.h +++ b/ports/atmel-samd/timer_handler.h @@ -30,7 +30,7 @@ #define TC_HANDLER_PULSEOUT 0x1 #define TC_HANDLER_FREQUENCYIN 0x2 -void set_timer_handler(uint8_t index, uint8_t timer_handler); +void set_timer_handler(bool is_tc, uint8_t index, uint8_t timer_handler); void shared_timer_handler(bool is_tc, uint8_t index); #endif // MICROPY_INCLUDED_ATMEL_SAMD_TIMER_HANDLER_H