@@ -48,7 +48,8 @@ static void ss_i2c_err(uint32_t dev_id)
48
48
i2c_err_source = dev_id ;
49
49
}
50
50
51
- static int wait_rx_or_err (bool no_stop ){
51
+ static int wait_rx_or_err ()
52
+ {
52
53
uint64_t timeout = TIMEOUT_MS * 200 ;
53
54
while (timeout -- ) {
54
55
if (i2c_err_detect ) {
@@ -65,20 +66,17 @@ static int wait_rx_or_err(bool no_stop){
65
66
return I2C_ERROR_OTHER ; // other error
66
67
}
67
68
}
68
- if (!no_stop ) {
69
- if (i2c_rx_complete ) {
70
- return I2C_OK ;
71
- }
69
+ if (i2c_rx_complete ) {
70
+ return I2C_OK ;
72
71
}
73
72
delayMicroseconds (10 );
74
73
}
75
- if (!no_stop )
76
- return I2C_TIMEOUT ;
77
- else
78
- return I2C_OK ;
74
+
75
+ return I2C_TIMEOUT ;
79
76
}
80
77
81
- static int wait_tx_or_err (bool no_stop ){
78
+ static int wait_tx_or_err ()
79
+ {
82
80
uint64_t timeout = TIMEOUT_MS * 200 ;
83
81
while (timeout -- ) {
84
82
if (i2c_err_detect ) {
@@ -95,17 +93,12 @@ static int wait_tx_or_err(bool no_stop){
95
93
return I2C_ERROR_OTHER ; // other error
96
94
}
97
95
}
98
- if (!no_stop ) {
99
- if (i2c_tx_complete ) {
96
+ if (i2c_tx_complete ) {
100
97
return I2C_OK ;
101
- }
102
98
}
103
99
delayMicroseconds (10 );
104
100
}
105
- if (!no_stop )
106
- return I2C_TIMEOUT ;
107
- else
108
- return I2C_OK ;
101
+ return I2C_TIMEOUT ;
109
102
}
110
103
111
104
static 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){
116
109
if (ret == I2C_OK ) {
117
110
return I2C_OK ;
118
111
}
119
- if (ret == I2C_BUSY ) {
112
+ else if (ret == I2C_BUSY ) {
120
113
delayMicroseconds (10 );
121
114
}
115
+ else
116
+ {
117
+ return I2C_TIMEOUT - ret ;
118
+ }
122
119
}
123
120
return I2C_TIMEOUT - ret ;
124
121
}
@@ -202,7 +199,7 @@ int i2c_writebytes(uint8_t *bytes, uint8_t length, bool no_stop)
202
199
i2c_err_detect = 0 ;
203
200
i2c_err_source = 0 ;
204
201
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 ();
206
203
if (ret )
207
204
return ret ;
208
205
ret = wait_dev_ready (I2C_SENSING_0 , no_stop );
@@ -219,7 +216,7 @@ int i2c_readbytes(uint8_t *buf, int length, bool no_stop)
219
216
i2c_err_detect = 0 ;
220
217
i2c_err_source = 0 ;
221
218
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 ();
223
220
if (ret )
224
221
return ret ;
225
222
ret = wait_dev_ready (I2C_SENSING_0 , no_stop );
0 commit comments