@@ -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
@@ -53,9 +55,11 @@ TwoWire::TwoWire(uint8_t bus_num)
5355 ,nonStopTask(NULL )
5456 ,lock(NULL )
5557#endif
58+ #if SOC_I2C_SUPPORT_SLAVE
5659 ,is_slave(false )
5760 ,user_onRequest(NULL )
5861 ,user_onReceive(NULL )
62+ #endif /* SOC_I2C_SUPPORT_SLAVE */
5963{}
6064
6165TwoWire::~TwoWire ()
@@ -297,10 +301,12 @@ bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
297301 return false ;
298302 }
299303#endif
304+ #if SOC_I2C_SUPPORT_SLAVE
300305 if (is_slave){
301306 log_e (" Bus already started in Slave Mode." );
302307 goto end;
303308 }
309+ #endif /* SOC_I2C_SUPPORT_SLAVE */
304310 if (i2cIsInit (num)){
305311 log_w (" Bus already started in Master Mode." );
306312 started = true ;
@@ -337,12 +343,15 @@ bool TwoWire::end()
337343 return false ;
338344 }
339345#endif
346+ #if SOC_I2C_SUPPORT_SLAVE
340347 if (is_slave){
341348 err = i2cSlaveDeinit (num);
342349 if (err == ESP_OK){
343350 is_slave = false ;
344351 }
345- } else if (i2cIsInit (num)){
352+ } else
353+ #endif /* SOC_I2C_SUPPORT_SLAVE */
354+ if (i2cIsInit (num)){
346355 err = i2cDeinit (num);
347356 }
348357 freeWireBuffer ();
@@ -363,9 +372,12 @@ uint32_t TwoWire::getClock()
363372 log_e (" could not acquire lock" );
364373 } else {
365374#endif
375+ #if SOC_I2C_SUPPORT_SLAVE
366376 if (is_slave){
367377 log_e (" Bus is in Slave Mode" );
368- } else {
378+ } else
379+ #endif /* SOC_I2C_SUPPORT_SLAVE */
380+ {
369381 i2cGetClock (num, &frequency);
370382 }
371383#if !CONFIG_DISABLE_HAL_LOCKS
@@ -386,10 +398,13 @@ bool TwoWire::setClock(uint32_t frequency)
386398 return false ;
387399 }
388400#endif
401+ #if SOC_I2C_SUPPORT_SLAVE
389402 if (is_slave){
390403 log_e (" Bus is in Slave Mode" );
391404 err = ESP_FAIL;
392- } else {
405+ } else
406+ #endif /* SOC_I2C_SUPPORT_SLAVE */
407+ {
393408 err = i2cSetClock (num, frequency);
394409 }
395410#if !CONFIG_DISABLE_HAL_LOCKS
@@ -411,10 +426,12 @@ uint16_t TwoWire::getTimeOut()
411426
412427void TwoWire::beginTransmission (uint16_t address)
413428{
429+ #if SOC_I2C_SUPPORT_SLAVE
414430 if (is_slave){
415431 log_e (" Bus is in Slave Mode" );
416432 return ;
417433 }
434+ #endif /* SOC_I2C_SUPPORT_SLAVE */
418435#if !CONFIG_DISABLE_HAL_LOCKS
419436 if (nonStop && nonStopTask == xTaskGetCurrentTaskHandle ()){
420437 log_e (" Unfinished Repeated Start transaction! Expected requestFrom, not beginTransmission! Clearing..." );
@@ -444,10 +461,12 @@ endTransmission() returns:
444461*/
445462uint8_t TwoWire::endTransmission (bool sendStop)
446463{
464+ #if SOC_I2C_SUPPORT_SLAVE
447465 if (is_slave){
448466 log_e (" Bus is in Slave Mode" );
449467 return 4 ;
450468 }
469+ #endif /* SOC_I2C_SUPPORT_SLAVE */
451470 if (txBuffer == NULL ){
452471 log_e (" NULL TX buffer pointer" );
453472 return 4 ;
@@ -477,10 +496,12 @@ uint8_t TwoWire::endTransmission(bool sendStop)
477496
478497size_t TwoWire::requestFrom (uint16_t address, size_t size, bool sendStop)
479498{
499+ #if SOC_I2C_SUPPORT_SLAVE
480500 if (is_slave){
481501 log_e (" Bus is in Slave Mode" );
482502 return 0 ;
483503 }
504+ #endif /* SOC_I2C_SUPPORT_SLAVE */
484505 if (rxBuffer == NULL || txBuffer == NULL ){
485506 log_e (" NULL buffer pointer" );
486507 return 0 ;
0 commit comments