Skip to main content

Flex

Struct Flex 

Source
pub struct Flex<'d> { /* private fields */ }
Available on crate feature unstable only.
Expand description

Flexible pin driver.

This pin driver can act as either input, or output, or both at the same time. The input and output are (not counting the shared pull direction) separately configurable, and they have independent enable states.

Enabling the input stage does not change the output stage, and vice versa. Disabling the input or output stages don’t forget their configuration. Disabling the output stage will not change the output level, but it will disable the driver.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Implementations§

Source§

impl Flex<'_>

Source

pub async fn wait_for(&mut self, event: Event)

Wait until the pin experiences a particular Event.

The GPIO driver will disable listening for the event once it occurs, or if the Future is dropped - which also means this method is not cancellation-safe, it will always wait for a future event.

Note that calling this function will overwrite previous listen operations for this pin.

A wait continues through a light sleep, and a pin that waits also ends the sleep, like a listening pin. There is one exception: a wait for an edge on a pin that is already at the level at the end of that edge. See listen.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub async fn wait_for_high(&mut self)

Wait until the pin is high.

See Self::wait_for for more information.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub async fn wait_for_low(&mut self)

Wait until the pin is low.

See Self::wait_for for more information.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub async fn wait_for_rising_edge(&mut self)

Wait for the pin to undergo a transition from low to high.

See Self::wait_for for more information.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub async fn wait_for_falling_edge(&mut self)

Wait for the pin to undergo a transition from high to low.

See Self::wait_for for more information.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub async fn wait_for_any_edge(&mut self)

Wait for the pin to undergo any transition, i.e low to high OR high to low.

See Self::wait_for for more information.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl<'d> Flex<'d>

Source

