@@ -86,6 +86,11 @@ impl Event {
8686 }
8787}
8888
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+
8994/// Serial receiver
9095pub struct Rx < USART , Pin , Dma > {
9196 pin : Pin ,
@@ -182,6 +187,8 @@ macro_rules! uart_shared {
182187 }
183188 ) +
184189
190+ impl Instance for $USARTX { }
191+
185192 impl <Pin , Dma > Rx <$USARTX, Pin , Dma > {
186193 /// Starts listening for an interrupt event
187194 pub fn listen( & mut self ) {
@@ -579,41 +586,27 @@ macro_rules! uart_lp {
579586 usart. cr3( ) . reset( ) ;
580587
581588 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)
586591 } ) ;
587592
588593 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)
597598 } ) ;
598599
599600 // Enable the UART and perform remaining configuration.
600601 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)
617610 } ) ;
618611
619612 Ok ( Serial {
@@ -726,10 +719,8 @@ macro_rules! uart_full {
726719 usart. cr3( ) . reset( ) ;
727720
728721 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)
733724 } ) ;
734725
735726 if let Some ( timeout) = config. receiver_timeout {
@@ -739,34 +730,22 @@ macro_rules! uart_full {
739730 }
740731
741732 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)
750737 } ) ;
751738
752739 // Enable the UART and perform remaining configuration.
753740 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)
770749 } ) ;
771750
772751 Ok ( Serial {
0 commit comments