status-led
no_std monochrome status LED abstraction for the embassy ecosystem.
- Polarity —
ActiveHigh/ActiveLowchosen at construction time via [PolarityMode]. - Reads hardware directly — no internal state cache;
is_on()reads the ODR register and applies polarity conversion. - Optional PWM — CIE L* perceptual brightness via
PwmLedwith a compact 32-byte lookup table + shift-add interpolation (zero multiply/divide). Supports 8-bit (0–255) and 12-bit (0–4095, viaarbitrary_int::u12) brightness resolution. - Optional breathing — Sinusoidal brightness animation via
Breath(CORDIC algorithm — zero float/mul/large tables) andBreathLedwrapper, also respecting the selected brightness bit-depth. - Zero mandatory dependencies — only
embedded-hal1.0.
Usage
use ;
use ;
let pin = new;
let mut led = from_pin;
led.on.unwrap;
led.off.unwrap;
PWM with gamma correction
Enable the pwm feature:
= { = "0.7", = ["pwm"] }
use ;
use PolarityMode;
let mut led = new.unwrap;
led.set_brightness.unwrap; // ~50% perceived brightness
Breathing effect
Enable the breath feature:
= { = "0.7", = ["breath"] }
Breath generates a stream of brightness values following a
sinusoidal pattern — 0–255 by default, or 0–4095 with the
brightness-12bit feature. Combine with BreathLed for a ready-to-use
PWM LED wrapper:
use ;
use GammaCorrection;
use PolarityMode;
// Manual breath loop with Breath
let mut breath = new;
loop
// Or use BreathLed for a single-call wrapper
let mut led = new.unwrap;
loop
breathe() combines the brightness update with the sleep — no separate
Timer call needed.
12-bit brightness
Enable the brightness-12bit feature for finer brightness control:
= { = "0.7", = ["breath", "brightness-12bit"] }
This switches the brightness type from u8 (0–255) to
arbitrary_int::u12 (0–4095), giving
16× finer resolution. The CIE L* gamma tables (still only 32 bytes)
are reused with two-level interpolation — no extra flash cost.
use ;
use PolarityMode;
let mut led = new.unwrap;
led.set_brightness.unwrap; // ~50% perceived brightness
The u12 type guarantees values are always in the 0–4095 range at
compile time — out-of-range values panic immediately.
Runtime polarity
When the polarity is read from configuration at runtime:
use ;
let pol = if config.active_low else ;
let mut led = new.unwrap;
led.toggle.unwrap;
Features
| Feature | Description | Extra deps |
|---|---|---|
| (none) | GPIO LED with runtime polarity | — |
pwm |
PwmLed with CIE L* perceptual brightness, zero runtime multiply/divide |
— |
breath |
Breath + BreathLed — CORDIC sinusoidal breathing with async breathe() |
— (enables pwm, embassy-time) |
brightness-12bit |
Switches brightness type from u8 to arbitrary_int::u12 (0–4095) |
arbitrary-int |
defmt |
defmt::Format impls for all public types |
defmt |
License
Licensed under either of Apache License 2.0 or MIT license at your option.