@@ -797,6 +797,26 @@ impl<SPI: Instance> Inner<SPI> {
797
797
nb:: Error :: WouldBlock
798
798
} )
799
799
}
800
+
801
+ fn spi_write < const BIDI : bool , W : FrameSize > (
802
+ & mut self ,
803
+ words : impl IntoIterator < Item = W > ,
804
+ ) -> Result < ( ) , Error > {
805
+ if BIDI {
806
+ self . bidi_output ( ) ;
807
+ for word in words. into_iter ( ) {
808
+ nb:: block!( self . check_send( word) ) ?;
809
+ }
810
+ } else {
811
+ for word in words. into_iter ( ) {
812
+ nb:: block!( self . check_send( word) ) ?;
813
+ nb:: block!( self . check_read:: <W >( ) ) ?;
814
+ }
815
+ }
816
+
817
+ Ok ( ( ) )
818
+ }
819
+
800
820
fn listen_event ( & mut self , disable : Option < BitFlags < Event > > , enable : Option < BitFlags < Event > > ) {
801
821
self . spi . cr2 ( ) . modify ( |r, w| unsafe {
802
822
w. bits ( {
@@ -985,35 +1005,11 @@ impl<SPI: Instance, const BIDI: bool, W: FrameSize> Spi<SPI, BIDI, W> {
985
1005
}
986
1006
987
1007
pub fn write ( & mut self , words : & [ W ] ) -> Result < ( ) , Error > {
988
- if BIDI {
989
- self . bidi_output ( ) ;
990
- for word in words {
991
- nb:: block!( self . check_send( * word) ) ?;
992
- }
993
- } else {
994
- for word in words {
995
- nb:: block!( self . check_send( * word) ) ?;
996
- nb:: block!( self . check_read:: <W >( ) ) ?;
997
- }
998
- }
999
-
1000
- Ok ( ( ) )
1008
+ self . spi_write :: < BIDI , W > ( words. iter ( ) . copied ( ) )
1001
1009
}
1002
1010
1003
1011
pub fn write_iter ( & mut self , words : impl IntoIterator < Item = W > ) -> Result < ( ) , Error > {
1004
- if BIDI {
1005
- self . bidi_output ( ) ;
1006
- for word in words. into_iter ( ) {
1007
- nb:: block!( self . check_send( word) ) ?;
1008
- }
1009
- } else {
1010
- for word in words. into_iter ( ) {
1011
- nb:: block!( self . check_send( word) ) ?;
1012
- nb:: block!( self . check_read:: <W >( ) ) ?;
1013
- }
1014
- }
1015
-
1016
- Ok ( ( ) )
1012
+ self . spi_write :: < BIDI , W > ( words)
1017
1013
}
1018
1014
1019
1015
pub fn read ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Error > {
@@ -1093,19 +1089,7 @@ impl<SPI: Instance, const BIDI: bool, W: FrameSize> SpiSlave<SPI, BIDI, W> {
1093
1089
}
1094
1090
1095
1091
pub fn write ( & mut self , words : & [ W ] ) -> Result < ( ) , Error > {
1096
- if BIDI {
1097
- self . bidi_output ( ) ;
1098
- for word in words {
1099
- nb:: block!( self . check_send( * word) ) ?;
1100
- }
1101
- } else {
1102
- for word in words {
1103
- nb:: block!( self . check_send( * word) ) ?;
1104
- nb:: block!( self . check_read:: <W >( ) ) ?;
1105
- }
1106
- }
1107
-
1108
- Ok ( ( ) )
1092
+ self . spi_write :: < BIDI , W > ( words. iter ( ) . copied ( ) )
1109
1093
}
1110
1094
1111
1095
pub fn read ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Error > {
0 commit comments