rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
2.01k stars 202 forks source link

`ToggleableOutputPin` feels redundant #549

Closed mvirkkunen closed 11 months ago

mvirkkunen commented 11 months ago

What are the practical use cases for a pin that you can only toggle, and is there hardware out there with pins that you can only toggle but not read the current state of?

I can't think of a use case for the trait beyond blinking an LED or something and even then it shouldn't need to be a separate trait. I think it should rather be a method with a default impl on StatefulOutputPin to avoid having to implement it separately in every HAL:

pub trait StatefulOutputPin: OutputPin {
    // ...

    fn toggle(&mut self) -> Result<(), Self::Error> {
        let new_state = self.is_set_low()?.into();
        self.set_state(new_state)
    }
}

The default implementation could of course be overridden on hardware where there is a more efficient way to toggle a pin.