pub struct Input<'d, P = AnyPin> { /* private fields */ }Expand description
Digital input.
This driver configures the GPIO pin to be an input. Input drivers read the
voltage of their pins and convert it to a logical Level.
Implementations§
Source§impl<P> Input<'_, P>where
P: InputPin,
impl<P> Input<'_, P>where
P: InputPin,
Sourcepub async fn wait_for_high(&mut self)
pub async fn wait_for_high(&mut self)
Wait until the pin is high. If it is already high, return immediately.
Sourcepub async fn wait_for_low(&mut self)
pub async fn wait_for_low(&mut self)
Wait until the pin is low. If it is already low, return immediately.
Sourcepub async fn wait_for_rising_edge(&mut self)
pub async fn wait_for_rising_edge(&mut self)
Wait for the pin to undergo a transition from low to high.
Sourcepub async fn wait_for_falling_edge(&mut self)
pub async fn wait_for_falling_edge(&mut self)
Wait for the pin to undergo a transition from high to low.
Sourcepub async fn wait_for_any_edge(&mut self)
pub async fn wait_for_any_edge(&mut self)
Wait for the pin to undergo any transition, i.e low to high OR high to low.
Source§impl<'d> Input<'d>
impl<'d> Input<'d>
Sourcepub fn new(pin: impl Peripheral<P = impl InputPin> + 'd, pull: Pull) -> Self
pub fn new(pin: impl Peripheral<P = impl InputPin> + 'd, pull: Pull) -> Self
Creates a new, type-erased GPIO input.
The pull parameter configures internal pull-up or pull-down
resistors.
§Example
The following example configures GPIO5 to read a button press. The
example assumes that the button is connected such that the pin is low
when the button is pressed.
use esp_hal::gpio::{Level, Input, Pull};
use esp_hal::delay::Delay;
fn print_when_pressed(button: &mut Input<'_>, delay: &mut Delay) {
let mut was_pressed = false;
loop {
let is_pressed = button.is_low();
if is_pressed && !was_pressed {
println!("Button pressed!");
}
was_pressed = is_pressed;
delay.delay_millis(100);
}
}
let mut button = Input::new(
peripherals.GPIO5,
Pull::Up,
);
let mut delay = Delay::new();
print_when_pressed(&mut button, &mut delay);Source§impl<'d, P> Input<'d, P>where
P: InputPin,
impl<'d, P> Input<'d, P>where
P: InputPin,
Sourcepub fn new_typed(pin: impl Peripheral<P = P> + 'd, pull: Pull) -> Self
pub fn new_typed(pin: impl Peripheral<P = P> + 'd, pull: Pull) -> Self
Creates a new, typed GPIO input.
The pull parameter configures internal pull-up or pull-down
resistors.
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 read a button press. The
example assumes that the button is connected such that the pin is low
when the button is pressed.
use esp_hal::gpio::{GpioPin, Level, Input, Pull};
use esp_hal::delay::Delay;
fn print_when_pressed(
button: &mut Input<'_, GpioPin<5>>,
delay: &mut Delay,
) {
let mut was_pressed = false;
loop {
let is_pressed = button.is_low();
if is_pressed && !was_pressed {
println!("Button pressed!");
}
was_pressed = is_pressed;
delay.delay_millis(100);
}
}
let mut button = Input::new_typed(
peripherals.GPIO5,
Pull::Up,
);
let mut delay = Delay::new();
print_when_pressed(&mut button, &mut delay);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 clear_interrupt(&mut self)
pub fn clear_interrupt(&mut self)
Clear the interrupt status bit for this Pin
Sourcepub fn is_interrupt_set(&self) -> bool
pub fn is_interrupt_set(&self) -> bool
Checks if the interrupt status bit for this Pin is set
Sourcepub fn wakeup_enable(&mut self, enable: bool, event: WakeEvent)
pub fn wakeup_enable(&mut self, enable: bool, event: WakeEvent)
Enable as a wake-up source.
This will unlisten for interrupts
Source§impl<P> Input<'_, P>
impl<P> Input<'_, P>
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 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.