esp-hal icon indicating copy to clipboard operation
esp-hal copied to clipboard

AnyTouchPin, type erased GPIO pin that implements TouchPin

Open Bahex opened this issue 11 months ago • 1 comments

Motivations

Statically allocating space for multiple gpio pins is easy with AnyPin, but there is currently no equivalent for the TouchPin trait.

Also, it makes any async function that needs to work with TouchPin generic, meaning if invoked with different pins, futures it returns are different types.

Solution

A TouchPin::degrade(self) -> AnyTouchPin method, analogous to Pin::degrade(self) -> AnyPin.

Alternatives

Currently I'm just dealing with generics, using function signatures similar to this:

fn foo<T0, T1, T2> (..., pins: (T0, T1, T2))
where
  T0: TouchPin,
  T1: TouchPin,
  T2: TouchPin
{}

Additional context

Bahex avatar Jan 14 '25 05:01 Bahex

Good idea, I think. If we do this, we should also add the same for the rest of the pin types (AnalogPin, RtcPin, but not InputPin/OutputPin). Internally, we can just convert back to AnyPin so it wouldn't be too much change, either.

bugadani avatar Jan 14 '25 09:01 bugadani