esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
626 stars 170 forks source link

Expose GPIO matrix to users #1662

Open Dominaezzz opened 1 month ago

Dominaezzz commented 1 month ago

At the moment, the drivers in the HAL take GPIO pins for each peripheral signal, which works for most cases.

However the ESP32 can also:

  1. Route a GPIO pin to multiple peripheral inputs.
  2. Route a peripheral output to multiple GPIO pins.
  3. Route a fixed 1 or 0 to peripheral's input.
  4. Route a GPIO's input to another GPIO's output. i.e. loopback

A use case for number 3 is #1515. Users should have the option to set a signal to a constant value instead of a GPIO pin. A use case for number 1 is to be able to route the vsync pin to the I2sCamera driver and also listen for interrupts on the pin with Input. Also see https://github.com/bjoernQ/esp-hal/pull/1 .

Dominaezzz commented 2 weeks ago

See https://github.com/esp-rs/esp-hal/pull/1684 . Inversion shouldn't be implemented per peripheral but should be a general thing.

jonored commented 1 week ago

We also really should have "route a peripheral output and some number of inputs to the same pin" - currently I'm hacking around esp-hal when doing 1-wire with the rmt peripheral to get the right configuration and it'd be good to have a proper solution.

ProfFan commented 1 week ago

GPIO matrix will be a great addition, many great hacks around RMT/I2S etc etc can be enabled by the GPIO matrix.

Dominaezzz commented 1 week ago

Another peripheral specific example of GPIO matrix features. https://github.com/esp-rs/esp-hal/blob/d0cd890e51c16b61707f7cce16f21fa7478fbdcf/esp-hal/src/pcnt/channel.rs#L69-L98

ProfFan commented 1 week ago

Another use case is I2C/SPI on multiple pins. This significantly improves board routing and allows much better signal integrity by avoiding long buses.