pub struct Output<'d, P = AnyPin> { /* private fields */ }Expand description
Push-pull digital output.
This driver configures the GPIO pin to be a push-pull output driver.
Push-pull means that the driver actively sets the output voltage level
for both high and low logical Levels.
Implementations§
Source§impl<'d> Output<'d>
impl<'d> Output<'d>
Sourcepub fn new(
pin: impl Peripheral<P = impl OutputPin> + 'd,
initial_output: Level,
) -> Self
pub fn new( pin: impl Peripheral<P = impl OutputPin> + 'd, initial_output: Level, ) -> Self
Creates a new, type-erased GPIO output driver.
The initial_output parameter sets the initial output level 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};
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 mut led = Output::new(peripherals.GPIO5, Level::High);
let mut delay = Delay::new();
blink_once(&mut led, &mut delay);Source§impl<'d, P> Output<'d, P>where
P: OutputPin,
impl<'d, P> Output<'d, P>where
P: OutputPin,
Sourcepub fn new_typed(
pin: impl Peripheral<P = P> + 'd,
initial_output: Level,
) -> Self
pub fn new_typed( pin: impl Peripheral<P = P> + 'd, initial_output: Level, ) -> Self
Creates a new, typed GPIO output driver.
The initial_output parameter sets the initial output level of the pin.
This constructor is useful when you want to limit which GPIO pin can be used for a particular function.
§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::{GpioPin, Level, Output};
use esp_hal::delay::Delay;
fn blink_once(led: &mut Output<'_, GpioPin<5>>, delay: &mut Delay) {
led.set_low();
delay.delay_millis(500);
led.set_high();
}
let mut led = Output::new_typed(peripherals.GPIO5, Level::High);
let mut delay = Delay::new();
blink_once(&mut led, &mut delay);Sourcepub fn split(self) -> (InputSignal, OutputSignal)
pub fn split(self) -> (InputSignal, OutputSignal)
Split the pin into an input and output signal.
Peripheral signals allow connecting peripherals together without using external hardware.
Sourcepub fn peripheral_input(&self) -> InputSignal
pub fn peripheral_input(&self) -> InputSignal
Returns a peripheral input connected to this pin.
The input signal can be passed to peripherals in place of an input pin.
Sourcepub fn into_peripheral_output(self) -> OutputSignal
pub fn into_peripheral_output(self) -> OutputSignal
Turns the pin object into a peripheral output.
The output signal can be passed to peripherals in place of an output pin.
Sourcepub fn is_set_high(&self) -> bool
pub fn is_set_high(&self) -> bool
Is the output pin set as high?
Sourcepub fn is_set_low(&self) -> bool
pub fn is_set_low(&self) -> bool
Is the output pin set as low?
Sourcepub fn output_level(&self) -> Level
pub fn output_level(&self) -> Level
What level output is set to
Sourcepub fn set_drive_strength(&mut self, strength: DriveStrength)
pub fn set_drive_strength(&mut self, strength: DriveStrength)
Configure the DriveStrength of the pin