@@ -59,12 +59,12 @@ TwoWire::TwoWire(uint8_t sda, uint8_t scl)
5959
6060// Public Methods //////////////////////////////////////////////////////////////
6161
62- void TwoWire::begin (void )
62+ void TwoWire::begin (bool generalCall )
6363{
64- begin (MASTER_ADDRESS);
64+ begin (MASTER_ADDRESS, generalCall );
6565}
6666
67- void TwoWire::begin (uint8_t address)
67+ void TwoWire::begin (uint8_t address, bool generalCall )
6868{
6969 rxBufferIndex = 0 ;
7070 rxBufferLength = 0 ;
@@ -78,15 +78,13 @@ void TwoWire::begin(uint8_t address)
7878
7979 ownAddress = address << 1 ;
8080
81- if (address == MASTER_ADDRESS) {
82- master = true ;
83- } else {
84- master = false ;
85- }
81+ _i2c.isMaster = (address == MASTER_ADDRESS) ? 1 : 0 ;
82+
83+ _i2c.generalCall = (generalCall == true ) ? 1 : 0 ;
8684
87- i2c_custom_init (&_i2c, I2C_100KHz, I2C_ADDRESSINGMODE_7BIT, ownAddress, master );
85+ i2c_custom_init (&_i2c, I2C_100KHz, I2C_ADDRESSINGMODE_7BIT, ownAddress);
8886
89- if (master == false ) {
87+ if (_i2c. isMaster == 0 ) {
9088 // i2c_attachSlaveTxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*)>(&TwoWire::onRequestService));
9189 // i2c_attachSlaveRxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*, uint8_t*, int)>(&TwoWire::onReceiveService));
9290
@@ -95,9 +93,9 @@ void TwoWire::begin(uint8_t address)
9593 }
9694}
9795
98- void TwoWire::begin (int address)
96+ void TwoWire::begin (int address, bool generalCall )
9997{
100- begin ((uint8_t )address);
98+ begin ((uint8_t )address, generalCall );
10199}
102100
103101void TwoWire::end (void )
@@ -119,7 +117,7 @@ void TwoWire::setClock(uint32_t frequency)
119117uint8_t TwoWire::requestFrom (uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
120118{
121119 UNUSED (sendStop);
122- if (master == true ) {
120+ if (_i2c. isMaster == 1 ) {
123121 allocateRxBuffer (quantity);
124122 // error if no memory block available to allocate the buffer
125123 if (rxBuffer == nullptr ) {
@@ -216,7 +214,7 @@ uint8_t TwoWire::endTransmission(uint8_t sendStop)
216214 UNUSED (sendStop);
217215 int8_t ret = 4 ;
218216
219- if (master == true ) {
217+ if (_i2c. isMaster == 1 ) {
220218 // transmit buffer (blocking)
221219 switch (i2c_master_write (&_i2c, txAddress, txBuffer, txBufferLength)) {
222220 case I2C_OK :
0 commit comments