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. The GPIO pins also provide tasks and events via the ETM interconnect system. For more information, see the etm module.

§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 and Output::new.

Output pins can be configured to either push-pull or open-drain (active low) mode, with configurable drive strength and pull-up/pull-down resistors.

Each pin is a different type initially. Internally, esp-hal will 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.

Modules§

etmunstable
Event Task Matrix (ETM)
interconnectunstable
Peripheral signal interconnect using IOMUX or GPIOMUX.
lp_iounstable
Low Power IO (LP_IO)

Structs§

AnyPin
Type-erased GPIO pin
Flex
Flexible pin driver.
GpioPin
GPIO pin
Input
Digital input.
InputConfig
Input pin configuration.
Iounstable
General Purpose Input/Output driver
NoPin
Placeholder pin, used when no pin is required when using a peripheral.
Output
Push-pull digital output.
OutputConfig
Output pin configuration.

Enums§

DriveMode
The drive mode of the output pin.
DriveStrength
Drive strength (values are approximates)
Event
Event used to trigger interrupts.
Level
Digital input or output level.
Pull
Pull setting for a GPIO.
RtcFunctionunstable
RTC function
WakeConfigErrorunstable
Errors that can occur when configuring a pin to be a wakeup source.
WakeEventunstable
Event used to wake up from light sleep.

Constants§

NUM_PINS
The total number of GPIO pins available.

Traits§

AnalogPinunstable
Trait implemented by pins which can be used as analog pins
InputPin
Trait implemented by pins which can be used as inputs.
OutputPin
Trait implemented by pins which can be used as outputs.
Pin
Common trait implemented by pins
RtcPinunstable
Trait implemented by RTC pins
RtcPinWithResistorsunstable
Trait implemented by RTC pins which supporting internal pull-up / pull-down resistors.