esp_hal::gpio

Struct Output

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

Source

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,

Source

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

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.

Source

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.

Source

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.

Source

pub fn set_high(&mut self)

Set the output as high.

Source

pub fn set_low(&mut self)

Set the output as low.

Source

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

Set the output level.

Source

pub fn is_set_high(&self) -> bool

Is the output pin set as high?

Source

pub fn is_set_low(&self) -> bool

Is the output pin set as low?

Source

pub fn output_level(&self) -> Level

What level output is set to

Source

pub fn toggle(&mut self)

Toggle pin output

Source

pub fn set_drive_strength(&mut self, strength: DriveStrength)

Configure the DriveStrength of the pin

Trait Implementations§

Source§

impl<P> ErrorType for Output<'_, P>
where P: OutputPin,

Source§

type Error = Infallible

Error type
Source§

impl<P> OutputPin for Output<'_, P>
where P: OutputPin,

Source§

type Error = Infallible

Error type
Source§

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

Drives the pin high Read more
Source§

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

Drives the pin low 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<P> OutputPin for Output<'_, P>
where P: OutputPin,

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, P> Peripheral for Output<'d, P>

Source§

type P = Flex<'d, P>

Peripheral singleton type
Source§

unsafe fn clone_unchecked(&self) -> Self::P

Unsafely clone (duplicate) a peripheral singleton. Read more
Source§

fn into_ref<'a>(self) -> PeripheralRef<'a, Self::P>
where Self: 'a,

Convert a value into a PeripheralRef. Read more
Source§

fn map_into<U>(self) -> U
where Self::P: Into<U>, U: Peripheral<P = U>,

Map the peripheral using Into. Read more
Source§

impl<P> StatefulOutputPin for Output<'_, P>
where P: OutputPin,

Source§

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

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

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

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

impl<P> StatefulOutputPin for Output<'_, P>
where P: OutputPin,

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

impl<P> ToggleableOutputPin for Output<'_, P>
where P: OutputPin,

Source§

type Error = Infallible

Error type
Source§

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

Toggle pin output.

Auto Trait Implementations§

§

impl<'d, P> Freeze for Output<'d, P>
where P: Freeze,

§

impl<'d, P> RefUnwindSafe for Output<'d, P>
where P: RefUnwindSafe,

§

impl<'d, P> Send for Output<'d, P>
where P: Send,

§

impl<'d, P> Sync for Output<'d, P>
where P: Sync,

§

impl<'d, P> Unpin for Output<'d, P>
where P: Unpin,

§

impl<'d, P = AnyPin> !UnwindSafe for Output<'d, P>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.