@@ -950,11 +950,31 @@ impl<SPI: Instance, const BIDI: bool, W: FrameSize> Spi<SPI, BIDI, W> {
950
950
}
951
951
952
952
pub fn transfer ( & mut self , buff : & mut [ W ] , data : & [ W ] ) -> Result < ( ) , Error > {
953
- assert_eq ! ( data. len( ) , buff. len( ) ) ;
954
-
955
- for ( d, b) in data. iter ( ) . cloned ( ) . zip ( buff. iter_mut ( ) ) {
956
- nb:: block!( self . write_nonblocking( d) ) ?;
957
- * b = nb:: block!( self . read_nonblocking( ) ) ?;
953
+ if data. len ( ) == buff. len ( ) {
954
+ for ( d, b) in data. iter ( ) . cloned ( ) . zip ( buff. iter_mut ( ) ) {
955
+ nb:: block!( self . write_nonblocking( d) ) ?;
956
+ * b = nb:: block!( self . read_nonblocking( ) ) ?;
957
+ }
958
+ } else {
959
+ let mut iter_r = buff. iter_mut ( ) ;
960
+ let mut iter_w = data. iter ( ) . cloned ( ) ;
961
+ loop {
962
+ match ( iter_r. next ( ) , iter_w. next ( ) ) {
963
+ ( Some ( r) , Some ( w) ) => {
964
+ nb:: block!( self . write_nonblocking( w) ) ?;
965
+ * r = nb:: block!( self . read_nonblocking( ) ) ?;
966
+ }
967
+ ( Some ( r) , None ) => {
968
+ nb:: block!( self . write_nonblocking( W :: default ( ) ) ) ?;
969
+ * r = nb:: block!( self . read_nonblocking( ) ) ?;
970
+ }
971
+ ( None , Some ( w) ) => {
972
+ nb:: block!( self . write_nonblocking( w) ) ?;
973
+ let _ = nb:: block!( self . read_nonblocking( ) ) ?;
974
+ }
975
+ ( None , None ) => break ,
976
+ }
977
+ }
958
978
}
959
979
960
980
Ok ( ( ) )
@@ -1038,11 +1058,31 @@ impl<SPI: Instance, const BIDI: bool, W: FrameSize> SpiSlave<SPI, BIDI, W> {
1038
1058
}
1039
1059
1040
1060
pub fn transfer ( & mut self , buff : & mut [ W ] , data : & [ W ] ) -> Result < ( ) , Error > {
1041
- assert_eq ! ( data. len( ) , buff. len( ) ) ;
1042
-
1043
- for ( d, b) in data. iter ( ) . cloned ( ) . zip ( buff. iter_mut ( ) ) {
1044
- nb:: block!( self . write_nonblocking( d) ) ?;
1045
- * b = nb:: block!( self . read_nonblocking( ) ) ?;
1061
+ if data. len ( ) == buff. len ( ) {
1062
+ for ( d, b) in data. iter ( ) . cloned ( ) . zip ( buff. iter_mut ( ) ) {
1063
+ nb:: block!( self . write_nonblocking( d) ) ?;
1064
+ * b = nb:: block!( self . read_nonblocking( ) ) ?;
1065
+ }
1066
+ } else {
1067
+ let mut iter_r = buff. iter_mut ( ) ;
1068
+ let mut iter_w = data. iter ( ) . cloned ( ) ;
1069
+ loop {
1070
+ match ( iter_r. next ( ) , iter_w. next ( ) ) {
1071
+ ( Some ( r) , Some ( w) ) => {
1072
+ nb:: block!( self . write_nonblocking( w) ) ?;
1073
+ * r = nb:: block!( self . read_nonblocking( ) ) ?;
1074
+ }
1075
+ ( Some ( r) , None ) => {
1076
+ nb:: block!( self . write_nonblocking( W :: default ( ) ) ) ?;
1077
+ * r = nb:: block!( self . read_nonblocking( ) ) ?;
1078
+ }
1079
+ ( None , Some ( w) ) => {
1080
+ nb:: block!( self . write_nonblocking( w) ) ?;
1081
+ let _ = nb:: block!( self . read_nonblocking( ) ) ?;
1082
+ }
1083
+ ( None , None ) => break ,
1084
+ }
1085
+ }
1046
1086
}
1047
1087
1048
1088
Ok ( ( ) )
0 commit comments