esp-idf-hal/examples/blinky_async.rs
ivmarkov a67bf2fd3d
Compatibility with ESP-IDF 5.4.x, 5.5.x and master (#541)
* Compatibility with ESP-IDF 4.x, 5.x and master

* Run main CI againzst released ESP-IDF
2025-08-13 09:02:33 +03:00

41 lines
1.0 KiB
Rust

//! Blinks an LED
//!
//! This assumes that a LED is connected to GPIO4.
//! Depending on your target and the board you are using you should change the pin.
//! If your board doesn't have on-board LEDs don't forget to add an appropriate resistor.
//!
#![allow(unexpected_cfgs)]
#[cfg(esp_idf_version_at_least_6_0_0)]
fn main() {
panic!("Timer not yet available when building against ESP-IDF 6.0+")
}
#[cfg(not(esp_idf_version_at_least_6_0_0))]
fn main() -> anyhow::Result<()> {
use esp_idf_hal::gpio::*;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::task::*;
use esp_idf_hal::timer::*;
esp_idf_hal::sys::link_patches();
let peripherals = Peripherals::take()?;
let mut led = PinDriver::output(peripherals.pins.gpio4)?;
let mut timer = TimerDriver::new(peripherals.timer00, &TimerConfig::new())?;
block_on(async {
loop {
led.set_high()?;
timer.delay(timer.tick_hz()).await?;
led.set_low()?;
timer.delay(timer.tick_hz()).await?;
}
})
}