@@ -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
@@ -53,9 +55,11 @@ TwoWire::TwoWire(uint8_t bus_num)
53
55
,nonStopTask(NULL )
54
56
,lock(NULL )
55
57
#endif
58
+ #if SOC_I2C_SUPPORT_SLAVE
56
59
,is_slave(false )
57
60
,user_onRequest(NULL )
58
61
,user_onReceive(NULL )
62
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
59
63
{}
60
64
61
65
TwoWire::~TwoWire ()
@@ -297,10 +301,12 @@ bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
297
301
return false ;
298
302
}
299
303
#endif
304
+ #if SOC_I2C_SUPPORT_SLAVE
300
305
if (is_slave){
301
306
log_e (" Bus already started in Slave Mode." );
302
307
goto end;
303
308
}
309
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
304
310
if (i2cIsInit (num)){
305
311
log_w (" Bus already started in Master Mode." );
306
312
started = true ;
@@ -337,12 +343,15 @@ bool TwoWire::end()
337
343
return false ;
338
344
}
339
345
#endif
346
+ #if SOC_I2C_SUPPORT_SLAVE
340
347
if (is_slave){
341
348
err = i2cSlaveDeinit (num);
342
349
if (err == ESP_OK){
343
350
is_slave = false ;
344
351
}
345
- } else if (i2cIsInit (num)){
352
+ } else
353
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
354
+ if (i2cIsInit (num)){
346
355
err = i2cDeinit (num);
347
356
}
348
357
freeWireBuffer ();
@@ -363,9 +372,12 @@ uint32_t TwoWire::getClock()
363
372
log_e (" could not acquire lock" );
364
373
} else {
365
374
#endif
375
+ #if SOC_I2C_SUPPORT_SLAVE
366
376
if (is_slave){
367
377
log_e (" Bus is in Slave Mode" );
368
- } else {
378
+ } else
379
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
380
+ {
369
381
i2cGetClock (num, &frequency);
370
382
}
371
383
#if !CONFIG_DISABLE_HAL_LOCKS
@@ -386,10 +398,13 @@ bool TwoWire::setClock(uint32_t frequency)
386
398
return false ;
387
399
}
388
400
#endif
401
+ #if SOC_I2C_SUPPORT_SLAVE
389
402
if (is_slave){
390
403
log_e (" Bus is in Slave Mode" );
391
404
err = ESP_FAIL;
392
- } else {
405
+ } else
406
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
407
+ {
393
408
err = i2cSetClock (num, frequency);
394
409
}
395
410
#if !CONFIG_DISABLE_HAL_LOCKS
@@ -411,10 +426,12 @@ uint16_t TwoWire::getTimeOut()
411
426
412
427
void TwoWire::beginTransmission (uint16_t address)
413
428
{
429
+ #if SOC_I2C_SUPPORT_SLAVE
414
430
if (is_slave){
415
431
log_e (" Bus is in Slave Mode" );
416
432
return ;
417
433
}
434
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
418
435
#if !CONFIG_DISABLE_HAL_LOCKS
419
436
if (nonStop && nonStopTask == xTaskGetCurrentTaskHandle ()){
420
437
log_e (" Unfinished Repeated Start transaction! Expected requestFrom, not beginTransmission! Clearing..." );
@@ -444,10 +461,12 @@ endTransmission() returns:
444
461
*/
445
462
uint8_t TwoWire::endTransmission (bool sendStop)
446
463
{
464
+ #if SOC_I2C_SUPPORT_SLAVE
447
465
if (is_slave){
448
466
log_e (" Bus is in Slave Mode" );
449
467
return 4 ;
450
468
}
469
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
451
470
if (txBuffer == NULL ){
452
471
log_e (" NULL TX buffer pointer" );
453
472
return 4 ;
@@ -477,10 +496,12 @@ uint8_t TwoWire::endTransmission(bool sendStop)
477
496
478
497
size_t TwoWire::requestFrom (uint16_t address, size_t size, bool sendStop)
479
498
{
499
+ #if SOC_I2C_SUPPORT_SLAVE
480
500
if (is_slave){
481
501
log_e (" Bus is in Slave Mode" );
482
502
return 0 ;
483
503
}
504
+ #endif /* SOC_I2C_SUPPORT_SLAVE */
484
505
if (rxBuffer == NULL || txBuffer == NULL ){
485
506
log_e (" NULL buffer pointer" );
486
507
return 0 ;
0 commit comments