@@ -93,14 +93,14 @@ pub trait Instance: crate::Sealed + crate::Ptr + Enable + Reset + CommonPins {}
93
93
94
94
/// Serial receiver
95
95
pub struct Rx < USART : Instance , Dma > {
96
- pin : USART :: Rx < PushPull > ,
96
+ pin : Option < USART :: Rx < PushPull > > ,
97
97
usart : USART ,
98
98
_dma : PhantomData < Dma > ,
99
99
}
100
100
101
101
/// Serial transmitter
102
102
pub struct Tx < USART : Instance , Dma , Otype = PushPull > {
103
- pin : USART :: Tx < Otype > ,
103
+ pin : Option < USART :: Tx < Otype > > ,
104
104
usart : USART ,
105
105
_dma : PhantomData < Dma > ,
106
106
}
@@ -118,10 +118,16 @@ pub struct NoDMA;
118
118
#[ derive( Debug ) ]
119
119
pub struct DMA ;
120
120
121
+ #[ allow( non_upper_case_globals) ]
121
122
pub trait SerialExt < Config > : Sized + Instance {
123
+ const NoTx : Option < Self :: Tx < PushPull > > = None ;
124
+ const NoRx : Option < Self :: Rx < PushPull > > = None ;
122
125
fn usart < Otype > (
123
126
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
+ ) ,
125
131
config : impl Into < Config > ,
126
132
rcc : & mut Rcc ,
127
133
) -> Result < Serial < Self , Otype > , InvalidConfig > ;
@@ -461,15 +467,17 @@ macro_rules! uart_shared {
461
467
self ,
462
468
) -> (
463
469
$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
+ ) ,
466
474
) {
467
475
// Disable the UART as well as its clock.
468
476
self . tx. usart. cr1( ) . modify( |_, w| w. ue( ) . clear_bit( ) ) ;
469
477
unsafe {
470
478
$USARTX:: disable_unchecked( ) ;
471
479
}
472
- ( self . tx. usart, self . tx. pin, self . rx. pin)
480
+ ( self . tx. usart, ( self . tx. pin, self . rx. pin) )
473
481
}
474
482
}
475
483
@@ -506,7 +514,10 @@ macro_rules! uart_lp {
506
514
impl SerialExt <LowPowerConfig > for $USARTX {
507
515
fn usart<Otype >(
508
516
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
+ ) ,
510
521
config: impl Into <LowPowerConfig >,
511
522
rcc: & mut Rcc ,
512
523
) -> Result <Serial <Self , Otype >, InvalidConfig > {
@@ -518,8 +529,8 @@ macro_rules! uart_lp {
518
529
pub fn $usartX(
519
530
usart: $USARTX,
520
531
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 > >>,
523
534
) ,
524
535
config: impl Into <LowPowerConfig >,
525
536
rcc: & mut Rcc ,
@@ -574,12 +585,12 @@ macro_rules! uart_lp {
574
585
575
586
Ok ( Serial {
576
587
tx: Tx {
577
- pin: pins. 0 . into ( ) ,
588
+ pin: pins. 0 . map ( Into :: into ) ,
578
589
usart,
579
590
_dma: PhantomData ,
580
591
} ,
581
592
rx: Rx {
582
- pin: pins. 1 . into ( ) ,
593
+ pin: pins. 1 . map ( Into :: into ) ,
583
594
usart: unsafe { $USARTX:: steal( ) } ,
584
595
_dma: PhantomData ,
585
596
} ,
@@ -631,7 +642,10 @@ macro_rules! uart_full {
631
642
impl SerialExt <FullConfig > for $USARTX {
632
643
fn usart<Otype >(
633
644
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
+ ) ,
635
649
config: impl Into <FullConfig >,
636
650
rcc: & mut Rcc ,
637
651
) -> Result <Serial <Self , Otype >, InvalidConfig > {
@@ -643,8 +657,8 @@ macro_rules! uart_full {
643
657
pub fn $usartX(
644
658
usart: $USARTX,
645
659
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 > >>,
648
662
) ,
649
663
config: impl Into <FullConfig >,
650
664
rcc: & mut Rcc ,
@@ -706,12 +720,12 @@ macro_rules! uart_full {
706
720
707
721
Ok ( Serial {
708
722
tx: Tx {
709
- pin: pins. 0 . into ( ) ,
723
+ pin: pins. 0 . map ( Into :: into ) ,
710
724
usart,
711
725
_dma: PhantomData ,
712
726
} ,
713
727
rx: Rx {
714
- pin: pins. 1 . into ( ) ,
728
+ pin: pins. 1 . map ( Into :: into ) ,
715
729
usart: unsafe { $USARTX:: steal( ) } ,
716
730
_dma: PhantomData ,
717
731
} ,
0 commit comments