pub struct Led<P, POL = ActiveHigh> { /* private fields */ }Expand description
Monochrome LED with compile-time polarity.
Type parameters:
P: pin type implementingOutputPinandStatefulOutputPin.POL: polarity marker,ActiveHighorActiveLow(defaultActiveHigh).
No internal state cache — is_on() reads the hardware register (ODR) directly
and applies the polarity conversion. In the embassy ecosystem OutputPin::Error
is Infallible, so unwrapping results is safe.
§Examples
ⓘ
use status_led::{Led, ActiveLow};
let mut led = Led::<_, ActiveLow>::new(pin).unwrap();
led.on().unwrap();
led.toggle().unwrap();
assert!(led.is_on().unwrap());Implementations§
Source§impl<P: OutputPin, POL: Polarity> Led<P, POL>
impl<P: OutputPin, POL: Polarity> Led<P, POL>
Sourcepub fn new(pin: P) -> Result<Self, P::Error>
pub fn new(pin: P) -> Result<Self, P::Error>
Build and force the pin to the logical OFF state.
Safest default — guarantees the LED starts dark regardless of the pin’s reset state.
Sourcepub fn on(&mut self) -> Result<(), P::Error>
pub fn on(&mut self) -> Result<(), P::Error>
Turn the LED on (logical ON → physical level determined by polarity).
Source§impl<P: StatefulOutputPin, POL: Polarity> Led<P, POL>
impl<P: StatefulOutputPin, POL: Polarity> Led<P, POL>
Sourcepub fn is_on(&mut self) -> Result<bool, P::Error>
pub fn is_on(&mut self) -> Result<bool, P::Error>
Read the logical state from the hardware register.
Reads the physical pin level (ODR register on STM32), then converts
through the polarity. Requires &mut self because
StatefulOutputPin::is_set_high does — in practice the read is a
single register access with no side effects.
Trait Implementations§
Auto Trait Implementations§
impl<P, POL> Freeze for Led<P, POL>where
P: Freeze,
impl<P, POL> RefUnwindSafe for Led<P, POL>where
P: RefUnwindSafe,
POL: RefUnwindSafe,
impl<P, POL> Send for Led<P, POL>
impl<P, POL> Sync for Led<P, POL>
impl<P, POL> Unpin for Led<P, POL>
impl<P, POL> UnsafeUnpin for Led<P, POL>where
P: UnsafeUnpin,
impl<P, POL> UnwindSafe for Led<P, POL>where
P: UnwindSafe,
POL: 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