@@ -15,7 +15,7 @@ use stable_deref_trait::StableDeref;
15
15
use crate :: hal:: serial:: { self , Write } ;
16
16
17
17
use crate :: dma:: { dma1, CircBuffer , DMAFrame , FrameReader , FrameSender } ;
18
- use crate :: gpio:: { self , Alternate , Floating , Input } ;
18
+ use crate :: gpio:: { self , Alternate , AlternateOD , Floating , Input } ;
19
19
use crate :: pac;
20
20
use crate :: rcc:: { Clocks , APB1R1 , APB2 } ;
21
21
use crate :: time:: { Bps , U32Ext } ;
@@ -289,6 +289,11 @@ macro_rules! hal {
289
289
w. ovrdis( ) . set_bit( ) ;
290
290
}
291
291
292
+ // configure Half Duplex
293
+ if PINS :: HALF_DUPLEX {
294
+ w. hdsel( ) . set_bit( ) ;
295
+ }
296
+
292
297
w
293
298
} ) ;
294
299
@@ -777,6 +782,9 @@ where
777
782
/// Marks pins as being as being TX pins for the given USART instance
778
783
pub trait TxPin < Instance > : private:: SealedTx { }
779
784
785
+ /// Marks pins as being TX Half Duplex pins for the given USART instance
786
+ pub trait TxHalfDuplexPin < Instance > : private:: SealedTxHalfDuplex { }
787
+
780
788
/// Marks pins as being as being RX pins for the given USART instance
781
789
pub trait RxPin < Instance > : private:: SealedRx { }
782
790
@@ -810,6 +818,13 @@ macro_rules! impl_pin_traits {
810
818
gpio:: $tx<Alternate <gpio:: $af, Input <Floating >>> { }
811
819
) *
812
820
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
+
813
828
$(
814
829
impl private:: SealedRx for
815
830
gpio:: $rx<Alternate <gpio:: $af, Input <Floating >>> { }
@@ -901,6 +916,7 @@ impl_pin_traits! {
901
916
pub trait Pins < USART > {
902
917
const FLOWCTL : bool ;
903
918
const DEM : bool ;
919
+ const HALF_DUPLEX : bool ;
904
920
}
905
921
906
922
// No flow control, just Rx+Tx
@@ -911,6 +927,17 @@ where
911
927
{
912
928
const FLOWCTL : bool = false ;
913
929
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 ;
914
941
}
915
942
916
943
// Hardware flow control, Rx+Tx+Rts+Cts
@@ -923,6 +950,7 @@ where
923
950
{
924
951
const FLOWCTL : bool = true ;
925
952
const DEM : bool = false ;
953
+ const HALF_DUPLEX : bool = false ;
926
954
}
927
955
928
956
// DEM for RS485 mode
@@ -934,11 +962,13 @@ where
934
962
{
935
963
const FLOWCTL : bool = false ;
936
964
const DEM : bool = true ;
965
+ const HALF_DUPLEX : bool = false ;
937
966
}
938
967
939
968
/// Contains supertraits used to restrict which traits users can implement
940
969
mod private {
941
970
pub trait SealedTx { }
971
+ pub trait SealedTxHalfDuplex { }
942
972
pub trait SealedRx { }
943
973
pub trait SealedRtsDe { }
944
974
pub trait SealedCts { }
0 commit comments