Skip to content

[DISCUSSION] GPIO Invert API #670

@felipebalbi

Description

@felipebalbi

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.

  1. Add a new set_inverted(&mut self) API to the existing InputPin struct
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions