@@ -32,7 +32,9 @@ extern "C" {
32
32
}
33
33
34
34
#include " esp32-hal-i2c.h"
35
+ #if SOC_I2C_SUPPORT_SLAVE
35
36
#include " esp32-hal-i2c-slave.h"
37
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
36
38
#include " Wire.h"
37
39
#include " Arduino.h"
38
40
@@ -57,7 +59,7 @@ TwoWire::TwoWire(uint8_t bus_num)
57
59
,is_slave(false )
58
60
,user_onRequest(NULL )
59
61
,user_onReceive(NULL )
60
- #endif
62
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
61
63
{}
62
64
63
65
TwoWire::~TwoWire ()
@@ -299,10 +301,12 @@ bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
299
301
return false ;
300
302
}
301
303
#endif
304
+ #if SOC_I2C_SUPPORT_SLAVE
302
305
if (is_slave){
303
306
log_e (" Bus already started in Slave Mode." );
304
307
goto end;
305
308
}
309
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
306
310
if (i2cIsInit (num)){
307
311
log_w (" Bus already started in Master Mode." );
308
312
started = true ;
@@ -339,14 +343,15 @@ bool TwoWire::end()
339
343
return false ;
340
344
}
341
345
#endif
342
- if (is_slave){
343
346
#if SOC_I2C_SUPPORT_SLAVE
347
+ if (is_slave){
344
348
err = i2cSlaveDeinit (num);
345
349
if (err == ESP_OK){
346
350
is_slave = false ;
347
351
}
348
- #endif
349
- } else if (i2cIsInit (num)){
352
+ } else
353
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
354
+ if (i2cIsInit (num)){
350
355
err = i2cDeinit (num);
351
356
}
352
357
freeWireBuffer ();
@@ -367,9 +372,12 @@ uint32_t TwoWire::getClock()
367
372
log_e (" could not acquire lock" );
368
373
} else {
369
374
#endif
375
+ #if SOC_I2C_SUPPORT_SLAVE
370
376
if (is_slave){
371
377
log_e (" Bus is in Slave Mode" );
372
- } else {
378
+ } else
379
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
380
+ {
373
381
i2cGetClock (num, &frequency);
374
382
}
375
383
#if !CONFIG_DISABLE_HAL_LOCKS
@@ -390,10 +398,13 @@ bool TwoWire::setClock(uint32_t frequency)
390
398
return false ;
391
399
}
392
400
#endif
401
+ #if SOC_I2C_SUPPORT_SLAVE
393
402
if (is_slave){
394
403
log_e (" Bus is in Slave Mode" );
395
404
err = ESP_FAIL;
396
- } else {
405
+ } else
406
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
407
+ {
397
408
err = i2cSetClock (num, frequency);
398
409
}
399
410
#if !CONFIG_DISABLE_HAL_LOCKS
@@ -415,10 +426,12 @@ uint16_t TwoWire::getTimeOut()
415
426
416
427
void TwoWire::beginTransmission (uint16_t address)
417
428
{
429
+ #if SOC_I2C_SUPPORT_SLAVE
418
430
if (is_slave){
419
431
log_e (" Bus is in Slave Mode" );
420
432
return ;
421
433
}
434
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
422
435
#if !CONFIG_DISABLE_HAL_LOCKS
423
436
if (nonStop && nonStopTask == xTaskGetCurrentTaskHandle ()){
424
437
log_e (" Unfinished Repeated Start transaction! Expected requestFrom, not beginTransmission! Clearing..." );
@@ -448,10 +461,12 @@ endTransmission() returns:
448
461
*/
449
462
uint8_t TwoWire::endTransmission (bool sendStop)
450
463
{
464
+ #if SOC_I2C_SUPPORT_SLAVE
451
465
if (is_slave){
452
466
log_e (" Bus is in Slave Mode" );
453
467
return 4 ;
454
468
}
469
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
455
470
if (txBuffer == NULL ){
456
471
log_e (" NULL TX buffer pointer" );
457
472
return 4 ;
@@ -481,10 +496,12 @@ uint8_t TwoWire::endTransmission(bool sendStop)
481
496
482
497
size_t TwoWire::requestFrom (uint16_t address, size_t size, bool sendStop)
483
498
{
499
+ #if SOC_I2C_SUPPORT_SLAVE
484
500
if (is_slave){
485
501
log_e (" Bus is in Slave Mode" );
486
502
return 0 ;
487
503
}
504
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
488
505
if (rxBuffer == NULL || txBuffer == NULL ){
489
506
log_e (" NULL buffer pointer" );
490
507
return 0 ;
@@ -708,4 +725,4 @@ void TwoWire::onRequest( void (*function)(void) )
708
725
TwoWire Wire = TwoWire (0 );
709
726
TwoWire Wire1 = TwoWire (1 );
710
727
711
- #endif /* SOC_I2C_SUPPORTED */
728
+ #endif /* SOC_I2C_SUPPORTED */
0 commit comments