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

InputPin not implemented for downgraded open_drain_output #156

Closed
gray-heron opened this issue Dec 22, 2019 · 1 comment · Fixed by #160
Closed

InputPin not implemented for downgraded open_drain_output #156

gray-heron opened this issue Dec 22, 2019 · 1 comment · Fixed by #160

Comments

@gray-heron
Copy link

Hello,
my project features two groups of six TM1637 displays, for whom I need to read a logical state of open-drain pins. Hence, I would like to group those pins in arrays, and I need them all to have the same type.

But I found out that InputPin trait is no longer satisfied after downgrade:

fn test<INPUT>(i: &mut INPUT) where INPUT: InputPin {}

[...]

        let mut p1 = gpioc.pc8.into_open_drain_output(&mut gpioc.crh);
        let mut p2 = gpioc.pc9.into_open_drain_output(&mut gpioc.crh).downgrade();

        test(&mut p1); //OK
        test(&mut p2); //Error

In gpio.rs I can see the implementation for generic OD pins and this would be enough for me (I can move all such pins to gpioc), but Generic is private:

impl InputPin for Generic<Output<OpenDrain>> {
    type Error = Infallible;
    fn is_high(&self) -> Result<bool, Self::Error> {
        self.is_low().map(|b| !b)
    }
        
    fn is_low(&self) -> Result<bool, Self::Error> {
        // NOTE(unsafe) atomic read with no side effects
        Ok(unsafe { (*$GPIOX::ptr()).idr.read().bits() & (1 << self.i) == 0 })
    }
}

Is there a technical reason behind loosing InputPin for downgraded OD pin? If so, how should I approach this? I don't want two functions doing the same thing, each taking 6 similar arguments.

Cheers,
~CS

@TeXitoi
Copy link
Contributor

TeXitoi commented Dec 22, 2019

We just forgot this impl.

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 a pull request may close this issue.

2 participants