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

Merged

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.

@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.

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>
@dpgeorge dpgeorge force-pushed the zephyr-pin-make-output-readable branch from 40c780e to 49dbe1e Compare July 7, 2025 22:58
@dpgeorge dpgeorge merged commit 49dbe1e into micropython:master Jul 7, 2025
7 checks passed
@dpgeorge dpgeorge deleted the zephyr-pin-make-output-readable branch July 7, 2025 23:29
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy