@@ -78,15 +78,11 @@ 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 ;
8682
87- i2c_custom_init (&_i2c, I2C_100KHz, I2C_ADDRESSINGMODE_7BIT, ownAddress, master );
83+ i2c_custom_init (&_i2c, I2C_100KHz, I2C_ADDRESSINGMODE_7BIT, ownAddress);
8884
89- if (master == false ) {
85+ if (_i2c. isMaster == 0 ) {
9086 // i2c_attachSlaveTxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*)>(&TwoWire::onRequestService));
9187 // i2c_attachSlaveRxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*, uint8_t*, int)>(&TwoWire::onReceiveService));
9288
@@ -119,7 +115,7 @@ void TwoWire::setClock(uint32_t frequency)
119115uint8_t TwoWire::requestFrom (uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
120116{
121117 UNUSED (sendStop);
122- if (master == true ) {
118+ if (_i2c. isMaster == 1 ) {
123119 allocateRxBuffer (quantity);
124120 // error if no memory block available to allocate the buffer
125121 if (rxBuffer == nullptr ) {
@@ -216,7 +212,7 @@ uint8_t TwoWire::endTransmission(uint8_t sendStop)
216212 UNUSED (sendStop);
217213 int8_t ret = 4 ;
218214
219- if (master == true ) {
215+ if (_i2c. isMaster == 1 ) {
220216 // transmit buffer (blocking)
221217 switch (i2c_master_write (&_i2c, txAddress, txBuffer, txBufferLength)) {
222218 case I2C_OK :
0 commit comments