@@ -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" ) ]
@@ -266,6 +269,20 @@ macro_rules! uartCommon {
266
269
} ;
267
270
}
268
271
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
+
269
286
impl RegisterBlockImpl for RegisterBlockUsart {
270
287
fn new < UART : Instance < RegisterBlock = Self > , WORD > (
271
288
uart : UART ,
@@ -406,6 +423,23 @@ where {
406
423
uartCommon ! { }
407
424
}
408
425
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
+
409
443
#[ cfg( feature = "uart4" ) ]
410
444
impl RegisterBlockImpl for RegisterBlockUart {
411
445
fn new < UART : Instance < RegisterBlock = Self > , WORD > (
@@ -513,6 +547,34 @@ where {
513
547
uartCommon ! { }
514
548
}
515
549
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
+
516
578
impl < UART : Instance , WORD > RxISR for Serial < UART , WORD >
517
579
where
518
580
Rx < UART , WORD > : RxISR ,
0 commit comments