sleep
This commit is contained in:
@@ -30,6 +30,7 @@ pub enum LowPowerCmd {
|
|||||||
Standby, // 3
|
Standby, // 3
|
||||||
Shutdown, // 4
|
Shutdown, // 4
|
||||||
StopMode(StopModeConfig),
|
StopMode(StopModeConfig),
|
||||||
|
Sleep,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
|
||||||
@@ -62,6 +63,7 @@ pub async fn uart_cmd_task() {
|
|||||||
[3] Standby minimal\r\n\
|
[3] Standby minimal\r\n\
|
||||||
[4] Shutdown\r\n\
|
[4] Shutdown\r\n\
|
||||||
[5] Stop mode (0-3)\r\n\
|
[5] Stop mode (0-3)\r\n\
|
||||||
|
[6] Sleep mode (WFI or WFE)\r\n\
|
||||||
"
|
"
|
||||||
).await;
|
).await;
|
||||||
embassy_time::Timer::after(embassy_time::Duration::from_millis(8)).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; }
|
_ => { print_menu().await; continue; }
|
||||||
};
|
};
|
||||||
CMD_CH.send(LowPowerCmd::StopMode(StopModeConfig { mode: stop_mode, entry })).await;
|
CMD_CH.send(LowPowerCmd::StopMode(StopModeConfig { mode: stop_mode, entry })).await;
|
||||||
}
|
},
|
||||||
|
b'6' => CMD_CH.send(LowPowerCmd::Sleep).await,
|
||||||
_ => { print_menu().await; continue; }
|
_ => { print_menu().await; continue; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,6 @@ pub mod standby;
|
|||||||
pub mod shutdown;
|
pub mod shutdown;
|
||||||
pub mod stop;
|
pub mod stop;
|
||||||
pub mod handler;
|
pub mod handler;
|
||||||
|
pub mod sleep;
|
||||||
|
|
||||||
pub use stop::StopEntry;
|
pub use stop::StopEntry;
|
||||||
|
|||||||
19
semestralka_2_uart/src/sleep/sleep.rs
Normal file
19
semestralka_2_uart/src/sleep/sleep.rs
Normal 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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user