pub fn new(pin: impl Pin + 'd) -> Self

Create flexible pin driver for a Pin. No mode change happens.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn apply_input_config(&mut self, config: &InputConfig)

Applies the given input configuration to the pin.

This function does not set the pin as input (i.e. it does not enable the input buffer). Note that the pull direction is common between the input and output configuration.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn set_input_enable(&mut self, enable_input: bool)

Enable or disable the GPIO pin input buffer.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn set_pad_hold(&mut self, enable: bool)

Takes or releases the hold of the pad.

A held pad keeps its level, its function and its resistors, and it ignores this driver.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn is_pad_held(&self) -> bool

Returns whether something holds the pad.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn is_high(&self) -> bool

Get whether the pin input level is high.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn is_low(&self) -> bool

Get whether the pin input level is low.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn level(&self) -> Level

Get the current pin input level.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn listen(&mut self, event: Event)

Listen for interrupts.

See Input::listen for more information and an example.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn unlisten(&mut self)

Stop listening for interrupts.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn is_listening(&self) -> bool

Check if the pin is listening for interrupts.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn clear_interrupt(&mut self)

Clear the interrupt status bit for this Pin

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn is_interrupt_set(&self) -> bool

Checks if the interrupt status bit for this Pin is set

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn apply_wakeup_config( &mut self, config: &WakeupConfig, ) -> Result<(), WakeConfigError>

Configures whether the pin can wake the chip from sleep.

The configuration selects the hardware paths that the pin can use. The wake condition is the interrupt trigger, so a pin that does not listen is not a wakeup source. A pin that listens already wakes the chip from light sleep through the digital path. See WakeupConfig.

The configuration stays after the driver is dropped, because a pad that wakes the chip from deep sleep must continue to do so while no driver owns it. To remove the configuration, call this function again with WakeupConfig::default().

§Errors

Returns WakeConfigError::NoLowPowerPath if the configuration requests the low-power path for a pad that has no such path.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn caused_wakeup(&self) -> bool

Returns whether this pin ended the most recent sleep.

More than one pin can end a sleep, so this function can return true for several pins. It returns false if the chip did not wake from a sleep, and false for a pin that ended an earlier sleep only.

esp-hal reads the result while the sleep ends, so a later clear of the interrupt of the pin does not change it. One case depends on the interrupt status: a pin that ends a light sleep without WakeupConfig::low_power_path. The interrupt handler of that pin clears the status, so the pin reports false if the handler runs before the sleep call returns. This can only occur if interrupts were enabled during the sleep.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn apply_output_config(&mut self, config: &OutputConfig)

Applies the given output configuration to the pin.

This function does not set the pin to output (i.e. it does not enable the output driver). Note that the pull direction is common between the input and output configuration.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn set_output_enable(&mut self, enable_output: bool)

Enable or disable the GPIO pin output driver.

The output level will be set to the last value. Use Self::set_high, Self::set_low or Self::set_level to set the output level before enabling the output.

This function does not disable the input buffer.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn set_high(&mut self)

Set the output as high.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn set_low(&mut self)

Set the output as low.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn set_level(&mut self, level: Level)

Set the output level.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn is_set_high(&self) -> bool

Is the output pin set as high?

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn is_set_low(&self) -> bool

Is the output pin set as low?

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn output_level(&self) -> Level

What level output is set to

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn toggle(&mut self)

Toggle pin output

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn peripheral_input(&self) -> InputSignal<'d>

Returns a peripheral input connected to this pin.

The input signal can be passed to peripherals in place of an input pin.

Note that the signal returned by this function is frozen.

use esp_hal::gpio::Flex;
let pin1_gpio = Flex::new(peripherals.GPIO1);
// Can be passed as an input.
let pin1 = pin1_gpio.peripheral_input();
// You can keep using the Flex, as well as connect the pin to a
// peripheral input.
§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn split(self) -> (InputSignal<'d>, OutputSignal<'d>)

Split the pin into an input and output signal pair.

Peripheral signals allow connecting peripherals together without using external hardware.

Note that the signals returned by this function is frozen.

use esp_hal::gpio::Flex;
let pin1 = Flex::new(peripherals.GPIO1);
let (input, output) = pin1.split();
§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub unsafe fn split_into_drivers(self) -> (Input<'d>, Output<'d>)

Split the pin into an Input and an Output driver pair.

Note that the signal returned by this function is frozen. On the other hand, the pin driver is free to change settings.

This function allows you to configure an input-output pin, then keep working with the output half. This is mainly intended for testing, allowing you to drive a peripheral from a signal generated by software.

§Safety

The caller must ensure that the pins are not being configured via their apply_config functions in the same time in multiple places. The pin drivers must not be turned back into Flex, unless one of the drivers is dropped first.

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source

pub fn into_peripheral_output(self) -> OutputSignal<'d>

Turns the pin object into a peripheral output.

The output signal can be passed to peripherals in place of an output pin.

Note that the signal returned by this function is frozen.

use esp_hal::gpio::Flex;
let pin1_gpio = Flex::new(peripherals.GPIO1);
// Can be passed as an output.
let pin1 = pin1_gpio.into_peripheral_output();
§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Trait Implementations§

Source§

impl<'d> Debug for Flex<'d>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ErrorType for Flex<'_>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

type Error = Infallible

Error type
Source§

impl<'d> From<Flex<'d>> for InputSignal<'d>

Source§

fn from(pin: Flex<'d>) -> Self

Converts to this type from the input type.
Source§

impl<'d> From<Flex<'d>> for OutputSignal<'d>

Source§

fn from(pin: Flex<'d>) -> Self

Converts to this type from the input type.
Source§

impl InputDriver for Flex<'_>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl InputDriver for &mut Flex<'_>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl InputPin for Flex<'_>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

fn is_high(&mut self) -> Result<bool, Self::Error>

Is the input pin high?
Source§

fn is_low(&mut self) -> Result<bool, Self::Error>

Is the input pin low?
Source§

impl OutputDriver for Flex<'_>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl OutputDriver for &mut Flex<'_>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl OutputPin for Flex<'_>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

fn set_low(&mut self) -> Result<(), Self::Error>

Drives the pin low. Read more
Source§

fn set_high(&mut self) -> Result<(), Self::Error>

Drives the pin high. Read more
Source§

fn set_state(&mut self, state: PinState) -> Result<(), Self::Error>

Drives the pin high or low depending on the provided value. Read more
Source§

impl<'d> PeripheralInput<'d> for Flex<'d>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl<'d> PeripheralOutput<'d> for Flex<'d>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl<'d> PeripheralSignal<'d> for Flex<'d>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

impl StatefulOutputPin for Flex<'_>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

fn is_set_high(&mut self) -> Result<bool, Self::Error>

Is the pin in drive high mode? Read more
Source§

fn is_set_low(&mut self) -> Result<bool, Self::Error>

Is the pin in drive low mode? Read more
Source§

fn toggle(&mut self) -> Result<(), Self::Error>

Toggle pin output.
Source§

impl Wait for Flex<'_>

§Stability

This API is marked as unstable and is only available when the unstable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.

Source§

async fn wait_for_high(&mut self) -> Result<(), Self::Error>

Wait until the pin is high. If it is already high, return immediately. Read more
Source§

async fn wait_for_low(&mut self) -> Result<(), Self::Error>

Wait until the pin is low. If it is already low, return immediately. Read more
Source§

async fn wait_for_rising_edge(&mut self) -> Result<(), Self::Error>

Wait for the pin to undergo a transition from low to high. Read more
Source§

async fn wait_for_falling_edge(&mut self) -> Result<(), Self::Error>

Wait for the pin to undergo a transition from high to low. Read more
Source§

async fn wait_for_any_edge(&mut self) -> Result<(), Self::Error>

Wait for the pin to undergo any transition, i.e low to high OR high to low.

Auto Trait Implementations§

§

impl<'d> !UnwindSafe for Flex<'d>

§

impl<'d> Freeze for Flex<'d>

§

impl<'d> RefUnwindSafe for Flex<'d>

§

impl<'d> Send for Flex<'d>

§

impl<'d> Sync for Flex<'d>

§

impl<'d> Unpin for Flex<'d>

§

impl<'d> UnsafeUnpin for Flex<'d>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.