Skip to content

Commit

Permalink
rp2/rp2_pio: Replace explicit pio ternary expression with pio_get_index.
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Gadgetoid authored and dpgeorge committed Jul 3, 2024
1 parent 462fa5f commit f61fac0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ports/rp2/rp2_pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static void asm_pio_init_gpio(PIO pio, uint32_t sm, asm_pio_config_t *config) {
pio_sm_set_pins_with_mask(pio, sm, config->pinvals << config->base, pinmask);
pio_sm_set_pindirs_with_mask(pio, sm, config->pindirs << config->base, pinmask);
for (size_t i = 0; i < config->count; ++i) {
gpio_set_function(config->base + i, pio == pio0 ? GPIO_FUNC_PIO0 : GPIO_FUNC_PIO1);
gpio_set_function(config->base + i, GPIO_FUNC_PIO0 + pio_get_index(pio));
}
}

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

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

// constructor(id)
Expand Down Expand Up @@ -326,7 +326,7 @@ static mp_obj_t rp2_pio_state_machine(size_t n_args, const mp_obj_t *pos_args, m
}

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

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

0 comments on commit f61fac0

Please sign in to comment.