From 7afbfc70038201fdea5fa2601be4d3235ffca7d6 Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Fri, 1 Mar 2019 16:46:59 +0100 Subject: [PATCH] Use find_free_timer() --- shared-module/_pew/PewPew.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/shared-module/_pew/PewPew.c b/shared-module/_pew/PewPew.c index 755b883945..c1d6aa5c35 100644 --- a/shared-module/_pew/PewPew.c +++ b/shared-module/_pew/PewPew.c @@ -74,17 +74,11 @@ void pew_init() { } if (pewpew_tc_index == 0xff) { // Find a spare timer. - Tc *tc = NULL; - int8_t index = TC_INST_NUM - 1; - for (; index >= 0; index--) { - if (tc_insts[index]->COUNT16.CTRLA.bit.ENABLE == 0) { - tc = tc_insts[index]; - break; - } - } - if (tc == NULL) { + uint8_t index = find_free_timer(); + if (index == 0xff) { mp_raise_RuntimeError(translate("")); } + Tc *tc = tc_insts[index]; pewpew_tc_index = index; set_timer_handler(true, index, TC_HANDLER_PEW);