Skip to content

Commit

Permalink
Add Wire:setPins(sda, scl)
Browse files Browse the repository at this point in the history
Fixes: #3779
  • Loading branch information
me-no-dev committed Jul 18, 2020
1 parent b92c58d commit 4d98cea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ TwoWire::~TwoWire()
}
}

bool TwoWire::setPins(int sdaPin, int sclPin)
{
if(i2c) {
log_e("can not set pins if begin was already called");
return false;
}
sda = sdaPin;
scl = sclPin;
return true;
}

bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
{
if(sdaPin < 0) { // default param passed
Expand Down
4 changes: 4 additions & 0 deletions libraries/Wire/src/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class TwoWire: public Stream
public:
TwoWire(uint8_t bus_num);
~TwoWire();

//call setPins() first, so that begin() can be called without arguments from libraries
bool setPins(int sda, int scl);

bool begin(int sda=-1, int scl=-1, uint32_t frequency=0); // returns true, if successful init of i2c bus
// calling will attemp to recover hung bus

Expand Down

0 comments on commit 4d98cea

Please sign in to comment.