@@ -93,14 +93,14 @@ pub trait Instance: crate::Sealed + crate::Ptr + Enable + Reset + CommonPins {}
9393
9494/// Serial receiver
9595pub struct Rx < USART : Instance , Dma > {
96- pin : USART :: Rx < PushPull > ,
96+ pin : Option < USART :: Rx < PushPull > > ,
9797 usart : USART ,
9898 _dma : PhantomData < Dma > ,
9999}
100100
101101/// Serial transmitter
102102pub struct Tx < USART : Instance , Dma , Otype = PushPull > {
103- pin : USART :: Tx < Otype > ,
103+ pin : Option < USART :: Tx < Otype > > ,
104104 usart : USART ,
105105 _dma : PhantomData < Dma > ,
106106}
@@ -118,10 +118,16 @@ pub struct NoDMA;
118118#[ derive( Debug ) ]
119119pub struct DMA ;
120120
121+ #[ allow( non_upper_case_globals) ]
121122pub trait SerialExt < Config > : Sized + Instance {
123+ const NoTx : Option < Self :: Tx < PushPull > > = None ;
124+ const NoRx : Option < Self :: Rx < PushPull > > = None ;
122125 fn usart < Otype > (
123126 self ,
124- pins : ( impl Into < Self :: Tx < Otype > > , impl Into < Self :: Rx < PushPull > > ) ,
127+ pins : (
128+ Option < impl Into < Self :: Tx < Otype > > > ,
129+ Option < impl Into < Self :: Rx < PushPull > > > ,
130+ ) ,
125131 config : impl Into < Config > ,
126132 rcc : & mut Rcc ,
127133 ) -> Result < Serial < Self , Otype > , InvalidConfig > ;
@@ -461,15 +467,17 @@ macro_rules! uart_shared {
461467 self ,
462468 ) -> (
463469 $USARTX,
464- <$USARTX as CommonPins >:: Tx <Otype >,
465- <$USARTX as CommonPins >:: Rx <PushPull >,
470+ (
471+ Option <<$USARTX as CommonPins >:: Tx <Otype >>,
472+ Option <<$USARTX as CommonPins >:: Rx <PushPull >>,
473+ ) ,
466474 ) {
467475 // Disable the UART as well as its clock.
468476 self . tx. usart. cr1( ) . modify( |_, w| w. ue( ) . clear_bit( ) ) ;
469477 unsafe {
470478 $USARTX:: disable_unchecked( ) ;
471479 }
472- ( self . tx. usart, self . tx. pin, self . rx. pin)
480+ ( self . tx. usart, ( self . tx. pin, self . rx. pin) )
473481 }
474482 }
475483
@@ -506,7 +514,10 @@ macro_rules! uart_lp {
506514 impl SerialExt <LowPowerConfig > for $USARTX {
507515 fn usart<Otype >(
508516 self ,
509- pins: ( impl Into <Self :: Tx <Otype >>, impl Into <Self :: Rx <PushPull >>) ,
517+ pins: (
518+ Option <impl Into <Self :: Tx <Otype >>>,
519+ Option <impl Into <Self :: Rx <PushPull >>>,
520+ ) ,
510521 config: impl Into <LowPowerConfig >,
511522 rcc: & mut Rcc ,
512523 ) -> Result <Serial <Self , Otype >, InvalidConfig > {
@@ -518,8 +529,8 @@ macro_rules! uart_lp {
518529 pub fn $usartX(
519530 usart: $USARTX,
520531 pins: (
521- impl Into <<$USARTX as CommonPins >:: Tx <Otype >>,
522- impl Into <<$USARTX as CommonPins >:: Rx <PushPull >>,
532+ Option < impl Into <<$USARTX as CommonPins >:: Tx <Otype > >>,
533+ Option < impl Into <<$USARTX as CommonPins >:: Rx <PushPull > >>,
523534 ) ,
524535 config: impl Into <LowPowerConfig >,
525536 rcc: & mut Rcc ,
@@ -574,12 +585,12 @@ macro_rules! uart_lp {
574585
575586 Ok ( Serial {
576587 tx: Tx {
577- pin: pins. 0 . into ( ) ,
588+ pin: pins. 0 . map ( Into :: into ) ,
578589 usart,
579590 _dma: PhantomData ,
580591 } ,
581592 rx: Rx {
582- pin: pins. 1 . into ( ) ,
593+ pin: pins. 1 . map ( Into :: into ) ,
583594 usart: unsafe { $USARTX:: steal( ) } ,
584595 _dma: PhantomData ,
585596 } ,
@@ -631,7 +642,10 @@ macro_rules! uart_full {
631642 impl SerialExt <FullConfig > for $USARTX {
632643 fn usart<Otype >(
633644 self ,
634- pins: ( impl Into <Self :: Tx <Otype >>, impl Into <Self :: Rx <PushPull >>) ,
645+ pins: (
646+ Option <impl Into <Self :: Tx <Otype >>>,
647+ Option <impl Into <Self :: Rx <PushPull >>>,
648+ ) ,
635649 config: impl Into <FullConfig >,
636650 rcc: & mut Rcc ,
637651 ) -> Result <Serial <Self , Otype >, InvalidConfig > {
@@ -643,8 +657,8 @@ macro_rules! uart_full {
643657 pub fn $usartX(
644658 usart: $USARTX,
645659 pins: (
646- impl Into <<$USARTX as CommonPins >:: Tx <Otype >>,
647- impl Into <<$USARTX as CommonPins >:: Rx <PushPull >>,
660+ Option < impl Into <<$USARTX as CommonPins >:: Tx <Otype > >>,
661+ Option < impl Into <<$USARTX as CommonPins >:: Rx <PushPull > >>,
648662 ) ,
649663 config: impl Into <FullConfig >,
650664 rcc: & mut Rcc ,
@@ -706,12 +720,12 @@ macro_rules! uart_full {
706720
707721 Ok ( Serial {
708722 tx: Tx {
709- pin: pins. 0 . into ( ) ,
723+ pin: pins. 0 . map ( Into :: into ) ,
710724 usart,
711725 _dma: PhantomData ,
712726 } ,
713727 rx: Rx {
714- pin: pins. 1 . into ( ) ,
728+ pin: pins. 1 . map ( Into :: into ) ,
715729 usart: unsafe { $USARTX:: steal( ) } ,
716730 _dma: PhantomData ,
717731 } ,
0 commit comments