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