@@ -771,7 +771,7 @@ where
771
771
self . i2c . cr1 . modify ( |_, w| w. pe ( ) . set_bit ( ) ) ;
772
772
}
773
773
774
- fn check_and_clear_error_flags ( & self ) -> Result < ( ) , Error > {
774
+ fn check_and_clear_error_flags ( & self ) -> Result < i2c1 :: sr1 :: R , Error > {
775
775
// Note that flags should only be cleared once they have been registered. If flags are
776
776
// cleared otherwise, there may be an inherent race condition and flags may be missed.
777
777
let sr1 = self . i2c . sr1 . read ( ) ;
@@ -806,7 +806,7 @@ where
806
806
return Err ( Error :: BUS ) ;
807
807
}
808
808
809
- Ok ( ( ) )
809
+ Ok ( sr1 )
810
810
}
811
811
812
812
pub fn release ( self ) -> ( I2C , PINS ) {
@@ -831,10 +831,7 @@ where
831
831
self . i2c . cr1 . modify ( |_, w| w. start ( ) . set_bit ( ) ) ;
832
832
833
833
// Wait until START condition was generated
834
- while {
835
- self . check_and_clear_error_flags ( ) ?;
836
- self . i2c . sr1 . read ( ) . sb ( ) . bit_is_clear ( )
837
- } { }
834
+ while self . check_and_clear_error_flags ( ) ?. sb ( ) . bit_is_clear ( ) { }
838
835
839
836
// Also wait until signalled we're master and everything is waiting for us
840
837
while {
@@ -852,10 +849,10 @@ where
852
849
// Wait until address was sent
853
850
while {
854
851
// Check for any I2C errors. If a NACK occurs, the ADDR bit will never be set.
855
- self . check_and_clear_error_flags ( ) ?;
852
+ let sr1 = self . check_and_clear_error_flags ( ) ?;
856
853
857
854
// Wait for the address to be acknowledged
858
- self . i2c . sr1 . read ( ) . addr ( ) . bit_is_clear ( )
855
+ sr1. addr ( ) . bit_is_clear ( )
859
856
} { }
860
857
861
858
// Clear condition by reading SR2
@@ -874,9 +871,7 @@ where
874
871
// Wait until we're ready for sending
875
872
while {
876
873
// Check for any I2C errors. If a NACK occurs, the ADDR bit will never be set.
877
- self . check_and_clear_error_flags ( ) ?;
878
-
879
- self . i2c . sr1 . read ( ) . tx_e ( ) . bit_is_clear ( )
874
+ self . check_and_clear_error_flags ( ) ?. tx_e ( ) . bit_is_clear ( )
880
875
} { }
881
876
882
877
// Push out a byte of data
@@ -885,9 +880,7 @@ where
885
880
// Wait until byte is transferred
886
881
while {
887
882
// Check for any potential error conditions.
888
- self . check_and_clear_error_flags ( ) ?;
889
-
890
- self . i2c . sr1 . read ( ) . btf ( ) . bit_is_clear ( )
883
+ self . check_and_clear_error_flags ( ) ?. btf ( ) . bit_is_clear ( )
891
884
} { }
892
885
893
886
Ok ( ( ) )
0 commit comments