Struct embedded_hal_sync_pins::pins::OpenDrainPin
source · pub struct OpenDrainPin { /* private fields */ }Expand description
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.set_low().unwrap();
assert_eq!(Ok(false), pin.is_low());
assert_eq!(Ok(false), pin.is_high());
assert_eq!(PinState::Floating, state.load(Ordering::SeqCst));
pin.set_high().unwrap();
assert_eq!(Ok(false), pin.is_high());
assert_eq!(Ok(true), pin.is_low());Implementations§
source§impl OpenDrainPin
impl OpenDrainPin
pub fn new(state: Arc<AtomicPinState>) -> Self
Trait Implementations§
source§impl Clone for OpenDrainPin
impl Clone for OpenDrainPin
source§fn clone(&self) -> OpenDrainPin
fn clone(&self) -> OpenDrainPin
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for OpenDrainPin
impl Debug for OpenDrainPin
source§impl ErrorType for OpenDrainPin
impl ErrorType for OpenDrainPin
§type Error = Infallible
type Error = Infallible
Error type