@@ -797,6 +797,26 @@ impl<SPI: Instance> Inner<SPI> {
797797 nb:: Error :: WouldBlock
798798 } )
799799 }
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+
800820 fn listen_event ( & mut self , disable : Option < BitFlags < Event > > , enable : Option < BitFlags < Event > > ) {
801821 self . spi . cr2 ( ) . modify ( |r, w| unsafe {
802822 w. bits ( {
@@ -985,35 +1005,11 @@ impl<SPI: Instance, const BIDI: bool, W: FrameSize> Spi<SPI, BIDI, W> {
9851005 }
9861006
9871007 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 ( ) )
10011009 }
10021010
10031011 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)
10171013 }
10181014
10191015 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> {
10931089 }
10941090
10951091 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 ( ) )
11091093 }
11101094
11111095 pub fn read ( & mut self , words : & mut [ W ] ) -> Result < ( ) , Error > {
0 commit comments