Struct switch_hal::Switch
source · pub struct Switch<IoPin, ActiveLevel> { /* private fields */ }
Expand description
Concrete implementation for InputSwitch and OutputSwitch
Type Params
IoPin
must be a type that implements either of the InputPin or OutputPin traits.ActiveLevel
indicates whether theSwitch
is ActiveHigh or ActiveLow.ActiveLevel
is not actually stored in the struct. It’s PhantomData used to indicate which implementation to use.
Implementations§
source§impl<IoPin, ActiveLevel> Switch<IoPin, ActiveLevel>
impl<IoPin, ActiveLevel> Switch<IoPin, ActiveLevel>
sourcepub fn new(pin: IoPin) -> Self
pub fn new(pin: IoPin) -> Self
Constructs a new Switch from a concrete implementation of an InputPin or OutputPin
Prefer the IntoSwitch trait over calling new directly.
Examples
Active High
use switch_hal::{ActiveHigh, OutputSwitch, Switch};
let mut led = Switch::<_, ActiveHigh>::new(pin);
ActiveLow
use switch_hal::{ActiveLow, OutputSwitch, Switch};
let mut led = Switch::<_, ActiveLow>::new(pin);
stm32f3xx-hal
ⓘ
// Example for the stm32f303
use stm32f3xx_hal::gpio::gpioe;
use stm32f3xx_hal::gpio::{PushPull, Output};
use stm32f3xx_hal::stm32;
use switch_hal::{ActiveHigh, Switch};
let device_periphs = stm32::Peripherals::take().unwrap();
let gpioe = device_periphs.GPIOE.split(&mut reset_control_clock.ahb);
let led = Switch::<_, ActiveHigh>::new(
gpioe
.pe9
.into_push_pull_output(&mut gpioe.moder, &mut gpioe.otyper)
)
sourcepub fn into_pin(self) -> IoPin
pub fn into_pin(self) -> IoPin
Consumes the Switch and returns the underlying InputPin or OutputPin.
This is useful fore retrieving the underlying pin to use it for a different purpose.
Examples
use switch_hal::{OutputSwitch, Switch, IntoSwitch};
let mut led = pin.into_active_high_switch();
led.on().ok();
let mut pin = led.into_pin();
// do something else with the pin
Trait Implementations§
source§impl<T: InputPin> InputSwitch for Switch<T, ActiveHigh>
impl<T: InputPin> InputSwitch for Switch<T, ActiveHigh>
source§impl<T: OutputPin> OutputSwitch for Switch<T, ActiveHigh>
impl<T: OutputPin> OutputSwitch for Switch<T, ActiveHigh>
source§impl<T: OutputPin + StatefulOutputPin> StatefulOutputSwitch for Switch<T, ActiveHigh>
impl<T: OutputPin + StatefulOutputPin> StatefulOutputSwitch for Switch<T, ActiveHigh>
source§impl<T: OutputPin + StatefulOutputPin> StatefulOutputSwitch for Switch<T, ActiveLow>
impl<T: OutputPin + StatefulOutputPin> StatefulOutputSwitch for Switch<T, ActiveLow>
source§impl<T: OutputPin + ToggleableOutputPin, ActiveLevel> ToggleableOutputSwitch for Switch<T, ActiveLevel>
impl<T: OutputPin + ToggleableOutputPin, ActiveLevel> ToggleableOutputSwitch for Switch<T, ActiveLevel>
Auto Trait Implementations§
impl<IoPin, ActiveLevel> RefUnwindSafe for Switch<IoPin, ActiveLevel>where ActiveLevel: RefUnwindSafe, IoPin: RefUnwindSafe,
impl<IoPin, ActiveLevel> Send for Switch<IoPin, ActiveLevel>where ActiveLevel: Send, IoPin: Send,
impl<IoPin, ActiveLevel> Sync for Switch<IoPin, ActiveLevel>where ActiveLevel: Sync, IoPin: Sync,
impl<IoPin, ActiveLevel> Unpin for Switch<IoPin, ActiveLevel>where ActiveLevel: Unpin, IoPin: Unpin,
impl<IoPin, ActiveLevel> UnwindSafe for Switch<IoPin, ActiveLevel>where ActiveLevel: UnwindSafe, IoPin: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more