From 03e6a9036ff4cb19c1ca82d2fb04f7abd22e3a44 Mon Sep 17 00:00:00 2001 From: Philipp_EndevourOS Date: Mon, 27 Oct 2025 15:04:21 +0100 Subject: [PATCH] implemented LED for new lib !esp-hhal-smartled is not released! --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/feedback.rs | 20 +++++++++++++++----- src/init/hardware.rs | 10 +++++++++- src/main.rs | 4 ++-- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e55fb72..5ce060b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -814,7 +814,7 @@ dependencies = [ [[package]] name = "esp-hal-smartled" version = "0.17.0" -source = "git+https://github.com/esp-rs/esp-hal-community.git?branch=main#ab4316534d90e3a12785907f043f6899faee0f20" +source = "git+https://github.com/esp-rs/esp-hal-community.git?rev=ab4316534d90e3a12785907f043f6899faee0f20#ab4316534d90e3a12785907f043f6899faee0f20" dependencies = [ "document-features", "esp-hal", diff --git a/Cargo.toml b/Cargo.toml index fe87538..8538482 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,7 @@ serde = { version = "1.0.219", default-features = false, features = ["derive", " serde_json = { version = "1.0.143", default-features = false, features = ["alloc"]} ds3231 = { version = "0.3.0", features = ["async", "temperature_f32"] } -esp-hal-smartled = { git = "https://github.com/esp-rs/esp-hal-community.git", package = "esp-hal-smartled", branch = "main", features = ["esp32c6"]} +esp-hal-smartled = { git = "https://github.com/esp-rs/esp-hal-community.git", rev = "ab4316534d90e3a12785907f043f6899faee0f20", package = "esp-hal-smartled", features = ["esp32c6"]} smart-leds = "0.4.0" embedded-sdmmc = "0.8.0" diff --git a/src/feedback.rs b/src/feedback.rs index cb476ae..78e8ea4 100644 --- a/src/feedback.rs +++ b/src/feedback.rs @@ -1,6 +1,9 @@ use embassy_time::{Duration, Timer}; -use esp_hal::peripherals; -use esp_hal_smartled::SmartLedsAdapterAsync; +use esp_hal::peripherals::RMT; +use esp_hal::rmt::Rmt; +use esp_hal::time::Rate; +use esp_hal::{peripherals, rmt}; +use esp_hal_smartled::{SmartLedsAdapterAsync, buffer_size_async}; use log::debug; use smart_leds::SmartLedsWriteAsync; use smart_leds::colors::{BLACK, GREEN, RED, YELLOW}; @@ -25,11 +28,18 @@ const LED_LEVEL: u8 = 255; #[embassy_executor::task] pub async fn feedback_task( - mut led: SmartLedsAdapterAsync<'static, { hardware::LED_BUFFER_SIZE }>, - buzzer: peripherals::GPIO21<'static>, + rmt: Rmt<'static, esp_hal::Async>, + led_gpio: peripherals::GPIO1<'static>, + buzzer_gpio: peripherals::GPIO21<'static>, ) { debug!("Starting feedback task"); - let mut buzzer = init::hardware::setup_buzzer(buzzer); + + let rmt_channel = rmt.channel0; + let rmt_buffer = [esp_hal::rmt::PulseCode::default(); buffer_size_async(hardware::NUM_LEDS)]; + + let mut led = SmartLedsAdapterAsync::new(rmt_channel, led_gpio, rmt_buffer); + + let mut buzzer = init::hardware::setup_buzzer(buzzer_gpio); loop { let feedback_state = FEEDBACK_STATE.wait().await; match feedback_state { diff --git a/src/init/hardware.rs b/src/init/hardware.rs index 3b57d85..0b3ffd3 100644 --- a/src/init/hardware.rs +++ b/src/init/hardware.rs @@ -50,7 +50,6 @@ use crate::init::wifi; *************************************************/ pub const NUM_LEDS: usize = 1; -pub const LED_BUFFER_SIZE: usize = buffer_size_async(NUM_LEDS); static SD_DET: Mutex>> = Mutex::new(RefCell::new(None)); @@ -70,6 +69,8 @@ pub async fn hardware_init( Uart<'static, Async>, Stack<'static>, I2c<'static, Async>, + Rmt<'static, esp_hal::Async>, + GPIO1<'static>, GPIO21<'static>, GPIO0<'static>, SmartLedsAdapterAsync<'static, LED_BUFFER_SIZE>, @@ -102,6 +103,10 @@ pub async fn hardware_init( let sd_det_gpio = peripherals.GPIO0; + let rmt: Rmt<'_, esp_hal::Async> = {let frequency: Rate = Rate::from_mhz(80); + Rmt::new(peripherals.RMT, frequency)} .expect("Failed to initialize RMT") + .into_async(); + let spi_bus = setup_spi( peripherals.SPI2, peripherals.GPIO19, @@ -117,6 +122,7 @@ pub async fn hardware_init( let vol_mgr = setup_sdcard(spi_bus, sd_cs_pin); + let led_gpio = peripherals.GPIO1; let buzzer_gpio = peripherals.GPIO21; let led = setup_led(peripherals.RMT, peripherals.GPIO1); @@ -129,6 +135,8 @@ pub async fn hardware_init( uart_device, stack, i2c_device, + rmt, + led_gpio, buzzer_gpio, sd_det_gpio, led, diff --git a/src/main.rs b/src/main.rs index 78b35a7..8dbf5dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ static CHAN: StaticCell = StaticCell::new(); #[esp_rtos::main] async fn main(spawner: Spawner) -> ! { - let (uart_device, stack, i2c, buzzer_gpio, sd_det_gpio, led, persistence_layer) = + let (uart_device, stack, i2c, rmt, led_gpio, buzzer_gpio, sd_det_gpio, persistence_layer) = init::hardware::hardware_init(spawner).await; info!("Starting up..."); @@ -73,7 +73,7 @@ async fn main(spawner: Spawner) -> ! { )); debug!("spawing feedback task.."); - spawner.must_spawn(feedback::feedback_task(led, buzzer_gpio)); + spawner.must_spawn(feedback::feedback_task(rmt, led_gpio, buzzer_gpio)); debug!("spawn sd detect task"); spawner.must_spawn(sd_detect_task(sd_det_gpio));