Skip to main content

FlexLed

Struct FlexLed 

Source
pub struct FlexLed<P> { /* private fields */ }
Expand description

LED with runtime-determined polarity.

Unlike Led which bakes polarity into the type, FlexLed stores it as a PolarityMode value. Useful when the polarity is read from configuration at runtime rather than known at compile time. Each operation incurs one extra match vs Led — negligible on Cortex-M.

§Examples

use status_led::{FlexLed, PolarityMode};

let pol = if config.active_low {
    PolarityMode::ActiveLow
} else {
    PolarityMode::ActiveHigh
};
let mut led = FlexLed::new(pin, pol).unwrap();
led.on().unwrap();

Implementations§

Source§

impl<P> FlexLed<P>

Source

pub fn from_pin(pin: P, polarity: PolarityMode) -> Self

Build from an already-configured pin without changing its level.

Source§

impl<P: OutputPin> FlexLed<P>

Source

pub fn new(pin: P, polarity: PolarityMode) -> Result<Self, P::Error>

Build and force the pin to the logical OFF state.

Source

pub fn on(&mut self) -> Result<(), P::Error>

Turn the LED on.

Source

pub fn off(&mut self) -> Result<(), P::Error>

Turn the LED off.

Source

pub fn set(&mut self, state: bool) -> Result<(), P::Error>

Set the logical state: true = ON, false = OFF.

Source§

impl<P: StatefulOutputPin> FlexLed<P>

Source

pub fn is_on(&mut self) -> Result<bool, P::Error>

Read the logical state from the hardware register.

Source

pub fn is_off(&mut self) -> Result<bool, P::Error>

Inverse of is_on.

Source

pub fn toggle(&mut self) -> Result<(), P::Error>

Toggle the logical state.

Source§

impl<P> FlexLed<P>

Source

pub fn polarity(&self) -> PolarityMode

Return the current polarity.

Source

pub fn release(self) -> P

Consume the FlexLed and return the underlying pin.

Trait Implementations§

Source§

impl<P, POL: Polarity> From<Led<P, POL>> for FlexLed<P>

Source§

fn from(led: Led<P, POL>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<P> Freeze for FlexLed<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for FlexLed<P>
where P: RefUnwindSafe,

§

impl<P> Send for FlexLed<P>
where P: Send,

§

impl<P> Sync for FlexLed<P>
where P: Sync,

§

impl<P> Unpin for FlexLed<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for FlexLed<P>
where P: UnsafeUnpin,

§

impl<P> UnwindSafe for FlexLed<P>
where P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.