@@ -10,7 +10,10 @@ use crate::dma::{
1010 traits:: { DMASet , PeriAddress } ,
1111 MemoryToPeripheral , PeripheralToMemory ,
1212} ;
13- use crate :: gpio:: { alt:: SerialAsync as CommonPins , NoPin , PushPull } ;
13+ use crate :: gpio:: {
14+ alt:: { SerialAsync as CommonPins , SerialFlowControl } ,
15+ NoPin , PushPull ,
16+ } ;
1417use crate :: rcc:: { self , Clocks } ;
1518
1619#[ cfg( feature = "uart4" ) ]
@@ -266,6 +269,20 @@ macro_rules! uartCommon {
266269 } ;
267270}
268271
272+ pub trait RBFlowControlImpl {
273+ fn enable_rts ( & self , state : bool ) ;
274+ fn enable_cts ( & self , state : bool ) ;
275+ }
276+
277+ impl RBFlowControlImpl for RegisterBlockUsart {
278+ fn enable_rts ( & self , state : bool ) {
279+ self . cr3 ( ) . modify ( |_, w| w. rtse ( ) . bit ( state) ) ;
280+ }
281+ fn enable_cts ( & self , state : bool ) {
282+ self . cr3 ( ) . modify ( |_, w| w. ctse ( ) . bit ( state) ) ;
283+ }
284+ }
285+
269286impl RegisterBlockImpl for RegisterBlockUsart {
270287 fn new < UART : Instance < RegisterBlock = Self > , WORD > (
271288 uart : UART ,
@@ -406,6 +423,23 @@ where {
406423 uartCommon ! { }
407424}
408425
426+ #[ cfg( feature = "uart4" ) ]
427+ #[ cfg( not( any(
428+ feature = "gpio-f413" ,
429+ feature = "gpio-f417" ,
430+ feature = "gpio-f427" ,
431+ feature = "gpio-f446" ,
432+ feature = "gpio-f469"
433+ ) ) ) ]
434+ impl RBFlowControlImpl for RegisterBlockUart {
435+ fn enable_rts ( & self , state : bool ) {
436+ self . cr3 ( ) . modify ( |_, w| w. rtse ( ) . bit ( state) ) ;
437+ }
438+ fn enable_cts ( & self , state : bool ) {
439+ self . cr3 ( ) . modify ( |_, w| w. ctse ( ) . bit ( state) ) ;
440+ }
441+ }
442+
409443#[ cfg( feature = "uart4" ) ]
410444impl RegisterBlockImpl for RegisterBlockUart {
411445 fn new < UART : Instance < RegisterBlock = Self > , WORD > (
@@ -513,6 +547,34 @@ where {
513547 uartCommon ! { }
514548}
515549
550+ impl < UART : Instance + SerialFlowControl , WORD > Serial < UART , WORD >
551+ where
552+ UART :: RegisterBlock : RBFlowControlImpl ,
553+ {
554+ pub fn with_rts ( self , rts : impl Into < UART :: Rts > ) -> Self {
555+ self . rx . usart . enable_rts ( true ) ;
556+ let _rts = rts. into ( ) ;
557+ self
558+ }
559+ pub fn with_cts ( self , cts : impl Into < UART :: Cts > ) -> Self {
560+ self . tx . usart . enable_cts ( true ) ;
561+ let _cts = cts. into ( ) ;
562+ self
563+ }
564+ pub fn enable_request_to_send ( & mut self ) {
565+ self . rx . usart . enable_rts ( true ) ;
566+ }
567+ pub fn disable_request_to_send ( & mut self ) {
568+ self . rx . usart . enable_rts ( false ) ;
569+ }
570+ pub fn enable_clear_to_send ( & mut self ) {
571+ self . tx . usart . enable_cts ( true ) ;
572+ }
573+ pub fn disable_clear_to_send ( & mut self ) {
574+ self . tx . usart . enable_cts ( false ) ;
575+ }
576+ }
577+
516578impl < UART : Instance , WORD > RxISR for Serial < UART , WORD >
517579where
518580 Rx < UART , WORD > : RxISR ,
0 commit comments