@@ -10,7 +10,10 @@ use crate::dma::{
10
10
traits:: { DMASet , PeriAddress } ,
11
11
MemoryToPeripheral , PeripheralToMemory ,
12
12
} ;
13
- use crate :: gpio:: { alt:: SerialAsync as CommonPins , NoPin , PushPull } ;
13
+ use crate :: gpio:: {
14
+ alt:: { SerialAsync as CommonPins , SerialFlowControl } ,
15
+ NoPin , PushPull ,
16
+ } ;
14
17
use crate :: rcc:: { self , Clocks } ;
15
18
16
19
#[ cfg( feature = "uart4" ) ]
@@ -262,6 +265,20 @@ macro_rules! uartCommon {
262
265
} ;
263
266
}
264
267
268
+ pub trait RBFlowControlImpl {
269
+ fn enable_rts ( & self , state : bool ) ;
270
+ fn enable_cts ( & self , state : bool ) ;
271
+ }
272
+
273
+ impl RBFlowControlImpl for RegisterBlockUsart {
274
+ fn enable_rts ( & self , state : bool ) {
275
+ self . cr3 ( ) . modify ( |_, w| w. rtse ( ) . bit ( state) ) ;
276
+ }
277
+ fn enable_cts ( & self , state : bool ) {
278
+ self . cr3 ( ) . modify ( |_, w| w. ctse ( ) . bit ( state) ) ;
279
+ }
280
+ }
281
+
265
282
impl RegisterBlockImpl for RegisterBlockUsart {
266
283
fn new < UART : Instance + crate :: Ptr < RB = Self > , WORD > (
267
284
uart : UART ,
@@ -402,6 +419,23 @@ where {
402
419
uartCommon ! { }
403
420
}
404
421
422
+ #[ cfg( feature = "uart4" ) ]
423
+ #[ cfg( not( any(
424
+ feature = "gpio-f413" ,
425
+ feature = "gpio-f417" ,
426
+ feature = "gpio-f427" ,
427
+ feature = "gpio-f446" ,
428
+ feature = "gpio-f469"
429
+ ) ) ) ]
430
+ impl RBFlowControlImpl for RegisterBlockUart {
431
+ fn enable_rts ( & self , state : bool ) {
432
+ self . cr3 ( ) . modify ( |_, w| w. rtse ( ) . bit ( state) ) ;
433
+ }
434
+ fn enable_cts ( & self , state : bool ) {
435
+ self . cr3 ( ) . modify ( |_, w| w. ctse ( ) . bit ( state) ) ;
436
+ }
437
+ }
438
+
405
439
#[ cfg( feature = "uart4" ) ]
406
440
impl RegisterBlockImpl for RegisterBlockUart {
407
441
fn new < UART : Instance + crate :: Ptr < RB = Self > , WORD > (
@@ -509,6 +543,34 @@ where {
509
543
uartCommon ! { }
510
544
}
511
545
546
+ impl < UART : Instance + SerialFlowControl , WORD > Serial < UART , WORD >
547
+ where
548
+ UART :: RegisterBlock : RBFlowControlImpl ,
549
+ {
550
+ pub fn with_rts ( self , rts : impl Into < UART :: Rts > ) -> Self {
551
+ self . rx . usart . enable_rts ( true ) ;
552
+ let _rts = rts. into ( ) ;
553
+ self
554
+ }
555
+ pub fn with_cts ( self , cts : impl Into < UART :: Cts > ) -> Self {
556
+ self . tx . usart . enable_cts ( true ) ;
557
+ let _cts = cts. into ( ) ;
558
+ self
559
+ }
560
+ pub fn enable_request_to_send ( & mut self ) {
561
+ self . rx . usart . enable_rts ( true ) ;
562
+ }
563
+ pub fn disable_request_to_send ( & mut self ) {
564
+ self . rx . usart . enable_rts ( false ) ;
565
+ }
566
+ pub fn enable_clear_to_send ( & mut self ) {
567
+ self . tx . usart . enable_cts ( true ) ;
568
+ }
569
+ pub fn disable_clear_to_send ( & mut self ) {
570
+ self . tx . usart . enable_cts ( false ) ;
571
+ }
572
+ }
573
+
512
574
impl < UART : Instance , WORD > RxISR for Serial < UART , WORD >
513
575
where
514
576
Rx < UART , WORD > : RxISR ,
0 commit comments