Skip to content

Commit f61fac0

Browse files
Gadgetoiddpgeorge
authored andcommitted
rp2/rp2_pio: Replace explicit pio ternary expression with pio_get_index.
There are three changes here: - Fix `rp2_pio_print` to use `pio_get_index()` too, since it had its own copy of the ternary expression. - Remove a ternary from `rp2_pio_state_machine` and calculate it from `pio_get_index`. - Remove a ternary on `GPIO_FUNC_PIO0` vs `GPIO_FUNC_PIO1`. These constants are sequentially ordered so we can calculate them too. Signed-off-by: Phil Howard <[email protected]>
1 parent 462fa5f commit f61fac0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

ports/rp2/rp2_pio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static void asm_pio_init_gpio(PIO pio, uint32_t sm, asm_pio_config_t *config) {
226226
pio_sm_set_pins_with_mask(pio, sm, config->pinvals << config->base, pinmask);
227227
pio_sm_set_pindirs_with_mask(pio, sm, config->pindirs << config->base, pinmask);
228228
for (size_t i = 0; i < config->count; ++i) {
229-
gpio_set_function(config->base + i, pio == pio0 ? GPIO_FUNC_PIO0 : GPIO_FUNC_PIO1);
229+
gpio_set_function(config->base + i, GPIO_FUNC_PIO0 + pio_get_index(pio));
230230
}
231231
}
232232

@@ -242,7 +242,7 @@ static rp2_pio_obj_t rp2_pio_obj[] = {
242242

243243
static void rp2_pio_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
244244
rp2_pio_obj_t *self = MP_OBJ_TO_PTR(self_in);
245-
mp_printf(print, "PIO(%u)", self->pio == pio0 ? 0 : 1);
245+
mp_printf(print, "PIO(%u)", pio_get_index(self->pio));
246246
}
247247

248248
// constructor(id)
@@ -326,7 +326,7 @@ static mp_obj_t rp2_pio_state_machine(size_t n_args, const mp_obj_t *pos_args, m
326326
}
327327

328328
// Return the correct StateMachine object.
329-
const rp2_state_machine_obj_t *sm = rp2_state_machine_get_object((self->pio == pio0 ? 0 : 4) + sm_id);
329+
const rp2_state_machine_obj_t *sm = rp2_state_machine_get_object(pio_get_index(self->pio) * 4 + sm_id);
330330

331331
if (n_args > 2 || kw_args->used > 0) {
332332
// Configuration arguments given so init this StateMachine.

0 commit comments

Comments
 (0)