Skip to main content

Output

Struct Output 

Source
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>

Source

pub fn into_lp<const PIN: u8>(self) -> Result<LowPowerOutput<'d, PIN>, Self>

Available on crate feature unstable only.

Hands the pin over to the low-power core.

PIN is the low-power pin number, which is how low-power core firmware refers to the pin.

§Errors

The original driver when the pad is not the low-power pin numbered PIN.

§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

pub fn into_open_drain_lp<const PIN: u8>( self, ) -> Result<LowPowerOutputOpenDrain<'d, PIN>, Self>

Available on crate feature unstable only.

Hands the pin over to the low-power core as an open-drain output.

PIN is the low-power pin number, which is how low-power core firmware refers to the pin. The pad’s pull-up is enabled, regardless of the driver’s configuration.

§Errors

The original driver when the pad is not the low-power pin numbered PIN.

§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<'d> Output<'d>

Source

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.

§Examples

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::{
    delay::Delay,
    gpio::{Level, Output, OutputConfig},
};

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);
Source

pub fn into_peripheral_output(self) -> OutputSignal<'d>

Available on crate feature unstable only.

Turns the pin object into a peripheral output.

The output signal can be passed to peripherals in place of an output pin.

The returned signal is frozen.

§Examples
use esp_hal::gpio::{Level, Output, OutputConfig};
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.

Source

pub fn apply_config(&mut self, config: &OutputConfig)

Changes the configuration.

§Examples
use esp_hal::gpio::{DriveMode, Level, Output, OutputConfig};
let mut pin = Output::new(peripherals.GPIO5, Level::High, OutputConfig::default());

pin.apply_config(&OutputConfig::default().with_drive_mode(DriveMode::OpenDrain));
Source

pub fn set_high(&mut self)

Sets the output as high.

§Examples
use esp_hal::gpio::{Level, Output, OutputConfig};
let mut pin = Output::new(peripherals.GPIO5, Level::Low, OutputConfig::default());
pin.set_high();
Source

pub fn set_low(&mut self)

Sets the output as low.

§Examples
use esp_hal::gpio::{Level, Output, OutputConfig};
let mut pin = Output::new(peripherals.GPIO5, Level::High, OutputConfig::default());
pin.set_low();
Source

pub fn set_level(&mut self, level: Level)

Sets the output level.

§Examples
use esp_hal::gpio::{Level, Output, OutputConfig};
let mut pin = Output::new(peripherals.GPIO5, Level::High, OutputConfig::default());
pin.set_level(Level::Low);
Source

pub fn is_set_high(&self) -> bool

Returns whether the pin is set to high level.

Reads back the value set using set_level, set_high or set_low. Does not need the input stage to be enabled.

§Examples
use esp_hal::gpio::{Level, Output, OutputConfig};
let pin = Output::new(peripherals.GPIO5, Level::High, OutputConfig::default());
let is_high = pin.is_set_high();
Source

pub fn is_set_low(&self) -> bool

Returns whether the pin is set to low level.

Reads back the value set using set_level, set_high or set_low. Does not need the input stage to be enabled.

§Examples
use esp_hal::gpio::{Level, Output, OutputConfig};
let pin = Output::new(peripherals.GPIO5, Level::High, OutputConfig::default());
let is_low = pin.is_set_low();
Source

pub fn output_level(&self) -> Level

Returns which level the pin is set to.

Reads back the value set using set_level, set_high or set_low. Does not need the input stage to be enabled.

§Examples
use esp_hal::gpio::{Level, Output, OutputConfig};
let pin = Output::new(peripherals.GPIO5, Level::High, OutputConfig::default());
let level = pin.output_level();
Source

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.

§Examples
use esp_hal::gpio::{Level, Output, OutputConfig};
let mut pin = Output::new(peripherals.GPIO5, Level::High, OutputConfig::default());
pin.toggle();
Source

pub fn set_pad_hold(&mut self, enable: bool)

Available on crate feature unstable only.

Takes or releases the hold of the pad.

A held pad keeps its level, its function and its resistors, and it ignores this driver.

§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

pub fn is_pad_held(&self) -> bool

Available on crate feature unstable only.

Returns whether something holds the pad.

§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

pub fn into_flex(self) -> Flex<'d>

Available on crate feature unstable only.

Converts the pin driver into a Flex driver.

§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.

Trait Implementations§

Source§

impl<'d> Debug for Output<'d>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl ErrorType for Output<'_>

Source§

type Error = !

Error type
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.

Source§

fn from(pin: Output<'d>) -> Self

Converts to this type from the input type.
Source§

impl OutputDriver for Output<'_>

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.

Source§

impl OutputDriver for &mut Output<'_>

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.

Source§

impl OutputPin for Output<'_>

Source§

fn set_low(&mut self) -> Result<(), Self::Error>

Drives the pin low. Read more
Source§

fn set_high(&mut self) -> Result<(), Self::Error>

Drives the pin high. Read more
Source§

fn set_state(&mut self, state: PinState) -> Result<(), Self::Error>

Drives the pin high or low depending on the provided value. Read more
Source§

impl<'d> PeripheralOutput<'d> for Output<'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.

Source§

impl<'d> PeripheralSignal<'d> for Output<'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.

Source§

impl StatefulOutputPin for Output<'_>

Source§

fn is_set_high(&mut self) -> Result<bool, Self::Error>

Is the pin in drive high mode? Read more
Source§

fn is_set_low(&mut self) -> Result<bool, Self::Error>

Is the pin in drive low mode? Read more
Source§

fn toggle(&mut self) -> Result<(), Self::Error>

Toggle pin output.

Auto Trait Implementations§

§

impl<'d> !UnwindSafe for Output<'d>

§

impl<'d> Freeze for Output<'d>

§

impl<'d> RefUnwindSafe for Output<'d>

§

impl<'d> Send for Output<'d>

§

impl<'d> Sync for Output<'d>

§

impl<'d> Unpin for Output<'d>

§

impl<'d> UnsafeUnpin for Output<'d>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.