From 27cfcbacb8e54c0182e118d3170c6f8be83a6b7c Mon Sep 17 00:00:00 2001 From: xoviat Date: Wed, 6 Jan 2021 12:12:29 -0600 Subject: [PATCH] try uart implementation --- embassy-stm32f4/src/serial.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs index 01348e32..ea84a227 100644 --- a/embassy-stm32f4/src/serial.rs +++ b/embassy-stm32f4/src/serial.rs @@ -10,8 +10,9 @@ use core::sync::atomic::{self, Ordering}; use core::task::{Context, Poll}; use embassy::interrupt::OwnedInterrupt; +use embassy::uart::Uart; use embassy::util::Signal; -use embedded_dma::{StaticReadBuffer, StaticWriteBuffer, WriteBuffer}; +use embedded_dma::StaticWriteBuffer; use crate::hal::dma::config::DmaConfig; use crate::hal::dma::traits::{PeriAddress, Stream}; @@ -135,16 +136,15 @@ impl Serial, Stream2> { STATE.rx_int.signal(()); } +} +impl Uart for Serial, Stream2> { /// Sends serial data. /// /// `tx_buffer` is marked as static as per `embedded-dma` requirements. /// It it safe to use a buffer with a non static lifetime if memory is not /// reused until the future has finished. - pub fn send<'a, B: 'a>(&'a mut self, tx_buffer: B) -> impl Future + 'a - where - B: StaticWriteBuffer, - { + fn send<'a>(&'a mut self, buf: &'a mut [u8]) -> dyn Future> { unsafe { INSTANCE = self }; let tx_stream = self.tx_stream.take().unwrap(); @@ -155,7 +155,7 @@ impl Serial, Stream2> { let mut tx_transfer = Transfer::init( tx_stream, usart, - tx_buffer, + buf, None, DmaConfig::default() .transfer_complete_interrupt(true) @@ -185,10 +185,7 @@ impl Serial, Stream2> { /// `rx_buffer` is marked as static as per `embedded-dma` requirements. /// It it safe to use a buffer with a non static lifetime if memory is not /// reused until the future has finished. - pub fn receive<'a, B: 'a>(&'a mut self, rx_buffer: B) -> impl Future + 'a - where - B: StaticWriteBuffer + Unpin, - { + fn receive<'a>(&'a mut self, buf: &'a mut [u8]) -> dyn Future> { unsafe { INSTANCE = self }; let rx_stream = self.rx_stream.take().unwrap(); @@ -199,7 +196,7 @@ impl Serial, Stream2> { let mut rx_transfer = Transfer::init( rx_stream, usart, - rx_buffer, + buf.static_write_buffer(), None, DmaConfig::default() .transfer_complete_interrupt(true) @@ -217,8 +214,6 @@ impl Serial, Stream2> { let (rx_stream, usart, buf, _) = rx_transfer.free(); self.rx_stream.replace(rx_stream); self.usart.replace(usart); - - buf } } }