diff --git a/src/bin/main.rs b/src/bin/main.rs index 6d0933a..d243908 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -9,7 +9,7 @@ use defmt::info; use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; +use embassy_time::Timer; use esp_hal::clock::CpuClock; use esp_hal::spi::master::{Spi, Config as SpiConfig}; use esp_hal::time::Rate; @@ -27,6 +27,8 @@ extern crate alloc; // For more information see: esp_bootloader_esp_idf::esp_app_desc!(); +const LED_SPI_HZ: u32 = 3_200_000; + #[allow( clippy::large_stack_frames, reason = "it's not unusual to allocate larger buffers etc. in main" @@ -45,22 +47,34 @@ async fn main(spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_rtos::start(timg0.timer0); - // TODO: Spawn some tasks - let _ = spawner; - - const LED_SPI_HZ: u32 = 3_200_000; let spi = Spi::new(peripherals.SPI2, SpiConfig::default().with_frequency(Rate::from_hz(LED_SPI_HZ))) .unwrap() .with_mosi(peripherals.GPIO48); - let mut led = WS2812SPI::new(spi); + let led = WS2812SPI::new(spi); + spawner.spawn(heartbeat_task(led)).unwrap(); info!("Padmapper initialized!"); + // Idle forever loop { - led.color_send_by_spi(Color([0, 0, 8]), LED_SPI_HZ).unwrap(); - Timer::after(Duration::from_secs(1)).await; - led.color_send_by_spi(Color([8, 0, 8]), LED_SPI_HZ).unwrap(); - Timer::after(Duration::from_secs(1)).await; + Timer::after_secs(6 * 60 * 60).await; + } +} + +#[embassy_executor::task] +async fn heartbeat_task(mut led: WS2812SPI>) { + let on_color = Color([8, 0, 0]); + let off_color = Color([0, 0, 0]); + + loop { + led.color_send_by_spi(on_color, LED_SPI_HZ).unwrap(); + Timer::after_millis(100).await; + led.color_send_by_spi(off_color, LED_SPI_HZ).unwrap(); + Timer::after_millis(100).await; + led.color_send_by_spi(on_color, LED_SPI_HZ).unwrap(); + Timer::after_millis(100).await; + led.color_send_by_spi(off_color, LED_SPI_HZ).unwrap(); + Timer::after_millis(700).await; } }