From 4d98cea085d619bed7026b37071bd8402a485d95 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Sun, 19 Jul 2020 02:21:15 +0300 Subject: [PATCH] Add Wire:setPins(sda, scl) Fixes: https://github.com/espressif/arduino-esp32/issues/3779 --- libraries/Wire/src/Wire.cpp | 11 +++++++++++ libraries/Wire/src/Wire.h | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index bc5801478..3fbd0eb08 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -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 diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index 37288beb6..00f268b7d 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -67,6 +67,10 @@ protected: 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