pub struct Led4<'a>(/* private fields */);Available on
target_os=none only.Expand description
A device abstraction for a 4-digit, 7-segment LED display with blinking support.
§Hardware Requirements
This abstraction is designed for common-cathode 7-segment displays where:
- Cell pins control which digit is active (LOW = on, HIGH = off)
- Segment pins control which segments light up (HIGH = on, LOW = off)
§Example
use device_envoy::{Error, led4::{BlinkState, Led4, Led4Static, OutputArray}};
async fn example(p: embassy_rp::Peripherals, spawner: embassy_executor::Spawner) -> Result<(), Error> {
// Set up cell pins (control which digit is active)
let cells = OutputArray::new([
embassy_rp::gpio::Output::new(p.PIN_1, embassy_rp::gpio::Level::High),
embassy_rp::gpio::Output::new(p.PIN_2, embassy_rp::gpio::Level::High),
embassy_rp::gpio::Output::new(p.PIN_3, embassy_rp::gpio::Level::High),
embassy_rp::gpio::Output::new(p.PIN_4, embassy_rp::gpio::Level::High),
]);
// Set up segment pins (control which segments light up)
let segments = OutputArray::new([
embassy_rp::gpio::Output::new(p.PIN_5, embassy_rp::gpio::Level::Low), // Segment A
embassy_rp::gpio::Output::new(p.PIN_6, embassy_rp::gpio::Level::Low), // Segment B
embassy_rp::gpio::Output::new(p.PIN_7, embassy_rp::gpio::Level::Low), // Segment C
embassy_rp::gpio::Output::new(p.PIN_8, embassy_rp::gpio::Level::Low), // Segment D
embassy_rp::gpio::Output::new(p.PIN_9, embassy_rp::gpio::Level::Low), // Segment E
embassy_rp::gpio::Output::new(p.PIN_10, embassy_rp::gpio::Level::Low), // Segment F
embassy_rp::gpio::Output::new(p.PIN_11, embassy_rp::gpio::Level::Low), // Segment G
embassy_rp::gpio::Output::new(p.PIN_12, embassy_rp::gpio::Level::Low), // Decimal point
]);
// Create the display
static LED4_STATIC: Led4Static = Led4::new_static();
let display = Led4::new(&LED4_STATIC, cells, segments, spawner)?;
// Display "1234" (solid)
display.write_text(['1', '2', '3', '4'], BlinkState::Solid);
// Display "rUSt" blinking
display.write_text(['r', 'U', 'S', 't'], BlinkState::BlinkingAndOn);
Ok(())
}Beyond simple text, the driver can loop animations via Led4::animate_text.
The struct owns the background task and signal wiring; create it once with
Led4::new and use the returned handle for all display updates.
Implementations§
Source§impl Led4<'_>
impl Led4<'_>
Sourcepub fn new(
led4_static: &'static Led4Static,
cell_pins: OutputArray<'static, CELL_COUNT>,
segment_pins: OutputArray<'static, SEGMENT_COUNT>,
spawner: Spawner,
) -> Result<Self>
pub fn new( led4_static: &'static Led4Static, cell_pins: OutputArray<'static, CELL_COUNT>, segment_pins: OutputArray<'static, SEGMENT_COUNT>, spawner: Spawner, ) -> Result<Self>
Creates the display device and spawns its background task; see Led4 docs.
Sourcepub const fn new_static() -> Led4Static
pub const fn new_static() -> Led4Static
Sourcepub fn write_text(&self, text: [char; 4], blink_state: BlinkState)
pub fn write_text(&self, text: [char; 4], blink_state: BlinkState)
Sends text to the display with optional blinking.
See the main Led4 example for end-to-end usage.
Sourcepub fn animate_text<I>(&self, animation: I)
pub fn animate_text<I>(&self, animation: I)
Plays a looped text animation using the provided frames.
§Example
use device_envoy::{Result, led4::{AnimationFrame, Led4, Led4Static, OutputArray}};
use embassy_time::Duration;
async fn demo(p: embassy_rp::Peripherals, spawner: Spawner) -> Result<()> {
let cells = OutputArray::new([
Output::new(p.PIN_1, Level::High),
Output::new(p.PIN_2, Level::High),
Output::new(p.PIN_3, Level::High),
Output::new(p.PIN_4, Level::High),
]);
let segments = OutputArray::new([
Output::new(p.PIN_5, Level::Low),
Output::new(p.PIN_6, Level::Low),
Output::new(p.PIN_7, Level::Low),
Output::new(p.PIN_8, Level::Low),
Output::new(p.PIN_9, Level::Low),
Output::new(p.PIN_10, Level::Low),
Output::new(p.PIN_11, Level::Low),
Output::new(p.PIN_12, Level::Low),
]);
static LED4_STATIC: Led4Static = Led4::new_static();
let display = Led4::new(&LED4_STATIC, cells, segments, spawner)?;
const FRAME_DURATION: Duration = Duration::from_millis(120);
let animation = [
AnimationFrame::new(['-', '-', '-', '-'], FRAME_DURATION),
AnimationFrame::new([' ', ' ', ' ', ' '], FRAME_DURATION),
AnimationFrame::new(['1', '2', '3', '4'], FRAME_DURATION),
];
display.animate_text(animation);
Ok(())
}See the example below for how to build animations.
Auto Trait Implementations§
impl<'a> Freeze for Led4<'a>
impl<'a> !RefUnwindSafe for Led4<'a>
impl<'a> Send for Led4<'a>
impl<'a> Sync for Led4<'a>
impl<'a> Unpin for Led4<'a>
impl<'a> !UnwindSafe for Led4<'a>
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Performs the conversion.
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Performs the conversion.
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Casts the value.
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
Source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
Casts the value.
Source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
Source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
Source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
Source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
Casts the value.
Source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
Source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.