Skip to content
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

Also release owned Pins with Usart::free() #261

Merged
merged 4 commits into from
Oct 30, 2020

Conversation

timokroeger
Copy link
Contributor

Return ownership of the pins back to the user when calling free()
Useful to multiplex a single USARTE instance to multiple serial connections on different pins (for smaller NRF52 devices which only have one USARTE instance).

Alternative: Only take a reference to the pins in in new().
Please let me know which one is the preferred approach.

@jonas-schievink
Copy link
Contributor

Alternative: Only take a reference to the pins in in new().

This would mean that Usart<_>: 'static never holds and prevent usage of Usart in RTIC resources, so we probably shouldn't do that.

I think we can do better than storing the Pins instance in every Usart though – what if we just read from the USART's pin configuration registers in free and create the pins from those? That way we don't have to pay for the extra Pins storage.

@timokroeger
Copy link
Contributor Author

Reading back the pins from the peripheral is a nifty idea. Going to try that tomorrow.

@Yatekii
Copy link
Contributor

Yatekii commented Oct 29, 2020

Cool stuff, thanks for doing this! I required this a few times already but just for debugging things and I just used unsfe for that :P

I think we can do better than storing the Pins instance in every Usart though – what if we just read from the USART's pin configuration registers in free and create the pins from those? That way we don't have to pay for the extra Pins storage.

I fully agree with this :)

Copy link
Contributor

@jonas-schievink jonas-schievink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Can you also add a changelog entry?

nrf-hal-common/src/gpio.rs Outdated Show resolved Hide resolved
@jonas-schievink jonas-schievink merged commit e932eea into nrf-rs:master Oct 30, 2020
@timokroeger timokroeger deleted the usart-free-pins branch October 30, 2020 15:41
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.

None yet

3 participants