[−][src]Struct switch_hal::Switch
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.
Methods
impl<IoPin, ActiveLevel> Switch<IoPin, ActiveLevel>
[src]
pub fn new(pin: IoPin) -> Self
[src]
Constructs a new Switch from a concrete implementation of an InputPin or OutputPin
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
ⓘThis example is not tested
// 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) )
pub fn into_pin(self) -> IoPin
[src]
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::{ActiveHigh, OutputSwitch, Switch}; let mut led = Switch::<_, ActiveHigh>::new(pin); led.on().ok(); let mut pin = led.into_pin(); // do something else with the pin
Trait Implementations
impl<T: InputPin> InputSwitch for Switch<T, ActiveHigh>
[src]
impl<T: InputPin> InputSwitch for Switch<T, ActiveLow>
[src]
impl<T: OutputPin> OutputSwitch for Switch<T, ActiveHigh>
[src]
type Error = <T as OutputPin>::Error
fn on(&mut self) -> Result<(), Self::Error>
[src]
fn off(&mut self) -> Result<(), Self::Error>
[src]
impl<T: OutputPin> OutputSwitch for Switch<T, ActiveLow>
[src]
type Error = <T as OutputPin>::Error
fn on(&mut self) -> Result<(), Self::Error>
[src]
fn off(&mut self) -> Result<(), Self::Error>
[src]
impl<T: OutputPin + ToggleableOutputPin, ActiveLevel> ToggleableOutputSwitch for Switch<T, ActiveLevel>
[src]
Auto Trait Implementations
impl<IoPin, ActiveLevel> Send for Switch<IoPin, ActiveLevel> where
ActiveLevel: Send,
IoPin: Send,
ActiveLevel: Send,
IoPin: Send,
impl<IoPin, ActiveLevel> Sync for Switch<IoPin, ActiveLevel> where
ActiveLevel: Sync,
IoPin: Sync,
ActiveLevel: Sync,
IoPin: Sync,
impl<IoPin, ActiveLevel> Unpin for Switch<IoPin, ActiveLevel> where
ActiveLevel: Unpin,
IoPin: Unpin,
ActiveLevel: Unpin,
IoPin: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,