From 925ede848ec1fc3389b5bbd22d98d919c808bfe3 Mon Sep 17 00:00:00 2001 From: xoviat Date: Thu, 31 Dec 2020 16:40:51 -0600 Subject: [PATCH] rename uarte as serial --- embassy-stm32f4/src/serial.rs | 44 +++++++++++++++++++--------------- examples-stm32f4/src/serial.rs | 2 +- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs index e414dc02..bb47a930 100644 --- a/embassy-stm32f4/src/serial.rs +++ b/embassy-stm32f4/src/serial.rs @@ -1,4 +1,4 @@ -//! Async low power UARTE. +//! Async low power Serial. //! //! The peripheral is autmatically enabled and disabled as required to save power. //! Lowest power consumption can only be guaranteed if the send receive futures @@ -34,7 +34,7 @@ use crate::hal::rcc::Clocks; use crate::hal::serial::config::{ Config as SerialConfig, DmaConfig as SerialDmaConfig, Parity, StopBits, WordLength, }; -use crate::hal::serial::{Event as SerialEvent, Serial}; +use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial}; use crate::hal::time::Bps; use crate::interrupt; @@ -44,8 +44,8 @@ use crate::pac::{DMA2, USART1}; use embedded_hal::digital::v2::OutputPin; -/// Interface to the UARTE peripheral -pub struct Uarte, TSTREAM: Stream, RSTREAM: Stream> { +/// Interface to the Serial peripheral +pub struct Serial, TSTREAM: Stream, RSTREAM: Stream> { // tx_transfer: Transfer, Channel4, USART1, MemoryToPeripheral, &mut [u8; 20]>, // rx_transfer: Transfer, Channel4, USART1, PeripheralToMemory, &mut [u8; 20]>, tx_stream: Option, @@ -63,7 +63,7 @@ static STATE: State = State { rx_done: Signal::new(), }; -impl Uarte, Stream2> { +impl Serial, Stream2> { pub fn new( rxd: PA10>, txd: PA9>, @@ -73,7 +73,7 @@ impl Uarte, Stream2> { baudrate: Bps, clocks: Clocks, ) -> Self { - let serial = Serial::usart1( + let serial = HalSerial::usart1( usart, (txd, rxd), SerialConfig { @@ -93,7 +93,7 @@ impl Uarte, Stream2> { let streams = StreamsTuple::new(dma); - Uarte { + Serial { tx_stream: Some(streams.7), rx_stream: Some(streams.2), usart: Some(usart), @@ -126,7 +126,7 @@ impl Uarte, Stream2> { ); SendFuture { - uarte: self, + Serial: self, tx_transfer: Some(tx_transfer), // tx_stream: Some(tx_stream), // usart: Some(usart), @@ -165,13 +165,13 @@ impl Uarte, Stream2> { ); ReceiveFuture { - uarte: self, + Serial: self, rx_transfer: Some(rx_transfer), } } } -/// Future for the [`LowPowerUarte::send()`] method. +/// Future for the [`LowPowerSerial::send()`] method. pub struct SendFuture< 'a, B: WriteBuffer + 'static, @@ -180,7 +180,7 @@ pub struct SendFuture< RSTREAM: Stream, CHANNEL, > { - uarte: &'a mut Uarte, + Serial: &'a mut Serial, tx_transfer: Option>, } @@ -198,13 +198,16 @@ where type Output = (); fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { - let Self { uarte, tx_transfer } = unsafe { self.get_unchecked_mut() }; + let Self { + Serial, + tx_transfer, + } = unsafe { self.get_unchecked_mut() }; let mut taken = tx_transfer.take().unwrap(); if Stream7::::get_transfer_complete_flag() { let (tx_stream, usart, buf, _) = taken.free(); - uarte.tx_stream.replace(tx_stream); - uarte.usart.replace(usart); + Serial.tx_stream.replace(tx_stream); + Serial.usart.replace(usart); Poll::Ready(()) } else { @@ -217,7 +220,7 @@ where } } -/// Future for the [`Uarte::receive()`] method. +/// Future for the [`Serial::receive()`] method. pub struct ReceiveFuture< 'a, B: WriteBuffer + 'static, @@ -226,7 +229,7 @@ pub struct ReceiveFuture< RSTREAM: Stream, CHANNEL, > { - uarte: &'a mut Uarte, + Serial: &'a mut Serial, rx_transfer: Option>, } @@ -244,14 +247,17 @@ where type Output = B; fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let Self { uarte, rx_transfer } = unsafe { self.get_unchecked_mut() }; + let Self { + Serial, + rx_transfer, + } = unsafe { self.get_unchecked_mut() }; let mut taken = rx_transfer.take().unwrap(); if Stream7::::get_transfer_complete_flag() { let (rx_stream, usart, buf, _) = rx_transfer.take().unwrap().free(); - uarte.rx_stream.replace(rx_stream); - uarte.usart.replace(usart); + Serial.rx_stream.replace(rx_stream); + Serial.usart.replace(usart); Poll::Ready(buf) } else { diff --git a/examples-stm32f4/src/serial.rs b/examples-stm32f4/src/serial.rs index f7fd525a..1f5c0fb7 100644 --- a/examples-stm32f4/src/serial.rs +++ b/examples-stm32f4/src/serial.rs @@ -26,7 +26,7 @@ async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) { .pclk1(24.mhz()) .freeze(); - let mut serial = serial::Uarte::new( + let mut serial = serial::Serial::new( gpioa.pa10.into_alternate_af7(), gpioa.pa9.into_alternate_af7(), dp.DMA2,