Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions libraries/Wire/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ void TwoWire::end(void) {


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

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

}
}
Expand All @@ -494,7 +494,7 @@ uint8_t TwoWire::read_from(uint8_t address, uint8_t* data, uint8_t length, unsig
}

/* -------------------------------------------------------------------------- */
uint8_t TwoWire::write_to(uint8_t address, uint8_t* data, uint8_t length, unsigned int timeout_ms, bool sendStop) {
uint8_t TwoWire::write_to(uint8_t address, uint8_t* data, uint8_t length, unsigned int timeout_us, bool sendStop) {
/* -------------------------------------------------------------------------- */
uint8_t rv = END_TX_OK;
fsp_err_t err = FSP_ERR_ASSERTION;
Expand All @@ -508,8 +508,8 @@ uint8_t TwoWire::write_to(uint8_t address, uint8_t* data, uint8_t length, unsign
err = m_write(&m_i2c_ctrl,data,length,!sendStop);
}
}
uint32_t const start = millis();
while(((millis() - start) < timeout_ms) && bus_status == WIRE_STATUS_UNSET && err == FSP_SUCCESS) {
uint32_t const start = micros();
while(((micros() - start) < timeout_us) && bus_status == WIRE_STATUS_UNSET && err == FSP_SUCCESS) {

}

Expand Down Expand Up @@ -835,7 +835,12 @@ void TwoWire::flush(void) {
while(bus_status != WIRE_STATUS_TX_COMPLETED && bus_status != WIRE_STATUS_TRANSACTION_ABORTED) {}
}


/* -------------------------------------------------------------------------- */
void TwoWire::setWireTimeout(unsigned int t, bool reset_on_timeout) {
/* -------------------------------------------------------------------------- */
(void)reset_on_timeout;
timeout = t;
}


#if WIRE_HOWMANY > 0
Expand Down
3 changes: 3 additions & 0 deletions libraries/Wire/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class TwoWire : public arduino::HardwareI2C {
void onRequest( void (*)(void) );

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

inline size_t write(unsigned long n) { return write((uint8_t)n); }
inline size_t write(long n) { return write((uint8_t)n); }
Expand Down