Skip to main content

Led4

Struct Led4 

Source
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<'_>

Source

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.

Source

pub const fn new_static() -> Led4Static

Creates static channel resources for Led4::new; see Led4 docs.

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

Source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
Source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

Source§

fn lossy_into(self) -> Dst

Performs the conversion.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> StrictAs for T

Source§

fn strict_as<Dst>(self) -> Dst
where T: StrictCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> StrictCastFrom<Src> for Dst
where Src: StrictCast<Dst>,

Source§

fn strict_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.