Struct embedded_hal_vcd::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>) -> OpenDrainPin
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
source§impl InputPin for OpenDrainPin
impl InputPin for OpenDrainPin
source§impl OutputPin for OpenDrainPin
impl OutputPin for OpenDrainPin
source§impl StatefulOutputPin for OpenDrainPin
impl StatefulOutputPin for OpenDrainPin
source§fn is_set_high(&self) -> Result<bool, <OpenDrainPin as ErrorType>::Error>
fn is_set_high(&self) -> Result<bool, <OpenDrainPin as ErrorType>::Error>
Is the pin in drive high mode? Read more
source§fn is_set_low(&self) -> Result<bool, <OpenDrainPin as ErrorType>::Error>
fn is_set_low(&self) -> Result<bool, <OpenDrainPin as ErrorType>::Error>
Is the pin in drive low mode? Read more