@@ -84,19 +84,19 @@ void TwoWire::begin(uint8_t address, bool generalCall, bool NoStretchMode)
8484
8585 ownAddress = address << 1 ;
8686
87- _i2c.isMaster = (address == MASTER_ADDRESS ) ? 1 : 0 ;
87+ _i2c.isMaster = (address == MASTER_ADDRESS );
8888
89- _i2c.generalCall = ( generalCall == true ) ? 1 : 0 ;
89+ _i2c.generalCall = generalCall;
9090
91- _i2c.NoStretchMode = ( NoStretchMode == true ) ? 1 : 0 ;
91+ _i2c.NoStretchMode = NoStretchMode;
9292
93- if (_i2c.isMaster == 1 ) {
93+ if (_i2c.isMaster ) {
9494 recoverBus (); // in case I2C bus (device) is stuck after a reset for example
9595 }
9696
9797 i2c_init (&_i2c, 100000 , ownAddress);
9898
99- if (_i2c.isMaster == 0 ) {
99+ if (! _i2c.isMaster ) {
100100 // i2c_attachSlaveTxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*)>(&TwoWire::onRequestService));
101101 // i2c_attachSlaveRxEvent(&_i2c, reinterpret_cast<void(*)(i2c_t*, uint8_t*, int)>(&TwoWire::onReceiveService));
102102
@@ -128,7 +128,7 @@ void TwoWire::end(void)
128128void TwoWire::setClock (uint32_t freq)
129129{
130130 i2c_setTiming (&_i2c, freq);
131- if (_i2c.isMaster == 0 ) {
131+ if (! _i2c.isMaster ) {
132132 i2c_attachSlaveTxEvent (&_i2c, onRequestService);
133133 i2c_attachSlaveRxEvent (&_i2c, onReceiveService);
134134 }
@@ -151,7 +151,7 @@ size_t TwoWire::requestFrom(uint8_t address, size_t len, uint32_t iaddress, uint
151151#endif
152152 size_t read = 0 ;
153153
154- if (_i2c.isMaster == 1 ) {
154+ if (_i2c.isMaster ) {
155155 allocateRxBuffer (len);
156156
157157 if (isize > 0 ) {
@@ -181,7 +181,13 @@ size_t TwoWire::requestFrom(uint8_t address, size_t len, uint32_t iaddress, uint
181181 _i2c.handle .XferOptions = I2C_OTHER_AND_LAST_FRAME ;
182182 }
183183#endif
184-
184+ #if defined(USE_HALV2_DRIVER)
185+ if (stopBit == false ) {
186+ _i2c.handle .xfer_opt = HAL_I2C_XFER_OTHER_FRAME ;
187+ } else {
188+ _i2c.handle .xfer_opt = HAL_I2C_XFER_OTHER_AND_LAST_FRAME ;
189+ }
190+ #endif
185191 if (I2C_OK == i2c_master_read (&_i2c, address << 1 , rxBuffer, (uint16_t )len)) {
186192 read = len;
187193 }
@@ -236,8 +242,15 @@ uint8_t TwoWire::endTransmission(bool stopBit)
236242 _i2c.handle .XferOptions = I2C_OTHER_AND_LAST_FRAME ;
237243 }
238244#endif
245+ #if defined(USE_HALV2_DRIVER)
246+ if (stopBit == false ) {
247+ _i2c.handle .xfer_opt = HAL_I2C_XFER_OTHER_FRAME ;
248+ } else {
249+ _i2c.handle .xfer_opt = HAL_I2C_XFER_OTHER_AND_LAST_FRAME ;
250+ }
251+ #endif
239252
240- if (_i2c.isMaster == 1 ) {
253+ if (_i2c.isMaster ) {
241254 // transmit buffer (blocking)
242255 switch (i2c_master_write (&_i2c, txAddress, txBuffer, txDataSize)) {
243256 case I2C_OK :
0 commit comments