Skip to content

Add InputPin trait#36

Merged
homunkulus merged 3 commits into
rust-embedded:masterfrom
thejpster:input_pin
Feb 5, 2018
Merged

Add InputPin trait#36
homunkulus merged 3 commits into
rust-embedded:masterfrom
thejpster:input_pin

Conversation

@thejpster

Copy link
Copy Markdown
Contributor

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

@therealprof

Copy link
Copy Markdown
Contributor

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

Much appreciated!

@dbrgn

dbrgn commented Feb 3, 2018

Copy link
Copy Markdown
Contributor

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

Is anything blocking this PR?

@japaric

japaric commented Feb 5, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor

📌 Commit 278145a has been approved by japaric

@homunkulus

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 <mail@dbrgn.ch>
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