Skip to content

Commit 455d856

Browse files
committed
raspberrypi: Fix state machine allocation
.. for duplicate programs, like two IncrementalEncoder instances. Closes: adafruit#10024
1 parent fe23bd7 commit 455d856

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,12 @@ static bool use_existing_program(PIO *pio_out, uint *sm_out, int *offset_inout,
247247
if (_current_program_id[i][j] == program_id &&
248248
_current_program_len[i][j] == program_len &&
249249
(*offset_inout == -1 || *offset_inout == _current_program_offset[i][j])) {
250-
*pio_out = pio;
251-
*sm_out = j;
252-
*offset_inout = _current_program_offset[i][j];
253-
return true;
250+
*sm_out = pio_claim_unused_sm(pio, false);
251+
if (*sm_out >= 0) {
252+
*pio_out = pio;
253+
*offset_inout = _current_program_offset[i][j];
254+
return true;
255+
}
254256
}
255257
}
256258
}

0 commit comments

Comments
 (0)