Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7998e23

Browse filesBrowse files
stickbreakerme-no-dev
authored andcommitted
Preserver custom pin assigments (espressif#1239)
This code allows Wire.begin() to assign the default values of SDA, and SCL only if they have not been previously configured. Arduino libraries that use Wire() usually re-init the I2C interface in their initialization code with a call to Wire.begin(). If a user app sets custom pins assignment in setup(); These assignments will be overwritten with the default values whenever Wire.begin() is called.
1 parent 5abe49e commit 7998e23
Copy full SHA for 7998e23

File tree

Expand file treeCollapse file tree

1 file changed

+14
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-6
lines changed

‎libraries/Wire/src/Wire.cpp

Copy file name to clipboardExpand all lines: libraries/Wire/src/Wire.cpp
+14-6Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,27 @@ TwoWire::TwoWire(uint8_t bus_num)
4646

4747
void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
4848
{
49-
if(sdaPin < 0) {
49+
if(sdaPin < 0) { // default param passed
5050
if(num == 0) {
51-
sdaPin = SDA;
51+
if(sda==-1) sdaPin = SDA; //use Default Pin
52+
else sdaPin = sda; // reuse prior pin
5253
} else {
53-
return;
54+
if(sda==-1) {
55+
log_e("no Default SDA Pin for Second Peripheral");
56+
return; //no Default pin for Second Peripheral
57+
} else sdaPin = sda; // reuse prior pin
5458
}
5559
}
5660

57-
if(sclPin < 0) {
61+
if(sclPin < 0) { // default param passed
5862
if(num == 0) {
59-
sclPin = SCL;
63+
if(scl==-1) sclPin = SCL; // use Default pin
64+
else sclPin = scl; // reuse prior pin
6065
} else {
61-
return;
66+
if(scl==-1){
67+
log_e("no Default SCL Pin for Second Peripheral");
68+
return; //no Default pin for Second Peripheral
69+
} else sclPin = scl; // reuse prior pin
6270
}
6371
}
6472

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.