esp_hal::gpio

Struct OutputOpenDrain

Source
pub struct OutputOpenDrain<'d, P = AnyPin> { /* private fields */ }
Expand description

Open drain digital output.

This driver configures the GPIO pin to be an open drain output driver. Open drain means that the driver actively pulls the output voltage level low for the low logical Level, but leaves the high level floating, which is then determined by external hardware, or internal pull-up/pull-down resistors.

Implementations§

Source§

impl<'d> OutputOpenDrain<'d>

Source

pub fn new( pin: impl Peripheral<P = impl InputPin + OutputPin> + 'd, initial_output: Level, pull: Pull, ) -> Self

Creates a new, type-erased GPIO output driver.

The initial_output parameter sets the initial output level of the pin. The pull parameter configures internal pull-up or pull-down resistors.

§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, OutputOpenDrain, Pull};
use esp_hal::delay::Delay;

fn blink_once(led: &mut OutputOpenDrain<'_>, delay: &mut Delay) {
    led.set_low();
    delay.delay_millis(500);
    led.set_high();
}

let mut led = OutputOpenDrain::new(
    peripherals.GPIO5,
    Level::High,
    Pull::Up,
);
let mut delay = Delay::new();

blink_once(&mut led, &mut delay);
Source§

impl<'d, P> OutputOpenDrain<'d, P>
where P: InputPin + OutputPin,

Source

pub fn new_typed( pin: impl Peripheral<P = P> + 'd, initial_output: Level, pull: Pull, ) -> Self

Creates a new, typed GPIO output driver.

The initial_output parameter sets the initial output level of the pin. The pull parameter configures internal pull-up or pull-down resistors.

§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, OutputOpenDrain, Pull};
use esp_hal::delay::Delay;

fn blink_once(
    led: &mut OutputOpenDrain<'_, GpioPin<5>>,
    delay: &mut Delay,
) {
    led.set_low();
    delay.delay_millis(500);
    led.set_high();
}

let mut led = OutputOpenDrain::new_typed(
    peripherals.GPIO5,
    Level::High,
    Pull::Up,
);
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 is_high(&self) -> bool

Get whether the pin input level is high.

Source

pub fn is_low(&self) -> bool

Get whether the pin input level is low.

Source

pub fn level(&self) -> Level

Get the current pin input level.

Source

pub fn listen(&mut self, event: Event)

Listen for interrupts

Source

pub fn clear_interrupt(&mut self)

Clear the interrupt status bit for this 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 OutputOpenDrain<'_, P>
where P: InputPin + OutputPin,

Source§

type Error = Infallible

Error type
Source§

impl<P> InputPin for OutputOpenDrain<'_, P>
where P: InputPin + OutputPin,

Source§

type Error = Infallible

Error type
Source§

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

Is the input pin high?
Source§

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

Is the input pin low?
Source§

impl<P> InputPin for OutputOpenDrain<'_, P>
where P: InputPin + OutputPin,

Source§

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

Is the input pin high?
Source§

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

Is the input pin low?
Source§

impl<P> OutputPin for OutputOpenDrain<'_, P>
where P: InputPin + 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 OutputOpenDrain<'_, P>
where P: InputPin + 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 OutputOpenDrain<'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 OutputOpenDrain<'_, P>
where P: InputPin + 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 OutputOpenDrain<'_, P>
where P: InputPin + 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 OutputOpenDrain<'_, P>
where P: InputPin + 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 OutputOpenDrain<'d, P>
where P: Freeze,

§

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

§

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

§

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

§

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

§

impl<'d, P = AnyPin> !UnwindSafe for OutputOpenDrain<'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.