Merge branch 'master' into esp32s2

This commit is contained in:
Me No Dev
2020-07-23 16:10:45 +03:00
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

@ -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) bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
{ {
if(sdaPin < 0) { // default param passed if(sdaPin < 0) { // default param passed

View File

@ -67,8 +67,11 @@ protected:
public: public:
TwoWire(uint8_t bus_num); TwoWire(uint8_t bus_num);
~TwoWire(); ~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=100000); // returns true, if successful init of i2c bus bool begin(int sda=-1, int scl=-1, uint32_t frequency=100000); // returns true, if successful init of i2c bus
// calling will attemp to recover hung bus
void setClock(uint32_t frequency); // change bus clock without initing hardware void setClock(uint32_t frequency); // change bus clock without initing hardware
size_t getClock(); // current bus clock rate in hz size_t getClock(); // current bus clock rate in hz