redesigned, removed redundancy
This commit is contained in:
@@ -12,7 +12,7 @@ use dma_gpio::software_uart::{
|
|||||||
gpio_dma_uart_tx::{
|
gpio_dma_uart_tx::{
|
||||||
write_uart_frames_to_ring, Parity, StopBits, UartConfig, TIM6_UP_REQ,
|
write_uart_frames_to_ring, Parity, StopBits, UartConfig, TIM6_UP_REQ,
|
||||||
},
|
},
|
||||||
runtime::rx_dma_task,
|
gpio_dma_uart_rx::rx_dma_task,
|
||||||
debug::dump_tim6_regs,
|
debug::dump_tim6_regs,
|
||||||
};
|
};
|
||||||
use embassy_stm32::dma::{TransferOptions, WritableRingBuffer};
|
use embassy_stm32::dma::{TransferOptions, WritableRingBuffer};
|
||||||
|
|||||||
@@ -1,57 +1,39 @@
|
|||||||
// src/gpio_dma_uart_rx.rs
|
// src/software_uart/runtime.rs
|
||||||
|
use embassy_executor::task;
|
||||||
use embassy_stm32::{
|
use embassy_stm32::{
|
||||||
dma::{Request, Transfer, TransferOptions},
|
dma::Request,
|
||||||
peripherals::GPDMA1_CH1,
|
peripherals::GPDMA1_CH1,
|
||||||
Peri,
|
Peri,
|
||||||
};
|
};
|
||||||
|
use embassy_stm32::dma::{
|
||||||
|
ReadableRingBuffer as DmaRingRx,
|
||||||
|
TransferOptions,
|
||||||
|
};
|
||||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, pipe::Pipe};
|
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, pipe::Pipe};
|
||||||
|
|
||||||
// RM0456 tabulka 137
|
// datasheet tabulka 137
|
||||||
pub const TIM7_UP_REQ: Request = 5;
|
pub const TIM7_UP_REQ: Request = 5;
|
||||||
|
|
||||||
pub struct GpioDmaRx<'d, const N: usize> {
|
/// RX DMA task: reads GPIO samples paced by TIM7 and fills PIPE_RX
|
||||||
ch: Peri<'d, GPDMA1_CH1>,
|
#[task]
|
||||||
pin_bit: u8,
|
pub async fn rx_dma_task(
|
||||||
buf: &'d mut [u32; N],
|
ch: Peri<'static, GPDMA1_CH1>,
|
||||||
opts: TransferOptions,
|
pipe_rx: &'static Pipe<CriticalSectionRawMutex, 256>,
|
||||||
pipe_rx: &'d Pipe<CriticalSectionRawMutex, 256>,
|
ring: &'static mut [u8],
|
||||||
}
|
) {
|
||||||
|
let gpioa_idr = embassy_stm32::pac::GPIOA.idr().as_ptr() as *mut u8;
|
||||||
|
|
||||||
impl<'d, const N: usize> GpioDmaRx<'d, N> {
|
let mut opts = TransferOptions::default();
|
||||||
pub fn new(
|
opts.half_transfer_ir = true;
|
||||||
ch: Peri<'d, GPDMA1_CH1>,
|
opts.complete_transfer_ir = true;
|
||||||
pin_bit: u8,
|
|
||||||
buf: &'d mut [u32; N],
|
|
||||||
pipe_rx: &'d Pipe<CriticalSectionRawMutex, 256>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
|
||||||
ch,
|
|
||||||
pin_bit,
|
|
||||||
buf,
|
|
||||||
opts: TransferOptions::default(),
|
|
||||||
pipe_rx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run(&mut self) -> ! {
|
// SAFETY: ring is exclusive to this task
|
||||||
loop {
|
let mut rx = unsafe { DmaRingRx::new(ch, TIM7_UP_REQ, gpioa_idr, ring, opts) };
|
||||||
let gpioa_idr_addr = embassy_stm32::pac::GPIOA.as_ptr() as *mut u32;
|
rx.start();
|
||||||
|
|
||||||
unsafe {
|
let mut chunk = [0u8; 256];
|
||||||
Transfer::new_read(
|
loop {
|
||||||
self.ch.reborrow(),
|
let _ = rx.read_exact(&mut chunk).await;
|
||||||
TIM7_UP_REQ,
|
pipe_rx.write(&chunk).await;
|
||||||
gpioa_idr_addr,
|
|
||||||
&mut self.buf[..],
|
|
||||||
self.opts,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.await;
|
|
||||||
|
|
||||||
for &word in self.buf.iter() {
|
|
||||||
let bit_high = ((word >> self.pin_bit) & 1) as u8;
|
|
||||||
self.pipe_rx.write(&[bit_high]).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,9 @@
|
|||||||
pub mod gpio_dma_uart_tx;
|
pub mod gpio_dma_uart_tx;
|
||||||
pub mod gpio_dma_uart_rx;
|
pub mod gpio_dma_uart_rx;
|
||||||
pub mod dma_timer;
|
pub mod dma_timer;
|
||||||
pub mod runtime;
|
|
||||||
pub mod debug;
|
pub mod debug;
|
||||||
|
|
||||||
pub use gpio_dma_uart_tx::*;
|
pub use gpio_dma_uart_tx::*;
|
||||||
pub use gpio_dma_uart_rx::*;
|
pub use gpio_dma_uart_rx::*;
|
||||||
pub use dma_timer::*;
|
pub use dma_timer::*;
|
||||||
pub use runtime::*;
|
|
||||||
pub use debug::*;
|
pub use debug::*;
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
// src/software_uart/runtime.rs
|
|
||||||
use embassy_executor::task;
|
|
||||||
use embassy_stm32::{
|
|
||||||
peripherals::GPDMA1_CH1,
|
|
||||||
Peri,
|
|
||||||
};
|
|
||||||
use embassy_stm32::dma::{
|
|
||||||
ReadableRingBuffer as DmaRingRx,
|
|
||||||
TransferOptions,
|
|
||||||
};
|
|
||||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, pipe::Pipe};
|
|
||||||
use crate::software_uart::gpio_dma_uart_rx::TIM7_UP_REQ;
|
|
||||||
|
|
||||||
/// RX DMA task: reads GPIO samples paced by TIM7 and fills PIPE_RX
|
|
||||||
#[task]
|
|
||||||
pub async fn rx_dma_task(
|
|
||||||
ch: Peri<'static, GPDMA1_CH1>,
|
|
||||||
pipe_rx: &'static Pipe<CriticalSectionRawMutex, 256>,
|
|
||||||
ring: &'static mut [u8],
|
|
||||||
) {
|
|
||||||
let gpioa_idr = embassy_stm32::pac::GPIOA.idr().as_ptr() as *mut u8;
|
|
||||||
|
|
||||||
let mut opts = TransferOptions::default();
|
|
||||||
opts.half_transfer_ir = true;
|
|
||||||
opts.complete_transfer_ir = true;
|
|
||||||
|
|
||||||
// SAFETY: ring is exclusive to this task
|
|
||||||
let mut rx = unsafe { DmaRingRx::new(ch, TIM7_UP_REQ, gpioa_idr, ring, opts) };
|
|
||||||
rx.start();
|
|
||||||
|
|
||||||
let mut chunk = [0u8; 256];
|
|
||||||
loop {
|
|
||||||
let _ = rx.read_exact(&mut chunk).await;
|
|
||||||
pipe_rx.write(&chunk).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user