Skip to content

Commit c65cbde

Browse files
authored
Merge branch 'earlephilhower:master' into master
2 parents 22dfda2 + 0148b14 commit c65cbde

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Read the [Contributing Guide](https://github.com/earlephilhower/arduino-pico/blo
2525
* Adafruit KB2040
2626
* Adafruit Macropad RP2040
2727
* Adafruit Metro RP2040
28+
* Adafruit Metro RP2350
2829
* Adafruit QTPy RP2040
2930
* Adafruit STEMMA Friend RP2040
3031
* Adafruit Trinkey RP2040 QT

libraries/Wire/src/Wire.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,25 @@ void TwoWire::flush(void) {
489489
// data transfer.
490490
}
491491

492+
bool TwoWire::busIdle() {
493+
// Check hardware status
494+
uint32_t status = _i2c->hw->status;
495+
bool tfe = (status & I2C_IC_STATUS_TFE_BITS);
496+
bool mast = (status & I2C_IC_STATUS_MST_ACTIVITY_BITS);
497+
return (tfe && !mast);
498+
}
499+
492500
// DMA/asynchronous transfers. Do not combime with synchronous runs or bad stuff will happen
493501
// All buffers must be valid for entire DMA and not touched until `finishedAsync()` returns true.
494502
bool TwoWire::writeReadAsync(uint8_t address, const void *wbuffer, size_t wbytes, const void *rbuffer, size_t rbytes, bool sendStop) {
495503
if (!_running || _txBegun || (wbytes == 0 && rbytes == 0)) {
496504
return false;
497505
}
498506

507+
if (!busIdle()) {
508+
return false;
509+
}
510+
499511
if (!_dmaRunning) {
500512
beginAsync();
501513
if (!_dmaRunning) {

libraries/Wire/src/Wire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class TwoWire : public HardwareI2C {
8787
bool writeReadAsync(uint8_t address, const void *wbuffer, size_t wbytes, const void *rbuffer, size_t rbytes, bool sendStop = true);
8888
bool writeAsync(uint8_t address, const void *buffer, size_t bytes, bool sendStop = true);
8989
bool readAsync(uint8_t address, void *buffer, size_t bytes, bool sendStop = true);
90+
bool busIdle();
9091
bool finishedAsync(); // Call to check if the async operations is completed and the buffer can be reused/read
9192
void abortAsync(); // Cancel an outstanding async I2C operation
9293
void onFinishedAsync(void(*function)(void)); // Set callback for async operation

0 commit comments

Comments
 (0)