redesign
This commit is contained in:
@@ -5,12 +5,10 @@
|
|||||||
use defmt::*;
|
use defmt::*;
|
||||||
use embassy_stm32::pac;
|
use embassy_stm32::pac;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_futures::yield_now;
|
use embassy_stm32::Config;
|
||||||
use embassy_stm32::bind_interrupts;
|
use embassy_stm32::bind_interrupts;
|
||||||
use embassy_stm32::peripherals;
|
use embassy_stm32::peripherals;
|
||||||
use embassy_stm32::Config;
|
use embassy_stm32::usart::{BufferedInterruptHandler, BufferedUart, Config as UsartConfig};
|
||||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel};
|
|
||||||
use embassy_stm32::usart::{BufferedUart, Config as UsartConfig, BufferedInterruptHandler};
|
|
||||||
use embassy_stm32::gpio::{Output, Level, Speed};
|
use embassy_stm32::gpio::{Output, Level, Speed};
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
|
|
||||||
@@ -22,48 +20,13 @@ use dma_gpio::hw_uart_pc::driver::uart_task;
|
|||||||
use dma_gpio::wakeup::iwdg::{clear_wakeup_flags, init_watchdog_reset};
|
use dma_gpio::wakeup::iwdg::{clear_wakeup_flags, init_watchdog_reset};
|
||||||
use dma_gpio::sleep::shutdown;
|
use dma_gpio::sleep::shutdown;
|
||||||
use dma_gpio::sleep::standby;
|
use dma_gpio::sleep::standby;
|
||||||
|
use dma_gpio::hw_uart_pc::init::{LowPowerCmd, CMD_CH, uart_cmd_task};
|
||||||
use {defmt_rtt as _, panic_probe as _};
|
use {defmt_rtt as _, panic_probe as _};
|
||||||
|
|
||||||
bind_interrupts!(struct Irqs {
|
bind_interrupts!(struct Irqs {
|
||||||
USART1 => BufferedInterruptHandler<peripherals::USART1>;
|
USART1 => BufferedInterruptHandler<peripherals::USART1>;
|
||||||
});
|
});
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
||||||
enum LowPowerCmd {
|
|
||||||
Standby8k, // 1
|
|
||||||
StandbyFull, // 2
|
|
||||||
Standby, // 3
|
|
||||||
Shutdown, // 4
|
|
||||||
}
|
|
||||||
|
|
||||||
static CMD_CH: Channel<CriticalSectionRawMutex, LowPowerCmd, 1> = Channel::new();
|
|
||||||
|
|
||||||
#[embassy_executor::task]
|
|
||||||
async fn uart_cmd_task() {
|
|
||||||
// Prompt once
|
|
||||||
let _ = PIPE_HW_TX
|
|
||||||
.write(b"Modes: 1=SB8, 2=SBfull, 3=SB, 4=SD\r\n")
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let mut b = [0u8; 1];
|
|
||||||
loop {
|
|
||||||
let n = PIPE_HW_RX.read(&mut b).await;
|
|
||||||
if n == 0 {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
match b[0] {
|
|
||||||
b'1' => { let _ = PIPE_HW_TX.write(b"ACK 1: standby 8KB\r\n").await; CMD_CH.send(LowPowerCmd::Standby8k).await; }
|
|
||||||
b'2' => { let _ = PIPE_HW_TX.write(b"ACK 2: standby full\r\n").await; CMD_CH.send(LowPowerCmd::StandbyFull).await; }
|
|
||||||
b'3' => { let _ = PIPE_HW_TX.write(b"ACK 3: standby\r\n").await; CMD_CH.send(LowPowerCmd::Standby).await; }
|
|
||||||
b'4' => { let _ = PIPE_HW_TX.write(b"ACK 4: shutdown\r\n").await; CMD_CH.send(LowPowerCmd::Shutdown).await; }
|
|
||||||
b'\r' | b'\n' | b' ' => {}
|
|
||||||
_ => { let _ = PIPE_HW_TX.write(b"ERR: use 1|2|3|4\r\n").await; }
|
|
||||||
}
|
|
||||||
yield_now().await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(spawner: Spawner) {
|
async fn main(spawner: Spawner) {
|
||||||
info!("boot");
|
info!("boot");
|
||||||
|
|||||||
53
semestralka_2_uart/src/hw_uart_pc/init.rs
Normal file
53
semestralka_2_uart/src/hw_uart_pc/init.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
// src/hw_uart_pc/init.rs
|
||||||
|
|
||||||
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
|
use embassy_sync::channel::Channel;
|
||||||
|
use embassy_futures::yield_now;
|
||||||
|
use crate::config::{PIPE_HW_TX, PIPE_HW_RX};
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum LowPowerCmd {
|
||||||
|
Standby8k, // 1
|
||||||
|
StandbyFull, // 2
|
||||||
|
Standby, // 3
|
||||||
|
Shutdown, // 4
|
||||||
|
}
|
||||||
|
|
||||||
|
pub static CMD_CH: Channel<CriticalSectionRawMutex, LowPowerCmd, 1> = Channel::new();
|
||||||
|
|
||||||
|
#[embassy_executor::task]
|
||||||
|
pub async fn uart_cmd_task() {
|
||||||
|
// Prompt once
|
||||||
|
let _ = PIPE_HW_TX
|
||||||
|
.write(b"Modes: 1=SB8, 2=SBfull, 3=SB, 4=SD\r\n")
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let mut b = [0u8; 1];
|
||||||
|
loop {
|
||||||
|
let n = PIPE_HW_RX.read(&mut b).await;
|
||||||
|
if n == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
match b[0] {
|
||||||
|
b'1' => {
|
||||||
|
let _ = PIPE_HW_TX.write(b"ACK 1: standby 8KB\r\n").await;
|
||||||
|
CMD_CH.send(LowPowerCmd::Standby8k).await;
|
||||||
|
}
|
||||||
|
b'2' => {
|
||||||
|
let _ = PIPE_HW_TX.write(b"ACK 2: standby full\r\n").await;
|
||||||
|
CMD_CH.send(LowPowerCmd::StandbyFull).await;
|
||||||
|
}
|
||||||
|
b'3' => {
|
||||||
|
let _ = PIPE_HW_TX.write(b"ACK 3: standby\r\n").await;
|
||||||
|
CMD_CH.send(LowPowerCmd::Standby).await;
|
||||||
|
}
|
||||||
|
b'4' => {
|
||||||
|
let _ = PIPE_HW_TX.write(b"ACK 4: shutdown\r\n").await;
|
||||||
|
CMD_CH.send(LowPowerCmd::Shutdown).await;
|
||||||
|
}
|
||||||
|
b'\r' | b'\n' | b' ' => {}
|
||||||
|
_ => { let _ = PIPE_HW_TX.write(b"ERR: use 1|2|3|4\r\n").await; }
|
||||||
|
}
|
||||||
|
yield_now().await;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,3 +2,4 @@
|
|||||||
pub mod driver;
|
pub mod driver;
|
||||||
pub mod usart1;
|
pub mod usart1;
|
||||||
pub mod safety;
|
pub mod safety;
|
||||||
|
pub mod init;
|
||||||
|
|||||||
Reference in New Issue
Block a user