mirror of
				https://github.com/Djeeberjr/fw-anwesenheit.git
				synced 2025-11-03 23:24:10 +00:00 
			
		
		
		
	implemented LED for new lib !esp-hhal-smartled is not released!
This commit is contained in:
		
							parent
							
								
									a0ed04a560
								
							
						
					
					
						commit
						03e6a9036f
					
				
							
								
								
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@ -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",
 | 
			
		||||
 | 
			
		||||
@ -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"
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
 | 
			
		||||
@ -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<RefCell<Option<Input>>> = 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,
 | 
			
		||||
 | 
			
		||||
@ -47,7 +47,7 @@ static CHAN: StaticCell<TallyChannel> = 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));
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user