moved handler
This commit is contained in:
@@ -12,7 +12,7 @@ use embassy_time::{Duration, Timer};
|
||||
use dma_gpio::config::BAUD;
|
||||
use dma_gpio::wakeup::iwdg::clear_wakeup_flags;
|
||||
use dma_gpio::wakeup::gpio::gpio_wakeup;
|
||||
use dma_gpio::sleep::handler::execute_low_power;
|
||||
use dma_gpio::logic::handler::execute_low_power;
|
||||
use dma_gpio::hw_uart_pc::init::{init_hw_uart_to_pc, CMD_CH};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
|
||||
@@ -6,3 +6,4 @@ pub mod hw_uart_pc;
|
||||
pub mod config;
|
||||
pub mod sleep;
|
||||
pub mod wakeup;
|
||||
pub mod logic;
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// src/sleep/handler.rs
|
||||
// src/logic/handler.rs
|
||||
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_stm32::peripherals;
|
||||
use embassy_stm32::Peri;
|
||||
|
||||
use crate::sleep::stop::*;
|
||||
use crate::sleep::stop::{enter_stop0, enter_stop1, enter_stop2, enter_stop3};
|
||||
use crate::sleep::sleep::{enter_sleep_mode, SleepEntry};
|
||||
use crate::sleep::{standby, shutdown};
|
||||
use crate::wakeup::iwdg::init_watchdog_reset;
|
||||
use crate::hw_uart_pc::init::{LowPowerCmd, StopMode, StopModeConfig};
|
||||
|
||||
@@ -22,25 +24,25 @@ pub async fn execute_low_power(
|
||||
if let Some(wdg) = iwdg.take() {
|
||||
init_watchdog_reset(wdg).await;
|
||||
}
|
||||
super::standby::enter_standby_with_sram2_8kb();
|
||||
standby::enter_standby_with_sram2_8kb();
|
||||
}
|
||||
LowPowerCmd::StandbyFull => {
|
||||
info!("Entering Standby with full SRAM2 retention");
|
||||
if let Some(wdg) = iwdg.take() {
|
||||
init_watchdog_reset(wdg).await;
|
||||
}
|
||||
super::standby::enter_standby_with_sram2_full();
|
||||
standby::enter_standby_with_sram2_full();
|
||||
}
|
||||
LowPowerCmd::Standby => {
|
||||
info!("Entering minimal Standby");
|
||||
if let Some(wdg) = iwdg.take() {
|
||||
init_watchdog_reset(wdg).await;
|
||||
}
|
||||
super::standby::enter_standby();
|
||||
standby::enter_standby();
|
||||
}
|
||||
LowPowerCmd::Shutdown => {
|
||||
info!("Entering Shutdown mode");
|
||||
super::shutdown::enter_shutdown();
|
||||
shutdown::enter_shutdown();
|
||||
}
|
||||
LowPowerCmd::StopMode(StopModeConfig { mode, entry }) => {
|
||||
info!("Entering {:?} with {:?}", mode, entry);
|
||||
@@ -58,7 +60,6 @@ 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.");
|
||||
}
|
||||
3
semestralka_2_uart/src/logic/mod.rs
Normal file
3
semestralka_2_uart/src/logic/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/logic/mod.rs
|
||||
|
||||
pub mod handler;
|
||||
@@ -3,7 +3,6 @@
|
||||
pub mod standby;
|
||||
pub mod shutdown;
|
||||
pub mod stop;
|
||||
pub mod handler;
|
||||
pub mod sleep;
|
||||
|
||||
pub use stop::StopEntry;
|
||||
|
||||
@@ -9,7 +9,7 @@ pub fn enter_standby() -> ! {
|
||||
HAL_PWR_EnterSTANDBYMode();
|
||||
}
|
||||
|
||||
cortex_m::asm::udf(); // never happen marker
|
||||
cortex_m::asm::udf();
|
||||
}
|
||||
|
||||
pub fn enter_standby_with_sram2_8kb() -> ! {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use cortex_m::Peripherals;
|
||||
use cortex_m::asm;
|
||||
|
||||
/// How to enter STOPx mode (STOP0–STOP3)
|
||||
/// Enter STOPx mode parameter
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
|
||||
pub enum StopEntry {
|
||||
Wfi,
|
||||
|
||||
@@ -7,19 +7,19 @@ use embassy_stm32::peripherals;
|
||||
use embassy_time::{Duration, Timer};
|
||||
use embassy_hal_internal::Peri;
|
||||
|
||||
/// GPIO pin as an EXTI wake‑up source.
|
||||
/// GPIO pin as an EXTI wake-up source.
|
||||
#[embassy_executor::task]
|
||||
pub async fn gpio_wakeup(
|
||||
pin: Peri<'static, peripherals::PA0>,
|
||||
ch: Peri<'static, peripherals::EXTI0>
|
||||
) {
|
||||
info!("Configuring EXTI wake input on PA0 (rising edge)");
|
||||
info!("EXTI wake input on PA0");
|
||||
let mut btn = ExtiInput::new(pin, ch, Pull::Up);
|
||||
|
||||
loop {
|
||||
info!("Waiting for rising edge on PA0");
|
||||
info!("Waiting for falling edge on PA0");
|
||||
btn.wait_for_falling_edge().await;
|
||||
info!("GPIO wake‑up: event detected!");
|
||||
info!("GPIO wake-up");
|
||||
Timer::after(Duration::from_millis(50)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,8 @@ use crate::sleep::standby;
|
||||
|
||||
use crate::config::WATCHDOG_TIMEOUT_US;
|
||||
|
||||
/// Clears system reset and standby flags after wakeup.
|
||||
/// Call early in startup
|
||||
///
|
||||
/// # Registers
|
||||
/// - `RCC_CSR` — Reset and Clock Control / Status
|
||||
/// - `PWR_SR` — Power Control / Status
|
||||
pub fn clear_wakeup_flags() {
|
||||
@@ -34,10 +32,10 @@ pub fn clear_wakeup_flags() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes the Independent Watchdog (IWDG) timer.
|
||||
/// Init Independent Watchdog (IWDG) timer.
|
||||
/// Timeout value is configured in `WATCHDOG_TIMEOUT_US` from config.rs
|
||||
pub async fn init_watchdog_reset(iwdg: Peri<'static, peripherals::IWDG>) {
|
||||
info!("Initializing watchdog after watchdog wake...");
|
||||
info!("Init watchdog after watchdog wake...");
|
||||
let mut watchdog = IndependentWatchdog::new(iwdg, WATCHDOG_TIMEOUT_US);
|
||||
watchdog.unleash();
|
||||
Timer::after(Duration::from_millis(10)).await;
|
||||
|
||||
Reference in New Issue
Block a user