pub struct Led<P> { /* private fields */ }Expand description
Monochrome LED with polarity chosen at construction time.
Stores a PolarityMode value — each operation incurs one match which
is negligible on Cortex-M.
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, PolarityMode};
let mut led = Led::new(pin, PolarityMode::ActiveLow).unwrap();
led.on().unwrap();
led.toggle().unwrap();
assert!(led.is_on().unwrap());Implementations§
Source§impl<P> Led<P>
impl<P> Led<P>
Sourcepub fn from_pin(pin: P, polarity: PolarityMode) -> Self
pub fn from_pin(pin: P, polarity: PolarityMode) -> Self
Build from an already-configured pin without changing its level.
Prefer this when the HAL already set the pin to a known state
(e.g. Output::new(pin, Level::High, Speed::Low) for an active-low LED).
Source§impl<P: OutputPin> Led<P>
impl<P: OutputPin> Led<P>
Sourcepub fn new(pin: P, polarity: PolarityMode) -> Result<Self, P::Error>
pub fn new(pin: P, polarity: PolarityMode) -> 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> Led<P>
impl<P: StatefulOutputPin> Led<P>
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.