@@ -124,48 +124,43 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres
124124
125125 if (_i2c.isMaster == 1 ) {
126126 allocateRxBuffer (quantity);
127- // error if no memory block available to allocate the buffer
128- if (rxBuffer == nullptr ) {
129- setWriteError ();
130- } else {
131127
132- if (isize > 0 ) {
133- // send internal address; this mode allows sending a repeated start to access
134- // some devices' internal registers. This function is executed by the hardware
135- // TWI module on other processors (for example Due's TWI_IADR and TWI_MMR registers)
128+ if (isize > 0 ) {
129+ // send internal address; this mode allows sending a repeated start to access
130+ // some devices' internal registers. This function is executed by the hardware
131+ // TWI module on other processors (for example Due's TWI_IADR and TWI_MMR registers)
136132
137- beginTransmission (address);
133+ beginTransmission (address);
138134
139- // the maximum size of internal address is 3 bytes
140- if (isize > 3 ) {
141- isize = 3 ;
142- }
135+ // the maximum size of internal address is 3 bytes
136+ if (isize > 3 ) {
137+ isize = 3 ;
138+ }
143139
144- // write internal register address - most significant byte first
145- while (isize-- > 0 ) {
146- write ((uint8_t )(iaddress >> (isize * 8 )));
147- }
148- endTransmission (false );
140+ // write internal register address - most significant byte first
141+ while (isize-- > 0 ) {
142+ write ((uint8_t )(iaddress >> (isize * 8 )));
149143 }
144+ endTransmission (false );
145+ }
150146
151- // perform blocking read into buffer
147+ // perform blocking read into buffer
152148#if defined(I2C_OTHER_FRAME)
153- if (sendStop == 0 ) {
154- _i2c.handle .XferOptions = I2C_OTHER_FRAME ;
155- } else {
156- _i2c.handle .XferOptions = I2C_OTHER_AND_LAST_FRAME;
157- }
149+ if (sendStop == 0 ) {
150+ _i2c.handle .XferOptions = I2C_OTHER_FRAME ;
151+ } else {
152+ _i2c.handle .XferOptions = I2C_OTHER_AND_LAST_FRAME;
153+ }
158154#endif
159155
160- if (I2C_OK == i2c_master_read (&_i2c, address << 1 , rxBuffer, quantity)) {
161- read = quantity;
162- }
156+ if (I2C_OK == i2c_master_read (&_i2c, address << 1 , rxBuffer, quantity)) {
157+ read = quantity;
158+ }
163159
164- // set rx buffer iterator vars
165- rxBufferIndex = 0 ;
166- rxBufferLength = read;
160+ // set rx buffer iterator vars
161+ rxBufferIndex = 0 ;
162+ rxBufferLength = read;
167163
168- }
169164 }
170165 return read;
171166}
@@ -291,10 +286,6 @@ size_t TwoWire::write(uint8_t data)
291286 // in master transmitter mode
292287 if (allocateTxBuffer (txDataSize + 1 ) == 0 ) {
293288 ret = 0 ;
294- } else if (txBuffer == nullptr ) {
295- // error if no memory block available to allocate the buffer
296- setWriteError ();
297- ret = 0 ;
298289 } else {
299290 // put byte in tx buffer
300291 txBuffer[txDataSize] = data;
@@ -326,10 +317,6 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity)
326317 // in master transmitter mode
327318 if (allocateTxBuffer (txDataSize + quantity) == 0 ) {
328319 ret = 0 ;
329- } else if (txBuffer == nullptr ) {
330- // error if no memory block available to allocate the buffer
331- setWriteError ();
332- ret = 0 ;
333320 } else {
334321 // put bytes in tx buffer
335322 memcpy (&(txBuffer[txDataSize]), data, quantity);
@@ -413,12 +400,7 @@ void TwoWire::onReceiveService(i2c_t *obj)
413400 // i know this drops data, but it allows for slight stupidity
414401 // meaning, they may not have read all the master requestFrom() data yet
415402 if (TW->rxBufferIndex >= TW->rxBufferLength ) {
416-
417403 TW->allocateRxBuffer (numBytes);
418- // error if no memory block available to allocate the buffer
419- if (TW->rxBuffer == nullptr ) {
420- Error_Handler ();
421- }
422404
423405 // copy twi rx buffer into local read buffer
424406 // this enables new reads to happen in parallel
0 commit comments