diff --git a/hp-core/src/main.rs b/hp-core/src/main.rs index ca198f5..5e9e92b 100644 --- a/hp-core/src/main.rs +++ b/hp-core/src/main.rs @@ -19,6 +19,7 @@ use esp_hal::{ gpio::lp_io::LowPowerOutput, load_lp_code, lp_core::{LpCore, LpCoreWakeupSource}, + rtc_cntl::{Rtc, sleep::WakeFromLpCoreWakeupSource}, main, }; use esp_println::{print, println}; @@ -28,12 +29,14 @@ fn main() -> ! { let peripherals = esp_hal::init(esp_hal::Config::default()); // configure GPIO 1 as LP output pin - let lp_pin = LowPowerOutput::new(peripherals.GPIO1); + let mut rtc = Rtc::new(peripherals.LPWR); + let reason = WakeFromLpCoreWakeupSource::default(); + let mut lp_core = LpCore::new(peripherals.LP_CORE); lp_core.stop(); - println!("lp core stopped"); + println!("lp-core -> stop"); // load code to LP core let lp_core_code = @@ -41,12 +44,19 @@ fn main() -> ! { // start LP core lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_pin); - println!("lpcore run"); + println!("lpcore -> run"); + let mut last: u32 = 0; let data = (0x5000_2000) as *mut u32; loop { - print!("Current {:x} \u{000d}", unsafe { + let read = unsafe { data.read_volatile() - }); + }; + if last != read { + print!("Current {:x} \u{000d}", read); + last = read; + } + println!("hp-core -> deep sleep"); + rtc.sleep_light(&[&reason]); } }