8000 separate initHardware() · torst3n/arduino-esp32@74710c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 74710c1

Browse files
authored
separate initHardware()
1 parent c6a44d7 commit 74710c1

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,35 @@ void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
6767
return;
6868
}
6969
}
70+
71+
if(!initHardware(sdaPin, sclPin, frequency)) return;
72+
73+
flush();
74+
75+
}
76+
77+
void TwoWire::setTimeOut(uint16_t timeOutMillis){
78+
_timeOutMillis = timeOutMillis;
79+
}
80+
81+
uint16_t TwoWire::getTimeOut(){
82+
return _timeOutMillis;
83+
}
84+
85+
void TwoWire::setClock(uint32_t frequency)
86+
{
87+
i2cSetFrequency(i2c, frequency);
88+
}
89+
90+
/*@StickBreaker common handler for processing the queued commands
91+
*/
92+
bool TwoWire::initHardware(int sdaPin, int sclPin, uint32_t frequency){
7093

7194
i2cDetachSCL(i2c,scl); // detach pins before resetting I2C perpherial
7295
i2cDetachSDA(i2c,sda); // else a glitch will appear on the i2c bus
7396
i2c = i2cInit(num);// i2cInit() now performs a hardware reset
7497
if(i2c == NULL) {
75-
return;
98+
return false;
7699
}
77100

78101
i2cSetFrequency(i2c, frequency);
@@ -104,33 +127,14 @@ void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
104127

105128
i2cAttachSDA(i2c, sda);
106129
i2cAttachSCL(i2c, scl);
130+
return true;
131+
}
107132

108-
flush();
109-
110-
/* This function should no longer be necessary, the
111-
i2cInitFix(i2c);
112-
*/
113-
}
114-
115-
void TwoWire::setTimeOut(uint16_t timeOutMillis){
116-
_timeOutMillis = timeOutMillis;
117-
}
118-
119-
uint16_t TwoWire::getTimeOut(){
120-
return _timeOutMillis;
121-
}
122-
123-
void TwoWire::setClock(uint32_t frequency)
124-
{
125-
i2cSetFrequency(i2c, frequency);
126-
}
127-
/*@StickBreaker common handler for processing the queued commands
128-
*/
129133
i2c_err_t TwoWire::processQueue(uint32_t * readCount){
130134
last_error=i2cProcQueue(i2c,readCount,_timeOutMillis);
131135
if(last_error==I2C_ERROR_BUSY){ // try to clear the bus
132-
begin(sda,scl,getClock());
133-
last_error=i2cProcQueue(i2c,readCount,_timeOutMillis);
136+
if(initHardware(sda,scl,getClock()))
137+
last_error=i2cProcQueue(i2c,readCount,_timeOutMillis);
134138
}
135139

136140
rxIndex = 0;

0 commit comments

Comments
 (0)
0