8000 Merge pull request #10025 from jepler/pio-fixes · jepler/circuitpython@1c0b37e · GitHub
[go: up one dir, main page]

Skip to content

Commit 1c0b37e

Browse files
authored
Merge pull request adafruit#10025 from jepler/pio-fixes
raspberrypi: Fix state machine allocation
2 parents 0a53eb8 + 455d856 commit 1c0b37e

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,6 @@ static void *_interrupt_arg[NUM_PIOS][NUM_PIO_STATE_MACHINES];
5757

5858
static void rp2pio_statemachine_interrupt_handler(void);
5959

60-
// Workaround for sdk bug: https://github.com/raspberrypi/pico-sdk/issues/1878
61-
// This workaround can be removed when we upgrade to sdk 2.0.1
62-
static inline void sm_config_set_in_pin_count_issue1878(pio_sm_config *c, uint in_count) {
63-
#if PICO_PIO_VERSION == 0
64-
// can't be changed from 32 on PIO v0
65-
((void)c);
66-
valid_params_if(HARDWARE_PIO, in_count == 32);
67-
#else
68-
valid_params_if(HARDWARE_PIO, in_count && in_count <= 32);
69-
c->shiftctrl = (c->shiftctrl & ~PIO_SM0_SHIFTCTRL_IN_COUNT_BITS) |
70-
((in_count & 0x1fu) << PIO_SM0_SHIFTCTRL_IN_COUNT_LSB);
71-
#endif
72-
}
7360
static void rp2pio_statemachine_set_pull(pio_pinmask_t pull_pin_up, pio_pinmask_t pull_pin_down, pio_pinmask_t pins_we_use) {
7461
for (size_t i = 0; i < NUM_BANK0_GPIOS; i++) {
7562
bool used = PIO_PINMASK_IS_SET(pins_we_use, i);
@@ -253,10 +240,12 @@ static bool use_existing_program(PIO *pio_out, uint *sm_out, int *offset_inout,
253240
if (_current_program_id[i][j] == program_id &&
254241
_current_program_len[i][j] == program_len &&
255242
(*offset_inout == -1 || *offset_inout == _current_program_offset[i][j])) {
256-
*pio_out = pio;
257-
*sm_out = j;
258-
*offset_inout = _current_program_offset[i][j];
259-
return true;
243+
*sm_out = pio_claim_unused_sm(pio, false);
244+
if (*sm_out >= 0) {
245+
*pio_out = pio;
246+
*offset_inout = _current_program_offset[i][j];
247+
return true;
248+
}
260249
}
261250
}
262251
}
@@ -435,7 +424,7 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
435424
sm_config_set_wrap(&c, wrap_target, wrap);
436425
sm_config_set_in_shift(&c, in_shift_right, auto_push, push_threshold);
437426
#if PICO_PIO_VERSION > 0
438-
sm_config_set_in_pin_count_issue1878(&c, in_pin_count);
427+
sm_config_set_in_pin_count(&c, in_pin_count);
439428
#endif
440429

441430
sm_config_set_out_shift(&c, out_shift_right, auto_pull, pull_threshold);

0 commit comments

Comments
 (0)
0