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 Peripheral<P = impl OutputPin> + 'd,
initial_level: Level,
config: OutputConfig,
) -> Self
pub fn new( pin: impl Peripheral<P = 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 split(self) -> (InputSignal, OutputSignal)
Available on crate feature unstable
only.
pub fn split(self) -> (InputSignal, OutputSignal)
unstable
only.Split the pin into an input and output signal.
Peripheral signals allow connecting peripherals together without using external hardware.
let pin1 = Output::new(peripherals.GPIO1, Level::High, config);
let (input, output) = pin1.split();
§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 peripheral_input(&self) -> InputSignal
Available on crate feature unstable
only.
pub fn peripheral_input(&self) -> InputSignal
unstable
only.Returns a peripheral input connected to this pin.
The input signal can be passed to peripherals in place of an input pin.
let pin1_gpio = Output::new(peripherals.GPIO1, Level::High, config);
// Can be passed as an input.
let input = pin1_gpio.peripheral_input();
§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 into_peripheral_output(self) -> OutputSignal
Available on crate feature unstable
only.
pub fn into_peripheral_output(self) -> OutputSignal
unstable
only.Turns the pin object into a peripheral output.
The output signal can be passed to peripherals in place of an output pin.
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> Peripheral for Output<'d>
impl<'d> Peripheral for Output<'d>
Source§unsafe fn clone_unchecked(&self) -> Self::P
unsafe fn clone_unchecked(&self) -> Self::P
Source§fn into_ref<'a>(self) -> PeripheralRef<'a, Self::P>where
Self: 'a,
fn into_ref<'a>(self) -> PeripheralRef<'a, Self::P>where
Self: 'a,
PeripheralRef
. Read more