From 4c7d9af29ab1f9b5fa0d7ecf39f876fbcb4f1448 Mon Sep 17 00:00:00 2001 From: Priec Date: Mon, 15 Dec 2025 16:46:10 +0100 Subject: [PATCH] moved handler --- semestralka_2_uart/src/bin/main.rs | 2 +- semestralka_2_uart/src/lib.rs | 1 + .../src/{sleep => logic}/handler.rs | 15 ++++++++------- semestralka_2_uart/src/logic/mod.rs | 3 +++ semestralka_2_uart/src/sleep/mod.rs | 1 - semestralka_2_uart/src/sleep/standby.rs | 2 +- semestralka_2_uart/src/sleep/stop.rs | 2 +- semestralka_2_uart/src/wakeup/gpio.rs | 8 ++++---- semestralka_2_uart/src/wakeup/iwdg.rs | 6 ++---- 9 files changed, 21 insertions(+), 19 deletions(-) rename semestralka_2_uart/src/{sleep => logic}/handler.rs (83%) create mode 100644 semestralka_2_uart/src/logic/mod.rs diff --git a/semestralka_2_uart/src/bin/main.rs b/semestralka_2_uart/src/bin/main.rs index 130fa78..35b77bc 100644 --- a/semestralka_2_uart/src/bin/main.rs +++ b/semestralka_2_uart/src/bin/main.rs @@ -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 _}; diff --git a/semestralka_2_uart/src/lib.rs b/semestralka_2_uart/src/lib.rs index 427f8e7..7049b20 100644 --- a/semestralka_2_uart/src/lib.rs +++ b/semestralka_2_uart/src/lib.rs @@ -6,3 +6,4 @@ pub mod hw_uart_pc; pub mod config; pub mod sleep; pub mod wakeup; +pub mod logic; diff --git a/semestralka_2_uart/src/sleep/handler.rs b/semestralka_2_uart/src/logic/handler.rs similarity index 83% rename from semestralka_2_uart/src/sleep/handler.rs rename to semestralka_2_uart/src/logic/handler.rs index f0c536b..6d193ea 100644 --- a/semestralka_2_uart/src/sleep/handler.rs +++ b/semestralka_2_uart/src/logic/handler.rs @@ -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."); } diff --git a/semestralka_2_uart/src/logic/mod.rs b/semestralka_2_uart/src/logic/mod.rs new file mode 100644 index 0000000..8a72c6c --- /dev/null +++ b/semestralka_2_uart/src/logic/mod.rs @@ -0,0 +1,3 @@ +// src/logic/mod.rs + +pub mod handler; diff --git a/semestralka_2_uart/src/sleep/mod.rs b/semestralka_2_uart/src/sleep/mod.rs index 0ae2f7f..2968455 100644 --- a/semestralka_2_uart/src/sleep/mod.rs +++ b/semestralka_2_uart/src/sleep/mod.rs @@ -3,7 +3,6 @@ pub mod standby; pub mod shutdown; pub mod stop; -pub mod handler; pub mod sleep; pub use stop::StopEntry; diff --git a/semestralka_2_uart/src/sleep/standby.rs b/semestralka_2_uart/src/sleep/standby.rs index b07b1fe..5ab7e2e 100644 --- a/semestralka_2_uart/src/sleep/standby.rs +++ b/semestralka_2_uart/src/sleep/standby.rs @@ -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() -> ! { diff --git a/semestralka_2_uart/src/sleep/stop.rs b/semestralka_2_uart/src/sleep/stop.rs index a2e9ac4..457ca7e 100644 --- a/semestralka_2_uart/src/sleep/stop.rs +++ b/semestralka_2_uart/src/sleep/stop.rs @@ -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, diff --git a/semestralka_2_uart/src/wakeup/gpio.rs b/semestralka_2_uart/src/wakeup/gpio.rs index e2729d7..9cb066b 100644 --- a/semestralka_2_uart/src/wakeup/gpio.rs +++ b/semestralka_2_uart/src/wakeup/gpio.rs @@ -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; } } diff --git a/semestralka_2_uart/src/wakeup/iwdg.rs b/semestralka_2_uart/src/wakeup/iwdg.rs index 0f1afed..4dfdaf6 100644 --- a/semestralka_2_uart/src/wakeup/iwdg.rs +++ b/semestralka_2_uart/src/wakeup/iwdg.rs @@ -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;