@@ -15,7 +15,7 @@ use stable_deref_trait::StableDeref;
1515use crate :: hal:: serial:: { self , Write } ;
1616
1717use crate :: dma:: { dma1, CircBuffer , DMAFrame , FrameReader , FrameSender } ;
18- use crate :: gpio:: { self , Alternate , Floating , Input } ;
18+ use crate :: gpio:: { self , Alternate , AlternateOD , Floating , Input } ;
1919use crate :: pac;
2020use crate :: rcc:: { Clocks , APB1R1 , APB2 } ;
2121use crate :: time:: { Bps , U32Ext } ;
@@ -289,6 +289,11 @@ macro_rules! hal {
289289 w. ovrdis( ) . set_bit( ) ;
290290 }
291291
292+ // configure Half Duplex
293+ if PINS :: HALF_DUPLEX {
294+ w. hdsel( ) . set_bit( ) ;
295+ }
296+
292297 w
293298 } ) ;
294299
@@ -777,6 +782,9 @@ where
777782/// Marks pins as being as being TX pins for the given USART instance
778783pub trait TxPin < Instance > : private:: SealedTx { }
779784
785+ /// Marks pins as being TX Half Duplex pins for the given USART instance
786+ pub trait TxHalfDuplexPin < Instance > : private:: SealedTxHalfDuplex { }
787+
780788/// Marks pins as being as being RX pins for the given USART instance
781789pub trait RxPin < Instance > : private:: SealedRx { }
782790
@@ -810,6 +818,13 @@ macro_rules! impl_pin_traits {
810818 gpio:: $tx<Alternate <gpio:: $af, Input <Floating >>> { }
811819 ) *
812820
821+ $(
822+ impl private:: SealedTxHalfDuplex for
823+ gpio:: $tx<AlternateOD <gpio:: $af, Input <Floating >>> { }
824+ impl TxHalfDuplexPin <pac:: $instance> for
825+ gpio:: $tx<AlternateOD <gpio:: $af, Input <Floating >>> { }
826+ ) *
827+
813828 $(
814829 impl private:: SealedRx for
815830 gpio:: $rx<Alternate <gpio:: $af, Input <Floating >>> { }
@@ -901,6 +916,7 @@ impl_pin_traits! {
901916pub trait Pins < USART > {
902917 const FLOWCTL : bool ;
903918 const DEM : bool ;
919+ const HALF_DUPLEX : bool ;
904920}
905921
906922// No flow control, just Rx+Tx
@@ -911,6 +927,17 @@ where
911927{
912928 const FLOWCTL : bool = false ;
913929 const DEM : bool = false ;
930+ const HALF_DUPLEX : bool = false ;
931+ }
932+
933+ // No flow control Half_duplex, just Tx
934+ impl < Instance , Tx > Pins < Instance > for ( Tx , )
935+ where
936+ Tx : TxHalfDuplexPin < Instance > ,
937+ {
938+ const FLOWCTL : bool = false ;
939+ const DEM : bool = false ;
940+ const HALF_DUPLEX : bool = true ;
914941}
915942
916943// Hardware flow control, Rx+Tx+Rts+Cts
@@ -923,6 +950,7 @@ where
923950{
924951 const FLOWCTL : bool = true ;
925952 const DEM : bool = false ;
953+ const HALF_DUPLEX : bool = false ;
926954}
927955
928956// DEM for RS485 mode
@@ -934,11 +962,13 @@ where
934962{
935963 const FLOWCTL : bool = false ;
936964 const DEM : bool = true ;
965+ const HALF_DUPLEX : bool = false ;
937966}
938967
939968/// Contains supertraits used to restrict which traits users can implement
940969mod private {
941970 pub trait SealedTx { }
971+ pub trait SealedTxHalfDuplex { }
942972 pub trait SealedRx { }
943973 pub trait SealedRtsDe { }
944974 pub trait SealedCts { }
0 commit comments