pub struct Flex<'d> { /* private fields */ }
Expand description
GPIO flexible pin.
This pin can either be a disconnected, input, or output pin, or both. The level register bit will remain set while not in output mode, so the pin’s level will be ‘remembered’ when it is not in output mode.
Implementations§
Source§impl<'d> Flex<'d>
impl<'d> Flex<'d>
Sourcepub fn new(pin: Peri<'d, impl Pin>) -> Self
pub fn new(pin: Peri<'d, impl Pin>) -> Self
Wrap the pin in a Flex
.
The pin remains disconnected. The initial output level is unspecified, but can be changed before the pin is put into output mode.
pub fn set_slewrate(&mut self, rate: SlewRate)
Sourcepub fn set_schmitt(&mut self, enable: bool)
pub fn set_schmitt(&mut self, enable: bool)
Set the pin’s Schmitt trigger.
Sourcepub fn set_as_input(&mut self)
pub fn set_as_input(&mut self)
Put the pin into input mode.
The pull setting is left unchanged.
Sourcepub fn set_as_output(&mut self)
pub fn set_as_output(&mut self)
Put the pin into output mode.
The pin level will be whatever was set before (or low by default). If you want it to begin
at a specific level, call set_high
/set_low
on the pin first.
Sourcepub fn set_as_input_output(&mut self)
pub fn set_as_input_output(&mut self)
Put the pin into input + open-drain output mode.
The hardware will drive the line low if you set it to low, and will leave it floating if you set it to high, in which case you can read the input to figure out whether another device is driving the line low.
The pin level will be whatever was set before (or low by default). If you want it to begin
at a specific level, call set_high
/set_low
on the pin first.
The internal weak pull-up and pull-down resistors will be disabled.
Sourcepub fn set_as_disconnected(&mut self)
pub fn set_as_disconnected(&mut self)
Set the pin as “disconnected”, ie doing nothing and consuming the lowest amount of power possible.
This is currently the same as [Self::set_as_analog()
] but is semantically different
really. Drivers should set_as_disconnected()
pins when dropped.
Note that this also disables the pull-up and pull-down resistors.
Sourcepub fn get_output_level(&self) -> Level
pub fn get_output_level(&self) -> Level
Get the current pin output level.
Sourcepub fn is_set_high(&self) -> bool
pub fn is_set_high(&self) -> bool
Is the output level high?
If the Flex
is set as an input, then this is equivalent to Flex::is_high
.
Sourcepub fn is_set_low(&self) -> bool
pub fn is_set_low(&self) -> bool
Is the output level low?
If the Flex
is set as an input, then this is equivalent to Flex::is_low
.
Sourcepub async fn wait_for_high(&mut self)
pub async fn wait_for_high(&mut self)
Wait until the pin is high. If it is already high, return immediately.
Sourcepub async fn wait_for_low(&mut self)
pub async fn wait_for_low(&mut self)
Wait until the pin is low. If it is already low, return immediately.
Sourcepub async fn wait_for_rising_edge(&mut self)
pub async fn wait_for_rising_edge(&mut self)
Wait for the pin to undergo a transition from low to high.
Sourcepub async fn wait_for_falling_edge(&mut self)
pub async fn wait_for_falling_edge(&mut self)
Wait for the pin to undergo a transition from high to low.
Sourcepub async fn wait_for_any_edge(&mut self)
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.