[][src]Struct embedded_hal_sync_pins::pins::OpenDrainPin

pub struct OpenDrainPin { /* fields omitted */ }

A mutable output pin in open drain configuration that can be safely shared between threads.

This pin implements embedded_hal::OutputPin and can be used to share an AtomicPinState with an embedded_hal implementation. In open drain configuration this pin is in a floating state (not connected) if it is set to low and logical low ("pull to GND") if it is set to high.

It also implements embedded_hal::InputPin, so it is possible to also read the internal state, which will be either Floating or Low.

Examples

use embedded_hal_sync_pins::pins::{AtomicPinState, OpenDrainPin, PinState};
use embedded_hal::digital::{InputPin as HalInputPin, OutputPin};
use std::sync::{Arc, atomic::Ordering};

let state = Arc::new(AtomicPinState::new());
let mut pin = OpenDrainPin::new(state.clone());
pin.try_set_low().unwrap();
assert_eq!(Ok(false), pin.try_is_low());
assert_eq!(Ok(false), pin.try_is_high());
assert_eq!(PinState::Floating, state.load(Ordering::SeqCst));
pin.try_set_high().unwrap();
assert_eq!(Ok(false), pin.try_is_high());
assert_eq!(Ok(true), pin.try_is_low());

Implementations

impl OpenDrainPin[src]

pub fn new(state: Arc<AtomicPinState>) -> Self[src]

Trait Implementations

impl Clone for OpenDrainPin[src]

impl Debug for OpenDrainPin[src]

impl InputPin for OpenDrainPin[src]

type Error = Infallible

Error type

impl OutputPin for OpenDrainPin[src]

type Error = Infallible

Error type

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.