Struct lpc8xx_hal::gpio::GpioPin
source · [−]pub struct GpioPin<P, D> { /* private fields */ }
Expand description
A pin used for general purpose I/O (GPIO).
This struct is a wrapper around the representation of a specific pin P
– it enables said pin
to be used as a GPIO pin.
You can get access to an instance of this struct by switching a pin to the
GPIO state, using Pin::into_input_pin
or Pin::into_output_pin
.
embedded-hal
traits
- While in input mode
embedded_hal::digital::v2::InputPin
for reading the pin state
- While in output mode
embedded_hal::digital::v2::OutputPin
for setting the pin stateembedded_hal::digital::v2::StatefulOutputPin
for reading the pin output stateembedded_hal::digital::v2::ToggleableOutputPin
for toggling the pin state
Implementations
sourceimpl<P, D> GpioPin<P, D>where
P: Trait,
D: Direction,
impl<P, D> GpioPin<P, D>where
P: Trait,
D: Direction,
sourcepub fn inner(&self) -> &P
pub fn inner(&self) -> &P
Get identifying information about this pin in the form of a pins::Trait
sourceimpl<P> GpioPin<P, Input>where
P: Trait,
impl<P> GpioPin<P, Input>where
P: Trait,
sourcepub fn into_output(self, initial: Level) -> GpioPin<P, Output>
pub fn into_output(self, initial: Level) -> GpioPin<P, Output>
Set pin direction to output
This method is only available while the pin is in input mode.
Consumes the pin instance and returns a new instance that is in output mode, making the methods to set the output level available.
sourcepub fn into_dynamic(
self,
initial_level: Level,
initial_direction: DynamicPinDirection
) -> GpioPin<P, Dynamic>
pub fn into_dynamic(
self,
initial_level: Level,
initial_direction: DynamicPinDirection
) -> GpioPin<P, Dynamic>
Set pin direction to dynamic (i.e. changeable at runtime)
This method is only available when the pin is not already in dynamic mode.
Consumes the pin instance and returns a new instance that is in dynamic mode, making the methods to change direction as well as read/set levels (depending on the current diection) available.
sourcepub fn is_high(&self) -> bool
pub fn is_high(&self) -> bool
Indicates wether the voltage at the pin is currently HIGH
This method is only available, if two conditions are met:
- The pin is in the GPIO state.
- The pin direction is set to input.
See Pin::into_input_pin
and into_input
. Unless both of these
conditions are met, code trying to call this method will not compile.
sourcepub fn is_low(&self) -> bool
pub fn is_low(&self) -> bool
Indicates wether the pin input is LOW
This method is only available, if two conditions are met:
- The pin is in the GPIO state.
- The pin direction is set to input.
See Pin::into_input_pin
and into_input
. Unless both of these
conditions are met, code trying to call this method will not compile.
sourcepub fn get_level(&self) -> Level
pub fn get_level(&self) -> Level
Returns the current voltage level at this pin.
This method is only available, if two conditions are met:
- The pin is in the GPIO state.
- The pin direction is set to input.
See Pin::into_input_pin
and into_input
. Unless both of these
conditions are met, code trying to call this method will not compile.
sourceimpl<P> GpioPin<P, Output>where
P: Trait,
impl<P> GpioPin<P, Output>where
P: Trait,
sourcepub fn into_input(self) -> GpioPin<P, Input>
pub fn into_input(self) -> GpioPin<P, Input>
Set pin direction to input
This method is only available while the pin is in output mode.
Consumes the pin instance and returns a new instance that is in output mode, making the methods to set the output level available.
sourcepub fn into_dynamic(
self,
initial_level: Level,
initial_direction: DynamicPinDirection
) -> GpioPin<P, Dynamic>
pub fn into_dynamic(
self,
initial_level: Level,
initial_direction: DynamicPinDirection
) -> GpioPin<P, Dynamic>
Set pin direction to dynamic (i.e. changeable at runtime)
This method is only available when the pin is not already in dynamic mode.
Consumes the pin instance and returns a new instance that is in dynamic mode, making the methods to change direction as well as read/set levels (depending on the current diection) available.
sourcepub fn set_high(&mut self)
pub fn set_high(&mut self)
Set the pin output to HIGH
This method is only available, if two conditions are met:
- The pin is in the GPIO state.
- The pin direction is set to output.
See Pin::into_output_pin
and into_output
. Unless both of these
conditions are met, code trying to call this method will not compile.
sourcepub fn set_low(&mut self)
pub fn set_low(&mut self)
Set the pin output to LOW
This method is only available, if two conditions are met:
- The pin is in the GPIO state.
- The pin direction is set to output.
See Pin::into_output_pin
and into_output
. Unless both of these
conditions are met, code trying to call this method will not compile.
sourcepub fn is_set_high(&self) -> bool
pub fn is_set_high(&self) -> bool
Indicates whether the pin output is currently set to HIGH
This method is only available, if two conditions are met:
- The pin is in the GPIO state.
- The pin direction is set to output.
See Pin::into_output_pin
and into_output
. Unless both of these
conditions are met, code trying to call this method will not compile.
sourcepub fn is_set_low(&self) -> bool
pub fn is_set_low(&self) -> bool
Indicates whether the pin output is currently set to LOW
This method is only available, if two conditions are met:
- The pin is in the GPIO state.
- The pin direction is set to output.
See Pin::into_output_pin
and into_output
. Unless both of these
conditions are met, code trying to call this method will not compile.
sourcepub fn get_set_level(&self) -> Level
pub fn get_set_level(&self) -> Level
Returns the level to which this pin is currently set
This method is only available, if two conditions are met:
- The pin is in the GPIO state.
- The pin direction is set to output.
See Pin::into_output_pin
and into_output
. Unless both of these
conditions are met, code trying to call this method will not compile.
sourcepub fn toggle(&mut self)
pub fn toggle(&mut self)
Toggle the pin output
This method is only available, if two conditions are met:
- The pin is in the GPIO state.
- The pin direction is set to output.
See Pin::into_output_pin
and into_output
. Unless both of these
conditions are met, code trying to call this method will not compile.
sourceimpl<P> GpioPin<P, Dynamic>where
P: Trait,
impl<P> GpioPin<P, Dynamic>where
P: Trait,
sourcepub fn direction_is_output(&self) -> bool
pub fn direction_is_output(&self) -> bool
Tell us whether this pin’s direction is currently set to Output.
sourcepub fn direction_is_input(&self) -> bool
pub fn direction_is_input(&self) -> bool
Tell us whether this pin’s direction is currently set to Input.
sourcepub fn switch_to_input(&mut self)
pub fn switch_to_input(&mut self)
Switch pin direction to input. If the pin is already an input pin, this does nothing.
sourcepub fn switch_to_output(&mut self, level: Level)
pub fn switch_to_output(&mut self, level: Level)
Switch pin direction to output with output level set to level
.
If the pin is already an output pin, this function only switches its level to level
.
sourcepub fn set_high(&mut self)
pub fn set_high(&mut self)
Set the pin level to High. Note that this will be executed regardless of the current pin direction. This enables you to set the initial pin level before switching to output
sourcepub fn set_low(&mut self)
pub fn set_low(&mut self)
Set the pin level to Low. Note that this will be executed regardless of the current pin direction. This enables you to set the initial pin level before switching to output
sourcepub fn get_level(&self) -> Level
pub fn get_level(&self) -> Level
Returns the current voltage level at this pin. This can be used when the pin is in any direction:
If it is currently an Output pin, it indicates to which level the pin is set If it is currently an Input pin, it indicates the level currently present at this pin
This method is only available, if the pin has been set to dynamic mode.
See Pin::into_dynamic_pin
.
Unless this condition is met, code trying to call this method will not compile.