Skip to content

Commit 7a5325d

Browse files
authored
Fixed a bug in timeout logic where millis() was used instead of micros()
1 parent 4be1689 commit 7a5325d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libraries/Wire/Wire.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ uint8_t TwoWire::read_from(uint8_t address, uint8_t* data, uint8_t length, uint3
489489
}
490490

491491
uint32_t const start = micros();
492-
while (((timeout_us == 0ul) || ((millis() - start) < timeout_us)) &&
492+
while (((timeout_us == 0ul) || ((micros() - start) < timeout_us)) &&
493493
bus_status == WIRE_STATUS_UNSET && err == FSP_SUCCESS) {
494494
}
495495
if ((err == FSP_SUCCESS) && (bus_status == WIRE_STATUS_UNSET)) {
@@ -522,7 +522,7 @@ uint8_t TwoWire::write_to(uint8_t address, uint8_t* data, uint8_t length, uint32
522522
}
523523

524524
uint32_t const start = micros();
525-
while (((timeout_us == 0ul) || ((millis() - start) < timeout_us)) &&
525+
while (((timeout_us == 0ul) || ((micros() - start) < timeout_us)) &&
526526
bus_status == WIRE_STATUS_UNSET && err == FSP_SUCCESS) {
527527
}
528528

@@ -680,6 +680,7 @@ void TwoWire::clearWireTimeoutFlag(void){
680680
void TwoWire::handleTimeout(bool reset){
681681
/* -------------------------------------------------------------------------- */
682682
timed_out_flag = true;
683+
683684
if (reset) { //TBD; What do we do here? like fixHungWire()?
684685
// TBD, Is this the way to go to reset the bus?
685686
// Do we need more to handle devices that hangs the bus?
@@ -689,15 +690,18 @@ void TwoWire::handleTimeout(bool reset){
689690
}
690691
// TDB, Is this the right way to get back after reset?
691692
//if(m_open != nullptr) {
692-
// if(FSP_SUCCESS == m_open(&m_i2c_ctrl,&m_i2c_cfg)) {
693+
// fsp_err_t err = m_open(&m_i2c_ctrl,&m_i2c_cfg);
694+
// if(FSP_SUCCESS == err) {
693695
// init_ok &= true;
694696
// }
695697
//}
696-
}
698+
}
697699
}
698700

699701

700702

703+
704+
701705
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
702706
* TRANSMISSION BEGIN
703707
* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */

0 commit comments

Comments
 (0)