8000 zephyr/machine_pin: Configure OUT pin also as input so it's readable. by dpgeorge · Pull Request #17599 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

zephyr/machine_pin: Configure OUT pin also as input so it's readable. #17599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dpgeorge
Copy link
Member
@dpgeorge dpgeorge commented Jul 2, 2025

Summary

Zephyr allows setting both GPIO_OUTPUT and GPIO_INPUT on a pin, which means it's an output pin that can have its current value read.

Fixes issue #17596.

Testing

Tested with bbc_microbit_v2 and nucleo_wb55rg board definitions. Both allow reading an output pin:

from machine import Pin
p = Pin(("gpioa", 0), Pin.OUT)
print(p())
p(1)
print(p())
p(0)
print(p())

Note: nucleo_wb55rg already works without this change, but bbc_microbit_v2 requires the change.

Zephyr allows setting both GPIO_OUTPUT and GPIO_INPUT on a pin, which means
it's an output pin that can have its current value read.

Fixes issue micropython#17596.

Signed-off-by: Damien George <damien@micropython.org>
@bikeNomad
Copy link
Contributor

Works with the XIAO BLE NRF52840 SENSE board.

@dpgeorge
Copy link
Member Author
dpgeorge commented Jul 3, 2025

Thanks for testing!

@bikeNomad
Copy link
Contributor
bikeNomad commented Jul 3, 2025

@dpgeorge Should Pin.OPEN_DRAIN also have this added?
ports/zephyr/machine_pin.c:

    { MP_ROM_QSTR(MP_QSTR_OUT),       MP_ROM_INT(GPIO_OUTPUT | GPIO_INPUT) },
    { MP_ROM_QSTR(MP_QSTR_OPEN_DRAIN), MP_ROM_INT(GPIO_OUTPUT | GPIO_OPEN_DRAIN | GPIO_INPUT) },

ports/zephyr/mphalport.h:

static inline void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin) {
    (void)gpio_pin_configure(pin->port, pin->pin, GPIO_OUTPUT | GPIO_OPEN_DRAIN | GPIO_INPUT);
}

@dpgeorge
Copy link
Member Author
dpgeorge commented Jul 4, 2025

Should Pin.OPEN_DRAIN also have this added?

Yes, I'll do that as part of #17552.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0