This commit is contained in:
Priec
2025-12-03 23:02:36 +01:00
parent 7184ce9898
commit e2afb2f2f0
3 changed files with 57 additions and 40 deletions

View 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;
}
}

View File

@@ -2,3 +2,4 @@
pub mod driver;
pub mod usart1;
pub mod safety;
pub mod init;