summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Howard <github@gadgetoid.com>2024-07-02 12:41:29 +0100
committerDamien George <damien@micropython.org>2024-07-03 16:48:18 +1000
commitf61fac0ba6e2684b8bb4b11c7a768b0cb805c198 (patch)
tree2c8f5fdd1346540211f07239e341ceb2d0222e1c
parent462fa5f94ff7a90afb42e72ce145309fa671ddce (diff)
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 <github@gadgetoid.com>
-rw-r--r--ports/rp2/rp2_pio.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/ports/rp2/rp2_pio.c b/ports/rp2/rp2_pio.c
index 447ea244c..410269e2d 100644
--- a/ports/rp2/rp2_pio.c
+++ b/ports/rp2/rp2_pio.c
@@ -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));
}
}
@@ -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)
@@ -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.