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>
impl<'d> OutputOpenDrain<'d>
Sourcepub fn new(
pin: impl Peripheral<P = impl InputPin + OutputPin> + 'd,
initial_output: Level,
pull: Pull,
) -> Self
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>
impl<'d, P> OutputOpenDrain<'d, P>
Sourcepub fn new_typed(
pin: impl Peripheral<P = P> + 'd,
initial_output: Level,
pull: Pull,
) -> Self
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);Sourcepub fn split(self) -> (InputSignal, OutputSignal)
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.
Sourcepub fn peripheral_input(&self) -> InputSignal
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.
Sourcepub fn into_peripheral_output(self) -> OutputSignal
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.
Sourcepub fn clear_interrupt(&mut self)
pub fn clear_interrupt(&mut self)
Clear the interrupt status bit for this Pin
Sourcepub fn is_set_high(&self) -> bool
pub fn is_set_high(&self) -> bool
Is the output pin set as high?
Sourcepub fn is_set_low(&self) -> bool
pub fn is_set_low(&self) -> bool
Is the output pin set as low?
Sourcepub fn output_level(&self) -> Level
pub fn output_level(&self) -> Level
What level output is set to
Sourcepub fn set_drive_strength(&mut self, strength: DriveStrength)
pub fn set_drive_strength(&mut self, strength: DriveStrength)
Configure the DriveStrength of the pin