summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2025-07-08 11:12:45 +1000
committerDamien George <damien@micropython.org>2025-07-08 11:15:11 +1000
commit9a9e5529af9012534f2935474476d631c1e7cb81 (patch)
tree6d44b146345e7596802e9ce64ec461acb971d104
parentbf432a3e0f542321b15fcc775f62f072ba56f29d (diff)
zephyr/machine_pin: Retry configuring gpio with just GPIO_OUTPUT.
Some targets like frdm_k64f don't support GPIO_OUTPUT|GPIO_INPUT, so just use GPIO_OUTPUT in those cases (it seems they still support reading the current output state even when configured only as GPIO_OUTPUT, unlike other targets which require both settings). Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/zephyr/machine_pin.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/ports/zephyr/machine_pin.c b/ports/zephyr/machine_pin.c
index 7834b5de6..e0718588d 100644
--- a/ports/zephyr/machine_pin.c
+++ b/ports/zephyr/machine_pin.c
@@ -116,6 +116,10 @@ static mp_obj_t machine_pin_obj_init_helper(machine_pin_obj_t *self, size_t n_ar
}
int ret = gpio_pin_configure(self->port, self->pin, mode | pull | init);
+ if (ret == -ENOTSUP && mode == (GPIO_OUTPUT | GPIO_INPUT)) {
+ // Some targets (eg frdm_k64f) don't support GPIO_OUTPUT|GPIO_INPUT, so try again with just GPIO_OUTPUT.
+ ret = gpio_pin_configure(self->port, self->pin, GPIO_OUTPUT | pull | init);
+ }
if (ret) {
mp_raise_ValueError(MP_ERROR_TEXT("invalid pin"));
}