Struct rppal::gpio::InputPin

source ·
pub struct InputPin { /* private fields */ }
Expand description

GPIO pin configured as input.

InputPins are constructed by converting a Pin using Pin::into_input, Pin::into_input_pullup or Pin::into_input_pulldown. The pin’s mode is automatically set to Mode::Input.

An InputPin can be used to read a pin’s logic level, or (a)synchronously poll for interrupt trigger events.

The embedded-hal trait implementations for InputPin can be enabled by specifying the optional hal feature in the dependency declaration for the rppal crate.

Implementations§

source§

impl InputPin

source

pub fn pin(&self) -> u8

Returns the GPIO pin number.

Pins are addressed by their BCM numbers, rather than their physical location.

source

pub fn read(&self) -> Level

Reads the pin’s logic level.

source

pub fn is_low(&self) -> bool

Reads the pin’s logic level, and returns true if it’s set to Low.

source

pub fn is_high(&self) -> bool

Reads the pin’s logic level, and returns true if it’s set to High.

source

pub fn set_interrupt(&mut self, trigger: Trigger) -> Result<()>

Configures a synchronous interrupt trigger.

After configuring a synchronous interrupt trigger, call poll_interrupt or Gpio::poll_interrupts to block while waiting for a trigger event.

Any previously configured (a)synchronous interrupt triggers will be cleared.

source

pub fn clear_interrupt(&mut self) -> Result<()>

Removes a previously configured synchronous interrupt trigger.

source

pub fn poll_interrupt( &mut self, reset: bool, timeout: Option<Duration> ) -> Result<Option<Level>>

Blocks until an interrupt is triggered on the pin, or a timeout occurs.

This only works after the pin has been configured for synchronous interrupts using set_interrupt. Asynchronous interrupt triggers are automatically polled on a separate thread.

Calling poll_interrupt blocks any other calls to poll_interrupt (including on other InputPins) or Gpio::poll_interrupts until it returns. If you need to poll multiple pins simultaneously, use Gpio::poll_interrupts to block while waiting for any of the interrupts to trigger, or switch to using asynchronous interrupts with set_async_interrupt.

Setting reset to false returns any cached interrupt trigger events if available. Setting reset to true clears all cached events before polling for new events.

The timeout duration indicates how long the call will block while waiting for interrupt trigger events, after which an Ok(None)) is returned. timeout can be set to None to wait indefinitely.

source

pub fn set_async_interrupt<C>( &mut self, trigger: Trigger, callback: C ) -> Result<()>where C: FnMut(Level) + Send + 'static,

Configures an asynchronous interrupt trigger, which executes the callback on a separate thread when the interrupt is triggered.

The callback closure or function pointer is called with a single Level argument.

Any previously configured (a)synchronous interrupt triggers for this pin are cleared when set_async_interrupt is called, or when InputPin goes out of scope.

source

pub fn clear_async_interrupt(&mut self) -> Result<()>

Removes a previously configured asynchronous interrupt trigger.

source

pub fn reset_on_drop(&self) -> bool

Returns the value of reset_on_drop.

source

pub fn set_reset_on_drop(&mut self, reset_on_drop: bool)

When enabled, resets the pin’s mode to its original state and disables the built-in pull-up/pull-down resistors when the pin goes out of scope. By default, this is set to true.

Note

Drop methods aren’t called when a process is abnormally terminated, for instance when a user presses Ctrl + C, and the SIGINT signal isn’t caught. You can catch those using crates such as simple_signal.

Trait Implementations§

source§

impl Debug for InputPin

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for InputPin

source§

fn drop(&mut self)

Resets the pin’s mode and disables the built-in pull-up/pull-down resistors if reset_on_drop is set to true (default).

source§

impl ErrorType for InputPin

§

type Error = Infallible

Error type
source§

impl InputPin for InputPin

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 InputPin for InputPin

§

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<'a> PartialEq<&'a InputPin> for InputPin

source§

fn eq(&self, other: &&'a InputPin) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a> PartialEq<InputPin> for &'a InputPin

source§

fn eq(&self, other: &InputPin) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for InputPin

source§

fn eq(&self, other: &InputPin) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for InputPin

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.