👎Deprecated since 0.2.2: Deprecated because the methods cannot return errors. Users should use the traits in digital::v2.
Expand description

If you can read and write the output state, a pin is toggleable by software.

This version of the module is now deprecated. Please use the new toggleable module in digital::v2::toggleable.

use embedded_hal::digital::{OutputPin, StatefulOutputPin, ToggleableOutputPin};
use embedded_hal::digital::toggleable;

/// A virtual output pin that exists purely in software
struct MyPin {
    state: bool
}

impl OutputPin for MyPin {
   fn set_low(&mut self) {
       self.state = false;
   }
   fn set_high(&mut self) {
       self.state = true;
   }
}

impl StatefulOutputPin for MyPin {
   fn is_set_low(&self) -> bool {
       !self.state
   }
   fn is_set_high(&self) -> bool {
       self.state
   }
}

/// Opt-in to the software implementation.
impl toggleable::Default for MyPin {}

let mut pin = MyPin { state: false };
pin.toggle();
assert!(pin.is_set_high());
pin.toggle();
assert!(pin.is_set_low());

Traits

DefaultDeprecated
Software-driven toggle() implementation.