pub struct Output<'d> { /* private fields */ }
Expand description
Push-pull digital output.
This driver configures the GPIO pin to be an output driver.
Implementations§
Source§impl<'d> Output<'d>
impl<'d> Output<'d>
Sourcepub fn new(
pin: impl OutputPin + 'd,
initial_level: Level,
config: OutputConfig,
) -> Self
pub fn new( pin: impl OutputPin + 'd, initial_level: Level, config: OutputConfig, ) -> Self
Creates a new GPIO output driver.
The initial_level
parameter sets the initial output level of the pin.
The config
parameter sets the drive mode, drive strength, and pull
direction of the pin.
§Example
The following example configures GPIO5
to pulse a LED once. The
example assumes that the LED is connected such that it is on when
the pin is low.
use esp_hal::gpio::{Level, Output, OutputConfig};
use esp_hal::delay::Delay;
fn blink_once(led: &mut Output<'_>, delay: &mut Delay) {
led.set_low();
delay.delay_millis(500);
led.set_high();
}
let config = OutputConfig::default();
let mut led = Output::new(peripherals.GPIO5, Level::High, config);
let mut delay = Delay::new();
blink_once(&mut led, &mut delay);
Sourcepub fn into_peripheral_output(self) -> OutputSignal<'d>
Available on crate feature unstable
only.
pub fn into_peripheral_output(self) -> OutputSignal<'d>
unstable
only.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.
let pin1_gpio = Output::new(peripherals.GPIO1, Level::High, config);
let output = 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.
Sourcepub fn apply_config(&mut self, config: &OutputConfig)
pub fn apply_config(&mut self, config: &OutputConfig)
Change the configuration.
Sourcepub fn is_set_high(&self) -> bool
pub fn is_set_high(&self) -> bool
Returns whether the pin is set to high level.
This function reads back the value set using set_level
, set_high
or
set_low
. It does not need the input stage to be enabled.
Sourcepub fn is_set_low(&self) -> bool
pub fn is_set_low(&self) -> bool
Returns whether the pin is set to low level.
This function reads back the value set using set_level
, set_high
or
set_low
. It does not need the input stage to be enabled.
Sourcepub fn output_level(&self) -> Level
pub fn output_level(&self) -> Level
Returns which level the pin is set to.
This function reads back the value set using set_level
, set_high
or
set_low
. It does not need the input stage to be enabled.
Sourcepub fn toggle(&mut self)
pub fn toggle(&mut self)
Toggles the pin output.
If the pin was previously set to high, it will be set to low, and vice versa.
Trait Implementations§
Source§impl<'d> From<Output<'d>> for OutputSignal<'d>
Available on crate feature unstable
only.§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.
impl<'d> From<Output<'d>> for OutputSignal<'d>
unstable
only.§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 Output<'_>
impl StatefulOutputPin for Output<'_>
impl<'d> PeripheralOutput<'d> for Output<'d>
unstable
only.§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.
impl<'d> PeripheralSignal<'d> for Output<'d>
unstable
only.§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.