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 25, 2024
1 parent 5fc93ec commit 2c71ff6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
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
6 changes: 3 additions & 3 deletions src/gpio/alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,10 @@ pub trait SerialSync {
type Ck;
}
/// Hardware flow control (RS232)
pub trait SerialRs232 {
/// Receive
pub trait SerialFlowControl {
/// "Clear To Send" blocks the data transmission at the end of the current transfer when high
type Cts;
/// Transmit
/// "Request to send" indicates that the USART is ready to receive a data (when low)
type Rts;
}

Expand Down
12 changes: 6 additions & 6 deletions src/gpio/alt/f4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4047,7 +4047,7 @@ pub mod usart1 {
impl SerialSync for USART {
type Ck = Ck;
}
impl SerialRs232 for USART {
impl SerialFlowControl for USART {
type Cts = Cts;
type Rts = Rts;
}
Expand Down Expand Up @@ -4103,7 +4103,7 @@ pub mod usart2 {
impl SerialSync for USART {
type Ck = Ck;
}
impl SerialRs232 for USART {
impl SerialFlowControl for USART {
type Cts = Cts;
type Rts = Rts;
}
Expand Down Expand Up @@ -4182,7 +4182,7 @@ pub mod usart3 {
impl SerialSync for USART {
type Ck = Ck;
}
impl SerialRs232 for USART {
impl SerialFlowControl for USART {
type Cts = Cts;
type Rts = Rts;
}
Expand Down Expand Up @@ -4293,7 +4293,7 @@ pub mod usart6 {
feature = "gpio-f446",
feature = "gpio-f469"
))]
impl SerialRs232 for USART {
impl SerialFlowControl for USART {
type Cts = Cts;
type Rts = Rts;
}
Expand Down Expand Up @@ -4355,7 +4355,7 @@ pub mod uart4 {
type Tx<Otype> = Tx<Otype>;
}
#[cfg(feature = "gpio-f446")]
impl SerialRs232 for UART {
impl SerialFlowControl for UART {
type Cts = Cts;
type Rts = Rts;
}
Expand Down Expand Up @@ -4416,7 +4416,7 @@ pub mod uart5 {
type Tx<Otype> = Tx<Otype>;
}
#[cfg(feature = "gpio-f446")]
impl SerialRs232 for UART {
impl SerialFlowControl for UART {
type Cts = Cts;
type Rts = Rts;
}
Expand Down
37 changes: 36 additions & 1 deletion src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) mod uart_impls;
pub use uart_impls::Instance;
use uart_impls::RegisterBlockImpl;

use crate::gpio::{self, PushPull};
use crate::gpio::{self, alt::SerialFlowControl, PushPull};

use crate::pac;

Expand Down Expand Up @@ -250,6 +250,41 @@ impl<UART: CommonPins, WORD> Serial<UART, WORD> {
}
}

impl<UART: Instance<RegisterBlock = pac::usart1::RegisterBlock> + SerialFlowControl, WORD>
Serial<UART, WORD>
{
fn enable_rts(&self, state: bool) {
self.rx.usart.cr3().modify(|_, w| w.rtse().bit(state));
}

fn enable_cts(&self, state: bool) {
self.tx.usart.cr3().modify(|_, w| w.ctse().bit(state));
}

pub fn with_rts(self, rts: impl Into<UART::Rts>) -> Self {
self.enable_rts(true);
let _rts = rts.into();
self
}
pub fn with_cts(self, cts: impl Into<UART::Cts>) -> Self {
self.enable_cts(true);
let _cts = cts.into();
self
}
pub fn enable_request_to_send(&mut self) {
self.enable_rts(true);
}
pub fn disable_request_to_send(&mut self) {
self.enable_rts(false);
}
pub fn enable_clear_to_send(&mut self) {
self.enable_cts(true);
}
pub fn disable_clear_to_send(&mut self) {
self.enable_cts(false);
}
}

macro_rules! halUsart {
($USART:ty, $Serial:ident, $Rx:ident, $Tx:ident) => {
pub type $Serial<WORD = u8> = Serial<$USART, WORD>;
Expand Down
2 changes: 1 addition & 1 deletion src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use crate::pac;

use crate::serial::uart_impls::{RegisterBlockImpl, RegisterBlockUart};
use crate::serial::uart_impls::RegisterBlockUart;

pub use crate::serial::{config, Error, Event, Instance, NoRx, NoTx, Rx, RxISR, Serial, Tx, TxISR};
pub use config::Config;
Expand Down

0 comments on commit 2c71ff6

Please sign in to comment.