Skip to content

[embassy-nrf] Add InputRef, OutputRef, and FlexRef #4146

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 2 commits into
base: main
Choose a base branch
from

Conversation

alexmoon
Copy link
Contributor

Adds reference types for GPIOs so that they can be borrowed by drivers without being torn down when the driver is dropped. This allows, for example, an Output to be used in a SimplePwm, then the SimplePwm can be dropped and a gpiote::OutputChannel created using the same Output without its configuration being reset (and the pin disconnected) in between.

Adds reference types for GPIOs so that they can be borrowed by drivers without being torn down when the driver is dropped. This allows, for example, an `Output` to be used in a `SimplePwm`, then the `SimplePwm` can be dropped and a `gpiote::OutputChannel` created using the same `Output` without its configuration being reset in between.
@lulf
Copy link
Member

lulf commented May 15, 2025

I don't really like the changes to the API here where you can't just pass the peripheral anymore, but I do understand the need for this. I thought passing &mut p.P0_10 etc. would work for this use case, but seems that no longer the case. Is that due to the Peri changes?

@alexmoon
Copy link
Contributor Author

Yeah, I agree. I considered making a From<Peri<'_, ...>> impl for OutputRef and InputRef which would use the default level and pull options. That would make it p.P0_10.into() instead of Output::new(p.P0_10, Level::Low).into(). Note that InputChannel and OutputChannel were already taking Input and Output parameters instead of raw peripherals. This is sort of bringing Pwm in line with those.

@0e4ef622
Copy link
Contributor

0e4ef622 commented May 15, 2025

I'm not sure what the purpose of InputRef/OutputRef are, it seems like adding a reborrow method to Input/Output would suffice.

EDIT: oh if its borrowed it won't drop.

@alexmoon
Copy link
Contributor Author

EDIT: oh if its borrowed it won't drop.

Yep

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

Successfully merging this pull request may close these issues.

3 participants