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

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.

Source

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

Change the configuration.

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

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.

Source

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.

Source

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.

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.

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 = Infallible

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

Auto Trait Implementations§

§

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> !UnwindSafe for Output<'d>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.