@@ -117,6 +117,8 @@ pub enum CFlag {
117117 TransmissionComplete = 1 << 6 ,
118118 /// LIN break detection flag
119119 LinBreak = 1 << 8 ,
120+ /// Clear to send flag
121+ Cts = 1 << 9 ,
120122}
121123
122124pub mod config;
@@ -128,7 +130,7 @@ pub use gpio::NoPin as NoTx;
128130/// A filler type for when the Rx pin is unnecessary
129131pub use gpio:: NoPin as NoRx ;
130132
131- pub use gpio:: alt:: SerialAsync as CommonPins ;
133+ pub use gpio:: alt:: { SerialAsync as CommonPins , SerialFlowControl } ;
132134
133135// Implemented by all USART/UART instances
134136pub trait Instance :
@@ -533,6 +535,75 @@ impl<UART: Instance> Serial<UART, u16> {
533535 }
534536}
535537
538+ pub trait InstanceFC : Instance < RB = pac:: usart1:: RegisterBlock > + SerialFlowControl { }
539+ impl InstanceFC for pac:: USART1 { }
540+ impl InstanceFC for pac:: USART2 { }
541+ #[ cfg( any(
542+ feature = "gpio-f412" ,
543+ feature = "gpio-f413" ,
544+ feature = "gpio-f417" ,
545+ feature = "gpio-f427" ,
546+ feature = "gpio-f446" ,
547+ feature = "gpio-f469"
548+ ) ) ]
549+ impl InstanceFC for pac:: USART6 { }
550+
551+ impl < UART : InstanceFC , WORD > Serial < UART , WORD > {
552+ pub fn with_rts ( self , rts : impl Into < UART :: Rts > ) -> Self {
553+ self . rx . usart . cr3 ( ) . modify ( |_, w| w. rtse ( ) . set_bit ( ) ) ;
554+ let _rts = rts. into ( ) ;
555+ self
556+ }
557+ pub fn with_cts ( self , cts : impl Into < UART :: Cts > ) -> Self {
558+ self . tx . usart . cr3 ( ) . modify ( |_, w| w. ctse ( ) . set_bit ( ) ) ;
559+ let _cts = cts. into ( ) ;
560+ self
561+ }
562+ }
563+ impl < UART : InstanceFC , WORD > Serial < UART , WORD > {
564+ pub fn enable_request_to_send ( & mut self ) {
565+ self . rx . enable_request_to_send ( ) ;
566+ }
567+ pub fn disable_request_to_send ( & mut self ) {
568+ self . rx . disable_request_to_send ( ) ;
569+ }
570+ pub fn enable_clear_to_send ( & mut self ) {
571+ self . tx . enable_clear_to_send ( ) ;
572+ }
573+ pub fn disable_clear_to_send ( & mut self ) {
574+ self . tx . disable_clear_to_send ( ) ;
575+ }
576+ pub fn listen_clear_to_send ( & mut self ) {
577+ self . tx . listen_clear_to_send ( ) ;
578+ }
579+ pub fn unlisten_clear_to_send ( & mut self ) {
580+ self . tx . unlisten_clear_to_send ( ) ;
581+ }
582+ }
583+ impl < UART : InstanceFC , WORD > Rx < UART , WORD > {
584+ pub fn enable_request_to_send ( & mut self ) {
585+ self . usart . cr3 ( ) . modify ( |_, w| w. rtse ( ) . set_bit ( ) ) ;
586+ }
587+ pub fn disable_request_to_send ( & mut self ) {
588+ self . usart . cr3 ( ) . modify ( |_, w| w. rtse ( ) . clear_bit ( ) ) ;
589+ }
590+ }
591+ impl < UART : InstanceFC , WORD > Tx < UART , WORD > {
592+ pub fn enable_clear_to_send ( & mut self ) {
593+ self . usart . cr3 ( ) . modify ( |_, w| w. ctse ( ) . set_bit ( ) ) ;
594+ }
595+ pub fn disable_clear_to_send ( & mut self ) {
596+ self . usart . cr3 ( ) . modify ( |_, w| w. ctse ( ) . clear_bit ( ) ) ;
597+ }
598+ fn listen_clear_to_send ( & mut self ) {
599+ self . usart . cr3 ( ) . modify ( |_, w| w. ctsie ( ) . set_bit ( ) ) ;
600+ }
601+
602+ fn unlisten_clear_to_send ( & mut self ) {
603+ self . usart . cr3 ( ) . modify ( |_, w| w. ctsie ( ) . clear_bit ( ) ) ;
604+ }
605+ }
606+
536607impl < UART : Instance , WORD > RxISR for Serial < UART , WORD >
537608where
538609 Rx < UART , WORD > : RxISR ,
0 commit comments