Skip to content

Commit 7afbfc7

Browse files
committed
Use find_free_timer()
1 parent ea78417 commit 7afbfc7

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

shared-module/_pew/PewPew.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,11 @@ void pew_init() {
7474
}
7575
if (pewpew_tc_index == 0xff) {
7676
// Find a spare timer.
77-
Tc *tc = NULL;
78-
int8_t index = TC_INST_NUM - 1;
79-
for (; index >= 0; index--) {
80-
if (tc_insts[index]->COUNT16.CTRLA.bit.ENABLE == 0) {
81-
tc = tc_insts[index];
82-
break;
83-
}
84-
}
85-
if (tc == NULL) {
77+
uint8_t index = find_free_timer();
78+
if (index == 0xff) {
8679
mp_raise_RuntimeError(translate(""));
8780
}
81+
Tc *tc = tc_insts[index];
8882

8983
pewpew_tc_index = index;
9084
set_timer_handler(true, index, TC_HANDLER_PEW);

0 commit comments

Comments
 (0)