Skip to content

Commit 4d98cea

Browse files
committed
Add Wire:setPins(sda, scl)
Fixes: #3779
1 parent b92c58d commit 4d98cea

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: libraries/Wire/src/Wire.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ TwoWire::~TwoWire()
5858
}
5959
}
6060

61+
bool TwoWire::setPins(int sdaPin, int sclPin)
62+
{
63+
if(i2c) {
64+
log_e("can not set pins if begin was already called");
65+
return false;
66+
}
67+
sda = sdaPin;
68+
scl = sclPin;
69+
return true;
70+
}
71+
6172
bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
6273
{
6374
if(sdaPin < 0) { // default param passed

Diff for: libraries/Wire/src/Wire.h

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class TwoWire: public Stream
6767
public:
6868
TwoWire(uint8_t bus_num);
6969
~TwoWire();
70+
71+
//call setPins() first, so that begin() can be called without arguments from libraries
72+
bool setPins(int sda, int scl);
73+
7074
bool begin(int sda=-1, int scl=-1, uint32_t frequency=0); // returns true, if successful init of i2c bus
7175
// calling will attemp to recover hung bus
7276

0 commit comments

Comments
 (0)