diff --git a/Cargo.lock b/Cargo.lock index bc7404e..1c516b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,6 +1092,7 @@ dependencies = [ "esp-rtos", "rtt-target", "static_cell", + "ws2812-rs", ] [[package]] @@ -1570,6 +1571,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "ws2812-rs" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31238e916943f43bc2cc4572e121688091483c89b31eec5e861f54853d60a4d" +dependencies = [ + "embassy-time", + "embedded-hal 1.0.0", +] + [[package]] name = "xtensa-lx" version = "0.13.0" diff --git a/Cargo.toml b/Cargo.toml index 7822c5b..6ac5d41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ rtt-target = { version = "0.6.2", features = ["defmt"] } critical-section = "1.2.0" static_cell = "2.1.1" +ws2812-rs = "0.3.1" [profile.dev] diff --git a/src/bin/main.rs b/src/bin/main.rs index f39dc19..6d0933a 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -11,7 +11,10 @@ use defmt::info; use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use esp_hal::clock::CpuClock; +use esp_hal::spi::master::{Spi, Config as SpiConfig}; +use esp_hal::time::Rate; use esp_hal::timer::timg::TimerGroup; +use ws2812_rs::{WS2812SPI, SendColorBySPI, Color}; #[panic_handler] fn panic(_: &core::panic::PanicInfo) -> ! { @@ -42,15 +45,22 @@ async fn main(spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_rtos::start(timg0.timer0); - info!("Embassy initialized!"); - // 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); + + info!("Padmapper initialized!"); + loop { - info!("Hello world!"); + 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; } - - // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0/examples }