Skip to content

Commit

Permalink
Serial flow control
Browse files Browse the repository at this point in the history
  • Loading branch information
burrbull committed Jul 27, 2024
1 parent ad969d2 commit 19a84c4
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- Serial flow control enable
- `i2c_scanner` example [#758]
- Enable `sdio` for stm32f446
- port LTDC implementation and example from stm32f7xx-hal [#731]
Expand Down
64 changes: 63 additions & 1 deletion src/serial/uart_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use crate::dma::{
traits::{DMASet, PeriAddress},
MemoryToPeripheral, PeripheralToMemory,
};
use crate::gpio::{alt::SerialAsync as CommonPins, NoPin, PushPull};
use crate::gpio::{
alt::{SerialAsync as CommonPins, SerialFlowControl},
NoPin, PushPull,
};
use crate::rcc::{self, Clocks};

#[cfg(feature = "uart4")]
Expand Down Expand Up @@ -262,6 +265,20 @@ macro_rules! uartCommon {
};
}

pub trait RBFlowControlImpl {
fn enable_rts(&self, state: bool);
fn enable_cts(&self, state: bool);
}

impl RBFlowControlImpl for RegisterBlockUsart {
fn enable_rts(&self, state: bool) {
self.cr3().modify(|_, w| w.rtse().bit(state));
}
fn enable_cts(&self, state: bool) {
self.cr3().modify(|_, w| w.ctse().bit(state));
}
}

impl RegisterBlockImpl for RegisterBlockUsart {
fn new<UART: Instance + crate::Ptr<RB = Self>, WORD>(
uart: UART,
Expand Down Expand Up @@ -402,6 +419,23 @@ where {
uartCommon! {}
}

#[cfg(feature = "uart4")]
#[cfg(not(any(
feature = "gpio-f413",
feature = "gpio-f417",
feature = "gpio-f427",
feature = "gpio-f446",
feature = "gpio-f469"
)))]
impl RBFlowControlImpl for RegisterBlockUart {
fn enable_rts(&self, state: bool) {
self.cr3().modify(|_, w| w.rtse().bit(state));
}
fn enable_cts(&self, state: bool) {
self.cr3().modify(|_, w| w.ctse().bit(state));
}
}

#[cfg(feature = "uart4")]
impl RegisterBlockImpl for RegisterBlockUart {
fn new<UART: Instance + crate::Ptr<RB = Self>, WORD>(
Expand Down Expand Up @@ -509,6 +543,34 @@ where {
uartCommon! {}
}

impl<UART: Instance + SerialFlowControl, WORD> Serial<UART, WORD>
where
UART::RegisterBlock: RBFlowControlImpl,
{
pub fn with_rts(self, rts: impl Into<UART::Rts>) -> Self {
self.rx.usart.enable_rts(true);
let _rts = rts.into();
self
}
pub fn with_cts(self, cts: impl Into<UART::Cts>) -> Self {
self.tx.usart.enable_cts(true);
let _cts = cts.into();
self
}
pub fn enable_request_to_send(&mut self) {
self.rx.usart.enable_rts(true);
}
pub fn disable_request_to_send(&mut self) {
self.rx.usart.enable_rts(false);
}
pub fn enable_clear_to_send(&mut self) {
self.tx.usart.enable_cts(true);
}
pub fn disable_clear_to_send(&mut self) {
self.tx.usart.enable_cts(false);
}
}

impl<UART: Instance, WORD> RxISR for Serial<UART, WORD>
where
Rx<UART, WORD>: RxISR,
Expand Down

0 comments on commit 19a84c4

Please sign in to comment.