@@ -48,7 +48,8 @@ static void ss_i2c_err(uint32_t dev_id)
4848 i2c_err_source = dev_id ;
4949}
5050
51- static int wait_rx_or_err (bool no_stop ){
51+ static int wait_rx_or_err ()
52+ {
5253 uint64_t timeout = TIMEOUT_MS * 200 ;
5354 while (timeout -- ) {
5455 if (i2c_err_detect ) {
@@ -65,20 +66,17 @@ static int wait_rx_or_err(bool no_stop){
6566 return I2C_ERROR_OTHER ; // other error
6667 }
6768 }
68- if (!no_stop ) {
69- if (i2c_rx_complete ) {
70- return I2C_OK ;
71- }
69+ if (i2c_rx_complete ) {
70+ return I2C_OK ;
7271 }
7372 delayMicroseconds (10 );
7473 }
75- if (!no_stop )
76- return I2C_TIMEOUT ;
77- else
78- return I2C_OK ;
74+
75+ return I2C_TIMEOUT ;
7976}
8077
81- static int wait_tx_or_err (bool no_stop ){
78+ static int wait_tx_or_err ()
79+ {
8280 uint64_t timeout = TIMEOUT_MS * 200 ;
8381 while (timeout -- ) {
8482 if (i2c_err_detect ) {
@@ -95,17 +93,12 @@ static int wait_tx_or_err(bool no_stop){
9593 return I2C_ERROR_OTHER ; // other error
9694 }
9795 }
98- if (!no_stop ) {
99- if (i2c_tx_complete ) {
96+ if (i2c_tx_complete ) {
10097 return I2C_OK ;
101- }
10298 }
10399 delayMicroseconds (10 );
104100 }
105- if (!no_stop )
106- return I2C_TIMEOUT ;
107- else
108- return I2C_OK ;
101+ return I2C_TIMEOUT ;
109102}
110103
111104static int wait_dev_ready (I2C_CONTROLLER controller_id , bool no_stop ){
@@ -116,9 +109,13 @@ static int wait_dev_ready(I2C_CONTROLLER controller_id, bool no_stop){
116109 if (ret == I2C_OK ) {
117110 return I2C_OK ;
118111 }
119- if (ret == I2C_BUSY ) {
112+ else if (ret == I2C_BUSY ) {
120113 delayMicroseconds (10 );
121114 }
115+ else
116+ {
117+ return I2C_TIMEOUT - ret ;
118+ }
122119 }
123120 return I2C_TIMEOUT - ret ;
124121}
@@ -202,7 +199,7 @@ int i2c_writebytes(uint8_t *bytes, uint8_t length, bool no_stop)
202199 i2c_err_detect = 0 ;
203200 i2c_err_source = 0 ;
204201 ss_i2c_transfer (I2C_SENSING_0 , bytes , length , 0 , 0 , i2c_slave , no_stop );
205- ret = wait_tx_or_err (no_stop );
202+ ret = wait_tx_or_err ();
206203 if (ret )
207204 return ret ;
208205 ret = wait_dev_ready (I2C_SENSING_0 , no_stop );
@@ -219,7 +216,7 @@ int i2c_readbytes(uint8_t *buf, int length, bool no_stop)
219216 i2c_err_detect = 0 ;
220217 i2c_err_source = 0 ;
221218 ss_i2c_transfer (I2C_SENSING_0 , 0 , 0 , buf , length , i2c_slave , no_stop );
222- ret = wait_rx_or_err (no_stop );
219+ ret = wait_rx_or_err ();
223220 if (ret )
224221 return ret ;
225222 ret = wait_dev_ready (I2C_SENSING_0 , no_stop );
0 commit comments