Skip to content

Commit 1e3a547

Browse files
committed
Updated setWireTimeout function signature to be compliant with same function present on ArduinoCore-avr
- the first parameter now express the timeout in micro seconds (default 25000 us) - the second parameter reset_on_timeout has been added for compatibility but has no effect on this core (default false) - the default timeout (if setWireTimeout is not called) remains set to 1 ms (1000 us)
1 parent 4f15d9d commit 1e3a547

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

libraries/Wire/Wire.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ TwoWire::TwoWire(int scl, int sda, WireAddressMode_t am /*= ADDRESS_MODE_7_BITS*
191191
is_master(true),
192192
is_sci(false),
193193
address_mode(am),
194-
timeout(1),
194+
timeout(1000),
195195
transmission_begun(false),
196196
data_too_long(false),
197197
rx_index(0),
@@ -465,7 +465,7 @@ void TwoWire::end(void) {
465465

466466

467467
/* -------------------------------------------------------------------------- */
468-
uint8_t TwoWire::read_from(uint8_t address, uint8_t* data, uint8_t length, unsigned int timeout_ms, bool sendStop) {
468+
uint8_t TwoWire::read_from(uint8_t address, uint8_t* data, uint8_t length, unsigned int timeout_us, bool sendStop) {
469469
/* -------------------------------------------------------------------------- */
470470
/* ??? does this function make sense only for MASTER ???? */
471471

@@ -480,8 +480,8 @@ uint8_t TwoWire::read_from(uint8_t address, uint8_t* data, uint8_t length, unsig
480480
err = m_read(&m_i2c_ctrl,data,length,!sendStop);
481481
}
482482
}
483-
uint32_t const start = millis();
484-
while(((millis() - start) < timeout_ms) && bus_status == WIRE_STATUS_UNSET && err == FSP_SUCCESS) {
483+
uint32_t const start = micros();
484+
while(((micros() - start) < timeout_us) && bus_status == WIRE_STATUS_UNSET && err == FSP_SUCCESS) {
485485

486486
}
487487
}
@@ -494,7 +494,7 @@ uint8_t TwoWire::read_from(uint8_t address, uint8_t* data, uint8_t length, unsig
494494
}
495495

496496
/* -------------------------------------------------------------------------- */
497-
uint8_t TwoWire::write_to(uint8_t address, uint8_t* data, uint8_t length, unsigned int timeout_ms, bool sendStop) {
497+
uint8_t TwoWire::write_to(uint8_t address, uint8_t* data, uint8_t length, unsigned int timeout_us, bool sendStop) {
498498
/* -------------------------------------------------------------------------- */
499499
uint8_t rv = END_TX_OK;
500500
fsp_err_t err = FSP_ERR_ASSERTION;
@@ -508,8 +508,8 @@ uint8_t TwoWire::write_to(uint8_t address, uint8_t* data, uint8_t length, unsign
508508
err = m_write(&m_i2c_ctrl,data,length,!sendStop);
509509
}
510510
}
511-
uint32_t const start = millis();
512-
while(((millis() - start) < timeout_ms) && bus_status == WIRE_STATUS_UNSET && err == FSP_SUCCESS) {
511+
uint32_t const start = micros();
512+
while(((micros() - start) < timeout_us) && bus_status == WIRE_STATUS_UNSET && err == FSP_SUCCESS) {
513513

514514
}
515515

@@ -836,8 +836,9 @@ void TwoWire::flush(void) {
836836
}
837837

838838
/* -------------------------------------------------------------------------- */
839-
void TwoWire::setWireTimeout(unsigned int t) {
839+
void TwoWire::setWireTimeout(unsigned int t, bool reset_on_timeout) {
840840
/* -------------------------------------------------------------------------- */
841+
(void)reset_on_timeout;
841842
timeout = t;
842843
}
843844

libraries/Wire/Wire.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ class TwoWire : public arduino::HardwareI2C {
124124
void onRequest( void (*)(void) );
125125

126126
void setBusStatus(WireStatus_t);
127-
/* set timeout in ms for I2C communication */
128-
void setWireTimeout(unsigned int t);
127+
/* set timeout in us for I2C communication (default is 1000 us)
128+
the second parameter has been added for compatibility but it has no effect*/
129+
void setWireTimeout(unsigned int t = 25000, bool reset_on_timeout = false);
129130

130131
inline size_t write(unsigned long n) { return write((uint8_t)n); }
131132
inline size_t write(long n) { return write((uint8_t)n); }

0 commit comments

Comments
 (0)