Skip to content

Commit 22afc3a

Browse files
authored
Update Wire.cpp
1 parent 9c1c532 commit 22afc3a

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

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

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

61-
void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
61+
bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
6262
{
6363
if(sdaPin < 0) { // default param passed
6464
if(num == 0) {
@@ -70,7 +70,7 @@ void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
7070
} else {
7171
if(sda==-1) {
7272
log_e("no Default SDA Pin for Second Peripheral");
73-
return; //no Default pin for Second Peripheral
73+
return false; //no Default pin for Second Peripheral
7474
} else {
7575
sdaPin = sda; // reuse prior pin
7676
}
@@ -87,7 +87,7 @@ void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
8787
} else {
8888
if(scl == -1) {
8989
log_e("no Default SCL Pin for Second Peripheral");
90-
return; //no Default pin for Second Peripheral
90+
return false; //no Default pin for Second Peripheral
9191
} else {
9292
sclPin = scl; // reuse prior pin
9393
}
@@ -98,10 +98,11 @@ void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
9898
scl = sclPin;
9999
i2c = i2cInit(num, sdaPin, sclPin, frequency);
100100
if(!i2c) {
101-
return;
101+
return false;
102102
}
103103

104104
flush();
105+
return true;
105106

106107
}
107108

@@ -145,6 +146,7 @@ void TwoWire::beginTransmission(uint16_t address)
145146
txAddress = address;
146147
txIndex = txQueued; // allow multiple beginTransmission(),write(),endTransmission(false) until endTransmission(true)
147148
txLength = txQueued;
149+
last_error = I2C_ERROR_OK;
148150
}
149151

150152
/*stickbreaker isr
@@ -202,27 +204,27 @@ size_t TwoWire::write(uint8_t data)
202204
{
203205
if(transmitting) {
204206
if(txLength >= I2C_BUFFER_LENGTH) {
207+
last_error = I2C_ERROR_MEMORY;
205208
return 0;
206209
}
207210
txBuffer[txIndex] = data;
208211
++txIndex;
209212
txLength = txIndex;
210213
return 1;
211214
}
215+
last_error = I2C_ERROR_NO_BEGIN; // no begin, not transmitting
212216
return 0;
213217
}
214218

215219
size_t TwoWire::write(const uint8_t *data, size_t quantity)
216220
{
217-
if(transmitting) {
218-
for(size_t i = 0; i < quantity; ++i) {
219-
if(!write(data[i])) {
220-
return i;
221-
}
221+
for(size_t i = 0; i < quantity; ++i) {
222+
if(!write(data[i])) {
223+
return i;
222224
}
223-
return quantity;
224225
}
225-
return 0;
226+
return quantity;
227+
226228
}
227229

228230
int TwoWire::available(void)
@@ -353,14 +355,13 @@ char * TwoWire::getErrorText(uint8_t err)
353355

354356
/*stickbreaker Dump i2c Interrupt buffer, i2c isr Debugging
355357
*/
356-
void TwoWire::dumpInts()
357-
{
358-
i2cDumpInts(num);
358+
359+
uint32_t TwoWire::setDebugFlags( uint32_t setBits, uint32_t resetBits){
360+
i2cDebug(i2c,setBits,resetBits);
359361
}
360362

361-
void TwoWire::dumpI2C()
362-
{
363-
i2cDumpI2c(i2c);
363+
bool TwoWire::busy(void){
364+
return ((i2cGetStatus(i2c) & 16 )==16);
364365
}
365366

366367
TwoWire Wire = TwoWire(0);

0 commit comments

Comments
 (0)