@@ -58,7 +58,7 @@ TwoWire::~TwoWire()
58
58
}
59
59
}
60
60
61
- void TwoWire::begin (int sdaPin, int sclPin, uint32_t frequency)
61
+ bool TwoWire::begin (int sdaPin, int sclPin, uint32_t frequency)
62
62
{
63
63
if (sdaPin < 0 ) { // default param passed
64
64
if (num == 0 ) {
@@ -70,7 +70,7 @@ void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
70
70
} else {
71
71
if (sda==-1 ) {
72
72
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
74
74
} else {
75
75
sdaPin = sda; // reuse prior pin
76
76
}
@@ -87,7 +87,7 @@ void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
87
87
} else {
88
88
if (scl == -1 ) {
89
89
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
91
91
} else {
92
92
sclPin = scl; // reuse prior pin
93
93
}
@@ -98,10 +98,11 @@ void TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
98
98
scl = sclPin;
99
99
i2c = i2cInit (num, sdaPin, sclPin, frequency);
100
100
if (!i2c) {
101
- return ;
101
+ return false ;
102
102
}
103
103
104
104
flush ();
105
+ return true ;
105
106
106
107
}
107
108
@@ -145,6 +146,7 @@ void TwoWire::beginTransmission(uint16_t address)
145
146
txAddress = address;
146
147
txIndex = txQueued; // allow multiple beginTransmission(),write(),endTransmission(false) until endTransmission(true)
147
148
txLength = txQueued;
149
+ last_error = I2C_ERROR_OK;
148
150
}
149
151
150
152
/* stickbreaker isr
@@ -202,27 +204,27 @@ size_t TwoWire::write(uint8_t data)
202
204
{
203
205
if (transmitting) {
204
206
if (txLength >= I2C_BUFFER_LENGTH) {
207
+ last_error = I2C_ERROR_MEMORY;
205
208
return 0 ;
206
209
}
207
210
txBuffer[txIndex] = data;
208
211
++txIndex;
209
212
txLength = txIndex;
210
213
return 1 ;
211
214
}
215
+ last_error = I2C_ERROR_NO_BEGIN; // no begin, not transmitting
212
216
return 0 ;
213
217
}
214
218
215
219
size_t TwoWire::write (const uint8_t *data, size_t quantity)
216
220
{
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;
222
224
}
223
- return quantity;
224
225
}
225
- return 0 ;
226
+ return quantity;
227
+
226
228
}
227
229
228
230
int TwoWire::available (void )
@@ -353,14 +355,13 @@ char * TwoWire::getErrorText(uint8_t err)
353
355
354
356
/* stickbreaker Dump i2c Interrupt buffer, i2c isr Debugging
355
357
*/
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 );
359
361
}
360
362
361
- void TwoWire::dumpI2C ()
362
- {
363
- i2cDumpI2c (i2c);
363
+ bool TwoWire::busy (void ){
364
+ return ((i2cGetStatus (i2c) & 16 )==16 );
364
365
}
365
366
366
367
TwoWire Wire = TwoWire(0 );
0 commit comments