@@ -86,6 +86,11 @@ impl Event {
86
86
}
87
87
}
88
88
89
+ pub use gpio:: alt:: SerialAsync as CommonPins ;
90
+
91
+ // Implemented by all USART/UART instances
92
+ pub trait Instance : crate :: Sealed + crate :: Ptr + Enable + Reset + CommonPins { }
93
+
89
94
/// Serial receiver
90
95
pub struct Rx < USART , Pin , Dma > {
91
96
pin : Pin ,
@@ -182,6 +187,8 @@ macro_rules! uart_shared {
182
187
}
183
188
) +
184
189
190
+ impl Instance for $USARTX { }
191
+
185
192
impl <Pin , Dma > Rx <$USARTX, Pin , Dma > {
186
193
/// Starts listening for an interrupt event
187
194
pub fn listen( & mut self ) {
@@ -579,41 +586,27 @@ macro_rules! uart_lp {
579
586
usart. cr3( ) . reset( ) ;
580
587
581
588
usart. cr2( ) . write( |w| unsafe {
582
- w. stop( )
583
- . bits( config. stopbits. bits( ) )
584
- . swap( )
585
- . bit( config. swap)
589
+ w. stop( ) . bits( config. stopbits. bits( ) ) ;
590
+ w. swap( ) . bit( config. swap)
586
591
} ) ;
587
592
588
593
usart. cr3( ) . write( |w| unsafe {
589
- w. txftcfg( )
590
- . bits( config. tx_fifo_threshold. bits( ) )
591
- . rxftcfg( )
592
- . bits( config. rx_fifo_threshold. bits( ) )
593
- . txftie( )
594
- . bit( config. tx_fifo_interrupt)
595
- . rxftie( )
596
- . bit( config. rx_fifo_interrupt)
594
+ w. txftcfg( ) . bits( config. tx_fifo_threshold. bits( ) ) ;
595
+ w. rxftcfg( ) . bits( config. rx_fifo_threshold. bits( ) ) ;
596
+ w. txftie( ) . bit( config. tx_fifo_interrupt) ;
597
+ w. rxftie( ) . bit( config. rx_fifo_interrupt)
597
598
} ) ;
598
599
599
600
// Enable the UART and perform remaining configuration.
600
601
usart. cr1( ) . write( |w| {
601
- w. ue( )
602
- . set_bit( )
603
- . te( )
604
- . set_bit( )
605
- . re( )
606
- . set_bit( )
607
- . m0( )
608
- . bit( config. wordlength == WordLength :: DataBits9 )
609
- . m1( )
610
- . bit( config. wordlength == WordLength :: DataBits7 )
611
- . pce( )
612
- . bit( config. parity != Parity :: ParityNone )
613
- . ps( )
614
- . bit( config. parity == Parity :: ParityOdd )
615
- . fifoen( )
616
- . bit( config. fifo_enable)
602
+ w. ue( ) . set_bit( ) ;
603
+ w. te( ) . set_bit( ) ;
604
+ w. re( ) . set_bit( ) ;
605
+ w. m0( ) . bit( config. wordlength == WordLength :: DataBits9 ) ;
606
+ w. m1( ) . bit( config. wordlength == WordLength :: DataBits7 ) ;
607
+ w. pce( ) . bit( config. parity != Parity :: ParityNone ) ;
608
+ w. ps( ) . bit( config. parity == Parity :: ParityOdd ) ;
609
+ w. fifoen( ) . bit( config. fifo_enable)
617
610
} ) ;
618
611
619
612
Ok ( Serial {
@@ -726,10 +719,8 @@ macro_rules! uart_full {
726
719
usart. cr3( ) . reset( ) ;
727
720
728
721
usart. cr2( ) . write( |w| unsafe {
729
- w. stop( )
730
- . bits( config. stopbits. bits( ) )
731
- . swap( )
732
- . bit( config. swap)
722
+ w. stop( ) . bits( config. stopbits. bits( ) ) ;
723
+ w. swap( ) . bit( config. swap)
733
724
} ) ;
734
725
735
726
if let Some ( timeout) = config. receiver_timeout {
@@ -739,34 +730,22 @@ macro_rules! uart_full {
739
730
}
740
731
741
732
usart. cr3( ) . write( |w| unsafe {
742
- w. txftcfg( )
743
- . bits( config. tx_fifo_threshold. bits( ) )
744
- . rxftcfg( )
745
- . bits( config. rx_fifo_threshold. bits( ) )
746
- . txftie( )
747
- . bit( config. tx_fifo_interrupt)
748
- . rxftie( )
749
- . bit( config. rx_fifo_interrupt)
733
+ w. txftcfg( ) . bits( config. tx_fifo_threshold. bits( ) ) ;
734
+ w. rxftcfg( ) . bits( config. rx_fifo_threshold. bits( ) ) ;
735
+ w. txftie( ) . bit( config. tx_fifo_interrupt) ;
736
+ w. rxftie( ) . bit( config. rx_fifo_interrupt)
750
737
} ) ;
751
738
752
739
// Enable the UART and perform remaining configuration.
753
740
usart. cr1( ) . modify( |_, w| {
754
- w. ue( )
755
- . set_bit( )
756
- . te( )
757
- . set_bit( )
758
- . re( )
759
- . set_bit( )
760
- . m0( )
761
- . bit( config. wordlength == WordLength :: DataBits7 )
762
- . m1( )
763
- . bit( config. wordlength == WordLength :: DataBits9 )
764
- . pce( )
765
- . bit( config. parity != Parity :: ParityNone )
766
- . ps( )
767
- . bit( config. parity == Parity :: ParityOdd )
768
- . fifoen( )
769
- . bit( config. fifo_enable)
741
+ w. ue( ) . set_bit( ) ;
742
+ w. te( ) . set_bit( ) ;
743
+ w. re( ) . set_bit( ) ;
744
+ w. m0( ) . bit( config. wordlength == WordLength :: DataBits7 ) ;
745
+ w. m1( ) . bit( config. wordlength == WordLength :: DataBits9 ) ;
746
+ w. pce( ) . bit( config. parity != Parity :: ParityNone ) ;
747
+ w. ps( ) . bit( config. parity == Parity :: ParityOdd ) ;
748
+ w. fifoen( ) . bit( config. fifo_enable)
770
749
} ) ;
771
750
772
751
Ok ( Serial {
0 commit comments