@@ -660,197 +660,206 @@ pub type Tx3 = Tx<USART3>;
660
660
use crate :: dma:: { Receive , TransferPayload , Transmit } ;
661
661
662
662
macro_rules! serialdma {
663
- ( $(
664
- $USARTX: ident: (
665
- $rxdma: ident,
666
- $txdma: ident,
667
- $dmarxch: ty,
668
- $dmatxch: ty,
669
- ) ,
670
- ) +) => {
671
- $(
672
- pub type $rxdma = RxDma <Rx <$USARTX>, $dmarxch>;
673
- pub type $txdma = TxDma <Tx <$USARTX>, $dmatxch>;
663
+ (
664
+ $USARTX: ident,
665
+ $rxdma: ident,
666
+ $txdma: ident,
667
+ $dmarxch: ty,
668
+ $dmatxch: ty
669
+ ) => {
670
+ pub type $rxdma = RxDma <Rx <$USARTX>, $dmarxch>;
671
+ pub type $txdma = TxDma <Tx <$USARTX>, $dmatxch>;
672
+
673
+ impl Receive for $rxdma {
674
+ type RxChannel = $dmarxch;
675
+ type TransmittedWord = u8 ;
676
+ }
674
677
675
- impl Receive for $rxdma {
676
- type RxChannel = $dmarxch ;
677
- type TransmittedWord = u8 ;
678
- }
678
+ impl Transmit for $txdma {
679
+ type TxChannel = $dmatxch ;
680
+ type ReceivedWord = u8 ;
681
+ }
679
682
680
- impl Transmit for $txdma {
681
- type TxChannel = $dmatxch ;
682
- type ReceivedWord = u8 ;
683
+ impl TransferPayload for $rxdma {
684
+ fn start ( & mut self ) {
685
+ self . channel . start ( ) ;
683
686
}
687
+ fn stop( & mut self ) {
688
+ self . channel. stop( ) ;
689
+ }
690
+ }
684
691
685
- impl TransferPayload for $rxdma {
686
- fn start( & mut self ) {
687
- self . channel. start( ) ;
688
- }
689
- fn stop( & mut self ) {
690
- self . channel. stop( ) ;
691
- }
692
+ impl TransferPayload for $txdma {
693
+ fn start( & mut self ) {
694
+ self . channel. start( ) ;
692
695
}
696
+ fn stop( & mut self ) {
697
+ self . channel. stop( ) ;
698
+ }
699
+ }
693
700
694
- impl TransferPayload for $txdma {
695
- fn start( & mut self ) {
696
- self . channel. start( ) ;
701
+ impl Rx <$USARTX> {
702
+ pub fn with_dma( self , channel: $dmarxch) -> $rxdma {
703
+ unsafe {
704
+ ( * $USARTX:: ptr( ) ) . cr3. modify( |_, w| w. dmar( ) . set_bit( ) ) ;
697
705
}
698
- fn stop( & mut self ) {
699
- self . channel. stop( ) ;
706
+ RxDma {
707
+ payload: self ,
708
+ channel,
700
709
}
701
710
}
711
+ }
702
712
703
- impl Rx <$USARTX> {
704
- pub fn with_dma( self , channel: $dmarxch) -> $rxdma {
705
- unsafe { ( * $USARTX:: ptr( ) ) . cr3. modify( |_, w| w. dmar( ) . set_bit( ) ) ; }
706
- RxDma {
707
- payload: self ,
708
- channel,
709
- }
713
+ impl Tx <$USARTX> {
714
+ pub fn with_dma( self , channel: $dmatxch) -> $txdma {
715
+ unsafe {
716
+ ( * $USARTX:: ptr( ) ) . cr3. modify( |_, w| w. dmat( ) . set_bit( ) ) ;
710
717
}
711
- }
712
-
713
- impl Tx <$USARTX> {
714
- pub fn with_dma( self , channel: $dmatxch) -> $txdma {
715
- unsafe { ( * $USARTX:: ptr( ) ) . cr3. modify( |_, w| w. dmat( ) . set_bit( ) ) ; }
716
- TxDma {
717
- payload: self ,
718
- channel,
719
- }
718
+ TxDma {
719
+ payload: self ,
720
+ channel,
720
721
}
721
722
}
723
+ }
722
724
723
- impl $rxdma {
724
- pub fn release( mut self ) -> ( Rx <$USARTX>, $dmarxch) {
725
- self . stop( ) ;
726
- unsafe { ( * $USARTX:: ptr( ) ) . cr3. modify( |_, w| w. dmar( ) . clear_bit( ) ) ; }
727
- let RxDma { payload, channel} = self ;
728
- (
729
- payload,
730
- channel
731
- )
725
+ impl $rxdma {
726
+ pub fn release( mut self ) -> ( Rx <$USARTX>, $dmarxch) {
727
+ self . stop( ) ;
728
+ unsafe {
729
+ ( * $USARTX:: ptr( ) ) . cr3. modify( |_, w| w. dmar( ) . clear_bit( ) ) ;
732
730
}
731
+ let RxDma { payload, channel } = self ;
732
+ ( payload, channel)
733
733
}
734
+ }
734
735
735
- impl $txdma {
736
- pub fn release( mut self ) -> ( Tx <$USARTX>, $dmatxch) {
737
- self . stop( ) ;
738
- unsafe { ( * $USARTX:: ptr( ) ) . cr3. modify( |_, w| w. dmat( ) . clear_bit( ) ) ; }
739
- let TxDma { payload, channel} = self ;
740
- (
741
- payload,
742
- channel,
743
- )
736
+ impl $txdma {
737
+ pub fn release( mut self ) -> ( Tx <$USARTX>, $dmatxch) {
738
+ self . stop( ) ;
739
+ unsafe {
740
+ ( * $USARTX:: ptr( ) ) . cr3. modify( |_, w| w. dmat( ) . clear_bit( ) ) ;
744
741
}
742
+ let TxDma { payload, channel } = self ;
743
+ ( payload, channel)
745
744
}
745
+ }
746
746
747
- impl <B > crate :: dma:: CircReadDma <B , u8 > for $rxdma
748
- where
749
- & ' static mut [ B ; 2 ] : WriteBuffer <Word = u8 >,
750
- B : ' static ,
751
- {
752
- fn circ_read( mut self , mut buffer: & ' static mut [ B ; 2 ] ) -> CircBuffer <B , Self > {
753
- // NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
754
- // until the end of the transfer.
755
- let ( ptr, len) = unsafe { buffer. write_buffer( ) } ;
756
- self . channel. set_peripheral_address( unsafe { & ( * $USARTX:: ptr( ) ) . dr as * const _ as u32 } , false ) ;
757
- self . channel. set_memory_address( ptr as u32 , true ) ;
758
- self . channel. set_transfer_length( len) ;
759
-
760
- atomic:: compiler_fence( Ordering :: Release ) ;
761
-
762
- self . channel. ch( ) . cr. modify( |_, w| {
763
- w. mem2mem( ) . clear_bit( ) ;
764
- w. pl( ) . medium( ) ;
765
- w. msize( ) . bits8( ) ;
766
- w. psize( ) . bits8( ) ;
767
- w. circ( ) . set_bit( ) ;
768
- w. dir( ) . clear_bit( )
769
- } ) ;
770
-
771
- self . start( ) ;
772
-
773
- CircBuffer :: new( buffer, self )
774
- }
747
+ impl <B > crate :: dma:: CircReadDma <B , u8 > for $rxdma
748
+ where
749
+ & ' static mut [ B ; 2 ] : WriteBuffer <Word = u8 >,
750
+ B : ' static ,
751
+ {
752
+ fn circ_read( mut self , mut buffer: & ' static mut [ B ; 2 ] ) -> CircBuffer <B , Self > {
753
+ // NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
754
+ // until the end of the transfer.
755
+ let ( ptr, len) = unsafe { buffer. write_buffer( ) } ;
756
+ self . channel. set_peripheral_address(
757
+ unsafe { & ( * $USARTX:: ptr( ) ) . dr as * const _ as u32 } ,
758
+ false ,
759
+ ) ;
760
+ self . channel. set_memory_address( ptr as u32 , true ) ;
761
+ self . channel. set_transfer_length( len) ;
762
+
763
+ atomic:: compiler_fence( Ordering :: Release ) ;
764
+
765
+ self . channel. ch( ) . cr. modify( |_, w| {
766
+ w. mem2mem( ) . clear_bit( ) ;
767
+ w. pl( ) . medium( ) ;
768
+ w. msize( ) . bits8( ) ;
769
+ w. psize( ) . bits8( ) ;
770
+ w. circ( ) . set_bit( ) ;
771
+ w. dir( ) . clear_bit( )
772
+ } ) ;
773
+
774
+ self . start( ) ;
775
+
776
+ CircBuffer :: new( buffer, self )
775
777
}
778
+ }
776
779
777
- impl <B > crate :: dma:: ReadDma <B , u8 > for $rxdma
778
- where
779
- B : WriteBuffer <Word = u8 >,
780
- {
781
- fn read( mut self , mut buffer: B ) -> Transfer <W , B , Self > {
782
- // NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
783
- // until the end of the transfer.
784
- let ( ptr, len) = unsafe { buffer. write_buffer( ) } ;
785
- self . channel. set_peripheral_address( unsafe { & ( * $USARTX:: ptr( ) ) . dr as * const _ as u32 } , false ) ;
786
- self . channel. set_memory_address( ptr as u32 , true ) ;
787
- self . channel. set_transfer_length( len) ;
788
-
789
- atomic:: compiler_fence( Ordering :: Release ) ;
790
- self . channel. ch( ) . cr. modify( |_, w| {
791
- w. mem2mem( ) . clear_bit( ) ;
792
- w. pl( ) . medium( ) ;
793
- w. msize( ) . bits8( ) ;
794
- w. psize( ) . bits8( ) ;
795
- w. circ( ) . clear_bit( ) ;
796
- w. dir( ) . clear_bit( )
797
- } ) ;
798
- self . start( ) ;
799
-
800
- Transfer :: w( buffer, self )
801
- }
780
+ impl <B > crate :: dma:: ReadDma <B , u8 > for $rxdma
781
+ where
782
+ B : WriteBuffer <Word = u8 >,
783
+ {
784
+ fn read( mut self , mut buffer: B ) -> Transfer <W , B , Self > {
785
+ // NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
786
+ // until the end of the transfer.
787
+ let ( ptr, len) = unsafe { buffer. write_buffer( ) } ;
788
+ self . channel. set_peripheral_address(
789
+ unsafe { & ( * $USARTX:: ptr( ) ) . dr as * const _ as u32 } ,
790
+ false ,
791
+ ) ;
792
+ self . channel. set_memory_address( ptr as u32 , true ) ;
793
+ self . channel. set_transfer_length( len) ;
794
+
795
+ atomic:: compiler_fence( Ordering :: Release ) ;
796
+ self . channel. ch( ) . cr. modify( |_, w| {
797
+ w. mem2mem( ) . clear_bit( ) ;
798
+ w. pl( ) . medium( ) ;
799
+ w. msize( ) . bits8( ) ;
800
+ w. psize( ) . bits8( ) ;
801
+ w. circ( ) . clear_bit( ) ;
802
+ w. dir( ) . clear_bit( )
803
+ } ) ;
804
+ self . start( ) ;
805
+
806
+ Transfer :: w( buffer, self )
802
807
}
808
+ }
803
809
804
- impl <B > crate :: dma:: WriteDma <B , u8 > for $txdma
805
- where
806
- B : ReadBuffer <Word = u8 >,
807
- {
808
- fn write( mut self , buffer: B ) -> Transfer <R , B , Self > {
809
- // NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
810
- // until the end of the transfer.
811
- let ( ptr, len) = unsafe { buffer. read_buffer( ) } ;
812
-
813
- self . channel. set_peripheral_address( unsafe { & ( * $USARTX:: ptr( ) ) . dr as * const _ as u32 } , false ) ;
814
-
815
- self . channel. set_memory_address( ptr as u32 , true ) ;
816
- self . channel. set_transfer_length( len) ;
817
-
818
- atomic:: compiler_fence( Ordering :: Release ) ;
819
-
820
- self . channel. ch( ) . cr. modify( |_, w| {
821
- w. mem2mem( ) . clear_bit( ) ;
822
- w. pl( ) . medium( ) ;
823
- w. msize( ) . bits8( ) ;
824
- w. psize( ) . bits8( ) ;
825
- w. circ( ) . clear_bit( ) ;
826
- w. dir( ) . set_bit( )
827
- } ) ;
828
- self . start( ) ;
829
-
830
- Transfer :: r( buffer, self )
831
- }
810
+ impl <B > crate :: dma:: WriteDma <B , u8 > for $txdma
811
+ where
812
+ B : ReadBuffer <Word = u8 >,
813
+ {
814
+ fn write( mut self , buffer: B ) -> Transfer <R , B , Self > {
815
+ // NOTE(unsafe) We own the buffer now and we won't call other `&mut` on it
816
+ // until the end of the transfer.
817
+ let ( ptr, len) = unsafe { buffer. read_buffer( ) } ;
818
+
819
+ self . channel. set_peripheral_address(
820
+ unsafe { & ( * $USARTX:: ptr( ) ) . dr as * const _ as u32 } ,
821
+ false ,
822
+ ) ;
823
+
824
+ self . channel. set_memory_address( ptr as u32 , true ) ;
825
+ self . channel. set_transfer_length( len) ;
826
+
827
+ atomic:: compiler_fence( Ordering :: Release ) ;
828
+
829
+ self . channel. ch( ) . cr. modify( |_, w| {
830
+ w. mem2mem( ) . clear_bit( ) ;
831
+ w. pl( ) . medium( ) ;
832
+ w. msize( ) . bits8( ) ;
833
+ w. psize( ) . bits8( ) ;
834
+ w. circ( ) . clear_bit( ) ;
835
+ w. dir( ) . set_bit( )
836
+ } ) ;
837
+ self . start( ) ;
838
+
839
+ Transfer :: r( buffer, self )
832
840
}
833
- ) +
834
- }
841
+ }
842
+ } ;
835
843
}
836
844
837
845
serialdma ! {
838
- USART1 : (
839
- RxDma1 ,
840
- TxDma1 ,
841
- dma1:: C5 ,
842
- dma1:: C4 ,
843
- ) ,
844
- USART2 : (
845
- RxDma2 ,
846
- TxDma2 ,
847
- dma1:: C6 ,
848
- dma1:: C7 ,
849
- ) ,
850
- USART3 : (
851
- RxDma3 ,
852
- TxDma3 ,
853
- dma1:: C3 ,
854
- dma1:: C2 ,
855
- ) ,
846
+ USART1 ,
847
+ RxDma1 ,
848
+ TxDma1 ,
849
+ dma1:: C5 ,
850
+ dma1:: C4
851
+ }
852
+ serialdma ! {
853
+ USART2 ,
854
+ RxDma2 ,
855
+ TxDma2 ,
856
+ dma1:: C6 ,
857
+ dma1:: C7
858
+ }
859
+ serialdma ! {
860
+ USART3 ,
861
+ RxDma3 ,
862
+ TxDma3 ,
863
+ dma1:: C3 ,
864
+ dma1:: C2
856
865
}
0 commit comments