implementation of stops and reorganization of the codebase
This commit is contained in:
55
semestralka_2_uart/src/sleep/stop.rs
Normal file
55
semestralka_2_uart/src/sleep/stop.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
// src/sleep/stop.rs
|
||||
|
||||
/// How to enter STOPx mode (STOP0–STOP3)
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
|
||||
pub enum StopEntry {
|
||||
Wfi,
|
||||
Wfe,
|
||||
WfeNoEventClear,
|
||||
}
|
||||
|
||||
impl From<StopEntry> for u8 {
|
||||
fn from(value: StopEntry) -> Self {
|
||||
match value {
|
||||
StopEntry::Wfi => 0x01,
|
||||
StopEntry::Wfe => 0x02,
|
||||
StopEntry::WfeNoEventClear => 0x03,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enter_stop1(entry: StopEntry) -> ! {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnterSTOP1Mode(entry: u8);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP1Mode(entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
pub fn enter_stop2(entry: StopEntry) -> ! {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnterSTOP2Mode(entry: u8);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP2Mode(entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
|
||||
pub fn enter_stop3(entry: StopEntry) -> ! {
|
||||
unsafe extern "C" {
|
||||
fn HAL_PWREx_EnterSTOP3Mode(entry: u8);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
HAL_PWREx_EnterSTOP3Mode(entry.into());
|
||||
}
|
||||
|
||||
cortex_m::asm::udf()
|
||||
}
|
||||
Reference in New Issue
Block a user