Skip to content

Add digital::IoPin to resolve issue 29#269

Merged
bors[bot] merged 1 commit into
rust-embedded:masterfrom
MorganR:master
Apr 27, 2021
Merged

Add digital::IoPin to resolve issue 29#269
bors[bot] merged 1 commit into
rust-embedded:masterfrom
MorganR:master

Conversation

@MorganR

@MorganR MorganR commented Apr 25, 2021

Copy link
Copy Markdown
Contributor

Closes #29.

This implementation is inspired by chrismoos's comment in #29.

I've demonstrated using this trait for a no-std DHT11 driver, and verified this on a Raspberry Pi 3B+ using an implementation in linux-embedded-hal (PR to follow).

I'll also be sending a PR to implement this in at least one additional HAL implementation library (recommendations welcome).

One question I have is how copyright/authorship is tracked in this repo? I believe the copyright owner for my code would technically be Google LLC. When patching repos, I'm meant to add that to the appropriate copyright/authors list.

@rust-highfive

Copy link
Copy Markdown

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @therealprof (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@MorganR

MorganR commented Apr 25, 2021

Copy link
Copy Markdown
Contributor Author

PR on linux-embedded-hal: rust-embedded/linux-embedded-hal#60

@eldruin eldruin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this proposal!
Could you add some examples on how to use this to the docs?
I do not know about copyright / authorship attribution matters. The current crate author list is missing many people.

Comment thread CHANGELOG.md Outdated
Comment thread src/digital.rs Outdated
Comment thread src/digital.rs Outdated
Comment thread src/digital.rs Outdated
Comment thread src/digital.rs Outdated
///
/// If the pin is already in the requested state, this method should
/// succeed.
fn try_switch_to_output_pin(self, state: PinState) -> Result<TOutput, Self::Error>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would not setting an initial state also make sense?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If the user didn't specify the state, then the result would be a pin in output mode that's either high or low, but the user doesn't know which it is. I think it's better to make the user specify which state they want rather than to leave it ambiguous.

That being, said I'm no expert in the embedded space. Do you see a valid use case?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was just wondering. From a software perspective it makes sense to always change to a defined state. However, from a hardware perspective, it may not always make sense to set a pin, since it has electrical implications.
Does anybody else here have an use case for changing the pin type to output but leaving it unset?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IIUC, an example use-case might be an output pin in open drain mode (I could be wrong; like I said, I'm not an embedded expert). However, the current digital traits don't seem to provide any support around these states either. Maybe it makes sense to look at that separately, eg. as an addition to PinState? Definitely interested in what other folks think here, as @eldruin said.

@MorganR

MorganR commented Apr 26, 2021

Copy link
Copy Markdown
Contributor Author

I've added an example to the IoPin docs.

I am not a lawyer, but I expect that if there isn't a formal process for tracking copyright at the moment, then the PR/commit history will be fine.

@eldruin eldruin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, although I do not have the whole discussion about this in #29 in mind at the moment.

Comment thread src/digital.rs Outdated
Comment thread src/digital.rs Outdated
@therealprof

Copy link
Copy Markdown
Contributor

@MorganR This is looking great.

I'm wondering if we can make the type stuff a little bit easier on the eyes and the mind but other than that I like it.

@MorganR

MorganR commented Apr 27, 2021

Copy link
Copy Markdown
Contributor Author

Thanks @therealprof! I agree the type system becomes a bit verbose when using the abstract trait. However, it's actually fairly clean when implementing the trait, and in user code that gives a concrete implementation to something using the abstraction.

To simplify things a little more, I've removed the TIoPin parameter from the example function. This is superfluous because the function can instead accept a pin that's already in either TInputPin or TOutputPin format.

@therealprof

Copy link
Copy Markdown
Contributor

If you could squash the commits and maybe add a "Closes #29" to your initial post, that would be great.

@MorganR

MorganR commented Apr 27, 2021

Copy link
Copy Markdown
Contributor Author

If you could squash the commits and maybe add a "Closes #29" to your initial post, that would be great.

Done

therealprof
therealprof previously approved these changes Apr 27, 2021

@therealprof therealprof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks a lot for your efforts!

bors r+

bors Bot added a commit that referenced this pull request Apr 27, 2021
269: Add digital::IoPin to resolve issue 29 r=therealprof a=MorganR

Closes #29.

This implementation is inspired by [chrismoos's comment](#29 (comment)) in #29.

I've demonstrated using this trait for a [no-std DHT11 driver](https://github.com/MorganR/rust-simple-sensors/blob/main/src/dht11.rs), and verified this on a Raspberry Pi 3B+ using an implementation in linux-embedded-hal (PR to follow). 

I'll also be sending a PR to implement this in at least one additional HAL implementation library (recommendations welcome).

One question I have is how copyright/authorship is tracked in this repo? I believe the copyright owner for my code would technically be Google LLC. When patching repos, I'm meant to add that to the appropriate copyright/authors list.

Co-authored-by: Morgan Roff <mroff@google.com>
@bors

bors Bot commented Apr 27, 2021

Copy link
Copy Markdown
Contributor

Build failed:

@MorganR

MorganR commented Apr 27, 2021

Copy link
Copy Markdown
Contributor Author

Sorry, fixed that remaining fmt error. Should be good now.

@therealprof

Copy link
Copy Markdown
Contributor

@MorganR I guess rustfmt doesn't like your formatting. 😅 It's a pity the new GH protection mechanisms seem to silently prevent actions from running...

@therealprof therealprof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's try this again.

bors r+

@bors

bors Bot commented Apr 27, 2021

Copy link
Copy Markdown
Contributor

@bors bors Bot merged commit 1d22385 into rust-embedded:master Apr 27, 2021
@ryankurte ryankurte mentioned this pull request Apr 28, 2021
@burrbull

Copy link
Copy Markdown
Member

Which combinations of output and input modes this should be implemented?
PushPull, OpenDrain
PullUp, PullDown, Floating
Alternate

bors Bot added a commit to rust-embedded/linux-embedded-hal that referenced this pull request Oct 4, 2021
60: Implementation of embedded_hal::digital::IoPin r=eldruin a=MorganR

This is just a draft, and is pending the PR merge of an [IoPin implementation](rust-embedded/embedded-hal#269) into embedded_hal.

I've verified it with a [no-std DHT11 driver based on the IoPin PR](https://github.com/MorganR/rust-simple-sensors/blob/main/src/dht11.rs).

Co-authored-by: Morgan Roff <mroff@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Review is incomplete T-hal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RFC] digital::IoPin, pins that can switch between input and output modes at runtime

5 participants