blinky.rs
1 #![no_std] 2 #![no_main] 3 #![deny( 4 clippy::mem_forget, 5 reason = "mem::forget is generally not safe to do with esp_hal types, especially those \ 6 holding buffers for the duration of a data transfer." 7 )] 8 #![deny(clippy::large_stack_frames)] 9 10 use esp_hal::{ 11 clock::CpuClock, 12 gpio::{Level, Output, OutputConfig}, 13 interrupt::software::SoftwareInterruptControl, 14 time::{Duration, Instant}, 15 timer::timg::TimerGroup, 16 }; 17 use volatile::Volatile; 18 19 use embassy_executor::Spawner; 20 use panic_rtt_target as _; 21 extern crate alloc; 22 23 fn blocking_delay(duration: Duration) { 24 let delay_start = Instant::now(); 25 while delay_start.elapsed() < duration {} 26 } 27 28 esp_bootloader_esp_idf::esp_app_desc!(); 29 30 #[allow( 31 clippy::large_stack_frames, 32 reason = "it's not unusual to allocate larger buffers etc. in main" 33 )] 34 #[esp_rtos::main] 35 async fn main(spawner: Spawner) -> ! { 36 rtt_target::rtt_init_defmt!(); 37 38 let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max()); 39 let peripherals = esp_hal::init(config); 40 41 esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 73744); 42 // COEX needs more RAM - so we've added some more 43 esp_alloc::heap_allocator!(size: 64 * 1024); 44 45 let timg0 = TimerGroup::new(peripherals.TIMG0); 46 let sw_ints = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT); 47 esp_rtos::start(timg0.timer0, sw_ints.software_interrupt0); 48 49 let mut led = Output::new(peripherals.GPIO21, Level::High, OutputConfig::default()); 50 51 let _ = spawner; 52 53 let mut half_period = 500_u64; 54 let v_half_period = Volatile::new(&mut half_period); 55 56 loop { 57 led.toggle(); 58 blocking_delay(Duration::from_millis(v_half_period.read())); 59 } 60 }