Struct embassy_stm32::gpio::Flex
source · pub struct Flex<'d, T: Pin> { /* 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, T: Pin> Flex<'d, T>
impl<'d, T: Pin> Flex<'d, T>
sourcepub fn new(pin: impl Peripheral<P = T> + 'd) -> Self
pub fn new(pin: impl Peripheral<P = T> + 'd) -> 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.
sourcepub fn degrade(self) -> Flex<'d, AnyPin>
pub fn degrade(self) -> Flex<'d, AnyPin>
Type-erase (degrade) this pin into an AnyPin
.
This converts pin singletons (PA5
, PB6
, …), which
are all different types, into the same type. It is useful for
creating arrays of pins, or avoiding generics.
sourcepub fn set_as_input(&mut self, pull: Pull)
pub fn set_as_input(&mut self, pull: Pull)
Put the pin into input mode.
sourcepub fn set_as_output(&mut self, speed: Speed)
pub fn set_as_output(&mut self, speed: Speed)
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, speed: Speed, pull: Pull)
pub fn set_as_input_output(&mut self, speed: Speed, pull: Pull)
Put the pin into input + output mode.
This is commonly used for “open drain” 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.
sourcepub fn is_set_high(&self) -> bool
pub fn is_set_high(&self) -> bool
Get whether the output level is set to high.
sourcepub fn is_set_low(&self) -> bool
pub fn is_set_low(&self) -> bool
Get whether the output level is set to low.
sourcepub fn get_output_level(&self) -> Level
pub fn get_output_level(&self) -> Level
Get the current output level.