@@ -6,12 +6,15 @@ use nb::block;
6
6
use super :: {
7
7
config, CFlag , Error , Event , Flag , Rx , RxISR , RxListen , Serial , SerialExt , Tx , TxISR , TxListen ,
8
8
} ;
9
- use crate :: dma:: {
10
- traits:: { DMASet , PeriAddress } ,
11
- MemoryToPeripheral , PeripheralToMemory ,
12
- } ;
13
- use crate :: gpio:: { alt:: SerialAsync as CommonPins , NoPin , PushPull } ;
9
+ use crate :: gpio:: { alt:: SerialAsync as CommonPins , NoPin , PushPull , SerialFlowControl } ;
14
10
use crate :: rcc:: { self , Clocks } ;
11
+ use crate :: {
12
+ dma:: {
13
+ traits:: { DMASet , PeriAddress } ,
14
+ MemoryToPeripheral , PeripheralToMemory ,
15
+ } ,
16
+ gpio:: alt:: SerialFlowControl ,
17
+ } ;
15
18
16
19
#[ cfg( feature = "uart4" ) ]
17
20
pub ( crate ) use crate :: pac:: uart4:: RegisterBlock as RegisterBlockUart ;
@@ -147,6 +150,9 @@ pub trait RegisterBlockImpl: crate::Sealed {
147
150
self . listen_event ( Some ( Event :: TxEmpty . into ( ) ) , None )
148
151
}
149
152
153
+ fn enable_rts ( & self , state : bool ) ;
154
+ fn enable_cts ( & self , state : bool ) ;
155
+
150
156
// PeriAddress
151
157
fn peri_address ( & self ) -> u32 ;
152
158
}
@@ -260,6 +266,14 @@ macro_rules! uartCommon {
260
266
} ) ;
261
267
}
262
268
269
+ fn enable_rts( & self , state: bool ) {
270
+ self . cr3( ) . modify( |_, w| w. rtse( ) . bit( state) ) ;
271
+ }
272
+
273
+ fn enable_cts( & self , state: bool ) {
274
+ self . cr3( ) . modify( |_, w| w. ctse( ) . bit( state) ) ;
275
+ }
276
+
263
277
fn peri_address( & self ) -> u32 {
264
278
self . dr( ) . as_ptr( ) as u32
265
279
}
@@ -513,6 +527,31 @@ where {
513
527
uartCommon ! { }
514
528
}
515
529
530
+ impl < UART : Instance + SerialFlowControl , WORD > Serial < UART , WORD > {
531
+ pub fn with_rts ( self , rts : impl Into < UART :: Rts > ) -> Self {
532
+ self . rx . usart . enable_rts ( true ) ;
533
+ let _rts = rts. into ( ) ;
534
+ self
535
+ }
536
+ pub fn with_cts ( self , cts : impl Into < UART :: Cts > ) -> Self {
537
+ self . tx . usart . enable_cts ( true ) ;
538
+ let _cts = cts. into ( ) ;
539
+ self
540
+ }
541
+ pub fn enable_request_to_send ( & mut self ) {
542
+ self . rx . usart . enable_rts ( true ) ;
543
+ }
544
+ pub fn disable_request_to_send ( & mut self ) {
545
+ self . rx . usart . enable_rts ( false ) ;
546
+ }
547
+ pub fn enable_clear_to_send ( & mut self ) {
548
+ self . tx . usart . enable_cts ( true ) ;
549
+ }
550
+ pub fn disable_clear_to_send ( & mut self ) {
551
+ self . tx . usart . enable_cts ( false ) ;
552
+ }
553
+ }
554
+
516
555
impl < UART : Instance , WORD > RxISR for Serial < UART , WORD >
517
556
where
518
557
Rx < UART , WORD > : RxISR ,
0 commit comments