Skip to content

Add InputPin trait #36

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
merged 3 commits into from
Feb 5, 2018
Merged

Add InputPin trait #36

merged 3 commits into from
Feb 5, 2018

Conversation

thejpster
Copy link
Contributor

I needed a basic InputPin trait for the buttons on my Stellaris Launchpad.

@therealprof
Copy link
Contributor

Hm, I thought I mentioned somewhere that this would be sorely missing but I can't find where. 😄

Much appreciated!

@dbrgn
Copy link
Contributor

dbrgn commented Feb 3, 2018

I'm also looking for a way to read the state of a GPIO pin :)

Is anything blocking this PR?

@japaric
Copy link
Member

japaric commented Feb 5, 2018

Thanks, @thejpster

@homunkulus r+

I read some comments on IRC I think there's some confusion about the role of the HAL traits. You don't need an InputPin trait to provide input pin functionality. It's totally fine to provide functionality using inherent methods like this:

impl<MODE> PA0<Input<MODE>> {
    pub fn is_low(&self) -> bool { /* .. */ }
    pub fn is_high(&self) -> bool { /* .. */ }
}

In fact, I prefer this form because then you don't need to import a trait to be able to use the method (thankfully, we have preludes). The main reason you'll want to provide the functionality through a trait is to be able to use it for generic programming, i.e. as a bound in some generic driver. (The other reason could be that you want to create a Vec<Box<InputTrait>> but that's unlikely in bare metal context).

@homunkulus
Copy link
Contributor

📌 Commit 278145a has been approved by japaric

@homunkulus
Copy link
Contributor

⌛ Testing commit 278145a with merge 54e0a1f...

japaric pushed a commit that referenced this pull request Feb 5, 2018
Add InputPin trait

I needed a basic InputPin trait for the buttons on my Stellaris Launchpad.
@homunkulus
Copy link
Contributor

☀️ Test successful - status-travis
Approved by: japaric
Pushing 54e0a1f to master...

@homunkulus homunkulus merged commit 278145a into rust-embedded:master Feb 5, 2018
@therealprof
Copy link
Contributor

@japaric Indeed. It is useful to bind it as an used "interrupt" pin to a driver to make sure it's correctly configured and cannot be used otherwise by accident. I'm curious how we could actually establish the connection with a real interrupt though since that setup is still somewhat messy and manual.

scowcron pushed a commit to scowcron/embedded-hal that referenced this pull request Feb 28, 2018
Add InputPin trait

I needed a basic InputPin trait for the buttons on my Stellaris Launchpad.
peckpeck pushed a commit to peckpeck/embedded-hal that referenced this pull request Nov 10, 2022
36: Add timer::CountDown implementation r=posborne a=dbrgn

Based on the [implementation by @MathiasKoch](https://github.com/BlackbirdHQ/ublox-cellular-rs/blob/master/examples/common/timer.rs).

Co-authored-by: Danilo Bargen <[email protected]>
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.

5 participants