Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/rp2_common/hardware_pio/pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,27 +433,28 @@ bool pio_claim_free_sm_and_add_program_for_gpio_range(const pio_program_t *progr
sm_index[num_claimed] = (int8_t)pio_claim_unused_sm(*pio, false);
if (sm_index[num_claimed] < 0) break;
}
if (num_claimed && (!pass || num_claimed == NUM_PIO_STATE_MACHINES)) {
int rc = num_claimed && (!pass || num_claimed == NUM_PIO_STATE_MACHINES) ? 0 : -1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably simplify this to either (num_claimed == pass ? 1 : NUM_PIO_STATE_MACHINES) ? 0 : -1 or even (int) (num_claimed - pass ? 1 : NUM_PIO_STATE_MACHINES)

if (rc >= 0) {
uint32_t save = hw_claim_lock();
if (pass) {
pio_set_gpio_base_unsafe(*pio, required_gpio_ranges & 4 ? 16 : 0);
}
int rc = is_gpio_compatible(*pio, required_gpio_ranges) ? PICO_OK : PICO_ERROR_BAD_ALIGNMENT;
if (rc == PICO_OK) rc = find_offset_for_program(*pio, program);
rc = is_gpio_compatible(*pio, required_gpio_ranges) ? 0 : -1;
if (rc >= 0) rc = find_offset_for_program(*pio, program);
if (rc >= 0) rc = add_program_at_offset(*pio, program, (uint)rc);
if (rc >= 0) {
*sm = (uint) sm_index[0];
*offset = (uint) rc;
}
hw_claim_unlock(save);
// always un-claim all SMs other than the one we need (array index 0),
// or all of them if we had an error
for (uint i = (rc >= 0); i < num_claimed; i++) {
pio_sm_unclaim(*pio, (uint) sm_index[i]);
}
if (rc >= 0) {
return true;
}
}
// always un-claim all SMs other than the one we need (array index 0),
// or all of them if we had an error
for (uint i = (rc >= 0); i < num_claimed; i++) {
pio_sm_unclaim(*pio, (uint) sm_index[i]);
}
if (rc >= 0) {
return true;
}
}
}
Expand Down