compiled hw and sw uart in semestralka
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
// src/uart/driver.rs
|
||||
use defmt::unwrap;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_futures::select::{select, Either};
|
||||
use embassy_stm32::usart::BufferedUart;
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
@@ -8,7 +7,7 @@ use embassy_sync::pipe::Pipe;
|
||||
use embassy_time::Duration;
|
||||
use embedded_io_async::{Read, Write};
|
||||
|
||||
use crate::uart::safety::{RX_PIPE_CAP, TX_PIPE_CAP};
|
||||
use crate::hw_uart_pc::safety::{RX_PIPE_CAP, TX_PIPE_CAP};
|
||||
|
||||
pub struct UartHandle {
|
||||
pub tx: &'static Pipe<CriticalSectionRawMutex, TX_PIPE_CAP>,
|
||||
@@ -36,9 +35,7 @@ pub async fn uart_task(
|
||||
// Incoming data from UART hardware
|
||||
Either::First(res) => {
|
||||
if let Ok(_) = res {
|
||||
// Forward to RX pipe and echo to TX pipe (same behavior as before)
|
||||
let _ = rx_pipe.write(&rx_byte).await;
|
||||
let _ = tx_pipe.try_write(&rx_byte);
|
||||
}
|
||||
}
|
||||
// Outgoing data waiting in TX pipe
|
||||
@@ -48,18 +45,3 @@ pub async fn uart_task(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_for(
|
||||
spawner: &Spawner,
|
||||
uart: BufferedUart<'static>,
|
||||
tx_pipe: &'static Pipe<CriticalSectionRawMutex, TX_PIPE_CAP>,
|
||||
rx_pipe: &'static Pipe<CriticalSectionRawMutex, RX_PIPE_CAP>,
|
||||
yield_period: Duration,
|
||||
) -> UartHandle {
|
||||
spawner.spawn(uart_task(uart, tx_pipe, rx_pipe)).unwrap();
|
||||
UartHandle {
|
||||
tx: tx_pipe,
|
||||
rx: rx_pipe,
|
||||
yield_period,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
// src/uart/usart1.rs
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::pipe::Pipe;
|
||||
use embassy_time::Duration;
|
||||
|
||||
use crate::uart::safety::{preflight_and_suggest_yield_period, RX_PIPE_CAP, TX_PIPE_CAP};
|
||||
use crate::uart::driver::{spawn_for, UartHandle};
|
||||
use crate::hw_uart_pc::safety::{preflight_and_suggest_yield_period, RX_PIPE_CAP, TX_PIPE_CAP};
|
||||
use crate::hw_uart_pc::driver::UartHandle;
|
||||
|
||||
// Static pipes and buffers
|
||||
static UART1_TX_PIPE: Pipe<CriticalSectionRawMutex, TX_PIPE_CAP> = Pipe::new();
|
||||
static UART1_RX_PIPE: Pipe<CriticalSectionRawMutex, RX_PIPE_CAP> = Pipe::new();
|
||||
|
||||
pub fn setup_and_spawn(
|
||||
spawner: &Spawner,
|
||||
uart: embassy_stm32::usart::BufferedUart<'static>,
|
||||
baudrate: u32,
|
||||
) -> UartHandle {
|
||||
pub fn setup_and_spawn(baudrate: u32,) -> (UartHandle, Duration) {
|
||||
let yield_period: Duration = preflight_and_suggest_yield_period(baudrate);
|
||||
info!("USART1 initialized");
|
||||
spawn_for(spawner, uart, &UART1_TX_PIPE, &UART1_RX_PIPE, yield_period)
|
||||
info!("HW USART1 safe");
|
||||
let handle = UartHandle {
|
||||
tx: &UART1_TX_PIPE,
|
||||
rx: &UART1_RX_PIPE,
|
||||
yield_period,
|
||||
};
|
||||
|
||||
(handle, yield_period)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user