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§
- etm
unstable
- Event Task Matrix (ETM)
- interconnect
unstable
- Peripheral signal interconnect using IOMUX or GPIOMUX.
- lp_io
unstable
- Low Power IO (LP_IO)
Structs§
- AnyPin
- Type-erased GPIO pin
- Flex
- Flexible pin driver.
- GpioPin
- GPIO pin
- Input
- Digital input.
- Input
Config - Input pin configuration.
- Io
unstable
- General Purpose Input/Output driver
- NoPin
- Placeholder pin, used when no pin is required when using a peripheral.
- Output
- Push-pull digital output.
- Output
Config - Output pin configuration.
Enums§
- Drive
Mode - The drive mode of the output pin.
- Drive
Strength - Drive strength (values are approximates)
- Event
- Event used to trigger interrupts.
- Level
- Digital input or output level.
- Pull
- Pull setting for a GPIO.
- RtcFunction
unstable
- RTC function
- Wake
Config Error unstable
- Errors that can occur when configuring a pin to be a wakeup source.
- Wake
Event unstable
- Event used to wake up from light sleep.
Constants§
- NUM_
PINS - The total number of GPIO pins available.
Traits§
- Analog
Pin unstable
- Trait implemented by pins which can be used as analog pins
- Input
Pin - Trait implemented by pins which can be used as inputs.
- Output
Pin - Trait implemented by pins which can be used as outputs.
- Pin
- Common trait implemented by pins
- RtcPin
unstable
- Trait implemented by RTC pins
- RtcPin
With Resistors unstable
- Trait implemented by RTC pins which supporting internal pull-up / pull-down resistors.