This commit is contained in:
Priec
2025-12-14 15:16:24 +01:00
parent 20dfdbc335
commit 053cba171d
4 changed files with 30 additions and 1 deletions

View File

@@ -30,6 +30,7 @@ pub enum LowPowerCmd {
Standby, // 3
Shutdown, // 4
StopMode(StopModeConfig),
Sleep,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
@@ -62,6 +63,7 @@ pub async fn uart_cmd_task() {
[3] Standby minimal\r\n\
[4] Shutdown\r\n\
[5] Stop mode (0-3)\r\n\
[6] Sleep mode (WFI or WFE)\r\n\
"
).await;
embassy_time::Timer::after(embassy_time::Duration::from_millis(8)).await;
@@ -112,7 +114,8 @@ pub async fn uart_cmd_task() {
_ => { print_menu().await; continue; }
};
CMD_CH.send(LowPowerCmd::StopMode(StopModeConfig { mode: stop_mode, entry })).await;
}
},
b'6' => CMD_CH.send(LowPowerCmd::Sleep).await,
_ => { print_menu().await; continue; }
}
}

View File

@@ -57,5 +57,11 @@ pub async fn execute_low_power(
}
}
}
LowPowerCmd::Sleep => {
info!("Entering Sleep mode (WFI)...");
use crate::sleep::sleep::{enter_sleep_mode, SleepEntry};
enter_sleep_mode(SleepEntry::Wfi);
info!("Woke up from Sleep mode.");
}
}
}

View File

@@ -4,5 +4,6 @@ pub mod standby;
pub mod shutdown;
pub mod stop;
pub mod handler;
pub mod sleep;
pub use stop::StopEntry;

View File

@@ -0,0 +1,19 @@
// src/sleep/sleep.rs
use cortex_m::Peripherals;
#[derive(Clone, Copy, Debug, defmt::Format)]
pub enum SleepEntry {
Wfi,
Wfe,
}
pub fn enter_sleep_mode(entry: SleepEntry) {
let mut core = unsafe { Peripherals::steal() };
core.SCB.clear_sleepdeep();
match entry {
SleepEntry::Wfi => cortex_m::asm::wfi(),
SleepEntry::Wfe => cortex_m::asm::wfe(),
}
}