Skip to content

Commit 8682149

Browse files
bigdinotechcalvinatintel
authored andcommitted
reduce i2c delays
-reduce i2c delays to increase performace without changing the timeout threshold
1 parent de0650c commit 8682149

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

cores/arduino/i2c.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void ss_i2c_err(uint32_t dev_id)
4949
}
5050

5151
static int wait_rx_or_err(bool no_stop){
52-
uint64_t timeout = TIMEOUT_MS;
52+
uint64_t timeout = TIMEOUT_MS * 20;
5353
while(timeout--) {
5454
if (i2c_err_detect) {
5555
if (i2c_err_source & I2C_ABRT_7B_ADDR_NOACK )
@@ -70,7 +70,7 @@ static int wait_rx_or_err(bool no_stop){
7070
return I2C_OK;
7171
}
7272
}
73-
delay(1);
73+
delayMicroseconds(50);
7474
}
7575
if (!no_stop)
7676
return I2C_TIMEOUT;
@@ -79,7 +79,7 @@ static int wait_rx_or_err(bool no_stop){
7979
}
8080

8181
static int wait_tx_or_err(bool no_stop){
82-
uint64_t timeout = TIMEOUT_MS;
82+
uint64_t timeout = TIMEOUT_MS * 20;
8383
while(timeout--) {
8484
if (i2c_err_detect) {
8585
if (i2c_err_source & I2C_ABRT_7B_ADDR_NOACK )
@@ -100,7 +100,7 @@ static int wait_tx_or_err(bool no_stop){
100100
return I2C_OK;
101101
}
102102
}
103-
delay(1);
103+
delayMicroseconds(50);
104104
}
105105
if (!no_stop)
106106
return I2C_TIMEOUT;
@@ -109,15 +109,15 @@ static int wait_tx_or_err(bool no_stop){
109109
}
110110

111111
static int wait_dev_ready(I2C_CONTROLLER controller_id, bool no_stop){
112-
uint64_t timeout = TIMEOUT_MS;
112+
uint64_t timeout = TIMEOUT_MS * 20;
113113
int ret = 0;
114114
while(timeout--) {
115115
ret = ss_i2c_status(controller_id, no_stop);
116116
if (ret == I2C_OK) {
117117
return I2C_OK;
118118
}
119119
if (ret == I2C_BUSY) {
120-
delay(1);
120+
delayMicroseconds(50);
121121
}
122122
}
123123
return I2C_TIMEOUT - ret;

0 commit comments

Comments
 (0)