@@ -32,7 +32,9 @@ extern "C" {
3232}
3333
3434#include " esp32-hal-i2c.h"
35+ #if SOC_I2C_SUPPORT_SLAVE
3536#include " esp32-hal-i2c-slave.h"
37+ #endif /* SOC_I2C_SUPPORT_SLAVE */
3638#include " Wire.h"
3739#include " Arduino.h"
3840
@@ -57,7 +59,7 @@ TwoWire::TwoWire(uint8_t bus_num)
5759 ,is_slave(false )
5860 ,user_onRequest(NULL )
5961 ,user_onReceive(NULL )
60- #endif
62+ #endif /* SOC_I2C_SUPPORT_SLAVE */
6163{}
6264
6365TwoWire::~TwoWire ()
@@ -299,10 +301,12 @@ bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
299301 return false ;
300302 }
301303#endif
304+ #if SOC_I2C_SUPPORT_SLAVE
302305 if (is_slave){
303306 log_e (" Bus already started in Slave Mode." );
304307 goto end;
305308 }
309+ #endif /* SOC_I2C_SUPPORT_SLAVE */
306310 if (i2cIsInit (num)){
307311 log_w (" Bus already started in Master Mode." );
308312 started = true ;
@@ -339,14 +343,15 @@ bool TwoWire::end()
339343 return false ;
340344 }
341345#endif
342- if (is_slave){
343346#if SOC_I2C_SUPPORT_SLAVE
347+ if (is_slave){
344348 err = i2cSlaveDeinit (num);
345349 if (err == ESP_OK){
346350 is_slave = false ;
347351 }
348- #endif
349- } else if (i2cIsInit (num)){
352+ } else
353+ #endif /* SOC_I2C_SUPPORT_SLAVE */
354+ if (i2cIsInit (num)){
350355 err = i2cDeinit (num);
351356 }
352357 freeWireBuffer ();
@@ -367,9 +372,12 @@ uint32_t TwoWire::getClock()
367372 log_e (" could not acquire lock" );
368373 } else {
369374#endif
375+ #if SOC_I2C_SUPPORT_SLAVE
370376 if (is_slave){
371377 log_e (" Bus is in Slave Mode" );
372- } else {
378+ } else
379+ #endif /* SOC_I2C_SUPPORT_SLAVE */
380+ {
373381 i2cGetClock (num, &frequency);
374382 }
375383#if !CONFIG_DISABLE_HAL_LOCKS
@@ -390,10 +398,13 @@ bool TwoWire::setClock(uint32_t frequency)
390398 return false ;
391399 }
392400#endif
401+ #if SOC_I2C_SUPPORT_SLAVE
393402 if (is_slave){
394403 log_e (" Bus is in Slave Mode" );
395404 err = ESP_FAIL;
396- } else {
405+ } else
406+ #endif /* SOC_I2C_SUPPORT_SLAVE */
407+ {
397408 err = i2cSetClock (num, frequency);
398409 }
399410#if !CONFIG_DISABLE_HAL_LOCKS
@@ -415,10 +426,12 @@ uint16_t TwoWire::getTimeOut()
415426
416427void TwoWire::beginTransmission (uint16_t address)
417428{
429+ #if SOC_I2C_SUPPORT_SLAVE
418430 if (is_slave){
419431 log_e (" Bus is in Slave Mode" );
420432 return ;
421433 }
434+ #endif /* SOC_I2C_SUPPORT_SLAVE */
422435#if !CONFIG_DISABLE_HAL_LOCKS
423436 if (nonStop && nonStopTask == xTaskGetCurrentTaskHandle ()){
424437 log_e (" Unfinished Repeated Start transaction! Expected requestFrom, not beginTransmission! Clearing..." );
@@ -448,10 +461,12 @@ endTransmission() returns:
448461*/
449462uint8_t TwoWire::endTransmission (bool sendStop)
450463{
464+ #if SOC_I2C_SUPPORT_SLAVE
451465 if (is_slave){
452466 log_e (" Bus is in Slave Mode" );
453467 return 4 ;
454468 }
469+ #endif /* SOC_I2C_SUPPORT_SLAVE */
455470 if (txBuffer == NULL ){
456471 log_e (" NULL TX buffer pointer" );
457472 return 4 ;
@@ -481,10 +496,12 @@ uint8_t TwoWire::endTransmission(bool sendStop)
481496
482497size_t TwoWire::requestFrom (uint16_t address, size_t size, bool sendStop)
483498{
499+ #if SOC_I2C_SUPPORT_SLAVE
484500 if (is_slave){
485501 log_e (" Bus is in Slave Mode" );
486502 return 0 ;
487503 }
504+ #endif /* SOC_I2C_SUPPORT_SLAVE */
488505 if (rxBuffer == NULL || txBuffer == NULL ){
489506 log_e (" NULL buffer pointer" );
490507 return 0 ;
@@ -708,4 +725,4 @@ void TwoWire::onRequest( void (*function)(void) )
708725TwoWire Wire = TwoWire (0 );
709726TwoWire Wire1 = TwoWire (1 );
710727
711- #endif /* SOC_I2C_SUPPORTED */
728+ #endif /* SOC_I2C_SUPPORTED */
0 commit comments