Struct switch_hal::Switch[][src]

pub struct Switch<IoPin, ActiveLevel> { /* fields omitted */ }
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 the Switch is ActiveHigh or ActiveLow. ActiveLevel is not actually stored in the struct. It’s PhantomData used to indicate which implementation to use.

Implementations

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)
)

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

Returns true if the swich has been activated, otherwise false i.e. if a button is currently pressed, returns true Read more

Returns true if the swich has been activated, otherwise false i.e. if a button is currently pressed, returns true Read more

Turns the switch on Read more

Turns the switch off Read more

Turns the switch on Read more

Turns the switch off Read more

Checks whether the switch is on Read more

Checks whether the switch is off Read more

Checks whether the switch is on Read more

Checks whether the switch is off Read more

Toggles the current state of the OutputSwitch Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Consumes the IoPin returning a Switch of the appropriate ActiveLevel. Read more

Consumes the IoPin returning a Switch<IoPin, ActiveLow>. Read more

Consumes the IoPin returning a Switch<IoPin, ActiveHigh>. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.