#![allow(missing_docs)]
#![no_std]
#![no_main]
#![allow(clippy::future_not_send, reason = "single-threaded")]

use defmt::info;
use defmt_rtt as _;
use device_envoy::Result;
use device_envoy::led_strip::Current;
use device_envoy::led_strip::Gamma;
use device_envoy::led2d::Led2dFont;
use device_envoy::led2d::layout::LedLayout;
use device_envoy::led2d::led2d;
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
use panic_probe as _;
use smart_leds::colors;

// Build a 24x4 display by concatenating two 12x4 serpentine panels horizontally.
const LED_LAYOUT_12X4: LedLayout<48, 12, 4> = LedLayout::serpentine_column_major();
const LED_LAYOUT_24X4: LedLayout<96, 24, 4> = LED_LAYOUT_12X4.combine_h(LED_LAYOUT_12X4);

led2d! {
    Led24x4Concat {
        pio: PIO1,
        pin: PIN_4,
        dma: DMA_CH1,
        led_layout: LED_LAYOUT_24X4,
        max_current: Current::Milliamps(1000),
        gamma: Gamma::SmartLeds,
        max_frames: 8,
        font: Led2dFont::Font3x4Trim,
    }
}

#[embassy_executor::main]
pub async fn main(spawner: Spawner) -> ! {
    let err = inner_main(spawner).await.unwrap_err();
    core::panic!("{err}");
}

async fn inner_main(spawner: Spawner) -> Result<()> {
    info!("Starting 24x4 concat-h demo");
    let p = embassy_rp::init(Default::default());

    let led24x4_concat = Led24x4Concat::new(p.PIN_4, p.PIO1, p.DMA_CH1, spawner)?;

    led24x4_concat
        .write_text("HELLO MOM", &[colors::CYAN, colors::WHITE])
        .await?;

    loop {
        Timer::after(Duration::from_millis(3600)).await;
    }
}
