unstable only.Expand description
Dedicated GPIO access.
This module implements fast GPIO access using special-purpose CPU features. Dedicated GPIO access works by connecting peripheral signals between the CPU and the GPIO pins, instead of using the GPIO registers via the peripheral bus.
To use dedicated GPIOs, first you must obtain the channel objects. The channels
are created by calling the DedicatedGpio::new function. The fields of the
DedicatedGpio struct represent the channels. The channels are DedicatedGpioChannel
objects, which by default represent both input and output channels. The channels can be split
into DedicatedGpioInputChannel and DedicatedGpioOutputChannel halves, or may be
used unsplit.
esp32c6 specific: There are 8 dedicated GPIO channels available.
Next, configure the pins you want to use as normal GPIO pin drivers. Then you can wrap them into the dedicated GPIO drivers:
The drivers can take channels and pins by value or by reference. Pass these objects by reference if you plan on reusing them again, after dropping the dedicated driver.
Due to how the hardware works, DedicatedGpioOutput can drive any number of GPIO pins.
§Bundles
If you need to read or update multiple channels together, you can use the bundle helpers:
Bundles are lightweight objects that precompute a channel mask from one or more drivers, allowing multi-channel operations with a single low-level read/write.
§Low-level functions
This module also exposes low-level helpers for direct, channel-bitmask-based access:
write_ll: write output levels for a selected set of channels in one operationread_all_ll: read the current input levels of all channelsoutput_levels_ll: read the current output levels of all channels These functions operate purely on channel bitmasks (bit 0 -> channel 0, bit 1 -> channel 1, …) and do not track pin configuration. Prefer the higher-level drivers and bundles unless you specifically need the lowest overhead.
§Examples
§sharing drivers across multiple bundles
The same driver can be borrowed by multiple bundles at the same time.
In this example, we build two input bundles:
bundle_areads channels 0, 1, 2bundle_breads channels 0, 2, 4
Both bundles share the same in0 and in2 drivers, and we use
DedicatedGpioInputBundle::all_high to check if all channels in each bundle are currently
high.
use esp_hal::gpio::{
Input,
InputConfig,
dedicated::{DedicatedGpio, DedicatedGpioInput, DedicatedGpioInputBundle},
};
// Create channels.
let channels = DedicatedGpio::new(peripherals.GPIO_DEDICATED);
// Configure GPIO inputs
let p0 = Input::new(peripherals.GPIO0, InputConfig::default());
let p1 = Input::new(peripherals.GPIO1, InputConfig::default());
let p2 = Input::new(peripherals.GPIO2, InputConfig::default());
let p4 = Input::new(peripherals.GPIO4, InputConfig::default());
let in0 = DedicatedGpioInput::new(channels.channel0.input, p0);
let in1 = DedicatedGpioInput::new(channels.channel1.input, p1);
let in2 = DedicatedGpioInput::new(channels.channel2.input, p2);
let in4 = DedicatedGpioInput::new(channels.channel4.input, p4);
// Bundle A reads channels 0, 1, 2.
let mut bundle_a = DedicatedGpioInputBundle::new();
bundle_a
.enable_input(&in0)
.enable_input(&in1)
.enable_input(&in2);
// Bundle B reads channels 0, 2, 4.
// Note: `in0` and `in2` are *shared* with bundle A.
let mut bundle_b = DedicatedGpioInputBundle::new();
bundle_b
.enable_input(&in0)
.enable_input(&in2)
.enable_input(&in4);
// Check whether all channels in each bundle are currently high.
let a_all_high = bundle_a.all_high(); // true if ch0, ch1, ch2 are all high
let b_all_high = bundle_b.all_high(); // true if ch0, ch2, ch4 are all high
This pattern is useful when different subsystems want different views of the same set of input channels without duplicating driver setup.
Structs§
- Dedicated
Gpio - Dedicated GPIO channels.
- Dedicated
Gpio Channel - A single dedicated GPIO channel, both input and output.
- Dedicated
Gpio Flex - A dedicated GPIO input and output driver.
- Dedicated
Gpio Flex Bundle - A bundle of dedicated GPIO flex drivers (input + output).
- Dedicated
Gpio Input - A dedicated GPIO input driver.
- Dedicated
Gpio Input Bundle - A bundle of dedicated GPIO input drivers.
- Dedicated
Gpio Input Channel - A single dedicated GPIO input channel.
- Dedicated
Gpio Output - A dedicated GPIO output driver.
- Dedicated
Gpio Output Bundle - A bundle of dedicated GPIO output drivers.
- Dedicated
Gpio Output Channel - A single dedicated GPIO output channel.
Traits§
- Input
Channel - Marker trait for dedicated GPIO input channels.
- Input
Driver - Marker trait for GPIO input drivers.
- Output
Channel - Marker trait for dedicated GPIO output channels.
- Output
Driver - Marker trait for GPIO output drivers.
Functions§
- output_
levels_ ll - Low-level function to read the current output levels of all dedicated GPIO channels.
- read_
all_ ll - Low-level function to read the current state of all dedicated input channels.
- write_
ll - Low-level function to write any number of dedicated output channels at once.