implemented LED for new lib !esp-hhal-smartled is not released!

This commit is contained in:
Philipp_EndevourOS 2025-10-27 15:04:21 +01:00
parent a0ed04a560
commit 03e6a9036f
5 changed files with 28 additions and 10 deletions

2
Cargo.lock generated
View File

@ -814,7 +814,7 @@ dependencies = [
[[package]] [[package]]
name = "esp-hal-smartled" name = "esp-hal-smartled"
version = "0.17.0" 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 = [ dependencies = [
"document-features", "document-features",
"esp-hal", "esp-hal",

View File

@ -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"]} serde_json = { version = "1.0.143", default-features = false, features = ["alloc"]}
ds3231 = { version = "0.3.0", features = ["async", "temperature_f32"] } 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" smart-leds = "0.4.0"
embedded-sdmmc = "0.8.0" embedded-sdmmc = "0.8.0"

View File

@ -1,6 +1,9 @@
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
use esp_hal::peripherals; use esp_hal::peripherals::RMT;
use esp_hal_smartled::SmartLedsAdapterAsync; 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 log::debug;
use smart_leds::SmartLedsWriteAsync; use smart_leds::SmartLedsWriteAsync;
use smart_leds::colors::{BLACK, GREEN, RED, YELLOW}; use smart_leds::colors::{BLACK, GREEN, RED, YELLOW};
@ -25,11 +28,18 @@ const LED_LEVEL: u8 = 255;
#[embassy_executor::task] #[embassy_executor::task]
pub async fn feedback_task( pub async fn feedback_task(
mut led: SmartLedsAdapterAsync<'static, { hardware::LED_BUFFER_SIZE }>, rmt: Rmt<'static, esp_hal::Async>,
buzzer: peripherals::GPIO21<'static>, led_gpio: peripherals::GPIO1<'static>,
buzzer_gpio: peripherals::GPIO21<'static>,
) { ) {
debug!("Starting feedback task"); 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 { loop {
let feedback_state = FEEDBACK_STATE.wait().await; let feedback_state = FEEDBACK_STATE.wait().await;
match feedback_state { match feedback_state {

View File

@ -50,7 +50,6 @@ use crate::init::wifi;
*************************************************/ *************************************************/
pub const NUM_LEDS: usize = 1; pub const NUM_LEDS: usize = 1;
pub const LED_BUFFER_SIZE: usize = buffer_size_async(NUM_LEDS);
static SD_DET: Mutex<RefCell<Option<Input>>> = Mutex::new(RefCell::new(None)); static SD_DET: Mutex<RefCell<Option<Input>>> = Mutex::new(RefCell::new(None));
@ -70,6 +69,8 @@ pub async fn hardware_init(
Uart<'static, Async>, Uart<'static, Async>,
Stack<'static>, Stack<'static>,
I2c<'static, Async>, I2c<'static, Async>,
Rmt<'static, esp_hal::Async>,
GPIO1<'static>,
GPIO21<'static>, GPIO21<'static>,
GPIO0<'static>, GPIO0<'static>,
SmartLedsAdapterAsync<'static, LED_BUFFER_SIZE>, SmartLedsAdapterAsync<'static, LED_BUFFER_SIZE>,
@ -102,6 +103,10 @@ pub async fn hardware_init(
let sd_det_gpio = peripherals.GPIO0; 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( let spi_bus = setup_spi(
peripherals.SPI2, peripherals.SPI2,
peripherals.GPIO19, peripherals.GPIO19,
@ -117,6 +122,7 @@ pub async fn hardware_init(
let vol_mgr = setup_sdcard(spi_bus, sd_cs_pin); let vol_mgr = setup_sdcard(spi_bus, sd_cs_pin);
let led_gpio = peripherals.GPIO1;
let buzzer_gpio = peripherals.GPIO21; let buzzer_gpio = peripherals.GPIO21;
let led = setup_led(peripherals.RMT, peripherals.GPIO1); let led = setup_led(peripherals.RMT, peripherals.GPIO1);
@ -129,6 +135,8 @@ pub async fn hardware_init(
uart_device, uart_device,
stack, stack,
i2c_device, i2c_device,
rmt,
led_gpio,
buzzer_gpio, buzzer_gpio,
sd_det_gpio, sd_det_gpio,
led, led,

View File

@ -47,7 +47,7 @@ static CHAN: StaticCell<TallyChannel> = StaticCell::new();
#[esp_rtos::main] #[esp_rtos::main]
async fn main(spawner: Spawner) -> ! { 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; init::hardware::hardware_init(spawner).await;
info!("Starting up..."); info!("Starting up...");
@ -73,7 +73,7 @@ async fn main(spawner: Spawner) -> ! {
)); ));
debug!("spawing feedback task.."); 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"); debug!("spawn sd detect task");
spawner.must_spawn(sd_detect_task(sd_det_gpio)); spawner.must_spawn(sd_detect_task(sd_det_gpio));