led timer is finished

This commit is contained in:
Priec
2025-10-15 11:44:57 +02:00
parent 8af5dcbede
commit e19a5853b5
10 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
#![no_std]
#![no_main]
#![deny(
clippy::mem_forget,
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
holding buffers for the duration of a data transfer."
)]
use embassy_executor::Spawner;
// use embassy_time::{Duration, Timer};
use esp_backtrace as _;
use esp_hal::{
clock::CpuClock,
gpio::{Level, Output, OutputConfig},
timer::Timer,
timer::timg::TimerGroup,
time::Duration,
};
use log::info;
extern crate alloc;
// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
#[esp_hal_embassy::main]
async fn main(spawner: Spawner) {
esp_println::logger::init_logger_from_env();
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(size: 64 * 1024);
let timer_group1 = TimerGroup::new(peripherals.TIMG1);
let timer0 = timer_group1.timer0;
// Initialize GPIO4 as output (starts LOW)
let mut gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
info!("Embassy initialized!");
loop {
gpio4.set_high();
info!("GPIO4 ON");
// Start timer for 1 second and block until done
let duration = Duration::from_secs(1);
timer0.load_value(duration).unwrap();
timer0.start();
info!("{:?}", duration);
// Wait until timer completes
while !timer0.is_interrupt_set() {}
timer0.clear_interrupt();
gpio4.set_low();
info!("GPIO4 OFF");
// Start timer for 1 second and block until done
timer0.load_value(duration).unwrap();
timer0.start();
while !timer0.is_interrupt_set() {}
timer0.clear_interrupt();
}
}