@@ -124,48 +124,43 @@ uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddres
124
124
125
125
if (_i2c.isMaster == 1 ) {
126
126
allocateRxBuffer (quantity);
127
- // error if no memory block available to allocate the buffer
128
- if (rxBuffer == nullptr ) {
129
- setWriteError ();
130
- } else {
131
127
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)
136
132
137
- beginTransmission (address);
133
+ beginTransmission (address);
138
134
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
+ }
143
139
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 )));
149
143
}
144
+ endTransmission (false );
145
+ }
150
146
151
- // perform blocking read into buffer
147
+ // perform blocking read into buffer
152
148
#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
+ }
158
154
#endif
159
155
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
+ }
163
159
164
- // set rx buffer iterator vars
165
- rxBufferIndex = 0 ;
166
- rxBufferLength = read ;
160
+ // set rx buffer iterator vars
161
+ rxBufferIndex = 0 ;
162
+ rxBufferLength = read ;
167
163
168
- }
169
164
}
170
165
return read ;
171
166
}
@@ -291,10 +286,6 @@ size_t TwoWire::write(uint8_t data)
291
286
// in master transmitter mode
292
287
if (allocateTxBuffer (txDataSize + 1 ) == 0 ) {
293
288
ret = 0 ;
294
- } else if (txBuffer == nullptr ) {
295
- // error if no memory block available to allocate the buffer
296
- setWriteError ();
297
- ret = 0 ;
298
289
} else {
299
290
// put byte in tx buffer
300
291
txBuffer[txDataSize] = data;
@@ -326,10 +317,6 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity)
326
317
// in master transmitter mode
327
318
if (allocateTxBuffer (txDataSize + quantity) == 0 ) {
328
319
ret = 0 ;
329
- } else if (txBuffer == nullptr ) {
330
- // error if no memory block available to allocate the buffer
331
- setWriteError ();
332
- ret = 0 ;
333
320
} else {
334
321
// put bytes in tx buffer
335
322
memcpy (&(txBuffer[txDataSize]), data, quantity);
@@ -413,12 +400,7 @@ void TwoWire::onReceiveService(i2c_t *obj)
413
400
// i know this drops data, but it allows for slight stupidity
414
401
// meaning, they may not have read all the master requestFrom() data yet
415
402
if (TW->rxBufferIndex >= TW->rxBufferLength ) {
416
-
417
403
TW->allocateRxBuffer (numBytes);
418
- // error if no memory block available to allocate the buffer
419
- if (TW->rxBuffer == nullptr ) {
420
- Error_Handler ();
421
- }
422
404
423
405
// copy twi rx buffer into local read buffer
424
406
// this enables new reads to happen in parallel
0 commit comments