Introduction
Some GPIO controllers have the ability to invert the logic level in HW. This is useful in cases where some generic code samples the state of a pin and take actions depending on the state. Rather than having the generic know about ActiveHigh vs ActiveLow, the HW invert the logic level and the generic code can rely solely on is_low()/is_high() as if the level was not inverted.
Proposal
There are two options here.
- Add a new
set_inverted(&mut self) API to the existing InputPin struct
- Add a new
InvertedInputPin which assumes GPIO is inverted.
Challenges
- It's unlikely that every GPIO controller is capable of inverting the logic level in HW. How can we guarantee that the HAL's SW implementation is sound?
- Adding a single new function to
InputPin would allow for drivers to implement that API and maintain all their types. Existing code using InputPin would continue to work, but it would be a breaking change if the new method is required.
- Adding a new
InvertedInputPin would avoid a breaking change, but any piece of code polymorphic over InputPin would have to be modified in order to use InvertedInputPin.
Introduction
Some GPIO controllers have the ability to invert the logic level in HW. This is useful in cases where some generic code samples the state of a pin and take actions depending on the state. Rather than having the generic know about
ActiveHighvsActiveLow, the HW invert the logic level and the generic code can rely solely onis_low()/is_high()as if the level was not inverted.Proposal
There are two options here.
set_inverted(&mut self)API to the existingInputPinstructInvertedInputPinwhich assumes GPIO is inverted.Challenges
InputPinwould allow for drivers to implement that API and maintain all their types. Existing code usingInputPinwould continue to work, but it would be a breaking change if the new method is required.InvertedInputPinwould avoid a breaking change, but any piece of code polymorphic overInputPinwould have to be modified in order to useInvertedInputPin.