esp_hal

Module gpio

Source
Expand description

§General Purpose Input/Output (GPIO)

§Overview

Each pin can be used as a general-purpose I/O, or be connected to one or more internal peripheral signals.

§Working with pins

After initializing the HAL, you can access the individual pins using the crate::Peripherals struct. These pins can then be used as general purpose digital IO using pin drivers, or they can be passed to peripherals (such as SPI, UART, I2C, etc.), or can be GpioPin::split into peripheral signals for advanced use.

Pin drivers can be created using Flex::new, Input::new, Output::new and OutputOpenDrain::new.

Each pin is a different type initially. Internally, esp-hal will often erase their types automatically, but they can also be converted into AnyPin manually by calling Pin::degrade.

The Io struct can also be used to configure the interrupt handler for GPIO interrupts. For more information, see the InterruptConfigurable::set_interrupt_handler.

This driver also implements pin-related traits from embedded-hal and Wait trait from embedded-hal-async.

§GPIO interconnect

Sometimes you may want to connect peripherals together without using external hardware. The interconnect module provides tools to achieve this using GPIO pins.

To obtain peripheral signals, use the GpioPin::split method to split a pin into an input and output signal. Alternatively, you may use Flex::split, Flex::into_peripheral_output, Flex::peripheral_input, and similar methods to split a pin driver into an input and output signal. You can then pass these signals to the peripheral drivers similar to how you would pass a pin.

§GPIO interconnect example

See the Inverting TX and RX Pins example of the UART documentation.

Modules§

  • interconnectunstable
    Peripheral signal interconnect using IOMUX or GPIOMUX.

Structs§

  • Type-erased GPIO pin
  • Flexible pin driver.
  • GPIO pin
  • Digital input.
  • General Purpose Input/Output driver
  • Placeholder pin, used when no pin is required when using a peripheral.
  • Push-pull digital output.
  • Open drain digital output.

Enums§

  • Drive strength (values are approximates)
  • Event used to trigger interrupts.
  • Digital input or output level.
  • Pull setting for an input.
  • RtcFunctionunstable
    RTC function
  • Errors that can occur when configuring a pin to be a wakeup source.
  • WakeEventunstable
    Event used to wake up from light sleep.

Constants§

  • The total number of GPIO pins available.

Traits§

  • AnalogPinunstable
    Trait implemented by pins which can be used as analog pins
  • Trait implemented by pins which can be used as inputs.
  • Trait implemented by pins which can be used as outputs.
  • Common trait implemented by pins
  • RtcPinunstable
    Trait implemented by RTC pins
  • Trait implemented by RTC pins which supporting internal pull-up / pull-down resistors.
  • TouchPinunstable
    Trait implemented by pins which can be used as Touchpad pins